Revision 689
tags/org.gvsig.app.document.layout2.app-2.0.105/org.gvsig.app.document.layout2.app.mainplugin/src/test/resources/README.txt | ||
---|---|---|
1 |
Put into this folder the resources needed by your test classes. |
|
2 |
|
|
3 |
This folder is added to the Tests classpath, so you can load any resources |
|
4 |
through the ClassLoader. |
|
5 |
|
|
6 |
By default, in this folder you can find an example of log4j configuration, |
|
7 |
prepared to log messages through the console, so logging works when you |
|
8 |
run your tests classes. |
tags/org.gvsig.app.document.layout2.app-2.0.105/org.gvsig.app.document.layout2.app.mainplugin/src/test/resources/log4j.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1" ?> |
|
2 |
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> |
|
3 |
|
|
4 |
<!-- |
|
5 |
Log4J configuration file for unit tests execution. |
|
6 |
--> |
|
7 |
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> |
|
8 |
|
|
9 |
<!-- Appender configuration to show logging messages through the console --> |
|
10 |
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> |
|
11 |
<layout class="org.apache.log4j.PatternLayout"> |
|
12 |
<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n %m%n" /> |
|
13 |
</layout> |
|
14 |
</appender> |
|
15 |
|
|
16 |
<!-- |
|
17 |
Activate logging messages of DEBUG level of higher only for the |
|
18 |
org.gvsig.tools packages. |
|
19 |
You can put full classes names or packages instead, to configure |
|
20 |
logging for all the classes and subpackages of the package. |
|
21 |
--> |
|
22 |
<category name="org.gvsig.tools"> |
|
23 |
<priority value="DEBUG" /> |
|
24 |
</category> |
|
25 |
<category name="org.gvsig.app.document.layout"> |
|
26 |
<priority value="DEBUG" /> |
|
27 |
</category> |
|
28 |
|
|
29 |
<!-- |
|
30 |
By default, show only logging messages of INFO level or higher, |
|
31 |
through the previously configured CONSOLE appender. |
|
32 |
--> |
|
33 |
<root> |
|
34 |
<priority value="INFO" /> |
|
35 |
<appender-ref ref="CONSOLE" /> |
|
36 |
</root> |
|
37 |
</log4j:configuration> |
|
0 | 38 |
tags/org.gvsig.app.document.layout2.app-2.0.105/org.gvsig.app.document.layout2.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml | ||
---|---|---|
1 |
<assembly> |
|
2 |
<id>gvsig-plugin-package</id> |
|
3 |
<formats> |
|
4 |
<format>zip</format> |
|
5 |
</formats> |
|
6 |
<baseDirectory>${project.artifactId}</baseDirectory> |
|
7 |
<includeBaseDirectory>true</includeBaseDirectory> |
|
8 |
<files> |
|
9 |
<file> |
|
10 |
<source>target/${project.artifactId}-${project.version}.jar</source> |
|
11 |
<outputDirectory>lib</outputDirectory> |
|
12 |
</file> |
|
13 |
<file> |
|
14 |
<source>target/package.info</source> |
|
15 |
</file> |
|
16 |
</files> |
|
17 |
|
|
18 |
<fileSets> |
|
19 |
<fileSet> |
|
20 |
<directory>src/main/resources-plugin</directory> |
|
21 |
<outputDirectory>.</outputDirectory> |
|
22 |
</fileSet> |
|
23 |
</fileSets> |
|
24 |
|
|
25 |
<dependencySets> |
|
26 |
|
|
27 |
<!-- |
|
28 |
<dependencySet> |
|
29 |
<useProjectArtifact>false</useProjectArtifact> |
|
30 |
<useTransitiveDependencies>false</useTransitiveDependencies> |
|
31 |
<outputDirectory>lib</outputDirectory> |
|
32 |
<includes> |
|
33 |
</includes> |
|
34 |
</dependencySet> |
|
35 |
|
|
36 |
--> |
|
37 |
|
|
38 |
</dependencySets> |
|
39 |
|
|
40 |
</assembly> |
|
0 | 41 |
tags/org.gvsig.app.document.layout2.app-2.0.105/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/math/intervals/IntervalUtils.java | ||
---|---|---|
1 |
package org.gvsig.math.intervals; |
|
2 |
|
|
3 |
public class IntervalUtils { |
|
4 |
|
|
5 |
/** |
|
6 |
* Calculates an nice round interval division. For instance, for |
|
7 |
* intervalLenght = 1100000 and numberOfDivisions=5, |
|
8 |
* the result would be 250000. |
|
9 |
* |
|
10 |
* @param intervalLength The full interval to be divided |
|
11 |
* @param numberOfDivisions The exact number of divisions to perform |
|
12 |
* @return A nice round interval division. The calculated result |
|
13 |
* ensures that the whole interval length is covered by the proposed |
|
14 |
* division, so it always fulfills the following formula: |
|
15 |
* <code>result*numberOfDivisions>=intervalLength</code> |
|
16 |
*/ |
|
17 |
public static double roundIntervalDivision(double intervalLength, int numberOfDivisions) { |
|
18 |
if (intervalLength<=0.0d || numberOfDivisions<=0) { |
|
19 |
return 0.0d; |
|
20 |
} |
|
21 |
|
|
22 |
double division = intervalLength/numberOfDivisions; |
|
23 |
if (division==0.0d) { |
|
24 |
return 0.0d; |
|
25 |
} |
|
26 |
double digitShift = Math.floor((Math.log10(division))); |
|
27 |
double scale = Math.pow(10, -digitShift); |
|
28 |
double firstSignificatDigit = Math.floor(scale*division); |
|
29 |
double result = firstSignificatDigit*Math.pow(10, digitShift); |
|
30 |
if (result*numberOfDivisions>=intervalLength) { |
|
31 |
return result; |
|
32 |
} |
|
33 |
else { |
|
34 |
result = (0.5+firstSignificatDigit)*Math.pow(10, digitShift); |
|
35 |
if (result*numberOfDivisions>=intervalLength) { |
|
36 |
return result; |
|
37 |
} |
|
38 |
} |
|
39 |
result = (1+firstSignificatDigit)*Math.pow(10, digitShift); |
|
40 |
return result; |
|
41 |
} |
|
42 |
} |
tags/org.gvsig.app.document.layout2.app-2.0.105/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/LayoutControl.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.app.project.documents.layout; |
|
23 |
|
|
24 |
import java.awt.Image; |
|
25 |
import java.awt.Point; |
|
26 |
import java.awt.Rectangle; |
|
27 |
import java.awt.geom.AffineTransform; |
|
28 |
import java.awt.geom.Rectangle2D; |
|
29 |
import java.awt.image.BufferedImage; |
|
30 |
|
|
31 |
import javax.swing.JComponent; |
|
32 |
|
|
33 |
import org.gvsig.app.project.documents.layout.geometryadapters.GeometryAdapter; |
|
34 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
|
35 |
import org.gvsig.app.project.documents.layout.tools.behavior.LayoutBehavior; |
|
36 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
37 |
import org.gvsig.tools.observer.Observer; |
|
38 |
|
|
39 |
/** |
|
40 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a> |
|
41 |
*/ |
|
42 |
public interface LayoutControl extends Observer { |
|
43 |
|
|
44 |
/** |
|
45 |
* <p>Returns a copy of the rectangle that represents the size |
|
46 |
* and position of the layout sheet (in pixels), relative to |
|
47 |
* the containing LayoutControl.</p> |
|
48 |
* |
|
49 |
* <p>Note: you must use {@link #setRect(Rectangle2D)} to update |
|
50 |
* the rectangle, as this method only returns a copy of it.</p> |
|
51 |
* @return Rectangle2D.Double Rectangle that represents the sheet. |
|
52 |
* @see LayoutControl#setRect(Rectangle2D) |
|
53 |
*/ |
|
54 |
public Rectangle2D.Double getRect(); |
|
55 |
|
|
56 |
/** |
|
57 |
* <p>Sets the size and position of the layout sheet in screen coordinates |
|
58 |
* (pixels), relative to the LayoutControl.</p> |
|
59 |
* |
|
60 |
* <p>The size of the sheet is usually different from the |
|
61 |
* bounds of the underlying UI control, for instance if we have zoomed in |
|
62 |
* an area of the sheet then the paper size in pixels will be bigger than |
|
63 |
* the actual control size.</p> |
|
64 |
* |
|
65 |
*/ |
|
66 |
public void setRect(Rectangle2D r); |
|
67 |
|
|
68 |
/** |
|
69 |
* Returns the name of the current selected tool on this Layout |
|
70 |
* |
|
71 |
* @return A tool name. |
|
72 |
*/ |
|
73 |
public String getCurrentTool(); |
|
74 |
|
|
75 |
/** |
|
76 |
* Add a new Layout tool. |
|
77 |
* |
|
78 |
* @param name |
|
79 |
* Name of tool. |
|
80 |
* @param tool |
|
81 |
* LayoutBehavior |
|
82 |
*/ |
|
83 |
public void addLayoutTool(String name, LayoutBehavior tool); |
|
84 |
|
|
85 |
/** |
|
86 |
* Inserts the LayoutContext. |
|
87 |
* |
|
88 |
* @param lc |
|
89 |
* LayoutContext. |
|
90 |
*/ |
|
91 |
public void setLayoutContext(LayoutContext lc); |
|
92 |
|
|
93 |
/** |
|
94 |
* Returns the image with the ruler. |
|
95 |
* |
|
96 |
* @return Ruler image. |
|
97 |
*/ |
|
98 |
public BufferedImage getImgRuler(); |
|
99 |
|
|
100 |
/** |
|
101 |
* It obtains the rect that is adjusted to the size of the window, |
|
102 |
* to see the full extent of layout. |
|
103 |
*/ |
|
104 |
public void fullRect(); |
|
105 |
|
|
106 |
/** |
|
107 |
* Returns the current image of Layout. |
|
108 |
* |
|
109 |
* @return Current image of Layout. |
|
110 |
*/ |
|
111 |
public BufferedImage getImage(); |
|
112 |
|
|
113 |
/** |
|
114 |
* Changes the pointer of the mouse by the image of parameter. |
|
115 |
* |
|
116 |
* @param image |
|
117 |
* Image |
|
118 |
*/ |
|
119 |
public void setMapCursor(Image image); |
|
120 |
|
|
121 |
/** |
|
122 |
* It establishes as selected to the tool from its name of identification. |
|
123 |
* |
|
124 |
* @param toolName |
|
125 |
* Name of identification tool. |
|
126 |
*/ |
|
127 |
public void setTool(String toolName); |
|
128 |
|
|
129 |
/** |
|
130 |
* Changes the currently selected tool to the default tool |
|
131 |
*/ |
|
132 |
public void setDefaultTool(); |
|
133 |
|
|
134 |
/** |
|
135 |
* Start the vertex edition of graphics. |
|
136 |
* |
|
137 |
*/ |
|
138 |
public void startEdit(); |
|
139 |
|
|
140 |
/** |
|
141 |
* Stop the vertex edition of graphics. |
|
142 |
* |
|
143 |
*/ |
|
144 |
public void stopEdit(); |
|
145 |
|
|
146 |
/** |
|
147 |
* It returns the point that represents the northwest corner of the Layout. |
|
148 |
* |
|
149 |
* @return Point. |
|
150 |
*/ |
|
151 |
public Point getRectOrigin(); |
|
152 |
|
|
153 |
/** |
|
154 |
* Returns the object to draw the Layout. |
|
155 |
* |
|
156 |
* @return FLayoutDraw. |
|
157 |
*/ |
|
158 |
public FLayoutDraw getLayoutDraw(); |
|
159 |
|
|
160 |
/** |
|
161 |
* Returns the current Layout tool. |
|
162 |
* |
|
163 |
* @return LayoutBehavior Current Layout Tool. |
|
164 |
*/ |
|
165 |
public LayoutBehavior getCurrentLayoutTool(); |
|
166 |
|
|
167 |
/** |
|
168 |
* It returns the first click point of mouse. |
|
169 |
* |
|
170 |
* @return Point. |
|
171 |
*/ |
|
172 |
public Point getFirstPoint(); |
|
173 |
|
|
174 |
/** |
|
175 |
* Returns the previous click of mouse. |
|
176 |
* |
|
177 |
* @return Point. |
|
178 |
*/ |
|
179 |
public Point getPointAnt(); |
|
180 |
|
|
181 |
/** |
|
182 |
* Returns the last click point of mouse. |
|
183 |
* |
|
184 |
* @return Point. |
|
185 |
*/ |
|
186 |
public Point getLastPoint(); |
|
187 |
|
|
188 |
/** |
|
189 |
* Inserts the first click point of mouse. |
|
190 |
* |
|
191 |
* @param p |
|
192 |
* Point. |
|
193 |
*/ |
|
194 |
public void setFirstPoint(); |
|
195 |
|
|
196 |
/** |
|
197 |
* Inserts the previous click point of mouse. |
|
198 |
* |
|
199 |
* @param p |
|
200 |
* Point. |
|
201 |
*/ |
|
202 |
public void setPointAnt(); |
|
203 |
|
|
204 |
/** |
|
205 |
* Inserts the last click point of mouse. |
|
206 |
* |
|
207 |
* @param p |
|
208 |
* Point. |
|
209 |
*/ |
|
210 |
public void setLastPoint(); |
|
211 |
|
|
212 |
/** |
|
213 |
* Insert the position point and calculate the new position if the grid is |
|
214 |
* actived. |
|
215 |
* |
|
216 |
* @param point2 |
|
217 |
* Position. |
|
218 |
*/ |
|
219 |
public void setPosition(Point point2); |
|
220 |
|
|
221 |
/** |
|
222 |
* Returns the position adjusted point. |
|
223 |
* |
|
224 |
* @return |
|
225 |
*/ |
|
226 |
public Point getPosition(); |
|
227 |
|
|
228 |
/** |
|
229 |
* Returns the AffineTransform that is applying in the Layout. |
|
230 |
* |
|
231 |
* @return AffineTransform |
|
232 |
*/ |
|
233 |
public AffineTransform getAT(); |
|
234 |
|
|
235 |
/** |
|
236 |
* It returns the current GeometryAdapter. |
|
237 |
* |
|
238 |
* @return Current GeometryAdapter. |
|
239 |
*/ |
|
240 |
public GeometryAdapter getGeometryAdapter(); |
|
241 |
|
|
242 |
/** |
|
243 |
* Remove last point of geometryAdapter. |
|
244 |
* |
|
245 |
*/ |
|
246 |
public void delLastPoint(); |
|
247 |
|
|
248 |
/** |
|
249 |
* Add a new point to geometryAdapter. |
|
250 |
* |
|
251 |
* @return Number of points in the geometryAdapter. |
|
252 |
*/ |
|
253 |
public int addGeometryAdapterPoint(); |
|
254 |
|
|
255 |
/** |
|
256 |
* Change the position of mousemoved point of geometryAdapter. |
|
257 |
*/ |
|
258 |
public void setGeometryAdapterPoinPosition(); |
|
259 |
|
|
260 |
/** |
|
261 |
* Clear the image of pointer of mouse. |
|
262 |
*/ |
|
263 |
public void clearMouseImage(); |
|
264 |
|
|
265 |
/** |
|
266 |
* Refres the Layout. |
|
267 |
*/ |
|
268 |
public void refresh(); |
|
269 |
|
|
270 |
/** |
|
271 |
* It returns true if the drawing has been canceled. |
|
272 |
* |
|
273 |
* @return true if the drawn has been canceled. |
|
274 |
*/ |
|
275 |
public boolean isDrawingCancelled(); |
|
276 |
|
|
277 |
/** |
|
278 |
* It cancels the drawing if the parameter is true. |
|
279 |
* |
|
280 |
* @param b |
|
281 |
* true if the drawing wants to be canceled |
|
282 |
*/ |
|
283 |
public void setCancelDrawing(boolean b); |
|
284 |
|
|
285 |
/** |
|
286 |
* Returns the rectangle of selection. |
|
287 |
* |
|
288 |
* @return Rectangle of selection. |
|
289 |
*/ |
|
290 |
public Rectangle getReSel(); |
|
291 |
|
|
292 |
/** |
|
293 |
* It returns true if should draw the rectangle of selection and does the |
|
294 |
* selection. |
|
295 |
* |
|
296 |
* @return true if should draw the rectangle of selection. |
|
297 |
*/ |
|
298 |
public boolean isReSel(); |
|
299 |
|
|
300 |
/** |
|
301 |
* Insert true if should draw the rectangle of selection and does the |
|
302 |
* selection. |
|
303 |
* |
|
304 |
* @param b |
|
305 |
* boolean. |
|
306 |
*/ |
|
307 |
public void setIsReSel(boolean b); |
|
308 |
|
|
309 |
/** |
|
310 |
* It does a full extent of the layers that contains the view of the |
|
311 |
* FFrameView selected. |
|
312 |
* |
|
313 |
* @throws ReadDriverException |
|
314 |
*/ |
|
315 |
public void viewFull() throws ReadException; |
|
316 |
|
|
317 |
/** |
|
318 |
* Returns the object to make zooms. |
|
319 |
* |
|
320 |
* @return FLayoutZooms. |
|
321 |
*/ |
|
322 |
public FLayoutZooms getLayoutZooms(); |
|
323 |
|
|
324 |
/** |
|
325 |
* Returns the object of FLayoutFunctions. |
|
326 |
* |
|
327 |
* @return FLayoutFunctions |
|
328 |
*/ |
|
329 |
public FLayoutFunctions getLayoutFunctions(); |
|
330 |
|
|
331 |
/** |
|
332 |
* Returns the LayoutContext. |
|
333 |
* |
|
334 |
* @return LayoutContext. |
|
335 |
*/ |
|
336 |
public LayoutContext getLayoutContext(); |
|
337 |
|
|
338 |
/** |
|
339 |
* Inserts the geometryAdapter. |
|
340 |
* |
|
341 |
* @param adapter |
|
342 |
* GeometryAdapter. |
|
343 |
*/ |
|
344 |
public void setGeometryAdapter(GeometryAdapter adapter); |
|
345 |
|
|
346 |
public JComponent getComponent(); |
|
347 |
|
|
348 |
public int getWidth(); |
|
349 |
|
|
350 |
public int getHeight(); |
|
351 |
|
|
352 |
public void repaint(); |
|
353 |
} |
tags/org.gvsig.app.document.layout2.app-2.0.105/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/FLayoutUtilities.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.app.project.documents.layout; |
|
23 |
|
|
24 |
import java.awt.Dimension; |
|
25 |
import java.awt.Point; |
|
26 |
import java.awt.geom.AffineTransform; |
|
27 |
import java.awt.geom.NoninvertibleTransformException; |
|
28 |
import java.awt.geom.Point2D; |
|
29 |
import java.awt.geom.Rectangle2D; |
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.List; |
|
32 |
|
|
33 |
import org.cresques.cts.IProjection; |
|
34 |
import org.slf4j.Logger; |
|
35 |
import org.slf4j.LoggerFactory; |
|
36 |
|
|
37 |
import org.gvsig.app.project.documents.Document; |
|
38 |
import org.gvsig.app.project.documents.layout.fframes.FFrameView; |
|
39 |
import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
|
40 |
import org.gvsig.app.project.documents.layout.fframes.IFFrameUseFMap; |
|
41 |
import org.gvsig.app.project.documents.view.ViewDocument; |
|
42 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
43 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
44 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
45 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
46 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
47 |
|
|
48 |
/** |
|
49 |
* Clase que recoge m?todos est?ticos sobre el Layout. |
|
50 |
* |
|
51 |
* @author Vicente Caballero Navarro |
|
52 |
*/ |
|
53 |
public class FLayoutUtilities { |
|
54 |
|
|
55 |
private static Logger logger = LoggerFactory.getLogger( |
|
56 |
FLayoutUtilities.class); |
|
57 |
|
|
58 |
/** |
|
59 |
* Devuelve true si las dos ArrayList que se le pasan como parametro son |
|
60 |
* iguales. |
|
61 |
* |
|
62 |
* @param n |
|
63 |
* lista anterior |
|
64 |
* @param l |
|
65 |
* lista actual |
|
66 |
* |
|
67 |
* @return true si los ArrayList son iguales. |
|
68 |
*/ |
|
69 |
public static boolean isEqualList(ArrayList n, ArrayList l) { |
|
70 |
if (n.size() != l.size()) { |
|
71 |
return false; |
|
72 |
} |
|
73 |
|
|
74 |
for (int i = 0; i < n.size(); i++) { |
|
75 |
if (l.get(i) != n.get(i)) { |
|
76 |
return false; |
|
77 |
} |
|
78 |
} |
|
79 |
|
|
80 |
return true; |
|
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* Pasa una distancia en pixels a unidades del folio. |
|
85 |
* |
|
86 |
* @param d |
|
87 |
* distancia en pixels. |
|
88 |
* @param at |
|
89 |
* Matriz de transformaci?n. |
|
90 |
* |
|
91 |
* @return distancia en unidades de folio. |
|
92 |
*/ |
|
93 |
public static double toSheetDistance(double d, AffineTransform at) { |
|
94 |
double dist = d / at.getScaleX(); // pProv.x; |
|
95 |
|
|
96 |
return dist; |
|
97 |
} |
|
98 |
|
|
99 |
/** |
|
100 |
* Pasa una distancia de coordenadas del folio a pixels. |
|
101 |
* |
|
102 |
* @param d |
|
103 |
* distancia en coordenadas de folio. |
|
104 |
* @param at |
|
105 |
* Matriz de transformaci?n. |
|
106 |
* |
|
107 |
* @return double en pixels. |
|
108 |
*/ |
|
109 |
public static double fromSheetDistance(double d, AffineTransform at) { |
|
110 |
Point2D.Double pSheet1 = new Point2D.Double(0, 0); |
|
111 |
Point2D.Double pSheet2 = new Point2D.Double(1, 0); |
|
112 |
Point2D.Double pScreen1 = new Point2D.Double(); |
|
113 |
Point2D.Double pScreen2 = new Point2D.Double(); |
|
114 |
|
|
115 |
try { |
|
116 |
at.transform(pSheet1, pScreen1); |
|
117 |
at.transform(pSheet2, pScreen2); |
|
118 |
} catch (Exception e) { |
|
119 |
System.err.print(e.getMessage()); |
|
120 |
} |
|
121 |
|
|
122 |
return pScreen1.distance(pScreen2) * d; |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* Pasa un punto en pixels a coordenadas del folio. |
|
127 |
* |
|
128 |
* @param pScreen |
|
129 |
* pixels. |
|
130 |
* @param at |
|
131 |
* Matriz de transformaci?n. |
|
132 |
* |
|
133 |
* @return Point2D en coordenadas de folio. |
|
134 |
*/ |
|
135 |
public static Point2D.Double toSheetPoint(Point2D pScreen, |
|
136 |
AffineTransform at) { |
|
137 |
Point2D.Double pWorld = new Point2D.Double(); |
|
138 |
AffineTransform at1; |
|
139 |
|
|
140 |
try { |
|
141 |
at1 = at.createInverse(); |
|
142 |
at1.transform(pScreen, pWorld); |
|
143 |
} catch (NoninvertibleTransformException e) { |
|
144 |
} |
|
145 |
|
|
146 |
return pWorld; |
|
147 |
} |
|
148 |
|
|
149 |
/** |
|
150 |
* Pasa un ret?ngulo de pixels a coordenadas del folio. |
|
151 |
* |
|
152 |
* @param r |
|
153 |
* rect?ngulo en coordenadas de pixels a coordenadas de folio. |
|
154 |
* @param at |
|
155 |
* Matriz de transformaci?n. |
|
156 |
* |
|
157 |
* @return Rectangle2D en coordenadas de folio. |
|
158 |
*/ |
|
159 |
public static Rectangle2D.Double toSheetRect(Rectangle2D r, |
|
160 |
AffineTransform at) { |
|
161 |
Point2D.Double pSheet = |
|
162 |
toSheetPoint(new Point2D.Double(r.getX(), r.getY()), at); |
|
163 |
Point2D.Double pSheetX = |
|
164 |
toSheetPoint(new Point2D.Double(r.getMaxX(), r.getMinY()), at); |
|
165 |
Point2D.Double pSheetY = |
|
166 |
toSheetPoint(new Point2D.Double(r.getMinX(), r.getMaxY()), at); |
|
167 |
Rectangle2D.Double res = new Rectangle2D.Double(); |
|
168 |
res.setRect(pSheet.getX(), pSheet.getY(), pSheet.distance(pSheetX), |
|
169 |
pSheet.distance(pSheetY)); |
|
170 |
|
|
171 |
return res; |
|
172 |
} |
|
173 |
|
|
174 |
/** |
|
175 |
* Pasa de un punto en coordenadas del folio a pixels. |
|
176 |
* |
|
177 |
* @param pSheet |
|
178 |
* punto en coordenadas de folio. |
|
179 |
* @param at |
|
180 |
* Matriz de transformaci?n. |
|
181 |
* |
|
182 |
* @return Point2D en pixels. |
|
183 |
*/ |
|
184 |
public static Point2D.Double fromSheetPoint(Point2D pSheet, |
|
185 |
AffineTransform at) { |
|
186 |
Point2D.Double pScreen = new Point2D.Double(); |
|
187 |
|
|
188 |
try { |
|
189 |
at.transform(pSheet, pScreen); |
|
190 |
} catch (Exception e) { |
|
191 |
System.err.print(e.getMessage()); |
|
192 |
} |
|
193 |
|
|
194 |
return pScreen; |
|
195 |
} |
|
196 |
|
|
197 |
/** |
|
198 |
* Pasa un rect?ngulo en coordenadas del folio a pixels. |
|
199 |
* |
|
200 |
* @param r |
|
201 |
* rect?ngulo en coordenadas de folio. |
|
202 |
* @param at |
|
203 |
* Matriz de transformaci?n. |
|
204 |
* |
|
205 |
* @return Rectangle2D en pixels. |
|
206 |
*/ |
|
207 |
public static Rectangle2D.Double fromSheetRect(Rectangle2D r, |
|
208 |
AffineTransform at) { |
|
209 |
Point2D.Double pSheet = new Point2D.Double(r.getX(), r.getY()); |
|
210 |
Point2D.Double pSX = new Point2D.Double(r.getMaxX(), r.getMinY()); |
|
211 |
Point2D.Double pSY = new Point2D.Double(r.getMinX(), r.getMaxY()); |
|
212 |
Point2D.Double pScreen = new Point2D.Double(); |
|
213 |
Point2D.Double pScreenX = new Point2D.Double(); |
|
214 |
Point2D.Double pScreenY = new Point2D.Double(); |
|
215 |
|
|
216 |
try { |
|
217 |
at.transform(pSheet, pScreen); |
|
218 |
at.transform(pSX, pScreenX); |
|
219 |
at.transform(pSY, pScreenY); |
|
220 |
} catch (Exception e) { |
|
221 |
System.err.print(e.getMessage()); |
|
222 |
} |
|
223 |
|
|
224 |
Rectangle2D.Double res = new Rectangle2D.Double(); |
|
225 |
res.setRect(pScreen.getX(), pScreen.getY(), pScreen.distance(pScreenX), |
|
226 |
pScreen.distance(pScreenY)); |
|
227 |
|
|
228 |
return res; |
|
229 |
} |
|
230 |
|
|
231 |
/** |
|
232 |
* Obtiene el punto ajustado al grid del layout. |
|
233 |
* |
|
234 |
* @param p |
|
235 |
* Punto a ajustar. |
|
236 |
* @param distX |
|
237 |
* Distancia m?nima en cm de X. |
|
238 |
* @param distY |
|
239 |
* Distancia m?nima en cm de Y. |
|
240 |
* @param at |
|
241 |
* Matriz de transformaci?n. |
|
242 |
*/ |
|
243 |
public static Point getPointGrid(Point p, double distX, double distY, |
|
244 |
AffineTransform at) { |
|
245 |
|
|
246 |
if (distX * at.getScaleX() < 2 && distY * at.getScaleY() < 2) { |
|
247 |
/* |
|
248 |
* In this case, it makes no sense to care about snapping |
|
249 |
* because snapping would mean to move the position by one pixel |
|
250 |
*/ |
|
251 |
return p; |
|
252 |
} |
|
253 |
|
|
254 |
Point2D.Double auxp = |
|
255 |
FLayoutUtilities.fromSheetPoint(new Point2D.Double(0, 0), at); |
|
256 |
|
|
257 |
double gridintx = distX * at.getScaleX(); |
|
258 |
double gridinty = distY * at.getScaleY(); |
|
259 |
|
|
260 |
double seppx = p.x - Math.round(auxp.x); |
|
261 |
double seppy = p.y - Math.round(auxp.y); |
|
262 |
|
|
263 |
long round_int_p_x = Math.round(seppx / gridintx); |
|
264 |
long round_int_p_y = Math.round(seppy / gridinty); |
|
265 |
|
|
266 |
// Rounded |
|
267 |
seppx = round_int_p_x * gridintx; |
|
268 |
seppy = round_int_p_y * gridinty; |
|
269 |
|
|
270 |
return new Point( |
|
271 |
(int) (auxp.x + seppx), |
|
272 |
(int) (auxp.y + seppy)); |
|
273 |
} |
|
274 |
|
|
275 |
/** |
|
276 |
* Cuando se dibuja sobre el graphics todo se tiene que situar en enteros y |
|
277 |
* aqu? lo que se comprueba es que si los valores que contiene el |
|
278 |
* Rectangle2D, que toma como par?metro, supera los valores soportados por |
|
279 |
* un entero. |
|
280 |
* |
|
281 |
* @param r |
|
282 |
* Rectangle2D a comprobar si los valores que contiene no superan |
|
283 |
* a los que puede tener un entero. |
|
284 |
* |
|
285 |
* @return true si no se han superado los l?mites. |
|
286 |
*/ |
|
287 |
public static boolean isPosible(Rectangle2D.Double r) { |
|
288 |
if ((r.getMaxX() > Integer.MAX_VALUE) |
|
289 |
|| (r.getMaxY() > Integer.MAX_VALUE) |
|
290 |
|| (r.getMinX() < Integer.MIN_VALUE) |
|
291 |
|| (r.getMinY() < Integer.MIN_VALUE) |
|
292 |
|| (r.getWidth() > Integer.MAX_VALUE) |
|
293 |
|| (r.getHeight() > Integer.MAX_VALUE)) { |
|
294 |
return false; |
|
295 |
} |
|
296 |
|
|
297 |
return true; |
|
298 |
} |
|
299 |
|
|
300 |
public static List<Document> removeEditing(List<Document> list) { |
|
301 |
|
|
302 |
List<Document> resp = new ArrayList<Document>(); |
|
303 |
|
|
304 |
Document item = null; |
|
305 |
ViewDocument viewdoc = null; |
|
306 |
for (int i=0; i<list.size(); i++) { |
|
307 |
item = list.get(i); |
|
308 |
if (item instanceof ViewDocument) { |
|
309 |
viewdoc = (ViewDocument) item; |
|
310 |
if (!hasEditingLayers(viewdoc)) { |
|
311 |
resp.add(item); |
|
312 |
} |
|
313 |
} |
|
314 |
} |
|
315 |
return resp; |
|
316 |
} |
|
317 |
|
|
318 |
|
|
319 |
public static boolean hasEditingLayers(ViewDocument viewdoc) { |
|
320 |
return hasEditingLayers(viewdoc.getMapContext().getLayers()); |
|
321 |
} |
|
322 |
|
|
323 |
/** |
|
324 |
* Recursively find out if any layer is in editing mode |
|
325 |
* |
|
326 |
* @param lyrs |
|
327 |
* @return |
|
328 |
*/ |
|
329 |
public static boolean hasEditingLayers(FLayers lyrs) { |
|
330 |
|
|
331 |
int len = lyrs.getLayersCount(); |
|
332 |
FLayer lyr = null; |
|
333 |
FLyrVect vlyr = null; |
|
334 |
for (int i=0; i<len; i++) { |
|
335 |
lyr = lyrs.getLayer(i); |
|
336 |
if (lyr instanceof FLyrVect) { |
|
337 |
vlyr = (FLyrVect) lyr; |
|
338 |
if (vlyr.isEditing()) { |
|
339 |
return true; |
|
340 |
} |
|
341 |
} else { |
|
342 |
if (lyr instanceof FLayers) { |
|
343 |
if (hasEditingLayers((FLayers) lyr)) { |
|
344 |
return true; |
|
345 |
} |
|
346 |
} |
|
347 |
} |
|
348 |
} |
|
349 |
return false; |
|
350 |
} |
|
351 |
|
|
352 |
public static Point2D screenCoordinatesToViewportImageCoordinates( |
|
353 |
Point2D screenp, IFFrame frame) { |
|
354 |
|
|
355 |
if (screenp == null || frame == null || !(frame instanceof IFFrameUseFMap)) { |
|
356 |
|
|
357 |
logger.info("Bad parameters in screenCoordinatesToViewportImageCoordinates", |
|
358 |
new Exception("Null values or Frame has no MapContext")); |
|
359 |
return screenp; |
|
360 |
} |
|
361 |
|
|
362 |
Rectangle2D.Double rect = frame.getBoundingBox(null); |
|
363 |
|
|
364 |
double screenRectWidth = rect.width; |
|
365 |
double vpWidth = ((IFFrameUseFMap) frame).getMapContext().getViewPort().getImageWidth(); |
|
366 |
if (screenRectWidth < 1 || vpWidth < 1) { |
|
367 |
logger.info("Bad size in screen/viewport (" |
|
368 |
+ "screenRectWidth = " + screenRectWidth + ", " |
|
369 |
+ "vpWidth = " + vpWidth + ")"); |
|
370 |
return screenp; |
|
371 |
} |
|
372 |
|
|
373 |
/* |
|
374 |
* Get coordinates in the rectangle (remove offset) |
|
375 |
*/ |
|
376 |
Point2D po = new Point2D.Double( |
|
377 |
screenp.getX() - rect.x, screenp.getY() - rect.y); |
|
378 |
|
|
379 |
double ratio = (vpWidth * 1d) / (screenRectWidth * 1d); |
|
380 |
Point2D resp = new Point2D.Double(ratio * po.getX(), ratio * po.getY()); |
|
381 |
return resp; |
|
382 |
} |
|
383 |
|
|
384 |
|
|
385 |
|
|
386 |
} |
tags/org.gvsig.app.document.layout2.app-2.0.105/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/tools/LayoutAddRectangleListenerImpl.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.app.project.documents.layout.tools; |
|
23 |
|
|
24 |
import java.awt.Image; |
|
25 |
import java.awt.event.MouseEvent; |
|
26 |
|
|
27 |
import org.gvsig.andami.PluginServices; |
|
28 |
import org.gvsig.app.project.documents.layout.geometryadapters.GeometryAdapter; |
|
29 |
import org.gvsig.app.project.documents.layout.geometryadapters.RectangleAdapter; |
|
30 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
|
31 |
import org.gvsig.app.project.documents.layout.tools.listener.LayoutPointListener; |
|
32 |
import org.gvsig.fmap.geom.Geometry; |
|
33 |
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent; |
|
34 |
|
|
35 |
/** |
|
36 |
* Implementaci?n de la interfaz LayoutPointListener como herramienta para |
|
37 |
* realizar |
|
38 |
* un rect?ngulo. |
|
39 |
* |
|
40 |
* @author Vicente Caballero Navarro |
|
41 |
*/ |
|
42 |
public class LayoutAddRectangleListenerImpl extends |
|
43 |
AbstractLayoutGraphicListener implements LayoutPointListener { |
|
44 |
|
|
45 |
public static final Image iRectangle = PluginServices.getIconTheme() |
|
46 |
.get("cursor-layout-insert-rectangle").getImage(); |
|
47 |
|
|
48 |
/** |
|
49 |
* Crea un nuevo LayoutAddRectagleListenerImpl. |
|
50 |
* |
|
51 |
* @param l |
|
52 |
* Layout. |
|
53 |
*/ |
|
54 |
public LayoutAddRectangleListenerImpl(LayoutPanel layoutPanel) { |
|
55 |
super(layoutPanel); |
|
56 |
} |
|
57 |
|
|
58 |
/** |
|
59 |
* @see org.gvsig.fmap.mapcontrol.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.PointEvent) |
|
60 |
*/ |
|
61 |
public void point(PointEvent event) { |
|
62 |
if (event.getEvent().getButton() == MouseEvent.BUTTON1) { |
|
63 |
if (event.getEvent().getButton() == MouseEvent.BUTTON1) { |
|
64 |
if (layoutPanel.getLayoutControl().addGeometryAdapterPoint() == 2) { |
|
65 |
endGraphic(); |
|
66 |
} |
|
67 |
} |
|
68 |
} |
|
69 |
} |
|
70 |
|
|
71 |
/** |
|
72 |
* @see org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener#getCursor() |
|
73 |
*/ |
|
74 |
public Image getImageCursor() { |
|
75 |
return iRectangle; |
|
76 |
} |
|
77 |
|
|
78 |
/** |
|
79 |
* @see org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener#cancelDrawing() |
|
80 |
*/ |
|
81 |
public boolean cancelDrawing() { |
|
82 |
System.out.println("cancelDrawing del ZoomOutListenerImpl"); |
|
83 |
return true; |
|
84 |
} |
|
85 |
|
|
86 |
public void pointDoubleClick(PointEvent event) { |
|
87 |
|
|
88 |
} |
|
89 |
|
|
90 |
public GeometryAdapter createGeometryAdapter() { |
|
91 |
return new RectangleAdapter(); |
|
92 |
} |
|
93 |
|
|
94 |
@Override |
|
95 |
public int getFFrameGraphicsType() { |
|
96 |
return Geometry.TYPES.SURFACE; |
|
97 |
} |
|
98 |
} |
tags/org.gvsig.app.document.layout2.app-2.0.105/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/tools/LayoutPanListenerImpl.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.app.project.documents.layout.tools; |
|
23 |
|
|
24 |
import java.awt.Image; |
|
25 |
import java.awt.Point; |
|
26 |
import java.awt.event.MouseEvent; |
|
27 |
import java.awt.geom.Rectangle2D; |
|
28 |
|
|
29 |
import org.gvsig.andami.PluginServices; |
|
30 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
|
31 |
import org.gvsig.app.project.documents.layout.tools.listener.LayoutMoveListener; |
|
32 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
|
33 |
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent; |
|
34 |
|
|
35 |
/** |
|
36 |
* Implementaci�n de la interfaz LayoutPanListener como herramienta para |
|
37 |
* realizar el |
|
38 |
* Pan. |
|
39 |
* |
|
40 |
* @author Vicente Caballero Navarro |
|
41 |
*/ |
|
42 |
public class LayoutPanListenerImpl extends AbstractLayoutToolListener implements |
|
43 |
LayoutMoveListener { |
|
44 |
|
|
45 |
public static final Image iLayoutpan = PluginServices.getIconTheme() |
|
46 |
.get("layout-pan-icon").getImage(); |
|
47 |
|
|
48 |
/** |
|
49 |
* Crea un nuevo RectangleListenerImpl. |
|
50 |
* |
|
51 |
* @param mapControl |
|
52 |
* MapControl. |
|
53 |
*/ |
|
54 |
public LayoutPanListenerImpl(LayoutPanel layoutPanel) { |
|
55 |
super(layoutPanel); |
|
56 |
} |
|
57 |
|
|
58 |
/** |
|
59 |
* @see org.gvsig.fmap.mapcontrol.tools.Listeners.PanListener#move(java.awt.geom.Point2D, |
|
60 |
* java.awt.geom.Point2D) |
|
61 |
*/ |
|
62 |
public void drag(PointEvent event) { |
|
63 |
Point pLast = layoutPanel.getLayoutControl().getLastPoint(); |
|
64 |
Point pAnt = layoutPanel.getLayoutControl().getPointAnt(); |
|
65 |
Point origin = layoutPanel.getLayoutControl().getRectOrigin(); |
|
66 |
Rectangle2D.Double r = layoutPanel.getLayoutControl().getRect(); |
|
67 |
r.x = origin.getX() + pLast.getX() - pAnt.getX(); |
|
68 |
r.y = origin.getY() + pLast.getY() - pAnt.getY(); |
|
69 |
layoutPanel.getLayoutControl().setRect(r); |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* @see org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener#getCursor() |
|
74 |
*/ |
|
75 |
public Image getImageCursor() { |
|
76 |
return iLayoutpan; |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* @see org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener#cancelDrawing() |
|
81 |
*/ |
|
82 |
public boolean cancelDrawing() { |
|
83 |
return true; |
|
84 |
} |
|
85 |
|
|
86 |
public void press(PointEvent event) throws BehaviorException { |
|
87 |
layoutPanel |
|
88 |
.getLayoutControl() |
|
89 |
.getRectOrigin() |
|
90 |
.setLocation(layoutPanel.getLayoutControl().getRect().x, |
|
91 |
layoutPanel.getLayoutControl().getRect().y); |
|
92 |
|
|
93 |
} |
|
94 |
|
|
95 |
public void release(PointEvent event) throws BehaviorException { |
|
96 |
Point p1; |
|
97 |
Point p2; |
|
98 |
|
|
99 |
if (event.getEvent().getButton() == MouseEvent.BUTTON1) { |
|
100 |
p1 = layoutPanel.getLayoutControl().getFirstPoint(); |
|
101 |
p2 = event.getEvent().getPoint(); |
|
102 |
layoutPanel.getLayoutControl().getLayoutZooms().setPan(p1, p2); |
|
103 |
layoutPanel.getLayoutControl().refresh(); |
|
104 |
PluginServices.getMainFrame().enableControls(); |
|
105 |
} |
|
106 |
|
|
107 |
layoutPanel.getLayoutControl().setFirstPoint(); |
|
108 |
layoutPanel.getLayoutControl().setLastPoint(); |
|
109 |
layoutPanel.getLayoutControl().setPointAnt(); |
|
110 |
layoutPanel |
|
111 |
.getLayoutControl() |
|
112 |
.getRectOrigin() |
|
113 |
.setLocation(layoutPanel.getLayoutControl().getRect().x, |
|
114 |
layoutPanel.getLayoutControl().getRect().y); |
|
115 |
|
|
116 |
} |
|
117 |
|
|
118 |
public void move(PointEvent event) throws BehaviorException { |
|
119 |
// TODO Auto-generated method stub |
|
120 |
|
|
121 |
} |
|
122 |
|
|
123 |
public void click(PointEvent event) throws BehaviorException { |
|
124 |
// TODO Auto-generated method stub |
|
125 |
|
|
126 |
} |
|
127 |
|
|
128 |
} |
tags/org.gvsig.app.document.layout2.app-2.0.105/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/tools/listener/LayoutAddRectangleListener.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.app.project.documents.layout.tools.listener; |
|
23 |
|
|
24 |
import java.awt.Image; |
|
25 |
import java.awt.geom.Point2D; |
|
26 |
import java.awt.geom.Rectangle2D; |
|
27 |
|
|
28 |
import org.gvsig.andami.PluginServices; |
|
29 |
import org.gvsig.app.project.documents.layout.fframes.FFrameGraphics; |
|
30 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
|
31 |
import org.gvsig.app.project.documents.layout.tools.AbstractLayoutToolListener; |
|
32 |
import org.gvsig.fmap.geom.Geometry; |
|
33 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
|
34 |
import org.gvsig.fmap.mapcontrol.tools.Events.EnvelopeEvent; |
|
35 |
|
|
36 |
/** |
|
37 |
* Implementaci?n de la interfaz LayoutRectangleListener como herramienta para |
|
38 |
* realizar una inserci?n por rect?ngulo. |
|
39 |
* |
|
40 |
* @author Vicente Caballero Navarro |
|
41 |
*/ |
|
42 |
public class LayoutAddRectangleListener extends AbstractLayoutToolListener |
|
43 |
implements LayoutRectangleListener { |
|
44 |
|
|
45 |
private final Image img = PluginServices.getIconTheme() |
|
46 |
.get("cursor-selection-by-rectangle").getImage(); |
|
47 |
protected static int TOLERANCE = 15; |
|
48 |
|
|
49 |
/** |
|
50 |
* Crea un nuevo LayoutAddRectangleListener. |
|
51 |
* |
|
52 |
* @param l |
|
53 |
* Layout. |
|
54 |
*/ |
|
55 |
public LayoutAddRectangleListener(LayoutPanel layoutPanel) { |
|
56 |
super(layoutPanel); |
|
57 |
} |
|
58 |
|
|
59 |
/** |
|
60 |
* @see org.gvsig.fmap.mapcontrol.tools.Listeners.RectangleListener#rectangle(org.gvsig.fmap.mapcontrol.tools.Events.EnvelopeEvent) |
|
61 |
*/ |
|
62 |
public void rectangle(EnvelopeEvent event) throws BehaviorException { |
|
63 |
FFrameGraphics fframe = |
|
64 |
(FFrameGraphics) layoutManager |
|
65 |
.createFrame(FFrameGraphics.PERSISTENCE_DEFINITION_NAME); |
|
66 |
|
|
67 |
fframe.setGeometryAdapter(layoutPanel.getLayoutControl() |
|
68 |
.getGeometryAdapter()); |
|
69 |
fframe.update(Geometry.TYPES.SURFACE, layoutPanel.getLayoutControl() |
|
70 |
.getAT()); |
|
71 |
fframe.setBoundBox(layoutPanel.getLayoutControl().getGeometryAdapter() |
|
72 |
.getBounds2D()); |
|
73 |
layoutPanel.getLayoutContext().addFFrame(fframe, true, true); |
|
74 |
PluginServices.getMainFrame().enableControls(); |
|
75 |
layoutPanel.getLayoutControl().refresh(); |
|
76 |
} |
|
77 |
|
|
78 |
/** |
|
79 |
* @see org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener#getCursor() |
|
80 |
*/ |
|
81 |
public Image getImageCursor() { |
|
82 |
return img; |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* @see org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener#cancelDrawing() |
|
87 |
*/ |
|
88 |
public boolean cancelDrawing() { |
|
89 |
return false; |
|
90 |
} |
|
91 |
|
|
92 |
protected Rectangle2D getRectangle(int tolerance) { |
|
93 |
Rectangle2D r = new Rectangle2D.Double(); |
|
94 |
if (isCorrectSize(tolerance, layoutPanel.getLayoutControl() |
|
95 |
.getFirstPoint(), layoutPanel.getLayoutControl().getLastPoint())) { |
|
96 |
Point2D fp = layoutPanel.getLayoutControl().getFirstPoint(); |
|
97 |
Point2D lp = layoutPanel.getLayoutControl().getLastPoint(); |
|
98 |
if (fp.getX() < lp.getX()) { |
|
99 |
if (fp.getY() < lp.getY()) { |
|
100 |
r.setRect(fp.getX(), fp.getY(), lp.getX() - fp.getX(), |
|
101 |
lp.getY() - fp.getY()); |
|
102 |
} else { |
|
103 |
r.setRect(fp.getX(), lp.getY(), lp.getX() - fp.getX(), |
|
104 |
fp.getY() - lp.getY()); |
|
105 |
} |
|
106 |
} else { |
|
107 |
if (fp.getY() > lp.getY()) { |
|
108 |
r.setRect(lp.getX(), lp.getY(), fp.getX() - lp.getX(), |
|
109 |
fp.getY() - lp.getY()); |
|
110 |
} else { |
|
111 |
r.setRect(lp.getX(), fp.getY(), lp.getX() - fp.getX(), |
|
112 |
lp.getY() - fp.getY()); |
|
113 |
} |
|
114 |
} |
|
115 |
} else { |
|
116 |
Point2D p1 = layoutPanel.getLayoutControl().getFirstPoint(); |
|
117 |
p1 = |
|
118 |
new Point2D.Double(p1.getX() + tolerance, p1.getY() + tolerance); |
|
119 |
r.setFrameFromDiagonal(layoutPanel.getLayoutControl() |
|
120 |
.getFirstPoint(), p1); |
|
121 |
} |
|
122 |
return r; |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* Devuelve true si el rectangulo formado por los dos puntos que se pasan |
|
127 |
* como par?metro es superior a la tolerancia. |
|
128 |
* |
|
129 |
* @param tolerance |
|
130 |
* Tolerancia |
|
131 |
* @param p1 |
|
132 |
* Punto inicial del rect?ngulo. |
|
133 |
* @param p2 |
|
134 |
* Punto final del rect?ngulo. |
|
135 |
* |
|
136 |
* @return True si el tama?o es correcto. |
|
137 |
*/ |
|
138 |
private boolean isCorrectSize(int tolerance, Point2D p1, Point2D p2) { |
|
139 |
if (Math.abs(p2.getX() - p1.getX()) < tolerance) { |
|
140 |
return false; |
|
141 |
} else |
|
142 |
if (Math.abs(p2.getY() - p1.getY()) < tolerance) { |
|
143 |
return false; |
|
144 |
} |
|
145 |
return true; |
|
146 |
} |
|
147 |
} |
tags/org.gvsig.app.document.layout2.app-2.0.105/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/tools/listener/LayoutToolListener.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.app.project.documents.layout.tools.listener; |
|
23 |
|
|
24 |
import java.awt.Image; |
|
25 |
|
|
26 |
/** |
|
27 |
* Interfaz listener de herramienta. |
|
28 |
* |
|
29 |
* @author Vicente Caballero Navarro |
|
30 |
*/ |
|
31 |
public interface LayoutToolListener { |
|
32 |
|
|
33 |
/** |
|
34 |
* Devuelve la imagen del cursor de la herramienta. |
|
35 |
* |
|
36 |
* @return ImageCursor. |
|
37 |
*/ |
|
38 |
public Image getImageCursor(); |
|
39 |
|
|
40 |
/** |
|
41 |
* Condici?n para que se cancele el dibujado. |
|
42 |
* |
|
43 |
* @return True si se cancela el dibujado. |
|
44 |
*/ |
|
45 |
public boolean cancelDrawing(); |
|
46 |
} |
tags/org.gvsig.app.document.layout2.app-2.0.105/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/tools/listener/LayoutPointSelectionListener.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.app.project.documents.layout.tools.listener; |
|
23 |
|
|
24 |
import java.awt.Image; |
|
25 |
|
|
26 |
import org.gvsig.andami.PluginServices; |
|
27 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
|
28 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
|
29 |
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent; |
|
30 |
|
|
31 |
/** |
|
32 |
* Implementaci?n de la interfaz LayoutPointListener como herramienta para |
|
33 |
* realizar |
|
34 |
* una selecci?n por punto. |
|
35 |
* |
|
36 |
* @author Vicente Caballero Navarro |
|
37 |
*/ |
|
38 |
public class LayoutPointSelectionListener implements LayoutPointListener { |
|
39 |
private final Image img = PluginServices.getIconTheme() |
|
40 |
.get("cursor-selection-simple").getImage(); |
|
41 |
protected LayoutPanel layout; |
|
42 |
|
|
43 |
/** |
|
44 |
* Crea un nuevo AreaListenerImpl. |
|
45 |
* |
|
46 |
* @param mc |
|
47 |
* MapControl. |
|
48 |
*/ |
|
49 |
public LayoutPointSelectionListener(LayoutPanel l) { |
|
50 |
this.layout = l; |
|
51 |
} |
|
52 |
|
|
53 |
/** |
|
54 |
* @see org.gvsig.fmap.mapcontrol.tools.Listeners.PointListener#point(org.gvsig.fmap.mapcontrol.tools.Events.PointEvent) |
|
55 |
*/ |
|
56 |
public void point(PointEvent event) throws BehaviorException { |
|
57 |
|
|
58 |
} |
|
59 |
|
Also available in: Unified diff