Revision 761 trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/FFrameView.java
FFrameView.java | ||
---|---|---|
29 | 29 |
import java.awt.Point; |
30 | 30 |
import java.awt.Rectangle; |
31 | 31 |
import java.awt.geom.AffineTransform; |
32 |
import java.awt.geom.Area; |
|
33 |
import java.awt.geom.NoninvertibleTransformException; |
|
34 | 32 |
import java.awt.geom.Point2D; |
35 | 33 |
import java.awt.geom.Rectangle2D; |
36 | 34 |
import java.awt.image.BufferedImage; |
37 | 35 |
|
38 | 36 |
import org.cresques.cts.IProjection; |
39 | 37 |
import org.gvsig.andami.PluginServices; |
40 |
import org.gvsig.andami.messages.NotificationManager; |
|
41 | 38 |
import org.gvsig.andami.ui.mdiFrame.NewStatusBar; |
42 | 39 |
import org.gvsig.app.project.Project; |
43 | 40 |
import org.gvsig.app.project.ProjectManager; |
44 |
import org.gvsig.app.project.documents.Document; |
|
45 | 41 |
import org.gvsig.app.project.documents.layout.DefaultLayoutNotification; |
46 | 42 |
import org.gvsig.app.project.documents.layout.FLayoutFunctions; |
47 | 43 |
import org.gvsig.app.project.documents.layout.FLayoutUtilities; |
... | ... | |
76 | 72 |
import org.gvsig.gui.beans.Messages; |
77 | 73 |
import org.gvsig.tools.ToolsLocator; |
78 | 74 |
import org.gvsig.tools.dynobject.DynStruct; |
79 |
import org.gvsig.tools.locator.LocatorException; |
|
80 | 75 |
import org.gvsig.tools.persistence.PersistenceManager; |
81 | 76 |
import org.gvsig.tools.persistence.PersistentState; |
82 | 77 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
... | ... | |
85 | 80 |
|
86 | 81 |
/** |
87 | 82 |
* FFrame used for embedding a View in the Layout. The View is not actually |
88 |
* inserted on the Layout, but it is used together with the MapContext |
|
89 |
* in order do draw an image which is then painted on the FFrame. Therefore,
|
|
90 |
* no MapControl is used in current implementation, but a similar behavior
|
|
91 |
* is simulated by the FFrameView. The original MapContext is cloned when
|
|
92 |
* assigned to the FFrameView, which is then used for drawing.
|
|
83 |
* inserted on the Layout, but it is used together with the MapContext in order
|
|
84 |
* do draw an image which is then painted on the FFrame. Therefore, no
|
|
85 |
* MapControl is used in current implementation, but a similar behavior is
|
|
86 |
* simulated by the FFrameView. The original MapContext is cloned when assigned
|
|
87 |
* to the FFrameView, which is then used for drawing. |
|
93 | 88 |
* |
94 |
* The FFrameView and the associated View can be synchronized, depending |
|
95 |
* on the values of {@link #getTypeScale()} and {@link #getLinked()}.
|
|
89 |
* The FFrameView and the associated View can be synchronized, depending on the
|
|
90 |
* values of {@link #getTypeScale()} and {@link #getLinked()}. |
|
96 | 91 |
* |
97 | 92 |
* The main synchronization logic is kept on two internal classes: |
98 | 93 |
* {@link OwnMapContextListener} and {@link ViewDocListener}. The first one |
99 | 94 |
* listens for events on the FFrameView and synchronizes the View accordingly. |
100 | 95 |
* The second one listens for events on the View and synchronizes the FFrameView |
101 | 96 |
* accordingly. There synchronization process is flagged using |
102 |
* {@link #b_updating} and {@link #b_updating}, in order |
|
103 |
* to avoid incurring on infinite synchronization loops.
|
|
97 |
* {@link #b_updating} and {@link #b_updating}, in order to avoid incurring on
|
|
98 |
* infinite synchronization loops. |
|
104 | 99 |
* |
105 |
* @author Vicente Caballero Navarro |
|
106 |
* @author Cesar Martinez Izquierdo |
|
107 | 100 |
*/ |
108 | 101 |
public class FFrameView extends FFrame implements IFFrameUseProject, |
109 |
IFFrameUseFMap, LayoutPanelListener{
|
|
102 |
IFFrameUseFMap, LayoutPanelListener {
|
|
110 | 103 |
|
104 |
private static final Logger logger = LoggerFactory.getLogger(FFrameView.class); |
|
105 |
|
|
111 | 106 |
public static final String PERSISTENCE_DEFINITION_NAME = "FFrameView"; |
112 | 107 |
|
113 | 108 |
private static final String QUALITY_FIELD = "quality"; |
... | ... | |
121 | 116 |
private static final String LAYER_SYNC_FIELD = "layerSync"; |
122 | 117 |
private static final String EXTENT_SYNC_FIELD = "extentSync"; |
123 | 118 |
private static final String SCALE_TYPE_FIELD = "scaleType"; |
119 |
|
|
124 | 120 |
// following fields are unused - they are kept for backward-compatibility |
125 | 121 |
private static final String EXTENSION_FIELD = "extension"; |
126 | 122 |
private static final String BLINKED_FIELD = "bLinked"; |
... | ... | |
129 | 125 |
private static final String MAPCONTEXT_FIELD = "mapContext"; |
130 | 126 |
private static final String VIEWING_FIELD = "viewing"; |
131 | 127 |
|
132 |
private static final Logger logger = LoggerFactory |
|
133 |
.getLogger(FFrameView.class); |
|
134 | 128 |
public static final int PRESENTATION = 0; |
135 | 129 |
public static final int DRAFT = 1; |
136 | 130 |
|
... | ... | |
151 | 145 |
protected IFFrame grid; |
152 | 146 |
protected boolean showGrid = false; |
153 | 147 |
|
154 |
private boolean b_updating = false;
|
|
155 |
protected boolean b_validCache = false;
|
|
156 |
protected boolean b_drawing = false;
|
|
157 |
protected ViewDocListener viewDocListener;
|
|
158 |
protected OwnMapContextListener ownMapContextListener;
|
|
159 |
private boolean b_hasToc = true;
|
|
148 |
private boolean b_updating = false;
|
|
149 |
protected boolean b_validCache = false;
|
|
150 |
protected boolean b_drawing = false;
|
|
151 |
private ViewDocListener viewDocListener;
|
|
152 |
private OwnMapContextListener ownMapContextListener;
|
|
153 |
private boolean b_hasToc = true;
|
|
160 | 154 |
protected static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
161 | 155 |
|
162 |
/**
|
|
163 |
* When we load a FFrameview from project, it will receive a wrong
|
|
164 |
* extentChanged event the first time the View is painted, so we must
|
|
165 |
* ignore this first event.
|
|
166 |
*/
|
|
167 |
private boolean b_frameInitialized = true;
|
|
156 |
/**
|
|
157 |
* When we load a FFrameview from project, it will receive a wrong
|
|
158 |
* extentChanged event the first time the View is painted, so we must ignore
|
|
159 |
* this first event.
|
|
160 |
*/
|
|
161 |
private boolean b_frameInitialized = true;
|
|
168 | 162 |
|
169 |
protected AffineTransform originalGraphicsAT = null;
|
|
170 |
protected Rectangle originalClip = null;
|
|
163 |
protected AffineTransform originalGraphicsAT = null;
|
|
164 |
protected Rectangle originalClip = null;
|
|
171 | 165 |
|
172 |
private SCALE_TYPE scaleType = SCALE_TYPE.NORMAL;
|
|
173 |
private Double fixedScale = null;
|
|
174 |
private Envelope fixedExtent = null;
|
|
166 |
private SCALE_TYPE scaleType = SCALE_TYPE.NORMAL;
|
|
167 |
private Double fixedScale = null;
|
|
168 |
private Envelope fixedExtent = null;
|
|
175 | 169 |
|
176 |
|
|
177 | 170 |
/** |
178 | 171 |
* Creates a new FFrameView object. |
179 | 172 |
*/ |
... | ... | |
188 | 181 |
* |
189 | 182 |
* @return Description. |
190 | 183 |
*/ |
184 |
@Override |
|
191 | 185 |
public String toString() { |
192 | 186 |
if (getView() == null) { |
193 | 187 |
return "FFrameView " + num + ": " + "Vacio"; |
194 | 188 |
} |
195 |
|
|
196 | 189 |
return "FFrameView " + num + ": " + getView().getName(); |
197 | 190 |
} |
198 | 191 |
|
... | ... | |
201 | 194 |
* |
202 | 195 |
* @param d Scale to be set |
203 | 196 |
*/ |
197 |
@Override |
|
204 | 198 |
public void setScale(double d) { |
205 |
if (getMapContext()!=null) {
|
|
206 |
getMapContext().setScaleView((long) d);
|
|
207 |
}
|
|
199 |
if (getMapContext() != null) {
|
|
200 |
getMapContext().setScaleView((long) d);
|
|
201 |
}
|
|
208 | 202 |
} |
209 | 203 |
|
210 | 204 |
/** |
211 |
* Sets a new Envelope on the MapContext contained in |
|
212 |
* this FFrameView |
|
205 |
* Sets a new Envelope on the MapContext contained in this FFrameView |
|
213 | 206 |
* |
214 | 207 |
* @param r Envelope to be set |
215 | 208 |
*/ |
209 |
@Override |
|
216 | 210 |
public void setNewEnvelope(Envelope r) { |
217 |
getMapContext().getViewPort().setEnvelope(r);
|
|
218 |
updateScaleCtrl();
|
|
211 |
getMapContext().getViewPort().setEnvelope(r);
|
|
212 |
updateScaleCtrl();
|
|
219 | 213 |
} |
220 | 214 |
|
221 | 215 |
/** |
222 | 216 |
* Calculates the resolution (measured on dots per inch, DPI) to be |
223 |
* considered to draw the FFrameView on screen. It is calculated by |
|
224 |
* dividing the width (in pixels) of the FFrame divided by the width |
|
225 |
* in inches of the paper. |
|
217 |
* considered to draw the FFrameView on screen. It is calculated by dividing |
|
218 |
* the width (in pixels) of the FFrame divided by the width in inches of the |
|
219 |
* paper. |
|
220 |
* |
|
221 |
* @return |
|
226 | 222 |
*/ |
227 | 223 |
protected double getDrawPaperDPI() { |
228 |
AffineTransform at = null;
|
|
229 |
if (getLayoutContext()!=null) {
|
|
230 |
at = getLayoutContext().getAT();
|
|
231 |
}
|
|
232 |
return (2.54*getBoundingBox(at).width)/getBoundBox().width;
|
|
224 |
AffineTransform at = null;
|
|
225 |
if (getLayoutContext() != null) {
|
|
226 |
at = getLayoutContext().getAT();
|
|
227 |
}
|
|
228 |
return (2.54 * getBoundingBox(at).width) / getBoundBox().width;
|
|
233 | 229 |
} |
234 | 230 |
|
235 | 231 |
/** |
236 |
* Returns the MapContext contained in this FFrameView, which is |
|
237 |
* usually a clone of the associated View. This MapContext
|
|
238 |
* may be synchronized with the View one, depending on the
|
|
239 |
* scale type that has been set (see {{@link #getTypeScale()}.
|
|
232 |
* Returns the MapContext contained in this FFrameView, which is usually a
|
|
233 |
* clone of the associated View. This MapContext may be synchronized with
|
|
234 |
* the View one, depending on the scale type that has been set (see
|
|
235 |
* {{@link #getTypeScale()}. |
|
240 | 236 |
* |
241 | 237 |
* @return The mapContext object |
242 | 238 |
*/ |
239 |
@Override |
|
243 | 240 |
public MapContext getMapContext() { |
244 | 241 |
return mapContext; |
245 | 242 |
} |
246 | 243 |
|
247 | 244 |
/** |
248 |
* Sets the quality of the visualization of the FFrame on screen. |
|
249 |
* Valid values include {@link #DRAFT} and {@link #PRESENTATION}. |
|
250 |
* Draft will disable the frame normal drawing, which will be |
|
251 |
* replaced by an empty rectangle only showing the name of the |
|
252 |
* frame. |
|
245 |
* Sets the quality of the visualization of the FFrame on screen. Valid |
|
246 |
* values include {@link #DRAFT} and {@link #PRESENTATION}. Draft will |
|
247 |
* disable the frame normal drawing, which will be replaced by an empty |
|
248 |
* rectangle only showing the name of the frame. |
|
253 | 249 |
* |
254 | 250 |
* @param q Integer representing the quality. |
255 | 251 |
*/ |
... | ... | |
258 | 254 |
} |
259 | 255 |
|
260 | 256 |
/** |
261 |
* Gets the quality of the visualization of the FFrame on screen. |
|
262 |
* Valid values include {@link #DRAFT} and {@link #PRESENTATION}. |
|
263 |
* Draft will disable the frame normal drawing, which will be |
|
264 |
* replaced by an empty rectangle only showing the name of the |
|
265 |
* frame. |
|
257 |
* Gets the quality of the visualization of the FFrame on screen. Valid |
|
258 |
* values include {@link #DRAFT} and {@link #PRESENTATION}. Draft will |
|
259 |
* disable the frame normal drawing, which will be replaced by an empty |
|
260 |
* rectangle only showing the name of the frame. |
|
266 | 261 |
* |
267 |
* @param q The selected quality
|
|
262 |
* @return
|
|
268 | 263 |
*/ |
269 | 264 |
public int getQuality() { |
270 | 265 |
return quality; |
271 | 266 |
} |
272 | 267 |
|
273 | 268 |
/** |
274 |
* Sets the MapContext associated with this FFrameView, which will |
|
275 |
* be used to clone the layers and synchronize the FFrameView with
|
|
276 |
* the associated View
|
|
269 |
* Sets the MapContext associated with this FFrameView, which will be used
|
|
270 |
* to clone the layers and synchronize the FFrameView with the associated
|
|
271 |
* View |
|
277 | 272 |
* |
278 | 273 |
* @param viewMapContext |
279 | 274 |
*/ |
280 | 275 |
public void setViewMapContext(MapContext viewMapContext) { |
281 |
Envelope oldEnvelope = null; |
|
282 |
if (mapContext!=null) { |
|
283 |
removeOwnListeners(); |
|
284 |
if (mapContext.getViewPort()!=null) { |
|
285 |
oldEnvelope = mapContext.getViewPort().getEnvelope(); |
|
286 |
} |
|
287 |
} |
|
288 |
if (viewMapContext==null) { // disconnect the view from the map |
|
289 |
this.mapContext=null; |
|
290 |
return; |
|
291 |
} |
|
292 |
try { |
|
293 |
if (syncLayers){ |
|
294 |
mapContext = |
|
295 |
viewMapContext.createNewFMap( |
|
296 |
(ViewPort) viewMapContext.getViewPort().clone()); |
|
297 |
} |
|
298 |
else { |
|
299 |
mapContext = viewMapContext.cloneFMap(); |
|
300 |
mapContext.setViewPort((ViewPort) viewMapContext |
|
301 |
.getViewPort().clone()); |
|
302 |
} |
|
303 |
ViewPort newViewPort = getMapContext().getViewPort(); |
|
304 |
if (!syncExtents && oldEnvelope!=null) { |
|
305 |
// if extent is not synced with the view, restore the previous |
|
306 |
// envelope if existing |
|
307 |
newViewPort.setEnvelope(oldEnvelope); |
|
308 |
} |
|
309 |
AffineTransform at; |
|
310 |
if (getLayoutContext()!=null) { |
|
311 |
at = getLayoutContext().getAT(); |
|
312 |
} |
|
313 |
else { |
|
314 |
at = null; |
|
315 |
} |
|
316 |
newViewPort.setImageSize(new Dimension((int) getBoundingBox(at).width, |
|
317 |
(int) getBoundingBox(at).height)); |
|
318 |
newViewPort.setDPI(getDrawPaperDPI()); |
|
319 |
addAllListeners(); |
|
320 |
updateScaleCtrl(); |
|
321 |
setTocModel(); |
|
322 |
} catch (CloneNotSupportedException e1) { |
|
323 |
NotificationManager.addError("Excepci?n :", e1); |
|
324 |
} |
|
276 |
Envelope oldEnvelope = null; |
|
277 |
if (mapContext != null) { |
|
278 |
removeOwnListeners(); |
|
279 |
if (mapContext.getViewPort() != null) { |
|
280 |
oldEnvelope = mapContext.getViewPort().getEnvelope(); |
|
281 |
} |
|
282 |
} |
|
283 |
if (viewMapContext == null) { // disconnect the view from the map |
|
284 |
this.mapContext = null; |
|
285 |
return; |
|
286 |
} |
|
287 |
try { |
|
288 |
if (syncLayers) { |
|
289 |
mapContext |
|
290 |
= viewMapContext.createNewFMap( |
|
291 |
(ViewPort) viewMapContext.getViewPort().clone()); |
|
292 |
} else { |
|
293 |
mapContext = viewMapContext.cloneFMap(); |
|
294 |
mapContext.setViewPort((ViewPort) viewMapContext |
|
295 |
.getViewPort().clone()); |
|
296 |
} |
|
297 |
ViewPort newViewPort = getMapContext().getViewPort(); |
|
298 |
if (!syncExtents && oldEnvelope != null) { |
|
299 |
// if extent is not synced with the view, restore the previous |
|
300 |
// envelope if existing |
|
301 |
newViewPort.setEnvelope(oldEnvelope); |
|
302 |
} |
|
303 |
AffineTransform at; |
|
304 |
if (getLayoutContext() != null) { |
|
305 |
at = getLayoutContext().getAT(); |
|
306 |
} else { |
|
307 |
at = null; |
|
308 |
} |
|
309 |
newViewPort.setImageSize(new Dimension((int) getBoundingBox(at).width, |
|
310 |
(int) getBoundingBox(at).height)); |
|
311 |
newViewPort.setDPI(getDrawPaperDPI()); |
|
312 |
addAllListeners(); |
|
313 |
updateScaleCtrl(); |
|
314 |
setTocModel(); |
|
315 |
} catch (CloneNotSupportedException e1) { |
|
316 |
logger.warn("Can't set mapcontext of the fframeview", e1); |
|
317 |
} |
|
325 | 318 |
|
326 | 319 |
} |
327 | 320 |
|
328 | 321 |
/** |
329 |
* Sets the View associated with this FFrameView, which will |
|
330 |
* be used to clone the MapContext and the layers. It will |
|
331 |
* also used to synchronize the FFrameView with |
|
332 |
* the associated View, depending on the selected scale type |
|
322 |
* Sets the View associated with this FFrameView, which will be used to |
|
323 |
* clone the MapContext and the layers. It will also used to synchronize the |
|
324 |
* FFrameView with the associated View, depending on the selected scale type |
|
333 | 325 |
* |
334 |
* @param dvd
|
|
326 |
* @param viewDocument
|
|
335 | 327 |
*/ |
336 |
public void setView(ViewDocument dvd) {
|
|
337 |
removeViewListeners();
|
|
338 |
viewDocument = dvd;
|
|
339 |
if (dvd!=null) {
|
|
340 |
setViewMapContext(dvd.getMapContext());
|
|
328 |
public void setView(ViewDocument viewDocument) {
|
|
329 |
removeViewListeners();
|
|
330 |
this.viewDocument = viewDocument;
|
|
331 |
if (this.viewDocument != null) {
|
|
332 |
setViewMapContext(this.viewDocument.getMapContext());
|
|
341 | 333 |
} else { |
342 | 334 |
setViewMapContext(null); |
343 | 335 |
} |
... | ... | |
354 | 346 |
} |
355 | 347 |
|
356 | 348 |
/** |
357 |
* Draws the FFrameView on the provided Graphics, according to the |
|
358 |
* provided affine transform and the visible rectangle.
|
|
349 |
* Draws the FFrameView on the provided Graphics, according to the provided
|
|
350 |
* affine transform and the visible rectangle. |
|
359 | 351 |
* |
360 | 352 |
* @param g Graphics2D |
361 |
* @param at Affine transform to translate sheet coordinates (in cm) |
|
362 |
* to screen coordinates (in pixels)
|
|
353 |
* @param at Affine transform to translate sheet coordinates (in cm) to
|
|
354 |
* screen coordinates (in pixels) |
|
363 | 355 |
* @param visibleLayoutDocRect visible rectangle |
364 | 356 |
* @param imgBase Image used to speed up the drawing process |
365 | 357 |
*/ |
358 |
@Override |
|
366 | 359 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D visibleLayoutDocRect, BufferedImage imgBase) { |
367 | 360 |
Rectangle2D.Double fframeViewRect = getBoundingBox(at); |
368 | 361 |
Rectangle2D.Double visibleArea = (Rectangle2D.Double) getVisibleRect(visibleLayoutDocRect, fframeViewRect); |
369 |
if (visibleArea==null) {
|
|
370 |
return;
|
|
362 |
if (visibleArea == null) {
|
|
363 |
return;
|
|
371 | 364 |
} |
372 | 365 |
preDraw(g, fframeViewRect, visibleArea); |
373 | 366 |
if (getMapContext() == null) { |
374 |
drawEmpty(g);
|
|
367 |
drawEmpty(g);
|
|
375 | 368 |
} else { |
376 |
if (FLayoutUtilities.hasEditingLayers(getView())) { |
|
369 |
if (FLayoutUtilities.hasEditingLayers(getView())) { |
|
370 |
// We are not drawing if any layer is in editing mode |
|
371 |
drawMessage(g, Messages.getText( |
|
372 |
"_Cannot_draw_view_if_layers_in_editing_mode")); |
|
377 | 373 |
|
378 |
/* |
|
379 |
* We are not drawing if any layer is in editing mode |
|
380 |
*/ |
|
381 |
drawMessage(g, Messages.getText( |
|
382 |
"_Cannot_draw_view_if_layers_in_editing_mode")); |
|
374 |
} else { |
|
375 |
if (getQuality() == PRESENTATION) { |
|
376 |
try { |
|
377 |
drawPresentation(g, at, fframeViewRect, visibleArea, imgBase); |
|
378 |
} catch (Exception exc) { |
|
379 |
drawMessage(g, FLayoutFunctions.getLastMessage(exc)); |
|
380 |
} |
|
383 | 381 |
|
384 |
} else { |
|
385 |
if (getQuality() == PRESENTATION) { |
|
386 |
try { |
|
387 |
drawPresentation(g, at, fframeViewRect, visibleArea, imgBase); |
|
388 |
} catch (Exception exc) { |
|
389 |
drawMessage(g, FLayoutFunctions.getLastMessage(exc)); |
|
390 |
} |
|
391 |
|
|
392 |
} else { |
|
393 |
drawDraft(g); |
|
394 |
} |
|
395 |
} |
|
382 |
} else { |
|
383 |
drawDraft(g); |
|
384 |
} |
|
385 |
} |
|
396 | 386 |
} |
397 | 387 |
postDraw(g, fframeViewRect, at); |
398 | 388 |
if (showGrid && grid != null) { |
... | ... | |
404 | 394 |
|
405 | 395 |
Rectangle2D r = getBoundingBox(null); |
406 | 396 |
g.setColor(Color.lightGray); |
407 |
g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(), |
|
408 |
(int) r.getHeight()); |
|
397 |
g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(), (int) r.getHeight()); |
|
409 | 398 |
g.setColor(Color.darkGray); |
410 | 399 |
g.setStroke(new BasicStroke(2)); |
411 |
g.drawRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(), |
|
412 |
(int) r.getHeight()); |
|
400 |
g.drawRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(), (int) r.getHeight()); |
|
413 | 401 |
g.setColor(Color.black); |
414 | 402 |
|
415 | 403 |
int scale = (int) (r.getWidth() / 24); |
416 | 404 |
Font f = new Font("SansSerif", Font.PLAIN, scale); |
417 | 405 |
g.setFont(f); |
418 |
if (msg==null) {
|
|
419 |
msg = Messages.getText("error");
|
|
406 |
if (msg == null) {
|
|
407 |
msg = Messages.getText("error");
|
|
420 | 408 |
} |
421 | 409 |
g.drawString(msg, (int) (r.getCenterX() - ((msg.length() * scale) / 4)), |
422 |
(int) (r.getCenterY())); |
|
410 |
(int) (r.getCenterY()) |
|
411 |
); |
|
423 | 412 |
} |
424 | 413 |
|
425 | 414 |
/** |
... | ... | |
427 | 416 |
* |
428 | 417 |
* @param fframeViewRect Rectangle defining the bounding box of the |
429 | 418 |
* FFrameView, in screen coordinates |
430 |
* @param visiblefframeViewRect Rectangle defining the bounding box |
|
431 |
* of the visible area of the fframeView, in screen coordinates
|
|
419 |
* @param visiblefframeViewRect Rectangle defining the bounding box of the
|
|
420 |
* visible area of the fframeView, in screen coordinates |
|
432 | 421 |
* @return |
433 | 422 |
*/ |
434 | 423 |
protected Envelope getVisibleEnvelope(Rectangle2D.Double fframeViewRect, |
435 | 424 |
Rectangle2D.Double visiblefframeViewRect) { |
436 |
Envelope oldEnv = getMapContext().getViewPort().getAdjustedEnvelope();
|
|
437 |
double widthFactor = ((int)visiblefframeViewRect.width) / fframeViewRect.width;
|
|
438 |
double heightFactor = ((int)visiblefframeViewRect.height) / fframeViewRect.height;
|
|
425 |
Envelope oldEnv = getMapContext().getViewPort().getAdjustedEnvelope();
|
|
426 |
double widthFactor = ((int) visiblefframeViewRect.width) / fframeViewRect.width;
|
|
427 |
double heightFactor = ((int) visiblefframeViewRect.height) / fframeViewRect.height;
|
|
439 | 428 |
|
440 |
double newWidth = oldEnv.getLength(0)*widthFactor;
|
|
441 |
double newHeight = oldEnv.getLength(1)*heightFactor;
|
|
429 |
double newWidth = oldEnv.getLength(0) * widthFactor;
|
|
430 |
double newHeight = oldEnv.getLength(1) * heightFactor;
|
|
442 | 431 |
|
443 | 432 |
double translateX = visiblefframeViewRect.x - fframeViewRect.x; |
444 | 433 |
double translateY = visiblefframeViewRect.y - fframeViewRect.y; |
445 | 434 |
double translateFactorX = translateX / fframeViewRect.width; |
446 | 435 |
double translateFactorY = translateY / fframeViewRect.height; |
447 | 436 |
|
448 |
double newX = oldEnv.getMinimum(0) + translateFactorX*oldEnv.getLength(0);
|
|
449 |
double newMaxY = oldEnv.getMaximum(1) - translateFactorY*oldEnv.getLength(1);
|
|
437 |
double newX = oldEnv.getMinimum(0) + translateFactorX * oldEnv.getLength(0);
|
|
438 |
double newMaxY = oldEnv.getMaximum(1) - translateFactorY * oldEnv.getLength(1);
|
|
450 | 439 |
double newMaxX = newX + newWidth; |
451 | 440 |
double newY = newMaxY - newHeight; |
452 | 441 |
|
453 | 442 |
Envelope newEnv = null; |
454 |
try {
|
|
455 |
newEnv = geomManager.createEnvelope(newX, newY, newMaxX, newMaxY, SUBTYPES.GEOM2D);
|
|
456 |
} catch (CreateEnvelopeException e) {
|
|
457 |
logger.error("Error calculating visible extent", e);
|
|
458 |
}
|
|
443 |
try {
|
|
444 |
newEnv = geomManager.createEnvelope(newX, newY, newMaxX, newMaxY, SUBTYPES.GEOM2D);
|
|
445 |
} catch (CreateEnvelopeException ex) {
|
|
446 |
logger.warn("Can't calculate the envelope of the visible area.", ex);
|
|
447 |
}
|
|
459 | 448 |
return newEnv; |
460 | 449 |
|
461 | 450 |
} |
462 | 451 |
|
463 | 452 |
protected void drawPresentation( |
464 |
Graphics2D g, |
|
465 |
AffineTransform affineTransform, |
|
466 |
Rectangle2D.Double fframeViewRect, |
|
467 |
Rectangle2D.Double visibleRect, |
|
468 |
BufferedImage imgBase) throws Exception { |
|
453 |
Graphics2D g,
|
|
454 |
AffineTransform affineTransform,
|
|
455 |
Rectangle2D.Double fframeViewRect,
|
|
456 |
Rectangle2D.Double visibleRect,
|
|
457 |
BufferedImage imgBase) throws Exception {
|
|
469 | 458 |
|
470 |
b_drawing = true;
|
|
471 |
int drawWidth = (int)visibleRect.width;
|
|
472 |
int drawHeight = (int)visibleRect.height;
|
|
459 |
b_drawing = true;
|
|
460 |
int drawWidth = (int) visibleRect.width;
|
|
461 |
int drawHeight = (int) visibleRect.height;
|
|
473 | 462 |
|
474 |
Envelope oldEnvelope = null;
|
|
463 |
Envelope oldEnvelope = null;
|
|
475 | 464 |
if (!visibleRect.equals(fframeViewRect)) { |
476 |
// if visible area is smaller than the fframe, we will only draw this area,
|
|
477 |
// so we need to tell the ViewPort the image size and extent for drawing,
|
|
478 |
// and restore the real extent after drawing
|
|
465 |
// if visible area is smaller than the fframe, we will only draw this area,
|
|
466 |
// so we need to tell the ViewPort the image size and extent for drawing,
|
|
467 |
// and restore the real extent after drawing
|
|
479 | 468 |
oldEnvelope = getMapContext().getViewPort().getEnvelope(); |
480 |
if (oldEnvelope==null) {
|
|
481 |
return;
|
|
469 |
if (oldEnvelope == null) {
|
|
470 |
return;
|
|
482 | 471 |
} |
483 | 472 |
|
484 |
Envelope newEnvelope = getVisibleEnvelope(fframeViewRect, visibleRect); |
|
485 |
// image size must be set before the envelope, as it has influence on the adjustedExtent |
|
486 |
getMapContext().getViewPort().setImageSize(new Dimension(drawWidth, drawHeight)); |
|
487 |
getMapContext().getViewPort().setEnvelope(newEnvelope); |
|
473 |
Envelope newEnvelope = getVisibleEnvelope(fframeViewRect, visibleRect); |
|
474 |
// image size must be set before the envelope, as it has influence on the adjustedExtent |
|
475 |
getMapContext().getViewPort().setImageSize(new Dimension(drawWidth, drawHeight)); |
|
476 |
getMapContext().getViewPort().setEnvelope(newEnvelope); |
|
477 |
} else { |
|
478 |
getMapContext().getViewPort().setImageSize(new Dimension(drawWidth, drawHeight)); |
|
479 |
getMapContext().getViewPort().refreshExtent(); |
|
488 | 480 |
} |
489 |
else { |
|
490 |
getMapContext().getViewPort().setImageSize(new Dimension(drawWidth, drawHeight)); |
|
491 |
getMapContext().getViewPort().refreshExtent(); |
|
492 |
} |
|
493 | 481 |
|
494 | 482 |
// map origin should be calculated using the full fframeview, as the visible position will be relative |
495 |
Point mapOrigin = new Point((int)fframeViewRect.getMinX(), (int)fframeViewRect.getMaxY());
|
|
483 |
Point mapOrigin = new Point((int) fframeViewRect.getMinX(), (int) fframeViewRect.getMaxY());
|
|
496 | 484 |
|
497 | 485 |
// paint the MapContext on m_image, if not already cached |
498 | 486 |
createImage(affineTransform, drawWidth, drawHeight, mapOrigin); |
... | ... | |
500 | 488 |
//Draw the created image |
501 | 489 |
drawImage(g, m_image, visibleRect); |
502 | 490 |
|
503 |
if (oldEnvelope!=null) {
|
|
504 |
// restore real envelope and image size
|
|
505 |
getMapContext().getViewPort().setImageSize(new Dimension((int)fframeViewRect.width, (int) fframeViewRect.height));
|
|
506 |
getMapContext().getViewPort().setEnvelope(oldEnvelope);
|
|
491 |
if (oldEnvelope != null) {
|
|
492 |
// restore real envelope and image size
|
|
493 |
getMapContext().getViewPort().setImageSize(new Dimension((int) fframeViewRect.width, (int) fframeViewRect.height));
|
|
494 |
getMapContext().getViewPort().setEnvelope(oldEnvelope);
|
|
507 | 495 |
} |
508 | 496 |
|
509 | 497 |
scaleAnt = affineTransform.getScaleX(); |
... | ... | |
512 | 500 |
} |
513 | 501 |
|
514 | 502 |
protected void createImage(AffineTransform affineTransform, |
515 |
int width, int height, Point mapOrigin) throws ReadException, MapContextException {
|
|
516 |
ViewPort viewPort = this.getMapContext().getViewPort();
|
|
503 |
int width, int height, Point mapOrigin) throws ReadException, MapContextException {
|
|
504 |
ViewPort viewPort = this.getMapContext().getViewPort();
|
|
517 | 505 |
|
518 | 506 |
//If the image has to be created... |
519 |
if (origin == null ||
|
|
520 |
!origin.equals(mapOrigin) ||
|
|
521 |
affineTransform.getScaleX() != scaleAnt ||
|
|
522 |
m_image == null ||
|
|
523 |
!b_validCache) {
|
|
507 |
if (origin == null
|
|
508 |
|| !origin.equals(mapOrigin)
|
|
509 |
|| affineTransform.getScaleX() != scaleAnt
|
|
510 |
|| m_image == null
|
|
511 |
|| !b_validCache) {
|
|
524 | 512 |
|
525 |
viewPort.setDPI(getDrawPaperDPI());
|
|
526 |
viewPort.setImageSize(new Dimension(width, height));
|
|
513 |
viewPort.setDPI(getDrawPaperDPI());
|
|
514 |
viewPort.setImageSize(new Dimension(width, height));
|
|
527 | 515 |
|
528 |
m_image = |
|
529 |
new BufferedImage(
|
|
530 |
width,
|
|
531 |
height,
|
|
532 |
BufferedImage.TYPE_INT_ARGB);
|
|
516 |
m_image = new BufferedImage(
|
|
517 |
width,
|
|
518 |
height,
|
|
519 |
BufferedImage.TYPE_INT_ARGB
|
|
520 |
); |
|
533 | 521 |
|
534 | 522 |
Graphics2D gimg = (Graphics2D) m_image.createGraphics(); |
535 | 523 |
getMapContext().draw(m_image, gimg, getScale()); |
... | ... | |
540 | 528 |
} |
541 | 529 |
|
542 | 530 |
protected void drawImage(Graphics2D g, BufferedImage image, |
543 |
Rectangle2D.Double visibleRectangle) {
|
|
531 |
Rectangle2D.Double visibleRectangle) {
|
|
544 | 532 |
|
545 |
Color theBackColor = getMapContext().getViewPort().getBackColor();
|
|
533 |
Color theBackColor = getMapContext().getViewPort().getBackColor();
|
|
546 | 534 |
if (theBackColor != null) { |
547 | 535 |
g.setColor(theBackColor); |
548 | 536 |
g.fillRect((int) visibleRectangle.x, (int) visibleRectangle.y, |
549 |
(int)visibleRectangle.width,
|
|
550 |
(int)visibleRectangle.height);
|
|
537 |
(int) visibleRectangle.width,
|
|
538 |
(int) visibleRectangle.height);
|
|
551 | 539 |
} |
552 | 540 |
g.drawImage(m_image, |
553 |
(int) visibleRectangle.x,
|
|
554 |
(int) visibleRectangle.y,
|
|
555 |
null);
|
|
541 |
(int) visibleRectangle.x,
|
|
542 |
(int) visibleRectangle.y,
|
|
543 |
null);
|
|
556 | 544 |
} |
557 | 545 |
|
558 |
protected void preDraw(Graphics2D g, Rectangle2D.Double fframeViewRect, Rectangle2D.Double visibleRect){ |
|
559 |
originalGraphicsAT = (AffineTransform) g.getTransform().clone();
|
|
546 |
protected void preDraw(Graphics2D g, Rectangle2D.Double fframeViewRect, Rectangle2D.Double visibleRect) {
|
|
547 |
originalGraphicsAT = (AffineTransform) g.getTransform().clone();
|
|
560 | 548 |
|
561 | 549 |
if (g.getClipBounds() != null) { |
562 | 550 |
originalClip = (Rectangle) g.getClipBounds().clone(); |
563 | 551 |
} |
564 | 552 |
AffineTransform rotationAT = getRotationAT(); |
565 |
if (rotationAT!=null) {
|
|
566 |
g.transform(rotationAT);
|
|
553 |
if (rotationAT != null) {
|
|
554 |
g.transform(rotationAT);
|
|
567 | 555 |
} |
568 | 556 |
g.setClip((int) visibleRect.getMinX(), (int) visibleRect.getMinY(), |
569 |
(int) visibleRect.getWidth(), (int) visibleRect.getHeight()); |
|
557 |
(int) visibleRect.getWidth(), (int) visibleRect.getHeight());
|
|
570 | 558 |
} |
571 | 559 |
|
572 |
protected void postDraw(Graphics2D g, Rectangle2D.Double fframeViewRect, AffineTransform at){ |
|
573 |
g.setTransform(originalGraphicsAT);
|
|
560 |
protected void postDraw(Graphics2D g, Rectangle2D.Double fframeViewRect, AffineTransform at) {
|
|
561 |
g.setTransform(originalGraphicsAT);
|
|
574 | 562 |
if (getMapContext() != null) { |
575 | 563 |
setATMap(getMapContext().getViewPort().getAffineTransform()); |
576 | 564 |
} |
... | ... | |
579 | 567 |
} |
580 | 568 |
} |
581 | 569 |
|
582 |
|
|
583 | 570 |
/** |
584 |
* @deprecated Use {@link #postDraw(Graphics2D, java.awt.geom.Rectangle2D.Double, AffineTransform)} instead. |
|
571 |
* @param g |
|
572 |
* @param rectangleLayout |
|
573 |
* @param rectangleView |
|
574 |
* @param originalClip |
|
575 |
* @param imgBase |
|
576 |
* @param at |
|
577 |
* @deprecated Use |
|
578 |
* {@link #postDraw(Graphics2D, java.awt.geom.Rectangle2D.Double, AffineTransform)} |
|
579 |
* instead. |
|
585 | 580 |
*/ |
586 | 581 |
@Deprecated |
587 | 582 |
protected void postDraw(Graphics2D g, Rectangle2D.Double rectangleLayout, Rectangle2D rectangleView, BufferedImage imgBase, Rectangle originalClip, AffineTransform at) { |
588 |
postDraw(g, rectangleLayout, at);
|
|
583 |
postDraw(g, rectangleLayout, at);
|
|
589 | 584 |
|
590 | 585 |
} |
591 | 586 |
|
592 | 587 |
/** |
588 |
* @param g |
|
589 |
* @param rectangleLayout |
|
590 |
* @return |
|
593 | 591 |
* @deprecated Use {@link #preDraw(Graphics2D, java.awt.geom.Rectangle2D.Double, java.awt.geom.Rectangle2D.Double) instead |
594 | 592 |
*/ |
595 | 593 |
@Deprecated |
596 |
protected Rectangle preDraw(Graphics2D g, Rectangle2D.Double rectangleLayout){ |
|
597 |
Rectangle originalClip = null;
|
|
594 |
protected Rectangle preDraw(Graphics2D g, Rectangle2D.Double rectangleLayout) {
|
|
595 |
Rectangle originalClip = null;
|
|
598 | 596 |
if (g.getClipBounds() != null) { |
599 | 597 |
originalClip = (Rectangle) g.getClipBounds().clone(); |
600 | 598 |
} |
601 |
preDraw(g, rectangleLayout, rectangleLayout);
|
|
602 |
return originalClip;
|
|
599 |
preDraw(g, rectangleLayout, rectangleLayout);
|
|
600 |
return originalClip;
|
|
603 | 601 |
} |
604 | 602 |
|
603 |
@Override |
|
605 | 604 |
public void print(Graphics2D g, AffineTransform at, Geometry geom, |
606 |
PrintAttributes printAttributes) { |
|
605 |
PrintAttributes printAttributes) {
|
|
607 | 606 |
Rectangle2D.Double rectangleLayout = getBoundingBox(at); |
608 | 607 |
|
609 | 608 |
preDraw(g, rectangleLayout, rectangleLayout); |
... | ... | |
628 | 627 |
double oldDpi = viewPort.getDPI(); |
629 | 628 |
|
630 | 629 |
viewPort.setOffset(new Point2D.Double(layoutRectangle.x, layoutRectangle.y)); |
631 |
viewPort.setImageSize(new Dimension((int) layoutRectangle.width, (int) layoutRectangle.height)); |
|
630 |
viewPort.setImageSize( |
|
631 |
new Dimension( |
|
632 |
(int) layoutRectangle.width, |
|
633 |
(int) layoutRectangle.height |
|
634 |
) |
|
635 |
); |
|
632 | 636 |
double dpi = PrintAttributes.PRINT_QUALITY_DPI[printAttributes.getPrintQuality()]; |
633 | 637 |
viewPort.setDPI(dpi); |
634 | 638 |
|
... | ... | |
636 | 640 |
Color theBackColor = viewPort.getBackColor(); |
637 | 641 |
if (theBackColor != null) { |
638 | 642 |
g.setColor(theBackColor); |
639 |
g.fillRect((int) layoutRectangle.x, (int) layoutRectangle.y, viewPort |
|
640 |
.getImageWidth(), viewPort |
|
641 |
.getImageHeight()); |
|
643 |
g.fillRect( |
|
644 |
(int) layoutRectangle.x, |
|
645 |
(int) layoutRectangle.y, |
|
646 |
viewPort.getImageWidth(), |
|
647 |
viewPort.getImageHeight() |
|
648 |
); |
|
642 | 649 |
} |
643 | 650 |
|
644 | 651 |
//Print the map |
645 | 652 |
try { |
646 | 653 |
this.getMapContext().print(g, getScale(), printAttributes); |
647 |
} catch (ReadException e) { |
|
648 |
NotificationManager.addError(e.getMessage(), e); |
|
649 |
} catch (MapContextException e) { |
|
650 |
NotificationManager.addError(e.getMessage(), e); |
|
654 |
} catch (Exception ex) { |
|
655 |
logger.warn("Can't print frame view.", ex); |
|
651 | 656 |
} |
652 | 657 |
|
653 | 658 |
// Restore offset, imgsize |
... | ... | |
660 | 665 |
/** |
661 | 666 |
* Rellena la unidad de medida en la que est? la vista. |
662 | 667 |
* |
663 |
* @param i |
|
664 |
* entero que representa la unidad de medida de la vista. |
|
668 |
* @param i entero que representa la unidad de medida de la vista. |
|
665 | 669 |
*/ |
666 | 670 |
public void setMapUnits(int i) { |
667 | 671 |
mapUnits = i; |
... | ... | |
683 | 687 |
* @return escala. |
684 | 688 |
*/ |
685 | 689 |
public long getScale() { |
686 |
return (long) getMapContext().getScaleView();
|
|
690 |
return (long) getMapContext().getScaleView();
|
|
687 | 691 |
} |
688 | 692 |
|
689 | 693 |
/** |
690 | 694 |
* Inserta la imagen para repintar el FFrameView. |
691 | 695 |
* |
692 |
* @param bi |
|
693 |
* Imagen para repintar. |
|
696 |
* @param bi Imagen para repintar. |
|
694 | 697 |
*/ |
695 | 698 |
public void setBufferedImage(BufferedImage bi) { |
696 | 699 |
m_image = bi; |
... | ... | |
701 | 704 |
* |
702 | 705 |
* @return Imagen para repintar. |
703 | 706 |
*/ |
707 |
@Override |
|
704 | 708 |
public BufferedImage getBufferedImage() { |
705 | 709 |
return m_image; |
706 | 710 |
} |
... | ... | |
710 | 714 |
* |
711 | 715 |
* @return MAtriz de transformaci?n. |
712 | 716 |
*/ |
717 |
@Override |
|
713 | 718 |
public AffineTransform getATMap() { |
714 | 719 |
return mapAT; |
715 | 720 |
} |
... | ... | |
717 | 722 |
/** |
718 | 723 |
* Inserta la matriz de transformaci?n. |
719 | 724 |
* |
720 |
* @param transform |
|
721 |
* Matriz de transformaci?n. |
|
725 |
* @param transform Matriz de transformaci?n. |
|
722 | 726 |
*/ |
727 |
@Override |
|
723 | 728 |
public void setATMap(AffineTransform transform) { |
724 | 729 |
mapAT = transform; |
725 | 730 |
} |
... | ... | |
727 | 732 |
/** |
728 | 733 |
* Inserta el proyecto. |
729 | 734 |
* |
730 |
* @param p |
|
731 |
* Proyecto. |
|
735 |
* @param p Proyecto. |
|
732 | 736 |
*/ |
737 |
@Override |
|
733 | 738 |
public void setProject(Project p) { |
734 | 739 |
project = p; |
735 | 740 |
} |
736 | 741 |
|
737 | 742 |
/** |
738 |
* @see org.gvsig.app.project.documents.layout.fframes.IFFrame#getNameFFrame() |
|
743 |
* @see |
|
744 |
* org.gvsig.app.project.documents.layout.fframes.IFFrame#getNameFFrame() |
|
739 | 745 |
*/ |
746 |
@Override |
|
740 | 747 |
public String getNameFFrame() { |
741 | 748 |
return PluginServices.getText(this, "Vista") + num; |
742 | 749 |
} |
743 | 750 |
|
751 |
@Override |
|
744 | 752 |
public String getName() { |
745 | 753 |
return PERSISTENCE_DEFINITION_NAME; |
746 | 754 |
} |
747 | 755 |
|
748 |
/** |
|
749 |
* DOCUMENT ME! |
|
750 |
* |
|
751 |
* @param arg0 |
|
752 |
* DOCUMENT ME! |
|
753 |
* |
|
754 |
* @return DOCUMENT ME! |
|
755 |
*/ |
|
756 | 756 |
public boolean compare(Object arg0) { |
757 | 757 |
if (!(arg0 instanceof FFrameView)) { |
758 | 758 |
return false; |
... | ... | |
763 | 763 |
} |
764 | 764 |
|
765 | 765 |
if (Math.abs(this.getBoundBox().getWidth() |
766 |
- (((FFrameView) arg0).getBoundBox().getWidth())) > 0.05) { |
|
766 |
- (((FFrameView) arg0).getBoundBox().getWidth())) > 0.05) {
|
|
767 | 767 |
return false; |
768 | 768 |
} |
769 | 769 |
if (Math.abs(this.getBoundBox().getHeight() |
770 |
- (((FFrameView) arg0).getBoundBox().getHeight())) > 0.05) { |
|
770 |
- (((FFrameView) arg0).getBoundBox().getHeight())) > 0.05) {
|
|
771 | 771 |
return false; |
772 | 772 |
} |
773 | 773 |
|
... | ... | |
776 | 776 |
} |
777 | 777 |
|
778 | 778 |
if (this.getMapContext() != null |
779 |
&& !this.getMapContext() |
|
780 |
.equals(((FFrameView) arg0).getMapContext())) { |
|
779 |
&& !this.getMapContext()
|
|
780 |
.equals(((FFrameView) arg0).getMapContext())) {
|
|
781 | 781 |
return false; |
782 | 782 |
} |
783 | 783 |
|
... | ... | |
788 | 788 |
} |
789 | 789 |
|
790 | 790 |
public void updateScaleCtrl() { |
791 |
NewStatusBar statusbar = PluginServices.getMainFrame().getStatusBar();
|
|
792 |
MapContext mapContext = this.getMapContext();
|
|
793 |
if (mapContext==null) {
|
|
794 |
return;
|
|
795 |
}
|
|
796 |
statusbar.setMessage("units",
|
|
797 |
PluginServices.getText(this, mapContext.getDistanceName()));
|
|
798 |
String scale;
|
|
799 |
if (fixedScale!=null && getScaleType()==SCALE_TYPE.FIXED_SCALE) {
|
|
800 |
// prefer fixedScale as getScaleView() may offer slight differences
|
|
801 |
// because the influence of the adjusted envelope
|
|
802 |
scale = String.valueOf(fixedScale.longValue());
|
|
803 |
}
|
|
804 |
else {
|
|
805 |
scale = String.valueOf(getMapContext().getScaleView());
|
|
806 |
}
|
|
807 |
statusbar.setControlValue("layout-view-change-scale",
|
|
808 |
scale);
|
|
809 |
IProjection proj = mapContext.getViewPort().getProjection();
|
|
810 |
if (proj != null) {
|
|
811 |
statusbar.setMessage("projection", proj.getAbrev());
|
|
812 |
} else {
|
|
813 |
statusbar.setMessage("projection", "");
|
|
814 |
}
|
|
791 |
NewStatusBar statusbar = PluginServices.getMainFrame().getStatusBar();
|
|
792 |
MapContext mapContext = this.getMapContext();
|
|
793 |
if (mapContext == null) {
|
|
794 |
return;
|
|
795 |
}
|
|
796 |
statusbar.setMessage("units",
|
|
797 |
PluginServices.getText(this, mapContext.getDistanceName())
|
|
798 |
);
|
|
799 |
String scale;
|
|
800 |
if (fixedScale != null && getScaleType() == SCALE_TYPE.FIXED_SCALE) {
|
|
801 |
// prefer fixedScale as getScaleView() may offer slight differences
|
|
802 |
// because the influence of the adjusted envelope
|
|
803 |
scale = String.valueOf(fixedScale.longValue());
|
|
804 |
} else {
|
|
805 |
scale = String.valueOf(getMapContext().getScaleView());
|
|
806 |
}
|
|
807 |
statusbar.setControlValue("layout-view-change-scale",
|
|
808 |
scale);
|
|
809 |
IProjection proj = mapContext.getViewPort().getProjection();
|
|
810 |
if (proj != null) {
|
|
811 |
statusbar.setMessage("projection", proj.getAbrev());
|
|
812 |
} else {
|
|
813 |
statusbar.setMessage("projection", "");
|
|
814 |
}
|
|
815 | 815 |
} |
816 | 816 |
|
817 |
@Override |
|
817 | 818 |
public void fullExtent() throws ReadException { |
818 | 819 |
setNewEnvelope(getMapContext().getFullEnvelope()); |
819 | 820 |
} |
820 | 821 |
|
822 |
@Override |
|
821 | 823 |
public void setPointsToZoom(Point2D px1, Point2D px2) { |
822 | 824 |
p1 = px1; |
823 | 825 |
p2 = px2; |
824 | 826 |
} |
825 | 827 |
|
828 |
@Override |
|
826 | 829 |
public void movePoints(Point2D px1, Point2D px2) { |
827 | 830 |
double difX = -px2.getX() + px1.getX(); |
828 | 831 |
double difY = -px2.getY() + px1.getY(); |
... | ... | |
839 | 842 |
frame.createListeners(); // necessary to create the listeners within the right scope |
840 | 843 |
frame.setView(this.getView()); |
841 | 844 |
frame.removeAllListeners(); // remove listeners add by setView |
842 |
|
|
845 |
|
|
843 | 846 |
if (grid != null) { |
844 | 847 |
FFrameGrid newGrid = (FFrameGrid) this.grid.clone(); |
845 | 848 |
newGrid.setFFrameDependence(frame); |
... | ... | |
858 | 861 |
return this.grid; |
859 | 862 |
} |
860 | 863 |
|
864 |
@Override |
|
861 | 865 |
public void setRotation(double rotation) { |
862 | 866 |
super.setRotation(rotation); |
863 | 867 |
if (grid != null) { |
... | ... | |
873 | 877 |
return showGrid; |
874 | 878 |
} |
875 | 879 |
|
880 |
@Override |
|
876 | 881 |
public void refreshOriginalExtent() { |
877 | 882 |
} |
878 | 883 |
|
879 | 884 |
public static void registerPersistent() { |
880 | 885 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
881 | 886 |
if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) { |
882 |
DynStruct definition = |
|
883 |
manager.addDefinition(FFrameView.class,
|
|
887 |
DynStruct definition = manager.addDefinition(
|
|
888 |
FFrameView.class,
|
|
884 | 889 |
PERSISTENCE_DEFINITION_NAME, |
885 |
"FFrameView persistence definition", null, null); |
|
886 |
definition.extend(manager |
|
887 |
.getDefinition(FFrame.PERSISTENCE_DEFINITION_NAME)); |
|
890 |
"FFrameView persistence definition", null, null |
|
891 |
); |
|
892 |
definition.extend( |
|
893 |
manager.getDefinition(FFrame.PERSISTENCE_DEFINITION_NAME) |
|
894 |
); |
|
888 | 895 |
definition.addDynFieldInt(QUALITY_FIELD).setMandatory(true); |
889 | 896 |
definition.addDynFieldInt(MAPUNITS_FIELD).setMandatory(true); |
890 | 897 |
definition.addDynFieldDouble(SCALE_FIELD).setMandatory(false); |
891 | 898 |
definition.addDynFieldObject(VIEW_FIELD) |
892 |
.setClassOfValue(ViewDocument.class).setMandatory(false); |
|
899 |
.setClassOfValue(ViewDocument.class).setMandatory(false);
|
|
893 | 900 |
definition.addDynFieldObject(ENVELOPE_FIELD) |
894 |
.setClassOfValue(Envelope.class).setMandatory(false); |
|
901 |
.setClassOfValue(Envelope.class).setMandatory(false);
|
|
895 | 902 |
definition.addDynFieldBoolean(SHOWGRID_FIELD).setMandatory(true); |
896 | 903 |
definition.addDynFieldObject(GRID_FIELD) |
897 |
.setClassOfValue(IFFrame.class).setMandatory(false); |
|
904 |
.setClassOfValue(IFFrame.class).setMandatory(false);
|
|
898 | 905 |
definition.addDynFieldBoolean(HAS_TOC_FIELD).setMandatory(false); |
899 | 906 |
definition.addDynFieldBoolean(EXTENT_SYNC_FIELD).setMandatory(false); |
900 | 907 |
definition.addDynFieldBoolean(LAYER_SYNC_FIELD).setMandatory(false); |
... | ... | |
904 | 911 |
definition.addDynFieldInt(TYPESCALE_FIELD).setMandatory(false); |
905 | 912 |
definition.addDynFieldBoolean(BLINKED_FIELD).setMandatory(false); |
906 | 913 |
definition.addDynFieldObject(MAPCONTEXT_FIELD) |
907 |
.setClassOfValue(MapContext.class).setMandatory(false); |
|
914 |
.setClassOfValue(MapContext.class).setMandatory(false);
|
|
908 | 915 |
definition.addDynFieldInt(VIEWING_FIELD).setMandatory(false); |
909 | 916 |
definition.addDynFieldInt(EXTENSION_FIELD).setMandatory(false); |
910 | 917 |
} |
... | ... | |
912 | 919 |
|
913 | 920 |
@Override |
914 | 921 |
public void loadFromState(PersistentState state) |
915 |
throws PersistenceException { |
|
922 |
throws PersistenceException {
|
|
916 | 923 |
super.loadFromState(state); |
917 | 924 |
b_frameInitialized = false; |
918 | 925 |
if (state.hasValue(EXTENT_SYNC_FIELD)) { |
919 |
syncExtents = state.getBoolean(EXTENT_SYNC_FIELD); |
|
926 |
syncExtents = state.getBoolean(EXTENT_SYNC_FIELD); |
|
927 |
} else { |
|
928 |
syncExtents = true; |
|
920 | 929 |
} |
921 |
else { |
|
922 |
syncExtents = true; |
|
923 |
} |
|
924 | 930 |
if (state.hasValue(LAYER_SYNC_FIELD)) { |
925 |
syncLayers = state.getBoolean(LAYER_SYNC_FIELD); |
|
931 |
syncLayers = state.getBoolean(LAYER_SYNC_FIELD); |
|
932 |
} else { |
|
933 |
syncLayers = true; |
|
926 | 934 |
} |
927 |
else { |
|
928 |
syncLayers = true; |
|
929 |
} |
|
930 | 935 |
Double layoutScale = null; |
931 | 936 |
if (state.hasValue(SCALE_FIELD)) { |
932 |
layoutScale = state.getDouble(SCALE_FIELD);
|
|
937 |
layoutScale = state.getDouble(SCALE_FIELD);
|
|
933 | 938 |
} |
934 |
Envelope envelope = (Envelope) state.get(ENVELOPE_FIELD);
|
|
939 |
Envelope envelope = (Envelope) state.get(ENVELOPE_FIELD);
|
|
935 | 940 |
|
936 | 941 |
if (state.hasValue(SCALE_TYPE_FIELD)) { |
937 |
int value = state.getInt(SCALE_TYPE_FIELD); |
|
938 |
if (value==SCALE_TYPE.FIXED_EXTENT.ordinal()) { |
|
939 |
scaleType = SCALE_TYPE.FIXED_EXTENT; |
|
940 |
fixedExtent = envelope; |
|
941 |
} |
|
942 |
else if (value==SCALE_TYPE.FIXED_SCALE.ordinal()) { |
|
943 |
scaleType = SCALE_TYPE.FIXED_SCALE; |
|
944 |
fixedScale = layoutScale; |
|
945 |
} |
|
946 |
// else use the default value |
|
942 |
int value = state.getInt(SCALE_TYPE_FIELD); |
|
943 |
if (value == SCALE_TYPE.FIXED_EXTENT.ordinal()) { |
|
944 |
scaleType = SCALE_TYPE.FIXED_EXTENT; |
|
945 |
fixedExtent = envelope; |
|
946 |
} else if (value == SCALE_TYPE.FIXED_SCALE.ordinal()) { |
|
947 |
scaleType = SCALE_TYPE.FIXED_SCALE; |
|
948 |
fixedScale = layoutScale; |
|
949 |
} |
|
950 |
// else use the default value |
|
947 | 951 |
} |
948 | 952 |
quality = state.getInt(QUALITY_FIELD); |
949 | 953 |
mapUnits = state.getInt(MAPUNITS_FIELD); |
950 | 954 |
if (state.hasValue(HAS_TOC_FIELD)) { |
951 |
this.b_hasToc = state.getBoolean(HAS_TOC_FIELD);
|
|
955 |
this.b_hasToc = state.getBoolean(HAS_TOC_FIELD);
|
|
952 | 956 |
} |
953 | 957 |
|
954 | 958 |
// When copying and pasting layout documents (in project manager), the view |
... | ... | |
958 | 962 |
// Therefore, we try to get first the "live" view if available, and get the persisted |
959 | 963 |
// one otherwise, which will be used when opening projects. |
960 | 964 |
ViewDocument persistenceView = (ViewDocument) state.get(VIEW_FIELD); |
961 |
if (persistenceView!= null) { |
|
962 |
ViewDocument view = (ViewDocument) ProjectManager.getInstance().getCurrentProject().getDocument(persistenceView.getName(), persistenceView.getTypeName());
|
|
963 |
if (view==null) {
|
|
964 |
view = persistenceView;
|
|
965 |
}
|
|
966 |
this.setView(view);
|
|
967 |
// it is crucial to don't persist the MapContext and get a cloned one from the View instead,
|
|
968 |
// as the cloned instance is different from the one created using persistence. In particular,
|
|
969 |
// the cloned one will share the EventBuffer with the original one, while persistence would
|
|
970 |
// create 2 separate EventBuffers, which will then have a very stange behaviour
|
|
965 |
if (persistenceView != null) {
|
|
966 |
ViewDocument view = (ViewDocument) ProjectManager.getInstance().getCurrentProject().getDocument(persistenceView.getName(), persistenceView.getTypeName());
|
|
967 |
if (view == null) {
|
|
968 |
view = persistenceView;
|
|
969 |
}
|
|
970 |
this.setView(view);
|
|
971 |
// it is crucial to don't persist the MapContext and get a cloned one from the View instead,
|
|
972 |
// as the cloned instance is different from the one created using persistence. In particular,
|
|
973 |
// the cloned one will share the EventBuffer with the original one, while persistence would
|
|
974 |
// create 2 separate EventBuffers, which will then have a very stange behaviour
|
|
971 | 975 |
} |
972 |
if (getMapContext()!=null) { |
|
973 |
if (layoutScale!=null) { |
|
974 |
getMapContext().setScaleView(layoutScale.longValue()); |
|
975 |
} |
|
976 |
getMapContext().getViewPort().setEnvelope(envelope); |
|
977 |
if (this.getLayoutContext()!=null) { |
|
978 |
this.getLayoutContext().setTocModel(getMapContext()); |
|
979 |
} |
|
980 |
|
|
976 |
if (getMapContext() != null) { |
|
977 |
if (layoutScale != null) { |
|
978 |
getMapContext().setScaleView(layoutScale.longValue()); |
|
979 |
} |
|
980 |
getMapContext().getViewPort().setEnvelope(envelope); |
|
981 |
if (this.getLayoutContext() != null) { |
|
982 |
this.getLayoutContext().setTocModel(getMapContext()); |
|
983 |
} |
|
981 | 984 |
} |
982 | 985 |
showGrid = state.getBoolean(SHOWGRID_FIELD); |
983 | 986 |
grid = (IFFrame) state.get(GRID_FIELD); |
... | ... | |
995 | 998 |
state.set(SCALE_TYPE_FIELD, scaleType.ordinal()); |
996 | 999 |
|
997 | 1000 |
if (getMapContext() != null |
998 |
&& getMapContext().getViewPort().getEnvelope() != null) { |
|
999 |
if (scaleType==SCALE_TYPE.FIXED_SCALE) { |
|
1000 |
if (fixedScale==null) { |
|
1001 |
fixedScale = new Double(getMapContext().getScaleView()); |
|
1002 |
} |
|
1003 |
state.set(SCALE_FIELD, (double)fixedScale); |
|
1004 |
} |
|
1005 |
else { |
|
1006 |
state.set(SCALE_FIELD, (double)getMapContext().getScaleView()); |
|
1007 |
} |
|
1008 |
if (scaleType == SCALE_TYPE.FIXED_EXTENT) { |
|
1009 |
if (fixedExtent==null) { |
|
1010 |
fixedExtent = getMapContext().getViewPort().getAdjustedEnvelope(); |
|
1011 |
} |
|
1012 |
state.set(ENVELOPE_FIELD, fixedExtent); |
|
1013 |
} |
|
1014 |
else { |
|
1015 |
state.set(ENVELOPE_FIELD, getMapContext().getViewPort() |
|
1001 |
&& getMapContext().getViewPort().getEnvelope() != null) { |
|
1002 |
if (scaleType == SCALE_TYPE.FIXED_SCALE) { |
|
1003 |
if (fixedScale == null) { |
|
1004 |
fixedScale = new Double(getMapContext().getScaleView()); |
|
1005 |
} |
|
1006 |
state.set(SCALE_FIELD, (double) fixedScale); |
|
1007 |
} else { |
|
1008 |
state.set(SCALE_FIELD, (double) getMapContext().getScaleView()); |
|
1009 |
} |
|
1010 |
if (scaleType == SCALE_TYPE.FIXED_EXTENT) { |
|
1011 |
if (fixedExtent == null) { |
|
1012 |
fixedExtent = getMapContext().getViewPort().getAdjustedEnvelope(); |
|
1013 |
} |
|
1014 |
state.set(ENVELOPE_FIELD, fixedExtent); |
|
1015 |
} else { |
|
1016 |
state.set(ENVELOPE_FIELD, getMapContext().getViewPort() |
|
1016 | 1017 |
.getAdjustedEnvelope()); |
1017 |
}
|
|
1018 |
}
|
|
1018 | 1019 |
} |
1019 |
|
|
1020 | 1020 |
state.set(SHOWGRID_FIELD, showGrid); |
1021 | 1021 |
state.set(GRID_FIELD, grid); |
1022 | 1022 |
} |
1023 | 1023 |
|
1024 | 1024 |
@Override |
1025 | 1025 |
public void setBoundBox(Rectangle2D r) { |
1026 |
super.setBoundBox(r); |
|
1027 |
if (this.getMapContext()!=null && this.getLayoutContext()!=null) { |
|
1028 |
AffineTransform at = this.getLayoutContext().getAT(); |
|
1029 |
long scale = getMapContext().getScaleView(); |
|
1030 |
getMapContext().getViewPort().setImageSize( |
|
1031 |
new Dimension((int)getBoundingBox(at).getWidth(), (int)getBoundingBox(at).getHeight())); |
|
1032 |
getMapContext().getViewPort().setDPI(getDrawPaperDPI()); |
|
1033 |
if (getScaleType()==SCALE_TYPE.FIXED_SCALE) { |
|
1034 |
getMapContext().setScaleView((long) scale); |
|
1035 |
} |
|
1036 |
updateScaleCtrl(); |
|
1037 |
refresh(); |
|
1038 |
} |
|
1026 |
super.setBoundBox(r); |
|
1027 |
if (this.getMapContext() != null && this.getLayoutContext() != null) { |
|
1028 |
AffineTransform at = this.getLayoutContext().getAT(); |
|
1029 |
long scale = getMapContext().getScaleView(); |
|
1030 |
getMapContext().getViewPort().setImageSize( |
|
1031 |
new Dimension( |
|
1032 |
(int) getBoundingBox(at).getWidth(), |
|
1033 |
(int) getBoundingBox(at).getHeight() |
|
1034 |
) |
|
1035 |
); |
|
1036 |
getMapContext().getViewPort().setDPI(getDrawPaperDPI()); |
|
1037 |
if (getScaleType() == SCALE_TYPE.FIXED_SCALE) { |
|
1038 |
getMapContext().setScaleView((long) scale); |
|
1039 |
} |
|
1040 |
updateScaleCtrl(); |
|
1041 |
refresh(); |
|
1042 |
} |
|
1039 | 1043 |
} |
1040 | 1044 |
|
1041 | 1045 |
/** |
... | ... | |
1047 | 1051 |
return 0; |
1048 | 1052 |
} |
1049 | 1053 |
|
1050 |
protected void invalidateLayout() {
|
|
1051 |
b_validCache = false;
|
|
1052 |
if (getLayoutContext()!=null) {
|
|
1053 |
getLayoutContext().notifAllObservers();
|
|
1054 |
}
|
|
1054 |
protected void invalidateLayout() {
|
|
1055 |
b_validCache = false;
|
|
1056 |
if (getLayoutContext() != null) {
|
|
1057 |
getLayoutContext().notifAllObservers();
|
|
1058 |
}
|
|
1055 | 1059 |
observers.notifyObservers(this, |
1056 |
new DefaultLayoutNotification(LayoutNotification.LAYOUT_REFRESH)); |
|
1057 |
} |
|
1060 |
new DefaultLayoutNotification(LayoutNotification.LAYOUT_REFRESH) |
|
1061 |
); |
|
1062 |
} |
|
1058 | 1063 |
|
1059 |
protected void invalidateToc() {
|
|
1060 |
if (getLayoutContext()!=null) {
|
|
1061 |
getLayoutContext().notifyTocUpdated(TocModelChangedNotification.Type.ITEM_UPDATED);
|
|
1062 |
}
|
|
1063 |
}
|
|
1064 |
protected void invalidateToc() {
|
|
1065 |
if (getLayoutContext() != null) {
|
|
1066 |
getLayoutContext().notifyTocUpdated(TocModelChangedNotification.Type.ITEM_UPDATED);
|
|
1067 |
}
|
|
1068 |
}
|
|
1064 | 1069 |
|
1065 |
protected void refreshToc() {
|
|
1066 |
if (getLayoutContext()!=null) {
|
|
1067 |
getLayoutContext().notifyTocUpdated(TocModelChangedNotification.Type.MODEL_CHANGED);
|
|
1068 |
}
|
|
1069 |
}
|
|
1070 |
protected void refreshToc() {
|
|
1071 |
if (getLayoutContext() != null) {
|
|
1072 |
getLayoutContext().notifyTocUpdated(TocModelChangedNotification.Type.MODEL_CHANGED);
|
|
1073 |
}
|
|
1074 |
}
|
|
1070 | 1075 |
|
1071 |
public void refresh() { |
|
1072 |
// force re-creating the cache on the next drawing cycle |
|
1073 |
b_validCache = false; |
|
1074 |
} |
|
1076 |
@Override |
|
1077 |
public void refresh() { |
|
1078 |
// force re-creating the cache on the next drawing cycle |
|
1079 |
b_validCache = false; |
|
1080 |
} |
|
1075 | 1081 |
|
1076 | 1082 |
protected void createListeners() { |
1077 |
this.removeAllListeners();
|
|
1083 |
this.removeAllListeners();
|
|
1078 | 1084 |
viewDocListener = new ViewDocListener(this); |
1079 |
ownMapContextListener = new OwnMapContextListener(this);
|
|
1085 |
ownMapContextListener = new OwnMapContextListener(this);
|
|
1080 | 1086 |
// logger.info("createListeners.viewDocListener "+ viewDocListener.getID()); |
1081 | 1087 |
// logger.info("createListeners.ownMapContextListener "+ ownMapContextListener.getID()); |
1082 | 1088 |
} |
1083 | 1089 |
|
1084 | 1090 |
protected void addAllListeners() { |
1085 |
if( viewDocListener == null && ownMapContextListener == null ) {
|
|
1091 |
if (viewDocListener == null && ownMapContextListener == null) {
|
|
1086 | 1092 |
this.createListeners(); |
1087 | 1093 |
} |
1088 | 1094 |
if (getView() != null) { |
... | ... | |
1116 | 1122 |
} |
1117 | 1123 |
|
1118 | 1124 |
protected void removeOwnListeners() { |
1119 |
if( this.ownMapContextListener == null ) {
|
|
1125 |
if (this.ownMapContextListener == null) {
|
|
1120 | 1126 |
return; |
1121 | 1127 |
} |
1122 |
if( this.mapContext==null ) {
|
|
1128 |
if (this.mapContext == null) {
|
|
1123 | 1129 |
return; |
1124 | 1130 |
} |
1125 | 1131 |
this.mapContext.removeLayerListener(ownMapContextListener); |
... | ... | |
1129 | 1135 |
} |
1130 | 1136 |
|
1131 | 1137 |
protected void removeViewListeners() { |
1132 |
if( this.viewDocListener == null ) {
|
|
1138 |
if (this.viewDocListener == null) {
|
|
1133 | 1139 |
return; |
1134 | 1140 |
} |
1135 |
if( this.getView()==null ) {
|
|
1141 |
if (this.getView() == null) {
|
|
1136 | 1142 |
return; |
1137 | 1143 |
} |
1138 | 1144 |
MapContext mapContext = this.getView().getMapContext(); |
1139 |
if( mapContext == null ) {
|
|
1145 |
if (mapContext == null) {
|
|
1140 | 1146 |
return; |
1141 | 1147 |
} |
1142 | 1148 |
mapContext.removeLayerListener(viewDocListener); |
... | ... | |
1155 | 1161 |
this.mapContext = null; |
1156 | 1162 |
} |
1157 | 1163 |
|
1158 |
public void frameRemoved() { |
|
1159 |
this.removeAllListeners(); |
|
1160 |
if (b_hasToc && getLayoutContext()!=null) { |
|
1161 |
getLayoutContext().setTocModel(null); |
|
1162 |
} |
|
1163 |
m_image = null; // FIXME: we could instead move it to a LRU cache to keep the last N images |
|
1164 |
} |
|
1164 |
@Override |
|
1165 |
public void frameRemoved() { |
|
1166 |
this.removeAllListeners(); |
|
1167 |
if (b_hasToc && getLayoutContext() != null) { |
|
1168 |
getLayoutContext().setTocModel(null); |
|
1169 |
} |
|
1170 |
m_image = null; // FIXME: we could instead move it to a LRU cache to keep the last N images |
|
1171 |
} |
|
1165 | 1172 |
|
1166 |
public void frameAdded() { |
|
1167 |
addAllListeners(); |
|
1168 |
setTocModel(); |
|
1169 |
updateScaleCtrl(); |
|
1170 |
} |
|
1173 |
@Override |
|
1174 |
public void frameAdded() { |
|
1175 |
addAllListeners(); |
|
1176 |
setTocModel(); |
|
1177 |
updateScaleCtrl(); |
|
1178 |
} |
|
1171 | 1179 |
|
1172 |
public void setHasToc(boolean hasToc) {
|
|
1173 |
this.b_hasToc = hasToc;
|
|
1174 |
setTocModel();
|
|
1175 |
}
|
|
1180 |
public void setHasToc(boolean hasToc) {
|
|
1181 |
this.b_hasToc = hasToc;
|
|
1182 |
setTocModel();
|
|
1183 |
}
|
|
1176 | 1184 |
|
1177 |
protected void setTocModel() { |
|
1178 |
if (getLayoutContext()!=null) { |
|
1179 |
if (b_hasToc && getMapContext()!=null) { |
|
1180 |
getLayoutContext().setTocModel(getMapContext()); |
|
1181 |
} |
|
1182 |
else { |
|
1183 |
getLayoutContext().setTocModel(null); |
|
1184 |
} |
|
1185 |
} |
|
1186 |
} |
|
1185 |
protected void setTocModel() { |
|
1186 |
if (getLayoutContext() != null) { |
|
1187 |
if (b_hasToc && getMapContext() != null) { |
|
1188 |
getLayoutContext().setTocModel(getMapContext()); |
|
1189 |
} else { |
|
1190 |
getLayoutContext().setTocModel(null); |
|
1191 |
} |
|
1192 |
} |
|
1193 |
} |
|
1187 | 1194 |
|
1188 |
@Override
|
|
1189 |
protected void doSetSelected(int selectedStatus) {
|
|
1190 |
boolean oldSelectedStatus = isSelected();
|
|
1191 |
super.doSetSelected(selectedStatus);
|
|
1192 |
if (!oldSelectedStatus && isSelected()) { // changed from not selected to selected
|
|
1193 |
setTocModel();
|
|
1194 |
updateScaleCtrl();
|
|
1195 |
}
|
|
1196 |
}
|
|
1195 |
@Override
|
|
1196 |
protected void doSetSelected(int selectedStatus) {
|
|
1197 |
boolean oldSelectedStatus = isSelected();
|
|
1198 |
super.doSetSelected(selectedStatus);
|
|
1199 |
if (!oldSelectedStatus && isSelected()) { // changed from not selected to selected
|
|
1200 |
setTocModel();
|
|
1201 |
updateScaleCtrl();
|
|
1202 |
}
|
|
1203 |
}
|
|
1197 | 1204 |
|
1198 |
public boolean getLayerSynced() { |
|
1199 |
return syncLayers; |
|
1200 |
} |
|
1205 |
@Override |
|
1206 |
public boolean getLayerSynced() { |
|
1207 |
return syncLayers; |
|
1208 |
} |
|
1201 | 1209 |
|
1202 |
public void setLayerSynced(boolean synced) { |
|
1210 |
@Override |
|
1211 |
public void setLayerSynced(boolean synced) { |
|
1203 | 1212 |
syncLayers = synced; |
1204 | 1213 |
resetAllListeners(); |
1205 |
}
|
|
1214 |
}
|
|
1206 | 1215 |
|
1207 |
public boolean getExtentSynced() { |
|
1208 |
return syncExtents; |
|
1209 |
} |
|
1216 |
@Override |
|
1217 |
public boolean getExtentSynced() { |
|
1218 |
return syncExtents; |
|
1219 |
} |
|
1210 | 1220 |
|
1211 |
public void setExtentSynced(boolean synced) { |
|
1212 |
syncExtents = synced; |
|
1221 |
@Override |
|
1222 |
public void setExtentSynced(boolean synced) { |
|
1223 |
syncExtents = synced; |
|
1213 | 1224 |
resetAllListeners(); |
1214 |
}
|
|
1225 |
}
|
|
1215 | 1226 |
|
1216 |
/** |
|
1217 |
* Returns true if the newEnvelope represents a pan operation on oldEnvelope, |
|
1218 |
* (both extents have the same height and width) |
|
1219 |
*/ |
|
1220 |
public static boolean isPan(Envelope oldEnvelope, Envelope newEnvelope) { |
|
1221 |
if (oldEnvelope!=null && newEnvelope!=null) { |
|
1222 |
double toleranceX = 0.00000001*Math.min(oldEnvelope.getLength(0), newEnvelope.getLength(0)); |
|
1223 |
double toleranceY = 0.00000001*Math.min(oldEnvelope.getLength(1), newEnvelope.getLength(1)); |
|
1227 |
/** |
|
1228 |
* Returns true if the newEnvelope represents a pan operation on |
|
1229 |
* oldEnvelope, (both extents have the same height and width) |
|
1230 |
* |
|
1231 |
* @param oldEnvelope |
|
1232 |
* @param newEnvelope |
|
1233 |
* @return |
|
1234 |
*/ |
|
1235 |
public static boolean isPan(Envelope oldEnvelope, Envelope newEnvelope) { |
|
1236 |
if (oldEnvelope != null && newEnvelope != null) { |
|
1237 |
double toleranceX = 0.00000001 * Math.min( |
|
1238 |
oldEnvelope.getLength(0), newEnvelope.getLength(0) |
|
1239 |
); |
|
1240 |
double toleranceY = 0.00000001 * Math.min( |
|
1241 |
oldEnvelope.getLength(1), newEnvelope.getLength(1) |
|
1242 |
); |
|
1224 | 1243 |
|
1225 |
// we consider it to be a pan if both lengths are equal
|
|
1226 |
// (we use tolerance to avoid direct comparison of double values)
|
|
1227 |
if ( ((oldEnvelope.getLength(0)-newEnvelope.getLength(0))<toleranceX)
|
|
1228 |
&& ((oldEnvelope.getLength(1)-newEnvelope.getLength(1))<toleranceY) ) {
|
|
1229 |
return true;
|
|
1230 |
}
|
|
1231 |
}
|
|
1232 |
return false;
|
|
1233 |
}
|
|
1244 |
// we consider it to be a pan if both lengths are equal
|
|
1245 |
// (we use tolerance to avoid direct comparison of double values)
|
|
1246 |
if (((oldEnvelope.getLength(0) - newEnvelope.getLength(0)) < toleranceX)
|
|
1247 |
&& ((oldEnvelope.getLength(1) - newEnvelope.getLength(1)) < toleranceY)) {
|
|
1248 |
return true;
|
|
1249 |
}
|
|
1250 |
}
|
|
1251 |
return false;
|
|
1252 |
}
|
|
1234 | 1253 |
|
1235 |
/** |
|
1236 |
* Calculates the new extent for the FFrame. It is necessary to avoid |
|
1237 |
* scale changes when a pan is triggered from the view, as the different |
|
1238 |
* size factors from View/FFrameView introduces scale changes even for |
|
1239 |
* pans |
|
1240 |
* |
|
1241 |
* @param newEnvelope |
|
1242 |
* @return |
|
1243 |
*/ |
|
1244 |
protected Envelope calculateNewExtent() { |
|
1245 |
Envelope newEnvelope = getView().getMapContext().getViewPort().getEnvelope(); |
|
1246 |
Envelope oldViewEnvelope = null; |
|
1247 |
try { |
|
1248 |
if (getView().getMapContext().getViewPort().getEnvelopes().hasPrevious()) { |
|
1249 |
Rectangle2D r = getView().getMapContext().getViewPort().getEnvelopes().getPrev(); |
Also available in: Unified diff