26 |
import java.util.Map; |
import java.util.Map; |
27 |
import java.util.Vector; |
import java.util.Vector; |
28 |
|
|
29 |
|
import javax.swing.JList; |
30 |
import javax.swing.Timer; |
import javax.swing.Timer; |
31 |
|
import javax.swing.border.Border; |
32 |
|
|
33 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
34 |
|
import org.geotools.factory.GeoTools; |
35 |
import org.geotools.feature.FeatureCollection; |
import org.geotools.feature.FeatureCollection; |
36 |
|
import org.geotools.geometry.DirectPosition2D; |
37 |
import org.geotools.geometry.jts.JTS; |
import org.geotools.geometry.jts.JTS; |
38 |
import org.geotools.geometry.jts.ReferencedEnvelope; |
import org.geotools.geometry.jts.ReferencedEnvelope; |
39 |
import org.geotools.map.DefaultMapContext; |
import org.geotools.map.DefaultMapContext; |
69 |
import schmitzm.lang.LangUtil; |
import schmitzm.lang.LangUtil; |
70 |
import schmitzm.swing.JPanel; |
import schmitzm.swing.JPanel; |
71 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
72 |
|
import schmitzm.swing.event.MouseInputType; |
73 |
|
|
74 |
import com.vividsolutions.jts.geom.Coordinate; |
import com.vividsolutions.jts.geom.Coordinate; |
75 |
import com.vividsolutions.jts.geom.Envelope; |
import com.vividsolutions.jts.geom.Envelope; |
100 |
*/ |
*/ |
101 |
public class XMapPane extends JPanel { |
public class XMapPane extends JPanel { |
102 |
|
|
103 |
private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB; |
// private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB; |
104 |
private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_INT_ARGB; |
// private static final int IMAGETYPE_withAlpha = |
105 |
|
// BufferedImage.TYPE_INT_ARGB; |
106 |
|
private static final int IMAGETYPE = BufferedImage.TYPE_3BYTE_BGR; |
107 |
|
public XMapPaneTool getTool() { |
108 |
|
return tool; |
109 |
|
} |
110 |
|
|
111 |
|
private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_4BYTE_ABGR; |
112 |
|
|
113 |
private static Logger LOGGER = Logger.getLogger(XMapPane.class); |
private final static Logger LOGGER = Logger.getLogger(XMapPane.class); |
114 |
|
|
115 |
|
/** |
116 |
|
* A flag indicating whether the {@link XMapPane} is accepting repaints from |
117 |
|
* the EDT. @see {@link XMapPane#setPainting(boolean)) |
118 |
|
**/ |
119 |
private boolean acceptsRepaintCalls = true; |
private boolean acceptsRepaintCalls = true; |
120 |
|
|
121 |
/** |
/** |
149 |
* The initial delay in milliseconds until the {@link #finalImage} is |
* The initial delay in milliseconds until the {@link #finalImage} is |
150 |
* updated the first time. |
* updated the first time. |
151 |
*/ |
*/ |
152 |
public static final int INITIAL_REPAINT_DELAY = 1000; |
public static final int INITIAL_REPAINT_DELAY = 900; |
153 |
|
|
154 |
/** |
/** |
155 |
* While the {@link #bgExecuter} and {@link #localExecuter} are rendering, |
* While the {@link #bgExecuter} and {@link #localExecuter} are rendering, |
166 |
*/ |
*/ |
167 |
public static final int DEFAULT_RESIZING_PAINT_DELAY = 600; |
public static final int DEFAULT_RESIZING_PAINT_DELAY = 600; |
168 |
|
|
|
private final Timer resizeTimer; |
|
|
|
|
|
public static final int NONE = -123; |
|
|
|
|
169 |
/** |
/** |
170 |
* Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl |
* This not-repeating {@link Timer} is re-started whenever the component is |
171 |
* moeglich! |
* resized. That means => only if the component is not resizing for |
172 |
* |
* {@link #DEFAULT_RESIZING_PAINT_DELAY} milliseconds, does the |
173 |
* @see #setState(int) |
* {@link XMapPane} react. |
174 |
*/ |
*/ |
175 |
public static final int PAN = 1; |
private final Timer resizeTimer; |
176 |
|
|
177 |
/** |
/** |
178 |
* Flag fuer Modus "SimpleFeature-Auswahl auf allen (sichtbaren) Layern". |
* Flag for no-tool. |
|
* |
|
|
* @see #setState(int) |
|
|
* @see #setState(int) |
|
179 |
*/ |
*/ |
180 |
public static final int SELECT_ALL = 103; |
public static final int NONE = -123; |
181 |
/** |
// |
182 |
* Flag fuer Modus |
// /** |
183 |
* "Auswahl nur eines Features, das erste sichtbare von Oben". |
// * Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl |
184 |
* |
// * moeglich! |
185 |
* @see #setState(int) |
// * |
186 |
* @see #setState(int) |
// * @see #setState(int) |
187 |
*/ |
// */ |
188 |
public static final int SELECT_ONE_FROM_TOP = 104; |
// public static final int PAN = 1; |
189 |
/** |
// |
190 |
* Flag fuer Modus |
// /** |
191 |
* "SimpleFeature-Auswahl auf dem obersten (sichtbaren) Layer". |
// * Flag fuer Modus "Heran zoomen". |
192 |
* |
// * |
193 |
* @see #setState(int) |
// * @see #setState(int) |
194 |
* @see #setState(int) |
// * @see #setState(int) |
195 |
*/ |
// */ |
196 |
public static final int SELECT_TOP = 4; |
// public static final int ZOOM_IN = 2; |
197 |
|
// |
198 |
public static final Cursor WAIT_CURSOR = Cursor |
// /** |
199 |
.getPredefinedCursor(Cursor.WAIT_CURSOR); |
// * Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich! |
200 |
|
// * |
201 |
|
// * @see #setState(int) |
202 |
|
// */ |
203 |
|
// public static final int ZOOM_OUT = 3; |
204 |
|
|
205 |
/** |
/** |
206 |
* {@link Font} used to paint the wait messages into the map |
* {@link Font} used to paint the wait messages into the map |
207 |
* |
* |
208 |
* @see #addGadgets(Graphics2D, boolean) |
* @see #addGadgets(Graphics2D, boolean) |
209 |
*/ |
*/ |
210 |
final static Font waitFont = new Font("Arial", Font.BOLD, 30); |
final static Font waitFont = new Font("Arial", Font.BOLD, 28); |
211 |
|
|
212 |
/** |
/** |
213 |
* {@link Font} used to paint error messages into the map |
* {@link Font} used to paint error messages into the map |
217 |
final static Font errorFont = new Font("Arial", Font.BOLD, 13); |
final static Font errorFont = new Font("Arial", Font.BOLD, 13); |
218 |
|
|
219 |
/** |
/** |
220 |
|
* If last average last two renderings took more than that many ms, show the |
221 |
|
* user a scaled preview |
222 |
|
**/ |
223 |
|
private static final long PRESCALE_MINTIME = 230; |
224 |
|
|
225 |
|
/** |
226 |
* 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 |
227 |
* another thread. |
* another thread. |
228 |
* |
* |
231 |
final String waitMsg = SwingUtil.R("WaitMess"); |
final String waitMsg = SwingUtil.R("WaitMess"); |
232 |
|
|
233 |
/** |
/** |
|
* Flag fuer Modus "Heran zoomen". |
|
|
* |
|
|
* @see #setState(int) |
|
|
* @see #setState(int) |
|
|
*/ |
|
|
public static final int ZOOM_IN = 2; |
|
|
|
|
|
/** |
|
|
* Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich! |
|
|
* |
|
|
* @see #setState(int) |
|
|
*/ |
|
|
public static final int ZOOM_OUT = 3; |
|
|
|
|
|
/** |
|
234 |
* Konvertiert die Maus-Koordinaten (relativ zum <code>JMapPane</code>) in |
* Konvertiert die Maus-Koordinaten (relativ zum <code>JMapPane</code>) in |
235 |
* Karten-Koordinaten. |
* Karten-Koordinaten. |
236 |
* |
* |
237 |
* @param e |
* @param e |
238 |
* Maus-Ereignis |
* Maus-Ereignis |
239 |
*/ |
*/ |
240 |
public static Point2D getMapCoordinatesFromEvent(final MouseEvent e) { |
public static DirectPosition2D getMapCoordinatesFromEvent(final MouseEvent e) { |
241 |
// aktuelle Geo-Position aus GeoMouseEvent ermitteln |
// aktuelle Geo-Position aus GeoMouseEvent ermitteln |
242 |
if (e != null && e instanceof MapMouseEvent) |
if (e != null && e instanceof MapMouseEvent) |
243 |
try { |
try { |
244 |
return ((MapMouseEvent) e).getMapPosition().toPoint2D(); |
return ((MapMouseEvent) e).getMapPosition(); |
245 |
} catch (final Exception err) { |
} catch (final Exception err) { |
246 |
LOGGER |
LOGGER |
247 |
.error( |
.error( |
258 |
return null; |
return null; |
259 |
|
|
260 |
final AffineTransform at = xMapPane.getScreenToWorld(); |
final AffineTransform at = xMapPane.getScreenToWorld(); |
261 |
if (at != null) |
if (at != null) { |
262 |
return at.transform(e.getPoint(), null); |
Point2D transformed = at.transform(e.getPoint(), null); |
263 |
|
return new DirectPosition2D(xMapPane.getMapContext() |
264 |
|
.getCoordinateReferenceSystem(), transformed.getX(), |
265 |
|
transformed.getY()); |
266 |
|
} |
267 |
return null; |
return null; |
268 |
} |
} |
269 |
throw new IllegalArgumentException( |
throw new IllegalArgumentException( |
278 |
|
|
279 |
@Override |
@Override |
280 |
public void layerAdded(final MapLayerListEvent event) { |
public void layerAdded(final MapLayerListEvent event) { |
281 |
MapLayer layer = event.getLayer(); |
final MapLayer layer = event.getLayer(); |
282 |
layer.addMapLayerListener(bgMapLayerListener); |
layer.addMapLayerListener(bgMapLayerListener); |
283 |
requestStartRendering(); |
requestStartRendering(); |
|
|
|
284 |
} |
} |
285 |
|
|
286 |
@Override |
@Override |
374 |
* While dragging, the {@link #updateFinalImage()} method is translating the |
* While dragging, the {@link #updateFinalImage()} method is translating the |
375 |
* cached images while setting it together. |
* cached images while setting it together. |
376 |
**/ |
**/ |
377 |
Point imageOrigin = new Point(0, 0); |
private final Point imageOrigin = new Point(0, 0); |
378 |
/** |
/** |
379 |
* For every rendering thread started, |
* For every rendering thread started, |
380 |
* {@link GTUtil#createGTRenderer(MapContext)} is called to create a new |
* {@link GTUtil#createGTRenderer(MapContext)} is called to create a new |
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(getMapContext()); |
getLocalRenderer().setContext(getMapContext()); |
400 |
requestStartRendering(); |
requestStartRendering(); |
401 |
|
|
402 |
} |
} |
403 |
|
|
404 |
@Override |
@Override |
405 |
public void layerChanged(final MapLayerListEvent event) { |
public void layerChanged(final MapLayerListEvent event) { |
406 |
localRenderer.setContext(getMapContext()); |
// getLocalRenderer().setContext(getMapContext()); geht doch auch |
407 |
|
// ohne?!?!? wow... |
408 |
requestStartRendering(); |
requestStartRendering(); |
409 |
} |
} |
410 |
|
|
411 |
@Override |
@Override |
412 |
public void layerMoved(final MapLayerListEvent event) { |
public void layerMoved(final MapLayerListEvent event) { |
413 |
localRenderer.setContext(getMapContext()); |
getLocalRenderer().setContext(getMapContext()); |
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 |
localRenderer.setContext(getMapContext()); |
getLocalRenderer().setContext(getMapContext()); |
422 |
requestStartRendering(); |
requestStartRendering(); |
423 |
} |
} |
424 |
}; |
}; |
425 |
|
|
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. We don't have to listen layerChanged, because that is |
429 |
|
* already done in {@link #localContextListener} |
430 |
*/ |
*/ |
431 |
protected MapLayerListener localMapLayerListener = new MapLayerAdapter() { |
protected MapLayerListener localMapLayerListener = new MapLayerAdapter() { |
432 |
|
|
433 |
@Override |
// @Override |
434 |
public void layerChanged(final MapLayerEvent event) { |
// public void layerChanged(final MapLayerEvent event) { |
435 |
localRenderer.setContext(getMapContext()); // betters for SLD changes?! |
// // getLocalRenderer().setContext(getMapContext()); // betters for SLD |
436 |
requestStartRendering(); |
// // // changes?! |
437 |
} |
// // requestStartRendering(); |
438 |
|
// } |
439 |
|
|
440 |
@Override |
@Override |
441 |
public void layerHidden(final MapLayerEvent event) { |
public void layerHidden(final MapLayerEvent event) { |
448 |
} |
} |
449 |
}; |
}; |
450 |
|
|
451 |
private final GTRenderer localRenderer = GTUtil.createGTRenderer(); |
final private GTRenderer localRenderer = GTUtil.createGTRenderer(); |
452 |
|
|
453 |
private final GTRenderer bgRenderer = GTUtil.createGTRenderer(); |
private final GTRenderer bgRenderer = GTUtil.createGTRenderer(); |
454 |
|
|
469 |
/** |
/** |
470 |
* 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. |
471 |
*/ |
*/ |
472 |
private Color mapBackgroundColor = Color.WHITE; |
private Color mapBackgroundColor = null; |
473 |
|
|
474 |
/** |
/** |
475 |
* 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 |
513 |
* A flag indicating, that the image size has changed and the buffered |
* A flag indicating, that the image size has changed and the buffered |
514 |
* images are not big enough any more |
* images are not big enough any more |
515 |
**/ |
**/ |
516 |
protected boolean paneResized = false; |
protected boolean paneResized = true; |
517 |
|
|
518 |
private BufferedImage preFinalImage; |
private BufferedImage preFinalImage; |
519 |
|
|
520 |
// if null, no quick preview will be shown |
// ** if 0, no quick preview will be shown **/ |
521 |
private int quickPreviewHint = 0; |
// private int quickPreviewHint = 0; |
522 |
|
|
523 |
private Map<Object, Object> rendererHints = GTUtil |
private Map<Object, Object> rendererHints = GTUtil |
524 |
.getDefaultGTRendererHints(localRenderer); |
.getDefaultGTRendererHints(getLocalRenderer()); |
525 |
|
|
526 |
/** |
/** |
527 |
* If set to <code>true</code>, the {@link #startRenderThreadsTimer} will |
* If set to <code>true</code>, the {@link #startRenderThreadsTimer} will |
541 |
* thread. |
* thread. |
542 |
*/ |
*/ |
543 |
final private Timer startRenderThreadsTimer; |
final private Timer startRenderThreadsTimer; |
544 |
|
// |
545 |
/** |
// /** |
546 |
* The default state is ZOOM_IN, hence by default the |
// * The default state is ZOOM_IN, hence by default the |
547 |
* {@link #zoomMapPaneMouseListener} is also enabled. |
// * {@link #xMapPaneMouseListener} is also enabled. |
548 |
**/ |
// **/ |
549 |
private int state = ZOOM_IN; |
// private int state = ZOOM_IN; |
550 |
|
// |
551 |
/** |
// /** |
552 |
* Manuell gesetzter statischer Cursor, unabhaengig von der aktuellen |
// * Manuell gesetzter statischer Cursor, unabhaengig von der aktuellen |
553 |
* MapPane-Funktion |
// * MapPane-Funktion |
554 |
*/ |
// */ |
555 |
protected Cursor staticCursor = null; |
// protected Cursor staticCursor = null; |
556 |
|
|
557 |
private AffineTransform worldToScreen; |
private AffineTransform worldToScreen; |
558 |
|
|
559 |
|
// /** |
560 |
|
// * This {@link MouseListener} is managing all zoom related tasks |
561 |
|
// */ |
562 |
|
// private final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new |
563 |
|
// ZoomXMapPaneMouseListener( |
564 |
|
// this); |
565 |
|
|
566 |
/** |
/** |
567 |
* This {@link MouseListener} is managing all zoom related tasks |
* This {@link MouseListener} is managing all zoom related tasks |
568 |
*/ |
*/ |
569 |
public final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new ZoomXMapPaneMouseListener( |
private final XMapPaneMouseListener xMapPaneMouseListener = new XMapPaneMouseListener( |
570 |
this); |
this); |
571 |
|
|
572 |
/** Is set if a renderer has an error **/ |
/** Is set if a renderer has an error **/ |
573 |
protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>(); |
protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>(); |
574 |
|
|
575 |
// /** If {@link #getVisibleRect()} of this {@link JPanel} is not yet |
/** |
576 |
// defined, but we are **/ |
* If <code>true</code>, then rendering exceptions are rendererd into the |
577 |
// private Envelope mapAreaCondidate = null; |
* map pane |
578 |
|
**/ |
579 |
|
private boolean showExceptions = false; |
580 |
|
|
581 |
public XMapPane() { |
public XMapPane() { |
582 |
this(null, null); |
this(null, null); |
608 |
/** |
/** |
609 |
* Adding the #zoomMapPaneMouseListener |
* Adding the #zoomMapPaneMouseListener |
610 |
*/ |
*/ |
611 |
this.addMouseListener(zoomMapPaneMouseListener); |
this.addMouseListener(xMapPaneMouseListener); |
612 |
this.addMouseMotionListener(zoomMapPaneMouseListener); |
this.addMouseMotionListener(xMapPaneMouseListener); |
613 |
this.addMouseWheelListener(zoomMapPaneMouseListener); |
this.addMouseWheelListener(xMapPaneMouseListener); |
614 |
|
|
615 |
|
// By default the XMapPAne uses the ZOOM_IN tool. |
616 |
|
setTool(XMapPaneTool.ZOOM_IN); |
617 |
|
|
618 |
/* |
/* |
619 |
* We use a Timer object to avoid rendering delays and flickering when |
* We use a Timer object to avoid rendering delays and flickering when |
620 |
* the user is drag-resizing the parent container of this map pane. |
* the user is drag-resizing the parent container of this map pane. |
629 |
if (!isWellDefined()) |
if (!isWellDefined()) |
630 |
return; |
return; |
631 |
|
|
632 |
final Rectangle bounds = getVisibleRect(); |
// LOGGER.debug("resizeTimer performed"); |
633 |
|
|
634 |
|
// final Rectangle bounds = getVisibleRect(); |
635 |
// |
// |
636 |
// System.out.println("\n\ntimer performs with bounds = " |
// System.out.println("\n\ntimer performs with bounds = " |
637 |
// + bounds); |
// + bounds); |
638 |
|
|
639 |
final Envelope geoMapArea = tranformWindowToGeo( |
// final Envelope geoMapArea = tranformWindowToGeo( |
640 |
bounds.x, bounds.y, bounds.x + bounds.width, |
// bounds.x, bounds.y, bounds.x + bounds.width, |
641 |
bounds.y + bounds.height); |
// bounds.y + bounds.height); |
642 |
|
|
643 |
if (setMapArea(geoMapArea)) |
paneResized = true; |
644 |
paneResized = true; |
if (!setMapArea(getMapArea())) { |
645 |
// else |
// It's important to request new rendering here. |
646 |
// syso |
// setMapArea only returns true and only calls |
647 |
|
// requestStartRendering if the maparea has changed. |
648 |
|
// But if the component is resized, the maparea |
649 |
|
// doesn't have to change. |
650 |
|
requestStartRendering(); |
651 |
|
} |
652 |
|
|
653 |
} |
} |
654 |
}); |
}); |
655 |
resizeTimer.setRepeats(false); |
resizeTimer.setRepeats(false); |
656 |
|
|
657 |
this.addComponentListener(new ComponentAdapter() { |
this.addComponentListener(new ComponentAdapter() { |
658 |
|
|
659 |
|
private Rectangle oldVisibleRect; |
660 |
|
|
661 |
@Override |
@Override |
662 |
public void componentResized(final ComponentEvent e) { |
public void componentResized(final ComponentEvent e) { |
663 |
|
|
664 |
// Already cancel the tasks... |
// Seems to be called twice with the same size.. |
665 |
if (bgExecuter != null) |
if (oldVisibleRect != null |
666 |
bgExecuter.cancelTask(); |
&& oldVisibleRect.equals(getVisibleRect())) { |
667 |
if (localExecuter != null) |
// LOGGER.debug("skipping resize."); |
668 |
localExecuter.cancelTask(); |
return; |
669 |
|
} |
670 |
|
|
671 |
|
// LOGGER.debug("resized: " + getVisibleRect()); |
672 |
resizeTimer.restart(); |
resizeTimer.restart(); |
673 |
|
oldVisibleRect = getVisibleRect(); |
674 |
} |
} |
675 |
|
|
676 |
}); |
}); |
682 |
|
|
683 |
@Override |
@Override |
684 |
public void actionPerformed(final ActionEvent e) { |
public void actionPerformed(final ActionEvent e) { |
685 |
if ((localExecuter != null && !localExecuter.isRunning()) |
if ((!localExecuter.isRunning()) |
686 |
&& (bgExecuter != null && !bgExecuter.isRunning())) { |
&& (bgExecuter != null && !bgExecuter.isRunning())) { |
687 |
repaintTimer.stop(); |
repaintTimer.stop(); |
688 |
} else { |
} else { |
689 |
updateFinalImage(); |
updateFinalImage(); |
690 |
XMapPane.this.repaint(100); |
XMapPane.this.repaint(100); |
691 |
|
|
692 |
} |
} |
693 |
} |
} |
694 |
}); |
}); |
695 |
|
|
696 |
repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY); |
repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY); |
697 |
repaintTimer.setRepeats(true); |
repaintTimer.setRepeats(true); |
698 |
|
|
710 |
if (localExecuter.isRunning()) { |
if (localExecuter.isRunning()) { |
711 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
712 |
} else { |
} else { |
|
|
|
713 |
// Stupidly, but we have to recheck the |
// Stupidly, but we have to recheck the |
714 |
setMapArea(getMapArea()); |
setMapArea(getMapArea()); |
715 |
requestStartRendering = false; |
requestStartRendering = false; |
798 |
} |
} |
799 |
|
|
800 |
final Envelope maxAllowedExtend = getMaxExtend(); |
final Envelope maxAllowedExtend = getMaxExtend(); |
801 |
|
|
802 |
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) |
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) |
803 |
&& newArea != null && !newArea.isNull() |
&& newArea != null && !newArea.isNull() |
804 |
&& !Double.isNaN(newArea.getMinX()) |
&& !Double.isNaN(newArea.getMinX()) |
943 |
bgExecuter.dispose(); |
bgExecuter.dispose(); |
944 |
} |
} |
945 |
|
|
946 |
if (localExecuter != null) { |
if (localExecuter.isRunning()) { |
947 |
int i = 0; |
int i = 0; |
948 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
949 |
while (i++ < 10 && localExecuter.isRunning()) { |
while (i++ < 10 && localExecuter.isRunning()) { |
968 |
// Remove all mapPaneListeners that have registered with us |
// Remove all mapPaneListeners that have registered with us |
969 |
mapPaneListeners.clear(); |
mapPaneListeners.clear(); |
970 |
|
|
971 |
removeMouseMotionListener(zoomMapPaneMouseListener); |
removeMouseMotionListener(xMapPaneMouseListener); |
972 |
removeMouseListener(zoomMapPaneMouseListener); |
removeMouseListener(xMapPaneMouseListener); |
973 |
|
|
974 |
if (localContext != null) |
if (localContext != null) |
975 |
getMapContext().clearLayerList(); |
getMapContext().clearLayerList(); |
985 |
*/ |
*/ |
986 |
protected void drawRectangle(final Graphics graphics, final Point startPos, |
protected void drawRectangle(final Graphics graphics, final Point startPos, |
987 |
final Point e) { |
final Point e) { |
988 |
|
drawRectangle(graphics, startPos, e, Color.WHITE, false); |
989 |
|
} |
990 |
|
|
991 |
|
/** |
992 |
|
* Draws a rectangle in XOR mode from the origin at {@link #startPos} to the |
993 |
|
* given point. All in screen coordinates. |
994 |
|
*/ |
995 |
|
protected void drawRectangle(final Graphics graphics, final Point startPos, |
996 |
|
final Point e, Color color, boolean fill) { |
997 |
|
|
998 |
if (!isWellDefined()) |
if (!isWellDefined()) |
999 |
return; |
return; |
1009 |
if (width == 0 && height == 0) |
if (width == 0 && height == 0) |
1010 |
return; |
return; |
1011 |
|
|
1012 |
graphics.setXORMode(Color.WHITE); |
graphics.setXORMode(color); |
1013 |
|
|
1014 |
|
if (fill) { |
1015 |
|
graphics.fillRect(left, bottom, width, height); |
1016 |
|
graphics.setXORMode(Color.WHITE); |
1017 |
|
} |
1018 |
|
|
1019 |
|
|
1020 |
graphics.drawRect(left, bottom, width, height); |
graphics.drawRect(left, bottom, width, height); |
1021 |
} |
} |
1022 |
|
|
1028 |
* |
* |
1029 |
* @param g |
* @param g |
1030 |
* Graphics2D to paint the preview into |
* Graphics2D to paint the preview into |
|
* |
|
|
* @param state |
|
|
* Max be {@link #ZOOM_IN} or {@link #ZOOM_OUT} |
|
1031 |
*/ |
*/ |
1032 |
protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) { |
protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) { |
1033 |
|
|
1034 |
// if (1 == 1)return false; |
// if (1 == 1)return false; |
1035 |
|
// if (quickPreviewHint == 0) |
1036 |
|
// return false; |
1037 |
|
|
1038 |
if (quickPreviewHint == 0) |
if (oldMapArea == null) |
1039 |
return false; |
return false; |
1040 |
|
|
1041 |
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) |
|
1042 |
return false; |
return false; |
1043 |
|
|
1044 |
final Rectangle visibleArea = getVisibleRect(); |
final Rectangle visibleArea = getVisibleRect(); |
1053 |
final int xx2 = (int) Math.round(oldMapWindow.getMaxX()); |
final int xx2 = (int) Math.round(oldMapWindow.getMaxX()); |
1054 |
final int yy2 = (int) Math.round(oldMapWindow.getMaxY()); |
final int yy2 = (int) Math.round(oldMapWindow.getMaxY()); |
1055 |
|
|
1056 |
|
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, |
1057 |
|
RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); |
1058 |
|
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
1059 |
|
RenderingHints.VALUE_ANTIALIAS_OFF); |
1060 |
|
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, |
1061 |
|
RenderingHints.VALUE_RENDER_SPEED); |
1062 |
|
|
1063 |
graphics.drawImage(getPreFinalImage(), xx1, yy1, xx2, yy2, |
graphics.drawImage(getPreFinalImage(), xx1, yy1, xx2, yy2, |
1064 |
(int) visibleArea.getMinX(), (int) visibleArea.getMinY(), |
(int) visibleArea.getMinX(), (int) visibleArea.getMinY(), |
1065 |
(int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(), |
(int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(), |
1068 |
final Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2 |
final Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2 |
1069 |
- yy1); |
- yy1); |
1070 |
|
|
1071 |
SwingUtil.clearAround(graphics, painedArea, visibleArea); |
SwingUtil.clearAround(graphics, painedArea, visibleArea, |
1072 |
|
getMapBackgroundColor()); |
1073 |
|
|
1074 |
addGadgets(graphics, true); |
addGadgets(graphics, true); |
1075 |
|
|
1076 |
quickPreviewHint = 0; |
// quickPreviewHint = 0; |
1077 |
|
|
1078 |
repaintTimer.restart(); |
repaintTimer.restart(); |
1079 |
|
|
|
graphics.dispose(); |
|
|
|
|
1080 |
// Something has been drawn |
// Something has been drawn |
1081 |
return true; |
return true; |
1082 |
} |
} |
1089 |
* Lazyly initializes a {@link BufferedImage} for the background renderer. |
* Lazyly initializes a {@link BufferedImage} for the background renderer. |
1090 |
*/ |
*/ |
1091 |
private Image getBgImage() { |
private Image getBgImage() { |
1092 |
// |
if (bgImage == null) { |
1093 |
// if (bgImage == null) { |
bgImage = new BufferedImage(getVisibleRect().width, |
1094 |
// bgImage = createImage(getBounds().width, getBounds().height); |
getVisibleRect().height, IMAGETYPE); |
1095 |
// } |
SwingUtil.clearImage(finalImage, getMapBackgroundColor()); |
1096 |
|
} |
1097 |
|
|
1098 |
return bgImage; |
return bgImage; |
1099 |
} |
} |
1111 |
// Rectangle curPaintArea = getVisibleRect(); |
// Rectangle curPaintArea = getVisibleRect(); |
1112 |
finalImage = new BufferedImage(getVisibleRect().width, |
finalImage = new BufferedImage(getVisibleRect().width, |
1113 |
getVisibleRect().height, IMAGETYPE); |
getVisibleRect().height, IMAGETYPE); |
1114 |
|
SwingUtil.clearImage(finalImage, getMapBackgroundColor()); |
1115 |
|
|
1116 |
requestStartRendering(); |
// requestStartRendering(); |
1117 |
} |
} |
1118 |
return finalImage; |
return finalImage; |
1119 |
} |
} |
1120 |
|
|
|
public RenderingHints getJava2dHints() { |
|
|
return java2dHints; |
|
|
} |
|
|
|
|
1121 |
/** |
/** |
1122 |
* Lazyly initializes a {@link BufferedImage} for the background renderer. |
* Lazyly initializes a {@link BufferedImage} for the background renderer. |
1123 |
*/ |
*/ |
1126 |
if (localImage == null) { |
if (localImage == null) { |
1127 |
localImage = new BufferedImage(getVisibleRect().width, |
localImage = new BufferedImage(getVisibleRect().width, |
1128 |
getVisibleRect().height, IMAGETYPE_withAlpha); |
getVisibleRect().height, IMAGETYPE_withAlpha); |
1129 |
|
SwingUtil.clearImage(localImage, getMapBackgroundColor()); |
1130 |
} |
} |
1131 |
|
|
1132 |
return localImage; |
return localImage; |
1142 |
ReferencedEnvelope mapArea_ = null; |
ReferencedEnvelope mapArea_ = null; |
1143 |
try { |
try { |
1144 |
mapArea_ = localContext.getLayerBounds(); |
mapArea_ = localContext.getLayerBounds(); |
1145 |
} catch (final IOException e) { |
} catch (final Exception e) { |
1146 |
LOGGER.warn("localContext.getLayerBounds()", e); |
LOGGER.warn("localContext.getLayerBounds()", e); |
1147 |
} |
} |
1148 |
|
|
1168 |
try { |
try { |
1169 |
localContext.setCoordinateReferenceSystem(GeoImportUtil |
localContext.setCoordinateReferenceSystem(GeoImportUtil |
1170 |
.getDefaultCRS()); |
.getDefaultCRS()); |
1171 |
} catch (Exception e) { |
} catch (final Exception e) { |
1172 |
throw new RuntimeException("setting context CRS:", e); |
throw new RuntimeException("setting context CRS:", e); |
1173 |
} |
} |
1174 |
|
|
1177 |
} |
} |
1178 |
|
|
1179 |
/** |
/** |
1180 |
* 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 |
1181 |
|
* methods looks for a parent component and will use its background color. |
1182 |
|
* If no parent component is available, WHITE is returned. |
1183 |
**/ |
**/ |
1184 |
public Color getMapBackgroundColor() { |
public Color getMapBackgroundColor() { |
1185 |
|
if (mapBackgroundColor == null) { |
1186 |
|
if (getParent() != null) |
1187 |
|
return getParent().getBackground(); |
1188 |
|
else |
1189 |
|
return Color.WHITE; |
1190 |
|
} |
1191 |
return mapBackgroundColor; |
return mapBackgroundColor; |
1192 |
} |
} |
1193 |
|
|
1214 |
|
|
1215 |
public Envelope getMaxExtend() { |
public Envelope getMaxExtend() { |
1216 |
if (maxExtend == null) { |
if (maxExtend == null) { |
1217 |
// Commented-out because it takes soo much time! |
|
1218 |
// |
// The next command may take long time! |
1219 |
// long start = System.currentTimeMillis(); |
// long start = System.currentTimeMillis(); |
1220 |
// final ReferencedEnvelope layerBounds = GTUtil |
final ReferencedEnvelope layerBounds = GTUtil |
1221 |
// .getVisibleLayoutBounds(localContext); |
.getVisibleLayoutBounds(localContext); |
1222 |
// |
// |
1223 |
// LOGGER.info( (System.currentTimeMillis()-start)+"m to get maxExtend"); |
// LOGGER.info( |
1224 |
// |
// (System.currentTimeMillis()-start)+"m to get maxExtend"); |
1225 |
// if (layerBounds == null) { |
// |
1226 |
// // TODO Last fallback could be the CRS valid area |
if (layerBounds == null) { |
1227 |
// return null; |
// // TODO Last fallback could be the CRS valid area |
1228 |
// } |
return null; |
1229 |
// |
} |
1230 |
// // Kartenbereich um 10% vergroessern |
|
1231 |
// return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil |
// Vergrößerung um 10% nochmal rausgenommen |
1232 |
// .expandEnvelope(layerBounds, 0.1), true); |
// // // Kartenbereich um 10% vergroessern |
1233 |
|
// return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil |
1234 |
|
// .expandEnvelope(layerBounds, 0.1), true); |
1235 |
|
|
1236 |
|
return JTSUtil.fixAspectRatio(getVisibleRect(), layerBounds, true); |
1237 |
} |
} |
1238 |
return maxExtend; |
return maxExtend; |
1239 |
} |
} |
1261 |
} |
} |
1262 |
|
|
1263 |
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(); |
|
|
// } |
|
1264 |
return preFinalImage; |
return preFinalImage; |
1265 |
} |
} |
1266 |
|
|
1288 |
return new AffineTransform(screenToWorld); |
return new AffineTransform(screenToWorld); |
1289 |
} |
} |
1290 |
|
|
1291 |
public int getState() { |
// public int getState() { |
1292 |
return state; |
// return state; |
1293 |
} |
// } |
1294 |
|
// |
1295 |
/** |
// /** |
1296 |
* Liefert den statisch eingestellten Cursor, der unabhaengig von der |
// * Liefert den statisch eingestellten Cursor, der unabhaengig von der |
1297 |
* eingestellten MapPane-Aktion (Zoom, Auswahl, ...) verwendet wird. |
// * eingestellten MapPane-Aktion (Zoom, Auswahl, ...) verwendet wird. |
1298 |
* |
// * |
1299 |
* @return {@code null}, wenn kein statischer Cursor verwendet, sondern der |
// * @return {@code null}, wenn kein statischer Cursor verwendet, sondern der |
1300 |
* Cursor automatisch je nach MapPane-Aktion eingestellt wird. |
// * Cursor automatisch je nach MapPane-Aktion eingestellt wird. |
1301 |
*/ |
// */ |
1302 |
public Cursor getStaticCursor() { |
// public Cursor getStaticCursor() { |
1303 |
return this.staticCursor; |
// return this.staticCursor; |
1304 |
} |
// } |
1305 |
|
|
1306 |
public AffineTransform getWorldToScreenTransform() { |
public AffineTransform getWorldToScreenTransform() { |
1307 |
if (worldToScreen == null) { |
if (worldToScreen == null) { |
1354 |
return true; |
return true; |
1355 |
} |
} |
1356 |
|
|
1357 |
public void mouseDragged(final Point startPos, final Point lastPos, |
/** |
1358 |
final MouseEvent event) { |
* Usually called from {@link XMapPaneAction_Pan} to pan the image. |
1359 |
|
* |
1360 |
if ((getState() == XMapPane.PAN) |
* @param startPos |
1361 |
|| ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) { |
* in screen coordinates |
1362 |
|
* @param lastPos |
1363 |
if (getCursor() != SwingUtil.PANNING_CURSOR) { |
* in screen coordinates |
1364 |
setCursor(SwingUtil.PANNING_CURSOR); |
*/ |
1365 |
|
public void pan(final int dX, final int dY) { |
1366 |
// While panning, we deactivate the rendering. So the tasts are |
|
1367 |
// ready to start when the panning os done. |
// Panning needs a panning coursor |
1368 |
if (bgExecuter != null) |
if (getCursor() != SwingUtil.PANNING_CURSOR) { |
1369 |
bgExecuter.cancelTask(); |
setCursor(SwingUtil.PANNING_CURSOR); |
1370 |
if (localExecuter != null) |
|
1371 |
localExecuter.cancelTask(); |
// While panning, we deactivate the rendering. So the tasks are |
1372 |
} |
// ready to start when the panning is finished. |
1373 |
|
if (bgExecuter != null && bgExecuter.isRunning()) |
1374 |
if (lastPos.x > 0 && lastPos.y > 0) { |
bgExecuter.cancelTask(); |
1375 |
final int dx = event.getX() - lastPos.x; |
if (localExecuter.isRunning()) |
1376 |
final int dy = event.getY() - lastPos.y; |
localExecuter.cancelTask(); |
|
|
|
|
// TODO Stop dragging when the drag would not be valid... |
|
|
// boolean dragValid = true; |
|
|
// // check if this panning results in a valid mapArea |
|
|
// { |
|
|
// Rectangle winBounds = xMapPane.getBounds(); |
|
|
// winBounds.translate(xMapPane.imageOrigin.x, |
|
|
// -xMapPane.imageOrigin.y); |
|
|
// Envelope newMapAreaBefore = xMapPane.tranformWindowToGeo( |
|
|
// winBounds.x, winBounds.y, winBounds.x |
|
|
// + winBounds.width, winBounds.y |
|
|
// + winBounds.height); |
|
|
// |
|
|
// |
|
|
// winBounds = xMapPane.getBounds(); |
|
|
// Point testIng = new Point(xMapPane.imageOrigin); |
|
|
// testIng.translate(dx, dy); |
|
|
// winBounds.translate(testIng.x, -testIng.y); |
|
|
// Envelope newMapAreaAfter = xMapPane.tranformWindowToGeo( |
|
|
// winBounds.x, winBounds.y, winBounds.x |
|
|
// + winBounds.width, winBounds.y |
|
|
// + winBounds.height); |
|
|
// |
|
|
// // If the last drag doesn't change the MapArea anymore cancel |
|
|
// it. |
|
|
// if (xMapPane.bestAllowedMapArea(newMapAreaAfter).equals( |
|
|
// xMapPane.bestAllowedMapArea(newMapAreaBefore))){ |
|
|
// dragValid = false; |
|
|
// return; |
|
|
// } |
|
|
// } |
|
|
|
|
|
imageOrigin.translate(dx, dy); |
|
|
updateFinalImage(); |
|
|
repaint(); |
|
|
} |
|
|
|
|
|
} else if ((getState() == XMapPane.ZOOM_IN) |
|
|
|| (getState() == XMapPane.ZOOM_OUT) |
|
|
|| (getState() == XMapPane.SELECT_ALL) |
|
|
|| (getState() == XMapPane.SELECT_TOP) |
|
|
// || (getState() == XMapPane.SELECT_ONE_FROM_TOP) |
|
|
) { |
|
|
final Graphics graphics = getGraphics(); |
|
|
|
|
|
drawRectangle(graphics, startPos, event.getPoint()); |
|
|
|
|
|
if ((lastPos.x > 0) && (lastPos.y > 0)) { |
|
|
drawRectangle(graphics, startPos, lastPos); |
|
|
} |
|
|
|
|
|
graphics.dispose(); |
|
|
|
|
1377 |
} |
} |
1378 |
|
// |
1379 |
|
// if (lastPos.x > 0 && lastPos.y > 0) { |
1380 |
|
// final int dx = event.getX() - lastPos.x; |
1381 |
|
// final int dy = event.getY() - lastPos.y; |
1382 |
|
|
1383 |
|
// TODO Stop dragging when the drag would not be valid... |
1384 |
|
// boolean dragValid = true; |
1385 |
|
// // check if this panning results in a valid mapArea |
1386 |
|
// { |
1387 |
|
// Rectangle winBounds = xMapPane.getBounds(); |
1388 |
|
// winBounds.translate(xMapPane.imageOrigin.x, |
1389 |
|
// -xMapPane.imageOrigin.y); |
1390 |
|
// Envelope newMapAreaBefore = xMapPane.tranformWindowToGeo( |
1391 |
|
// winBounds.x, winBounds.y, winBounds.x |
1392 |
|
// + winBounds.width, winBounds.y |
1393 |
|
// + winBounds.height); |
1394 |
|
// |
1395 |
|
// |
1396 |
|
// winBounds = xMapPane.getBounds(); |
1397 |
|
// Point testIng = new Point(xMapPane.imageOrigin); |
1398 |
|
// testIng.translate(dx, dy); |
1399 |
|
// winBounds.translate(testIng.x, -testIng.y); |
1400 |
|
// Envelope newMapAreaAfter = xMapPane.tranformWindowToGeo( |
1401 |
|
// winBounds.x, winBounds.y, winBounds.x |
1402 |
|
// + winBounds.width, winBounds.y |
1403 |
|
// + winBounds.height); |
1404 |
|
// |
1405 |
|
// // If the last drag doesn't change the MapArea anymore cancel |
1406 |
|
// it. |
1407 |
|
// if (xMapPane.bestAllowedMapArea(newMapAreaAfter).equals( |
1408 |
|
// xMapPane.bestAllowedMapArea(newMapAreaBefore))){ |
1409 |
|
// dragValid = false; |
1410 |
|
// return; |
1411 |
|
// } |
1412 |
|
// } |
1413 |
|
|
1414 |
|
getImageOrigin().translate(dX, dY); |
1415 |
|
updateFinalImage(); |
1416 |
|
repaint(); |
1417 |
|
// } |
1418 |
|
|
1419 |
|
// } else if ((getState() == XMapPane.ZOOM_IN) |
1420 |
|
// || (getState() == XMapPane.ZOOM_OUT) |
1421 |
|
// || (getState() == XMapPane.SELECT_ALL) |
1422 |
|
// || (getState() == XMapPane.SELECT_TOP)) { |
1423 |
|
// |
1424 |
|
// // Draws a rectangle |
1425 |
|
// final Graphics2D graphics = (Graphics2D) getGraphics(); |
1426 |
|
// drawRectangle(graphics, startPos, event.getPoint()); |
1427 |
|
// if ((lastPos.x > 0) && (lastPos.y > 0)) |
1428 |
|
// drawRectangle(graphics, startPos, lastPos); |
1429 |
|
// graphics.dispose(); |
1430 |
|
// } |
1431 |
} |
} |
1432 |
|
|
1433 |
/** |
/** |
1434 |
* Called by the {@link RenderingExecutor} when rendering was cancelled. |
* Called by the {@link RenderingExecutor} when rendering was cancelled. |
1435 |
*/ |
*/ |
1436 |
public void onRenderingCancelled() { |
public void onRenderingCancelled() { |
1437 |
LOGGER.debug("Rendering cancelled"); |
// LOGGER.debug("Rendering cancelled"); |
1438 |
repaintTimer.stop(); |
repaintTimer.stop(); |
1439 |
} |
} |
1440 |
|
|
1441 |
/** |
/** |
1442 |
* Called by the {@link RenderingExecutor} when rendering has been |
* Called by the {@link RenderingExecutor} when rendering has been |
1443 |
* completed. |
* completed. |
1444 |
|
* |
1445 |
|
* @param l |
1446 |
|
* long ms the rendering took |
1447 |
*/ |
*/ |
1448 |
public void onRenderingCompleted() { |
public void onRenderingCompleted(final long l) { |
1449 |
|
lastRenderingDuration = (lastRenderingDuration + l) / 2; |
1450 |
|
// LOGGER |
1451 |
|
// .debug("complete rendering after " + lastRenderingDuration |
1452 |
|
// + "ms"); |
1453 |
|
|
1454 |
repaintTimer.stop(); |
repaintTimer.stop(); |
1455 |
updateFinalImage(); |
|
1456 |
repaint(); |
// We "forget" about an exception every time we complete a rendering |
1457 |
|
// thread successfully |
1458 |
if (renderingErrors.size() > 0) |
if (renderingErrors.size() > 0) |
1459 |
renderingErrors.remove(0); |
renderingErrors.remove(0); |
1460 |
|
|
1461 |
|
updateFinalImage(); |
1462 |
|
repaint(); |
1463 |
} |
} |
1464 |
|
|
1465 |
/** |
/** |
1473 |
* @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent) |
* @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent) |
1474 |
*/ |
*/ |
1475 |
public void onRenderingFailed(final Exception renderingError) { |
public void onRenderingFailed(final Exception renderingError) { |
1476 |
this.renderingErrors.add(renderingError); |
|
1477 |
|
// Store the exceptions so we can show it to the user: |
1478 |
|
if (!(renderingError instanceof java.lang.IllegalArgumentException && renderingError |
1479 |
|
.getMessage().equals( |
1480 |
|
"Argument \"sourceCRS\" should not be null."))) |
1481 |
|
this.renderingErrors.add(renderingError); |
1482 |
if (renderingErrors.size() > 3) |
if (renderingErrors.size() > 3) |
1483 |
renderingErrors.remove(0); |
renderingErrors.remove(0); |
1484 |
|
|
1485 |
repaintTimer.stop(); |
repaintTimer.stop(); |
1486 |
|
|
1487 |
LOGGER.warn("Rendering failed", renderingError); |
LOGGER.warn("Rendering failed", renderingError); |
1488 |
updateFinalImage(); |
updateFinalImage(); |
1489 |
repaint(); |
repaint(); |
1490 |
|
|
1491 |
} |
} |
1492 |
|
|
|
public void onRenderingPending() { |
|
|
// LOGGER.debug("Pending rendering updates the preview..."); |
|
|
updateFinalImage(); |
|
|
repaint(); |
|
|
} |
|
|
|
|
1493 |
@Override |
@Override |
1494 |
protected void paintComponent(final Graphics g) { |
protected void paintComponent(final Graphics g) { |
1495 |
|
|
1496 |
|
// Maybe update the cursor and maybe stop the repainting timer |
1497 |
|
updateCursor(); |
1498 |
|
|
1499 |
if (!acceptsRepaintCalls) |
if (!acceptsRepaintCalls) |
1500 |
return; |
return; |
1501 |
|
|
1502 |
// Maybe update the cursor and maybe stop the repainting timer |
if (!isWellDefined()) |
1503 |
updateCursor(); |
return; |
1504 |
|
// |
1505 |
|
// if (paneResized) { |
1506 |
|
// // ((Graphics2D) g).setBackground(getMapBackgroundColor()); |
1507 |
|
// // g.clearRect(0, 0, getVisibleRect().width, |
1508 |
|
// getVisibleRect().height); |
1509 |
|
// return; |
1510 |
|
// } |
1511 |
|
|
1512 |
// super.paintComponent(g); // candidate for removal |
// super.paintComponent(g); // candidate for removal |
1513 |
|
|
1520 |
// If the new mapArea and the oldMapArea intersect, we can draw some |
// If the new mapArea and the oldMapArea intersect, we can draw some |
1521 |
// quick scaled preview to make the user feel that something is |
// quick scaled preview to make the user feel that something is |
1522 |
// happening. |
// happening. |
1523 |
if (mapAreaChanged && oldMapArea != null |
if (lastRenderingDuration > PRESCALE_MINTIME && mapAreaChanged |
1524 |
|
&& oldMapArea != null |
1525 |
&& getMapArea().intersects(oldMapArea) |
&& getMapArea().intersects(oldMapArea) |
1526 |
& !getMapArea().equals(oldMapArea) && !paneResized) { |
&& !getMapArea().equals(oldMapArea) && !paneResized) { |
1527 |
|
|
1528 |
mapAreaChanged = false; |
mapAreaChanged = false; |
1529 |
|
|
1530 |
if (getMapArea().covers(oldMapArea)) { |
// if (getMapArea().covers(oldMapArea)) { |
1531 |
setQuickPreviewHint(ZOOM_OUT); |
// // quickPreviewHint = ZOOM_OUT; |
1532 |
paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g); |
// paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) |
1533 |
} else if (oldMapArea.covers(getMapArea())) { |
// g); |
1534 |
setQuickPreviewHint(ZOOM_IN); |
// } else if (oldMapArea.covers(getMapArea())) { |
1535 |
paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g); |
// quickPreviewHint = ZOOM_IN; |
1536 |
} |
paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g); |
1537 |
|
// } |
1538 |
} |
} |
|
|
|
|
// if (paneResized) { |
|
|
// paneResized = false; |
|
|
// disposeImages(); |
|
|
// } |
|
|
// |
|
|
// // Start the Threads and Timers to render the image |
|
|
// requestStartRendering(); |
|
|
|
|
1539 |
} |
} |
1540 |
|
|
1541 |
if (!paintedSomething) { |
if (!paintedSomething) { |
1542 |
|
|
1543 |
g.drawImage(getFinalImage(), 0, 0, null); |
g.drawImage(getFinalImage(), 0, 0, null); |
1544 |
|
|
|
g.dispose(); // cand. for removal |
|
|
|
|
1545 |
paintedSomething = true; // cand. for removal |
paintedSomething = true; // cand. for removal |
1546 |
} |
} |
1547 |
|
|
1589 |
} |
} |
1590 |
|
|
1591 |
} |
} |
1592 |
|
// |
1593 |
/** |
// /** |
1594 |
* Performs a {@value #PAN} action. During panning, the displacement is |
// * Performs a {@value #PAN} action. During panning, the displacement is |
1595 |
* stored in {@link #imageOrigin} object. Calling {@link #performPan()} will |
// * stored in {@link #imageOrigin} object. Calling {@link #performPan()} will |
1596 |
* reset the offset and call {@link #setMapArea(Envelope)}. |
// * reset the offset and call {@link #setMapArea(Envelope)}. |
1597 |
*/ |
// */ |
1598 |
public void performPan() { |
// public void performPan() { |
1599 |
|
// |
1600 |
Rectangle winBounds = getVisibleRect(); |
// final Rectangle winBounds = getVisibleRect(); |
1601 |
|
// |
1602 |
winBounds.translate(-imageOrigin.x, -imageOrigin.y); |
// winBounds.translate(-imageOrigin.x, -imageOrigin.y); |
1603 |
final Envelope newMapArea = tranformWindowToGeo(winBounds.x, |
// final Envelope newMapArea = tranformWindowToGeo(winBounds.x, |
1604 |
winBounds.y, winBounds.x + winBounds.width, winBounds.y |
// winBounds.y, winBounds.x + winBounds.width, winBounds.y |
1605 |
+ winBounds.height); |
// + winBounds.height); |
1606 |
|
// |
1607 |
imageOrigin.x = 0; |
// imageOrigin.x = 0; |
1608 |
imageOrigin.y = 0; |
// imageOrigin.y = 0; |
1609 |
|
// |
1610 |
if (!setMapArea(newMapArea)) { |
// if (!setMapArea(newMapArea)) { |
1611 |
/** |
// /** |
1612 |
* If setMapArea returns true, the finalImage is updated anyways. |
// * If setMapArea returns true, the finalImage is updated anyways. |
1613 |
* This if-case exists to ensure that we repaint a correct image |
// * This if-case exists to ensure that we repaint a correct image |
1614 |
* even if the new panning area has been denied. |
// * even if the new panning area has been denied. |
1615 |
*/ |
// */ |
1616 |
updateFinalImage(); |
// updateFinalImage(); |
1617 |
repaint(); |
// repaint(); |
1618 |
} |
// } |
1619 |
|
// |
1620 |
if (getCursor() == SwingUtil.PANNING_CURSOR) |
// if (getCursor() == SwingUtil.PANNING_CURSOR) |
1621 |
setCursor(SwingUtil.PAN_CURSOR); |
// setCursor(SwingUtil.PAN_CURSOR); |
1622 |
} |
// } |
|
|
|
|
// |
|
|
// /** |
|
|
// * 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); |
|
|
// } |
|
|
// } |
|
1623 |
|
|
1624 |
/** |
/** |
1625 |
* Entfernt einen Listener von der Map. |
* Entfernt einen Listener von der Map. |
1639 |
private void requestStartRendering() { |
private void requestStartRendering() { |
1640 |
if (bgExecuter != null) |
if (bgExecuter != null) |
1641 |
bgExecuter.cancelTask(); |
bgExecuter.cancelTask(); |
1642 |
if (localExecuter != null) |
|
1643 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
1644 |
|
|
1645 |
mapImageInvalid = true; |
mapImageInvalid = true; |
1646 |
if (paneResized) { |
if (paneResized) { |
1665 |
* the current map pane extent (screen units) |
* the current map pane extent (screen units) |
1666 |
*/ |
*/ |
1667 |
private void resetTransforms() { |
private void resetTransforms() { |
|
ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea, |
|
|
getMapContext().getCoordinateReferenceSystem()); |
|
|
|
|
1668 |
// System.out |
// System.out |
1669 |
// .println("paintArea in resetTeansofrms = " + getVisibleRect()); |
// .println("paintArea in resetTeansofrms = " + getVisibleRect()); |
1670 |
if (!isWellDefined()) |
if (!isWellDefined()) |
1671 |
return; |
return; |
1672 |
|
|
1673 |
|
if (mapArea == null) |
1674 |
|
return; |
1675 |
|
|
1676 |
|
final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea, |
1677 |
|
getMapContext().getCoordinateReferenceSystem()); |
1678 |
|
|
1679 |
worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv, |
worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv, |
1680 |
getVisibleRect()); |
getVisibleRect()); |
1681 |
|
|
1682 |
try { |
try { |
1683 |
screenToWorld = worldToScreen.createInverse(); |
screenToWorld = worldToScreen.createInverse(); |
1684 |
|
|
1685 |
} catch (NoninvertibleTransformException ex) { |
} catch (final NoninvertibleTransformException ex) { |
1686 |
LOGGER |
LOGGER |
1687 |
.error("can't invert worldToScreen to get screenToWorld!", |
.error("can't invert worldToScreen to get screenToWorld!", |
1688 |
ex); |
ex); |
1738 |
|
|
1739 |
// setMapArea(localContext.getAreaOfInterest()); |
// setMapArea(localContext.getAreaOfInterest()); |
1740 |
|
|
1741 |
localRenderer.setContext(localContext); |
getLocalRenderer().setContext(localContext); |
1742 |
|
|
1743 |
this.localContext.addMapLayerListListener(localContextListener); |
this.localContext.addMapLayerListListener(localContextListener); |
1744 |
|
|
1752 |
|
|
1753 |
} |
} |
1754 |
|
|
1755 |
|
public void setBorder(final Border b) { |
1756 |
|
super.setBorder(b); |
1757 |
|
} |
1758 |
|
|
1759 |
|
/** |
1760 |
|
* Triggers to repaint (fast) and re-render (slow) the JMapPane. |
1761 |
|
*/ |
1762 |
|
public void refresh() { |
1763 |
|
mapImageInvalid = true; |
1764 |
|
repaint(); |
1765 |
|
} |
1766 |
|
|
1767 |
|
// /** |
1768 |
|
// * Triggers to use new {@link GTRenderer} and refresh the map. Should be |
1769 |
|
// * called after {@link Style}s have been changed because GTRenderer is |
1770 |
|
// * otherwise not working well. |
1771 |
|
// */ |
1772 |
|
// public void refreshRenderers() { |
1773 |
|
// localRenderer = GTUtil.createGTRenderer(); |
1774 |
|
// setLocalContext(getMapContext()); |
1775 |
|
// mapImageInvalid = true; |
1776 |
|
// repaint(); |
1777 |
|
// } |
1778 |
|
|
1779 |
|
/** |
1780 |
|
* Set the new map area. |
1781 |
|
* |
1782 |
|
* @param newMapArea |
1783 |
|
* @return <code>true</code> if the mapArea has been changed and a repaint |
1784 |
|
* has been triggered. |
1785 |
|
*/ |
1786 |
public boolean setMapArea(final Envelope newMapArea) { |
public boolean setMapArea(final Envelope newMapArea) { |
1787 |
|
if (newMapArea == null) |
1788 |
|
return false; |
1789 |
|
if (getMapContext().getCoordinateReferenceSystem() == null) |
1790 |
|
return false; |
1791 |
return setMapArea(new ReferencedEnvelope(newMapArea, getMapContext() |
return setMapArea(new ReferencedEnvelope(newMapArea, getMapContext() |
1792 |
.getCoordinateReferenceSystem())); |
.getCoordinateReferenceSystem())); |
1793 |
} |
} |
1794 |
|
|
1795 |
/** |
/** |
1796 |
|
* Set the new map area. |
1797 |
|
* |
1798 |
* @param newMapArea |
* @param newMapArea |
1799 |
* @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 |
1800 |
* has been triggered. |
* has been triggered. |
1801 |
*/ |
*/ |
1802 |
public boolean setMapArea(final ReferencedEnvelope newMapArea) { |
public boolean setMapArea(final ReferencedEnvelope newMapArea) { |
|
// |
|
|
// if (getVisibleRect().getWidth() == 0 || (!isVisible()) || |
|
|
// getVisibleRect().getHeight() == 0) { |
|
|
// // The window is not yet defined.. so we can not really determine the |
|
|
// asepect ratio for the mapPane. We store this as a candidate mappane |
|
|
// and handle it when the component resizes or becomes visible) |
|
|
// mapAreaCondidate = newMapArea; |
|
|
// } |
|
1803 |
|
|
1804 |
if (newMapArea == null |
if (newMapArea == null |
1805 |
|| bestAllowedMapArea(newMapArea).equals(mapArea)) { |
|| bestAllowedMapArea(newMapArea).equals(mapArea)) { |
1857 |
|
|
1858 |
mapAreaChanged = true; |
mapAreaChanged = true; |
1859 |
|
|
1860 |
repaint(100); |
repaint(200); // Do not remove it! |
1861 |
|
|
1862 |
requestStartRendering(); |
requestStartRendering(); |
1863 |
|
|
1869 |
* |
* |
1870 |
* @param if <code>null</code>, white is used. |
* @param if <code>null</code>, white is used. |
1871 |
*/ |
*/ |
1872 |
public void setMapBackgroundColor(Color bgColor) { |
public void setMapBackgroundColor(final Color bgColor) { |
|
if (bgColor == null) |
|
|
bgColor = Color.WHITE; |
|
1873 |
this.mapBackgroundColor = bgColor; |
this.mapBackgroundColor = bgColor; |
1874 |
} |
} |
1875 |
|
|
1927 |
} |
} |
1928 |
|
|
1929 |
// /** Stored the time used for the last real rendering in ms. **/ |
// /** Stored the time used for the last real rendering in ms. **/ |
1930 |
// private long lastRenderingDuration = Long.MAX_VALUE; |
private long lastRenderingDuration = 1000; |
1931 |
|
private XMapPaneTool tool = null; |
1932 |
|
|
1933 |
/** |
/** |
1934 |
* Set the minimum (nearest) allowed zoom scale. This is the bigger number |
* Set the minimum (nearest) allowed zoom scale. This is the bigger number |
1945 |
} |
} |
1946 |
|
|
1947 |
/** |
/** |
1948 |
* |
* If <code>true</code>, allow the {@link XMapPane} to process #repaint() |
1949 |
* @param b |
* requests. Otherwise the map will not paint anything and not start any |
1950 |
|
* rendering {@link Thread}s. |
1951 |
*/ |
*/ |
1952 |
public void setPainting(final boolean b) { |
public void setPainting(final boolean b) { |
1953 |
acceptsRepaintCalls = b; |
acceptsRepaintCalls = b; |
1954 |
} |
if (acceptsRepaintCalls == true) |
1955 |
|
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; |
|
|
|
|
1956 |
} |
} |
1957 |
|
|
1958 |
private void setRendererHints(final Map<Object, Object> rendererHints) { |
private void setRendererHints(final Map<Object, Object> rendererHints) { |
1960 |
this.rendererHints = rendererHints; |
this.rendererHints = rendererHints; |
1961 |
} |
} |
1962 |
|
|
1963 |
/** |
// @Deprecated |
1964 |
* Enables/Disables the ZOOM Mouse Listener. Upates the Cursor and stops the |
// public void setState(final int state) { |
1965 |
* repaint Timer if |
// this.state = state; |
1966 |
* |
// |
1967 |
* @param state |
// // throw new RuntimeException("Old concept.. migrate to new concept!"); |
1968 |
*/ |
// |
1969 |
public void setState(final int state) { |
// // xMapPaneMouseListener.setEnabled((state == ZOOM_IN |
1970 |
this.state = state; |
// // || state == ZOOM_OUT || state == PAN)); |
1971 |
|
// |
1972 |
zoomMapPaneMouseListener.setEnabled((state == ZOOM_IN |
// // Je nach Aktion den Cursor umsetzen |
1973 |
|| state == ZOOM_OUT || state == PAN)); |
// updateCursor(); |
1974 |
|
// } |
1975 |
// Je nach Aktion den Cursor umsetzen |
|
1976 |
updateCursor(); |
public void configureMouse(MouseInputType type, XMapPaneAction action) { |
1977 |
} |
xMapPaneMouseListener.actions.put(type, action); |
1978 |
|
} |
1979 |
/** |
|
1980 |
* Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion (Zoom, |
/** |
1981 |
* Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor |
* Configure the {@link XMapPaneTool} that active on the map. Passing |
1982 |
* gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion |
* <code>null</code> will set the NO_ACTION tool. |
1983 |
* beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann |
*/ |
1984 |
* {@code null} als Parameter uebergeben werden |
public void setTool(XMapPaneTool tool) { |
1985 |
* |
if (tool == null) |
1986 |
* @param cursor |
tool = XMapPaneTool.NO_ACTION; |
1987 |
* Cursor |
this.tool = tool; |
1988 |
*/ |
xMapPaneMouseListener.configure(tool); |
1989 |
public void setStaticCursor(final Cursor cursor) { |
setCursor(tool.getCursor()); |
1990 |
this.staticCursor = cursor; |
} |
1991 |
if (cursor != null) |
|
1992 |
super.setCursor(cursor); |
// /** |
1993 |
} |
// * Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion (Zoom, |
1994 |
|
// * Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor |
1995 |
|
// * gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion |
1996 |
|
// * beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann |
1997 |
|
// * {@code null} als Parameter uebergeben werden |
1998 |
|
// * |
1999 |
|
// * @param cursor |
2000 |
|
// * Cursor |
2001 |
|
// */ |
2002 |
|
// public void setStaticCursor(final Cursor cursor) { |
2003 |
|
// this.staticCursor = cursor; |
2004 |
|
// if (cursor != null) |
2005 |
|
// super.setCursor(cursor); |
2006 |
|
// } |
2007 |
|
|
2008 |
/** |
/** |
2009 |
* Starts rendering on one or two threads |
* Starts rendering on one or two threads |
2011 |
private void startRendering() { |
private void startRendering() { |
2012 |
|
|
2013 |
if (!isWellDefined() || !acceptsRepaintCalls) { |
if (!isWellDefined() || !acceptsRepaintCalls) { |
2014 |
|
// if we are not ready to start rendering, try it again the next |
2015 |
|
// time the timer is chacking the flag. |
2016 |
requestStartRendering = true; |
requestStartRendering = true; |
2017 |
return; |
return; |
2018 |
} |
} |
2022 |
bgExecuter.cancelTask(); |
bgExecuter.cancelTask(); |
2023 |
} |
} |
2024 |
|
|
2025 |
if (localExecuter != null) { |
localExecuter.cancelTask(); |
|
localExecuter.cancelTask(); |
|
|
} |
|
2026 |
|
|
2027 |
final Rectangle curPaintArea = getVisibleRect(); |
final Rectangle curPaintArea = getVisibleRect(); |
2028 |
|
|
2049 |
// localExecuter = new RenderingExecutor(this, 150l); |
// localExecuter = new RenderingExecutor(this, 150l); |
2050 |
// LOGGER.debug("starting local renderer:"); |
// LOGGER.debug("starting local renderer:"); |
2051 |
|
|
2052 |
localRenderer.setJava2DHints(getJava2dHints()); |
getLocalRenderer().setJava2DHints(getJava2dHints()); |
2053 |
localRenderer.setRendererHints(getRendererHints()); |
getLocalRenderer().setRendererHints(getRendererHints()); |
2054 |
|
|
2055 |
final boolean submitted = localExecuter.submit(getMapArea(), |
final boolean submitted = localExecuter.submit(getMapArea(), |
2056 |
curPaintArea, (Graphics2D) getLocalImage().getGraphics(), |
curPaintArea, (Graphics2D) getLocalImage().getGraphics(), |
2057 |
localRenderer |
getLocalRenderer()); |
|
// , getWorldToScreenTransform() |
|
|
); |
|
2058 |
if (submitted) |
if (submitted) |
2059 |
repaintTimer.restart(); |
repaintTimer.restart(); |
2060 |
else |
else |
2066 |
updateCursor(); |
updateCursor(); |
2067 |
} |
} |
2068 |
|
|
2069 |
|
private RenderingHints getJava2dHints() { |
2070 |
|
return java2dHints; |
2071 |
|
} |
2072 |
|
|
2073 |
/** |
/** |
2074 |
* Transformiert einen Geo-Koordinaten-Bereich in Fenster-Koordinaten. |
* Transformiert einen Geo-Koordinaten-Bereich in Fenster-Koordinaten. |
2075 |
* |
* |
2133 |
// if the renderers have stopped, also stop the timer that is updating |
// if the renderers have stopped, also stop the timer that is updating |
2134 |
// the final image |
// the final image |
2135 |
if (bgExecuter != null && bgExecuter.isRunning() |
if (bgExecuter != null && bgExecuter.isRunning() |
2136 |
|| localExecuter != null && localExecuter.isRunning()) { |
|| localExecuter.isRunning()) { |
2137 |
setCursor(WAIT_CURSOR); |
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); |
2138 |
return; |
return; |
2139 |
} else { |
} else { |
2140 |
// Allow one last rendering |
// Allow one last rendering |
2145 |
repaint(); |
repaint(); |
2146 |
} |
} |
2147 |
} |
} |
2148 |
|
// |
2149 |
// wenn manueller Cursor gesetzt ist, dann diesen verwenden (unabhaengig |
//// |
2150 |
// von der aktuellen Aktion |
// // wenn manueller Cursor gesetzt ist, dann diesen verwenden (unabhaengig |
2151 |
if (this.staticCursor != null) { |
// // von der aktuellen Aktion |
2152 |
setCursor(staticCursor); |
// if (this.staticCursor != null) { |
2153 |
return; |
// setCursor(staticCursor); |
2154 |
} |
// return; |
2155 |
|
// } |
2156 |
|
// |
2157 |
if (getCursor() == SwingUtil.PANNING_CURSOR) { |
if (getCursor() == SwingUtil.PANNING_CURSOR) { |
2158 |
// This cursor will reset itself |
// This cursor will reset itself |
2159 |
return; |
return; |
2160 |
} |
} |
2161 |
|
|
2162 |
// Set the cursor depending on what tool is in use... |
setCursor(tool.getCursor()); |
2163 |
switch (state) { |
|
2164 |
case SELECT_TOP: |
// |
2165 |
case SELECT_ONE_FROM_TOP: |
// // Set the cursor depending on what tool is in use... |
2166 |
case SELECT_ALL: |
// switch (state) { |
2167 |
setCursor(SwingUtil.CROSSHAIR_CURSOR); |
// case SELECT_TOP: |
2168 |
break; |
// case SELECT_ONE_FROM_TOP: |
2169 |
case ZOOM_IN: |
// case SELECT_ALL: |
2170 |
setCursor(SwingUtil.ZOOMIN_CURSOR); |
// setCursor(SwingUtil.CROSSHAIR_CURSOR); |
2171 |
break; |
// break; |
2172 |
case ZOOM_OUT: |
// case ZOOM_IN: |
2173 |
setCursor(SwingUtil.ZOOMOUT_CURSOR); |
// setCursor(SwingUtil.ZOOMIN_CURSOR); |
2174 |
break; |
// break; |
2175 |
case PAN: |
// case ZOOM_OUT: |
2176 |
setCursor(SwingUtil.PAN_CURSOR); |
// setCursor(SwingUtil.ZOOMOUT_CURSOR); |
2177 |
break; |
// break; |
2178 |
default: |
// case PAN: |
2179 |
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
// setCursor(SwingUtil.PAN_CURSOR); |
2180 |
break; |
// break; |
2181 |
} |
// default: |
2182 |
|
// setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
2183 |
|
// break; |
2184 |
|
// } |
2185 |
} |
} |
2186 |
|
|
2187 |
/** |
/** |
2211 |
|
|
2212 |
final Graphics2D finalG = getFinalImage().createGraphics(); |
final Graphics2D finalG = getFinalImage().createGraphics(); |
2213 |
finalG.setBackground(getMapBackgroundColor()); |
finalG.setBackground(getMapBackgroundColor()); |
2214 |
finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y, |
finalG.drawImage(getPreFinalImage(), getImageOrigin().x, getImageOrigin().y, |
2215 |
getMapBackgroundColor(), null); |
getMapBackgroundColor(), null); |
2216 |
|
|
2217 |
final int finalImageHeight = getFinalImage().getHeight(null); |
// When panning, we have to clear the area around the image |
2218 |
final int finalImageWidth = getFinalImage().getWidth(null); |
final Rectangle painedArea = new Rectangle(getImageOrigin().x, |
2219 |
|
getImageOrigin().y, getFinalImage().getWidth(), getFinalImage() |
2220 |
|
.getHeight()); |
2221 |
|
SwingUtil.clearAround(finalG, painedArea, getVisibleRect(), |
2222 |
|
getMapBackgroundColor()); |
2223 |
|
|
2224 |
final Rectangle painedArea = new Rectangle(imageOrigin.x, |
// addGadgets(finalG, false); |
|
imageOrigin.y, finalImageWidth, finalImageHeight); |
|
|
SwingUtil.clearAround(finalG, painedArea, getVisibleRect()); |
|
|
|
|
|
addGadgets(finalG, false); |
|
2225 |
|
|
2226 |
finalG.dispose(); |
finalG.dispose(); |
2227 |
|
|
2238 |
* <code>false</code>, it will only depend on |
* <code>false</code>, it will only depend on |
2239 |
* {@link #localExecuter.isRunning} and #bgExecuter.isRunning |
* {@link #localExecuter.isRunning} and #bgExecuter.isRunning |
2240 |
*/ |
*/ |
2241 |
private void addGadgets(final Graphics2D graphics, boolean forceWait) { |
private void addGadgets(final Graphics2D graphics, final boolean forceWait) { |
2242 |
|
|
2243 |
// Paint a logo to the bottom right if available |
// Paint a logo to the bottom right if available |
2244 |
if (mapImage != null) { |
if (mapImage != null) { |
2245 |
Rectangle visibleRect = getVisibleRect(); |
final Rectangle visibleRect = getVisibleRect(); |
2246 |
graphics.drawImage(mapImage, visibleRect.width |
graphics.drawImage(mapImage, visibleRect.width |
2247 |
- mapImage.getWidth() - 10, getVisibleRect().height |
- mapImage.getWidth() - 10, getVisibleRect().height |
2248 |
- mapImage.getHeight() - 10, null); |
- mapImage.getHeight() - 10, null); |
2252 |
|
|
2253 |
// If the rendering process is still running, indicate this is the image |
// If the rendering process is still running, indicate this is the image |
2254 |
if (forceWait || bgExecuter != null && bgExecuter.isRunning() |
if (forceWait || bgExecuter != null && bgExecuter.isRunning() |
2255 |
|| localExecuter != null && localExecuter.isRunning()) { |
|| localExecuter.isRunning()) { |
2256 |
|
|
2257 |
y += 8; |
y += 8; |
2258 |
|
|
2268 |
|
|
2269 |
graphics.setColor(c); |
graphics.setColor(c); |
2270 |
|
|
2271 |
y += 24; |
y += 21; |
2272 |
} |
} |
2273 |
|
|
2274 |
if (renderingErrors != null) { |
if (!renderingErrors.isEmpty() && isShowExceptions()) { |
2275 |
|
|
2276 |
final Color c = graphics.getColor(); |
final Color c = graphics.getColor(); |
2277 |
graphics.setFont(errorFont); |
graphics.setFont(errorFont); |
2278 |
|
|
2279 |
for (Exception ex : renderingErrors) { |
for (final Exception ex : renderingErrors) { |
|
|
|
|
if (ex instanceof java.lang.IllegalArgumentException |
|
|
&& ex.getMessage().equals( |
|
|
"Argument \"sourceCRS\" should not be null.")) |
|
|
continue; |
|
2280 |
|
|
2281 |
String errStr = ex.getLocalizedMessage(); |
String errStr = ex.getLocalizedMessage(); |
2282 |
|
|
2285 |
if (errStr == null) |
if (errStr == null) |
2286 |
errStr = "unknown error: " + ex.getClass().getSimpleName(); |
errStr = "unknown error: " + ex.getClass().getSimpleName(); |
2287 |
|
|
2288 |
graphics.setColor(Color.WHITE); |
graphics.setColor(getMapBackgroundColor()); |
2289 |
graphics.drawString(errStr, 5, y); |
graphics.drawString(errStr, 5, y); |
2290 |
graphics.setColor(Color.RED); |
graphics.setColor(Color.RED); |
2291 |
graphics.drawString(errStr, 6, y + 1); |
graphics.drawString(errStr, 6, y + 1); |
2313 |
final CoordinateReferenceSystem mapCRS = getMapContext() |
final CoordinateReferenceSystem mapCRS = getMapContext() |
2314 |
.getCoordinateReferenceSystem(); |
.getCoordinateReferenceSystem(); |
2315 |
final CoordinateReferenceSystem fCRS = features.getSchema() |
final CoordinateReferenceSystem fCRS = features.getSchema() |
2316 |
.getGeometryDescriptor().getCoordinateReferenceSystem(); |
.getCoordinateReferenceSystem(); |
2317 |
|
|
2318 |
ReferencedEnvelope _mapArea; |
ReferencedEnvelope _mapArea; |
2319 |
if (mapArea == null) |
if (mapArea == null) |
2320 |
_mapArea = features.getBounds(); |
_mapArea = features.getBounds(); |
2321 |
else _mapArea = getMapArea(); |
else |
2322 |
|
_mapArea = getMapArea(); |
2323 |
double width = _mapArea.getWidth(); |
double width = _mapArea.getWidth(); |
2324 |
double height = _mapArea.getHeight(); |
double height = _mapArea.getHeight(); |
2325 |
final double ratio = height / width; |
final double ratio = height / width; |
2406 |
* @param center |
* @param center |
2407 |
* position in window coordinates |
* position in window coordinates |
2408 |
* @param zoomFaktor |
* @param zoomFaktor |
2409 |
* > 1 for zoom in, < 1 for zoom out. Default is 1.33. |
* > 1 for zoom out, < 1 for zoom in. Default is .5 |
2410 |
*/ |
*/ |
2411 |
public void zoomTo(Point center, Double zoomFaktor) { |
public void zoomTo(Point center, Double zoomFaktor) { |
2412 |
if (zoomFaktor == null || zoomFaktor == 0.) |
if (zoomFaktor == null || zoomFaktor == 0.) |
2413 |
zoomFaktor = 2.; |
zoomFaktor = .5; |
2414 |
|
|
2415 |
final Point2D gcenter = getScreenToWorld().transform(center, null); |
final Point2D gcenter = getScreenToWorld().transform(center, null); |
2416 |
center = null; |
center = null; |
2431 |
.getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea |
.getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea |
2432 |
.getHeight()) / 2.); |
.getHeight()) / 2.); |
2433 |
|
|
2434 |
// TODO we actually want that |
// // Move the newMapArea above the new center if we zoom in: |
2435 |
// // Move the newMapArea above the new center |
newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter |
2436 |
// newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter |
.getY() |
2437 |
// .getY() |
- mapArea.centre().y); |
|
// - mapArea.centre().y); |
|
2438 |
|
|
2439 |
setMapArea(newMapArea); |
setMapArea(newMapArea); |
2440 |
} |
} |
2441 |
|
|
2442 |
|
/** |
2443 |
|
* Shall non-fatal rendering exceptions be reported in the mappane or be |
2444 |
|
* dropped quitely. |
2445 |
|
*/ |
2446 |
|
public void setShowExceptions(final boolean showExceptions) { |
2447 |
|
this.showExceptions = showExceptions; |
2448 |
|
} |
2449 |
|
|
2450 |
|
/** |
2451 |
|
* Shall exceptions be reported in the mappane? |
2452 |
|
*/ |
2453 |
|
public boolean isShowExceptions() { |
2454 |
|
return showExceptions; |
2455 |
|
} |
2456 |
|
|
2457 |
|
public GTRenderer getLocalRenderer() { |
2458 |
|
return localRenderer; |
2459 |
|
} |
2460 |
|
|
2461 |
|
/** |
2462 |
|
* Setzt den Kartenausschnitt auf die Ausdehnung eines bestimmten Layers. |
2463 |
|
* Macht nichts, wenn {@code null} uebergeben wird. |
2464 |
|
* |
2465 |
|
* <br> |
2466 |
|
* |
2467 |
|
* @param layer |
2468 |
|
* ein Layer |
2469 |
|
*/ |
2470 |
|
public void zoomToLayer(MapLayer layer) { |
2471 |
|
if (layer == null) |
2472 |
|
return; |
2473 |
|
try { |
2474 |
|
|
2475 |
|
// BB umrechnen von Layer-CRS in Map-CRS |
2476 |
|
final CoordinateReferenceSystem targetCRS = getMapContext() |
2477 |
|
.getCoordinateReferenceSystem(); |
2478 |
|
final CoordinateReferenceSystem sourceCRS = layer |
2479 |
|
.getFeatureSource().getSchema() |
2480 |
|
.getCoordinateReferenceSystem(); |
2481 |
|
|
2482 |
|
Envelope mapAreaNew; |
2483 |
|
if (!CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) { |
2484 |
|
mapAreaNew = JTSUtil.transformEnvelope(layer.getFeatureSource() |
2485 |
|
.getBounds(), sourceCRS, targetCRS); |
2486 |
|
} else { |
2487 |
|
try { |
2488 |
|
mapAreaNew = layer.getFeatureSource().getBounds(); |
2489 |
|
} catch (java.lang.IllegalArgumentException e) { |
2490 |
|
LOGGER.error("Can't calc layers bounds...", e); |
2491 |
|
mapAreaNew = null; |
2492 |
|
|
2493 |
|
/** |
2494 |
|
* |
2495 |
|
23.10.2009 11:20:50 |
2496 |
|
* org.geotools.data.shapefile.shp.PolygonHandler read |
2497 |
|
* WARNUNG: only one hole in this polygon record ERROR |
2498 |
|
* JMapPane zoomToLayer Zoom to layer did not terminate |
2499 |
|
* correctly java.lang.IllegalArgumentException: Points of |
2500 |
|
* LinearRing do not form a closed linestring at |
2501 |
|
* com.vividsolutions |
2502 |
|
* .jts.geom.LinearRing.validateConstruction |
2503 |
|
* (LinearRing.java:105) at |
2504 |
|
* com.vividsolutions.jts.geom.LinearRing |
2505 |
|
* .<init>(LinearRing.java:100) at |
2506 |
|
* com.vividsolutions.jts.geom |
2507 |
|
* .GeometryFactory.createLinearRing |
2508 |
|
* (GeometryFactory.java:339) at |
2509 |
|
* org.geotools.data.shapefile. |
2510 |
|
* shp.PolygonHandler.read(PolygonHandler.java:188) at |
2511 |
|
* org.geotools |
2512 |
|
* .data.shapefile.shp.ShapefileReader$Record.shape |
2513 |
|
* (ShapefileReader.java:106) at |
2514 |
|
* org.geotools.data.shapefile. |
2515 |
|
* ShapefileAttributeReader.next( |
2516 |
|
* ShapefileAttributeReader.java:157) at |
2517 |
|
* org.geotools.data.shapefile |
2518 |
|
* .indexed.IndexedShapefileAttributeReader |
2519 |
|
* .next(IndexedShapefileAttributeReader.java:122) at |
2520 |
|
* org.geotools |
2521 |
|
* .data.FIDFeatureReader.next(FIDFeatureReader.java:96) at |
2522 |
|
* org.geotools.data.FIDFeatureReader.next(FIDFeatureReader. |
2523 |
|
* java:55) at org.geotools.data.MaxFeatureReader.next( |
2524 |
|
* MaxFeatureReader.java:61) at |
2525 |
|
* org.geotools.data.MaxFeatureReader |
2526 |
|
* .next(MaxFeatureReader.java:61) |
2527 |
|
**/ |
2528 |
|
} |
2529 |
|
} |
2530 |
|
|
2531 |
|
// Kartenbereich um 10% vergroessern, damit z.B. auch ein |
2532 |
|
// Punkt-Layer, |
2533 |
|
// welches nur aus 2 Punnkten besteht, sichtbar ist (Punkte liegen |
2534 |
|
// sonst |
2535 |
|
// genau auf dem Rand der angezeigten Flaeche) |
2536 |
|
|
2537 |
|
if (mapAreaNew != null) { |
2538 |
|
mapAreaNew.expandBy(mapAreaNew.getWidth() * 0.1, mapAreaNew |
2539 |
|
.getHeight() * 0.1); |
2540 |
|
setMapArea(mapAreaNew); |
2541 |
|
} else { |
2542 |
|
LOGGER |
2543 |
|
.warn("Couldn't transformEnvelope when zooming to the layer"); |
2544 |
|
} |
2545 |
|
} catch (Exception err) { |
2546 |
|
LOGGER.error("Zoom to layer did not terminate correctly", err); |
2547 |
|
} |
2548 |
|
} |
2549 |
|
|
2550 |
|
/** |
2551 |
|
* Zooms the {@link SelectableXMapPane} to the {@link Envelope} of a layer. |
2552 |
|
* |
2553 |
|
* <br> |
2554 |
|
* A refresh of the map is not done automatically |
2555 |
|
* |
2556 |
|
* @param index |
2557 |
|
* Index of the {@link MapLayer} in the {@link MapContext} (from |
2558 |
|
* back to top) |
2559 |
|
* |
2560 |
|
* @author <a href="mailto:[email protected]">Stefan Alfons |
2561 |
|
* Krüger</a> |
2562 |
|
*/ |
2563 |
|
public void zoomToLayer(int index) { |
2564 |
|
final MapContext context = getMapContext(); |
2565 |
|
if (context != null) |
2566 |
|
zoomToLayer(context.getLayer(index)); |
2567 |
|
} |
2568 |
|
|
2569 |
|
/** |
2570 |
|
* Zooms the {@link SelectableXMapPane} to the {@link Envelope} of the |
2571 |
|
* selected layer. The layer is selected by the idx, counting from front to |
2572 |
|
* back, like humans would expect in a {@link JList} |
2573 |
|
* |
2574 |
|
* <br> |
2575 |
|
* A refresh of the map is not done automatically |
2576 |
|
* |
2577 |
|
* |
2578 |
|
* |
2579 |
|
* @param index |
2580 |
|
* Reverse index of the {@link MapLayer} in the |
2581 |
|
* {@link MapContext} |
2582 |
|
* |
2583 |
|
* @author <a href="mailto:[email protected]">Stefan Alfons |
2584 |
|
* Krüger</a> |
2585 |
|
*/ |
2586 |
|
public void zoomToLayerIdxReverse(int index) { |
2587 |
|
zoomToLayer(getMapContext().getLayerCount() - 1 - index); |
2588 |
|
} |
2589 |
|
|
2590 |
|
/** |
2591 |
|
* Aktiviert oder deaktiviert das AntiAliasing for diese |
2592 |
|
* {@link SelectableXMapPane}. AntiALiasing ist besonders fuer |
2593 |
|
* Textbeschriftung sehr schoen, verbraucht aber auch mehr Performance. |
2594 |
|
* |
2595 |
|
* @author <a href="mailto:[email protected]">Stefan Alfons |
2596 |
|
* Krüger</a> |
2597 |
|
*/ |
2598 |
|
public void setAntiAliasing(final boolean aa) { |
2599 |
|
// LOGGER.info("Setting AntiAliasing for this JMapPane to " + aa); |
2600 |
|
RenderingHints java2DHints = java2dHints; |
2601 |
|
if (java2DHints == null) { |
2602 |
|
java2DHints = GeoTools.getDefaultHints(); |
2603 |
|
} |
2604 |
|
|
2605 |
|
java2DHints.put(RenderingHints.KEY_ANTIALIASING, |
2606 |
|
aa ? RenderingHints.VALUE_ANTIALIAS_ON |
2607 |
|
: RenderingHints.VALUE_ANTIALIAS_OFF); |
2608 |
|
java2DHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, |
2609 |
|
aa ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON |
2610 |
|
: RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); |
2611 |
|
java2DHints.put(RenderingHints.KEY_RENDERING, |
2612 |
|
aa ? RenderingHints.VALUE_RENDER_QUALITY |
2613 |
|
: RenderingHints.VALUE_RENDER_SPEED); |
2614 |
|
|
2615 |
|
} |
2616 |
|
|
2617 |
|
public Point getImageOrigin() { |
2618 |
|
return imageOrigin; |
2619 |
|
} |
2620 |
|
|
2621 |
} |
} |