root / branches / dal_time_support / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / ViewPort.java @ 35625
History | View | Annotate | Download (59.6 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package org.gvsig.fmap.mapcontext; |
42 |
|
43 |
import java.awt.Color; |
44 |
import java.awt.Dimension; |
45 |
import java.awt.Toolkit; |
46 |
import java.awt.geom.AffineTransform; |
47 |
import java.awt.geom.NoninvertibleTransformException; |
48 |
import java.awt.geom.Point2D; |
49 |
import java.awt.geom.Rectangle2D; |
50 |
import java.util.ArrayList; |
51 |
|
52 |
import org.cresques.cts.GeoCalc; |
53 |
import org.cresques.cts.IProjection; |
54 |
import org.cresques.cts.UTM; |
55 |
import org.slf4j.Logger; |
56 |
import org.slf4j.LoggerFactory; |
57 |
|
58 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
59 |
import org.gvsig.fmap.geom.Geometry; |
60 |
import org.gvsig.fmap.geom.GeometryLocator; |
61 |
import org.gvsig.fmap.geom.GeometryManager; |
62 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
63 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
64 |
import org.gvsig.fmap.geom.primitive.Envelope; |
65 |
import org.gvsig.fmap.geom.primitive.Point; |
66 |
import org.gvsig.fmap.mapcontext.events.ColorEvent; |
67 |
import org.gvsig.fmap.mapcontext.events.ExtentEvent; |
68 |
import org.gvsig.fmap.mapcontext.events.ProjectionEvent; |
69 |
import org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener; |
70 |
import org.gvsig.timesupport.Time; |
71 |
import org.gvsig.tools.ToolsLocator; |
72 |
import org.gvsig.tools.dynobject.DynStruct; |
73 |
import org.gvsig.tools.lang.Cloneable; |
74 |
import org.gvsig.tools.persistence.PersistenceManager; |
75 |
import org.gvsig.tools.persistence.Persistent; |
76 |
import org.gvsig.tools.persistence.PersistentState; |
77 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
78 |
import org.gvsig.tools.util.Callable; |
79 |
|
80 |
/**
|
81 |
* <p>
|
82 |
* <code>ViewPort</code> class represents the logic needed to transform a
|
83 |
* rectangular area of a map to the available area in screen to display it.
|
84 |
* </p>
|
85 |
*
|
86 |
* <p>
|
87 |
* Includes an affine transformation, between the rectangular area selected of
|
88 |
* the external map, in its own <i>map coordinates</i>, to the rectangular area
|
89 |
* available of a view in <i>screen coordinates</i>.
|
90 |
* </p>
|
91 |
*
|
92 |
* <p>
|
93 |
* Elements:
|
94 |
* <ul>
|
95 |
* <li><i>extent</i>: the area selected of the map, in <i>map coordinates</i>.
|
96 |
* <li><i>imageSize</i>: width and height in pixels (<i>screen coordinates</i>)
|
97 |
* of the area available in screen to display the area selected of the map.
|
98 |
* <li><i>adjustedExtent</i>: the area selected must be an scale of
|
99 |
* <i>imageSize</i>.<br>
|
100 |
* This implies adapt the extent, preserving and centering it, and adding around
|
101 |
* the needed area to fill all the image size. That added area will be extracted
|
102 |
* from the original map, wherever exists, and filled with the background color
|
103 |
* wherever not.
|
104 |
* <li><i>scale</i>: the scale between the adjusted extent and the image size.
|
105 |
* <li><i>backColor</i>: the default background color in the view, if there is
|
106 |
* no map.
|
107 |
* <li><i>trans</i>: the affine transformation.
|
108 |
* <li><i>proj</i>: map projection used in this view.
|
109 |
* <li><i>distanceUnits</i>: distance measurement units, of data in screen.
|
110 |
* <li><i>mapUnits</i>: measurement units, of data in map.
|
111 |
* <li><i>extents</i>: an {@link ExtentHistory ExtentHistory} with the last
|
112 |
* previous extents.
|
113 |
* <li><i>offset</i>: position in pixels of the available rectangular area,
|
114 |
* where start drawing the map.
|
115 |
* <li><i>dist1pixel</i>: the distance in <i>world coordinates</i> equivalent to
|
116 |
* 1 pixel in the view with the current extent.
|
117 |
* <li><i>dist3pixel</i>: the distance in <i>world coordinates</i> equivalent to
|
118 |
* 3 pixels in the view with the current extent.
|
119 |
* <li><i>listeners</i>: list with the {@link ViewPortListener ViewPortListener}
|
120 |
* registered.
|
121 |
* </ul>
|
122 |
* </p>
|
123 |
*
|
124 |
* @author Vicente Caballero Navarro
|
125 |
*/
|
126 |
public class ViewPort implements Persistent, Cloneable { |
127 |
|
128 |
private static final String FIELD_DISTANCE_AREA = "distanceArea"; |
129 |
private static final String FIELD_IMAGE_SIZE = "imageSize"; |
130 |
private static final String FIELD_PROJ = "proj"; |
131 |
private static final String FIELD_OFFSET = "offset"; |
132 |
private static final String FIELD_MAP_UNITS = "mapUnits"; |
133 |
private static final String FIELD_EXTENT = "extent"; |
134 |
private static final String FIELD_EXTENTS = "extents"; |
135 |
private static final String FIELD_DISTANCE_UNITS = "distanceUnits"; |
136 |
private static final String FIELD_DIST3PIXEL = "dist3pixel"; |
137 |
private static final String FIELD_DIST1PIXEL = "dist1pixel"; |
138 |
private static final String FIELD_CLIP = "clip"; |
139 |
private static final String FIELD_BACK_COLOR = "backColor"; |
140 |
private static final String FIELD_ADJUSTED_EXTENT = "adjustedExtent"; |
141 |
|
142 |
private static final GeometryManager geomManager = |
143 |
GeometryLocator.getGeometryManager(); |
144 |
private static final Logger logger = |
145 |
LoggerFactory.getLogger(ViewPort.class); |
146 |
|
147 |
/**
|
148 |
* <p>
|
149 |
* Screen resolution in <i>dots-per-inch</i>. Useful to calculate the
|
150 |
* geographic scale of the view.
|
151 |
* </p>
|
152 |
*
|
153 |
* @see Toolkit#getScreenResolution()
|
154 |
* @see #getScale()
|
155 |
*/
|
156 |
private static int dpi = java.awt.Toolkit.getDefaultToolkit() |
157 |
.getScreenResolution(); |
158 |
|
159 |
/**
|
160 |
* <p>
|
161 |
* Area selected by user using some tool.
|
162 |
* </p>
|
163 |
*
|
164 |
* <p>
|
165 |
* When the zoom changes (for instance when using the zoom in or zoom out
|
166 |
* tools, but also zooming to a selected feature or shape) the extent that
|
167 |
* covers that area is the value returned by this method. It is not the
|
168 |
* actual area shown in the view because it does not care about the aspect
|
169 |
* ratio of the available area. However, any part of the real world
|
170 |
* contained in this extent is shown in the view.
|
171 |
* </p>
|
172 |
* <p>
|
173 |
* Probably this is not what you are looking for. If you are looking for the
|
174 |
* complete extent currently shown, you must use
|
175 |
* {@linkplain #getAdjustedExtent()} method which returns the extent that
|
176 |
* contains this one but regarding the current view's aspect ratio.
|
177 |
* </p>
|
178 |
*
|
179 |
* @see #getExtent()
|
180 |
* @see #setEnvelope(Envelope)
|
181 |
*/
|
182 |
protected Rectangle2D extent; |
183 |
|
184 |
protected Time time; |
185 |
|
186 |
/**
|
187 |
* <p>
|
188 |
* Location and dimensions of the extent adjusted to the image size.
|
189 |
* </p>
|
190 |
*
|
191 |
* @see #getAdjustedExtent()
|
192 |
*/
|
193 |
protected Rectangle2D adjustedExtent; |
194 |
|
195 |
/**
|
196 |
* Draw version of the context. It's used for know when de componend has
|
197 |
* changed any visualization property
|
198 |
*
|
199 |
* @see getDrawVersion
|
200 |
* @see updateDrawVersion
|
201 |
*/
|
202 |
private long drawVersion = 0L; |
203 |
|
204 |
/**
|
205 |
* <p>
|
206 |
* History with the last extents of the view.
|
207 |
* </p>
|
208 |
*
|
209 |
* @see #setPreviousExtent()
|
210 |
* @see #getExtents()
|
211 |
*/
|
212 |
protected ExtentHistory extents = new ExtentHistory(); |
213 |
|
214 |
/**
|
215 |
* <p>
|
216 |
* Size in <i>screen coordinates</i> of the rectangle where the image is
|
217 |
* displayed.
|
218 |
* </p>
|
219 |
* <p>
|
220 |
* Used by {@linkplain #calculateAffineTransform()} to calculate:<br>
|
221 |
*
|
222 |
* <ul>
|
223 |
* <li>The new {@link #scale scale} .
|
224 |
* <li>The new {@link #adjustedExtent adjustableExtent} .
|
225 |
* <li>The new {@link #trans trans} .
|
226 |
* <li>The new real world coordinates equivalent to 1 pixel (
|
227 |
* {@link #dist1pixel dist1pixel}) .
|
228 |
* <li>The new real world coordinates equivalent to 3 pixels (
|
229 |
* {@link #dist3pixel dist3pixel}) .
|
230 |
* </ul>
|
231 |
* </p>
|
232 |
*
|
233 |
* @see #getImageSize()
|
234 |
* @see #getImageHeight()
|
235 |
* @see #getImageWidth()
|
236 |
* @see #setImageSize(Dimension)
|
237 |
*/
|
238 |
private Dimension imageSize; |
239 |
|
240 |
/**
|
241 |
* <p>
|
242 |
* the affine transformation between the {@link #extent extent} in <i>map 2D
|
243 |
* coordinates</i> to the image area in the screen, in <i>screen 2D
|
244 |
* coordinates</i> (pixels).
|
245 |
* </p>
|
246 |
*
|
247 |
* @see AffineTransform
|
248 |
*
|
249 |
* @see #getAffineTransform()
|
250 |
* @see #setAffineTransform(AffineTransform)
|
251 |
* @see #calculateAffineTransform()
|
252 |
*/
|
253 |
private AffineTransform trans = new AffineTransform(); |
254 |
|
255 |
/**
|
256 |
* <p>
|
257 |
* Measurement unit used for measuring distances and displaying information.
|
258 |
* </p>
|
259 |
*
|
260 |
* @see #getDistanceUnits()
|
261 |
* @see #setDistanceUnits(int)
|
262 |
*/
|
263 |
private int distanceUnits = 1; |
264 |
/**
|
265 |
* <p>
|
266 |
* Measurement unit used for measuring areas and displaying information.
|
267 |
* </p>
|
268 |
*
|
269 |
* @see #getDistanceArea()
|
270 |
* @see #setDistanceArea(int)
|
271 |
*/
|
272 |
private int distanceArea = 1; |
273 |
/**
|
274 |
* <p>
|
275 |
* Measurement unit used by this view port for the map.
|
276 |
* </p>
|
277 |
*
|
278 |
* @see #getMapUnits()
|
279 |
* @see #setMapUnits(int)
|
280 |
*/
|
281 |
private int mapUnits = 1; |
282 |
|
283 |
/**
|
284 |
* <p>
|
285 |
* Array with the {@link ViewPortListener ViewPortListener}s registered to
|
286 |
* this view port.
|
287 |
* </p>
|
288 |
*
|
289 |
* @see #addViewPortListener(ViewPortListener)
|
290 |
* @see #removeViewPortListener(ViewPortListener)
|
291 |
*/
|
292 |
private ArrayList listeners = new ArrayList(); |
293 |
|
294 |
/**
|
295 |
* <p>
|
296 |
* The offset is the position where start drawing the map.
|
297 |
* </p>
|
298 |
* <p>
|
299 |
* The offset of a <a href="http://www.gvsig.gva.es/">gvSIG</a>'s
|
300 |
* <i>View</i> is always (0, 0) because the drawing area fits with the full
|
301 |
* window area. But in a <a href="http://www.gvsig.gva.es/">gvSIG</a>'s
|
302 |
* <i>Layout</i> it's up to the place where the <code>FFrameView</code> is
|
303 |
* located.
|
304 |
* </p>
|
305 |
*
|
306 |
* @see #getOffset()
|
307 |
* @see #setOffset(Point2D)
|
308 |
*/
|
309 |
private Point2D offset = new Point2D.Double(0, 0); |
310 |
|
311 |
/**
|
312 |
* <p>
|
313 |
* Clipping area.
|
314 |
* </p>
|
315 |
*/
|
316 |
// private Rectangle2D clip;
|
317 |
|
318 |
/**
|
319 |
* <p>
|
320 |
* Background color of this view.
|
321 |
* </p>
|
322 |
*
|
323 |
* @see #getBackColor()
|
324 |
* @see #setBackColor(Color)
|
325 |
*/
|
326 |
private Color backColor = null; // Color.WHITE; |
327 |
|
328 |
/**
|
329 |
* <p>
|
330 |
* Information about the map projection used in this view.
|
331 |
* </p>
|
332 |
*
|
333 |
* @see #getProjection()
|
334 |
* @see #setProjection(IProjection)
|
335 |
*/
|
336 |
private IProjection proj;
|
337 |
|
338 |
/**
|
339 |
* <p>
|
340 |
* Represents the distance in <i>world coordinates</i> equivalent to 1 pixel
|
341 |
* in the view with the current extent.
|
342 |
* </p>
|
343 |
*
|
344 |
* @see #getDist1pixel()
|
345 |
* @see #setDist1pixel(double)
|
346 |
*/
|
347 |
private double dist1pixel; |
348 |
|
349 |
/**
|
350 |
* <p>
|
351 |
* Represents the distance in <i>world coordinates</i> equivalent to 3
|
352 |
* pixels in the view with the current extent.
|
353 |
* </p>
|
354 |
*
|
355 |
* @see #getDist3pixel()
|
356 |
* @see #setDist3pixel(double)
|
357 |
*/
|
358 |
private double dist3pixel; |
359 |
|
360 |
/**
|
361 |
* <p>
|
362 |
* Ratio between the size of <code>imageSize</code> and <code>extent</code>:
|
363 |
* <br>
|
364 |
* <i>
|
365 |
*
|
366 |
* <pre>
|
367 |
* min{(imageSize.getHeight()/extent.getHeight(), imageSize.getWidth()/extent.getWidth())}
|
368 |
* </pre>
|
369 |
*
|
370 |
* </i>
|
371 |
* </p>
|
372 |
*/
|
373 |
private double scale; |
374 |
|
375 |
/**
|
376 |
* <p>
|
377 |
* Clipping area.
|
378 |
* </p>
|
379 |
*
|
380 |
* @see #setClipRect(Rectangle2D)
|
381 |
*/
|
382 |
private Rectangle2D cliprect; |
383 |
|
384 |
/**
|
385 |
* <p>
|
386 |
* Enables or disables the <i>"adjustable extent"</i> mode.
|
387 |
* </p>
|
388 |
*
|
389 |
* <p>
|
390 |
* When calculates the affine transform, if
|
391 |
* <ul>
|
392 |
* <li><i>enabled</i>: the new <code>adjustedExtent</code> will have the (X,
|
393 |
* Y) coordinates of the <code>extent</code> and an area that will be an
|
394 |
* scale of the image size. That area will have different height or width
|
395 |
* (not both) of the extent according the least ratio (height or width) in
|
396 |
*
|
397 |
* <pre>
|
398 |
* image.size/extent.size"
|
399 |
* </pre>.
|
400 |
* <li><i>disabled</i>: the new <code>adjustedExtent</code> will be like
|
401 |
* <code>extent</code>.
|
402 |
* </ul>
|
403 |
* </p>
|
404 |
*
|
405 |
* @see #setAdjustable(boolean)
|
406 |
*/
|
407 |
private boolean adjustableExtent = true; |
408 |
|
409 |
public ViewPort() {
|
410 |
|
411 |
} |
412 |
|
413 |
/**
|
414 |
* <p>
|
415 |
* Creates a new view port with the information of the projection in
|
416 |
* <code>proj</code> argument, and default configuration:
|
417 |
* </p>
|
418 |
* <p>
|
419 |
* <ul>
|
420 |
* <li><i><code>distanceUnits</code></i> = meters
|
421 |
* <li><i><code>mapUnits</code></i> = meters
|
422 |
* <li><i><code>backColor</code></i> = <i>undefined</i>
|
423 |
* <li><i><code>offset</code></i> = <code>new Point2D.Double(0, 0);</code>
|
424 |
* </ul>
|
425 |
* </p>
|
426 |
*
|
427 |
* @param proj
|
428 |
* information of the projection for this view port
|
429 |
*/
|
430 |
public ViewPort(IProjection proj) {
|
431 |
// Por defecto
|
432 |
this.proj = proj;
|
433 |
} |
434 |
|
435 |
/**
|
436 |
* <p>
|
437 |
* Changes the status of the <i>"adjustable extent"</i> option to enabled or
|
438 |
* disabled.
|
439 |
* </p>
|
440 |
*
|
441 |
* <p>
|
442 |
* If view port isn't adjustable, won't bear in mind the aspect ratio of the
|
443 |
* available rectangular area to calculate the affine transform from the
|
444 |
* original map in real coordinates. (Won't scale the image to adapt it to
|
445 |
* the available rectangular area).
|
446 |
* </p>
|
447 |
*
|
448 |
* @param boolean the boolean to be set
|
449 |
*/
|
450 |
public void setAdjustable(boolean adjustable) { |
451 |
if (adjustable == adjustableExtent) {
|
452 |
return;
|
453 |
} |
454 |
adjustableExtent = adjustable; |
455 |
this.updateDrawVersion();
|
456 |
} |
457 |
|
458 |
/**
|
459 |
* <p>
|
460 |
* Appends the specified {@link ViewPortListener ViewPortListener} listener
|
461 |
* if weren't.
|
462 |
* </p>
|
463 |
*
|
464 |
* @param arg0
|
465 |
* the listener to add
|
466 |
*
|
467 |
* @return <code>true</code> if has been added successfully
|
468 |
*
|
469 |
* @see #removeViewPortListener(ViewPortListener)
|
470 |
*/
|
471 |
public boolean addViewPortListener(ViewPortListener arg0) { |
472 |
if (!listeners.contains(arg0)) {
|
473 |
return listeners.add(arg0);
|
474 |
} |
475 |
return false; |
476 |
} |
477 |
|
478 |
/**
|
479 |
* <p>
|
480 |
* Removes the specified {@link ViewPortListener ViewPortListener} listener,
|
481 |
* if existed.
|
482 |
* </p>
|
483 |
*
|
484 |
* @param arg0
|
485 |
* the listener to remove
|
486 |
*
|
487 |
* @return <code>true</code> if the contained the specified listener.
|
488 |
*
|
489 |
* @see #addViewPortListener(ViewPortListener)
|
490 |
*/
|
491 |
public boolean removeViewPortListener(ViewPortListener arg0) { |
492 |
return listeners.remove(arg0);
|
493 |
} |
494 |
|
495 |
/**
|
496 |
* <p>
|
497 |
* Converts and returns the distance <code>d</code>, that is in <i>map
|
498 |
* coordinates</i> to <i>screen coordinates</i> using a <i>delta
|
499 |
* transform</i> with the transformation affine information in the
|
500 |
* {@link #trans #trans} attribute.
|
501 |
* </p>
|
502 |
*
|
503 |
* @param d
|
504 |
* distance in <i>map coordinates</i>
|
505 |
*
|
506 |
* @return distance equivalent in <i>screen coordinates</i>
|
507 |
*
|
508 |
* @see #toMapDistance(int)
|
509 |
* @see AffineTransform#deltaTransform(Point2D, Point2D)S
|
510 |
*/
|
511 |
public int fromMapDistance(double d) { |
512 |
Point2D.Double pWorld = new Point2D.Double(1, 1); |
513 |
Point2D.Double pScreen = new Point2D.Double(); |
514 |
|
515 |
try {
|
516 |
trans.deltaTransform(pWorld, pScreen); |
517 |
} catch (Exception e) { |
518 |
System.err.print(e.getMessage());
|
519 |
} |
520 |
|
521 |
return (int) (d * pScreen.x); |
522 |
} |
523 |
|
524 |
/**
|
525 |
* <p>
|
526 |
* Converts and returns the 2D point <code>(x,y)</code>, that is in <i>map
|
527 |
* coordinates</i> to <i>screen coordinates</i> (pixels) using the affine
|
528 |
* transformation in the {@link #trans #trans} attribute.
|
529 |
* </p>
|
530 |
*
|
531 |
* @param x
|
532 |
* the <code>x</code> <i>map coordinate</i> of a 2D point
|
533 |
* @param y
|
534 |
* the <code>y</code> <i>map coordinate</i> of a 2D point
|
535 |
*
|
536 |
* @return 2D point equivalent in <i>screen coordinates</i> (pixels)
|
537 |
*
|
538 |
* @see #fromMapPoint(Point2D)
|
539 |
* @see AffineTransform#transform(Point2D, Point2D)
|
540 |
*/
|
541 |
public Point2D fromMapPoint(double x, double y) { |
542 |
Point2D.Double pWorld = new Point2D.Double(x, y); |
543 |
Point2D.Double pScreen = new Point2D.Double(); |
544 |
|
545 |
try {
|
546 |
trans.transform(pWorld, pScreen); |
547 |
} catch (Exception e) { |
548 |
System.err.print(e.getMessage());
|
549 |
} |
550 |
|
551 |
return pScreen;
|
552 |
} |
553 |
|
554 |
/**
|
555 |
* <p>
|
556 |
* Converts and returns the 2D point argument, that is in <i>map
|
557 |
* coordinates</i> to <i>screen coordinates</i> (pixels) using the affine
|
558 |
* transformation in the {@link #trans #trans} attribute.
|
559 |
* </p>
|
560 |
*
|
561 |
* @param point
|
562 |
* the 2D point in <i>map coordinates</i>
|
563 |
*
|
564 |
* @return 2D point equivalent in <i>screen coordinates</i> (pixels)
|
565 |
*
|
566 |
* @see #toMapPoint(Point2D)
|
567 |
* @see #fromMapPoint(double, double)
|
568 |
*/
|
569 |
public Point2D fromMapPoint(Point2D point) { |
570 |
return fromMapPoint(point.getX(), point.getY());
|
571 |
} |
572 |
|
573 |
/**
|
574 |
* <p>
|
575 |
* Converts and returns the 2D point <code>(x,y)</code>, that is in
|
576 |
* <i>screen coordinates</i> (pixels) to <i>map coordinates</i> using the
|
577 |
* affine transformation in the {@link #trans #trans} attribute.
|
578 |
* </p>
|
579 |
*
|
580 |
* @param x
|
581 |
* the <code>x</code> <i>screen coordinate</i> of a 2D point
|
582 |
* @param y
|
583 |
* the <code>y</code> <i>screen coordinate</i> of a 2D point
|
584 |
*
|
585 |
* @return 2D point equivalent in <i>map coordinates</i>
|
586 |
*
|
587 |
* @see #toMapPoint(Point2D)
|
588 |
* @see #fromMapPoint(double, double)
|
589 |
* @deprecated use {@link #convertToMapPoint(int, int)}
|
590 |
*/
|
591 |
public Point2D toMapPoint(int x, int y) { |
592 |
Point2D pScreen = new Point2D.Double(x, y); |
593 |
|
594 |
return toMapPoint(pScreen);
|
595 |
} |
596 |
|
597 |
/**
|
598 |
* <p>
|
599 |
* Converts and returns the {@link Rectangle2D Rectangle2D}, that is in
|
600 |
* <i>screen coordinates</i> (pixels) to <i>map coordinates</i> using
|
601 |
* {@linkplain #toMapDistance(int)}, and {@linkplain #toMapPoint(int, int)}.
|
602 |
* </p>
|
603 |
*
|
604 |
* @param r
|
605 |
* the 2D rectangle in <i>screen coordinates</i> (pixels)
|
606 |
* @return 2D rectangle equivalent in <i>map coordinates</i>
|
607 |
*
|
608 |
* @see #fromMapRectangle(Rectangle2D)
|
609 |
* @see #toMapDistance(int)
|
610 |
* @see #toMapPoint(int, int)
|
611 |
*/
|
612 |
public Rectangle2D toMapRectangle(Rectangle2D r) { |
613 |
Rectangle2D rect = new Rectangle2D.Double(); |
614 |
Point2D p1 = toMapPoint((int) r.getX(), (int) r.getY()); |
615 |
Point2D p2 = toMapPoint((int) r.getMaxX(), (int) r.getMaxY()); |
616 |
rect.setFrameFromDiagonal(p1, p2); |
617 |
return rect;
|
618 |
} |
619 |
|
620 |
/**
|
621 |
* <p>
|
622 |
* Converts and returns the distance <code>d</code>, that is in <i>screen
|
623 |
* coordinates</i> to <i>map coordinates</i> using the transformation affine
|
624 |
* information in the {@link #trans #trans} attribute.
|
625 |
* </p>
|
626 |
*
|
627 |
* @param d
|
628 |
* distance in pixels
|
629 |
*
|
630 |
* @return distance equivalent in <i>map coordinates</i>
|
631 |
*
|
632 |
* @see #fromMapDistance(double)
|
633 |
* @see AffineTransform
|
634 |
*/
|
635 |
public double toMapDistance(int d) { |
636 |
double dist = d / trans.getScaleX();
|
637 |
|
638 |
return dist;
|
639 |
} |
640 |
|
641 |
/**
|
642 |
* <p>
|
643 |
* Converts and returns the 2D point argument, that is in <i>screen
|
644 |
* coordinates</i> (pixels) to <i>map coordinates</i> using the inverse
|
645 |
* affine transformation of the {@link #trans #trans} attribute.
|
646 |
* </p>
|
647 |
*
|
648 |
* @param pScreen
|
649 |
* the 2D point in <i>screen coordinates</i> (pixels)
|
650 |
*
|
651 |
* @return 2D point equivalent in <i>map coordinates</i>
|
652 |
*
|
653 |
* @see #toMapPoint(int, int)
|
654 |
* @see AffineTransform#createInverse()
|
655 |
* @see AffineTransform#transform(Point2D, Point2D)
|
656 |
* @deprecated use {@link #convertToMapPoint(Point2D)}
|
657 |
*/
|
658 |
public Point2D toMapPoint(Point2D pScreen) { |
659 |
Point2D.Double pWorld = new Point2D.Double(); |
660 |
AffineTransform at;
|
661 |
|
662 |
try {
|
663 |
at = trans.createInverse(); |
664 |
at.transform(pScreen, pWorld); |
665 |
} catch (NoninvertibleTransformException e) { |
666 |
throw new RuntimeException("Non invertible transform Exception", e); |
667 |
} |
668 |
|
669 |
return pWorld;
|
670 |
} |
671 |
|
672 |
public Point convertToMapPoint(Point2D pScreen) { |
673 |
Point2D p = toMapPoint(pScreen);
|
674 |
try {
|
675 |
return geomManager.createPoint(
|
676 |
p.getX(), |
677 |
p.getY(), |
678 |
Geometry.SUBTYPES.GEOM2D |
679 |
); |
680 |
} catch (CreateGeometryException e) {
|
681 |
// FIXME: Use a most especific exception.
|
682 |
throw new RuntimeException(e); |
683 |
} |
684 |
} |
685 |
|
686 |
public Point convertToMapPoint(int x, int y) { |
687 |
Point2D pScreen = new Point2D.Double(x, y); |
688 |
|
689 |
return convertToMapPoint(pScreen);
|
690 |
} |
691 |
|
692 |
|
693 |
/**
|
694 |
* <p>
|
695 |
* Returns the real distance (in <i>world coordinates</i>) at the graphic
|
696 |
* layers of two 2D points (in <i>map coordinates</i>) of the plane where is
|
697 |
* selected the <i>extent</i>.
|
698 |
* </p>
|
699 |
* <p>
|
700 |
* If the projection of this view is UTM, considers the Earth curvature.
|
701 |
* </p>
|
702 |
*
|
703 |
* @param pt1
|
704 |
* a 2D point in <i>map coordinates</i>
|
705 |
* @param pt2
|
706 |
* another 2D point in <i>map coordinates</i>
|
707 |
*
|
708 |
* @return the distance in meters between the two points 2D
|
709 |
*
|
710 |
* @see GeoCalcImpl#distanceVincenty(Point2D, Point2D)
|
711 |
*/
|
712 |
public double distanceWorld(Point2D pt1, Point2D pt2) { |
713 |
double dist = -1; |
714 |
dist = pt1.distance(pt2); |
715 |
|
716 |
if ((proj != null) && !(proj instanceof UTM)) { |
717 |
dist = |
718 |
new GeoCalc(proj).distanceVincenty(proj.toGeo(pt1),
|
719 |
proj.toGeo(pt2)); |
720 |
return dist;
|
721 |
} |
722 |
return (dist * MapContext.getDistanceTrans2Meter()[getMapUnits()]);
|
723 |
} |
724 |
|
725 |
/**
|
726 |
* <p>
|
727 |
* Sets as extent and adjusted extent of this view port, the previous.
|
728 |
* Recalculating its parameters.
|
729 |
* </p>
|
730 |
*
|
731 |
* @see #getExtents()
|
732 |
* @see #calculateAffineTransform()
|
733 |
* @deprecated use {@link ViewPort#setPreviousEnvelope()}
|
734 |
*/
|
735 |
public void setPreviousExtent() { |
736 |
setPreviousEnvelope(); |
737 |
} |
738 |
|
739 |
/**
|
740 |
* <p>
|
741 |
* Sets as envelope and adjusted envelope of this view port, the previous.
|
742 |
* Recalculating its parameters.
|
743 |
* </p>
|
744 |
*
|
745 |
* @see #getExtents()
|
746 |
* @see #calculateAffineTransform()
|
747 |
*/
|
748 |
public void setPreviousEnvelope() { |
749 |
this.updateDrawVersion();
|
750 |
extent = extents.removePrev(); |
751 |
|
752 |
// Calcula la transformaci?n af?n
|
753 |
calculateAffineTransform(); |
754 |
|
755 |
// Lanzamos los eventos de extent cambiado
|
756 |
callExtentChanged(getAdjustedExtent()); |
757 |
} |
758 |
|
759 |
/**
|
760 |
* <p>
|
761 |
* Gets the area selected by user using some tool.
|
762 |
* </p>
|
763 |
*
|
764 |
* <p>
|
765 |
* When the zoom changes (for instance using the <i>zoom in</i> or <i>zoom
|
766 |
* out</i> tools, but also zooming to a selected feature or shape) the
|
767 |
* extent that covers that area is the value returned by this method. It is
|
768 |
* not the actual area shown because it doesn't care about the aspect ratio
|
769 |
* of the image size of the view. However, any part of the real world
|
770 |
* contained in this extent is shown in the view.
|
771 |
* </p>
|
772 |
*
|
773 |
* <p>
|
774 |
* If you are looking for the complete extent currently shown, you must use
|
775 |
* the {@linkplain #getAdjustedExtent()} method.
|
776 |
* </p>
|
777 |
*
|
778 |
* @return the current extent
|
779 |
*
|
780 |
* @see #setEnvelope(Envelope)
|
781 |
* @see #getAdjustedExtent()
|
782 |
* @see #setPreviousExtent()
|
783 |
* @see #getExtents()
|
784 |
*
|
785 |
* @deprecated use {@link ViewPort#getEnvelope()}
|
786 |
*/
|
787 |
public Rectangle2D getExtent() { |
788 |
return extent;
|
789 |
} |
790 |
|
791 |
/**
|
792 |
* <p>
|
793 |
* Gets the envelope selected by user using some tool.
|
794 |
* </p>
|
795 |
*
|
796 |
* <p>
|
797 |
* When the zoom changes (for instance using the <i>zoom in</i> or <i>zoom
|
798 |
* out</i> tools, but also zooming to a selected feature or shape) the
|
799 |
* envelope that covers that area is the value returned by this method. It
|
800 |
* is not the actual envelope shown because it doesn't care about the aspect
|
801 |
* ratio of the image size of the view. However, any part of the real world
|
802 |
* contained in this envelope is shown in the view.
|
803 |
* </p>
|
804 |
*
|
805 |
* <p>
|
806 |
* If you are looking for the complete extent currently shown, you must use
|
807 |
* the {@linkplain #getAdjustedEnvelope()} method.
|
808 |
* </p>
|
809 |
*
|
810 |
* @return the current envelope
|
811 |
*
|
812 |
* @see #setEnvelope(Envelope)
|
813 |
* @see #getAdjustedEnvelope()
|
814 |
* @see #setPreviousEnvelope()
|
815 |
* @see #getEnvelopes()
|
816 |
*/
|
817 |
public Envelope getEnvelope() {
|
818 |
if (this.extent == null) { |
819 |
return null; |
820 |
} |
821 |
try {
|
822 |
return geomManager.createEnvelope(extent.getMinX(),
|
823 |
extent.getMinY(), |
824 |
extent.getMaxX(), |
825 |
extent.getMaxY(), |
826 |
SUBTYPES.GEOM2D); |
827 |
// This class has to use Envelope instead of Rectangle2D. This catch
|
828 |
// will disappear
|
829 |
} catch (CreateEnvelopeException e) {
|
830 |
logger.error("Error creating the envelope");
|
831 |
} |
832 |
return null; |
833 |
} |
834 |
|
835 |
/**
|
836 |
* <p>
|
837 |
* Changes the <i>extent</i> and <i>adjusted extent</i> of this view port:<br>
|
838 |
* <ul>
|
839 |
* <li>Stores the previous extent.
|
840 |
* <li>Calculates the new extent using <code>r</code>:
|
841 |
*
|
842 |
* <pre>
|
843 |
* extent =
|
844 |
* new Rectangle2D.Double(r.getMinX() - 0.1,
|
845 |
* r.getMinY() - 0.1,
|
846 |
* r.getWidth() + 0.2,
|
847 |
* r.getHeight() + 0.2);
|
848 |
* </pre>
|
849 |
*
|
850 |
* <li>Executes {@linkplain #calculateAffineTransform()}: getting the new
|
851 |
* scale, adjusted extent, affine transformation between map and screen
|
852 |
* coordinates, the real world coordinates equivalent to 1 pixel, and the
|
853 |
* real world coordinates equivalent to 3 pixels.
|
854 |
* <li>Notifies all {@link ViewPortListener ViewPortListener} registered
|
855 |
* that the extent has changed.
|
856 |
* </ul>
|
857 |
* </p>
|
858 |
*
|
859 |
* @param r
|
860 |
* the new extent
|
861 |
*
|
862 |
* @see #getExtent()
|
863 |
* @see #getExtents()
|
864 |
* @see #calculateAffineTransform()
|
865 |
* @see #setPreviousExtent()
|
866 |
*/
|
867 |
public void setEnvelope(Envelope r) { |
868 |
Rectangle2D newExtent = null; |
869 |
// Esto comprueba que el extent no es de anchura o altura = "0"
|
870 |
// y si es as? lo redimensiona.
|
871 |
if (r != null) { |
872 |
if ((r.getMaximum(0) - r.getMinimum(0) == 0) |
873 |
|| (r.getMaximum(1) - r.getMinimum(1) == 0)) { |
874 |
newExtent = |
875 |
new Rectangle2D.Double(r.getMinimum(0) - 0.1, |
876 |
r.getMinimum(1) - 0.1, |
877 |
r.getMaximum(0) - r.getMinimum(0) + 0.2, |
878 |
r.getMaximum(1) - r.getMinimum(1) + 0.2); |
879 |
} else {
|
880 |
newExtent = |
881 |
new Rectangle2D.Double(r.getMinimum(0), |
882 |
r.getMinimum(1),
|
883 |
Math.abs(r.getMaximum(0) - r.getMinimum(0)), |
884 |
Math.abs(r.getMaximum(1) - r.getMinimum(1))); |
885 |
} |
886 |
} |
887 |
|
888 |
if (this.extent != null && this.extent.equals(newExtent)) { |
889 |
return;
|
890 |
} |
891 |
if (extent != null) { |
892 |
extents.put(extent); |
893 |
} |
894 |
this.updateDrawVersion();
|
895 |
this.extent = newExtent;
|
896 |
|
897 |
// Calcula la transformaci?n af?n
|
898 |
calculateAffineTransform(); |
899 |
|
900 |
// Lanzamos los eventos de extent cambiado
|
901 |
callExtentChanged(getAdjustedExtent()); |
902 |
} |
903 |
|
904 |
/**
|
905 |
* <p>
|
906 |
* Changes the <i>extent</i> and <i>adjusted extent</i> of this view port:<br>
|
907 |
* <ul>
|
908 |
* <li>Executes {@linkplain #calculateAffineTransform()}: getting the new
|
909 |
* scale, adjusted extent, affine transformation between map and screen
|
910 |
* coordinates, the real world coordinates equivalent to 1 pixel, and the
|
911 |
* real world coordinates equivalent to 3 pixels.
|
912 |
* <li>Notifies to all {@link ViewPortListener ViewPortListener} registered
|
913 |
* that the extent has changed.
|
914 |
* </ul>
|
915 |
* </p>
|
916 |
*
|
917 |
* @see #setEnvelope(Envelope)
|
918 |
* @see #calculateAffineTransform()
|
919 |
*/
|
920 |
public void refreshExtent() { |
921 |
// this.scale = scale;
|
922 |
|
923 |
// Calcula la transformaci?n af?n
|
924 |
calculateAffineTransform(); |
925 |
|
926 |
// Lanzamos los eventos de extent cambiado
|
927 |
callExtentChanged(getAdjustedExtent()); |
928 |
} |
929 |
|
930 |
/**
|
931 |
* <p>
|
932 |
* Calculates and returns using the current projection of this view port,
|
933 |
* the scale that is the extent in <i>screen coordinates</i> from the image
|
934 |
* in <i>map coordinates</i>.
|
935 |
* </p>
|
936 |
*
|
937 |
* @return the scale <i>extent / image size</i> projected by this view port
|
938 |
*
|
939 |
* @deprecated since 07/09/07, use {@linkplain MapContext#getScaleView()}
|
940 |
*/
|
941 |
public double getScale() { |
942 |
return proj.getScale(extent.getMinX(),
|
943 |
extent.getMaxX(), |
944 |
imageSize.width, |
945 |
dpi); |
946 |
} |
947 |
|
948 |
/**
|
949 |
* <p>
|
950 |
* Affine transformation between <i>map 2D coordinates</i> to <i>screen 2D
|
951 |
* coordinates</i> (pixels), preserving the "straightness" and "parallelism"
|
952 |
* of the lines.
|
953 |
* </p>
|
954 |
*
|
955 |
* @return the affine transformation
|
956 |
*
|
957 |
* @see #setAffineTransform(AffineTransform)
|
958 |
* @see #calculateAffineTransform()
|
959 |
*/
|
960 |
public AffineTransform getAffineTransform() { |
961 |
return trans;
|
962 |
} |
963 |
|
964 |
/**
|
965 |
* <p>
|
966 |
* Returns the size of the image projected.
|
967 |
* </p>
|
968 |
*
|
969 |
* @return the image size
|
970 |
*
|
971 |
* @see #setImageSize(Dimension)
|
972 |
* @see #getImageHeight()
|
973 |
* @see #getImageWidth()
|
974 |
*/
|
975 |
public Dimension getImageSize() { |
976 |
return imageSize;
|
977 |
} |
978 |
|
979 |
/**
|
980 |
* <p>
|
981 |
* Sets the size of the image projected, recalculating the parameters of
|
982 |
* this view port.
|
983 |
* </p>
|
984 |
*
|
985 |
* @param imageSize
|
986 |
* the image size
|
987 |
*
|
988 |
* @see #getImageSize()
|
989 |
* @see #calculateAffineTransform()
|
990 |
*/
|
991 |
public void setImageSize(Dimension imageSize) { |
992 |
|
993 |
if (this.imageSize == null || (!this.imageSize.equals(imageSize))) { |
994 |
this.updateDrawVersion();
|
995 |
this.imageSize = imageSize;
|
996 |
calculateAffineTransform(); |
997 |
} |
998 |
} |
999 |
|
1000 |
/**
|
1001 |
* <p>
|
1002 |
* Notifies to all view port listeners registered, that the adjusted extent
|
1003 |
* of this view port has changed.
|
1004 |
* </p>
|
1005 |
*
|
1006 |
* @param newRect
|
1007 |
* the new adjusted extend
|
1008 |
*
|
1009 |
* @see #refreshExtent()
|
1010 |
* @see #setEnvelope(Envelope)
|
1011 |
* @see #setPreviousExtent()
|
1012 |
* @see ExtentEvent
|
1013 |
* @see ViewPortListener
|
1014 |
*/
|
1015 |
protected void callExtentChanged(Envelope newRect) { |
1016 |
ExtentEvent ev = ExtentEvent.createExtentEvent(newRect); |
1017 |
|
1018 |
for (int i = 0; i < listeners.size(); i++) { |
1019 |
ViewPortListener listener = (ViewPortListener) listeners.get(i); |
1020 |
listener.extentChanged(ev); |
1021 |
} |
1022 |
} |
1023 |
|
1024 |
/**
|
1025 |
* <p>
|
1026 |
* Notifies to all view port listeners registered, that the background color
|
1027 |
* of this view port has changed.
|
1028 |
* </p>
|
1029 |
*
|
1030 |
* @param c
|
1031 |
* the new background color
|
1032 |
*
|
1033 |
* @see #setBackColor(Color)
|
1034 |
* @see ColorEvent
|
1035 |
* @see ViewPortListener
|
1036 |
*/
|
1037 |
private void callColorChanged(Color c) { |
1038 |
ColorEvent ce = ColorEvent.createColorEvent(c); |
1039 |
|
1040 |
for (int i = 0; i < listeners.size(); i++) { |
1041 |
ViewPortListener listener = (ViewPortListener) listeners.get(i); |
1042 |
listener.backColorChanged(ce); |
1043 |
} |
1044 |
} |
1045 |
|
1046 |
/**
|
1047 |
* <p>
|
1048 |
* Notifies to all view port listeners registered, that the projection of
|
1049 |
* this view port has changed.
|
1050 |
* </p>
|
1051 |
*
|
1052 |
* @param projection
|
1053 |
* the new projection
|
1054 |
*
|
1055 |
* @see #setProjection(IProjection)
|
1056 |
* @see ProjectionEvent
|
1057 |
* @see ViewPortListener
|
1058 |
*/
|
1059 |
private void callProjectionChanged(IProjection projection) { |
1060 |
ProjectionEvent ev = ProjectionEvent.createProjectionEvent(projection); |
1061 |
|
1062 |
for (int i = 0; i < listeners.size(); i++) { |
1063 |
ViewPortListener listener = (ViewPortListener) listeners.get(i); |
1064 |
listener.projectionChanged(ev); |
1065 |
} |
1066 |
} |
1067 |
|
1068 |
/**
|
1069 |
* <p>
|
1070 |
* Calculates the affine transformation between the {@link #extent extent}
|
1071 |
* in <i>map 2D coordinates</i> to the image area in the screen, in
|
1072 |
* <i>screen 2D coordinates</i> (pixels).
|
1073 |
* </p>
|
1074 |
*
|
1075 |
* <p>
|
1076 |
* This process recalculates some parameters of this view port:<br>
|
1077 |
*
|
1078 |
* <ul>
|
1079 |
* <li>The new {@link #scale scale} .
|
1080 |
* <li>The new {@link #adjustedExtent adjustedExtent} .
|
1081 |
* <li>The new {@link #trans trans} .
|
1082 |
* <li>The new real world coordinates equivalent to 1 pixel (
|
1083 |
* {@link #dist1pixel dist1pixel}) .
|
1084 |
* <li>The new real world coordinates equivalent to 3 pixels (
|
1085 |
* {@link #dist3pixel dist3pixel}) .
|
1086 |
* </ul>
|
1087 |
* </p>
|
1088 |
*
|
1089 |
* @see #getAffineTransform()
|
1090 |
* @see #setAffineTransform(AffineTransform)
|
1091 |
* @see #refreshExtent()
|
1092 |
* @see #setEnvelope(Envelope)
|
1093 |
* @see #setImageSize(Dimension)
|
1094 |
* @see #setPreviousExtent()
|
1095 |
* @see #createFromXML(XMLEntity)
|
1096 |
* @see AffineTransform
|
1097 |
*/
|
1098 |
private void calculateAffineTransform() { |
1099 |
if ((imageSize == null) || (extent == null) || (imageSize.width <= 0) |
1100 |
|| (imageSize.height <= 0)) {
|
1101 |
return;
|
1102 |
} |
1103 |
|
1104 |
AffineTransform escalado = new AffineTransform(); |
1105 |
AffineTransform translacion = new AffineTransform(); |
1106 |
|
1107 |
double escalaX;
|
1108 |
double escalaY;
|
1109 |
|
1110 |
escalaX = imageSize.width / extent.getWidth(); |
1111 |
escalaY = imageSize.height / extent.getHeight(); |
1112 |
|
1113 |
double xCenter = extent.getCenterX();
|
1114 |
double yCenter = extent.getCenterY();
|
1115 |
double newHeight;
|
1116 |
double newWidth;
|
1117 |
|
1118 |
adjustedExtent = new Rectangle2D.Double(); |
1119 |
|
1120 |
if (adjustableExtent) {
|
1121 |
if (escalaX < escalaY) {
|
1122 |
scale = escalaX; |
1123 |
newHeight = imageSize.height / scale; |
1124 |
adjustedExtent.setRect(xCenter - (extent.getWidth() / 2.0),
|
1125 |
yCenter - (newHeight / 2.0),
|
1126 |
extent.getWidth(), |
1127 |
newHeight); |
1128 |
} else {
|
1129 |
scale = escalaY; |
1130 |
newWidth = imageSize.width / scale; |
1131 |
adjustedExtent.setRect(xCenter - (newWidth / 2.0), yCenter
|
1132 |
- (extent.getHeight() / 2.0), newWidth, extent.getHeight());
|
1133 |
} |
1134 |
escalado.setToScale(scale, -scale); |
1135 |
} else { // adjusted is same as extent |
1136 |
scale = escalaX; |
1137 |
adjustedExtent.setFrame(extent); |
1138 |
escalado.setToScale(escalaX, -escalaY); |
1139 |
} |
1140 |
Envelope env = getAdjustedExtent(); |
1141 |
if (env == null) { |
1142 |
return;
|
1143 |
} |
1144 |
translacion.setToTranslation(-env.getMinimum(0), -env.getMinimum(1) |
1145 |
- getAdjustedExtent().getLength(1));
|
1146 |
|
1147 |
AffineTransform offsetTrans = new AffineTransform(); |
1148 |
offsetTrans.setToTranslation(offset.getX(), offset.getY()); |
1149 |
|
1150 |
trans.setToIdentity(); |
1151 |
trans.concatenate(offsetTrans); |
1152 |
trans.concatenate(escalado); |
1153 |
|
1154 |
trans.concatenate(translacion); |
1155 |
|
1156 |
// Calculamos las distancias de 1 pixel y 3 pixel con esa
|
1157 |
// transformaci?n
|
1158 |
// de coordenadas, de forma que est?n precalculadas para cuando las
|
1159 |
// necesitemos
|
1160 |
AffineTransform at;
|
1161 |
|
1162 |
try {
|
1163 |
at = trans.createInverse(); |
1164 |
|
1165 |
Point2D pPixel = new Point2D.Float(1, 1); |
1166 |
|
1167 |
Point2D.Float pProv = new Point2D.Float(); |
1168 |
at.deltaTransform(pPixel, pProv); |
1169 |
|
1170 |
dist1pixel = pProv.x; |
1171 |
dist3pixel = 3 * pProv.x;
|
1172 |
} catch (NoninvertibleTransformException e) { |
1173 |
System.err.println("transformada afin = " + trans.toString()); |
1174 |
System.err.println("extent = " + extent.toString() + " imageSize= " |
1175 |
+ imageSize.toString()); |
1176 |
throw new RuntimeException("Non invertible transform Exception", e); |
1177 |
} |
1178 |
} |
1179 |
|
1180 |
/**
|
1181 |
* <p>
|
1182 |
* Sets the offset.
|
1183 |
* </p>
|
1184 |
* <p>
|
1185 |
* The offset is the position where start drawing the map.
|
1186 |
* </p>
|
1187 |
*
|
1188 |
* @param p
|
1189 |
* 2D point that represents the offset in pixels
|
1190 |
*
|
1191 |
* @see #getOffset()
|
1192 |
*/
|
1193 |
public void setOffset(Point2D p) { |
1194 |
if (!offset.equals(p)) {
|
1195 |
this.updateDrawVersion();
|
1196 |
offset = p; |
1197 |
} |
1198 |
} |
1199 |
|
1200 |
/**
|
1201 |
* <p>
|
1202 |
* Gets the offset.
|
1203 |
* </p>
|
1204 |
* <p>
|
1205 |
* The offset is the position where start drawing the map.
|
1206 |
* </p>
|
1207 |
*
|
1208 |
* @return 2D point that represents the offset in pixels
|
1209 |
*
|
1210 |
* @see #setOffset(Point2D)
|
1211 |
*/
|
1212 |
public Point2D getOffset() { |
1213 |
return offset;
|
1214 |
} |
1215 |
|
1216 |
/**
|
1217 |
* <p>
|
1218 |
* Sets the background color.
|
1219 |
* </p>
|
1220 |
*
|
1221 |
* @param c
|
1222 |
* the new background color
|
1223 |
*
|
1224 |
* @see #getBackColor()
|
1225 |
*/
|
1226 |
public void setBackColor(Color c) { |
1227 |
if (!c.equals(this.backColor)) { |
1228 |
this.updateDrawVersion();
|
1229 |
backColor = c; |
1230 |
callColorChanged(backColor); |
1231 |
} |
1232 |
} |
1233 |
|
1234 |
/**
|
1235 |
* <p>
|
1236 |
* Gets the background color.
|
1237 |
* </p>
|
1238 |
*
|
1239 |
* @return the background color of the view
|
1240 |
*
|
1241 |
* @see #setBackColor(Color)
|
1242 |
*/
|
1243 |
public Color getBackColor() { |
1244 |
return backColor;
|
1245 |
} |
1246 |
|
1247 |
/**
|
1248 |
* <p>
|
1249 |
* Returns the extent currently covered by the view adjusted (scaled) to the
|
1250 |
* image size aspect.
|
1251 |
* </p>
|
1252 |
*
|
1253 |
* @return extent of the view adjusted to the image size aspect
|
1254 |
*
|
1255 |
* @see #setAdjustable(boolean)
|
1256 |
* @deprecated use {@link ViewPort#getAdjustedEnvelope()} instead
|
1257 |
*/
|
1258 |
public Envelope getAdjustedExtent() {
|
1259 |
return getAdjustedEnvelope();
|
1260 |
} |
1261 |
|
1262 |
/**
|
1263 |
* <p>
|
1264 |
* Returns the envelope currently covered by the view adjusted (scaled) to
|
1265 |
* the image size aspect.
|
1266 |
* </p>
|
1267 |
*
|
1268 |
* @return envelope of the view adjusted to the image size aspect
|
1269 |
*
|
1270 |
* @see #setAdjustable(boolean)
|
1271 |
*/
|
1272 |
public Envelope getAdjustedEnvelope() {
|
1273 |
if (cliprect != null) { |
1274 |
Rectangle2D r = adjustedExtent.createIntersection(cliprect);
|
1275 |
try {
|
1276 |
return geomManager.createEnvelope(r.getX(),
|
1277 |
r.getY(), |
1278 |
r.getMaxX(), |
1279 |
r.getMaxY(), |
1280 |
SUBTYPES.GEOM2D); |
1281 |
} catch (CreateEnvelopeException e) {
|
1282 |
e.printStackTrace(); |
1283 |
logger.error("Error adjusting the extent", e);
|
1284 |
} |
1285 |
} |
1286 |
if (adjustedExtent != null) { |
1287 |
try {
|
1288 |
return geomManager.createEnvelope(adjustedExtent.getX(),
|
1289 |
adjustedExtent.getY(), |
1290 |
adjustedExtent.getMaxX(), |
1291 |
adjustedExtent.getMaxY(), |
1292 |
SUBTYPES.GEOM2D); |
1293 |
} catch (CreateEnvelopeException e) {
|
1294 |
e.printStackTrace(); |
1295 |
logger.error("Error adjusting the extent", e);
|
1296 |
} |
1297 |
} |
1298 |
return null; |
1299 |
} |
1300 |
|
1301 |
/**
|
1302 |
* <p>
|
1303 |
* Returns the measurement unit of this view port used for measuring
|
1304 |
* distances and displaying information.
|
1305 |
* </p>
|
1306 |
*
|
1307 |
* @return the measurement unit of this view used for measuring distances
|
1308 |
* and displaying information
|
1309 |
*
|
1310 |
* @see #setDistanceUnits(int)
|
1311 |
*/
|
1312 |
public int getDistanceUnits() { |
1313 |
return distanceUnits;
|
1314 |
} |
1315 |
|
1316 |
/**
|
1317 |
* <p>
|
1318 |
* Returns the measurement unit of this view port used for measuring areas
|
1319 |
* and displaying information.
|
1320 |
* </p>
|
1321 |
*
|
1322 |
* @return the measurement unit of this view used for measuring areas and
|
1323 |
* displaying information
|
1324 |
*
|
1325 |
* @see #setDistanceUnits(int)
|
1326 |
*/
|
1327 |
public int getDistanceArea() { |
1328 |
return distanceArea;
|
1329 |
} |
1330 |
|
1331 |
/**
|
1332 |
* <p>
|
1333 |
* Sets the measurement unit of this view port used for measuring distances
|
1334 |
* and displaying information.
|
1335 |
* </p>
|
1336 |
*
|
1337 |
* @param distanceUnits
|
1338 |
* the measurement unit of this view used for measuring distances
|
1339 |
* and displaying information
|
1340 |
*
|
1341 |
* @see #getDistanceUnits()
|
1342 |
*/
|
1343 |
public void setDistanceUnits(int distanceUnits) { |
1344 |
this.distanceUnits = distanceUnits;
|
1345 |
} |
1346 |
|
1347 |
/**
|
1348 |
* <p>
|
1349 |
* Sets the measurement unit of this view port used for measuring areas and
|
1350 |
* displaying information.
|
1351 |
* </p>
|
1352 |
*
|
1353 |
* @param distanceUnits
|
1354 |
* the measurement unit of this view used for measuring areas and
|
1355 |
* displaying information
|
1356 |
*
|
1357 |
* @see #getDistanceUnits()
|
1358 |
*/
|
1359 |
public void setDistanceArea(int distanceArea) { |
1360 |
this.distanceArea = distanceArea;
|
1361 |
} |
1362 |
|
1363 |
/**
|
1364 |
* <p>
|
1365 |
* Gets the measurement unit used by this view port for the map.
|
1366 |
* </p>
|
1367 |
*
|
1368 |
* @return Returns the current map measure unit
|
1369 |
*
|
1370 |
* @see #setMapUnits(int)
|
1371 |
*/
|
1372 |
public int getMapUnits() { |
1373 |
return mapUnits;
|
1374 |
} |
1375 |
|
1376 |
/**
|
1377 |
* <p>
|
1378 |
* Sets the measurement unit used by this view port for the map.
|
1379 |
* </p>
|
1380 |
*
|
1381 |
* @param mapUnits
|
1382 |
* the new map measure unit
|
1383 |
*
|
1384 |
* @see #getMapUnits()
|
1385 |
*/
|
1386 |
public void setMapUnits(int mapUnits) { |
1387 |
this.mapUnits = mapUnits;
|
1388 |
} |
1389 |
|
1390 |
/**
|
1391 |
* <p>
|
1392 |
* Gets the width in <i>screen coordinates</i> of the rectangle where the
|
1393 |
* image is displayed.
|
1394 |
* </p>
|
1395 |
* <p>
|
1396 |
* Used by {@linkplain #calculateAffineTransform()} to calculate:<br>
|
1397 |
*
|
1398 |
* <ul>
|
1399 |
* <li>The new {@link #scale scale} .
|
1400 |
* <li>The new {@link #adjustedExtent adjustableExtent} .
|
1401 |
* <li>The new {@link #trans trans} .
|
1402 |
* <li>The new real world coordinates equivalent to 1 pixel (
|
1403 |
* {@link #dist1pixel dist1pixel}) .
|
1404 |
* <li>The new real world coordinates equivalent to 3 pixels (
|
1405 |
* {@link #dist3pixel dist3pixel}) .
|
1406 |
* </ul>
|
1407 |
* </p>
|
1408 |
*
|
1409 |
* @see #getImageHeight()
|
1410 |
* @see #getImageSize()
|
1411 |
* @see #setImageSize(Dimension)
|
1412 |
*/
|
1413 |
public int getImageWidth() { |
1414 |
return imageSize.width;
|
1415 |
} |
1416 |
|
1417 |
/**
|
1418 |
* <p>
|
1419 |
* Gets the height in <i>screen coordinates</i> of the rectangle where the
|
1420 |
* image is displayed.
|
1421 |
* </p>
|
1422 |
* <p>
|
1423 |
* Used by {@linkplain #calculateAffineTransform()} to calculate:<br>
|
1424 |
*
|
1425 |
* <ul>
|
1426 |
* <li>The new {@link #scale scale} .
|
1427 |
* <li>The new {@link #adjustedExtent adjustableExtent} .
|
1428 |
* <li>The new {@link #trans trans} .
|
1429 |
* <li>The new real world coordinates equivalent to 1 pixel (
|
1430 |
* {@link #dist1pixel dist1pixel}) .
|
1431 |
* <li>The new real world coordinates equivalent to 3 pixels (
|
1432 |
* {@link #dist3pixel dist3pixel}) .
|
1433 |
* </ul>
|
1434 |
* </p>
|
1435 |
*
|
1436 |
* @see #getImageWidth()
|
1437 |
* @see #getImageSize()
|
1438 |
* @see #setImageSize(Dimension)
|
1439 |
*/
|
1440 |
public int getImageHeight() { |
1441 |
return imageSize.height;
|
1442 |
} |
1443 |
|
1444 |
/**
|
1445 |
* <p>
|
1446 |
* Gets the distance in <i>world coordinates</i> equivalent to 1 pixel in
|
1447 |
* the view with the current extent.
|
1448 |
* </p>
|
1449 |
*
|
1450 |
* @return the distance
|
1451 |
*
|
1452 |
* @see #setDist1pixel(double)
|
1453 |
*/
|
1454 |
public double getDist1pixel() { |
1455 |
return dist1pixel;
|
1456 |
} |
1457 |
|
1458 |
/**
|
1459 |
* <p>
|
1460 |
* Sets the distance in <i>world coordinates</i> equivalent to 1 pixel in
|
1461 |
* the view with the current extent.
|
1462 |
* </p>
|
1463 |
*
|
1464 |
* @param dist1pixel
|
1465 |
* the distance
|
1466 |
*
|
1467 |
* @see #getDist1pixel()
|
1468 |
*/
|
1469 |
public void setDist1pixel(double dist1pixel) { |
1470 |
if (dist1pixel == this.dist1pixel) { |
1471 |
return;
|
1472 |
} |
1473 |
this.updateDrawVersion();
|
1474 |
this.dist1pixel = dist1pixel;
|
1475 |
} |
1476 |
|
1477 |
/**
|
1478 |
* <p>
|
1479 |
* Gets the distance in <i>world coordinates</i> equivalent to 3 pixels in
|
1480 |
* the view with the current extent.
|
1481 |
* </p>
|
1482 |
*
|
1483 |
* @return the distance
|
1484 |
*
|
1485 |
* @see #setDist3pixel(double)
|
1486 |
*/
|
1487 |
public double getDist3pixel() { |
1488 |
return dist3pixel;
|
1489 |
} |
1490 |
|
1491 |
/**
|
1492 |
* <p>
|
1493 |
* Sets the distance in <i>world coordinates</i> equivalent to 3 pixels in
|
1494 |
* the view with the current extent.
|
1495 |
* </p>
|
1496 |
*
|
1497 |
* @param dist3pixel
|
1498 |
* the distance
|
1499 |
*
|
1500 |
* @see #getDist3pixel()
|
1501 |
*/
|
1502 |
public void setDist3pixel(double dist3pixel) { |
1503 |
if (this.dist3pixel == dist3pixel) { |
1504 |
return;
|
1505 |
} |
1506 |
this.updateDrawVersion();
|
1507 |
this.dist3pixel = dist3pixel;
|
1508 |
} |
1509 |
|
1510 |
/**
|
1511 |
* <p>
|
1512 |
* Returns the last previous extents of this view port.
|
1513 |
* </p>
|
1514 |
*
|
1515 |
* @return the last previous extents of this view port
|
1516 |
*
|
1517 |
* @see #setPreviousExtent()
|
1518 |
* @deprecated use {@link ViewPort#getEnvelopes()}
|
1519 |
*/
|
1520 |
public ExtentHistory getExtents() {
|
1521 |
return getEnvelopes();
|
1522 |
} |
1523 |
|
1524 |
/**
|
1525 |
* <p>
|
1526 |
* Returns the last previous extents of this view port.
|
1527 |
* </p>
|
1528 |
*
|
1529 |
* @return the last previous extents of this view port
|
1530 |
*
|
1531 |
* @see #setPreviousExtent()
|
1532 |
*/
|
1533 |
public ExtentHistory getEnvelopes() {
|
1534 |
return extents;
|
1535 |
} |
1536 |
|
1537 |
/**
|
1538 |
* <p>
|
1539 |
* Gets the projection used in this view port.
|
1540 |
* </p>
|
1541 |
*
|
1542 |
* @return projection used in this view port
|
1543 |
*
|
1544 |
* @see #setProjection(IProjection)
|
1545 |
*/
|
1546 |
public IProjection getProjection() {
|
1547 |
return proj;
|
1548 |
} |
1549 |
|
1550 |
/**
|
1551 |
* <p>
|
1552 |
* Sets the projection to this view port.
|
1553 |
* </p>
|
1554 |
*
|
1555 |
* @param proj
|
1556 |
* the new projection
|
1557 |
*
|
1558 |
* @see #getProjection()
|
1559 |
*/
|
1560 |
public void setProjection(IProjection proj) { |
1561 |
if (this.proj == null || !this.proj.getAbrev().equals(proj.getAbrev())) { |
1562 |
this.updateDrawVersion();
|
1563 |
this.proj = proj;
|
1564 |
callProjectionChanged(proj); |
1565 |
} |
1566 |
} |
1567 |
|
1568 |
// -----------------------------------------------------------------------------------------------------------
|
1569 |
// NOTA PARA DESARROLLADORES SOBRE EL M?TODO
|
1570 |
// "public void setAffineTransform(AffineTransform at)"
|
1571 |
// ==============================================================================================
|
1572 |
// Only used for print, should be removed, redefining the {@link
|
1573 |
// RasterAdapter RasterAdapter} interface,
|
1574 |
// allowing it to receive a {@link ViewPortData ViewPortData} .
|
1575 |
// -----------------------------------------------------------------------------------------------------------
|
1576 |
|
1577 |
/**
|
1578 |
* <p>
|
1579 |
* Sets only the affine transform to this view port, without updating
|
1580 |
* dependent attributes.
|
1581 |
* </p>
|
1582 |
* <p>
|
1583 |
* <b><i>This method could be problematic!</i></b>
|
1584 |
* </p>
|
1585 |
*
|
1586 |
* @param at
|
1587 |
* the affine transform to set
|
1588 |
*
|
1589 |
* @see #getAffineTransform()
|
1590 |
* @see #calculateAffineTransform()
|
1591 |
*/
|
1592 |
public void setAffineTransform(AffineTransform at) { |
1593 |
this.trans = at;
|
1594 |
} |
1595 |
|
1596 |
/**
|
1597 |
* <p>
|
1598 |
* Returns an XML entity that represents this view port instance:<br>
|
1599 |
* <ul>
|
1600 |
* <li>Properties:
|
1601 |
* <ul>
|
1602 |
* <li><i>className</i>: name of this class.
|
1603 |
* <li>If defined, the adjusted extent:
|
1604 |
* <ul>
|
1605 |
* <li><i>adjustedExtentX</i>: X coordinate of the adjusted extent.
|
1606 |
* <li><i>adjustedExtentY</i>: Y coordinate of the adjusted extent.
|
1607 |
* <li><i>adjustedExtentW</i>: width of the adjusted extent.
|
1608 |
* <li><i>adjustedExtentH</i>: height of the adjusted extent.
|
1609 |
* </ul>
|
1610 |
* <li>If defined, the background color:
|
1611 |
* <ul>
|
1612 |
* <li><i>backColor</i>: background color.
|
1613 |
* </ul>
|
1614 |
* <li>If defined, the clip:
|
1615 |
* <ul>
|
1616 |
* <li><i>clipX</i>: X coordinate of the clip.
|
1617 |
* <li><i>clipY</i>: Y coordinate of clip.
|
1618 |
* <li><i>clipW</i>: width of the clip.
|
1619 |
* <li><i>clipH</i>: height of the clip.
|
1620 |
* </ul>
|
1621 |
* <li><i>dist1pixel</i>: the distance in world coordinates equivalent to 1
|
1622 |
* pixel in the view.
|
1623 |
* <li><i>dist3pixel</i>: the distance in world coordinates equivalent to 3
|
1624 |
* pixels in the view.
|
1625 |
* <li><i>distanceUnits</i>: the distance measurement unit.
|
1626 |
* <li>If defined, the extent:
|
1627 |
* <ul>
|
1628 |
* <li><i>extentX</i>: X coordinate of the extent.
|
1629 |
* <li><i>extentY</i>: Y coordinate of the extent.
|
1630 |
* <li><i>extentW</i>: width of the extent.
|
1631 |
* <li><i>extentH</i>: height of the extent.
|
1632 |
* </ul>
|
1633 |
* <li><i>mapUnits</i>: the map measurement unit.
|
1634 |
* <li><i>offsetX</i>: X coordinate of the offset.
|
1635 |
* <li><i>offsetY</i>: Y coordinate of the offset.
|
1636 |
* <li>If defined, the projection:
|
1637 |
* <ul>
|
1638 |
* <li>If its defined, the projection:
|
1639 |
* <ul>
|
1640 |
* <li><i>proj</i>: the projection.</li>
|
1641 |
* </ul>
|
1642 |
* </ul>
|
1643 |
* <li><i>scale</i>: ratio between the size of <code>imageSize</code> and
|
1644 |
* <code>extent</code>.
|
1645 |
* </ul>
|
1646 |
* <li>Child branches:
|
1647 |
* <ul>
|
1648 |
* <li>XML entity of the internal {@link ExtentHistory ExtentHistory} .
|
1649 |
* </ul>
|
1650 |
* </ul>
|
1651 |
*
|
1652 |
* @return the XML entity
|
1653 |
*
|
1654 |
* @see #createFromXML(XMLEntity)
|
1655 |
*/
|
1656 |
public void saveToState(PersistentState state) throws PersistenceException { |
1657 |
|
1658 |
state.set(FIELD_ADJUSTED_EXTENT, adjustedExtent); |
1659 |
state.set(FIELD_BACK_COLOR, backColor); |
1660 |
state.set(FIELD_CLIP, cliprect); |
1661 |
state.set(FIELD_DIST1PIXEL, dist1pixel); |
1662 |
state.set(FIELD_DIST3PIXEL, dist3pixel); |
1663 |
state.set(FIELD_DISTANCE_UNITS, distanceUnits); |
1664 |
state.set(FIELD_DISTANCE_AREA, distanceArea); |
1665 |
|
1666 |
state.set(FIELD_EXTENT, extent); |
1667 |
state.set(FIELD_EXTENTS, extents); |
1668 |
|
1669 |
state.set(FIELD_MAP_UNITS, mapUnits); |
1670 |
state.set(FIELD_OFFSET, offset); |
1671 |
|
1672 |
state.set(FIELD_PROJ, proj); |
1673 |
|
1674 |
state.set(FIELD_IMAGE_SIZE, imageSize); |
1675 |
} |
1676 |
|
1677 |
public void loadFromState(PersistentState state) throws PersistenceException { |
1678 |
|
1679 |
adjustedExtent = (Rectangle2D) state.get(FIELD_ADJUSTED_EXTENT);
|
1680 |
backColor = (Color) state.get(FIELD_BACK_COLOR);
|
1681 |
cliprect = (Rectangle2D) state.get(FIELD_CLIP);
|
1682 |
dist1pixel = state.getDouble(FIELD_DIST1PIXEL); |
1683 |
dist3pixel = state.getDouble(FIELD_DIST3PIXEL); |
1684 |
distanceUnits = state.getInt(FIELD_DISTANCE_UNITS); |
1685 |
extents = (ExtentHistory) state.get(FIELD_EXTENTS); |
1686 |
extent = (Rectangle2D) state.get(FIELD_EXTENT);
|
1687 |
mapUnits = state.getInt(FIELD_MAP_UNITS); |
1688 |
offset = (Point2D) state.get(FIELD_OFFSET);
|
1689 |
proj = (IProjection) state.get(FIELD_PROJ); |
1690 |
imageSize = (Dimension) state.get(FIELD_IMAGE_SIZE);
|
1691 |
distanceArea = state.getInt(FIELD_DISTANCE_AREA); |
1692 |
|
1693 |
refreshExtent(); |
1694 |
} |
1695 |
|
1696 |
public static class RegisterPersistence implements Callable { |
1697 |
|
1698 |
public Object call() throws Exception { |
1699 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
1700 |
if( manager.getDefinition("ViewPort")==null ) { |
1701 |
DynStruct definition = |
1702 |
manager.addDefinition(ViewPort.class, |
1703 |
"ViewPort",
|
1704 |
"ViewPort Persistence definition",
|
1705 |
null,
|
1706 |
null);
|
1707 |
|
1708 |
definition.addDynFieldObject(FIELD_ADJUSTED_EXTENT) |
1709 |
.setClassOfValue(Rectangle2D.class)
|
1710 |
.setMandatory(false);
|
1711 |
|
1712 |
definition.addDynFieldObject(FIELD_BACK_COLOR) |
1713 |
.setClassOfValue(Color.class)
|
1714 |
.setMandatory(false);
|
1715 |
|
1716 |
definition.addDynFieldObject(FIELD_CLIP) |
1717 |
.setClassOfValue(Rectangle2D.class)
|
1718 |
.setMandatory(false);
|
1719 |
|
1720 |
definition.addDynFieldDouble(FIELD_DIST1PIXEL).setMandatory(true);
|
1721 |
|
1722 |
definition.addDynFieldDouble(FIELD_DIST3PIXEL).setMandatory(true);
|
1723 |
|
1724 |
definition.addDynFieldInt(FIELD_DISTANCE_UNITS).setMandatory(true);
|
1725 |
|
1726 |
definition.addDynFieldInt(FIELD_DISTANCE_AREA).setMandatory(false);
|
1727 |
|
1728 |
definition.addDynFieldObject(FIELD_EXTENT) |
1729 |
.setClassOfValue(Rectangle2D.class)
|
1730 |
.setMandatory(false);
|
1731 |
|
1732 |
definition.addDynFieldObject(FIELD_EXTENTS) |
1733 |
.setClassOfValue(ExtentHistory.class) |
1734 |
.setMandatory(true);
|
1735 |
|
1736 |
definition.addDynFieldInt(FIELD_MAP_UNITS).setMandatory(true);
|
1737 |
|
1738 |
definition.addDynFieldObject(FIELD_OFFSET) |
1739 |
.setClassOfValue(Point2D.class)
|
1740 |
.setMandatory(false);
|
1741 |
|
1742 |
definition.addDynFieldObject(FIELD_PROJ) |
1743 |
.setClassOfValue(IProjection.class) |
1744 |
.setMandatory(true);
|
1745 |
|
1746 |
definition.addDynFieldObject(FIELD_IMAGE_SIZE) |
1747 |
.setClassOfValue(Dimension.class)
|
1748 |
.setMandatory(false);
|
1749 |
} |
1750 |
return Boolean.TRUE; |
1751 |
} |
1752 |
|
1753 |
} |
1754 |
|
1755 |
/**
|
1756 |
* Clone the view port without clone the listeners nor the extent history.
|
1757 |
*
|
1758 |
* @return the cloned view port
|
1759 |
*/
|
1760 |
public Object clone() throws CloneNotSupportedException { |
1761 |
|
1762 |
ViewPort clonedViewPort = (ViewPort) super.clone();
|
1763 |
clonedViewPort.listeners = new ArrayList(); |
1764 |
clonedViewPort.extents = new ExtentHistory();
|
1765 |
|
1766 |
if (this.adjustedExtent!=null){ |
1767 |
clonedViewPort.adjustedExtent = |
1768 |
(Rectangle2D) this.adjustedExtent.clone(); |
1769 |
} |
1770 |
|
1771 |
if (this.cliprect!=null){ |
1772 |
clonedViewPort.cliprect = (Rectangle2D) this.cliprect.clone(); |
1773 |
} |
1774 |
|
1775 |
if (this.extent!=null) { |
1776 |
clonedViewPort.extent = (Rectangle2D) this.extent.clone(); |
1777 |
} |
1778 |
if (this.imageSize!=null){ |
1779 |
clonedViewPort.imageSize = (Dimension) this.imageSize.clone(); |
1780 |
} |
1781 |
|
1782 |
if (this.offset!=null){ |
1783 |
clonedViewPort.offset = (Point2D) this.offset.clone(); |
1784 |
} |
1785 |
if (proj!=null){ |
1786 |
clonedViewPort.proj = (IProjection) this.proj.clone();
|
1787 |
} |
1788 |
|
1789 |
clonedViewPort.trans = (AffineTransform) this.trans.clone(); |
1790 |
|
1791 |
return clonedViewPort;
|
1792 |
} |
1793 |
|
1794 |
/**
|
1795 |
* <p>
|
1796 |
* Returns a <code>String</code> representation of the main values of this
|
1797 |
* view port: <code>{@linkplain #extent}</code>,
|
1798 |
* <code>{@linkplain #adjustedExtent}</code>,
|
1799 |
* <code>{@linkplain #imageSize}</code>, <code>{@linkplain #scale}</code>,
|
1800 |
* and <code>{@linkplain #trans}</code>.
|
1801 |
* </p>
|
1802 |
*
|
1803 |
* @return a <code>string</code> representation of the main values of this
|
1804 |
* view port
|
1805 |
*/
|
1806 |
public String toString() { |
1807 |
|
1808 |
String str;
|
1809 |
str = |
1810 |
"Datos del viewPort:\nExtent=" + extent + "\nadjustedExtent=" |
1811 |
+ adjustedExtent + "\nimageSize=" + imageSize + "\nescale=" |
1812 |
+ scale + "\ntrans=" + trans;
|
1813 |
|
1814 |
return str;
|
1815 |
} |
1816 |
|
1817 |
/**
|
1818 |
* <p>
|
1819 |
* Sets the position and size of the clipping rectangle.
|
1820 |
* </p>
|
1821 |
*
|
1822 |
* @param rectView
|
1823 |
* the clipping rectangle to set
|
1824 |
*/
|
1825 |
public void setClipRect(Rectangle2D rectView) { |
1826 |
this.updateDrawVersion();
|
1827 |
cliprect = rectView; |
1828 |
} |
1829 |
|
1830 |
/**
|
1831 |
* <p>
|
1832 |
* Converts and returns the {@link Rectangle2D Rectangle2D}, that is in
|
1833 |
* <i>map coordinates</i> to <i>screen coordinates</i> (pixels) using an
|
1834 |
* <i>inverse transform</i> with the transformation affine information in
|
1835 |
* the {@link #trans #trans} attribute.
|
1836 |
* </p>
|
1837 |
*
|
1838 |
* @param r
|
1839 |
* the 2D rectangle in <i>map coordinates</i>
|
1840 |
* @return 2D rectangle equivalent in <i>screen coordinates</i> (pixels)
|
1841 |
*
|
1842 |
* @see #toMapRectangle(Rectangle2D)
|
1843 |
* @see #fromMapDistance(double)
|
1844 |
* @see #fromMapPoint(Point2D)
|
1845 |
*/
|
1846 |
public Rectangle2D fromMapRectangle(Rectangle2D r) { |
1847 |
Rectangle2D rect = new Rectangle2D.Double(); |
1848 |
Point2D p1 = fromMapPoint((int) r.getX(), (int) r.getY()); |
1849 |
Point2D p2 = fromMapPoint((int) r.getMaxX(), (int) r.getMaxY()); |
1850 |
rect.setFrameFromDiagonal(p1, p2); |
1851 |
return rect;
|
1852 |
} |
1853 |
|
1854 |
/**
|
1855 |
* <p>
|
1856 |
* Recalculates the current <code>{@linkplain #extent}</code> using an
|
1857 |
* scale. It's necessary execute {@linkplain #refreshExtent()} after.
|
1858 |
* </p>
|
1859 |
*
|
1860 |
* @param s
|
1861 |
* the scale to set
|
1862 |
*
|
1863 |
* @deprecated since 07/09/07, use
|
1864 |
* {@linkplain MapContext#setScaleView(long)}
|
1865 |
*/
|
1866 |
public void setScale(long s) { |
1867 |
double x = extent.getX();
|
1868 |
double y = extent.getY();
|
1869 |
double escalaX = imageSize.width / extent.getWidth();
|
1870 |
// double w = imageSize.width / s;
|
1871 |
// double h = imageSize.height / s;
|
1872 |
double difw = escalaX / s;
|
1873 |
|
1874 |
double x1 = (-x * difw) - x + extent.getWidth() / 2; |
1875 |
double y1 = (-y * difw) - y + extent.getHeight() / 2; |
1876 |
double w1 = extent.getWidth() * difw;
|
1877 |
double h1 = extent.getHeight() * difw;
|
1878 |
extent.setRect(-x1, -y1, w1, h1); |
1879 |
} |
1880 |
|
1881 |
public long getDrawVersion() { |
1882 |
return this.drawVersion; |
1883 |
} |
1884 |
|
1885 |
protected void updateDrawVersion() { |
1886 |
this.drawVersion++;
|
1887 |
} |
1888 |
|
1889 |
// /**
|
1890 |
// * Obtiene la representaci?n de un color como String
|
1891 |
// *
|
1892 |
// * @param c
|
1893 |
// * Color
|
1894 |
// *
|
1895 |
// * @return String
|
1896 |
// */
|
1897 |
// public static String color2String(Color c) {
|
1898 |
// if (c == null)
|
1899 |
// return null;
|
1900 |
// return c.getRed() + "," + c.getGreen() + "," + c.getBlue() + ","
|
1901 |
// + c.getAlpha();
|
1902 |
// }
|
1903 |
//
|
1904 |
// /**
|
1905 |
// * Obtiene el color de un string generado con color2String
|
1906 |
// *
|
1907 |
// * @param stringColor
|
1908 |
// * string
|
1909 |
// *
|
1910 |
// * @return Color
|
1911 |
// */
|
1912 |
// public static Color string2Color(String stringColor) {
|
1913 |
// if (stringColor == null || stringColor.equals("null"))
|
1914 |
// return null;
|
1915 |
// String[] ints = new String[4];
|
1916 |
//
|
1917 |
// ints = CompatLocator.getStringUtils().split(stringColor, ",");
|
1918 |
//
|
1919 |
// int[] ret = new int[4];
|
1920 |
//
|
1921 |
// for (int i = 0; i < ret.length; i++) {
|
1922 |
// ret[i] = new Integer(ints[i]).intValue();
|
1923 |
// }
|
1924 |
//
|
1925 |
// return new Color(ret[0], ret[1], ret[2], ret[3]);
|
1926 |
// }
|
1927 |
|
1928 |
public Time getTime() { |
1929 |
return time;
|
1930 |
} |
1931 |
|
1932 |
public void setTime(Time time) { |
1933 |
this.time = time;
|
1934 |
} |
1935 |
} |