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