svn-document-layout / trunk / org.gvsig.app.document.layout.app / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / fframes / FFrameView.java @ 54
History | View | Annotate | Download (39.6 KB)
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.fframes; |
23 |
|
24 |
import java.awt.Color; |
25 |
import java.awt.Dimension; |
26 |
import java.awt.Graphics; |
27 |
import java.awt.Graphics2D; |
28 |
import java.awt.Image; |
29 |
import java.awt.Point; |
30 |
import java.awt.Rectangle; |
31 |
import java.awt.geom.AffineTransform; |
32 |
import java.awt.geom.Point2D; |
33 |
import java.awt.geom.Rectangle2D; |
34 |
import java.awt.image.BufferedImage; |
35 |
|
36 |
import javax.swing.SwingUtilities; |
37 |
|
38 |
import org.cresques.cts.IProjection; |
39 |
import org.slf4j.Logger; |
40 |
import org.slf4j.LoggerFactory; |
41 |
|
42 |
import org.gvsig.andami.PluginServices; |
43 |
import org.gvsig.andami.messages.NotificationManager; |
44 |
import org.gvsig.app.project.Project; |
45 |
import org.gvsig.app.project.documents.layout.DefaultLayoutNotification; |
46 |
import org.gvsig.app.project.documents.layout.FLayoutUtilities; |
47 |
import org.gvsig.app.project.documents.layout.LayoutNotification; |
48 |
import org.gvsig.app.project.documents.view.DefaultViewDocument; |
49 |
import org.gvsig.app.project.documents.view.ViewDocument; |
50 |
import org.gvsig.compat.print.PrintAttributes; |
51 |
import org.gvsig.fmap.dal.exception.ReadException; |
52 |
import org.gvsig.fmap.geom.Geometry; |
53 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
54 |
import org.gvsig.fmap.geom.GeometryLocator; |
55 |
import org.gvsig.fmap.geom.GeometryManager; |
56 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
57 |
import org.gvsig.fmap.geom.primitive.Envelope; |
58 |
import org.gvsig.fmap.mapcontext.MapContext; |
59 |
import org.gvsig.fmap.mapcontext.MapContextException; |
60 |
import org.gvsig.fmap.mapcontext.ViewPort; |
61 |
import org.gvsig.fmap.mapcontext.events.ColorEvent; |
62 |
import org.gvsig.fmap.mapcontext.events.ExtentEvent; |
63 |
import org.gvsig.fmap.mapcontext.events.ProjectionEvent; |
64 |
import org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener; |
65 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent; |
66 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.listeners.LegendListener; |
67 |
import org.gvsig.tools.ToolsLocator; |
68 |
import org.gvsig.tools.dynobject.DynStruct; |
69 |
import org.gvsig.tools.persistence.PersistenceManager; |
70 |
import org.gvsig.tools.persistence.PersistentState; |
71 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
72 |
|
73 |
/**
|
74 |
* FFrame para introducir una vista en el Layout.
|
75 |
*
|
76 |
* @author Vicente Caballero Navarro
|
77 |
*/
|
78 |
public class FFrameView extends FFrame implements ViewPortListener, |
79 |
LegendListener, IFFrameUseProject, IFFrameUseFMap { |
80 |
|
81 |
public static final String PERSISTENCE_DEFINITION_NAME = "FFrameView"; |
82 |
|
83 |
private static final String MODE_FIELD = "mode"; |
84 |
private static final String TYPESCALE_FIELD = "typeScale"; |
85 |
private static final String EXTENSION_FIELD = "extension"; |
86 |
private static final String QUALITY_FIELD = "quality"; |
87 |
private static final String VIEWING_FIELD = "viewing"; |
88 |
private static final String BLINKED_FIELD = "bLinked"; |
89 |
private static final String MAPUNITS_FIELD = "mapUnits"; |
90 |
private static final String SCALE_FIELD = "scale"; |
91 |
private static final String VIEW_FIELD = "view"; |
92 |
private static final String ENVELOPE_FIELD = "envelope"; |
93 |
private static final String SHOWGRID_FIELD = "showGrid"; |
94 |
private static final String GRID_FIELD = "gridview"; |
95 |
private static final String MAPCONTEXT_FIELD = "mapContext"; |
96 |
|
97 |
private static final GeometryManager geomManager = GeometryLocator |
98 |
.getGeometryManager(); |
99 |
private static final Logger logger = LoggerFactory |
100 |
.getLogger(FFrameView.class); |
101 |
public static final int PRESENTATION = 0; |
102 |
public static final int DRAFT = 1; |
103 |
protected int mode; |
104 |
protected int typeScale = AUTOMATICO; |
105 |
protected int extension = 0; |
106 |
protected int quality = PRESENTATION; |
107 |
protected int viewing = 0; |
108 |
protected boolean linked = true; |
109 |
protected ViewDocument viewDocument = null; |
110 |
protected MapContext mapContext = null; |
111 |
protected double mapScale = 0; |
112 |
protected int mapUnits = 1; // Meters. |
113 |
|
114 |
private BufferedImage m_image = null; |
115 |
private AffineTransform at = null; |
116 |
protected Project project = null; |
117 |
private double scaleAnt; |
118 |
private boolean refresh = false; |
119 |
private Point origin; |
120 |
private Point2D p1; |
121 |
private Point2D p2; |
122 |
private IFFrame grid;
|
123 |
private boolean showGrid = false; |
124 |
|
125 |
/**
|
126 |
* Creates a new FFrameView object.
|
127 |
*/
|
128 |
public FFrameView() {
|
129 |
num++; |
130 |
} |
131 |
|
132 |
/**
|
133 |
* Devuelve una descripci?n del FFrameView.
|
134 |
*
|
135 |
* @return Descripci?n.
|
136 |
*/
|
137 |
public String toString() { |
138 |
if (getView() == null) { |
139 |
return "FFrameView " + num + ": " + "Vacio"; |
140 |
} |
141 |
|
142 |
return "FFrameView " + num + ": " + getView().getName(); |
143 |
} |
144 |
|
145 |
/**
|
146 |
* Rellena la escala de la vista que contiene el fframe.
|
147 |
*
|
148 |
* @param d
|
149 |
* escala de la vista.
|
150 |
*/
|
151 |
public void setScale(double d) { |
152 |
mapScale = d; |
153 |
} |
154 |
|
155 |
/**
|
156 |
* Inserta el nuevo extent a la FFrameView.
|
157 |
*
|
158 |
* @param r
|
159 |
* Rect?ngulo a ocupar por el FFrameView.
|
160 |
*/
|
161 |
public void setNewEnvelope(Envelope r) { |
162 |
getMapContext().getViewPort().setEnvelope(r); |
163 |
refresh = true;
|
164 |
mapScale = |
165 |
FLayoutUtilities.getScaleView(getMapContext().getViewPort(), |
166 |
getBoundBox().width, getBoundingBox(null).width
|
167 |
/ getBoundBox().width); |
168 |
} |
169 |
|
170 |
/**
|
171 |
* Devuelve el FMap de la vista o una clonaci?n de este si se utiliza una
|
172 |
* escala fija.
|
173 |
*
|
174 |
* @return FMap.
|
175 |
*/
|
176 |
public MapContext getMapContext() {
|
177 |
return mapContext;
|
178 |
} |
179 |
|
180 |
/**
|
181 |
* Rellena la calidad que se quiere aplicar.
|
182 |
*
|
183 |
* @param q
|
184 |
* entero que representa la calidad a aplicar.
|
185 |
*/
|
186 |
public void setQuality(int q) { |
187 |
quality = q; |
188 |
} |
189 |
|
190 |
/**
|
191 |
* Devuelve un entero que representa la calidad que est? seleccionada.
|
192 |
*
|
193 |
* @return tipo de calidad selccionada.
|
194 |
*/
|
195 |
public int getQuality() { |
196 |
return quality;
|
197 |
} |
198 |
|
199 |
/**
|
200 |
* Devuelve un entero que representa la forma en que se actualiza la vista.
|
201 |
*
|
202 |
* @return forma que se actualiza la vista.
|
203 |
*/
|
204 |
public int getViewing() { |
205 |
return viewing;
|
206 |
} |
207 |
|
208 |
/**
|
209 |
* Rellena la forma de actualizar la vista(cuando activo o siempre). De
|
210 |
* momento esta opci?n esta deshabilitada.
|
211 |
*
|
212 |
* @param v
|
213 |
* entero que representa la forma de actualizar la vista.
|
214 |
*/
|
215 |
public void setViewing(int v) { |
216 |
viewing = v; |
217 |
} |
218 |
|
219 |
/**
|
220 |
* Inserta el ProjectView de donde obtener las propiedades de la vista a
|
221 |
* mostrar.
|
222 |
*
|
223 |
* @param v
|
224 |
* Modelo de la vista.
|
225 |
*/
|
226 |
public void setView(DefaultViewDocument v) { |
227 |
viewDocument = v; |
228 |
ViewPort vp = null;
|
229 |
if (getMapContext() != null) { |
230 |
vp = getMapContext().getViewPort(); |
231 |
}else{
|
232 |
try {
|
233 |
vp = (ViewPort) v.getMapContext().getViewPort().clone(); |
234 |
} catch (CloneNotSupportedException e1) { |
235 |
NotificationManager.addError("Excepci?n :", e1);
|
236 |
} |
237 |
|
238 |
} |
239 |
vp.setImageSize(new Dimension((int) getBoundingBox(null).width, |
240 |
(int) getBoundingBox(null).height)); |
241 |
|
242 |
if (linked){
|
243 |
if (getTypeScale() == AUTOMATICO) {
|
244 |
try {
|
245 |
mapContext = |
246 |
v.getMapContext().createNewFMap( |
247 |
(ViewPort) v.getMapContext().getViewPort().clone()); |
248 |
} catch (CloneNotSupportedException e1) { |
249 |
NotificationManager.addError("Excepci?n :", e1);
|
250 |
} |
251 |
|
252 |
mapContext.getViewPort().setImageSize( |
253 |
new Dimension((int) getBoundingBox(null).width, |
254 |
(int) getBoundingBox(null).height)); |
255 |
v.getMapContext().getViewPort().addViewPortListener(this);
|
256 |
v.getMapContext().addLayerListener(this);
|
257 |
}else{
|
258 |
if (getTypeScale() == CONSTANTE) {
|
259 |
mapContext = v.getMapContext().createNewFMap(vp); |
260 |
vp.setEnvelope(getNewEnvelope(getScale())); |
261 |
v.getMapContext().getViewPort().addViewPortListener(this);
|
262 |
v.getMapContext().addLayerListener(this);
|
263 |
}else{
|
264 |
if (getTypeScale() == MANUAL) {
|
265 |
mapContext = v.getMapContext().createNewFMap(vp); |
266 |
vp.setEnvelope(getNewEnvelope(getScale())); |
267 |
v.getMapContext().getViewPort() |
268 |
.addViewPortListener(this);
|
269 |
v.getMapContext().addLayerListener(this);
|
270 |
} |
271 |
} |
272 |
} |
273 |
}else{
|
274 |
if (!linked) {
|
275 |
|
276 |
if (getTypeScale() == AUTOMATICO) {
|
277 |
mapContext = v.getMapContext().cloneFMap(); // (v.getMapContext().getViewPort().cloneViewPort());
|
278 |
try {
|
279 |
mapContext.setViewPort((ViewPort) v.getMapContext() |
280 |
.getViewPort().clone()); |
281 |
} catch (CloneNotSupportedException e1) { |
282 |
NotificationManager.addError("Excepci?n :", e1);
|
283 |
} |
284 |
mapContext.getViewPort().setImageSize( |
285 |
new Dimension((int) getBoundingBox(null).width, |
286 |
(int) getBoundingBox(null).height)); |
287 |
v.getMapContext().getViewPort().addViewPortListener(this);
|
288 |
}else{
|
289 |
if (getTypeScale() == CONSTANTE) {
|
290 |
mapContext = v.getMapContext().cloneFMap(); |
291 |
vp.setEnvelope(getNewEnvelope(getScale())); |
292 |
mapContext.setViewPort(vp); |
293 |
v.getMapContext().getViewPort() |
294 |
.addViewPortListener(this);
|
295 |
}else{
|
296 |
if (getTypeScale() == MANUAL) {
|
297 |
mapContext = v.getMapContext().cloneFMap(); |
298 |
vp.setEnvelope(getNewEnvelope(getScale())); |
299 |
mapContext.setViewPort(vp); |
300 |
v.getMapContext().getViewPort() |
301 |
.addViewPortListener(this);
|
302 |
} |
303 |
} |
304 |
} |
305 |
} |
306 |
} |
307 |
} |
308 |
|
309 |
/**
|
310 |
* Devuelve el modelo de la vista.
|
311 |
*
|
312 |
* @return Modelo de la vista.
|
313 |
*/
|
314 |
public ViewDocument getView() {
|
315 |
return viewDocument;
|
316 |
} |
317 |
|
318 |
/**
|
319 |
* Devuelve un Rect?ngulo que representa el extent de la vista que se
|
320 |
* requiere a partir de una escala.
|
321 |
*
|
322 |
* @param scale
|
323 |
* Escala a mostrar.
|
324 |
*
|
325 |
* @return Rect?ngulo.
|
326 |
*/
|
327 |
protected Envelope getNewEnvelope(long scale) { |
328 |
double hview = getBoundBox().getHeight();
|
329 |
double wview = getBoundBox().getWidth();
|
330 |
double hextent = (scale * hview) / 100.0; |
331 |
double wextent = (scale * wview) / 100.0; |
332 |
|
333 |
if (mapContext.getViewPort().getEnvelope() == null) { |
334 |
try {
|
335 |
return geomManager.createEnvelope(0, 0, 0, 0, SUBTYPES.GEOM2D); |
336 |
} catch (CreateEnvelopeException e) {
|
337 |
logger.error("Error creating the envelope", e);
|
338 |
return null; |
339 |
} |
340 |
} |
341 |
double newx =
|
342 |
mapContext.getViewPort().getEnvelope().getCenter(Geometry.DIMENSIONS.X) |
343 |
- (wextent / 2.0);
|
344 |
double newy =
|
345 |
mapContext.getViewPort().getEnvelope().getCenter(Geometry.DIMENSIONS.Y) |
346 |
- (hextent / 2.0);
|
347 |
IProjection proj = mapContext.getViewPort().getProjection(); |
348 |
Envelope r = null;
|
349 |
try {
|
350 |
r = |
351 |
geomManager.createEnvelope(newx, newy, newx + wextent, newy |
352 |
+ hextent, SUBTYPES.GEOM2D); |
353 |
} catch (CreateEnvelopeException e) {
|
354 |
logger.error("Error creating the envelope", e);
|
355 |
} |
356 |
if (!proj.isProjected()) {
|
357 |
Rectangle2D auxR =
|
358 |
new Rectangle2D.Double(newx, newy, wextent, hextent); |
359 |
Rectangle2D aux =
|
360 |
mapContext.getViewPort().getProjection() |
361 |
.getExtent(auxR, scale, wview, hview, 1, 100, 2.54); |
362 |
try {
|
363 |
r = |
364 |
geomManager.createEnvelope(aux.getX(), aux.getY(), |
365 |
aux.getMaxX(), aux.getMaxY(), SUBTYPES.GEOM2D); |
366 |
} catch (CreateEnvelopeException e) {
|
367 |
logger.error("Error creating the envelope", e);
|
368 |
} |
369 |
} |
370 |
return r;
|
371 |
} |
372 |
|
373 |
/**
|
374 |
* M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
|
375 |
* la transformada afin que se debe de aplicar y el rect?ngulo que se debe
|
376 |
* de dibujar.
|
377 |
*
|
378 |
* @param g
|
379 |
* Graphics2D
|
380 |
* @param at
|
381 |
* Transformada af?n.
|
382 |
* @param rectangleView
|
383 |
* rect?ngulo sobre el que hacer un clip.
|
384 |
* @param imgBase
|
385 |
* Imagen para acelerar el dibujado.
|
386 |
*/
|
387 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rectangleView, BufferedImage imgBase) { |
388 |
Rectangle2D.Double rectangleLayout = getBoundingBox(at);
|
389 |
Rectangle originalClip = preDraw(g, rectangleLayout);
|
390 |
if (intersects(rectangleView, rectangleLayout)) {
|
391 |
if (getMapContext() == null) { |
392 |
drawEmpty(g); |
393 |
} else {
|
394 |
if (getQuality() == PRESENTATION) {
|
395 |
drawPresentation(g, at, rectangleLayout, rectangleView, imgBase); |
396 |
} else {
|
397 |
drawDraft(g); |
398 |
} |
399 |
} |
400 |
} |
401 |
postDraw(g, rectangleLayout, rectangleView, imgBase, originalClip, at); |
402 |
if (showGrid && grid != null) { |
403 |
grid.draw(g, at, rectangleView, imgBase); |
404 |
} |
405 |
} |
406 |
|
407 |
private void drawPresentation(Graphics2D g, AffineTransform affineTransform, Rectangle2D.Double rectangleLayout, Rectangle2D rectangleView, BufferedImage imgBase){ |
408 |
Point mapOrigin = new Point((int)rectangleView.getMinX(), (int)rectangleView.getMaxY()); |
409 |
|
410 |
ViewPort viewPort = this.getMapContext().getViewPort();
|
411 |
Color theBackColor = viewPort.getBackColor();
|
412 |
|
413 |
//If the image has to be created...
|
414 |
if (!(origin != null |
415 |
&& origin.equals(mapOrigin) |
416 |
&& affineTransform.getScaleX() == scaleAnt |
417 |
&& m_image != null
|
418 |
&& !refresh |
419 |
&& !(rectangleLayout.getWidth() > rectangleView.getWidth() || rectangleLayout.getHeight() > rectangleView.getHeight()))) { |
420 |
|
421 |
double scale1_1 = MapContext.getScreenDPI() / 2.54; |
422 |
/*
|
423 |
* This is the ratio between the size assumed by the
|
424 |
* mapcontext drawer and the true size on screen
|
425 |
*/
|
426 |
double visible_factor = affineTransform.getScaleX() / scale1_1;
|
427 |
int draw_w = (int) (1d * rectangleLayout.width / visible_factor); |
428 |
int draw_h = (int) (1d * rectangleLayout.height / visible_factor); |
429 |
|
430 |
viewPort.setImageSize(new Dimension(draw_w, draw_h)); |
431 |
viewPort.refreshExtent(); |
432 |
|
433 |
/*
|
434 |
viewPort.setOffset(new Point2D.Double(rectangleLayout.x, rectangleLayout.y));
|
435 |
*/
|
436 |
|
437 |
m_image = |
438 |
new BufferedImage( |
439 |
draw_w, //(int) rectangleLayout.getWidth(),
|
440 |
draw_h, //(int) rectangleLayout.getHeight(),
|
441 |
BufferedImage.TYPE_INT_ARGB);
|
442 |
|
443 |
Graphics2D gimg = (Graphics2D) m_image.createGraphics(); |
444 |
|
445 |
/*
|
446 |
gimg.translate(-((int) rectangleLayout.getX()),
|
447 |
-((int) rectangleLayout.getY()));
|
448 |
*/
|
449 |
|
450 |
try {
|
451 |
getMapContext().draw(m_image, gimg, getScale()); |
452 |
gimg.dispose(); |
453 |
} catch (ReadException e) {
|
454 |
LOG.error("Error reading the provider" , e);
|
455 |
} catch (MapContextException mpex) {
|
456 |
LOG.error("Error reading the provider" , e);
|
457 |
} |
458 |
/*
|
459 |
gimg.translate(((int) rectangleLayout.getX()),
|
460 |
((int) rectangleLayout.getY()));
|
461 |
*/
|
462 |
refresh = false;
|
463 |
} |
464 |
|
465 |
//Draw the created image
|
466 |
if (theBackColor != null) { |
467 |
g.setColor(theBackColor); |
468 |
g.fillRect((int) rectangleLayout.x, (int) rectangleLayout.y, |
469 |
viewPort.getImageWidth(), |
470 |
viewPort.getImageHeight()); |
471 |
} |
472 |
|
473 |
m_image = copyForcingImageSize( |
474 |
m_image, |
475 |
(int) rectangleLayout.getWidth(),
|
476 |
(int) rectangleLayout.getHeight());
|
477 |
|
478 |
g.drawImage(m_image, |
479 |
(int) rectangleLayout.getX(),
|
480 |
(int) rectangleLayout.getY(), null); |
481 |
|
482 |
scaleAnt = affineTransform.getScaleX(); |
483 |
origin = mapOrigin; |
484 |
} |
485 |
|
486 |
/**
|
487 |
* @param m_image2
|
488 |
* @param width
|
489 |
* @param height
|
490 |
* @return
|
491 |
*/
|
492 |
private BufferedImage copyForcingImageSize( |
493 |
BufferedImage disp_img, int w, int h) { |
494 |
|
495 |
if (disp_img == null || w < 1 || h < 1) { |
496 |
return new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); |
497 |
} |
498 |
int from_w = disp_img.getWidth(null); |
499 |
int from_h = disp_img.getHeight(null); |
500 |
if (from_w < 1 || from_h < 1) { |
501 |
return new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); |
502 |
} |
503 |
|
504 |
BufferedImage resp =
|
505 |
new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
506 |
Graphics rg = resp.createGraphics();
|
507 |
|
508 |
double rat_w = (1d*w) / (1d*from_w); |
509 |
double rat_h = (1d*h) / (1d*from_h); |
510 |
int offset_w = 0; |
511 |
int offset_h = 0; |
512 |
Image aux = null; |
513 |
|
514 |
if (rat_w <= rat_h) {
|
515 |
// apply resize of width
|
516 |
int target_h = Math.max(1, (int) (from_h * rat_w)); |
517 |
// w, target_h
|
518 |
offset_w = 0;
|
519 |
offset_h = (h - target_h) / 2;
|
520 |
aux = disp_img.getScaledInstance(w, target_h, Image.SCALE_FAST);
|
521 |
rg.drawImage(aux, offset_w, offset_h, null);
|
522 |
|
523 |
} else {
|
524 |
// apply resize from height
|
525 |
int target_w = Math.max(1, (int) (from_w * rat_h)); |
526 |
// target_w, h
|
527 |
offset_w = (w - target_w) / 2;
|
528 |
offset_h = 0;
|
529 |
aux = disp_img.getScaledInstance(target_w, h, Image.SCALE_FAST);
|
530 |
rg.drawImage(aux, offset_w, offset_h, null);
|
531 |
} |
532 |
|
533 |
aux = null;
|
534 |
resp.flush(); |
535 |
rg.dispose(); |
536 |
return resp;
|
537 |
} |
538 |
|
539 |
private Rectangle preDraw(Graphics2D g, Rectangle2D.Double rectangleLayout){ |
540 |
Rectangle originalClip = null; |
541 |
if (g.getClipBounds() != null) { |
542 |
originalClip = (Rectangle) g.getClipBounds().clone();
|
543 |
} |
544 |
if (getRotation() != 0) { |
545 |
g.rotate(Math.toRadians(getRotation()), rectangleLayout.getCenterX(), rectangleLayout.getCenterY()
|
546 |
+ (rectangleLayout.height / 2));
|
547 |
} |
548 |
g.clipRect((int) rectangleLayout.getMinX(), (int) rectangleLayout.getMinY(), |
549 |
(int) rectangleLayout.getWidth(), (int) rectangleLayout.getHeight()); |
550 |
return originalClip;
|
551 |
} |
552 |
|
553 |
private void postDraw(Graphics2D g, Rectangle2D.Double rectangleLayout, Rectangle2D rectangleView, BufferedImage imgBase, |
554 |
Rectangle originalClip, AffineTransform at){ |
555 |
if (getRotation() != 0) { |
556 |
g.rotate(Math.toRadians(-getRotation()), rectangleLayout.getCenterX(), rectangleLayout.getCenterY());
|
557 |
} |
558 |
if (getMapContext() != null) { |
559 |
setATMap(getMapContext().getViewPort().getAffineTransform()); |
560 |
} |
561 |
if (originalClip != null) { |
562 |
g.setClip(originalClip.x, originalClip.y, originalClip.width, originalClip.height); |
563 |
} |
564 |
} |
565 |
|
566 |
private Envelope calculateEnvelope() {
|
567 |
if (p1 == null || p2 == null) { |
568 |
try {
|
569 |
return geomManager.createEnvelope(0, 0, 0, 0, SUBTYPES.GEOM2D); |
570 |
} catch (CreateEnvelopeException e) {
|
571 |
logger.error("Error creating the envelope", e);
|
572 |
} |
573 |
} |
574 |
Envelope r = null;
|
575 |
try {
|
576 |
r = |
577 |
geomManager.createEnvelope(p1.getX(), p1.getY(), p2.getX(), |
578 |
p2.getY(), SUBTYPES.GEOM2D); |
579 |
} catch (CreateEnvelopeException e) {
|
580 |
logger.error("Error creating the envelope", e);
|
581 |
} |
582 |
return r;
|
583 |
} |
584 |
|
585 |
public void print(Graphics2D g, AffineTransform at, Geometry geom, |
586 |
PrintAttributes printAttributes) { |
587 |
Rectangle2D.Double rectangleLayout = getBoundingBox(at);
|
588 |
|
589 |
Rectangle originalClip = preDraw(g, rectangleLayout);
|
590 |
print(g, at, printAttributes); |
591 |
postDraw(g, rectangleLayout, null, null, originalClip, at); |
592 |
if (showGrid && grid != null) { |
593 |
grid.print(g, at, geom, printAttributes); |
594 |
} |
595 |
} |
596 |
|
597 |
private void print(Graphics2D g, AffineTransform at, PrintAttributes printAttributes) { |
598 |
Rectangle2D.Double layoutRectangle = getBoundingBox(at);
|
599 |
|
600 |
ViewPort viewPort = this.getMapContext().getViewPort();
|
601 |
|
602 |
viewPort.setOffset(new Point2D.Double(layoutRectangle.x, layoutRectangle.y)); |
603 |
viewPort.setImageSize(new Dimension((int) layoutRectangle.width, (int) layoutRectangle.height)); |
604 |
|
605 |
//Draw the backgroung color of the map
|
606 |
Color theBackColor = viewPort.getBackColor();
|
607 |
if (theBackColor != null) { |
608 |
g.setColor(theBackColor); |
609 |
g.fillRect((int) layoutRectangle.x, (int) layoutRectangle.y, viewPort |
610 |
.getImageWidth(), viewPort |
611 |
.getImageHeight()); |
612 |
} |
613 |
|
614 |
//Print the map
|
615 |
try {
|
616 |
this.getMapContext().print(g, getScale(), printAttributes);
|
617 |
} catch (ReadException e) {
|
618 |
NotificationManager.addError(e.getMessage(), e); |
619 |
} catch (MapContextException e) {
|
620 |
NotificationManager.addError(e.getMessage(), e); |
621 |
} |
622 |
} |
623 |
|
624 |
/**
|
625 |
* Rellena la unidad de medida en la que est? la vista.
|
626 |
*
|
627 |
* @param i
|
628 |
* entero que representa la unidad de medida de la vista.
|
629 |
*/
|
630 |
public void setMapUnits(int i) { |
631 |
mapUnits = i; |
632 |
} |
633 |
|
634 |
/**
|
635 |
* Obtiene la unidad de medida en la que est? la vista.
|
636 |
*
|
637 |
* @return Unidad de medida.
|
638 |
*/
|
639 |
public int getMapUnits() { |
640 |
return mapUnits;
|
641 |
} |
642 |
|
643 |
/**
|
644 |
* Devuelve la escala seg?n el tipo de escala que se haya seleccionado al
|
645 |
* a?adida la vista.
|
646 |
*
|
647 |
* @return escala.
|
648 |
*/
|
649 |
public long getScale() { |
650 |
/*
|
651 |
* if (m_bLinked){
|
652 |
* return getScaleView1(METROS);
|
653 |
* }
|
654 |
*/
|
655 |
if (getMapContext() == null) { |
656 |
return 0; |
657 |
} |
658 |
if (getTypeScale() == AUTOMATICO) {
|
659 |
return FLayoutUtilities.getScaleView(getMapContext().getViewPort(),
|
660 |
getBoundBox().width, getBoundingBox(null).width);
|
661 |
} else
|
662 |
if (getTypeScale() == CONSTANTE) {
|
663 |
return (long) mapScale; |
664 |
} else
|
665 |
if (getTypeScale() == MANUAL) {
|
666 |
return (long) mapScale; |
667 |
} |
668 |
|
669 |
return (long) mapScale; |
670 |
} |
671 |
|
672 |
/**
|
673 |
* Seleccionar si la vista esta relacionada o no con la original.
|
674 |
*
|
675 |
* @param b
|
676 |
* true si est? ligada y false si no lo est?.
|
677 |
*/
|
678 |
public void setLinked(boolean b) { |
679 |
linked = b; |
680 |
} |
681 |
|
682 |
/**
|
683 |
* Devuelve si est? ligada o no el FFrameView con la vista.
|
684 |
*
|
685 |
* @return True si la vista est? ligada.
|
686 |
*/
|
687 |
public boolean getLinked() { |
688 |
return linked;
|
689 |
} |
690 |
|
691 |
/**
|
692 |
* Devuelve la opci?n seleccionada:Rellenar marco de la vista o recorte a
|
693 |
* la vista.
|
694 |
*
|
695 |
* @return entero que representa la opci?n elegida.
|
696 |
*/
|
697 |
public int getExtension() { |
698 |
return extension;
|
699 |
} |
700 |
|
701 |
/**
|
702 |
* Devuelve el tipo de escala que est? seleccionada AUTOMATICO,CONSTANTE o
|
703 |
* MANUAL.
|
704 |
*
|
705 |
* @return entero que representa el tipo seleccionado.
|
706 |
*/
|
707 |
public int getTypeScale() { |
708 |
return typeScale;
|
709 |
} |
710 |
|
711 |
/**
|
712 |
* Rellenar si se quiere:Rellenar marco de la vista o recorte a la vista.
|
713 |
*
|
714 |
* @param i
|
715 |
* entero que representa la opci?n elegida.
|
716 |
*/
|
717 |
public void setExtension(int i) { |
718 |
extension = i; |
719 |
} |
720 |
|
721 |
/**
|
722 |
* Rellenar el tipo de escala que se desea.
|
723 |
*
|
724 |
* @param i
|
725 |
* entero que representa el tipo de escala.
|
726 |
*/
|
727 |
public void setTypeScale(int i) { |
728 |
typeScale = i; |
729 |
} |
730 |
|
731 |
/**
|
732 |
* Inserta la imagen para repintar el FFrameView.
|
733 |
*
|
734 |
* @param bi
|
735 |
* Imagen para repintar.
|
736 |
*/
|
737 |
public void setBufferedImage(BufferedImage bi) { |
738 |
m_image = bi; |
739 |
} |
740 |
|
741 |
/**
|
742 |
* Devuelve la imagen para repintar.
|
743 |
*
|
744 |
* @return Imagen para repintar.
|
745 |
*/
|
746 |
public BufferedImage getBufferedImage() { |
747 |
return m_image;
|
748 |
} |
749 |
|
750 |
/**
|
751 |
* Devuelve la MAtriz de transformaci?n utilizada por la FFrameView.
|
752 |
*
|
753 |
* @return MAtriz de transformaci?n.
|
754 |
*/
|
755 |
public AffineTransform getATMap() { |
756 |
return at;
|
757 |
} |
758 |
|
759 |
/**
|
760 |
* Inserta la matriz de transformaci?n.
|
761 |
*
|
762 |
* @param transform
|
763 |
* Matriz de transformaci?n.
|
764 |
*/
|
765 |
public void setATMap(AffineTransform transform) { |
766 |
at = transform; |
767 |
} |
768 |
|
769 |
/**
|
770 |
* Inserta el proyecto.
|
771 |
*
|
772 |
* @param p
|
773 |
* Proyecto.
|
774 |
*/
|
775 |
public void setProject(Project p) { |
776 |
project = p; |
777 |
} |
778 |
|
779 |
/**
|
780 |
* @see org.gvsig.app.project.documents.layout.fframes.IFFrame#getNameFFrame()
|
781 |
*/
|
782 |
public String getNameFFrame() { |
783 |
return PluginServices.getText(this, "Vista") + num; |
784 |
} |
785 |
|
786 |
public String getName() { |
787 |
return PERSISTENCE_DEFINITION_NAME;
|
788 |
} |
789 |
|
790 |
/**
|
791 |
* @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(org.gvsig.fmap.mapcontext.events.ExtentEvent)
|
792 |
*/
|
793 |
public void extentChanged(ExtentEvent e) { |
794 |
if (linked){
|
795 |
if (getTypeScale() == AUTOMATICO) {
|
796 |
mapContext.getViewPort().setEnvelope(e.getNewExtent()); |
797 |
observers.notifyObservers(this,
|
798 |
new DefaultLayoutNotification(LayoutNotification.LAYOUT_INVALIDATED));
|
799 |
} else
|
800 |
if (getTypeScale() == MANUAL) {
|
801 |
Envelope oldExtent = mapContext.getViewPort().getEnvelope(); |
802 |
Envelope newExtent = e.getNewExtent(); |
803 |
double xDif = newExtent.getCenter(0) - oldExtent.getCenter(0); |
804 |
double yDif = newExtent.getCenter(1) - oldExtent.getCenter(1); |
805 |
try {
|
806 |
mapContext.getViewPort().setEnvelope( |
807 |
geomManager.createEnvelope(oldExtent.getMinimum(0)
|
808 |
+ xDif, oldExtent.getMinimum(1) + yDif,
|
809 |
oldExtent.getMaximum(0) + xDif,
|
810 |
oldExtent.getMaximum(1) + yDif, SUBTYPES.GEOM2D));
|
811 |
} catch (CreateEnvelopeException e1) {
|
812 |
e1.printStackTrace(); |
813 |
} |
814 |
|
815 |
observers.notifyObservers(this,
|
816 |
new DefaultLayoutNotification(LayoutNotification.LAYOUT_INVALIDATED));
|
817 |
|
818 |
} |
819 |
refresh = true;
|
820 |
} |
821 |
} |
822 |
|
823 |
/**
|
824 |
* @see org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener#backColorChanged(org.gvsig.fmap.mapcontext.events.ColorEvent)
|
825 |
*/
|
826 |
public void backColorChanged(ColorEvent e) { |
827 |
if (getLinked()) {
|
828 |
mapContext.getViewPort().setBackColor(e.getNewColor()); |
829 |
observers.notifyObservers(this,
|
830 |
new DefaultLayoutNotification(LayoutNotification.LAYOUT_INVALIDATED));
|
831 |
} |
832 |
} |
833 |
|
834 |
/**
|
835 |
* @see org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener#projectionChanged(org.gvsig.fmap.mapcontext.events.ProjectionEvent)
|
836 |
*/
|
837 |
public void projectionChanged(ProjectionEvent e) { |
838 |
if (getTypeScale() == AUTOMATICO) {
|
839 |
mapContext.getViewPort().setProjection(e.getNewProjection()); |
840 |
observers.notifyObservers(this,
|
841 |
new DefaultLayoutNotification(LayoutNotification.LAYOUT_INVALIDATED));
|
842 |
} |
843 |
} |
844 |
|
845 |
/**
|
846 |
* DOCUMENT ME!
|
847 |
*
|
848 |
* @param e
|
849 |
* DOCUMENT ME!
|
850 |
*/
|
851 |
public void legendChanged(final LegendChangedEvent e) { |
852 |
if (!SwingUtilities.isEventDispatchThread()) { |
853 |
SwingUtilities.invokeLater(new Runnable() { |
854 |
|
855 |
public void run() { |
856 |
legendChanged(e); |
857 |
} |
858 |
}); |
859 |
return;
|
860 |
} |
861 |
if (getLinked()) {
|
862 |
observers.notifyObservers(this,
|
863 |
new DefaultLayoutNotification(LayoutNotification.LAYOUT_INVALIDATED));
|
864 |
refresh = true;
|
865 |
} |
866 |
} |
867 |
|
868 |
/**
|
869 |
* DOCUMENT ME!
|
870 |
*
|
871 |
* @param arg0
|
872 |
* DOCUMENT ME!
|
873 |
*
|
874 |
* @return DOCUMENT ME!
|
875 |
*/
|
876 |
public boolean compare(Object arg0) { |
877 |
if (!(arg0 instanceof FFrameView)) { |
878 |
return false; |
879 |
} |
880 |
|
881 |
if (!this.getName().equals(((FFrameView) arg0).getName())) { |
882 |
return false; |
883 |
} |
884 |
|
885 |
if (Math.abs(this.getBoundBox().getWidth() |
886 |
- (((FFrameView) arg0).getBoundBox().getWidth())) > 0.05) {
|
887 |
return false; |
888 |
} |
889 |
if (Math.abs(this.getBoundBox().getHeight() |
890 |
- (((FFrameView) arg0).getBoundBox().getHeight())) > 0.05) {
|
891 |
return false; |
892 |
} |
893 |
|
894 |
if (!this.toString().equals(((FFrameView) arg0).toString())) { |
895 |
return false; |
896 |
} |
897 |
|
898 |
if (this.getMapContext() != null |
899 |
&& !this.getMapContext()
|
900 |
.equals(((FFrameView) arg0).getMapContext())) { |
901 |
return false; |
902 |
} |
903 |
|
904 |
if (this.getRotation() != ((FFrameView) arg0).getRotation()) { |
905 |
return false; |
906 |
} |
907 |
return true; |
908 |
} |
909 |
|
910 |
/*
|
911 |
* This was causing issues with the notifications
|
912 |
* because different instances were considered the same
|
913 |
* after cloning a frame (the frame is cloned for example
|
914 |
* when the user changes size of frame)
|
915 |
*
|
916 |
public boolean equals(Object arg0) {
|
917 |
return this.compare(arg0);
|
918 |
}
|
919 |
*/
|
920 |
|
921 |
public void refresh() { |
922 |
if (viewDocument != null |
923 |
&& (getTypeScale() == MANUAL || getTypeScale() == CONSTANTE)) { |
924 |
getMapContext().getViewPort().setEnvelope( |
925 |
getNewEnvelope(getScale())); |
926 |
} |
927 |
refresh = true;
|
928 |
} |
929 |
|
930 |
public void fullExtent() throws ReadException { |
931 |
setNewEnvelope(getMapContext().getFullEnvelope()); |
932 |
} |
933 |
|
934 |
public void setPointsToZoom(Point2D px1, Point2D px2) { |
935 |
p1 = px1; |
936 |
p2 = px2; |
937 |
} |
938 |
|
939 |
public void movePoints(Point2D px1, Point2D px2) { |
940 |
double difX = -px2.getX() + px1.getX();
|
941 |
double difY = -px2.getY() + px1.getY();
|
942 |
if (p1 != null) { |
943 |
p1.setLocation(p1.getX() + difX, p1.getY() + difY); |
944 |
p2.setLocation(p2.getX() + difX, p2.getY() + difY); |
945 |
} |
946 |
} |
947 |
|
948 |
/**
|
949 |
* This method deals with places where this fframeview and the cloned
|
950 |
* fframeview (frame) are registered as listeners. The goal should be
|
951 |
* leaving the cloned instance (frame) as listener in the same way
|
952 |
* that 'this' instance is doing.
|
953 |
*/
|
954 |
protected void cloneActions(FFrameView frame) { |
955 |
if (viewDocument == null || viewDocument.getMapContext() == null) { |
956 |
return;
|
957 |
} |
958 |
|
959 |
frame.setTypeScale(this.getTypeScale());
|
960 |
frame.setLinked(linked); |
961 |
|
962 |
if (linked) {
|
963 |
if (getTypeScale() == AUTOMATICO) {
|
964 |
frame.viewDocument.getMapContext().getViewPort().addViewPortListener(frame); |
965 |
frame.viewDocument.getMapContext().addLayerListener(frame); |
966 |
} else
|
967 |
if (getTypeScale() == CONSTANTE) {
|
968 |
frame.viewDocument.getMapContext().getViewPort().removeViewPortListener(frame); |
969 |
frame.viewDocument.getMapContext().addLayerListener(frame); |
970 |
} else
|
971 |
if (getTypeScale() == MANUAL) {
|
972 |
frame.viewDocument.getMapContext().getViewPort().removeViewPortListener(frame); |
973 |
frame.viewDocument.getMapContext().addLayerListener(frame); |
974 |
} |
975 |
} else
|
976 |
if (!linked) {
|
977 |
if (getTypeScale() == AUTOMATICO) {
|
978 |
frame.viewDocument.getMapContext().getViewPort().addViewPortListener(frame); |
979 |
} else
|
980 |
if (getTypeScale() == CONSTANTE) {
|
981 |
frame.viewDocument.getMapContext().getViewPort().removeViewPortListener(frame); |
982 |
} else
|
983 |
if (getTypeScale() == MANUAL) {
|
984 |
frame.viewDocument.getMapContext().getViewPort().removeViewPortListener(frame); |
985 |
} |
986 |
} |
987 |
/*
|
988 |
((FFrameView) frame).viewDocument.getMapContext().removeLayerListener(
|
989 |
(FFrameView) frame);
|
990 |
((FFrameView) frame).viewDocument.getMapContext().getViewPort()
|
991 |
.removeViewPortListener((FFrameView) frame);
|
992 |
*/
|
993 |
} |
994 |
|
995 |
public Object clone() throws CloneNotSupportedException { |
996 |
FFrameView frame = (FFrameView) super.clone();
|
997 |
|
998 |
frame.setSelected(this.getSelected() != IFFrame.NOSELECT);
|
999 |
|
1000 |
if (grid != null) { |
1001 |
FFrameGrid newGrid = (FFrameGrid) this.grid.clone();
|
1002 |
newGrid.setFFrameDependence(frame); |
1003 |
frame.setGrid(newGrid); |
1004 |
} |
1005 |
cloneActions(frame); |
1006 |
return frame;
|
1007 |
} |
1008 |
|
1009 |
public void setGrid(IFFrame grid) { |
1010 |
this.grid = grid;
|
1011 |
this.grid.setRotation(this.getRotation()); |
1012 |
} |
1013 |
|
1014 |
public IFFrame getGrid() {
|
1015 |
return this.grid; |
1016 |
} |
1017 |
|
1018 |
public void setRotation(double rotation) { |
1019 |
super.setRotation(rotation);
|
1020 |
if (grid != null) { |
1021 |
grid.setRotation(rotation); |
1022 |
} |
1023 |
} |
1024 |
|
1025 |
public void showGrid(boolean b) { |
1026 |
showGrid = b; |
1027 |
} |
1028 |
|
1029 |
public boolean isShowGrid() { |
1030 |
return showGrid;
|
1031 |
} |
1032 |
|
1033 |
public void refreshOriginalExtent() { |
1034 |
if (getTypeScale() == AUTOMATICO) {
|
1035 |
viewDocument.getMapContext().getViewPort() |
1036 |
.setEnvelope(getMapContext().getViewPort().getEnvelope()); |
1037 |
viewDocument.getMapContext().getViewPort().refreshExtent(); |
1038 |
} else
|
1039 |
if (getTypeScale() == MANUAL) {
|
1040 |
Envelope oldExtent = |
1041 |
viewDocument.getMapContext().getViewPort().getEnvelope(); |
1042 |
Envelope newExtent = |
1043 |
getMapContext().getViewPort().getEnvelope(); |
1044 |
double xDif = newExtent.getCenter(0) - oldExtent.getCenter(0); |
1045 |
double yDif = newExtent.getCenter(1) - oldExtent.getCenter(1); |
1046 |
try {
|
1047 |
viewDocument.getMapContext() |
1048 |
.getViewPort() |
1049 |
.setEnvelope( |
1050 |
geomManager.createEnvelope(oldExtent.getMinimum(0)
|
1051 |
+ xDif, oldExtent.getMinimum(1) + yDif,
|
1052 |
oldExtent.getMaximum(0) + xDif,
|
1053 |
oldExtent.getMaximum(1) + yDif, SUBTYPES.GEOM2D));
|
1054 |
} catch (CreateEnvelopeException e) {
|
1055 |
e.printStackTrace(); |
1056 |
} |
1057 |
viewDocument.getMapContext().getViewPort().refreshExtent(); |
1058 |
} |
1059 |
} |
1060 |
|
1061 |
public static void registerPersistent() { |
1062 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
1063 |
if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) { |
1064 |
DynStruct definition = |
1065 |
manager.addDefinition(FFrameView.class, |
1066 |
PERSISTENCE_DEFINITION_NAME, |
1067 |
"FFrameView persistence definition", null, null); |
1068 |
|
1069 |
definition.extend(manager |
1070 |
.getDefinition(FFrame.PERSISTENCE_DEFINITION_NAME)); |
1071 |
|
1072 |
definition.addDynFieldInt(MODE_FIELD).setMandatory(true);
|
1073 |
definition.addDynFieldInt(TYPESCALE_FIELD).setMandatory(true);
|
1074 |
definition.addDynFieldInt(EXTENSION_FIELD).setMandatory(true);
|
1075 |
definition.addDynFieldInt(QUALITY_FIELD).setMandatory(true);
|
1076 |
definition.addDynFieldInt(VIEWING_FIELD).setMandatory(true);
|
1077 |
definition.addDynFieldBoolean(BLINKED_FIELD).setMandatory(true);
|
1078 |
definition.addDynFieldInt(MAPUNITS_FIELD).setMandatory(true);
|
1079 |
definition.addDynFieldDouble(SCALE_FIELD).setMandatory(true);
|
1080 |
definition.addDynFieldObject(VIEW_FIELD) |
1081 |
.setClassOfValue(ViewDocument.class).setMandatory(false);
|
1082 |
definition.addDynFieldObject(ENVELOPE_FIELD) |
1083 |
.setClassOfValue(Envelope.class).setMandatory(false);
|
1084 |
definition.addDynFieldBoolean(SHOWGRID_FIELD).setMandatory(true);
|
1085 |
definition.addDynFieldObject(GRID_FIELD) |
1086 |
.setClassOfValue(IFFrame.class).setMandatory(false);
|
1087 |
definition.addDynFieldObject(MAPCONTEXT_FIELD) |
1088 |
.setClassOfValue(MapContext.class).setMandatory(false);
|
1089 |
} |
1090 |
} |
1091 |
|
1092 |
@Override
|
1093 |
public void loadFromState(PersistentState state) |
1094 |
throws PersistenceException {
|
1095 |
super.loadFromState(state);
|
1096 |
mode = state.getInt(MODE_FIELD); |
1097 |
typeScale = state.getInt(TYPESCALE_FIELD); |
1098 |
extension = state.getInt(EXTENSION_FIELD); |
1099 |
quality = state.getInt(QUALITY_FIELD); |
1100 |
viewing = state.getInt(VIEWING_FIELD); |
1101 |
linked = state.getBoolean(BLINKED_FIELD); |
1102 |
mapUnits = state.getInt(MAPUNITS_FIELD); |
1103 |
mapScale = state.getDouble(SCALE_FIELD); |
1104 |
viewDocument = (ViewDocument) state.get(VIEW_FIELD); |
1105 |
|
1106 |
if (state.hasValue(MAPCONTEXT_FIELD)) {
|
1107 |
mapContext = (MapContext) state.get(MAPCONTEXT_FIELD); |
1108 |
mapContext.getViewPort().setEnvelope( |
1109 |
(Envelope) state.get(ENVELOPE_FIELD)); |
1110 |
} |
1111 |
|
1112 |
showGrid = state.getBoolean(SHOWGRID_FIELD); |
1113 |
grid = (IFFrame) state.get(GRID_FIELD); |
1114 |
} |
1115 |
|
1116 |
@Override
|
1117 |
public void saveToState(PersistentState state) throws PersistenceException { |
1118 |
super.saveToState(state);
|
1119 |
state.set(MODE_FIELD, mode); |
1120 |
state.set(TYPESCALE_FIELD, typeScale); |
1121 |
state.set(EXTENSION_FIELD, extension); |
1122 |
state.set(QUALITY_FIELD, quality); |
1123 |
state.set(VIEWING_FIELD, viewing); |
1124 |
state.set(BLINKED_FIELD, linked); |
1125 |
state.set(MAPUNITS_FIELD, mapUnits); |
1126 |
state.set(SCALE_FIELD, mapScale); |
1127 |
state.set(VIEW_FIELD, viewDocument); |
1128 |
|
1129 |
if (getMapContext() != null |
1130 |
&& getMapContext().getViewPort().getEnvelope() != null) {
|
1131 |
state.set(ENVELOPE_FIELD, getMapContext().getViewPort() |
1132 |
.getEnvelope()); |
1133 |
state.set(MAPCONTEXT_FIELD, mapContext); |
1134 |
} |
1135 |
|
1136 |
state.set(SHOWGRID_FIELD, showGrid); |
1137 |
state.set(GRID_FIELD, grid); |
1138 |
} |
1139 |
|
1140 |
@Override
|
1141 |
public void setBoundBox(Rectangle2D r) { |
1142 |
super.setBoundBox(r);
|
1143 |
refresh(); |
1144 |
} |
1145 |
} |