13 |
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
14 |
import java.awt.event.ComponentAdapter; |
import java.awt.event.ComponentAdapter; |
15 |
import java.awt.event.ComponentEvent; |
import java.awt.event.ComponentEvent; |
|
import java.awt.event.InputEvent; |
|
16 |
import java.awt.event.MouseEvent; |
import java.awt.event.MouseEvent; |
17 |
import java.awt.event.MouseListener; |
import java.awt.event.MouseListener; |
18 |
import java.awt.geom.AffineTransform; |
import java.awt.geom.AffineTransform; |
25 |
import java.util.Map; |
import java.util.Map; |
26 |
import java.util.Vector; |
import java.util.Vector; |
27 |
|
|
28 |
|
import javax.swing.JList; |
29 |
import javax.swing.Timer; |
import javax.swing.Timer; |
30 |
|
import javax.swing.border.Border; |
31 |
|
|
32 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
33 |
|
import org.geotools.factory.GeoTools; |
34 |
import org.geotools.feature.FeatureCollection; |
import org.geotools.feature.FeatureCollection; |
35 |
|
import org.geotools.geometry.DirectPosition2D; |
36 |
import org.geotools.geometry.jts.JTS; |
import org.geotools.geometry.jts.JTS; |
37 |
import org.geotools.geometry.jts.ReferencedEnvelope; |
import org.geotools.geometry.jts.ReferencedEnvelope; |
38 |
import org.geotools.map.DefaultMapContext; |
import org.geotools.map.DefaultMapContext; |
39 |
|
import org.geotools.map.DefaultMapLayer; |
40 |
import org.geotools.map.MapContext; |
import org.geotools.map.MapContext; |
41 |
import org.geotools.map.MapLayer; |
import org.geotools.map.MapLayer; |
42 |
import org.geotools.map.event.MapLayerEvent; |
import org.geotools.map.event.MapLayerEvent; |
49 |
import org.geotools.renderer.lite.LabelCache; |
import org.geotools.renderer.lite.LabelCache; |
50 |
import org.geotools.renderer.lite.RendererUtilities; |
import org.geotools.renderer.lite.RendererUtilities; |
51 |
import org.geotools.renderer.lite.StreamingRenderer; |
import org.geotools.renderer.lite.StreamingRenderer; |
52 |
|
import org.geotools.resources.image.ImageUtilities; |
53 |
|
import org.geotools.styling.Style; |
54 |
import org.geotools.swing.JMapPane; |
import org.geotools.swing.JMapPane; |
55 |
import org.geotools.swing.event.MapMouseEvent; |
import org.geotools.swing.event.MapMouseEvent; |
56 |
import org.geotools.swing.event.MapPaneEvent; |
import org.geotools.swing.event.MapPaneEvent; |
68 |
import schmitzm.geotools.io.GeoImportUtil; |
import schmitzm.geotools.io.GeoImportUtil; |
69 |
import schmitzm.geotools.map.event.JMapPaneListener; |
import schmitzm.geotools.map.event.JMapPaneListener; |
70 |
import schmitzm.geotools.map.event.MapLayerAdapter; |
import schmitzm.geotools.map.event.MapLayerAdapter; |
71 |
|
import schmitzm.geotools.styling.StylingUtil; |
72 |
import schmitzm.lang.LangUtil; |
import schmitzm.lang.LangUtil; |
73 |
import schmitzm.swing.JPanel; |
import schmitzm.swing.JPanel; |
74 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
75 |
|
import schmitzm.swing.event.MouseInputType; |
76 |
|
|
77 |
import com.vividsolutions.jts.geom.Coordinate; |
import com.vividsolutions.jts.geom.Coordinate; |
78 |
import com.vividsolutions.jts.geom.Envelope; |
import com.vividsolutions.jts.geom.Envelope; |
103 |
*/ |
*/ |
104 |
public class XMapPane extends JPanel { |
public class XMapPane extends JPanel { |
105 |
|
|
106 |
private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB; |
/** |
107 |
private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_INT_ARGB; |
* If {@link #maxExtend} is <code>null</code> the following rules are used |
108 |
|
* to create a default maximum. |
109 |
|
* <ul> |
110 |
|
* <li>Values < 0 : don't grow to fit the monitors aspect ratio, no |
111 |
|
* margin</li> |
112 |
|
* <li>Values 0 : grow to fit the monitors aspect ratio, no margin</li> |
113 |
|
* <li>Values > 0 : grow to fit the monitors aspect ratio, and add a |
114 |
|
* relative margin</li> |
115 |
|
* </ul> |
116 |
|
* **/ |
117 |
|
private double defaultMaxMapExtendMode = .05; |
118 |
|
|
119 |
|
// private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB; |
120 |
|
// private static final int IMAGETYPE_withAlpha = |
121 |
|
// BufferedImage.TYPE_INT_ARGB; |
122 |
|
private static final int IMAGETYPE = BufferedImage.TYPE_3BYTE_BGR; |
123 |
|
|
124 |
|
public XMapPaneTool getTool() { |
125 |
|
return tool; |
126 |
|
} |
127 |
|
|
128 |
|
/** |
129 |
|
* If the {@link JPanel} is disabled, it shows nothing and the images are disposed. |
130 |
|
*/ |
131 |
|
@Override |
132 |
|
public void setEnabled(boolean enabled) { |
133 |
|
super.setEnabled(enabled); |
134 |
|
if (enabled == false) |
135 |
|
disposeImages(); |
136 |
|
else |
137 |
|
requestStartRendering(); |
138 |
|
} |
139 |
|
|
140 |
|
private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_4BYTE_ABGR; |
141 |
|
|
142 |
private final static Logger LOGGER = Logger.getLogger(XMapPane.class); |
private final static Logger LOGGER = Logger.getLogger(XMapPane.class); |
143 |
|
|
144 |
|
/** |
145 |
|
* A flag indicating whether the {@link XMapPane} is accepting repaints from |
146 |
|
* the EDT. @see {@link XMapPane#setPainting(boolean)) |
147 |
|
**/ |
148 |
private boolean acceptsRepaintCalls = true; |
private boolean acceptsRepaintCalls = true; |
149 |
|
|
150 |
/** |
/** |
185 |
* the {@link #repaintTimer} is regularly updating the {@link #finalImage} |
* the {@link #repaintTimer} is regularly updating the {@link #finalImage} |
186 |
* with previews. |
* with previews. |
187 |
*/ |
*/ |
188 |
public static final int REPEATING_REPAINT_DELAY = 600; |
public static final int REPEATING_REPAINT_DELAY = 500; |
189 |
|
|
190 |
/** |
/** |
191 |
* Default delay (milliseconds) before the map will be redrawn when resizing |
* Default delay (milliseconds) before the map will be redrawn when resizing |
207 |
* Flag for no-tool. |
* Flag for no-tool. |
208 |
*/ |
*/ |
209 |
public static final int NONE = -123; |
public static final int NONE = -123; |
210 |
|
// |
211 |
/** |
// /** |
212 |
* Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl |
// * Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl |
213 |
* moeglich! |
// * moeglich! |
214 |
* |
// * |
215 |
* @see #setState(int) |
// * @see #setState(int) |
216 |
*/ |
// */ |
217 |
public static final int PAN = 1; |
// public static final int PAN = 1; |
218 |
|
// |
219 |
/** |
// /** |
220 |
* Flag fuer Modus "Heran zoomen". |
// * Flag fuer Modus "Heran zoomen". |
221 |
* |
// * |
222 |
* @see #setState(int) |
// * @see #setState(int) |
223 |
* @see #setState(int) |
// * @see #setState(int) |
224 |
*/ |
// */ |
225 |
public static final int ZOOM_IN = 2; |
// public static final int ZOOM_IN = 2; |
226 |
|
// |
227 |
/** |
// /** |
228 |
* Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich! |
// * Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich! |
229 |
* |
// * |
230 |
* @see #setState(int) |
// * @see #setState(int) |
231 |
*/ |
// */ |
232 |
public static final int ZOOM_OUT = 3; |
// public static final int ZOOM_OUT = 3; |
|
|
|
|
/** |
|
|
* Flag fuer Modus "SimpleFeature-Auswahl auf allen (sichtbaren) Layern". |
|
|
* |
|
|
* @see #setState(int) |
|
|
* @see #setState(int) |
|
|
*/ |
|
|
public static final int SELECT_ALL = 103; |
|
|
/** |
|
|
* Flag fuer Modus |
|
|
* "Auswahl nur eines Features, das erste sichtbare von Oben". |
|
|
* |
|
|
* @see #setState(int) |
|
|
* @see #setState(int) |
|
|
*/ |
|
|
public static final int SELECT_ONE_FROM_TOP = 104; |
|
|
/** |
|
|
* Flag fuer Modus |
|
|
* "SimpleFeature-Auswahl auf dem obersten (sichtbaren) Layer". |
|
|
* |
|
|
* @see #setState(int) |
|
|
* @see #setState(int) |
|
|
*/ |
|
|
public static final int SELECT_TOP = 4; |
|
233 |
|
|
234 |
/** |
/** |
235 |
* {@link Font} used to paint the wait messages into the map |
* {@link Font} used to paint the wait messages into the map |
236 |
* |
* |
237 |
* @see #addGadgets(Graphics2D, boolean) |
* @see #addGadgets(Graphics2D, boolean) |
238 |
*/ |
*/ |
239 |
final static Font waitFont = new Font("Arial", Font.BOLD, 30); |
final static Font waitFont = new Font("Arial", Font.BOLD, 28); |
240 |
|
|
241 |
/** |
/** |
242 |
* {@link Font} used to paint error messages into the map |
* {@link Font} used to paint error messages into the map |
246 |
final static Font errorFont = new Font("Arial", Font.BOLD, 13); |
final static Font errorFont = new Font("Arial", Font.BOLD, 13); |
247 |
|
|
248 |
/** |
/** |
249 |
|
* If last average last two renderings took more than that many ms, show the |
250 |
|
* user a scaled preview |
251 |
|
**/ |
252 |
|
private static final long PRESCALE_MINTIME = 230; |
253 |
|
|
254 |
|
/** |
255 |
* The wait message painted into the map while rendering is going on on |
* The wait message painted into the map while rendering is going on on |
256 |
* another thread. |
* another thread. |
257 |
* |
* |
266 |
* @param e |
* @param e |
267 |
* Maus-Ereignis |
* Maus-Ereignis |
268 |
*/ |
*/ |
269 |
public static Point2D getMapCoordinatesFromEvent(final MouseEvent e) { |
public static DirectPosition2D getMapCoordinatesFromEvent(final MouseEvent e) { |
270 |
// aktuelle Geo-Position aus GeoMouseEvent ermitteln |
// aktuelle Geo-Position aus GeoMouseEvent ermitteln |
271 |
if (e != null && e instanceof MapMouseEvent) |
if (e != null && e instanceof MapMouseEvent) |
272 |
try { |
try { |
273 |
return ((MapMouseEvent) e).getMapPosition().toPoint2D(); |
return ((MapMouseEvent) e).getMapPosition(); |
274 |
} catch (final Exception err) { |
} catch (final Exception err) { |
275 |
LOGGER |
LOGGER |
276 |
.error( |
.error( |
287 |
return null; |
return null; |
288 |
|
|
289 |
final AffineTransform at = xMapPane.getScreenToWorld(); |
final AffineTransform at = xMapPane.getScreenToWorld(); |
290 |
if (at != null) |
if (at != null) { |
291 |
return at.transform(e.getPoint(), null); |
Point2D transformed = at.transform(e.getPoint(), null); |
292 |
|
return new DirectPosition2D(xMapPane.getMapContext() |
293 |
|
.getCoordinateReferenceSystem(), transformed.getX(), |
294 |
|
transformed.getY()); |
295 |
|
} |
296 |
return null; |
return null; |
297 |
} |
} |
298 |
throw new IllegalArgumentException( |
throw new IllegalArgumentException( |
307 |
|
|
308 |
@Override |
@Override |
309 |
public void layerAdded(final MapLayerListEvent event) { |
public void layerAdded(final MapLayerListEvent event) { |
310 |
MapLayer layer = event.getLayer(); |
final MapLayer layer = event.getLayer(); |
311 |
layer.addMapLayerListener(bgMapLayerListener); |
layer.addMapLayerListener(bgMapLayerListener); |
312 |
requestStartRendering(); |
requestStartRendering(); |
|
|
|
313 |
} |
} |
314 |
|
|
315 |
@Override |
@Override |
403 |
* While dragging, the {@link #updateFinalImage()} method is translating the |
* While dragging, the {@link #updateFinalImage()} method is translating the |
404 |
* cached images while setting it together. |
* cached images while setting it together. |
405 |
**/ |
**/ |
406 |
Point imageOrigin = new Point(0, 0); |
private final Point imageOrigin = new Point(0, 0); |
407 |
/** |
/** |
408 |
* For every rendering thread started, |
* For every rendering thread started, |
409 |
* {@link GTUtil#createGTRenderer(MapContext)} is called to create a new |
* {@link GTUtil#createGTRenderer(MapContext)} is called to create a new |
425 |
public void layerAdded(final MapLayerListEvent event) { |
public void layerAdded(final MapLayerListEvent event) { |
426 |
event.getLayer().addMapLayerListener(localMapLayerListener); |
event.getLayer().addMapLayerListener(localMapLayerListener); |
427 |
|
|
428 |
localRenderer.setContext(getMapContext()); |
getLocalRenderer().setContext(getMapContext()); |
429 |
requestStartRendering(); |
requestStartRendering(); |
430 |
|
|
431 |
} |
} |
432 |
|
|
433 |
@Override |
@Override |
434 |
public void layerChanged(final MapLayerListEvent event) { |
public void layerChanged(final MapLayerListEvent event) { |
435 |
localRenderer.setContext(getMapContext()); |
// getLocalRenderer().setContext(getMapContext()); geht doch auch |
436 |
|
// ohne?!?!? wow... |
437 |
requestStartRendering(); |
requestStartRendering(); |
438 |
} |
} |
439 |
|
|
440 |
@Override |
@Override |
441 |
public void layerMoved(final MapLayerListEvent event) { |
public void layerMoved(final MapLayerListEvent event) { |
442 |
localRenderer.setContext(getMapContext()); |
getLocalRenderer().setContext(getMapContext()); |
443 |
requestStartRendering(); |
requestStartRendering(); |
444 |
} |
} |
445 |
|
|
447 |
public void layerRemoved(final MapLayerListEvent event) { |
public void layerRemoved(final MapLayerListEvent event) { |
448 |
if (event.getLayer() != null) |
if (event.getLayer() != null) |
449 |
event.getLayer().removeMapLayerListener(localMapLayerListener); |
event.getLayer().removeMapLayerListener(localMapLayerListener); |
450 |
localRenderer.setContext(getMapContext()); |
getLocalRenderer().setContext(getMapContext()); |
451 |
requestStartRendering(); |
requestStartRendering(); |
452 |
} |
} |
453 |
}; |
}; |
454 |
|
|
455 |
/** |
/** |
456 |
* Listens to each layer in the local {@link MapContext} for changes and |
* Listens to each layer in the local {@link MapContext} for changes and |
457 |
* triggers repaints. |
* triggers repaints. We don't have to listen layerChanged, because that is |
458 |
|
* already done in {@link #localContextListener} |
459 |
*/ |
*/ |
460 |
protected MapLayerListener localMapLayerListener = new MapLayerAdapter() { |
protected MapLayerListener localMapLayerListener = new MapLayerAdapter() { |
461 |
|
|
462 |
@Override |
// @Override |
463 |
public void layerChanged(final MapLayerEvent event) { |
// public void layerChanged(final MapLayerEvent event) { |
464 |
localRenderer.setContext(getMapContext()); // betters for SLD |
// // getLocalRenderer().setContext(getMapContext()); // betters for SLD |
465 |
// changes?! |
// // // changes?! |
466 |
requestStartRendering(); |
// // requestStartRendering(); |
467 |
} |
// } |
468 |
|
|
469 |
@Override |
@Override |
470 |
public void layerHidden(final MapLayerEvent event) { |
public void layerHidden(final MapLayerEvent event) { |
477 |
} |
} |
478 |
}; |
}; |
479 |
|
|
480 |
private final GTRenderer localRenderer = GTUtil.createGTRenderer(); |
final private GTRenderer localRenderer = GTUtil.createGTRenderer(); |
481 |
|
|
482 |
private final GTRenderer bgRenderer = GTUtil.createGTRenderer(); |
private final GTRenderer bgRenderer = GTUtil.createGTRenderer(); |
483 |
|
|
498 |
/** |
/** |
499 |
* 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. |
500 |
*/ |
*/ |
501 |
private Color mapBackgroundColor = Color.WHITE; |
private Color mapBackgroundColor = null; |
502 |
|
|
503 |
/** |
/** |
504 |
* 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 |
547 |
private BufferedImage preFinalImage; |
private BufferedImage preFinalImage; |
548 |
|
|
549 |
// ** if 0, no quick preview will be shown **/ |
// ** if 0, no quick preview will be shown **/ |
550 |
private int quickPreviewHint = 0; |
// private int quickPreviewHint = 0; |
551 |
|
|
552 |
private Map<Object, Object> rendererHints = GTUtil |
private Map<Object, Object> rendererHints = GTUtil |
553 |
.getDefaultGTRendererHints(localRenderer); |
.getDefaultGTRendererHints(getLocalRenderer()); |
554 |
|
|
555 |
/** |
/** |
556 |
* If set to <code>true</code>, the {@link #startRenderThreadsTimer} will |
* If set to <code>true</code>, the {@link #startRenderThreadsTimer} will |
570 |
* thread. |
* thread. |
571 |
*/ |
*/ |
572 |
final private Timer startRenderThreadsTimer; |
final private Timer startRenderThreadsTimer; |
573 |
|
// |
574 |
/** |
// /** |
575 |
* The default state is ZOOM_IN, hence by default the |
// * The default state is ZOOM_IN, hence by default the |
576 |
* {@link #zoomMapPaneMouseListener} is also enabled. |
// * {@link #xMapPaneMouseListener} is also enabled. |
577 |
**/ |
// **/ |
578 |
private int state = ZOOM_IN; |
// private int state = ZOOM_IN; |
579 |
|
// |
580 |
/** |
// /** |
581 |
* Manuell gesetzter statischer Cursor, unabhaengig von der aktuellen |
// * Manuell gesetzter statischer Cursor, unabhaengig von der aktuellen |
582 |
* MapPane-Funktion |
// * MapPane-Funktion |
583 |
*/ |
// */ |
584 |
protected Cursor staticCursor = null; |
// protected Cursor staticCursor = null; |
585 |
|
|
586 |
private AffineTransform worldToScreen; |
private AffineTransform worldToScreen; |
587 |
|
|
588 |
|
// /** |
589 |
|
// * This {@link MouseListener} is managing all zoom related tasks |
590 |
|
// */ |
591 |
|
// private final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new |
592 |
|
// ZoomXMapPaneMouseListener( |
593 |
|
// this); |
594 |
|
|
595 |
/** |
/** |
596 |
* This {@link MouseListener} is managing all zoom related tasks |
* This {@link MouseListener} is managing all zoom related tasks |
597 |
*/ |
*/ |
598 |
public final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new ZoomXMapPaneMouseListener( |
private final XMapPaneMouseListener xMapPaneMouseListener = new XMapPaneMouseListener( |
599 |
this); |
this); |
600 |
|
|
601 |
/** Is set if a renderer has an error **/ |
/** Is set if a renderer has an error **/ |
625 |
*/ |
*/ |
626 |
public XMapPane(final MapContext localContext_, |
public XMapPane(final MapContext localContext_, |
627 |
final Map<Object, Object> rendererHints) { |
final Map<Object, Object> rendererHints) { |
628 |
|
|
629 |
super(true); |
super(true); |
630 |
|
|
631 |
|
blinkTimer = initBlinkTimer(); |
632 |
|
|
633 |
|
// A default setting |
634 |
|
RenderingHints hintsJava2d = ImageUtilities.NN_INTERPOLATION_HINT; |
635 |
|
setJava2dHints(hintsJava2d); |
636 |
|
|
637 |
setRendererHints(rendererHints); |
setRendererHints(rendererHints); |
638 |
|
|
639 |
setOpaque(true); |
setOpaque(true); |
644 |
/** |
/** |
645 |
* Adding the #zoomMapPaneMouseListener |
* Adding the #zoomMapPaneMouseListener |
646 |
*/ |
*/ |
647 |
this.addMouseListener(zoomMapPaneMouseListener); |
this.addMouseListener(xMapPaneMouseListener); |
648 |
this.addMouseMotionListener(zoomMapPaneMouseListener); |
this.addMouseMotionListener(xMapPaneMouseListener); |
649 |
this.addMouseWheelListener(zoomMapPaneMouseListener); |
this.addMouseWheelListener(xMapPaneMouseListener); |
650 |
|
|
651 |
|
// By default the XMapPAne uses the ZOOM_IN tool. |
652 |
|
setTool(XMapPaneTool.ZOOM_IN); |
653 |
|
|
654 |
/* |
/* |
655 |
* We use a Timer object to avoid rendering delays and flickering when |
* We use a Timer object to avoid rendering delays and flickering when |
665 |
if (!isWellDefined()) |
if (!isWellDefined()) |
666 |
return; |
return; |
667 |
|
|
668 |
LOGGER.info("resizeTimer performed"); |
// LOGGER.debug("resizeTimer performed"); |
669 |
|
|
670 |
final Rectangle bounds = getVisibleRect(); |
// final Rectangle bounds = getVisibleRect(); |
671 |
// |
// |
672 |
// System.out.println("\n\ntimer performs with bounds = " |
// System.out.println("\n\ntimer performs with bounds = " |
673 |
// + bounds); |
// + bounds); |
674 |
|
|
675 |
final Envelope geoMapArea = tranformWindowToGeo( |
// final Envelope geoMapArea = tranformWindowToGeo( |
676 |
bounds.x, bounds.y, bounds.x + bounds.width, |
// bounds.x, bounds.y, bounds.x + bounds.width, |
677 |
bounds.y + bounds.height); |
// bounds.y + bounds.height); |
678 |
|
|
679 |
if (setMapArea(geoMapArea)) { |
paneResized = true; |
680 |
LOGGER.info(" maparea changed"); |
if (!setMapArea(getMapArea())) { |
681 |
paneResized = true; |
// It's important to request new rendering here. |
682 |
} else |
// setMapArea only returns true and only calls |
683 |
LOGGER.info(" maparea NOT changed"); |
// requestStartRendering if the maparea has changed. |
684 |
|
// But if the component is resized, the maparea |
685 |
|
// doesn't have to change. |
686 |
|
requestStartRendering(); |
687 |
|
} |
688 |
|
|
689 |
} |
} |
690 |
}); |
}); |
691 |
resizeTimer.setRepeats(false); |
resizeTimer.setRepeats(false); |
697 |
@Override |
@Override |
698 |
public void componentResized(final ComponentEvent e) { |
public void componentResized(final ComponentEvent e) { |
699 |
|
|
700 |
// Seems to be called twice with the same size.. |
// Seems to be called twice with the same size.. |
701 |
if (oldVisibleRect != null |
if (oldVisibleRect != null |
702 |
&& oldVisibleRect.equals(getVisibleRect())){ |
&& oldVisibleRect.equals(getVisibleRect())) { |
703 |
LOGGER.info("skipping resize."); |
// LOGGER.debug("skipping resize."); |
704 |
return; |
return; |
705 |
} |
} |
706 |
|
|
707 |
LOGGER.info("resized: " + getVisibleRect()); |
// LOGGER.debug("resized: " + getVisibleRect()); |
708 |
resizeTimer.restart(); |
resizeTimer.restart(); |
709 |
oldVisibleRect = getVisibleRect(); |
oldVisibleRect = getVisibleRect(); |
710 |
} |
} |
741 |
@Override |
@Override |
742 |
public void actionPerformed(final ActionEvent e) { |
public void actionPerformed(final ActionEvent e) { |
743 |
synchronized (requestStartRendering) { |
synchronized (requestStartRendering) { |
744 |
if (requestStartRendering && isWellDefined()) { |
if (requestStartRendering && isWellDefined() && isEnabled()) { |
745 |
|
|
746 |
if (localExecuter.isRunning()) { |
if (localExecuter.isRunning()) { |
747 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
835 |
|
|
836 |
final Envelope maxAllowedExtend = getMaxExtend(); |
final Envelope maxAllowedExtend = getMaxExtend(); |
837 |
|
|
838 |
|
// This variable is used to break the loop if it runs forever... |
839 |
|
Envelope lastCalculatedArea = null; |
840 |
|
/* |
841 |
|
* If a maxAllowedExtend is set, we have to honour that... |
842 |
|
*/ |
843 |
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) |
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) |
844 |
&& newArea != null && !newArea.isNull() |
&& newArea != null && !newArea.isNull() |
845 |
&& !Double.isNaN(newArea.getMinX()) |
&& !Double.isNaN(newArea.getMinX()) |
846 |
&& !Double.isNaN(newArea.getMaxX()) |
&& !Double.isNaN(newArea.getMaxX()) |
847 |
&& !Double.isNaN(newArea.getMinY()) |
&& !Double.isNaN(newArea.getMinY()) |
848 |
&& !Double.isNaN(newArea.getMaxY())) { |
&& !Double.isNaN(newArea.getMaxY())) // Due to Double precision |
849 |
/* |
// problems, this may |
850 |
* If a maxExtend is set, we have to honour that... |
// iterate for ever |
851 |
*/ |
{ |
852 |
|
|
853 |
|
if (newArea.equals(lastCalculatedArea)) |
854 |
|
break; |
855 |
|
// Check that we are not iterating for ever due to double precision |
856 |
|
// rounding errors |
857 |
|
lastCalculatedArea = newArea; |
858 |
|
|
859 |
// Exceeds top? Move down and maybe cut |
// Exceeds top? Move down and maybe cut |
860 |
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
959 |
.getCoordinateReferenceSystem()), false); |
.getCoordinateReferenceSystem()), false); |
960 |
} |
} |
961 |
} |
} |
962 |
|
|
963 |
} |
} |
964 |
|
|
965 |
return new ReferencedEnvelope(newArea, env |
return new ReferencedEnvelope(newArea, env |
1016 |
// Remove all mapPaneListeners that have registered with us |
// Remove all mapPaneListeners that have registered with us |
1017 |
mapPaneListeners.clear(); |
mapPaneListeners.clear(); |
1018 |
|
|
1019 |
removeMouseMotionListener(zoomMapPaneMouseListener); |
removeMouseMotionListener(xMapPaneMouseListener); |
1020 |
removeMouseListener(zoomMapPaneMouseListener); |
removeMouseListener(xMapPaneMouseListener); |
1021 |
|
|
1022 |
if (localContext != null) |
if (localContext != null) |
1023 |
getMapContext().clearLayerList(); |
getMapContext().clearLayerList(); |
1033 |
*/ |
*/ |
1034 |
protected void drawRectangle(final Graphics graphics, final Point startPos, |
protected void drawRectangle(final Graphics graphics, final Point startPos, |
1035 |
final Point e) { |
final Point e) { |
1036 |
|
drawRectangle(graphics, startPos, e, Color.WHITE, false); |
1037 |
|
} |
1038 |
|
|
1039 |
|
/** |
1040 |
|
* Draws a rectangle in XOR mode from the origin at {@link #startPos} to the |
1041 |
|
* given point. All in screen coordinates. |
1042 |
|
*/ |
1043 |
|
protected void drawRectangle(final Graphics graphics, final Point startPos, |
1044 |
|
final Point e, Color color, boolean fill) { |
1045 |
|
|
1046 |
if (!isWellDefined()) |
if (!isWellDefined()) |
1047 |
return; |
return; |
1057 |
if (width == 0 && height == 0) |
if (width == 0 && height == 0) |
1058 |
return; |
return; |
1059 |
|
|
1060 |
graphics.setXORMode(Color.WHITE); |
graphics.setXORMode(color); |
1061 |
|
|
1062 |
|
if (fill) { |
1063 |
|
graphics.fillRect(left, bottom, width, height); |
1064 |
|
graphics.setXORMode(Color.WHITE); |
1065 |
|
} |
1066 |
|
|
1067 |
graphics.drawRect(left, bottom, width, height); |
graphics.drawRect(left, bottom, width, height); |
1068 |
} |
} |
1069 |
|
|
1075 |
* |
* |
1076 |
* @param g |
* @param g |
1077 |
* Graphics2D to paint the preview into |
* Graphics2D to paint the preview into |
|
* |
|
|
* @param state |
|
|
* Max be {@link #ZOOM_IN} or {@link #ZOOM_OUT} |
|
1078 |
*/ |
*/ |
1079 |
protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) { |
protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) { |
1080 |
|
|
1081 |
// if (1 == 1)return false; |
// if (1 == 1)return false; |
1082 |
|
// if (quickPreviewHint == 0) |
1083 |
|
// return false; |
1084 |
|
|
1085 |
if (quickPreviewHint == 0) |
if (oldMapArea == null) |
1086 |
return false; |
return false; |
1087 |
|
|
1088 |
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, |
if (getPreFinalImage() == null) |
|
RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); |
|
|
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
|
|
RenderingHints.VALUE_ANTIALIAS_OFF); |
|
|
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, |
|
|
RenderingHints.VALUE_RENDER_SPEED); |
|
|
|
|
|
if (oldMapArea == null) |
|
1089 |
return false; |
return false; |
1090 |
|
|
1091 |
final Rectangle visibleArea = getVisibleRect(); |
final Rectangle visibleArea = getVisibleRect(); |
1100 |
final int xx2 = (int) Math.round(oldMapWindow.getMaxX()); |
final int xx2 = (int) Math.round(oldMapWindow.getMaxX()); |
1101 |
final int yy2 = (int) Math.round(oldMapWindow.getMaxY()); |
final int yy2 = (int) Math.round(oldMapWindow.getMaxY()); |
1102 |
|
|
1103 |
|
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, |
1104 |
|
RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); |
1105 |
|
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
1106 |
|
RenderingHints.VALUE_ANTIALIAS_OFF); |
1107 |
|
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, |
1108 |
|
RenderingHints.VALUE_RENDER_SPEED); |
1109 |
|
|
1110 |
graphics.drawImage(getPreFinalImage(), xx1, yy1, xx2, yy2, |
graphics.drawImage(getPreFinalImage(), xx1, yy1, xx2, yy2, |
1111 |
(int) visibleArea.getMinX(), (int) visibleArea.getMinY(), |
(int) visibleArea.getMinX(), (int) visibleArea.getMinY(), |
1112 |
(int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(), |
(int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(), |
1115 |
final Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2 |
final Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2 |
1116 |
- yy1); |
- yy1); |
1117 |
|
|
1118 |
SwingUtil.clearAround(graphics, painedArea, visibleArea); |
SwingUtil.clearAround(graphics, painedArea, visibleArea, |
1119 |
|
getMapBackgroundColor()); |
1120 |
|
|
1121 |
addGadgets(graphics, true); |
addGadgets(graphics, true); |
1122 |
|
|
1123 |
quickPreviewHint = 0; |
// quickPreviewHint = 0; |
1124 |
|
|
1125 |
repaintTimer.restart(); |
repaintTimer.restart(); |
1126 |
|
|
|
graphics.dispose(); |
|
|
|
|
1127 |
// Something has been drawn |
// Something has been drawn |
1128 |
return true; |
return true; |
1129 |
} |
} |
1136 |
* Lazyly initializes a {@link BufferedImage} for the background renderer. |
* Lazyly initializes a {@link BufferedImage} for the background renderer. |
1137 |
*/ |
*/ |
1138 |
private Image getBgImage() { |
private Image getBgImage() { |
1139 |
// |
if (bgImage == null) { |
1140 |
// if (bgImage == null) { |
bgImage = new BufferedImage(getVisibleRect().width, |
1141 |
// bgImage = createImage(getBounds().width, getBounds().height); |
getVisibleRect().height, IMAGETYPE); |
1142 |
// } |
SwingUtil.clearImage(finalImage, getMapBackgroundColor()); |
1143 |
|
} |
1144 |
|
|
1145 |
return bgImage; |
return bgImage; |
1146 |
} |
} |
1158 |
// Rectangle curPaintArea = getVisibleRect(); |
// Rectangle curPaintArea = getVisibleRect(); |
1159 |
finalImage = new BufferedImage(getVisibleRect().width, |
finalImage = new BufferedImage(getVisibleRect().width, |
1160 |
getVisibleRect().height, IMAGETYPE); |
getVisibleRect().height, IMAGETYPE); |
1161 |
|
SwingUtil.clearImage(finalImage, getMapBackgroundColor()); |
1162 |
|
|
1163 |
requestStartRendering(); |
// requestStartRendering(); |
1164 |
} |
} |
1165 |
return finalImage; |
return finalImage; |
1166 |
} |
} |
1167 |
|
|
|
public RenderingHints getJava2dHints() { |
|
|
return java2dHints; |
|
|
} |
|
|
|
|
1168 |
/** |
/** |
1169 |
* Lazyly initializes a {@link BufferedImage} for the background renderer. |
* Lazyly initializes a {@link BufferedImage} for the background renderer. |
1170 |
*/ |
*/ |
1173 |
if (localImage == null) { |
if (localImage == null) { |
1174 |
localImage = new BufferedImage(getVisibleRect().width, |
localImage = new BufferedImage(getVisibleRect().width, |
1175 |
getVisibleRect().height, IMAGETYPE_withAlpha); |
getVisibleRect().height, IMAGETYPE_withAlpha); |
1176 |
|
SwingUtil.clearImage(localImage, getMapBackgroundColor()); |
1177 |
} |
} |
1178 |
|
|
1179 |
return localImage; |
return localImage; |
1189 |
ReferencedEnvelope mapArea_ = null; |
ReferencedEnvelope mapArea_ = null; |
1190 |
try { |
try { |
1191 |
mapArea_ = localContext.getLayerBounds(); |
mapArea_ = localContext.getLayerBounds(); |
1192 |
} catch (final IOException e) { |
} catch (final Exception e) { |
1193 |
LOGGER.warn("localContext.getLayerBounds()", e); |
LOGGER.warn("localContext.getLayerBounds()", e); |
1194 |
} |
} |
1195 |
|
|
1215 |
try { |
try { |
1216 |
localContext.setCoordinateReferenceSystem(GeoImportUtil |
localContext.setCoordinateReferenceSystem(GeoImportUtil |
1217 |
.getDefaultCRS()); |
.getDefaultCRS()); |
1218 |
} catch (Exception e) { |
} catch (final Exception e) { |
1219 |
throw new RuntimeException("setting context CRS:", e); |
throw new RuntimeException("setting context CRS:", e); |
1220 |
} |
} |
1221 |
|
|
1224 |
} |
} |
1225 |
|
|
1226 |
/** |
/** |
1227 |
* 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 |
1228 |
|
* methods looks for a parent component and will use its background color. |
1229 |
|
* If no parent component is available, WHITE is returned. |
1230 |
**/ |
**/ |
1231 |
public Color getMapBackgroundColor() { |
public Color getMapBackgroundColor() { |
1232 |
|
if (mapBackgroundColor == null) { |
1233 |
|
if (getParent() != null) |
1234 |
|
return getParent().getBackground(); |
1235 |
|
else |
1236 |
|
return Color.WHITE; |
1237 |
|
} |
1238 |
return mapBackgroundColor; |
return mapBackgroundColor; |
1239 |
} |
} |
1240 |
|
|
1261 |
|
|
1262 |
public Envelope getMaxExtend() { |
public Envelope getMaxExtend() { |
1263 |
if (maxExtend == null) { |
if (maxExtend == null) { |
1264 |
// Commented-out because it takes soo much time! |
|
1265 |
// |
// The next command may take long time! |
1266 |
// long start = System.currentTimeMillis(); |
// long start = System.currentTimeMillis(); |
1267 |
// final ReferencedEnvelope layerBounds = GTUtil |
final ReferencedEnvelope layerBounds = GTUtil |
1268 |
// .getVisibleLayoutBounds(localContext); |
.getVisibleLayoutBounds(localContext); |
1269 |
// |
// |
1270 |
// LOGGER.info( |
// LOGGER.info( |
1271 |
// (System.currentTimeMillis()-start)+"m to get maxExtend"); |
// (System.currentTimeMillis()-start)+"m to get maxExtend"); |
1272 |
// |
// |
1273 |
// if (layerBounds == null) { |
if (layerBounds == null) { |
1274 |
// // TODO Last fallback could be the CRS valid area |
// // TODO Last fallback could be the CRS valid area |
1275 |
// return null; |
return null; |
1276 |
// } |
} |
1277 |
// |
|
1278 |
// // Kartenbereich um 10% vergroessern |
return JTSUtil.fixAspectRatio(getVisibleRect(), |
1279 |
// return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil |
addDefaultMargin(layerBounds), true); |
1280 |
// .expandEnvelope(layerBounds, 0.1), true); |
|
1281 |
} |
} |
1282 |
return maxExtend; |
return maxExtend; |
1283 |
} |
} |
1305 |
} |
} |
1306 |
|
|
1307 |
private Image getPreFinalImage() { |
private Image getPreFinalImage() { |
|
// if (preFinalImage == null) { |
|
|
// |
|
|
// // Rectangle curPaintArea = getVisibleRect(); |
|
|
// // preFinalImage = new BufferedImage(curPaintArea.width, |
|
|
// // curPaintArea.height, BufferedImage.TYPE_INT_RGB); |
|
|
// |
|
|
// preFinalImage = createImage(getBounds().width, getBounds().height); |
|
|
// |
|
|
// requestStartRendering(); |
|
|
// } |
|
1308 |
return preFinalImage; |
return preFinalImage; |
1309 |
} |
} |
1310 |
|
|
1332 |
return new AffineTransform(screenToWorld); |
return new AffineTransform(screenToWorld); |
1333 |
} |
} |
1334 |
|
|
1335 |
public int getState() { |
// public int getState() { |
1336 |
return state; |
// return state; |
1337 |
} |
// } |
1338 |
|
// |
1339 |
/** |
// /** |
1340 |
* Liefert den statisch eingestellten Cursor, der unabhaengig von der |
// * Liefert den statisch eingestellten Cursor, der unabhaengig von der |
1341 |
* eingestellten MapPane-Aktion (Zoom, Auswahl, ...) verwendet wird. |
// * eingestellten MapPane-Aktion (Zoom, Auswahl, ...) verwendet wird. |
1342 |
* |
// * |
1343 |
* @return {@code null}, wenn kein statischer Cursor verwendet, sondern der |
// * @return {@code null}, wenn kein statischer Cursor verwendet, sondern |
1344 |
* Cursor automatisch je nach MapPane-Aktion eingestellt wird. |
// der |
1345 |
*/ |
// * Cursor automatisch je nach MapPane-Aktion eingestellt wird. |
1346 |
public Cursor getStaticCursor() { |
// */ |
1347 |
return this.staticCursor; |
// public Cursor getStaticCursor() { |
1348 |
} |
// return this.staticCursor; |
1349 |
|
// } |
1350 |
|
|
1351 |
public AffineTransform getWorldToScreenTransform() { |
public AffineTransform getWorldToScreenTransform() { |
1352 |
if (worldToScreen == null) { |
if (worldToScreen == null) { |
1400 |
} |
} |
1401 |
|
|
1402 |
/** |
/** |
1403 |
* Called from the listeners while the mouse is dragging, this method either |
* Usually called from {@link XMapPaneAction_Pan} to pan the image. |
|
* paints a translated (moved/panned) version of the image, or a rectangle. |
|
1404 |
* |
* |
1405 |
* @param startPos |
* @param startPos |
1406 |
* in screen coordinates |
* in screen coordinates |
1407 |
* @param lastPos |
* @param lastPos |
1408 |
* in screen coordinates |
* in screen coordinates |
|
* @param event |
|
|
* the {@link MouseEvent} to read the mouse buttons from |
|
1409 |
*/ |
*/ |
1410 |
public void mouseDragged(final Point startPos, final Point lastPos, |
public void pan(final int dX, final int dY) { |
|
final MouseEvent event) { |
|
|
|
|
|
if ((getState() == XMapPane.PAN) |
|
|
|| ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) { |
|
1411 |
|
|
1412 |
// Panning needs a panning coursor |
// Panning needs a panning coursor |
1413 |
if (getCursor() != SwingUtil.PANNING_CURSOR) { |
if (getCursor() != SwingUtil.PANNING_CURSOR) { |
1414 |
setCursor(SwingUtil.PANNING_CURSOR); |
setCursor(SwingUtil.PANNING_CURSOR); |
1415 |
|
|
1416 |
// While panning, we deactivate the rendering. So the tasks are |
// While panning, we deactivate the rendering. So the tasks are |
1417 |
// ready to start when the panning is finished. |
// ready to start when the panning is finished. |
1418 |
if (bgExecuter != null && bgExecuter.isRunning()) |
if (bgExecuter != null && bgExecuter.isRunning()) |
1419 |
bgExecuter.cancelTask(); |
bgExecuter.cancelTask(); |
1420 |
if (localExecuter.isRunning()) |
if (localExecuter.isRunning()) |
1421 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
1422 |
} |
} |
1423 |
|
// |
1424 |
if (lastPos.x > 0 && lastPos.y > 0) { |
// if (lastPos.x > 0 && lastPos.y > 0) { |
1425 |
final int dx = event.getX() - lastPos.x; |
// final int dx = event.getX() - lastPos.x; |
1426 |
final int dy = event.getY() - lastPos.y; |
// final int dy = event.getY() - lastPos.y; |
1427 |
|
|
1428 |
// TODO Stop dragging when the drag would not be valid... |
// TODO Stop dragging when the drag would not be valid... |
1429 |
// boolean dragValid = true; |
// boolean dragValid = true; |
1430 |
// // check if this panning results in a valid mapArea |
// // check if this panning results in a valid mapArea |
1431 |
// { |
// { |
1432 |
// Rectangle winBounds = xMapPane.getBounds(); |
// Rectangle winBounds = xMapPane.getBounds(); |
1433 |
// winBounds.translate(xMapPane.imageOrigin.x, |
// winBounds.translate(xMapPane.imageOrigin.x, |
1434 |
// -xMapPane.imageOrigin.y); |
// -xMapPane.imageOrigin.y); |
1435 |
// Envelope newMapAreaBefore = xMapPane.tranformWindowToGeo( |
// Envelope newMapAreaBefore = xMapPane.tranformWindowToGeo( |
1436 |
// winBounds.x, winBounds.y, winBounds.x |
// winBounds.x, winBounds.y, winBounds.x |
1437 |
// + winBounds.width, winBounds.y |
// + winBounds.width, winBounds.y |
1438 |
// + winBounds.height); |
// + winBounds.height); |
1439 |
// |
// |
1440 |
// |
// |
1441 |
// winBounds = xMapPane.getBounds(); |
// winBounds = xMapPane.getBounds(); |
1442 |
// Point testIng = new Point(xMapPane.imageOrigin); |
// Point testIng = new Point(xMapPane.imageOrigin); |
1443 |
// testIng.translate(dx, dy); |
// testIng.translate(dx, dy); |
1444 |
// winBounds.translate(testIng.x, -testIng.y); |
// winBounds.translate(testIng.x, -testIng.y); |
1445 |
// Envelope newMapAreaAfter = xMapPane.tranformWindowToGeo( |
// Envelope newMapAreaAfter = xMapPane.tranformWindowToGeo( |
1446 |
// winBounds.x, winBounds.y, winBounds.x |
// winBounds.x, winBounds.y, winBounds.x |
1447 |
// + winBounds.width, winBounds.y |
// + winBounds.width, winBounds.y |
1448 |
// + winBounds.height); |
// + winBounds.height); |
1449 |
// |
// |
1450 |
// // If the last drag doesn't change the MapArea anymore cancel |
// // If the last drag doesn't change the MapArea anymore cancel |
1451 |
// it. |
// it. |
1452 |
// if (xMapPane.bestAllowedMapArea(newMapAreaAfter).equals( |
// if (xMapPane.bestAllowedMapArea(newMapAreaAfter).equals( |
1453 |
// xMapPane.bestAllowedMapArea(newMapAreaBefore))){ |
// xMapPane.bestAllowedMapArea(newMapAreaBefore))){ |
1454 |
// dragValid = false; |
// dragValid = false; |
1455 |
// return; |
// return; |
1456 |
// } |
// } |
1457 |
// } |
// } |
1458 |
|
|
1459 |
imageOrigin.translate(dx, dy); |
getImageOrigin().translate(dX, dY); |
1460 |
updateFinalImage(); |
updateFinalImage(); |
1461 |
repaint(); |
repaint(); |
1462 |
} |
// } |
1463 |
|
|
1464 |
} else if ((getState() == XMapPane.ZOOM_IN) |
// } else if ((getState() == XMapPane.ZOOM_IN) |
1465 |
|| (getState() == XMapPane.ZOOM_OUT) |
// || (getState() == XMapPane.ZOOM_OUT) |
1466 |
|| (getState() == XMapPane.SELECT_ALL) |
// || (getState() == XMapPane.SELECT_ALL) |
1467 |
|| (getState() == XMapPane.SELECT_TOP)) { |
// || (getState() == XMapPane.SELECT_TOP)) { |
1468 |
|
// |
1469 |
// Draws a rectangle |
// // Draws a rectangle |
1470 |
final Graphics graphics = getGraphics(); |
// final Graphics2D graphics = (Graphics2D) getGraphics(); |
1471 |
drawRectangle(graphics, startPos, event.getPoint()); |
// drawRectangle(graphics, startPos, event.getPoint()); |
1472 |
if ((lastPos.x > 0) && (lastPos.y > 0)) |
// if ((lastPos.x > 0) && (lastPos.y > 0)) |
1473 |
drawRectangle(graphics, startPos, lastPos); |
// drawRectangle(graphics, startPos, lastPos); |
1474 |
graphics.dispose(); |
// graphics.dispose(); |
1475 |
} |
// } |
1476 |
} |
} |
1477 |
|
|
1478 |
/** |
/** |
1479 |
* Called by the {@link RenderingExecutor} when rendering was cancelled. |
* Called by the {@link RenderingExecutor} when rendering was cancelled. |
1480 |
*/ |
*/ |
1481 |
public void onRenderingCancelled() { |
public void onRenderingCancelled() { |
1482 |
LOGGER.debug("Rendering cancelled"); |
// LOGGER.debug("Rendering cancelled"); |
1483 |
repaintTimer.stop(); |
repaintTimer.stop(); |
1484 |
} |
} |
1485 |
|
|
1486 |
/** |
/** |
1487 |
* Called by the {@link RenderingExecutor} when rendering has been |
* Called by the {@link RenderingExecutor} when rendering has been |
1488 |
* completed. |
* completed. |
1489 |
|
* |
1490 |
|
* @param l |
1491 |
|
* long ms the rendering took |
1492 |
*/ |
*/ |
1493 |
public void onRenderingCompleted() { |
public void onRenderingCompleted(final long l) { |
1494 |
LOGGER.info("complete"); |
lastRenderingDuration = (lastRenderingDuration + l) / 2; |
1495 |
|
// LOGGER |
1496 |
|
// .debug("complete rendering after " + lastRenderingDuration |
1497 |
|
// + "ms"); |
1498 |
|
|
1499 |
repaintTimer.stop(); |
repaintTimer.stop(); |
1500 |
|
|
1546 |
|
|
1547 |
if (!isWellDefined()) |
if (!isWellDefined()) |
1548 |
return; |
return; |
1549 |
|
// |
1550 |
|
// if (paneResized) { |
1551 |
|
// // ((Graphics2D) g).setBackground(getMapBackgroundColor()); |
1552 |
|
// // g.clearRect(0, 0, getVisibleRect().width, |
1553 |
|
// getVisibleRect().height); |
1554 |
|
// return; |
1555 |
|
// } |
1556 |
|
|
1557 |
// super.paintComponent(g); // candidate for removal |
// super.paintComponent(g); // candidate for removal |
1558 |
|
|
1565 |
// If the new mapArea and the oldMapArea intersect, we can draw some |
// If the new mapArea and the oldMapArea intersect, we can draw some |
1566 |
// quick scaled preview to make the user feel that something is |
// quick scaled preview to make the user feel that something is |
1567 |
// happening. |
// happening. |
1568 |
if (mapAreaChanged && oldMapArea != null |
if (lastRenderingDuration > PRESCALE_MINTIME && mapAreaChanged |
1569 |
|
&& oldMapArea != null |
1570 |
&& getMapArea().intersects(oldMapArea) |
&& getMapArea().intersects(oldMapArea) |
1571 |
& !getMapArea().equals(oldMapArea) && !paneResized) { |
&& !getMapArea().equals(oldMapArea) && !paneResized) { |
1572 |
|
|
1573 |
mapAreaChanged = false; |
mapAreaChanged = false; |
1574 |
|
|
1575 |
if (getMapArea().covers(oldMapArea)) { |
// if (getMapArea().covers(oldMapArea)) { |
1576 |
quickPreviewHint = ZOOM_OUT; |
// // quickPreviewHint = ZOOM_OUT; |
1577 |
paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g); |
// paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) |
1578 |
} else if (oldMapArea.covers(getMapArea())) { |
// g); |
1579 |
quickPreviewHint = ZOOM_IN; |
// } else if (oldMapArea.covers(getMapArea())) { |
1580 |
paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g); |
// quickPreviewHint = ZOOM_IN; |
1581 |
} |
paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g); |
1582 |
|
// } |
1583 |
} |
} |
1584 |
} |
} |
1585 |
|
|
1587 |
|
|
1588 |
g.drawImage(getFinalImage(), 0, 0, null); |
g.drawImage(getFinalImage(), 0, 0, null); |
1589 |
|
|
|
g.dispose(); // cand. for removal |
|
|
|
|
1590 |
paintedSomething = true; // cand. for removal |
paintedSomething = true; // cand. for removal |
1591 |
} |
} |
1592 |
|
|
1635 |
|
|
1636 |
} |
} |
1637 |
|
|
1638 |
/** |
// |
1639 |
* Performs a {@value #PAN} action. During panning, the displacement is |
// /** |
1640 |
* stored in {@link #imageOrigin} object. Calling {@link #performPan()} will |
// * Performs a {@value #PAN} action. During panning, the displacement is |
1641 |
* reset the offset and call {@link #setMapArea(Envelope)}. |
// * stored in {@link #imageOrigin} object. Calling {@link #performPan()} |
1642 |
*/ |
// will |
1643 |
public void performPan() { |
// * reset the offset and call {@link #setMapArea(Envelope)}. |
1644 |
|
// */ |
1645 |
Rectangle winBounds = getVisibleRect(); |
// public void performPan() { |
1646 |
|
// |
1647 |
winBounds.translate(-imageOrigin.x, -imageOrigin.y); |
// final Rectangle winBounds = getVisibleRect(); |
1648 |
final Envelope newMapArea = tranformWindowToGeo(winBounds.x, |
// |
1649 |
winBounds.y, winBounds.x + winBounds.width, winBounds.y |
// winBounds.translate(-imageOrigin.x, -imageOrigin.y); |
1650 |
+ winBounds.height); |
// final Envelope newMapArea = tranformWindowToGeo(winBounds.x, |
1651 |
|
// winBounds.y, winBounds.x + winBounds.width, winBounds.y |
1652 |
imageOrigin.x = 0; |
// + winBounds.height); |
1653 |
imageOrigin.y = 0; |
// |
1654 |
|
// imageOrigin.x = 0; |
1655 |
if (!setMapArea(newMapArea)) { |
// imageOrigin.y = 0; |
1656 |
/** |
// |
1657 |
* If setMapArea returns true, the finalImage is updated anyways. |
// if (!setMapArea(newMapArea)) { |
1658 |
* This if-case exists to ensure that we repaint a correct image |
// /** |
1659 |
* even if the new panning area has been denied. |
// * If setMapArea returns true, the finalImage is updated anyways. |
1660 |
*/ |
// * This if-case exists to ensure that we repaint a correct image |
1661 |
updateFinalImage(); |
// * even if the new panning area has been denied. |
1662 |
repaint(); |
// */ |
1663 |
} |
// updateFinalImage(); |
1664 |
|
// repaint(); |
1665 |
if (getCursor() == SwingUtil.PANNING_CURSOR) |
// } |
1666 |
setCursor(SwingUtil.PAN_CURSOR); |
// |
1667 |
} |
// if (getCursor() == SwingUtil.PANNING_CURSOR) |
1668 |
|
// setCursor(SwingUtil.PAN_CURSOR); |
1669 |
|
// } |
1670 |
|
|
1671 |
/** |
/** |
1672 |
* Entfernt einen Listener von der Map. |
* Entfernt einen Listener von der Map. |
1712 |
* the current map pane extent (screen units) |
* the current map pane extent (screen units) |
1713 |
*/ |
*/ |
1714 |
private void resetTransforms() { |
private void resetTransforms() { |
|
ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea, |
|
|
getMapContext().getCoordinateReferenceSystem()); |
|
|
|
|
1715 |
// System.out |
// System.out |
1716 |
// .println("paintArea in resetTeansofrms = " + getVisibleRect()); |
// .println("paintArea in resetTeansofrms = " + getVisibleRect()); |
1717 |
if (!isWellDefined()) |
if (!isWellDefined()) |
1718 |
return; |
return; |
1719 |
|
|
1720 |
|
if (mapArea == null) |
1721 |
|
return; |
1722 |
|
|
1723 |
|
final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea, |
1724 |
|
getMapContext().getCoordinateReferenceSystem()); |
1725 |
|
|
1726 |
worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv, |
worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv, |
1727 |
getVisibleRect()); |
getVisibleRect()); |
1728 |
|
|
1729 |
try { |
try { |
1730 |
screenToWorld = worldToScreen.createInverse(); |
screenToWorld = worldToScreen.createInverse(); |
1731 |
|
|
1732 |
} catch (NoninvertibleTransformException ex) { |
} catch (final NoninvertibleTransformException ex) { |
1733 |
LOGGER |
LOGGER |
1734 |
.error("can't invert worldToScreen to get screenToWorld!", |
.error("can't invert worldToScreen to get screenToWorld!", |
1735 |
ex); |
ex); |
1785 |
|
|
1786 |
// setMapArea(localContext.getAreaOfInterest()); |
// setMapArea(localContext.getAreaOfInterest()); |
1787 |
|
|
1788 |
localRenderer.setContext(localContext); |
getLocalRenderer().setContext(localContext); |
1789 |
|
|
1790 |
this.localContext.addMapLayerListListener(localContextListener); |
this.localContext.addMapLayerListListener(localContextListener); |
1791 |
|
|
1799 |
|
|
1800 |
} |
} |
1801 |
|
|
1802 |
|
public void setBorder(final Border b) { |
1803 |
|
super.setBorder(b); |
1804 |
|
} |
1805 |
|
|
1806 |
|
/** |
1807 |
|
* Triggers to repaint (fast) and re-render (slow) the JMapPane. |
1808 |
|
*/ |
1809 |
|
public void refresh() { |
1810 |
|
mapImageInvalid = true; |
1811 |
|
repaint(); |
1812 |
|
} |
1813 |
|
|
1814 |
|
// /** |
1815 |
|
// * Triggers to use new {@link GTRenderer} and refresh the map. Should be |
1816 |
|
// * called after {@link Style}s have been changed because GTRenderer is |
1817 |
|
// * otherwise not working well. |
1818 |
|
// */ |
1819 |
|
// public void refreshRenderers() { |
1820 |
|
// localRenderer = GTUtil.createGTRenderer(); |
1821 |
|
// setLocalContext(getMapContext()); |
1822 |
|
// mapImageInvalid = true; |
1823 |
|
// repaint(); |
1824 |
|
// } |
1825 |
|
|
1826 |
|
/** |
1827 |
|
* Set the new map area. |
1828 |
|
* |
1829 |
|
* @param newMapArea |
1830 |
|
* @return <code>true</code> if the mapArea has been changed and a repaint |
1831 |
|
* has been triggered. |
1832 |
|
*/ |
1833 |
public boolean setMapArea(final Envelope newMapArea) { |
public boolean setMapArea(final Envelope newMapArea) { |
1834 |
|
if (newMapArea == null) |
1835 |
|
return false; |
1836 |
|
if (getMapContext().getCoordinateReferenceSystem() == null) |
1837 |
|
return false; |
1838 |
return setMapArea(new ReferencedEnvelope(newMapArea, getMapContext() |
return setMapArea(new ReferencedEnvelope(newMapArea, getMapContext() |
1839 |
.getCoordinateReferenceSystem())); |
.getCoordinateReferenceSystem())); |
1840 |
} |
} |
1841 |
|
|
1842 |
/** |
/** |
1843 |
|
* Set the new map area. |
1844 |
|
* |
1845 |
* @param newMapArea |
* @param newMapArea |
1846 |
* @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 |
1847 |
* has been triggered. |
* has been triggered. |
1916 |
* |
* |
1917 |
* @param if <code>null</code>, white is used. |
* @param if <code>null</code>, white is used. |
1918 |
*/ |
*/ |
1919 |
public void setMapBackgroundColor(Color bgColor) { |
public void setMapBackgroundColor(final Color bgColor) { |
|
if (bgColor == null) |
|
|
bgColor = Color.WHITE; |
|
1920 |
this.mapBackgroundColor = bgColor; |
this.mapBackgroundColor = bgColor; |
1921 |
} |
} |
1922 |
|
|
1974 |
} |
} |
1975 |
|
|
1976 |
// /** Stored the time used for the last real rendering in ms. **/ |
// /** Stored the time used for the last real rendering in ms. **/ |
1977 |
// private long lastRenderingDuration = Long.MAX_VALUE; |
private long lastRenderingDuration = 1000; |
1978 |
|
private XMapPaneTool tool = null; |
1979 |
|
|
1980 |
|
private Timer blinkTimer; |
1981 |
|
|
1982 |
/** |
/** |
1983 |
* Set the minimum (nearest) allowed zoom scale. This is the bigger number |
* Set the minimum (nearest) allowed zoom scale. This is the bigger number |
2009 |
this.rendererHints = rendererHints; |
this.rendererHints = rendererHints; |
2010 |
} |
} |
2011 |
|
|
2012 |
/** |
// @Deprecated |
2013 |
* Enables/Disables the ZOOM Mouse Listener. Upates the Cursor and stops the |
// public void setState(final int state) { |
2014 |
* repaint Timer if |
// this.state = state; |
2015 |
* |
// |
2016 |
* @param state |
// // throw new RuntimeException("Old concept.. migrate to new concept!"); |
2017 |
*/ |
// |
2018 |
public void setState(final int state) { |
// // xMapPaneMouseListener.setEnabled((state == ZOOM_IN |
2019 |
this.state = state; |
// // || state == ZOOM_OUT || state == PAN)); |
2020 |
|
// |
2021 |
zoomMapPaneMouseListener.setEnabled((state == ZOOM_IN |
// // Je nach Aktion den Cursor umsetzen |
2022 |
|| state == ZOOM_OUT || state == PAN)); |
// updateCursor(); |
2023 |
|
// } |
2024 |
// Je nach Aktion den Cursor umsetzen |
|
2025 |
updateCursor(); |
public void configureMouse(MouseInputType type, XMapPaneAction action) { |
2026 |
|
xMapPaneMouseListener.actions.put(type, action); |
2027 |
} |
} |
2028 |
|
|
2029 |
/** |
/** |
2030 |
* Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion (Zoom, |
* Configure the {@link XMapPaneTool} that active on the map. Passing |
2031 |
* Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor |
* <code>null</code> will set the NO_ACTION tool. |
2032 |
* gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion |
*/ |
2033 |
* beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann |
public void setTool(XMapPaneTool tool) { |
2034 |
* {@code null} als Parameter uebergeben werden |
if (tool == null) |
2035 |
* |
tool = XMapPaneTool.NO_ACTION; |
2036 |
* @param cursor |
this.tool = tool; |
2037 |
* Cursor |
xMapPaneMouseListener.configure(tool); |
2038 |
*/ |
setCursor(tool.getCursor()); |
2039 |
public void setStaticCursor(final Cursor cursor) { |
} |
2040 |
this.staticCursor = cursor; |
|
2041 |
if (cursor != null) |
// /** |
2042 |
super.setCursor(cursor); |
// * Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion |
2043 |
} |
// (Zoom, |
2044 |
|
// * Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor |
2045 |
|
// * gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion |
2046 |
|
// * beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann |
2047 |
|
// * {@code null} als Parameter uebergeben werden |
2048 |
|
// * |
2049 |
|
// * @param cursor |
2050 |
|
// * Cursor |
2051 |
|
// */ |
2052 |
|
// public void setStaticCursor(final Cursor cursor) { |
2053 |
|
// this.staticCursor = cursor; |
2054 |
|
// if (cursor != null) |
2055 |
|
// super.setCursor(cursor); |
2056 |
|
// } |
2057 |
|
|
2058 |
/** |
/** |
2059 |
* Starts rendering on one or two threads |
* Starts rendering on one or two threads |
2099 |
// localExecuter = new RenderingExecutor(this, 150l); |
// localExecuter = new RenderingExecutor(this, 150l); |
2100 |
// LOGGER.debug("starting local renderer:"); |
// LOGGER.debug("starting local renderer:"); |
2101 |
|
|
2102 |
localRenderer.setJava2DHints(getJava2dHints()); |
getLocalRenderer().setJava2DHints(getJava2dHints()); |
2103 |
localRenderer.setRendererHints(getRendererHints()); |
getLocalRenderer().setRendererHints(getRendererHints()); |
2104 |
|
|
2105 |
final boolean submitted = localExecuter.submit(getMapArea(), |
final boolean submitted = localExecuter.submit(getMapArea(), |
2106 |
curPaintArea, (Graphics2D) getLocalImage().getGraphics(), |
curPaintArea, (Graphics2D) getLocalImage().getGraphics(), |
2107 |
localRenderer); |
getLocalRenderer()); |
2108 |
if (submitted) |
if (submitted) |
2109 |
repaintTimer.restart(); |
repaintTimer.restart(); |
2110 |
else |
else |
2116 |
updateCursor(); |
updateCursor(); |
2117 |
} |
} |
2118 |
|
|
2119 |
|
private RenderingHints getJava2dHints() { |
2120 |
|
return java2dHints; |
2121 |
|
} |
2122 |
|
|
2123 |
/** |
/** |
2124 |
* Transformiert einen Geo-Koordinaten-Bereich in Fenster-Koordinaten. |
* Transformiert einen Geo-Koordinaten-Bereich in Fenster-Koordinaten. |
2125 |
* |
* |
2131 |
* X-Koordinate der BIS-Position |
* X-Koordinate der BIS-Position |
2132 |
* @param py |
* @param py |
2133 |
* Y-Koordinate der BIS-Position |
* Y-Koordinate der BIS-Position |
|
* @param winToGeotransform |
|
|
* Eine Window to Geo transform. If <code>null</code>, |
|
|
* {@link #getScreenToWorld()} is used. |
|
2134 |
*/ |
*/ |
2135 |
public Envelope tranformGeoToWindow(final double ox, final double oy, |
public Envelope tranformGeoToWindow(final double ox, final double oy, |
2136 |
final double px, final double py) { |
final double px, final double py) { |
2147 |
} |
} |
2148 |
|
|
2149 |
/** |
/** |
2150 |
|
* Transformiert einen Geo-Koordinate in eine Fenster-Koordinaten. |
2151 |
|
* |
2152 |
|
* @param x |
2153 |
|
* X-Koordinate der VON-Position |
2154 |
|
* @param y |
2155 |
|
* Y-Koordinate der VON-Position |
2156 |
|
*/ |
2157 |
|
public Point2D tranformGeoToWindow(final double x, final double y) { |
2158 |
|
return getWorldToScreenTransform().transform(new Point2D.Double(x, y), |
2159 |
|
null); |
2160 |
|
} |
2161 |
|
|
2162 |
|
/** |
2163 |
* Transformiert einen Fenster-Koordinaten-Bereich in Geo-Koordinaten. |
* Transformiert einen Fenster-Koordinaten-Bereich in Geo-Koordinaten. |
2164 |
* |
* |
2165 |
* @param ox |
* @param ox |
2205 |
repaint(); |
repaint(); |
2206 |
} |
} |
2207 |
} |
} |
2208 |
|
// |
2209 |
// wenn manueller Cursor gesetzt ist, dann diesen verwenden (unabhaengig |
// // |
2210 |
// von der aktuellen Aktion |
// // wenn manueller Cursor gesetzt ist, dann diesen verwenden |
2211 |
if (this.staticCursor != null) { |
// (unabhaengig |
2212 |
setCursor(staticCursor); |
// // von der aktuellen Aktion |
2213 |
return; |
// if (this.staticCursor != null) { |
2214 |
} |
// setCursor(staticCursor); |
2215 |
|
// return; |
2216 |
|
// } |
2217 |
|
// |
2218 |
if (getCursor() == SwingUtil.PANNING_CURSOR) { |
if (getCursor() == SwingUtil.PANNING_CURSOR) { |
2219 |
// This cursor will reset itself |
// This cursor will reset itself |
2220 |
return; |
return; |
2221 |
} |
} |
2222 |
|
|
2223 |
// Set the cursor depending on what tool is in use... |
setCursor(tool.getCursor()); |
2224 |
switch (state) { |
|
2225 |
case SELECT_TOP: |
// |
2226 |
case SELECT_ONE_FROM_TOP: |
// // Set the cursor depending on what tool is in use... |
2227 |
case SELECT_ALL: |
// switch (state) { |
2228 |
setCursor(SwingUtil.CROSSHAIR_CURSOR); |
// case SELECT_TOP: |
2229 |
break; |
// case SELECT_ONE_FROM_TOP: |
2230 |
case ZOOM_IN: |
// case SELECT_ALL: |
2231 |
setCursor(SwingUtil.ZOOMIN_CURSOR); |
// setCursor(SwingUtil.CROSSHAIR_CURSOR); |
2232 |
break; |
// break; |
2233 |
case ZOOM_OUT: |
// case ZOOM_IN: |
2234 |
setCursor(SwingUtil.ZOOMOUT_CURSOR); |
// setCursor(SwingUtil.ZOOMIN_CURSOR); |
2235 |
break; |
// break; |
2236 |
case PAN: |
// case ZOOM_OUT: |
2237 |
setCursor(SwingUtil.PAN_CURSOR); |
// setCursor(SwingUtil.ZOOMOUT_CURSOR); |
2238 |
break; |
// break; |
2239 |
default: |
// case PAN: |
2240 |
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
// setCursor(SwingUtil.PAN_CURSOR); |
2241 |
break; |
// break; |
2242 |
} |
// default: |
2243 |
|
// setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
2244 |
|
// break; |
2245 |
|
// } |
2246 |
} |
} |
2247 |
|
|
2248 |
/** |
/** |
2272 |
|
|
2273 |
final Graphics2D finalG = getFinalImage().createGraphics(); |
final Graphics2D finalG = getFinalImage().createGraphics(); |
2274 |
finalG.setBackground(getMapBackgroundColor()); |
finalG.setBackground(getMapBackgroundColor()); |
2275 |
finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y, |
finalG.drawImage(getPreFinalImage(), getImageOrigin().x, |
2276 |
getMapBackgroundColor(), null); |
getImageOrigin().y, getMapBackgroundColor(), null); |
2277 |
|
|
2278 |
final int finalImageHeight = getFinalImage().getHeight(null); |
// When panning, we have to clear the area around the image |
2279 |
final int finalImageWidth = getFinalImage().getWidth(null); |
final Rectangle painedArea = new Rectangle(getImageOrigin().x, |
2280 |
|
getImageOrigin().y, getFinalImage().getWidth(), getFinalImage() |
2281 |
final Rectangle painedArea = new Rectangle(imageOrigin.x, |
.getHeight()); |
2282 |
imageOrigin.y, finalImageWidth, finalImageHeight); |
SwingUtil.clearAround(finalG, painedArea, getVisibleRect(), |
2283 |
SwingUtil.clearAround(finalG, painedArea, getVisibleRect()); |
getMapBackgroundColor()); |
2284 |
|
|
2285 |
addGadgets(finalG, false); |
addGadgets(finalG, false); |
2286 |
|
|
2299 |
* <code>false</code>, it will only depend on |
* <code>false</code>, it will only depend on |
2300 |
* {@link #localExecuter.isRunning} and #bgExecuter.isRunning |
* {@link #localExecuter.isRunning} and #bgExecuter.isRunning |
2301 |
*/ |
*/ |
2302 |
private void addGadgets(final Graphics2D graphics, boolean forceWait) { |
private void addGadgets(final Graphics2D graphics, final boolean forceWait) { |
2303 |
|
|
2304 |
// Paint a logo to the bottom right if available |
// Paint a logo to the bottom right if available |
2305 |
if (mapImage != null) { |
if (mapImage != null) { |
2306 |
Rectangle visibleRect = getVisibleRect(); |
final Rectangle visibleRect = getVisibleRect(); |
2307 |
graphics.drawImage(mapImage, visibleRect.width |
graphics.drawImage(mapImage, visibleRect.width |
2308 |
- mapImage.getWidth() - 10, getVisibleRect().height |
- mapImage.getWidth() - 10, getVisibleRect().height |
2309 |
- mapImage.getHeight() - 10, null); |
- mapImage.getHeight() - 10, null); |
2329 |
|
|
2330 |
graphics.setColor(c); |
graphics.setColor(c); |
2331 |
|
|
2332 |
y += 24; |
y += 21; |
2333 |
} |
} |
2334 |
|
|
2335 |
if (!renderingErrors.isEmpty() && isShowExceptions()) { |
if (!renderingErrors.isEmpty() && isShowExceptions()) { |
2337 |
final Color c = graphics.getColor(); |
final Color c = graphics.getColor(); |
2338 |
graphics.setFont(errorFont); |
graphics.setFont(errorFont); |
2339 |
|
|
2340 |
for (Exception ex : renderingErrors) { |
for (final Exception ex : renderingErrors) { |
2341 |
|
|
2342 |
String errStr = ex.getLocalizedMessage(); |
String errStr = ex.getLocalizedMessage(); |
2343 |
|
|
2346 |
if (errStr == null) |
if (errStr == null) |
2347 |
errStr = "unknown error: " + ex.getClass().getSimpleName(); |
errStr = "unknown error: " + ex.getClass().getSimpleName(); |
2348 |
|
|
2349 |
graphics.setColor(Color.WHITE); |
graphics.setColor(getMapBackgroundColor()); |
2350 |
graphics.drawString(errStr, 5, y); |
graphics.drawString(errStr, 5, y); |
2351 |
graphics.setColor(Color.RED); |
graphics.setColor(Color.RED); |
2352 |
graphics.drawString(errStr, 6, y + 1); |
graphics.drawString(errStr, 6, y + 1); |
2374 |
final CoordinateReferenceSystem mapCRS = getMapContext() |
final CoordinateReferenceSystem mapCRS = getMapContext() |
2375 |
.getCoordinateReferenceSystem(); |
.getCoordinateReferenceSystem(); |
2376 |
final CoordinateReferenceSystem fCRS = features.getSchema() |
final CoordinateReferenceSystem fCRS = features.getSchema() |
2377 |
.getGeometryDescriptor().getCoordinateReferenceSystem(); |
.getCoordinateReferenceSystem(); |
2378 |
|
|
2379 |
ReferencedEnvelope _mapArea; |
ReferencedEnvelope _mapArea; |
2380 |
if (mapArea == null) |
if (mapArea == null) |
2443 |
// BB umrechnen von Layer-CRS in Map-CRS |
// BB umrechnen von Layer-CRS in Map-CRS |
2444 |
|
|
2445 |
// Expand a bit |
// Expand a bit |
2446 |
bounds.expandBy(bounds.getWidth() / 6., bounds.getHeight() / 6.); |
addDefaultMargin(bounds); |
2447 |
|
|
2448 |
setMapArea(bounds); |
setMapArea(bounds); |
2449 |
} |
} |
2450 |
} |
} |
2451 |
|
|
2452 |
|
private ReferencedEnvelope addDefaultMargin(ReferencedEnvelope bounds) { |
2453 |
|
return JTSUtil.expandEnvelope(bounds, Math.max(0, |
2454 |
|
defaultMaxMapExtendMode)); |
2455 |
|
} |
2456 |
|
|
2457 |
|
private Envelope addDefaultMargin(Envelope bounds) { |
2458 |
|
return JTSUtil.expandEnvelope(bounds, Math.max(0, |
2459 |
|
defaultMaxMapExtendMode)); |
2460 |
|
} |
2461 |
|
|
2462 |
/** |
/** |
2463 |
* Zooms towards a point. |
* Zooms towards a point. |
2464 |
* |
* |
2477 |
* @param center |
* @param center |
2478 |
* position in window coordinates |
* position in window coordinates |
2479 |
* @param zoomFaktor |
* @param zoomFaktor |
2480 |
* > 1 for zoom in, < 1 for zoom out. Default is 1.33. |
* > 1 for zoom out, < 1 for zoom in. Default is .5 |
2481 |
*/ |
*/ |
2482 |
public void zoomTo(Point center, Double zoomFaktor) { |
public void zoomTo(Point center, Double zoomFaktor) { |
2483 |
if (zoomFaktor == null || zoomFaktor == 0.) |
if (zoomFaktor == null || zoomFaktor == 0.) |
2484 |
zoomFaktor = 2.; |
zoomFaktor = .5; |
2485 |
|
|
2486 |
final Point2D gcenter = getScreenToWorld().transform(center, null); |
final Point2D gcenter = getScreenToWorld().transform(center, null); |
2487 |
center = null; |
center = null; |
2502 |
.getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea |
.getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea |
2503 |
.getHeight()) / 2.); |
.getHeight()) / 2.); |
2504 |
|
|
2505 |
// TODO we actually want that |
// // Move the newMapArea above the new center if we zoom in: |
2506 |
// // Move the newMapArea above the new center |
newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter |
2507 |
// newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter |
.getY() |
2508 |
// .getY() |
- mapArea.centre().y); |
|
// - mapArea.centre().y); |
|
2509 |
|
|
2510 |
setMapArea(newMapArea); |
setMapArea(newMapArea); |
2511 |
} |
} |
2514 |
* Shall non-fatal rendering exceptions be reported in the mappane or be |
* Shall non-fatal rendering exceptions be reported in the mappane or be |
2515 |
* dropped quitely. |
* dropped quitely. |
2516 |
*/ |
*/ |
2517 |
public void setShowExceptions(boolean showExceptions) { |
public void setShowExceptions(final boolean showExceptions) { |
2518 |
this.showExceptions = showExceptions; |
this.showExceptions = showExceptions; |
2519 |
} |
} |
2520 |
|
|
2525 |
return showExceptions; |
return showExceptions; |
2526 |
} |
} |
2527 |
|
|
2528 |
|
public GTRenderer getLocalRenderer() { |
2529 |
|
return localRenderer; |
2530 |
|
} |
2531 |
|
|
2532 |
|
/** |
2533 |
|
* Setzt den Kartenausschnitt auf die Ausdehnung eines bestimmten Layers. |
2534 |
|
* Macht nichts, wenn {@code null} uebergeben wird. |
2535 |
|
* |
2536 |
|
* <br> |
2537 |
|
* |
2538 |
|
* @param layer |
2539 |
|
* ein Layer |
2540 |
|
*/ |
2541 |
|
public void zoomToLayer(MapLayer layer) { |
2542 |
|
if (layer == null) |
2543 |
|
return; |
2544 |
|
try { |
2545 |
|
|
2546 |
|
// BB umrechnen von Layer-CRS in Map-CRS |
2547 |
|
final CoordinateReferenceSystem targetCRS = getMapContext() |
2548 |
|
.getCoordinateReferenceSystem(); |
2549 |
|
final CoordinateReferenceSystem sourceCRS = layer |
2550 |
|
.getFeatureSource().getSchema() |
2551 |
|
.getCoordinateReferenceSystem(); |
2552 |
|
|
2553 |
|
Envelope mapAreaNew; |
2554 |
|
if (!CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) { |
2555 |
|
mapAreaNew = JTSUtil.transformEnvelope(layer.getFeatureSource() |
2556 |
|
.getBounds(), sourceCRS, targetCRS); |
2557 |
|
} else { |
2558 |
|
try { |
2559 |
|
mapAreaNew = layer.getFeatureSource().getBounds(); |
2560 |
|
} catch (java.lang.IllegalArgumentException e) { |
2561 |
|
LOGGER.error("Can't calc layers bounds...", e); |
2562 |
|
mapAreaNew = null; |
2563 |
|
|
2564 |
|
/** |
2565 |
|
* |
2566 |
|
23.10.2009 11:20:50 |
2567 |
|
* org.geotools.data.shapefile.shp.PolygonHandler read |
2568 |
|
* WARNUNG: only one hole in this polygon record ERROR |
2569 |
|
* JMapPane zoomToLayer Zoom to layer did not terminate |
2570 |
|
* correctly java.lang.IllegalArgumentException: Points of |
2571 |
|
* LinearRing do not form a closed linestring at |
2572 |
|
* com.vividsolutions |
2573 |
|
* .jts.geom.LinearRing.validateConstruction |
2574 |
|
* (LinearRing.java:105) at |
2575 |
|
* com.vividsolutions.jts.geom.LinearRing |
2576 |
|
* .<init>(LinearRing.java:100) at |
2577 |
|
* com.vividsolutions.jts.geom |
2578 |
|
* .GeometryFactory.createLinearRing |
2579 |
|
* (GeometryFactory.java:339) at |
2580 |
|
* org.geotools.data.shapefile. |
2581 |
|
* shp.PolygonHandler.read(PolygonHandler.java:188) at |
2582 |
|
* org.geotools |
2583 |
|
* .data.shapefile.shp.ShapefileReader$Record.shape |
2584 |
|
* (ShapefileReader.java:106) at |
2585 |
|
* org.geotools.data.shapefile. |
2586 |
|
* ShapefileAttributeReader.next( |
2587 |
|
* ShapefileAttributeReader.java:157) at |
2588 |
|
* org.geotools.data.shapefile |
2589 |
|
* .indexed.IndexedShapefileAttributeReader |
2590 |
|
* .next(IndexedShapefileAttributeReader.java:122) at |
2591 |
|
* org.geotools |
2592 |
|
* .data.FIDFeatureReader.next(FIDFeatureReader.java:96) at |
2593 |
|
* org.geotools.data.FIDFeatureReader.next(FIDFeatureReader. |
2594 |
|
* java:55) at org.geotools.data.MaxFeatureReader.next( |
2595 |
|
* MaxFeatureReader.java:61) at |
2596 |
|
* org.geotools.data.MaxFeatureReader |
2597 |
|
* .next(MaxFeatureReader.java:61) |
2598 |
|
**/ |
2599 |
|
} |
2600 |
|
} |
2601 |
|
|
2602 |
|
// Kartenbereich um 10% vergroessern, damit z.B. auch ein |
2603 |
|
// Punkt-Layer, |
2604 |
|
// welches nur aus 2 Punnkten besteht, sichtbar ist (Punkte liegen |
2605 |
|
// sonst |
2606 |
|
// genau auf dem Rand der angezeigten Flaeche) |
2607 |
|
|
2608 |
|
if (mapAreaNew != null) { |
2609 |
|
|
2610 |
|
mapAreaNew = addDefaultMargin(mapAreaNew); |
2611 |
|
setMapArea(mapAreaNew); |
2612 |
|
} else { |
2613 |
|
LOGGER |
2614 |
|
.warn("Couldn't transformEnvelope when zooming to the layer"); |
2615 |
|
} |
2616 |
|
} catch (Exception err) { |
2617 |
|
LOGGER.error("Zoom to layer did not terminate correctly", err); |
2618 |
|
} |
2619 |
|
} |
2620 |
|
|
2621 |
|
/** |
2622 |
|
* Zooms the {@link SelectableXMapPane} to the {@link Envelope} of a layer. |
2623 |
|
* |
2624 |
|
* <br> |
2625 |
|
* A refresh of the map is not done automatically |
2626 |
|
* |
2627 |
|
* @param index |
2628 |
|
* Index of the {@link MapLayer} in the {@link MapContext} (from |
2629 |
|
* back to top) |
2630 |
|
* |
2631 |
|
* @author <a href="mailto:[email protected]">Stefan Alfons |
2632 |
|
* Krüger</a> |
2633 |
|
*/ |
2634 |
|
public void zoomToLayer(int index) { |
2635 |
|
final MapContext context = getMapContext(); |
2636 |
|
if (context != null) |
2637 |
|
zoomToLayer(context.getLayer(index)); |
2638 |
|
} |
2639 |
|
|
2640 |
|
/** |
2641 |
|
* Zooms the {@link SelectableXMapPane} to the {@link Envelope} of the |
2642 |
|
* selected layer. The layer is selected by the idx, counting from front to |
2643 |
|
* back, like humans would expect in a {@link JList} |
2644 |
|
* |
2645 |
|
* <br> |
2646 |
|
* A refresh of the map is not done automatically |
2647 |
|
* |
2648 |
|
* |
2649 |
|
* |
2650 |
|
* @param index |
2651 |
|
* Reverse index of the {@link MapLayer} in the |
2652 |
|
* {@link MapContext} |
2653 |
|
* |
2654 |
|
* @author <a href="mailto:[email protected]">Stefan Alfons |
2655 |
|
* Krüger</a> |
2656 |
|
*/ |
2657 |
|
public void zoomToLayerIdxReverse(int index) { |
2658 |
|
zoomToLayer(getMapContext().getLayerCount() - 1 - index); |
2659 |
|
} |
2660 |
|
|
2661 |
|
/** |
2662 |
|
* Aktiviert oder deaktiviert das AntiAliasing for diese |
2663 |
|
* {@link SelectableXMapPane}. AntiALiasing ist besonders fuer |
2664 |
|
* Textbeschriftung sehr schoen, verbraucht aber auch mehr Performance. |
2665 |
|
* |
2666 |
|
* @author <a href="mailto:[email protected]">Stefan Alfons |
2667 |
|
* Krüger</a> |
2668 |
|
*/ |
2669 |
|
public void setAntiAliasing(final boolean aa) { |
2670 |
|
// LOGGER.info("Setting AntiAliasing for this JMapPane to " + aa); |
2671 |
|
RenderingHints java2DHints = java2dHints; |
2672 |
|
if (java2DHints == null) { |
2673 |
|
java2DHints = GeoTools.getDefaultHints(); |
2674 |
|
} |
2675 |
|
|
2676 |
|
java2DHints.put(RenderingHints.KEY_ANTIALIASING, |
2677 |
|
aa ? RenderingHints.VALUE_ANTIALIAS_ON |
2678 |
|
: RenderingHints.VALUE_ANTIALIAS_OFF); |
2679 |
|
java2DHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, |
2680 |
|
aa ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON |
2681 |
|
: RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); |
2682 |
|
java2DHints.put(RenderingHints.KEY_RENDERING, |
2683 |
|
aa ? RenderingHints.VALUE_RENDER_QUALITY |
2684 |
|
: RenderingHints.VALUE_RENDER_SPEED); |
2685 |
|
|
2686 |
|
} |
2687 |
|
|
2688 |
|
public Point getImageOrigin() { |
2689 |
|
return imageOrigin; |
2690 |
|
} |
2691 |
|
|
2692 |
|
/** |
2693 |
|
* If {@link #maxExtend} is <code>null</code> the following rules are used |
2694 |
|
* to create a default maximum. |
2695 |
|
* <ul> |
2696 |
|
* <li>Values < 0 : don't grow to fit the monitors aspect ratio, no |
2697 |
|
* margin</li> |
2698 |
|
* <li>Values 0 : grow to fit the monitors aspect ratio, no margin</li> |
2699 |
|
* <li>Values > 0 : grow to fit the monitors aspect ratio, and add a |
2700 |
|
* relative margin</li> |
2701 |
|
* </ul> |
2702 |
|
* **/ |
2703 |
|
public void setDefaultMaxMapExtendMode(double defaultMaxMapExtendMode) { |
2704 |
|
this.defaultMaxMapExtendMode = defaultMaxMapExtendMode; |
2705 |
|
} |
2706 |
|
|
2707 |
|
/** |
2708 |
|
* If {@link #maxExtend} is <code>null</code> the following rules are used |
2709 |
|
* to create a default maximum. |
2710 |
|
* <ul> |
2711 |
|
* <li>Values < 0 : don't grow to fit the monitors aspect ratio, no |
2712 |
|
* margin</li> |
2713 |
|
* <li>Values 0 : grow to fit the monitors aspect ratio, no margin</li> |
2714 |
|
* <li>Values > 0 : grow to fit the monitors aspect ratio, and add a |
2715 |
|
* relative margin</li> |
2716 |
|
* </ul> |
2717 |
|
* **/ |
2718 |
|
public double getDefaultMaxMapExtendMode() { |
2719 |
|
return defaultMaxMapExtendMode; |
2720 |
|
} |
2721 |
|
|
2722 |
|
final static int BLINK_TIMER_DEPLAY = 800; |
2723 |
|
|
2724 |
|
private Timer initBlinkTimer() { |
2725 |
|
Timer timer = new Timer(BLINK_TIMER_DEPLAY, new ActionListener() { |
2726 |
|
|
2727 |
|
@Override |
2728 |
|
public void actionPerformed(ActionEvent e) { |
2729 |
|
XMapPane.this.repaint(300); |
2730 |
|
} |
2731 |
|
}); |
2732 |
|
timer.setDelay(BLINK_TIMER_DEPLAY); |
2733 |
|
timer.setRepeats(false); |
2734 |
|
return timer; |
2735 |
|
} |
2736 |
|
|
2737 |
|
/** |
2738 |
|
* Makes the given {@link FeatureCollection} bink in the map for a moment |
2739 |
|
*/ |
2740 |
|
public void blink( |
2741 |
|
FeatureCollection<SimpleFeatureType, SimpleFeature> features) { |
2742 |
|
{ |
2743 |
|
blinkTimer.stop(); |
2744 |
|
repaint(); |
2745 |
|
blinkTimer = initBlinkTimer(); |
2746 |
|
|
2747 |
|
DefaultMapContext mc = new DefaultMapContext(getMapContext() |
2748 |
|
.getCoordinateReferenceSystem()); |
2749 |
|
|
2750 |
|
Style style = StylingUtil.STYLE_FACTORY.createStyle(); |
2751 |
|
style.featureTypeStyles().add( |
2752 |
|
StylingUtil.createBlinkFeatureTypeStyle(features)); |
2753 |
|
|
2754 |
|
// style = StylingUtil.createStyleSimple(features, Color.pink, |
2755 |
|
// Color.WHITE); |
2756 |
|
|
2757 |
|
DefaultMapLayer dml = new DefaultMapLayer(features, style); |
2758 |
|
mc.addLayer(dml); |
2759 |
|
|
2760 |
|
GTRenderer renderer = new StreamingRenderer(); |
2761 |
|
|
2762 |
|
renderer.setJava2DHints(getJava2dHints()); |
2763 |
|
|
2764 |
|
renderer.setContext(mc); |
2765 |
|
|
2766 |
|
Graphics2D g2d = (Graphics2D) getGraphics(); |
2767 |
|
renderer.paint(g2d, getVisibleRect(), getMapArea()); |
2768 |
|
|
2769 |
|
blinkTimer.start(); |
2770 |
|
|
2771 |
|
} |
2772 |
|
|
2773 |
|
} |
2774 |
|
|
2775 |
} |
} |