01: /*
02: @COPYRIGHT@
03: */
04: package demo.sharededitor.models;
05:
06: import java.awt.Shape;
07: import java.awt.geom.Ellipse2D;
08: import java.awt.geom.Rectangle2D;
09:
10: final class Selector extends BaseObject {
11: private Rectangle2D.Double shape;
12:
13: protected Shape getShape() {
14: return shape;
15: }
16:
17: protected Shape[] getAnchors() {
18: return new Shape[] {
19: new Ellipse2D.Double(x1 - 5, y2 - 5, 10, 10),
20: new Ellipse2D.Double(x2 - 5, y2 - 5, 10, 10),
21: new Ellipse2D.Double(x2 - 5, y1 - 5, 10, 10),
22: new Ellipse2D.Double(x1 - 5, y1 - 5, 10, 10) };
23: }
24:
25: public synchronized void move(int dx, int dy) {
26: x1 += dx;
27: y1 += dy;
28: x2 += dx;
29: y2 += dy;
30: shape.setFrameFromDiagonal(x1, y1, x2, y2);
31: this .notifyListeners(this );
32: }
33:
34: public synchronized void resize(int x, int y) {
35: switch (grabbedAnchor()) {
36: case 0:
37: x1 = x;
38: y2 = y;
39: break;
40: case 1:
41: x2 = x;
42: y2 = y;
43: break;
44: case 2:
45: x2 = x;
46: y1 = y;
47: break;
48: case 3:
49: x1 = x;
50: y1 = y;
51: break;
52: }
53: shape.setFrameFromDiagonal(x1, y1, x2, y2);
54: this .notifyListeners(this );
55: }
56:
57: public boolean isTransient() {
58: return true;
59: }
60:
61: private int x1, y1, x2, y2;
62:
63: public Selector() {
64: x1 = y1 = x2 = y2 = 0;
65: shape = new Rectangle2D.Double();
66: shape.setFrameFromDiagonal(x1, y1, x2, y2);
67: }
68: }
|