Line | Hits | Source |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2005, the JUNG Project and the Regents of the University of | |
3 | * California All rights reserved. | |
4 | * | |
5 | * This software is open-source under the BSD license; see either "license.txt" | |
6 | * or http://jung.sourceforge.net/license.txt for a description. | |
7 | * | |
8 | * Created on Apr 16, 2005 | |
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.utils.ChangeEventSupport; | |
20 | import edu.uci.ics.jung.utils.DefaultChangeEventSupport; | |
21 | import edu.uci.ics.jung.visualization.transform.shape.ShapeTransformer; | |
22 | ||
23 | /** | |
24 | * | |
25 | * Provides methods to mutate the AffineTransform used by AffineTransformer | |
26 | * base class to map points from one coordinate system to | |
27 | * another. | |
28 | * | |
29 | * | |
30 | * @author Tom Nelson - RABA Technologies | |
31 | * | |
32 | * | |
33 | */ | |
34 | public class MutableAffineTransformer extends AffineTransformer | |
35 | implements MutableTransformer, ShapeTransformer, ChangeEventSupport { | |
36 | ||
37 | 0 | protected ChangeEventSupport changeSupport = |
38 | new DefaultChangeEventSupport(this); | |
39 | ||
40 | /** | |
41 | * create an instance that does not transform points | |
42 | * | |
43 | */ | |
44 | 0 | public MutableAffineTransformer() { |
45 | // nothing left to do | |
46 | 0 | } |
47 | /** | |
48 | * Create an instance with the supplied transform | |
49 | */ | |
50 | public MutableAffineTransformer(AffineTransform transform) { | |
51 | 0 | super(transform); |
52 | 0 | } |
53 | ||
54 | public String toString() { | |
55 | 0 | return "MutableAffineTransformer using "+transform; |
56 | } | |
57 | /** | |
58 | * setter for the scale | |
59 | * fires a PropertyChangeEvent with the AffineTransforms representing | |
60 | * the previous and new values for scale and offset | |
61 | * @param scalex | |
62 | * @param scaley | |
63 | */ | |
64 | public void scale(double scalex, double scaley, Point2D from) { | |
65 | 0 | AffineTransform xf = AffineTransform.getTranslateInstance(from.getX(),from.getY()); |
66 | 0 | xf.scale(scalex, scaley); |
67 | 0 | xf.translate(-from.getX(), -from.getY()); |
68 | 0 | inverse = null; |
69 | 0 | transform.preConcatenate(xf); |
70 | 0 | fireStateChanged(); |
71 | 0 | } |
72 | ||
73 | /** | |
74 | * setter for the scale | |
75 | * fires a PropertyChangeEvent with the AffineTransforms representing | |
76 | * the previous and new values for scale and offset | |
77 | * @param scalex | |
78 | * @param scaley | |
79 | */ | |
80 | public void setScale(double scalex, double scaley, Point2D from) { | |
81 | 0 | transform.setToIdentity(); |
82 | 0 | scale(scalex, scaley, from); |
83 | 0 | } |
84 | ||
85 | /** | |
86 | * shears the transform by passed parameters | |
87 | * @param shx x value to shear | |
88 | * @param shy y value to shear | |
89 | */ | |
90 | public void shear(double shx, double shy, Point2D from) { | |
91 | 0 | inverse = null; |
92 | 0 | AffineTransform at = |
93 | AffineTransform.getTranslateInstance(from.getX(), from.getY()); | |
94 | 0 | at.shear(shx, shy); |
95 | 0 | at.translate(-from.getX(), -from.getY()); |
96 | 0 | transform.preConcatenate(at); |
97 | 0 | fireStateChanged(); |
98 | 0 | } |
99 | ||
100 | /** | |
101 | * replace the Transform's translate x and y values | |
102 | * with the passed values, leaving the scale values | |
103 | * unchanged | |
104 | * @param tx the x value | |
105 | * @param ty the y value | |
106 | */ | |
107 | public void setTranslate(double tx, double ty) { | |
108 | 0 | float scalex = (float) transform.getScaleX(); |
109 | 0 | float scaley = (float) transform.getScaleY(); |
110 | 0 | float shearx = (float) transform.getShearX(); |
111 | 0 | float sheary = (float) transform.getShearY(); |
112 | 0 | inverse = null; |
113 | 0 | transform.setTransform(scalex, |
114 | sheary, | |
115 | shearx, | |
116 | scaley, | |
117 | tx, ty); | |
118 | 0 | fireStateChanged(); |
119 | 0 | } |
120 | ||
121 | /** | |
122 | * Apply the passed values to the current Transform | |
123 | * @param offsetx the x-value | |
124 | * @param offsety the y-value | |
125 | */ | |
126 | public void translate(double offsetx, double offsety) { | |
127 | 0 | inverse = null; |
128 | 0 | transform.translate(offsetx, offsety); |
129 | 0 | fireStateChanged(); |
130 | 0 | } |
131 | ||
132 | /** | |
133 | * preconcatenates the rotation at the supplied point with the current transform | |
134 | */ | |
135 | public void rotate(double theta, Point2D from) { | |
136 | 0 | AffineTransform rotate = |
137 | AffineTransform.getRotateInstance(theta, from.getX(), from.getY()); | |
138 | 0 | inverse = null; |
139 | 0 | transform.preConcatenate(rotate); |
140 | ||
141 | 0 | fireStateChanged(); |
142 | 0 | } |
143 | ||
144 | /** | |
145 | * rotates the current transform at the supplied points | |
146 | */ | |
147 | public void rotate(double radians, double x, double y) { | |
148 | 0 | inverse = null; |
149 | 0 | transform.rotate(radians, x, y); |
150 | 0 | fireStateChanged(); |
151 | 0 | } |
152 | ||
153 | public void concatenate(AffineTransform xform) { | |
154 | 0 | inverse = null; |
155 | 0 | transform.concatenate(xform); |
156 | 0 | fireStateChanged(); |
157 | ||
158 | 0 | } |
159 | public void preConcatenate(AffineTransform xform) { | |
160 | 0 | inverse = null; |
161 | 0 | transform.preConcatenate(xform); |
162 | 0 | fireStateChanged(); |
163 | 0 | } |
164 | ||
165 | ||
166 | /** | |
167 | * Adds a <code>ChangeListener</code>. | |
168 | * @param l the listener to be added | |
169 | */ | |
170 | public void addChangeListener(ChangeListener l) { | |
171 | 0 | changeSupport.addChangeListener(l); |
172 | 0 | } |
173 | ||
174 | /** | |
175 | * Removes a ChangeListener. | |
176 | * @param l the listener to be removed | |
177 | */ | |
178 | public void removeChangeListener(ChangeListener l) { | |
179 | 0 | changeSupport.removeChangeListener(l); |
180 | 0 | } |
181 | ||
182 | /** | |
183 | * Returns an array of all the <code>ChangeListener</code>s added | |
184 | * with addChangeListener(). | |
185 | * | |
186 | * @return all of the <code>ChangeListener</code>s added or an empty | |
187 | * array if no listeners have been added | |
188 | */ | |
189 | public ChangeListener[] getChangeListeners() { | |
190 | 0 | return changeSupport.getChangeListeners(); |
191 | } | |
192 | ||
193 | /** | |
194 | * Notifies all listeners that have registered interest for | |
195 | * notification on this event type. The event instance | |
196 | * is lazily created. | |
197 | * @see EventListenerList | |
198 | */ | |
199 | public void fireStateChanged() { | |
200 | 0 | changeSupport.fireStateChanged(); |
201 | 0 | } |
202 | ||
203 | public void setToIdentity() { | |
204 | 0 | inverse = null; |
205 | 0 | transform.setToIdentity(); |
206 | 0 | fireStateChanged(); |
207 | 0 | } |
208 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |