26 |
import java.util.Map; |
import java.util.Map; |
27 |
import java.util.Vector; |
import java.util.Vector; |
28 |
|
|
29 |
|
import javax.jws.soap.SOAPBinding.Style; |
30 |
import javax.swing.Timer; |
import javax.swing.Timer; |
31 |
|
|
32 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
33 |
import org.geotools.feature.FeatureCollection; |
import org.geotools.feature.FeatureCollection; |
|
import org.geotools.geometry.Envelope2D; |
|
34 |
import org.geotools.geometry.jts.JTS; |
import org.geotools.geometry.jts.JTS; |
35 |
import org.geotools.geometry.jts.ReferencedEnvelope; |
import org.geotools.geometry.jts.ReferencedEnvelope; |
36 |
import org.geotools.map.DefaultMapContext; |
import org.geotools.map.DefaultMapContext; |
44 |
import org.geotools.renderer.GTRenderer; |
import org.geotools.renderer.GTRenderer; |
45 |
import org.geotools.renderer.label.LabelCacheImpl; |
import org.geotools.renderer.label.LabelCacheImpl; |
46 |
import org.geotools.renderer.lite.LabelCache; |
import org.geotools.renderer.lite.LabelCache; |
47 |
|
import org.geotools.renderer.lite.RendererUtilities; |
48 |
import org.geotools.renderer.lite.StreamingRenderer; |
import org.geotools.renderer.lite.StreamingRenderer; |
49 |
import org.geotools.swing.JMapPane; |
import org.geotools.swing.JMapPane; |
50 |
import org.geotools.swing.event.MapMouseEvent; |
import org.geotools.swing.event.MapMouseEvent; |
99 |
private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB; |
private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB; |
100 |
private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_INT_ARGB; |
private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_INT_ARGB; |
101 |
|
|
102 |
private static Logger LOGGER = Logger.getLogger(XMapPane.class); |
private final static Logger LOGGER = Logger.getLogger(XMapPane.class); |
103 |
|
|
104 |
private boolean acceptsRepaintCalls = true; |
private boolean acceptsRepaintCalls = true; |
105 |
|
|
125 |
* regularly and {@link #repaint()}. This {@link Timer} is stopped when all |
* regularly and {@link #repaint()}. This {@link Timer} is stopped when all |
126 |
* renderers have finished. |
* renderers have finished. |
127 |
* |
* |
128 |
* @see #INITIAL_REPAINT_DELAYAL |
* @see INITIAL_REPAINT_DELAYAL |
129 |
* @see #REPEATING_REPAINT_DELAY |
* @see #REPEATING_REPAINT_DELAY |
130 |
*/ |
*/ |
131 |
final private Timer repaintTimer; |
final private Timer repaintTimer; |
134 |
* The initial delay in milliseconds until the {@link #finalImage} is |
* The initial delay in milliseconds until the {@link #finalImage} is |
135 |
* updated the first time. |
* updated the first time. |
136 |
*/ |
*/ |
137 |
public static final int INITIAL_REPAINT_DELAY = 1000; |
public static final int INITIAL_REPAINT_DELAY = 900; |
138 |
|
|
139 |
/** |
/** |
140 |
* While the {@link #bgExecuter} and {@link #localExecuter} are rendering, |
* While the {@link #bgExecuter} and {@link #localExecuter} are rendering, |
141 |
* the {@link #repaintTimer} is regularly updating the {@link #finalImage} |
* the {@link #repaintTimer} is regularly updating the {@link #finalImage} |
142 |
* with previews. |
* with previews. |
143 |
*/ |
*/ |
144 |
public static final long REPEATING_REPAINT_DELAY = 500; |
public static final int REPEATING_REPAINT_DELAY = 500; |
145 |
|
|
146 |
/** |
/** |
147 |
* Default delay (milliseconds) before the map will be redrawn when resizing |
* Default delay (milliseconds) before the map will be redrawn when resizing |
148 |
* the pane. This is to avoid flickering while drag-resizing. |
* the pane. This is to avoid flickering while drag-resizing. |
149 |
|
* |
150 |
|
* @see #resizeTimer |
151 |
|
*/ |
152 |
|
public static final int DEFAULT_RESIZING_PAINT_DELAY = 600; |
153 |
|
|
154 |
|
/** |
155 |
|
* This not-repeating {@link Timer} is re-started whenever the component is |
156 |
|
* resized. That means => only if the component is not resizing for |
157 |
|
* {@link #DEFAULT_RESIZING_PAINT_DELAY} milliseconds, does the |
158 |
|
* {@link XMapPane} react. |
159 |
*/ |
*/ |
160 |
public static final int DEFAULT_RESIZING_PAINT_DELAY = 500; |
private final Timer resizeTimer; |
161 |
|
|
162 |
|
/** |
163 |
|
* Flag for no-tool. |
164 |
|
*/ |
165 |
public static final int NONE = -123; |
public static final int NONE = -123; |
166 |
|
|
167 |
/** |
/** |
173 |
public static final int PAN = 1; |
public static final int PAN = 1; |
174 |
|
|
175 |
/** |
/** |
176 |
|
* Flag fuer Modus "Heran zoomen". |
177 |
|
* |
178 |
|
* @see #setState(int) |
179 |
|
* @see #setState(int) |
180 |
|
*/ |
181 |
|
public static final int ZOOM_IN = 2; |
182 |
|
|
183 |
|
/** |
184 |
|
* Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich! |
185 |
|
* |
186 |
|
* @see #setState(int) |
187 |
|
*/ |
188 |
|
public static final int ZOOM_OUT = 3; |
189 |
|
|
190 |
|
/** |
191 |
* Flag fuer Modus "SimpleFeature-Auswahl auf allen (sichtbaren) Layern". |
* Flag fuer Modus "SimpleFeature-Auswahl auf allen (sichtbaren) Layern". |
192 |
* |
* |
193 |
* @see #setState(int) |
* @see #setState(int) |
211 |
*/ |
*/ |
212 |
public static final int SELECT_TOP = 4; |
public static final int SELECT_TOP = 4; |
213 |
|
|
214 |
public static final Cursor WAIT_CURSOR = Cursor |
/** |
215 |
.getPredefinedCursor(Cursor.WAIT_CURSOR); |
* {@link Font} used to paint the wait messages into the map |
216 |
|
* |
217 |
|
* @see #addGadgets(Graphics2D, boolean) |
218 |
|
*/ |
219 |
final static Font waitFont = new Font("Arial", Font.BOLD, 30); |
final static Font waitFont = new Font("Arial", Font.BOLD, 30); |
|
final String waitMsg = SwingUtil.R("WaitMess"); |
|
|
final static Font errorFont = new Font("Arial", Font.BOLD, 13); |
|
220 |
|
|
221 |
/** |
/** |
222 |
* Flag fuer Modus "Heran zoomen". |
* {@link Font} used to paint error messages into the map |
223 |
* |
* |
224 |
* @see #setState(int) |
* @see #addGadgets(Graphics2D, boolean) |
|
* @see #setState(int) |
|
225 |
*/ |
*/ |
226 |
public static final int ZOOM_IN = 2; |
final static Font errorFont = new Font("Arial", Font.BOLD, 13); |
227 |
|
|
228 |
/** |
/** |
229 |
* Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich! |
* The wait message painted into the map while rendering is going on on |
230 |
|
* another thread. |
231 |
* |
* |
232 |
* @see #setState(int) |
* @see #addGadgets(Graphics2D, boolean) |
233 |
*/ |
*/ |
234 |
public static final int ZOOM_OUT = 3; |
final String waitMsg = SwingUtil.R("WaitMess"); |
235 |
|
|
236 |
/** |
/** |
237 |
* Konvertiert die Maus-Koordinaten (relativ zum <code>JMapPane</code>) in |
* Konvertiert die Maus-Koordinaten (relativ zum <code>JMapPane</code>) in |
277 |
|
|
278 |
@Override |
@Override |
279 |
public void layerAdded(final MapLayerListEvent event) { |
public void layerAdded(final MapLayerListEvent event) { |
|
|
|
280 |
MapLayer layer = event.getLayer(); |
MapLayer layer = event.getLayer(); |
|
|
|
281 |
layer.addMapLayerListener(bgMapLayerListener); |
layer.addMapLayerListener(bgMapLayerListener); |
|
|
|
|
if (localContext.getLayers().length == 0 |
|
|
&& bgContext.getLayers().length == 1) { // the first one and |
|
|
// localContext is |
|
|
// empty |
|
|
if (!setMapArea(localContext.getAreaOfInterest())) |
|
|
requestStartRendering(); |
|
|
return; |
|
|
} |
|
|
|
|
|
// We need to redraw, even in case that the mapArea didn't change |
|
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
282 |
requestStartRendering(); |
requestStartRendering(); |
283 |
|
|
284 |
} |
} |
285 |
|
|
286 |
@Override |
@Override |
287 |
public void layerChanged(final MapLayerListEvent event) { |
public void layerChanged(final MapLayerListEvent event) { |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
288 |
requestStartRendering(); |
requestStartRendering(); |
289 |
} |
} |
290 |
|
|
291 |
@Override |
@Override |
292 |
public void layerMoved(final MapLayerListEvent event) { |
public void layerMoved(final MapLayerListEvent event) { |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
293 |
requestStartRendering(); |
requestStartRendering(); |
294 |
} |
} |
295 |
|
|
297 |
public void layerRemoved(final MapLayerListEvent event) { |
public void layerRemoved(final MapLayerListEvent event) { |
298 |
if (event.getLayer() != null) |
if (event.getLayer() != null) |
299 |
event.getLayer().removeMapLayerListener(bgMapLayerListener); |
event.getLayer().removeMapLayerListener(bgMapLayerListener); |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
300 |
requestStartRendering(); |
requestStartRendering(); |
301 |
} |
} |
302 |
}; |
}; |
303 |
|
|
304 |
/** |
/** |
305 |
* compass and icon are rendered into this image |
* This {@link RenderingExecutor} manages the creation and cancellation of |
306 |
|
* up to one {@link Thread} for rendering the {@link #localContext}. |
307 |
*/ |
*/ |
308 |
// protected BufferedImage gadgetsImage; |
private final RenderingExecutor localExecuter = new RenderingExecutor(this); |
309 |
|
|
310 |
|
/** |
311 |
|
* This {@link RenderingExecutor} manages the creation and cancellation of |
312 |
|
* up to one {@link Thread} for rendering the {@link #bgContext}. |
313 |
|
*/ |
314 |
protected RenderingExecutor bgExecuter; |
protected RenderingExecutor bgExecuter; |
315 |
|
|
316 |
/** |
/** |
317 |
* The Renderer for the LocalLayers uses this Image. When set to null, |
* The {@link #localRenderer} for the {@link #localContext} uses this |
318 |
* please dispose this {@link Graphics2D} |
* {@link Image}. |
319 |
*/ |
*/ |
320 |
private BufferedImage localImage; |
private BufferedImage localImage; |
321 |
|
|
|
private BufferedImage finalImage; |
|
322 |
/** |
/** |
323 |
* If # {@link #bgExecuter} is using {@link #bgRenderer} for the Background |
* The {@link #bgRenderer} for the {@link #bgContext} uses this |
324 |
* uses this Image. When set to null, please dispose the {@link Graphics2D} |
* {@link Image}. |
325 |
*/ |
*/ |
326 |
private BufferedImage bgImage; |
private BufferedImage bgImage; |
327 |
|
|
328 |
/** |
/** |
329 |
|
* This {@link Image} is a merge of the {@link #bgImage}, |
330 |
|
* {@link #localImage} and {@link #addGadgets(Graphics2D, boolean)}. It is |
331 |
|
* updated with {@link #updateFinalImage()} and used for painting in |
332 |
|
* {@link #paintComponent(Graphics)} |
333 |
|
*/ |
334 |
|
private BufferedImage finalImage; |
335 |
|
|
336 |
|
/** |
337 |
* Optionally a transparent image to paint over the map in the lower right |
* Optionally a transparent image to paint over the map in the lower right |
338 |
* corner. |
* corner. |
339 |
* |
* |
350 |
|
|
351 |
@Override |
@Override |
352 |
public void layerChanged(final MapLayerEvent event) { |
public void layerChanged(final MapLayerEvent event) { |
|
// Change of SLD for example |
|
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
353 |
requestStartRendering(); |
requestStartRendering(); |
354 |
} |
} |
355 |
|
|
356 |
@Override |
@Override |
357 |
public void layerHidden(final MapLayerEvent event) { |
public void layerHidden(final MapLayerEvent event) { |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
358 |
requestStartRendering(); |
requestStartRendering(); |
359 |
} |
} |
360 |
|
|
361 |
@Override |
@Override |
362 |
public void layerShown(final MapLayerEvent event) { |
public void layerShown(final MapLayerEvent event) { |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
363 |
requestStartRendering(); |
requestStartRendering(); |
364 |
} |
} |
365 |
}; |
}; |
396 |
public void layerAdded(final MapLayerListEvent event) { |
public void layerAdded(final MapLayerListEvent event) { |
397 |
event.getLayer().addMapLayerListener(localMapLayerListener); |
event.getLayer().addMapLayerListener(localMapLayerListener); |
398 |
|
|
399 |
localRenderer.setContext(getContext()); |
getLocalRenderer().setContext(getMapContext()); |
|
|
|
|
if (localContext.getLayers().length == 1) { // the first one |
|
|
// if the Area of Interest is unset, the LayerBounds are used |
|
|
if (!setMapArea(localContext.getAreaOfInterest())) |
|
|
repaint(); |
|
|
|
|
|
return; |
|
|
} |
|
|
|
|
|
// We need to redraw, even in case that the mapArea didn't change |
|
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
400 |
requestStartRendering(); |
requestStartRendering(); |
401 |
|
|
402 |
} |
} |
403 |
|
|
404 |
@Override |
@Override |
405 |
public void layerChanged(final MapLayerListEvent event) { |
public void layerChanged(final MapLayerListEvent event) { |
406 |
// mapImageInvalid = true; |
// localRenderer = GTUtil.createGTRenderer(); |
407 |
// repaint(); |
getLocalRenderer().setContext(getMapContext()); |
|
localRenderer.setContext(getContext()); |
|
408 |
requestStartRendering(); |
requestStartRendering(); |
409 |
} |
} |
410 |
|
|
411 |
@Override |
@Override |
412 |
public void layerMoved(final MapLayerListEvent event) { |
public void layerMoved(final MapLayerListEvent event) { |
413 |
// mapImageInvalid = true; |
getLocalRenderer().setContext(getMapContext()); |
|
// repaint(); |
|
|
localRenderer.setContext(getContext()); |
|
414 |
requestStartRendering(); |
requestStartRendering(); |
415 |
} |
} |
416 |
|
|
418 |
public void layerRemoved(final MapLayerListEvent event) { |
public void layerRemoved(final MapLayerListEvent event) { |
419 |
if (event.getLayer() != null) |
if (event.getLayer() != null) |
420 |
event.getLayer().removeMapLayerListener(localMapLayerListener); |
event.getLayer().removeMapLayerListener(localMapLayerListener); |
421 |
// mapImageInvalid = true; |
getLocalRenderer().setContext(getMapContext()); |
|
// repaint(); |
|
|
localRenderer.setContext(getContext()); |
|
422 |
requestStartRendering(); |
requestStartRendering(); |
423 |
} |
} |
424 |
}; |
}; |
425 |
|
|
|
private final RenderingExecutor localExecuter = new RenderingExecutor(this); |
|
|
|
|
426 |
/** |
/** |
427 |
* Listens to each layer in the local {@link MapContext} for changes and |
* Listens to each layer in the local {@link MapContext} for changes and |
428 |
* triggers repaints. |
* triggers repaints. |
431 |
|
|
432 |
@Override |
@Override |
433 |
public void layerChanged(final MapLayerEvent event) { |
public void layerChanged(final MapLayerEvent event) { |
434 |
localRenderer.setContext(getContext()); // betters for SLD changes?! |
getLocalRenderer().setContext(getMapContext()); // betters for SLD |
435 |
// Change of SLD for example |
// changes?! |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
436 |
requestStartRendering(); |
requestStartRendering(); |
437 |
} |
} |
438 |
|
|
439 |
@Override |
@Override |
440 |
public void layerHidden(final MapLayerEvent event) { |
public void layerHidden(final MapLayerEvent event) { |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
441 |
requestStartRendering(); |
requestStartRendering(); |
442 |
} |
} |
443 |
|
|
444 |
@Override |
@Override |
445 |
public void layerShown(final MapLayerEvent event) { |
public void layerShown(final MapLayerEvent event) { |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
446 |
requestStartRendering(); |
requestStartRendering(); |
447 |
} |
} |
448 |
}; |
}; |
449 |
|
|
450 |
private final GTRenderer localRenderer = GTUtil.createGTRenderer(); |
final private GTRenderer localRenderer = GTUtil.createGTRenderer(); |
451 |
|
|
452 |
private final GTRenderer bgRenderer = GTUtil.createGTRenderer(); |
private final GTRenderer bgRenderer = GTUtil.createGTRenderer(); |
453 |
|
|
468 |
/** |
/** |
469 |
* This color is used as the default background color when painting a map. |
* This color is used as the default background color when painting a map. |
470 |
*/ |
*/ |
471 |
private Color mapBackgroundColor = Color.WHITE; |
private Color mapBackgroundColor = null; |
472 |
|
|
473 |
/** |
/** |
474 |
* A flag indicating that the shown image is invalid and needs to be |
* A flag indicating that the shown image is invalid and needs to be |
512 |
* A flag indicating, that the image size has changed and the buffered |
* A flag indicating, that the image size has changed and the buffered |
513 |
* images are not big enough any more |
* images are not big enough any more |
514 |
**/ |
**/ |
515 |
protected boolean paneResized = false; |
protected boolean paneResized = true; |
516 |
|
|
517 |
private BufferedImage preFinalImage; |
private BufferedImage preFinalImage; |
518 |
|
|
519 |
// if null, no quick preview will be shown |
// ** if 0, no quick preview will be shown **/ |
520 |
private int quickPreviewHint = 0; |
private int quickPreviewHint = 0; |
521 |
|
|
522 |
private Map<Object, Object> rendererHints = GTUtil |
private Map<Object, Object> rendererHints = GTUtil |
523 |
.getDefaultGTRendererHints(localRenderer); |
.getDefaultGTRendererHints(getLocalRenderer()); |
524 |
|
|
525 |
|
/** |
526 |
|
* If set to <code>true</code>, the {@link #startRenderThreadsTimer} will |
527 |
|
* start rendering {@link Thread}s |
528 |
|
**/ |
529 |
private volatile Boolean requestStartRendering = false; |
private volatile Boolean requestStartRendering = false; |
530 |
|
|
|
private final Timer resizeTimer; |
|
|
|
|
|
private final int resizingPaintDelay; |
|
|
|
|
531 |
/** |
/** |
532 |
* Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten |
* Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten |
533 |
* (lat/lon) |
* (lat/lon) |
564 |
/** Is set if a renderer has an error **/ |
/** Is set if a renderer has an error **/ |
565 |
protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>(); |
protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>(); |
566 |
|
|
567 |
// TODO doku |
/** |
568 |
|
* If <code>true</code>, then rendering exceptions are rendererd into the |
569 |
|
* map pane |
570 |
|
**/ |
571 |
|
private boolean showExceptions = false; |
572 |
|
|
573 |
public XMapPane() { |
public XMapPane() { |
574 |
this(null, null); |
this(null, null); |
575 |
} |
} |
578 |
* full constructor extending JPanel |
* full constructor extending JPanel |
579 |
* |
* |
580 |
* @param rendererHints |
* @param rendererHints |
581 |
|
* may be <code>null</code>. Otherwise a {@link Map<Object, |
582 |
|
* Object>} of {@link RenderingHints} to override the default |
583 |
|
* from {@link GTUtil#getDefaultGTRendererHints(GTRenderer)} |
584 |
* |
* |
|
* @param layout |
|
|
* - layout (probably shouldn't be set) |
|
|
* @param isDoubleBuffered |
|
|
* - a Swing thing I don't really understand |
|
|
* @param render |
|
|
* - what to draw the map with |
|
585 |
* @param localContext |
* @param localContext |
586 |
* - {@link MapContext} of layer to render. |
* The main {@link MapContext} to use. If <code>null</code>, an |
587 |
|
* empty {@link DefaultMapContext} will be created. |
588 |
*/ |
*/ |
589 |
public XMapPane(final MapContext localContext_, |
public XMapPane(final MapContext localContext_, |
590 |
final Map<Object, Object> rendererHints) { |
final Map<Object, Object> rendererHints) { |
611 |
* Using a ComponentListener doesn't work because, unlike a JFrame, the |
* Using a ComponentListener doesn't work because, unlike a JFrame, the |
612 |
* pane receives a stream of events during drag-resizing. |
* pane receives a stream of events during drag-resizing. |
613 |
*/ |
*/ |
614 |
resizingPaintDelay = DEFAULT_RESIZING_PAINT_DELAY; |
resizeTimer = new Timer(DEFAULT_RESIZING_PAINT_DELAY, |
615 |
resizeTimer = new Timer(resizingPaintDelay, new ActionListener() { |
new ActionListener() { |
|
|
|
|
public void actionPerformed(final ActionEvent e) { |
|
|
paneResized = true; |
|
|
|
|
|
if (!isWellDefined()) |
|
|
return; |
|
616 |
|
|
617 |
final Rectangle bounds = getVisibleRect(); |
public void actionPerformed(final ActionEvent e) { |
618 |
|
if (!isWellDefined()) |
619 |
|
return; |
620 |
|
|
621 |
final Envelope geoMapArea = tranformWindowToGeo(bounds.x, |
LOGGER.debug("resizeTimer performed"); |
|
bounds.y, bounds.x + bounds.width, bounds.y |
|
|
+ bounds.height); |
|
622 |
|
|
623 |
setMapArea(bestAllowedMapArea(geoMapArea)); |
final Rectangle bounds = getVisibleRect(); |
624 |
} |
// |
625 |
}); |
// System.out.println("\n\ntimer performs with bounds = " |
626 |
|
// + bounds); |
627 |
|
|
628 |
|
final Envelope geoMapArea = tranformWindowToGeo( |
629 |
|
bounds.x, bounds.y, bounds.x + bounds.width, |
630 |
|
bounds.y + bounds.height); |
631 |
|
|
632 |
|
if (setMapArea(geoMapArea)) { |
633 |
|
LOGGER.debug(" maparea changed"); |
634 |
|
paneResized = true; |
635 |
|
} else |
636 |
|
LOGGER.debug(" maparea NOT changed"); |
637 |
|
} |
638 |
|
}); |
639 |
resizeTimer.setRepeats(false); |
resizeTimer.setRepeats(false); |
640 |
|
|
641 |
this.addComponentListener(new ComponentAdapter() { |
this.addComponentListener(new ComponentAdapter() { |
642 |
|
|
643 |
|
private Rectangle oldVisibleRect; |
644 |
|
|
645 |
@Override |
@Override |
646 |
public void componentResized(final ComponentEvent e) { |
public void componentResized(final ComponentEvent e) { |
647 |
if (bgExecuter != null) |
|
648 |
bgExecuter.cancelTask(); |
// Seems to be called twice with the same size.. |
649 |
if (localExecuter != null) |
if (oldVisibleRect != null |
650 |
localExecuter.cancelTask(); |
&& oldVisibleRect.equals(getVisibleRect())) { |
651 |
|
LOGGER.debug("skipping resize."); |
652 |
|
return; |
653 |
|
} |
654 |
|
|
655 |
|
LOGGER.debug("resized: " + getVisibleRect()); |
656 |
resizeTimer.restart(); |
resizeTimer.restart(); |
657 |
|
oldVisibleRect = getVisibleRect(); |
658 |
} |
} |
659 |
|
|
660 |
}); |
}); |
662 |
/* |
/* |
663 |
* Setting up the repaintTimer. Not started automatically. |
* Setting up the repaintTimer. Not started automatically. |
664 |
*/ |
*/ |
665 |
repaintTimer = new Timer((int) REPEATING_REPAINT_DELAY, |
repaintTimer = new Timer(REPEATING_REPAINT_DELAY, new ActionListener() { |
666 |
new ActionListener() { |
|
667 |
|
@Override |
668 |
|
public void actionPerformed(final ActionEvent e) { |
669 |
|
if ((!localExecuter.isRunning()) |
670 |
|
&& (bgExecuter != null && !bgExecuter.isRunning())) { |
671 |
|
repaintTimer.stop(); |
672 |
|
} else { |
673 |
|
updateFinalImage(); |
674 |
|
XMapPane.this.repaint(100); |
675 |
|
|
676 |
|
} |
677 |
|
} |
678 |
|
}); |
679 |
|
|
|
@Override |
|
|
public void actionPerformed(final ActionEvent e) { |
|
|
updateFinalImage(); |
|
|
XMapPane.this.repaint(); |
|
|
} |
|
|
}); |
|
680 |
repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY); |
repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY); |
681 |
repaintTimer.setRepeats(true); |
repaintTimer.setRepeats(true); |
682 |
|
|
694 |
if (localExecuter.isRunning()) { |
if (localExecuter.isRunning()) { |
695 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
696 |
} else { |
} else { |
697 |
|
// Stupidly, but we have to recheck the |
698 |
|
setMapArea(getMapArea()); |
699 |
requestStartRendering = false; |
requestStartRendering = false; |
700 |
startRendering(); |
startRendering(); |
701 |
} |
} |
728 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons |
729 |
* Krüger</a> |
* Krüger</a> |
730 |
*/ |
*/ |
731 |
public Envelope bestAllowedMapArea(Envelope env) { |
public ReferencedEnvelope bestAllowedMapArea(ReferencedEnvelope env) { |
732 |
|
|
733 |
if (getWidth() == 0) |
if (getWidth() == 0) |
734 |
return env; |
return env; |
735 |
|
|
736 |
if (env == null) |
if (env == null) |
737 |
return null; |
return null; |
738 |
|
|
782 |
} |
} |
783 |
|
|
784 |
final Envelope maxAllowedExtend = getMaxExtend(); |
final Envelope maxAllowedExtend = getMaxExtend(); |
785 |
|
|
786 |
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) |
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) |
787 |
&& newArea != null && !newArea.isNull() |
&& newArea != null && !newArea.isNull() |
788 |
&& !Double.isNaN(newArea.getMinX()) |
&& !Double.isNaN(newArea.getMinX()) |
812 |
|
|
813 |
// LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
814 |
|
|
815 |
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, |
newArea = JTSUtil.fixAspectRatio(getVisibleRect(), |
816 |
false); |
new ReferencedEnvelope(newArea, env |
817 |
|
.getCoordinateReferenceSystem()), false); |
818 |
} |
} |
819 |
} |
} |
820 |
|
|
837 |
|
|
838 |
// LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
839 |
|
|
840 |
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, |
newArea = JTSUtil.fixAspectRatio(getVisibleRect(), |
841 |
false); |
new ReferencedEnvelope(newArea, env |
842 |
|
.getCoordinateReferenceSystem()), false); |
843 |
} |
} |
844 |
} |
} |
845 |
|
|
864 |
|
|
865 |
// LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
866 |
|
|
867 |
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, |
newArea = JTSUtil.fixAspectRatio(getVisibleRect(), |
868 |
false); |
new ReferencedEnvelope(newArea, env |
869 |
|
.getCoordinateReferenceSystem()), false); |
870 |
} |
} |
871 |
} |
} |
872 |
|
|
891 |
|
|
892 |
// LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
893 |
|
|
894 |
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, |
newArea = JTSUtil.fixAspectRatio(getVisibleRect(), |
895 |
false); |
new ReferencedEnvelope(newArea, env |
896 |
|
.getCoordinateReferenceSystem()), false); |
897 |
} |
} |
898 |
} |
} |
899 |
} |
} |
900 |
|
|
901 |
return newArea; |
return new ReferencedEnvelope(newArea, env |
902 |
|
.getCoordinateReferenceSystem()); |
903 |
} |
} |
904 |
|
|
905 |
/** |
/** |
927 |
bgExecuter.dispose(); |
bgExecuter.dispose(); |
928 |
} |
} |
929 |
|
|
930 |
if (localExecuter != null) { |
if (localExecuter.isRunning()) { |
931 |
int i = 0; |
int i = 0; |
932 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
933 |
while (i++ < 10 && localExecuter.isRunning()) { |
while (i++ < 10 && localExecuter.isRunning()) { |
934 |
try { |
try { |
935 |
Thread.sleep(100); |
Thread.sleep(200); |
936 |
} catch (final InterruptedException e) { |
} catch (final InterruptedException e) { |
937 |
// TODO Auto-generated catch block |
LOGGER |
938 |
e.printStackTrace(); |
.warn( |
939 |
|
"while XMapPane we are waiting for the localExcutor to stop", |
940 |
|
e); |
941 |
} |
} |
942 |
} |
} |
943 |
if (localExecuter.isRunning()) { |
if (localExecuter.isRunning()) { |
944 |
System.out |
LOGGER |
945 |
.println("BAD BAD BAD... still running the thread...."); |
.warn("localExecutor Thread still running after 2s! Continuing anyways..."); |
946 |
} |
} |
947 |
localExecuter.dispose(); |
localExecuter.dispose(); |
948 |
} |
} |
|
// |
|
|
// if (bgImage != null) { |
|
|
// bgImage = dispose(bgImage); |
|
|
// bgImage = null; |
|
|
// // LangUtil.gcTotal(); |
|
|
// } |
|
|
// |
|
|
// if (localImage != null) { |
|
|
// localImage = dispose(localImage); |
|
|
// localImage = null; |
|
|
// // LangUtil.gcTotal(); |
|
|
// } |
|
|
// |
|
|
// if (finalImage != null) { |
|
|
// finalImage = dispose(finalImage); |
|
|
// finalImage = null; |
|
|
// // LangUtil.gcTotal(); |
|
|
// } |
|
|
// |
|
|
// if (preFinalImage != null) { |
|
|
// preFinalImage = dispose(preFinalImage); |
|
|
// preFinalImage = null; |
|
|
// } |
|
|
disposeImages(); |
|
949 |
|
|
950 |
// LangUtil.gcTotal(); |
disposeImages(); |
951 |
|
|
952 |
// Alle mapPaneListener entfernen |
// Remove all mapPaneListeners that have registered with us |
953 |
mapPaneListeners.clear(); |
mapPaneListeners.clear(); |
954 |
|
|
955 |
removeMouseMotionListener(zoomMapPaneMouseListener); |
removeMouseMotionListener(zoomMapPaneMouseListener); |
956 |
removeMouseListener(zoomMapPaneMouseListener); |
removeMouseListener(zoomMapPaneMouseListener); |
957 |
|
|
958 |
if (localContext != null) |
if (localContext != null) |
959 |
getContext().clearLayerList(); |
getMapContext().clearLayerList(); |
960 |
if (bgContext != null) |
if (bgContext != null) |
961 |
getBgContext().clearLayerList(); |
getBgContext().clearLayerList(); |
962 |
|
|
1002 |
*/ |
*/ |
1003 |
protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) { |
protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) { |
1004 |
|
|
1005 |
|
// if (1 == 1)return false; |
1006 |
|
|
1007 |
if (quickPreviewHint == 0) |
if (quickPreviewHint == 0) |
1008 |
return false; |
return false; |
1009 |
|
|
1022 |
// Calculate the oldMapArea in the current WindowCoordinates: |
// Calculate the oldMapArea in the current WindowCoordinates: |
1023 |
final Envelope oldMapWindow = tranformGeoToWindow(oldMapArea.getMinX(), |
final Envelope oldMapWindow = tranformGeoToWindow(oldMapArea.getMinX(), |
1024 |
oldMapArea.getMinY(), oldMapArea.getMaxX(), oldMapArea |
oldMapArea.getMinY(), oldMapArea.getMaxX(), oldMapArea |
1025 |
.getMaxY(), null); |
.getMaxY()); |
1026 |
|
|
1027 |
final int xx1 = (int) Math.round(oldMapWindow.getMinX()); |
final int xx1 = (int) Math.round(oldMapWindow.getMinX()); |
1028 |
final int yy1 = (int) Math.round(oldMapWindow.getMinY()); |
final int yy1 = (int) Math.round(oldMapWindow.getMinY()); |
1067 |
return bgImage; |
return bgImage; |
1068 |
} |
} |
1069 |
|
|
1070 |
public MapContext getContext() { |
public MapContext getMapContext() { |
1071 |
if (localContext == null) { |
if (localContext == null) { |
1072 |
setLocalContext(new DefaultMapContext()); |
setLocalContext(new DefaultMapContext()); |
1073 |
} |
} |
1078 |
// |
// |
1079 |
if (finalImage == null) { |
if (finalImage == null) { |
1080 |
// Rectangle curPaintArea = getVisibleRect(); |
// Rectangle curPaintArea = getVisibleRect(); |
1081 |
finalImage = new BufferedImage(getBounds().width, |
finalImage = new BufferedImage(getVisibleRect().width, |
1082 |
getBounds().height, IMAGETYPE); |
getVisibleRect().height, IMAGETYPE); |
1083 |
|
|
1084 |
requestStartRendering(); |
requestStartRendering(); |
1085 |
} |
} |
1096 |
private BufferedImage getLocalImage() { |
private BufferedImage getLocalImage() { |
1097 |
|
|
1098 |
if (localImage == null) { |
if (localImage == null) { |
1099 |
localImage = new BufferedImage(getBounds().width, |
localImage = new BufferedImage(getVisibleRect().width, |
1100 |
getBounds().height, IMAGETYPE_withAlpha); |
getVisibleRect().height, IMAGETYPE_withAlpha); |
1101 |
} |
} |
1102 |
|
|
1103 |
return localImage; |
return localImage; |
1114 |
try { |
try { |
1115 |
mapArea_ = localContext.getLayerBounds(); |
mapArea_ = localContext.getLayerBounds(); |
1116 |
} catch (final IOException e) { |
} catch (final IOException e) { |
1117 |
LOGGER.warn("context.getLayerBounds()", e); |
LOGGER.warn("localContext.getLayerBounds()", e); |
1118 |
|
} |
1119 |
|
|
1120 |
|
if (mapArea_ == null && bgContext != null) { |
1121 |
|
try { |
1122 |
|
mapArea_ = bgContext.getLayerBounds(); |
1123 |
|
} catch (final IOException e) { |
1124 |
|
LOGGER.warn("bgContext.getLayerBounds()", e); |
1125 |
|
} |
1126 |
} |
} |
1127 |
|
|
1128 |
if (mapArea_ != null) { |
if (mapArea_ != null) { |
|
mapImageInvalid = true; /* note we need to redraw */ |
|
|
// setMapArea(mapArea_); // results in a loop |
|
1129 |
mapArea = bestAllowedMapArea(mapArea_); |
mapArea = bestAllowedMapArea(mapArea_); |
1130 |
|
requestStartRendering(); |
1131 |
} |
} |
1132 |
} |
} |
1133 |
|
|
1134 |
if (mapArea == null) |
if (mapArea == null) |
1135 |
return null; |
return null; |
1136 |
|
|
1137 |
|
// TODO is needed at all, this should go to setMapArea maybe |
1138 |
if (localContext.getCoordinateReferenceSystem() == null) |
if (localContext.getCoordinateReferenceSystem() == null) |
1139 |
try { |
try { |
1140 |
localContext.setCoordinateReferenceSystem(GeoImportUtil |
localContext.setCoordinateReferenceSystem(GeoImportUtil |
1141 |
.getDefaultCRS()); |
.getDefaultCRS()); |
1142 |
} catch (TransformException e) { |
} catch (Exception e) { |
1143 |
// TODO Auto-generated catch block |
throw new RuntimeException("setting context CRS:", e); |
|
e.printStackTrace(); |
|
|
} catch (FactoryException e) { |
|
|
// TODO Auto-generated catch block |
|
|
e.printStackTrace(); |
|
1144 |
} |
} |
1145 |
|
|
1146 |
return new ReferencedEnvelope(mapArea, localContext |
return new ReferencedEnvelope(mapArea, localContext |
1148 |
} |
} |
1149 |
|
|
1150 |
/** |
/** |
1151 |
* Returns the background {@link Color} of the map pane. Default is white. |
* Returns the background {@link Color} of the map pane. If not set, the |
1152 |
|
* methods looks for a parent component and will use its background color. |
1153 |
|
* If no parent component is available, WHITE is returned. |
1154 |
**/ |
**/ |
1155 |
public Color getMapBackgroundColor() { |
public Color getMapBackgroundColor() { |
1156 |
|
if (mapBackgroundColor == null) { |
1157 |
|
if (getParent() != null) |
1158 |
|
return getParent().getBackground(); |
1159 |
|
else |
1160 |
|
return Color.WHITE; |
1161 |
|
} |
1162 |
return mapBackgroundColor; |
return mapBackgroundColor; |
1163 |
} |
} |
1164 |
|
|
1185 |
|
|
1186 |
public Envelope getMaxExtend() { |
public Envelope getMaxExtend() { |
1187 |
if (maxExtend == null) { |
if (maxExtend == null) { |
1188 |
final ReferencedEnvelope layerBounds = GTUtil |
// Commented-out because it takes soo much time! |
1189 |
.getVisibleLayoutBounds(localContext); |
// |
1190 |
if (layerBounds == null) { |
// long start = System.currentTimeMillis(); |
1191 |
// TODO Last fallback could be the CRS valid area |
// final ReferencedEnvelope layerBounds = GTUtil |
1192 |
return null; |
// .getVisibleLayoutBounds(localContext); |
1193 |
} |
// |
1194 |
|
// LOGGER.info( |
1195 |
// Kartenbereich um 10% vergroessern |
// (System.currentTimeMillis()-start)+"m to get maxExtend"); |
1196 |
return JTSUtil.fixAspectRatio(this.getBounds(), JTSUtil |
// |
1197 |
.expandEnvelope(layerBounds, 0.1), true); |
// if (layerBounds == null) { |
1198 |
|
// // TODO Last fallback could be the CRS valid area |
1199 |
|
// return null; |
1200 |
|
// } |
1201 |
|
// |
1202 |
|
// // Kartenbereich um 10% vergroessern |
1203 |
|
// return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil |
1204 |
|
// .expandEnvelope(layerBounds, 0.1), true); |
1205 |
} |
} |
1206 |
return maxExtend; |
return maxExtend; |
1207 |
} |
} |
1315 |
* {@link XMapPane} is visible and has bounds set. |
* {@link XMapPane} is visible and has bounds set. |
1316 |
*/ |
*/ |
1317 |
public boolean isWellDefined() { |
public boolean isWellDefined() { |
|
|
|
1318 |
try { |
try { |
1319 |
|
if (getMapContext() == null) |
|
if (getContext() == null) |
|
|
return false; |
|
|
if (getContext().getLayerCount() <= 0) |
|
1320 |
return false; |
return false; |
1321 |
if (getMapArea() == null) |
if (getMapContext().getLayerCount() <= 0) |
1322 |
return false; |
return false; |
1323 |
if (getBounds().getWidth() == 0) |
if (getVisibleRect().getWidth() == 0) |
1324 |
return false; |
return false; |
1325 |
if (getBounds().getHeight() == 0) |
if (getVisibleRect().getHeight() == 0) |
1326 |
return false; |
return false; |
1327 |
|
// if (getMapArea() == null) |
1328 |
|
// return false; |
1329 |
} catch (final Exception e) { |
} catch (final Exception e) { |
1330 |
return false; |
return false; |
1331 |
} |
} |
1332 |
return true; |
return true; |
1333 |
} |
} |
1334 |
|
|
1335 |
|
/** |
1336 |
|
* Called from the listeners while the mouse is dragging, this method either |
1337 |
|
* paints a translated (moved/panned) version of the image, or a rectangle. |
1338 |
|
* |
1339 |
|
* @param startPos |
1340 |
|
* in screen coordinates |
1341 |
|
* @param lastPos |
1342 |
|
* in screen coordinates |
1343 |
|
* @param event |
1344 |
|
* the {@link MouseEvent} to read the mouse buttons from |
1345 |
|
*/ |
1346 |
public void mouseDragged(final Point startPos, final Point lastPos, |
public void mouseDragged(final Point startPos, final Point lastPos, |
1347 |
final MouseEvent event) { |
final MouseEvent event) { |
1348 |
|
|
1349 |
if ((getState() == XMapPane.PAN) |
if ((getState() == XMapPane.PAN) |
1350 |
|| ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) { |
|| ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) { |
1351 |
|
|
1352 |
|
// Panning needs a panning coursor |
1353 |
if (getCursor() != SwingUtil.PANNING_CURSOR) { |
if (getCursor() != SwingUtil.PANNING_CURSOR) { |
1354 |
setCursor(SwingUtil.PANNING_CURSOR); |
setCursor(SwingUtil.PANNING_CURSOR); |
1355 |
|
|
1356 |
// While panning, we deactivate the rendering. So the tasts are |
// While panning, we deactivate the rendering. So the tasks are |
1357 |
// ready to start when the panning os done. |
// ready to start when the panning is finished. |
1358 |
if (bgExecuter != null) |
if (bgExecuter != null && bgExecuter.isRunning()) |
1359 |
bgExecuter.cancelTask(); |
bgExecuter.cancelTask(); |
1360 |
if (localExecuter != null) |
if (localExecuter.isRunning()) |
1361 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
1362 |
} |
} |
1363 |
|
|
1404 |
} else if ((getState() == XMapPane.ZOOM_IN) |
} else if ((getState() == XMapPane.ZOOM_IN) |
1405 |
|| (getState() == XMapPane.ZOOM_OUT) |
|| (getState() == XMapPane.ZOOM_OUT) |
1406 |
|| (getState() == XMapPane.SELECT_ALL) |
|| (getState() == XMapPane.SELECT_ALL) |
1407 |
|| (getState() == XMapPane.SELECT_TOP) |
|| (getState() == XMapPane.SELECT_TOP)) { |
|
// || (getState() == XMapPane.SELECT_ONE_FROM_TOP) |
|
|
) { |
|
|
final Graphics graphics = getGraphics(); |
|
1408 |
|
|
1409 |
|
// Draws a rectangle |
1410 |
|
final Graphics graphics = getGraphics(); |
1411 |
drawRectangle(graphics, startPos, event.getPoint()); |
drawRectangle(graphics, startPos, event.getPoint()); |
1412 |
|
if ((lastPos.x > 0) && (lastPos.y > 0)) |
|
if ((lastPos.x > 0) && (lastPos.y > 0)) { |
|
1413 |
drawRectangle(graphics, startPos, lastPos); |
drawRectangle(graphics, startPos, lastPos); |
|
} |
|
|
|
|
1414 |
graphics.dispose(); |
graphics.dispose(); |
|
|
|
1415 |
} |
} |
|
|
|
1416 |
} |
} |
1417 |
|
|
1418 |
/** |
/** |
1419 |
* Called by the {@link RenderingExecutor} when rendering was cancelled. |
* Called by the {@link RenderingExecutor} when rendering was cancelled. |
1420 |
*/ |
*/ |
1421 |
public void onRenderingCancelled() { |
public void onRenderingCancelled() { |
|
repaintTimer.stop(); |
|
1422 |
LOGGER.debug("Rendering cancelled"); |
LOGGER.debug("Rendering cancelled"); |
1423 |
|
repaintTimer.stop(); |
1424 |
} |
} |
1425 |
|
|
1426 |
/** |
/** |
1428 |
* completed. |
* completed. |
1429 |
*/ |
*/ |
1430 |
public void onRenderingCompleted() { |
public void onRenderingCompleted() { |
1431 |
|
LOGGER.debug("complete"); |
1432 |
|
|
1433 |
repaintTimer.stop(); |
repaintTimer.stop(); |
1434 |
updateFinalImage(); |
|
1435 |
repaint(); |
// We "forget" about an exception every time we complete a rendering |
1436 |
|
// thread successfully |
1437 |
if (renderingErrors.size() > 0) |
if (renderingErrors.size() > 0) |
1438 |
renderingErrors.remove(0); |
renderingErrors.remove(0); |
1439 |
|
|
1440 |
|
updateFinalImage(); |
1441 |
|
repaint(); |
1442 |
} |
} |
1443 |
|
|
1444 |
/** |
/** |
1452 |
* @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent) |
* @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent) |
1453 |
*/ |
*/ |
1454 |
public void onRenderingFailed(final Exception renderingError) { |
public void onRenderingFailed(final Exception renderingError) { |
1455 |
this.renderingErrors.add(renderingError); |
|
1456 |
|
// Store the exceptions so we can show it to the user: |
1457 |
|
if (!(renderingError instanceof java.lang.IllegalArgumentException && renderingError |
1458 |
|
.getMessage().equals( |
1459 |
|
"Argument \"sourceCRS\" should not be null."))) |
1460 |
|
this.renderingErrors.add(renderingError); |
1461 |
if (renderingErrors.size() > 3) |
if (renderingErrors.size() > 3) |
1462 |
renderingErrors.remove(0); |
renderingErrors.remove(0); |
1463 |
|
|
1464 |
repaintTimer.stop(); |
repaintTimer.stop(); |
1465 |
|
|
1466 |
LOGGER.warn("Rendering failed", renderingError); |
LOGGER.warn("Rendering failed", renderingError); |
1467 |
updateFinalImage(); |
updateFinalImage(); |
1468 |
repaint(); |
repaint(); |
1469 |
|
|
1470 |
} |
} |
1471 |
|
|
|
public void onRenderingPending() { |
|
|
// LOGGER.debug("Pending rendering updates the preview..."); |
|
|
updateFinalImage(); |
|
|
repaint(); |
|
|
} |
|
|
|
|
1472 |
@Override |
@Override |
1473 |
protected void paintComponent(final Graphics g) { |
protected void paintComponent(final Graphics g) { |
|
if (!acceptsRepaintCalls) |
|
|
return; |
|
1474 |
|
|
1475 |
// Maybe update the cursor and maybe stop the repainting timer |
// Maybe update the cursor and maybe stop the repainting timer |
1476 |
updateCursor(); |
updateCursor(); |
1477 |
|
|
1478 |
// super.paintComponent(g); // candidate for removal |
if (!acceptsRepaintCalls) |
1479 |
|
return; |
1480 |
|
|
1481 |
|
if (!isWellDefined()) |
1482 |
|
return; |
1483 |
|
|
1484 |
|
// super.paintComponent(g); // candidate for removal |
1485 |
|
|
1486 |
boolean paintedSomething = false; |
boolean paintedSomething = false; |
1487 |
|
|
1494 |
// happening. |
// happening. |
1495 |
if (mapAreaChanged && oldMapArea != null |
if (mapAreaChanged && oldMapArea != null |
1496 |
&& getMapArea().intersects(oldMapArea) |
&& getMapArea().intersects(oldMapArea) |
1497 |
& !getMapArea().equals(oldMapArea)) { |
& !getMapArea().equals(oldMapArea) && !paneResized) { |
1498 |
|
|
1499 |
mapAreaChanged = false; |
mapAreaChanged = false; |
1500 |
|
|
1501 |
if (getMapArea().covers(oldMapArea)) { |
if (getMapArea().covers(oldMapArea)) { |
1502 |
setQuickPreviewHint(ZOOM_OUT); |
quickPreviewHint = ZOOM_OUT; |
1503 |
paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g); |
paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g); |
1504 |
} else if (oldMapArea.covers(getMapArea())) { |
} else if (oldMapArea.covers(getMapArea())) { |
1505 |
setQuickPreviewHint(ZOOM_IN); |
quickPreviewHint = ZOOM_IN; |
1506 |
paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g); |
paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g); |
1507 |
} |
} |
|
|
|
1508 |
} |
} |
|
|
|
|
if (paneResized) { |
|
|
paneResized = false; |
|
|
disposeImages(); |
|
|
} |
|
|
|
|
|
// Start the Threads and Timers to render the image |
|
|
requestStartRendering(); |
|
|
|
|
1509 |
} |
} |
1510 |
|
|
1511 |
if (!paintedSomething) { |
if (!paintedSomething) { |
1569 |
*/ |
*/ |
1570 |
public void performPan() { |
public void performPan() { |
1571 |
|
|
1572 |
final Rectangle winBounds = getBounds(); |
Rectangle winBounds = getVisibleRect(); |
1573 |
|
|
1574 |
winBounds.translate(-imageOrigin.x, -imageOrigin.y); |
winBounds.translate(-imageOrigin.x, -imageOrigin.y); |
1575 |
final Envelope newMapArea = tranformWindowToGeo(winBounds.x, |
final Envelope newMapArea = tranformWindowToGeo(winBounds.x, |
1576 |
winBounds.y, winBounds.x + winBounds.width, winBounds.y |
winBounds.y, winBounds.x + winBounds.width, winBounds.y |
1593 |
setCursor(SwingUtil.PAN_CURSOR); |
setCursor(SwingUtil.PAN_CURSOR); |
1594 |
} |
} |
1595 |
|
|
|
// |
|
|
// /** |
|
|
// * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot |
|
|
// gemacht |
|
|
// * wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt. |
|
|
// * |
|
|
// * @author <a href="mailto:[email protected]">Stefan Alfons |
|
|
// * Krüger</a> |
|
|
// */ |
|
|
// @Override |
|
|
// public void print(final Graphics g) { |
|
|
// final Color orig = getBackground(); |
|
|
// setBackground(Color.WHITE); |
|
|
// |
|
|
// // wrap in try/finally so that we always restore the state |
|
|
// try { |
|
|
// super.print(g); |
|
|
// } finally { |
|
|
// setBackground(orig); |
|
|
// } |
|
|
// } |
|
|
|
|
1596 |
/** |
/** |
1597 |
* Entfernt einen Listener von der Map. |
* Entfernt einen Listener von der Map. |
1598 |
* |
* |
1611 |
private void requestStartRendering() { |
private void requestStartRendering() { |
1612 |
if (bgExecuter != null) |
if (bgExecuter != null) |
1613 |
bgExecuter.cancelTask(); |
bgExecuter.cancelTask(); |
1614 |
if (localExecuter != null) |
|
1615 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
1616 |
|
|
1617 |
|
mapImageInvalid = true; |
1618 |
|
if (paneResized) { |
1619 |
|
paneResized = false; |
1620 |
|
disposeImages(); |
1621 |
|
} |
1622 |
requestStartRendering = true; |
requestStartRendering = true; |
1623 |
|
|
1624 |
} |
} |
1625 |
// |
|
1626 |
// /** |
/** |
1627 |
// * Berechnet die Transformation zwischen Fenster- und Karten-Koordinaten |
* Calculate the affine transforms used to convert between world and pixel |
1628 |
// * neu. |
* coordinates. The calculations here are very basic and assume a cartesian |
1629 |
// */ |
* reference system. |
1630 |
// protected void resetTransforms() { |
* <p> |
1631 |
// if (getMapArea() == null || getWidth() == 0 || getHeight() == 0) |
* Tne transform is calculated such that {@code envelope} will be centred in |
1632 |
// return; |
* the display |
1633 |
// |
* |
1634 |
// // We store the last Transform |
* @param envelope |
1635 |
// oldScreenToWorld = screenToWorld; |
* the current map extent (world coordinates) |
1636 |
// |
* @param paintArea |
1637 |
// this.screenToWorld = new AffineTransform( |
* the current map pane extent (screen units) |
1638 |
// // Genauso wie die Fenster-Koordinaten, werden die Longitude-Koordinaten |
*/ |
1639 |
// // nach rechts (Osten) hin groesser |
private void resetTransforms() { |
1640 |
// // --> positive Verschiebung |
ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea, |
1641 |
// getMapArea().getWidth() / getWidth(), |
getMapContext().getCoordinateReferenceSystem()); |
1642 |
// // keine Verzerrung |
|
1643 |
// 0.0, 0.0, |
// System.out |
1644 |
// // Waehrend die Fenster-Koordinaten nach unten hin groesser |
// .println("paintArea in resetTeansofrms = " + getVisibleRect()); |
1645 |
// // werden, |
if (!isWellDefined()) |
1646 |
// // werden Latitude-Koordinaten nach Sueden hin keiner |
return; |
1647 |
// // --> negative Verschiebung |
|
1648 |
// -getMapArea().getHeight() / getHeight(), |
worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv, |
1649 |
// // Die Longitude-Koordinaten werden nach Osten hin groesser |
getVisibleRect()); |
1650 |
// // --> obere linke Ecke des Fensters hat also den Minimalwert |
|
1651 |
// getMapArea().getMinX(), |
try { |
1652 |
// // Die Latitude-Koordinaten werden nach Norden hin groesser |
screenToWorld = worldToScreen.createInverse(); |
1653 |
// // --> obere linke Ecke des Fensters hat also den Maximalwert |
|
1654 |
// getMapArea().getMaxY()); |
} catch (NoninvertibleTransformException ex) { |
1655 |
// |
LOGGER |
1656 |
// try { |
.error("can't invert worldToScreen to get screenToWorld!", |
1657 |
// this.worldToScreen = screenToWorld.createInverse(); |
ex); |
1658 |
// } catch (final NoninvertibleTransformException e) { |
} |
1659 |
// LOGGER.error(e); |
} |
|
// } |
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
* Calculate the affine transforms used to convert between |
|
|
* world and pixel coordinates. The calculations here are very |
|
|
* basic and assume a cartesian reference system. |
|
|
* <p> |
|
|
* Tne transform is calculated such that {@code envelope} will |
|
|
* be centred in the display |
|
|
* |
|
|
* @param envelope the current map extent (world coordinates) |
|
|
* @param paintArea the current map pane extent (screen units) |
|
|
*/ |
|
|
private void resetTransforms() { |
|
|
ReferencedEnvelope refEnv = new ReferencedEnvelope(mapArea, getContext().getCoordinateReferenceSystem()); |
|
|
|
|
|
Rectangle paintArea = getBounds(); |
|
|
|
|
|
double xscale = paintArea.getWidth() / refEnv.getWidth(); |
|
|
double yscale = paintArea.getHeight() / refEnv.getHeight(); |
|
|
|
|
|
double scale = Math.min(xscale, yscale); |
|
|
|
|
|
double xoff = refEnv.getMedian(0) * scale - paintArea.getCenterX(); |
|
|
double yoff = refEnv.getMedian(1) * scale + paintArea.getCenterY(); |
|
|
|
|
|
worldToScreen = new AffineTransform(scale, 0, 0, -scale, -xoff, yoff); |
|
|
try { |
|
|
screenToWorld = worldToScreen.createInverse(); |
|
|
|
|
|
} catch (NoninvertibleTransformException ex) { |
|
|
ex.printStackTrace(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
1660 |
|
|
1661 |
public void setBgContext(final MapContext context) { |
public void setBgContext(final MapContext context) { |
1662 |
|
|
1673 |
this.bgContext = context; |
this.bgContext = context; |
1674 |
|
|
1675 |
if (context != null) { |
if (context != null) { |
1676 |
setMapArea(bgContext.getAreaOfInterest()); |
// setMapArea(bgContext.getAreaOfInterest()); |
1677 |
|
|
1678 |
this.bgContext.addMapLayerListListener(bgContextListener); |
this.bgContext.addMapLayerListListener(bgContextListener); |
1679 |
|
|
1682 |
mapLayer.addMapLayerListener(bgMapLayerListener); |
mapLayer.addMapLayerListener(bgMapLayerListener); |
1683 |
} |
} |
1684 |
} |
} |
1685 |
mapImageInvalid = true; |
|
1686 |
repaint(); |
requestStartRendering(); |
1687 |
} |
} |
1688 |
|
|
1689 |
public void setJava2dHints(final RenderingHints java2dHints) { |
public void setJava2dHints(final RenderingHints java2dHints) { |
1690 |
this.java2dHints = java2dHints; |
this.java2dHints = java2dHints; |
1691 |
} |
} |
1692 |
|
|
|
/** |
|
|
* |
|
|
* @param context |
|
|
*/ |
|
1693 |
public void setLocalContext(final MapContext context) { |
public void setLocalContext(final MapContext context) { |
1694 |
// Remove the default listener from the old context |
// Remove the default listener from the old context |
1695 |
if (this.localContext != null) { |
if (this.localContext != null) { |
1705 |
|
|
1706 |
if (context != null) { |
if (context != null) { |
1707 |
|
|
1708 |
setMapArea(localContext.getAreaOfInterest()); |
// setMapArea(localContext.getAreaOfInterest()); |
1709 |
|
|
1710 |
localRenderer.setContext(localContext); |
getLocalRenderer().setContext(localContext); |
1711 |
|
|
1712 |
this.localContext.addMapLayerListListener(localContextListener); |
this.localContext.addMapLayerListListener(localContextListener); |
1713 |
|
|
1717 |
} |
} |
1718 |
} |
} |
1719 |
|
|
1720 |
|
requestStartRendering(); |
1721 |
|
|
1722 |
|
} |
1723 |
|
|
1724 |
|
/** |
1725 |
|
* Triggers to repaint (fast) and re-render (slow) the JMapPane. |
1726 |
|
*/ |
1727 |
|
public void refresh() { |
1728 |
mapImageInvalid = true; |
mapImageInvalid = true; |
1729 |
repaint(); |
repaint(); |
1730 |
} |
} |
1731 |
|
|
1732 |
|
// /** |
1733 |
|
// * Triggers to use new {@link GTRenderer} and refresh the map. Should be |
1734 |
|
// * called after {@link Style}s have been changed because GTRenderer is |
1735 |
|
// * otherwise not working well. |
1736 |
|
// */ |
1737 |
|
// public void refreshRenderers() { |
1738 |
|
// localRenderer = GTUtil.createGTRenderer(); |
1739 |
|
// setLocalContext(getMapContext()); |
1740 |
|
// mapImageInvalid = true; |
1741 |
|
// repaint(); |
1742 |
|
// } |
1743 |
|
|
1744 |
|
public boolean setMapArea(final Envelope newMapArea) { |
1745 |
|
if (newMapArea == null) |
1746 |
|
return false; |
1747 |
|
if (getMapContext().getCoordinateReferenceSystem() == null) |
1748 |
|
return false; |
1749 |
|
return setMapArea(new ReferencedEnvelope(newMapArea, getMapContext() |
1750 |
|
.getCoordinateReferenceSystem())); |
1751 |
|
} |
1752 |
|
|
1753 |
/** |
/** |
1754 |
* @param newMapArea |
* @param newMapArea |
1755 |
* @return <code>true</code> if the mapArea has been changed and a repaint |
* @return <code>true</code> if the mapArea has been changed and a repaint |
1756 |
* has been triggered. |
* has been triggered. |
1757 |
*/ |
*/ |
1758 |
public boolean setMapArea(final Envelope newMapArea) { |
public boolean setMapArea(final ReferencedEnvelope newMapArea) { |
1759 |
|
|
1760 |
if (newMapArea == null |
if (newMapArea == null |
1761 |
|| bestAllowedMapArea(newMapArea).equals(mapArea)) { |
|| bestAllowedMapArea(newMapArea).equals(mapArea)) { |
1774 |
return false; |
return false; |
1775 |
} |
} |
1776 |
|
|
1777 |
|
final Envelope candNew = bestAllowedMapArea(newMapArea); |
1778 |
|
|
1779 |
// Testing, whether the difference if just minimal |
// Testing, whether the difference if just minimal |
1780 |
if (mapArea != null) { |
if (mapArea != null) { |
|
final Envelope candNew = bestAllowedMapArea(newMapArea); |
|
1781 |
final double tolX = mapArea.getWidth() / 1000.; |
final double tolX = mapArea.getWidth() / 1000.; |
1782 |
final double tolY = mapArea.getHeight() / 1000.; |
final double tolY = mapArea.getHeight() / 1000.; |
1783 |
if ((candNew.getMinX() - tolX < mapArea.getMinX()) |
if ((candNew.getMinX() - tolX < mapArea.getMinX()) |
1797 |
} |
} |
1798 |
} |
} |
1799 |
|
|
1800 |
|
// New map are is accepted: |
1801 |
oldMapArea = mapArea; |
oldMapArea = mapArea; |
1802 |
|
mapArea = candNew; |
1803 |
this.mapArea = bestAllowedMapArea(newMapArea); |
resetTransforms(); |
1804 |
|
|
1805 |
if (localContext != null) { |
if (localContext != null) { |
1806 |
localContext.setAreaOfInterest(mapArea, localContext |
localContext.setAreaOfInterest(mapArea, localContext |
1810 |
bgContext.setAreaOfInterest(mapArea, localContext |
bgContext.setAreaOfInterest(mapArea, localContext |
1811 |
.getCoordinateReferenceSystem()); |
.getCoordinateReferenceSystem()); |
1812 |
} |
} |
1813 |
resetTransforms(); |
|
|
mapImageInvalid = true; |
|
1814 |
mapAreaChanged = true; |
mapAreaChanged = true; |
|
repaint(); |
|
1815 |
|
|
1816 |
// LOGGER.debug("New maparea = " + mapArea); |
repaint(200); // Do not remove it! |
1817 |
|
|
1818 |
|
requestStartRendering(); |
1819 |
|
|
1820 |
return true; |
return true; |
1821 |
} |
} |
1822 |
|
|
1826 |
* @param if <code>null</code>, white is used. |
* @param if <code>null</code>, white is used. |
1827 |
*/ |
*/ |
1828 |
public void setMapBackgroundColor(Color bgColor) { |
public void setMapBackgroundColor(Color bgColor) { |
|
if (bgColor == null) |
|
|
bgColor = Color.WHITE; |
|
1829 |
this.mapBackgroundColor = bgColor; |
this.mapBackgroundColor = bgColor; |
1830 |
} |
} |
1831 |
|
|
1900 |
} |
} |
1901 |
|
|
1902 |
/** |
/** |
1903 |
* |
* If <code>true</code>, allow the {@link XMapPane} to process #repaint() |
1904 |
* @param b |
* requests. Otherwise the map will not paint anything and not start any |
1905 |
|
* rendering {@link Thread}s. |
1906 |
*/ |
*/ |
1907 |
public void setPainting(final boolean b) { |
public void setPainting(final boolean b) { |
1908 |
acceptsRepaintCalls = b; |
acceptsRepaintCalls = b; |
1909 |
} |
if (acceptsRepaintCalls == true) |
1910 |
|
repaint(); |
|
// /** |
|
|
// * Returns in milli seconds the time the last rending of the |
|
|
// * {@link SelectableXMapPane} took. #Long.MAX_VALUE if the JMapPane has |
|
|
// not |
|
|
// * been rendered yet. |
|
|
// */ |
|
|
// public long getLastRenderingDuration() { |
|
|
// return lastRenderingDuration; |
|
|
// } |
|
|
|
|
|
public void setQuickPreviewHint(final int quickPreviewHint) { |
|
|
this.quickPreviewHint = quickPreviewHint; |
|
|
|
|
1911 |
} |
} |
1912 |
|
|
1913 |
private void setRendererHints(final Map<Object, Object> rendererHints) { |
private void setRendererHints(final Map<Object, Object> rendererHints) { |
1952 |
*/ |
*/ |
1953 |
private void startRendering() { |
private void startRendering() { |
1954 |
|
|
1955 |
if (!isWellDefined()) |
if (!isWellDefined() || !acceptsRepaintCalls) { |
1956 |
|
// if we are not ready to start rendering, try it again the next |
1957 |
|
// time the timer is chacking the flag. |
1958 |
|
requestStartRendering = true; |
1959 |
return; |
return; |
1960 |
|
} |
1961 |
|
|
1962 |
if (bgExecuter != null) { |
if (bgExecuter != null) { |
1963 |
// Stop all renderers |
// Stop all renderers |
1964 |
bgExecuter.cancelTask(); |
bgExecuter.cancelTask(); |
1965 |
} |
} |
1966 |
|
|
1967 |
if (localExecuter != null) { |
localExecuter.cancelTask(); |
|
localExecuter.cancelTask(); |
|
|
} |
|
1968 |
|
|
1969 |
final Rectangle curPaintArea = getVisibleRect(); |
final Rectangle curPaintArea = getVisibleRect(); |
1970 |
|
|
1987 |
// (Graphics2D) getBgImage().getGraphics(), createGTRenderer); |
// (Graphics2D) getBgImage().getGraphics(), createGTRenderer); |
1988 |
} |
} |
1989 |
|
|
1990 |
if (getContext() != null) { |
if (getMapContext() != null) { |
1991 |
// localExecuter = new RenderingExecutor(this, 150l); |
// localExecuter = new RenderingExecutor(this, 150l); |
1992 |
// LOGGER.debug("starting local renderer:"); |
// LOGGER.debug("starting local renderer:"); |
1993 |
|
|
1994 |
localRenderer.setJava2DHints(getJava2dHints()); |
getLocalRenderer().setJava2DHints(getJava2dHints()); |
1995 |
localRenderer.setRendererHints(getRendererHints()); |
getLocalRenderer().setRendererHints(getRendererHints()); |
1996 |
|
|
1997 |
ReferencedEnvelope areaOfInterest = getMapArea(); |
final boolean submitted = localExecuter.submit(getMapArea(), |
|
final boolean submitted = localExecuter.submit(areaOfInterest, |
|
1998 |
curPaintArea, (Graphics2D) getLocalImage().getGraphics(), |
curPaintArea, (Graphics2D) getLocalImage().getGraphics(), |
1999 |
localRenderer, getWorldToScreenTransform()); |
getLocalRenderer()); |
2000 |
if (submitted) |
if (submitted) |
2001 |
repaintTimer.restart(); |
repaintTimer.restart(); |
2002 |
else |
else |
2003 |
requestStartRendering = true; // Try to start rendering again in |
requestStartRendering = true; // Try to start rendering |
2004 |
|
// again in |
2005 |
// a moment |
// a moment |
2006 |
} |
} |
2007 |
|
|
2024 |
* {@link #getScreenToWorld()} is used. |
* {@link #getScreenToWorld()} is used. |
2025 |
*/ |
*/ |
2026 |
public Envelope tranformGeoToWindow(final double ox, final double oy, |
public Envelope tranformGeoToWindow(final double ox, final double oy, |
2027 |
final double px, final double py, |
final double px, final double py) { |
2028 |
final AffineTransform winToGeotransform) { |
final AffineTransform at = getWorldToScreenTransform(); |
|
final AffineTransform at = winToGeotransform == null ? getScreenToWorld() |
|
|
: winToGeotransform; |
|
2029 |
Point2D geoO; |
Point2D geoO; |
2030 |
try { |
// try { |
2031 |
geoO = at.inverseTransform(new Point2D.Double(ox, oy), null); |
geoO = at.transform(new Point2D.Double(ox, oy), null); |
2032 |
final Point2D geoP = at.inverseTransform( |
final Point2D geoP = at.transform(new Point2D.Double(px, py), null); |
2033 |
new Point2D.Double(px, py), null); |
return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY()); |
2034 |
return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP |
// } catch (final NoninvertibleTransformException e) { |
2035 |
.getY()); |
// LOGGER.error(e); |
2036 |
} catch (final NoninvertibleTransformException e) { |
// return new Envelope(ox, oy, px, py); |
2037 |
LOGGER.error(e); |
// } |
|
return new Envelope(ox, oy, px, py); |
|
|
} |
|
2038 |
} |
} |
2039 |
|
|
2040 |
/** |
/** |
2054 |
final AffineTransform at = getScreenToWorld(); |
final AffineTransform at = getScreenToWorld(); |
2055 |
final Point2D geoO = at.transform(new Point2D.Double(ox, oy), null); |
final Point2D geoO = at.transform(new Point2D.Double(ox, oy), null); |
2056 |
final Point2D geoP = at.transform(new Point2D.Double(px, py), null); |
final Point2D geoP = at.transform(new Point2D.Double(px, py), null); |
2057 |
return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY()); |
|
2058 |
|
// Mmmmm... don't really understand why its x,x,y,y |
2059 |
|
// return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), |
2060 |
|
// geoP.getY()); |
2061 |
|
return new Envelope(new Coordinate(geoO.getX(), geoO.getY()), |
2062 |
|
new Coordinate(geoP.getX(), geoP.getY())); |
2063 |
} |
} |
2064 |
|
|
2065 |
/** |
/** |
2071 |
// if the renderers have stopped, also stop the timer that is updating |
// if the renderers have stopped, also stop the timer that is updating |
2072 |
// the final image |
// the final image |
2073 |
if (bgExecuter != null && bgExecuter.isRunning() |
if (bgExecuter != null && bgExecuter.isRunning() |
2074 |
|| localExecuter != null && localExecuter.isRunning()) { |
|| localExecuter.isRunning()) { |
2075 |
setCursor(WAIT_CURSOR); |
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); |
2076 |
return; |
return; |
2077 |
} else { |
} else { |
2078 |
// Allow one last rendering |
// Allow one last rendering |
2079 |
if (repaintTimer.isRunning()) { |
if (repaintTimer.isRunning()) { |
2080 |
System.out.println("one last rendering...."); |
// System.out.println("one last rendering...."); |
2081 |
repaintTimer.stop(); |
repaintTimer.stop(); |
2082 |
updateFinalImage(); |
updateFinalImage(); |
2083 |
repaint(); |
repaint(); |
2175 |
|
|
2176 |
// Paint a logo to the bottom right if available |
// Paint a logo to the bottom right if available |
2177 |
if (mapImage != null) { |
if (mapImage != null) { |
2178 |
graphics.drawImage(mapImage, getBounds().width |
Rectangle visibleRect = getVisibleRect(); |
2179 |
- mapImage.getWidth() - 10, getBounds().height |
graphics.drawImage(mapImage, visibleRect.width |
2180 |
|
- mapImage.getWidth() - 10, getVisibleRect().height |
2181 |
- mapImage.getHeight() - 10, null); |
- mapImage.getHeight() - 10, null); |
2182 |
} |
} |
2183 |
|
|
|
|
|
2184 |
int y = 17; |
int y = 17; |
2185 |
|
|
2186 |
// If the rendering process is still running, indicate this is the image |
// If the rendering process is still running, indicate this is the image |
2187 |
if (forceWait || bgExecuter != null && bgExecuter.isRunning() |
if (forceWait || bgExecuter != null && bgExecuter.isRunning() |
2188 |
|| localExecuter != null && localExecuter.isRunning()) { |
|| localExecuter.isRunning()) { |
2189 |
|
|
2190 |
y+=8; |
y += 8; |
2191 |
|
|
2192 |
final Color c = graphics.getColor(); |
final Color c = graphics.getColor(); |
2193 |
graphics.setFont(waitFont); |
graphics.setFont(waitFont); |
|
// String waitStr = "Wait..."; // i8n |
|
2194 |
|
|
2195 |
graphics.setColor(getMapBackgroundColor()); |
graphics.setColor(getMapBackgroundColor()); |
2196 |
graphics.drawString(waitMsg, 5, y); |
graphics.drawString(waitMsg, 5, y); |
2197 |
graphics.setColor(getMapBackgroundColor()); |
graphics.setColor(getMapBackgroundColor()); |
2198 |
graphics.drawString(waitMsg, 7, y+2); |
graphics.drawString(waitMsg, 7, y + 2); |
2199 |
graphics.setColor(Color.BLACK); |
graphics.setColor(Color.BLACK); |
2200 |
graphics.drawString(waitMsg, 6, y+1); |
graphics.drawString(waitMsg, 6, y + 1); |
2201 |
|
|
2202 |
graphics.setColor(c); |
graphics.setColor(c); |
2203 |
|
|
2204 |
y += 24; |
y += 24; |
2205 |
} |
} |
2206 |
|
|
2207 |
if (renderingErrors != null) { |
if (!renderingErrors.isEmpty() && isShowExceptions()) { |
2208 |
|
|
2209 |
final Color c = graphics.getColor(); |
final Color c = graphics.getColor(); |
2210 |
graphics.setFont(errorFont); |
graphics.setFont(errorFont); |
2211 |
|
|
2212 |
for (Exception ex : renderingErrors) { |
for (Exception ex : renderingErrors) { |
2213 |
|
|
|
if (ex instanceof java.lang.IllegalArgumentException |
|
|
&& ex.getMessage().equals( |
|
|
"Argument \"sourceCRS\" should not be null.")) |
|
|
continue; |
|
|
|
|
2214 |
String errStr = ex.getLocalizedMessage(); |
String errStr = ex.getLocalizedMessage(); |
2215 |
|
|
2216 |
graphics.setColor(Color.WHITE); |
if (errStr == null) |
2217 |
|
errStr = ex.getMessage(); |
2218 |
|
if (errStr == null) |
2219 |
|
errStr = "unknown error: " + ex.getClass().getSimpleName(); |
2220 |
|
|
2221 |
|
graphics.setColor(getMapBackgroundColor()); |
2222 |
graphics.drawString(errStr, 5, y); |
graphics.drawString(errStr, 5, y); |
2223 |
graphics.setColor(Color.RED); |
graphics.setColor(Color.RED); |
2224 |
graphics.drawString(errStr, 6, y + 1); |
graphics.drawString(errStr, 6, y + 1); |
2241 |
public void zoomTo( |
public void zoomTo( |
2242 |
final FeatureCollection<SimpleFeatureType, SimpleFeature> features) { |
final FeatureCollection<SimpleFeatureType, SimpleFeature> features) { |
2243 |
|
|
2244 |
final CoordinateReferenceSystem mapCRS = getContext() |
// if (!isWellDefined()) return; |
2245 |
|
|
2246 |
|
final CoordinateReferenceSystem mapCRS = getMapContext() |
2247 |
.getCoordinateReferenceSystem(); |
.getCoordinateReferenceSystem(); |
2248 |
final CoordinateReferenceSystem fCRS = features.getSchema() |
final CoordinateReferenceSystem fCRS = features.getSchema() |
2249 |
.getGeometryDescriptor().getCoordinateReferenceSystem(); |
.getGeometryDescriptor().getCoordinateReferenceSystem(); |
2250 |
|
|
2251 |
double width = mapArea.getWidth(); |
ReferencedEnvelope _mapArea; |
2252 |
double height = mapArea.getHeight(); |
if (mapArea == null) |
2253 |
|
_mapArea = features.getBounds(); |
2254 |
|
else |
2255 |
|
_mapArea = getMapArea(); |
2256 |
|
double width = _mapArea.getWidth(); |
2257 |
|
double height = _mapArea.getHeight(); |
2258 |
final double ratio = height / width; |
final double ratio = height / width; |
2259 |
|
|
2260 |
if (features == null || features.size() == 0) { |
if (features == null || features.size() == 0) { |
2306 |
} else { |
} else { |
2307 |
final ReferencedEnvelope fBounds = features.getBounds(); |
final ReferencedEnvelope fBounds = features.getBounds(); |
2308 |
|
|
2309 |
Envelope bounds; |
ReferencedEnvelope bounds; |
2310 |
if (!mapCRS.equals(fCRS)) { |
if (!mapCRS.equals(fCRS)) { |
2311 |
bounds = JTSUtil.transformEnvelope(fBounds, fCRS, mapCRS); |
bounds = JTSUtil.transformEnvelope(fBounds, mapCRS); |
2312 |
} else { |
} else { |
2313 |
bounds = fBounds; |
bounds = fBounds; |
2314 |
} |
} |
2364 |
.getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea |
.getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea |
2365 |
.getHeight()) / 2.); |
.getHeight()) / 2.); |
2366 |
|
|
2367 |
// Move the newMapArea above the new center |
// TODO we actually want that |
2368 |
newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter |
// // Move the newMapArea above the new center |
2369 |
.getY() |
// newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter |
2370 |
- mapArea.centre().y); |
// .getY() |
2371 |
|
// - mapArea.centre().y); |
2372 |
|
|
2373 |
setMapArea(newMapArea); |
setMapArea(newMapArea); |
2374 |
} |
} |
2375 |
|
|
2376 |
|
/** |
2377 |
|
* Shall non-fatal rendering exceptions be reported in the mappane or be |
2378 |
|
* dropped quitely. |
2379 |
|
*/ |
2380 |
|
public void setShowExceptions(boolean showExceptions) { |
2381 |
|
this.showExceptions = showExceptions; |
2382 |
|
} |
2383 |
|
|
2384 |
|
/** |
2385 |
|
* Shall exceptions be reported in the mappane? |
2386 |
|
*/ |
2387 |
|
public boolean isShowExceptions() { |
2388 |
|
return showExceptions; |
2389 |
|
} |
2390 |
|
|
2391 |
|
public GTRenderer getLocalRenderer() { |
2392 |
|
return localRenderer; |
2393 |
|
} |
2394 |
|
|
2395 |
} |
} |