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