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; |
108 |
|
|
109 |
private final static Logger LOGGER = Logger.getLogger(XMapPane.class); |
private final static Logger LOGGER = Logger.getLogger(XMapPane.class); |
110 |
|
|
111 |
|
/** |
112 |
|
* A flag indicating whether the {@link XMapPane} is accepting repaints from |
113 |
|
* the EDT. @see {@link XMapPane#setPainting(boolean)) |
114 |
|
**/ |
115 |
private boolean acceptsRepaintCalls = true; |
private boolean acceptsRepaintCalls = true; |
116 |
|
|
117 |
/** |
/** |
280 |
final AffineTransform at = xMapPane.getScreenToWorld(); |
final AffineTransform at = xMapPane.getScreenToWorld(); |
281 |
if (at != null) { |
if (at != null) { |
282 |
Point2D transformed = at.transform(e.getPoint(), null); |
Point2D transformed = at.transform(e.getPoint(), null); |
283 |
return new DirectPosition2D(xMapPane.getMapContext().getCoordinateReferenceSystem(), transformed.getX(), transformed.getY()); |
return new DirectPosition2D(xMapPane.getMapContext() |
284 |
|
.getCoordinateReferenceSystem(), transformed.getX(), |
285 |
|
transformed.getY()); |
286 |
} |
} |
287 |
return null; |
return null; |
288 |
} |
} |
289 |
throw new IllegalArgumentException( |
throw new IllegalArgumentException( |
290 |
"MouseEvent has to be of instance MapMouseEvent or come from an XMapPane"); |
"MouseEvent has to be of instance MapMouseEvent or come from an XMapPane"); |
291 |
} |
} |
|
|
|
|
|
|
292 |
|
|
293 |
/** |
/** |
294 |
* Listens to changes of the "background" {@link MapContext} and triggers |
* Listens to changes of the "background" {@link MapContext} and triggers |
424 |
|
|
425 |
@Override |
@Override |
426 |
public void layerChanged(final MapLayerListEvent event) { |
public void layerChanged(final MapLayerListEvent event) { |
427 |
// getLocalRenderer().setContext(getMapContext()); geht doch auch ohne?!?!? wow... |
// getLocalRenderer().setContext(getMapContext()); geht doch auch |
428 |
|
// ohne?!?!? wow... |
429 |
requestStartRendering(); |
requestStartRendering(); |
430 |
} |
} |
431 |
|
|
565 |
|
|
566 |
/** |
/** |
567 |
* The default state is ZOOM_IN, hence by default the |
* The default state is ZOOM_IN, hence by default the |
568 |
* {@link #zoomMapPaneMouseListener} is also enabled. |
* {@link #xMapPaneMouseListener} is also enabled. |
569 |
**/ |
**/ |
570 |
private int state = ZOOM_IN; |
private int state = ZOOM_IN; |
571 |
|
|
577 |
|
|
578 |
private AffineTransform worldToScreen; |
private AffineTransform worldToScreen; |
579 |
|
|
580 |
|
// /** |
581 |
|
// * This {@link MouseListener} is managing all zoom related tasks |
582 |
|
// */ |
583 |
|
// private final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new |
584 |
|
// ZoomXMapPaneMouseListener( |
585 |
|
// this); |
586 |
|
|
587 |
/** |
/** |
588 |
* This {@link MouseListener} is managing all zoom related tasks |
* This {@link MouseListener} is managing all zoom related tasks |
589 |
*/ |
*/ |
590 |
public final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new ZoomXMapPaneMouseListener( |
private final XMapPaneMouseListener xMapPaneMouseListener = new XMapPaneMouseListener( |
591 |
this); |
this); |
592 |
|
|
593 |
/** Is set if a renderer has an error **/ |
/** Is set if a renderer has an error **/ |
629 |
/** |
/** |
630 |
* Adding the #zoomMapPaneMouseListener |
* Adding the #zoomMapPaneMouseListener |
631 |
*/ |
*/ |
632 |
this.addMouseListener(zoomMapPaneMouseListener); |
this.addMouseListener(xMapPaneMouseListener); |
633 |
this.addMouseMotionListener(zoomMapPaneMouseListener); |
this.addMouseMotionListener(xMapPaneMouseListener); |
634 |
this.addMouseWheelListener(zoomMapPaneMouseListener); |
this.addMouseWheelListener(xMapPaneMouseListener); |
635 |
|
xMapPaneMouseListener.actions.put(MouseInputType.LClick, |
636 |
|
XMapPaneAction.ZOOM_IN); |
637 |
|
xMapPaneMouseListener.actions.put(MouseInputType.LDrag, |
638 |
|
XMapPaneAction.ZOOM_IN); |
639 |
|
xMapPaneMouseListener.actions.put(MouseInputType.Wheel, |
640 |
|
XMapPaneAction.ZOOM_IN); |
641 |
|
|
642 |
|
xMapPaneMouseListener.actions.put(MouseInputType.RClick, |
643 |
|
XMapPaneAction.ZOOM_OUT); |
644 |
|
|
645 |
|
xMapPaneMouseListener.actions.put(MouseInputType.RDrag, |
646 |
|
XMapPaneAction.ZOOM_OUT); |
647 |
|
|
648 |
/* |
/* |
649 |
* We use a Timer object to avoid rendering delays and flickering when |
* We use a Timer object to avoid rendering delays and flickering when |
998 |
// Remove all mapPaneListeners that have registered with us |
// Remove all mapPaneListeners that have registered with us |
999 |
mapPaneListeners.clear(); |
mapPaneListeners.clear(); |
1000 |
|
|
1001 |
removeMouseMotionListener(zoomMapPaneMouseListener); |
removeMouseMotionListener(xMapPaneMouseListener); |
1002 |
removeMouseListener(zoomMapPaneMouseListener); |
removeMouseListener(xMapPaneMouseListener); |
1003 |
|
|
1004 |
if (localContext != null) |
if (localContext != null) |
1005 |
getMapContext().clearLayerList(); |
getMapContext().clearLayerList(); |
1015 |
*/ |
*/ |
1016 |
protected void drawRectangle(final Graphics graphics, final Point startPos, |
protected void drawRectangle(final Graphics graphics, final Point startPos, |
1017 |
final Point e) { |
final Point e) { |
1018 |
|
drawRectangle(graphics, startPos, e, Color.WHITE); |
1019 |
|
} |
1020 |
|
|
1021 |
|
/** |
1022 |
|
* Draws a rectangle in XOR mode from the origin at {@link #startPos} to the |
1023 |
|
* given point. All in screen coordinates. |
1024 |
|
*/ |
1025 |
|
protected void drawRectangle(final Graphics graphics, final Point startPos, |
1026 |
|
final Point e, Color color) { |
1027 |
|
|
1028 |
if (!isWellDefined()) |
if (!isWellDefined()) |
1029 |
return; |
return; |
1039 |
if (width == 0 && height == 0) |
if (width == 0 && height == 0) |
1040 |
return; |
return; |
1041 |
|
|
1042 |
graphics.setXORMode(Color.WHITE); |
graphics.setXORMode(color); |
1043 |
graphics.drawRect(left, bottom, width, height); |
graphics.drawRect(left, bottom, width, height); |
1044 |
} |
} |
1045 |
|
|
1477 |
*/ |
*/ |
1478 |
public void onRenderingCompleted(final long l) { |
public void onRenderingCompleted(final long l) { |
1479 |
lastRenderingDuration = (lastRenderingDuration + l) / 2; |
lastRenderingDuration = (lastRenderingDuration + l) / 2; |
1480 |
// LOGGER |
// LOGGER |
1481 |
// .debug("complete rendering after " + lastRenderingDuration |
// .debug("complete rendering after " + lastRenderingDuration |
1482 |
// + "ms"); |
// + "ms"); |
1483 |
|
|
1484 |
repaintTimer.stop(); |
repaintTimer.stop(); |
1485 |
|
|
1695 |
* the current map pane extent (screen units) |
* the current map pane extent (screen units) |
1696 |
*/ |
*/ |
1697 |
private void resetTransforms() { |
private void resetTransforms() { |
|
final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea, |
|
|
getMapContext().getCoordinateReferenceSystem()); |
|
|
|
|
1698 |
// System.out |
// System.out |
1699 |
// .println("paintArea in resetTeansofrms = " + getVisibleRect()); |
// .println("paintArea in resetTeansofrms = " + getVisibleRect()); |
1700 |
if (!isWellDefined()) |
if (!isWellDefined()) |
1701 |
return; |
return; |
1702 |
|
|
1703 |
|
if (mapArea == null) |
1704 |
|
return; |
1705 |
|
|
1706 |
|
final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea, |
1707 |
|
getMapContext().getCoordinateReferenceSystem()); |
1708 |
|
|
1709 |
worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv, |
worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv, |
1710 |
getVisibleRect()); |
getVisibleRect()); |
1711 |
|
|
1995 |
* |
* |
1996 |
* @param state |
* @param state |
1997 |
*/ |
*/ |
1998 |
|
@Deprecated |
1999 |
public void setState(final int state) { |
public void setState(final int state) { |
2000 |
this.state = state; |
this.state = state; |
2001 |
|
|
2002 |
zoomMapPaneMouseListener.setEnabled((state == ZOOM_IN |
// throw new RuntimeException("Old concept.. migrate to new concept!"); |
2003 |
|| state == ZOOM_OUT || state == PAN)); |
|
2004 |
|
// xMapPaneMouseListener.setEnabled((state == ZOOM_IN |
2005 |
|
// || state == ZOOM_OUT || state == PAN)); |
2006 |
|
|
2007 |
// Je nach Aktion den Cursor umsetzen |
// Je nach Aktion den Cursor umsetzen |
2008 |
updateCursor(); |
updateCursor(); |
2009 |
} |
} |
2010 |
|
|
2011 |
|
public void configureMouse(MouseInputType type, XMapPaneAction action) { |
2012 |
|
xMapPaneMouseListener.actions.put(type, action); |
2013 |
|
} |
2014 |
|
|
2015 |
/** |
/** |
2016 |
* Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion (Zoom, |
* Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion (Zoom, |
2017 |
* Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor |
* Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor |
2476 |
return localRenderer; |
return localRenderer; |
2477 |
} |
} |
2478 |
|
|
|
|
|
|
|
|
2479 |
/** |
/** |
2480 |
* Setzt den Kartenausschnitt auf die Ausdehnung eines bestimmten Layers. |
* Setzt den Kartenausschnitt auf die Ausdehnung eines bestimmten Layers. |
2481 |
* Macht nichts, wenn {@code null} uebergeben wird. |
* Macht nichts, wenn {@code null} uebergeben wird. |
2605 |
zoomToLayer(getMapContext().getLayerCount() - 1 - index); |
zoomToLayer(getMapContext().getLayerCount() - 1 - index); |
2606 |
} |
} |
2607 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2608 |
/** |
/** |
2609 |
* Aktiviert oder deaktiviert das AntiAliasing for diese |
* Aktiviert oder deaktiviert das AntiAliasing for diese |
2610 |
* {@link SelectableXMapPane}. AntiALiasing ist besonders fuer |
* {@link SelectableXMapPane}. AntiALiasing ist besonders fuer |
2619 |
if (java2DHints == null) { |
if (java2DHints == null) { |
2620 |
java2DHints = GeoTools.getDefaultHints(); |
java2DHints = GeoTools.getDefaultHints(); |
2621 |
} |
} |
2622 |
|
|
2623 |
java2DHints.put(RenderingHints.KEY_ANTIALIASING, |
java2DHints.put(RenderingHints.KEY_ANTIALIASING, |
2624 |
aa ? RenderingHints.VALUE_ANTIALIAS_ON |
aa ? RenderingHints.VALUE_ANTIALIAS_ON |
2625 |
: RenderingHints.VALUE_ANTIALIAS_OFF); |
: RenderingHints.VALUE_ANTIALIAS_OFF); |
2629 |
java2DHints.put(RenderingHints.KEY_RENDERING, |
java2DHints.put(RenderingHints.KEY_RENDERING, |
2630 |
aa ? RenderingHints.VALUE_RENDER_QUALITY |
aa ? RenderingHints.VALUE_RENDER_QUALITY |
2631 |
: RenderingHints.VALUE_RENDER_SPEED); |
: RenderingHints.VALUE_RENDER_SPEED); |
2632 |
|
|
2633 |
} |
} |
2634 |
|
|
2635 |
} |
} |