KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > sharededitor > models > Selector


1 /*
2 @COPYRIGHT@
3 */

4 package demo.sharededitor.models;
5
6 import java.awt.Image JavaDoc;
7 import java.awt.Shape JavaDoc;
8 import java.awt.geom.Ellipse2D JavaDoc;
9 import java.awt.geom.Rectangle2D JavaDoc;
10
11 final class Selector
12     extends BaseObject
13 {
14     private Rectangle2D.Double JavaDoc shape;
15     
16     protected Shape JavaDoc getShape()
17     {
18         return shape;
19     }
20
21     protected Shape JavaDoc[] getAnchors()
22     {
23         return new Shape JavaDoc[] {
24             new Ellipse2D.Double JavaDoc(x1 - 5, y2 - 5, 10, 10),
25             new Ellipse2D.Double JavaDoc(x2 - 5, y2 - 5, 10, 10),
26             new Ellipse2D.Double JavaDoc(x2 - 5, y1 - 5, 10, 10),
27             new Ellipse2D.Double JavaDoc(x1 - 5, y1 - 5, 10, 10)
28         };
29     }
30
31     public synchronized void move(int dx, int dy)
32     {
33         x1 += dx;
34         y1 += dy;
35         x2 += dx;
36         y2 += dy;
37         shape.setFrameFromDiagonal(x1, y1, x2, y2);
38         this.notifyListeners(this);
39     }
40
41     public synchronized void resize(int x, int y)
42     {
43         switch (grabbedAnchor())
44         {
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     public boolean isTransient()
67     {
68        return true;
69     }
70
71     private int x1, y1, x2, y2;
72     
73     public Selector()
74     {
75         x1 = y1 = x2 = y2 = 0;
76         shape = new Rectangle2D.Double JavaDoc();
77         shape.setFrameFromDiagonal(x1, y1, x2, y2);
78     }
79 }
80
Popular Tags