1
2
3
4
5
6
7
8
9
10
11 package edu.uci.ics.jung.visualization.transform;
12
13 import java.awt.geom.AffineTransform;
14 import java.awt.geom.Point2D;
15
16 import javax.swing.event.ChangeListener;
17 import javax.swing.event.EventListenerList;
18
19 import edu.uci.ics.jung.visualization.transform.shape.ShapeTransformer;
20 import edu.uci.ics.jung.visualization.util.ChangeEventSupport;
21 import edu.uci.ics.jung.visualization.util.DefaultChangeEventSupport;
22
23
24
25
26
27
28
29
30
31
32
33
34 public class MutableAffineTransformer extends AffineTransformer
35 implements MutableTransformer, ShapeTransformer, ChangeEventSupport {
36
37 protected ChangeEventSupport changeSupport =
38 new DefaultChangeEventSupport(this);
39
40
41
42
43
44 public MutableAffineTransformer() {
45
46 }
47
48
49
50 public MutableAffineTransformer(AffineTransform transform) {
51 super(transform);
52 }
53
54 public String toString() {
55 return "MutableAffineTransformer using "+transform;
56 }
57
58
59
60
61
62
63
64 public void scale(double scalex, double scaley, Point2D from) {
65 AffineTransform xf = AffineTransform.getTranslateInstance(from.getX(),from.getY());
66 xf.scale(scalex, scaley);
67 xf.translate(-from.getX(), -from.getY());
68 inverse = null;
69 transform.preConcatenate(xf);
70 fireStateChanged();
71 }
72
73
74
75
76
77
78
79
80 public void setScale(double scalex, double scaley, Point2D from) {
81 transform.setToIdentity();
82 scale(scalex, scaley, from);
83 }
84
85
86
87
88
89
90 public void shear(double shx, double shy, Point2D from) {
91 inverse = null;
92 AffineTransform at =
93 AffineTransform.getTranslateInstance(from.getX(), from.getY());
94 at.shear(shx, shy);
95 at.translate(-from.getX(), -from.getY());
96 transform.preConcatenate(at);
97 fireStateChanged();
98 }
99
100
101
102
103
104
105
106
107 public void setTranslate(double tx, double ty) {
108 float scalex = (float) transform.getScaleX();
109 float scaley = (float) transform.getScaleY();
110 float shearx = (float) transform.getShearX();
111 float sheary = (float) transform.getShearY();
112 inverse = null;
113 transform.setTransform(scalex,
114 sheary,
115 shearx,
116 scaley,
117 tx, ty);
118 fireStateChanged();
119 }
120
121
122
123
124
125
126 public void translate(double offsetx, double offsety) {
127 inverse = null;
128 transform.translate(offsetx, offsety);
129 fireStateChanged();
130 }
131
132
133
134
135 public void rotate(double theta, Point2D from) {
136 AffineTransform rotate =
137 AffineTransform.getRotateInstance(theta, from.getX(), from.getY());
138 inverse = null;
139 transform.preConcatenate(rotate);
140
141 fireStateChanged();
142 }
143
144
145
146
147 public void rotate(double radians, double x, double y) {
148 inverse = null;
149 transform.rotate(radians, x, y);
150 fireStateChanged();
151 }
152
153 public void concatenate(AffineTransform xform) {
154 inverse = null;
155 transform.concatenate(xform);
156 fireStateChanged();
157
158 }
159 public void preConcatenate(AffineTransform xform) {
160 inverse = null;
161 transform.preConcatenate(xform);
162 fireStateChanged();
163 }
164
165
166
167
168
169
170 public void addChangeListener(ChangeListener l) {
171 changeSupport.addChangeListener(l);
172 }
173
174
175
176
177
178 public void removeChangeListener(ChangeListener l) {
179 changeSupport.removeChangeListener(l);
180 }
181
182
183
184
185
186
187
188
189 public ChangeListener[] getChangeListeners() {
190 return changeSupport.getChangeListeners();
191 }
192
193
194
195
196
197
198
199 public void fireStateChanged() {
200 changeSupport.fireStateChanged();
201 }
202
203 public void setToIdentity() {
204 inverse = null;
205 transform.setToIdentity();
206 fireStateChanged();
207 }
208 }