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; |
104 |
// private static final int IMAGETYPE_withAlpha = |
// private static final int IMAGETYPE_withAlpha = |
105 |
// BufferedImage.TYPE_INT_ARGB; |
// BufferedImage.TYPE_INT_ARGB; |
106 |
private static final int IMAGETYPE = BufferedImage.TYPE_3BYTE_BGR; |
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; |
private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_4BYTE_ABGR; |
112 |
|
|
113 |
private final 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 |
/** |
/** |
178 |
* Flag for no-tool. |
* Flag for no-tool. |
179 |
*/ |
*/ |
180 |
public static final int NONE = -123; |
public static final int NONE = -123; |
181 |
|
// |
182 |
/** |
// /** |
183 |
* Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl |
// * Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl |
184 |
* moeglich! |
// * moeglich! |
185 |
* |
// * |
186 |
* @see #setState(int) |
// * @see #setState(int) |
187 |
*/ |
// */ |
188 |
public static final int PAN = 1; |
// public static final int PAN = 1; |
189 |
|
// |
190 |
/** |
// /** |
191 |
* Flag fuer Modus "Heran zoomen". |
// * 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 ZOOM_IN = 2; |
// public static final int ZOOM_IN = 2; |
197 |
|
// |
198 |
/** |
// /** |
199 |
* Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich! |
// * Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich! |
200 |
* |
// * |
201 |
* @see #setState(int) |
// * @see #setState(int) |
202 |
*/ |
// */ |
203 |
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; |
|
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 |
260 |
final AffineTransform at = xMapPane.getScreenToWorld(); |
final AffineTransform at = xMapPane.getScreenToWorld(); |
261 |
if (at != null) { |
if (at != null) { |
262 |
Point2D transformed = at.transform(e.getPoint(), null); |
Point2D transformed = at.transform(e.getPoint(), null); |
263 |
return new DirectPosition2D(xMapPane.getMapContext().getCoordinateReferenceSystem(), transformed.getX(), transformed.getY()); |
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( |
270 |
"MouseEvent has to be of instance MapMouseEvent or come from an XMapPane"); |
"MouseEvent has to be of instance MapMouseEvent or come from an XMapPane"); |
271 |
} |
} |
|
|
|
|
|
|
272 |
|
|
273 |
/** |
/** |
274 |
* Listens to changes of the "background" {@link MapContext} and triggers |
* Listens to changes of the "background" {@link MapContext} and triggers |
281 |
final 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 |
403 |
|
|
404 |
@Override |
@Override |
405 |
public void layerChanged(final MapLayerListEvent event) { |
public void layerChanged(final MapLayerListEvent event) { |
406 |
// getLocalRenderer().setContext(getMapContext()); geht doch auch ohne?!?!? wow... |
// getLocalRenderer().setContext(getMapContext()); geht doch auch |
407 |
|
// ohne?!?!? wow... |
408 |
requestStartRendering(); |
requestStartRendering(); |
409 |
} |
} |
410 |
|
|
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 **/ |
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. |
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 |
|
|
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 |
|
|
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) { |
1355 |
} |
} |
1356 |
|
|
1357 |
/** |
/** |
1358 |
* 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. |
|
1359 |
* |
* |
1360 |
* @param startPos |
* @param startPos |
1361 |
* in screen coordinates |
* in screen coordinates |
1362 |
* @param lastPos |
* @param lastPos |
1363 |
* in screen coordinates |
* in screen coordinates |
|
* @param event |
|
|
* the {@link MouseEvent} to read the mouse buttons from |
|
1364 |
*/ |
*/ |
1365 |
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)) { |
|
1366 |
|
|
1367 |
// Panning needs a panning coursor |
// Panning needs a panning coursor |
1368 |
if (getCursor() != SwingUtil.PANNING_CURSOR) { |
if (getCursor() != SwingUtil.PANNING_CURSOR) { |
1369 |
setCursor(SwingUtil.PANNING_CURSOR); |
setCursor(SwingUtil.PANNING_CURSOR); |
1370 |
|
|
1371 |
// While panning, we deactivate the rendering. So the tasks are |
// While panning, we deactivate the rendering. So the tasks are |
1372 |
// ready to start when the panning is finished. |
// ready to start when the panning is finished. |
1373 |
if (bgExecuter != null && bgExecuter.isRunning()) |
if (bgExecuter != null && bgExecuter.isRunning()) |
1374 |
bgExecuter.cancelTask(); |
bgExecuter.cancelTask(); |
1375 |
if (localExecuter.isRunning()) |
if (localExecuter.isRunning()) |
1376 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
1377 |
} |
} |
1378 |
|
// |
1379 |
if (lastPos.x > 0 && lastPos.y > 0) { |
// if (lastPos.x > 0 && lastPos.y > 0) { |
1380 |
final int dx = event.getX() - lastPos.x; |
// final int dx = event.getX() - lastPos.x; |
1381 |
final int dy = event.getY() - lastPos.y; |
// final int dy = event.getY() - lastPos.y; |
1382 |
|
|
1383 |
// TODO Stop dragging when the drag would not be valid... |
// TODO Stop dragging when the drag would not be valid... |
1384 |
// boolean dragValid = true; |
// boolean dragValid = true; |
1385 |
// // check if this panning results in a valid mapArea |
// // check if this panning results in a valid mapArea |
1386 |
// { |
// { |
1387 |
// Rectangle winBounds = xMapPane.getBounds(); |
// Rectangle winBounds = xMapPane.getBounds(); |
1388 |
// winBounds.translate(xMapPane.imageOrigin.x, |
// winBounds.translate(xMapPane.imageOrigin.x, |
1389 |
// -xMapPane.imageOrigin.y); |
// -xMapPane.imageOrigin.y); |
1390 |
// Envelope newMapAreaBefore = xMapPane.tranformWindowToGeo( |
// Envelope newMapAreaBefore = xMapPane.tranformWindowToGeo( |
1391 |
// winBounds.x, winBounds.y, winBounds.x |
// winBounds.x, winBounds.y, winBounds.x |
1392 |
// + winBounds.width, winBounds.y |
// + winBounds.width, winBounds.y |
1393 |
// + winBounds.height); |
// + winBounds.height); |
1394 |
// |
// |
1395 |
// |
// |
1396 |
// winBounds = xMapPane.getBounds(); |
// winBounds = xMapPane.getBounds(); |
1397 |
// Point testIng = new Point(xMapPane.imageOrigin); |
// Point testIng = new Point(xMapPane.imageOrigin); |
1398 |
// testIng.translate(dx, dy); |
// testIng.translate(dx, dy); |
1399 |
// winBounds.translate(testIng.x, -testIng.y); |
// winBounds.translate(testIng.x, -testIng.y); |
1400 |
// Envelope newMapAreaAfter = xMapPane.tranformWindowToGeo( |
// Envelope newMapAreaAfter = xMapPane.tranformWindowToGeo( |
1401 |
// winBounds.x, winBounds.y, winBounds.x |
// winBounds.x, winBounds.y, winBounds.x |
1402 |
// + winBounds.width, winBounds.y |
// + winBounds.width, winBounds.y |
1403 |
// + winBounds.height); |
// + winBounds.height); |
1404 |
// |
// |
1405 |
// // If the last drag doesn't change the MapArea anymore cancel |
// // If the last drag doesn't change the MapArea anymore cancel |
1406 |
// it. |
// it. |
1407 |
// if (xMapPane.bestAllowedMapArea(newMapAreaAfter).equals( |
// if (xMapPane.bestAllowedMapArea(newMapAreaAfter).equals( |
1408 |
// xMapPane.bestAllowedMapArea(newMapAreaBefore))){ |
// xMapPane.bestAllowedMapArea(newMapAreaBefore))){ |
1409 |
// dragValid = false; |
// dragValid = false; |
1410 |
// return; |
// return; |
1411 |
// } |
// } |
1412 |
// } |
// } |
1413 |
|
|
1414 |
imageOrigin.translate(dx, dy); |
getImageOrigin().translate(dX, dY); |
1415 |
updateFinalImage(); |
updateFinalImage(); |
1416 |
repaint(); |
repaint(); |
1417 |
} |
// } |
1418 |
|
|
1419 |
} else if ((getState() == XMapPane.ZOOM_IN) |
// } else if ((getState() == XMapPane.ZOOM_IN) |
1420 |
|| (getState() == XMapPane.ZOOM_OUT) |
// || (getState() == XMapPane.ZOOM_OUT) |
1421 |
|| (getState() == XMapPane.SELECT_ALL) |
// || (getState() == XMapPane.SELECT_ALL) |
1422 |
|| (getState() == XMapPane.SELECT_TOP)) { |
// || (getState() == XMapPane.SELECT_TOP)) { |
1423 |
|
// |
1424 |
// Draws a rectangle |
// // Draws a rectangle |
1425 |
final Graphics2D graphics = (Graphics2D) getGraphics(); |
// final Graphics2D graphics = (Graphics2D) getGraphics(); |
1426 |
drawRectangle(graphics, startPos, event.getPoint()); |
// drawRectangle(graphics, startPos, event.getPoint()); |
1427 |
if ((lastPos.x > 0) && (lastPos.y > 0)) |
// if ((lastPos.x > 0) && (lastPos.y > 0)) |
1428 |
drawRectangle(graphics, startPos, lastPos); |
// drawRectangle(graphics, startPos, lastPos); |
1429 |
graphics.dispose(); |
// graphics.dispose(); |
1430 |
} |
// } |
1431 |
} |
} |
1432 |
|
|
1433 |
/** |
/** |
1447 |
*/ |
*/ |
1448 |
public void onRenderingCompleted(final long l) { |
public void onRenderingCompleted(final long l) { |
1449 |
lastRenderingDuration = (lastRenderingDuration + l) / 2; |
lastRenderingDuration = (lastRenderingDuration + l) / 2; |
1450 |
// LOGGER |
// LOGGER |
1451 |
// .debug("complete rendering after " + lastRenderingDuration |
// .debug("complete rendering after " + lastRenderingDuration |
1452 |
// + "ms"); |
// + "ms"); |
1453 |
|
|
1454 |
repaintTimer.stop(); |
repaintTimer.stop(); |
1455 |
|
|
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 |
final 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 |
} |
// } |
1623 |
|
|
1624 |
/** |
/** |
1625 |
* Entfernt einen Listener von der Map. |
* Entfernt einen Listener von der Map. |
1665 |
* the current map pane extent (screen units) |
* the current map pane extent (screen units) |
1666 |
*/ |
*/ |
1667 |
private void resetTransforms() { |
private void resetTransforms() { |
|
final 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 |
|
|
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 = 1000; |
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 |
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 |
|
|
1976 |
// Je nach Aktion den Cursor umsetzen |
public void configureMouse(MouseInputType type, XMapPaneAction action) { |
1977 |
updateCursor(); |
xMapPaneMouseListener.actions.put(type, action); |
1978 |
} |
} |
1979 |
|
|
1980 |
/** |
/** |
1981 |
* Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion (Zoom, |
* Configure the {@link XMapPaneTool} that active on the map. Passing |
1982 |
* Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor |
* <code>null</code> will set the NO_ACTION tool. |
1983 |
* gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion |
*/ |
1984 |
* beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann |
public void setTool(XMapPaneTool tool) { |
1985 |
* {@code null} als Parameter uebergeben werden |
if (tool == null) |
1986 |
* |
tool = XMapPaneTool.NO_ACTION; |
1987 |
* @param cursor |
this.tool = tool; |
1988 |
* Cursor |
xMapPaneMouseListener.configure(tool); |
1989 |
*/ |
setCursor(tool.getCursor()); |
1990 |
public void setStaticCursor(final Cursor cursor) { |
} |
1991 |
this.staticCursor = cursor; |
|
1992 |
if (cursor != null) |
// /** |
1993 |
super.setCursor(cursor); |
// * 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 |
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 |
// When panning, we have to clear the area around the image |
// When panning, we have to clear the area around the image |
2218 |
final Rectangle painedArea = new Rectangle(imageOrigin.x, |
final Rectangle painedArea = new Rectangle(getImageOrigin().x, |
2219 |
imageOrigin.y, getFinalImage().getWidth(), getFinalImage() |
getImageOrigin().y, getFinalImage().getWidth(), getFinalImage() |
2220 |
.getHeight()); |
.getHeight()); |
2221 |
SwingUtil.clearAround(finalG, painedArea, getVisibleRect(), |
SwingUtil.clearAround(finalG, painedArea, getVisibleRect(), |
2222 |
getMapBackgroundColor()); |
getMapBackgroundColor()); |
2223 |
|
|
2224 |
addGadgets(finalG, false); |
// addGadgets(finalG, false); |
2225 |
|
|
2226 |
finalG.dispose(); |
finalG.dispose(); |
2227 |
|
|
2458 |
return localRenderer; |
return localRenderer; |
2459 |
} |
} |
2460 |
|
|
|
|
|
|
|
|
2461 |
/** |
/** |
2462 |
* Setzt den Kartenausschnitt auf die Ausdehnung eines bestimmten Layers. |
* Setzt den Kartenausschnitt auf die Ausdehnung eines bestimmten Layers. |
2463 |
* Macht nichts, wenn {@code null} uebergeben wird. |
* Macht nichts, wenn {@code null} uebergeben wird. |
2587 |
zoomToLayer(getMapContext().getLayerCount() - 1 - index); |
zoomToLayer(getMapContext().getLayerCount() - 1 - index); |
2588 |
} |
} |
2589 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2590 |
/** |
/** |
2591 |
* Aktiviert oder deaktiviert das AntiAliasing for diese |
* Aktiviert oder deaktiviert das AntiAliasing for diese |
2592 |
* {@link SelectableXMapPane}. AntiALiasing ist besonders fuer |
* {@link SelectableXMapPane}. AntiALiasing ist besonders fuer |
2601 |
if (java2DHints == null) { |
if (java2DHints == null) { |
2602 |
java2DHints = GeoTools.getDefaultHints(); |
java2DHints = GeoTools.getDefaultHints(); |
2603 |
} |
} |
2604 |
|
|
2605 |
java2DHints.put(RenderingHints.KEY_ANTIALIASING, |
java2DHints.put(RenderingHints.KEY_ANTIALIASING, |
2606 |
aa ? RenderingHints.VALUE_ANTIALIAS_ON |
aa ? RenderingHints.VALUE_ANTIALIAS_ON |
2607 |
: RenderingHints.VALUE_ANTIALIAS_OFF); |
: RenderingHints.VALUE_ANTIALIAS_OFF); |
2611 |
java2DHints.put(RenderingHints.KEY_RENDERING, |
java2DHints.put(RenderingHints.KEY_RENDERING, |
2612 |
aa ? RenderingHints.VALUE_RENDER_QUALITY |
aa ? RenderingHints.VALUE_RENDER_QUALITY |
2613 |
: RenderingHints.VALUE_RENDER_SPEED); |
: RenderingHints.VALUE_RENDER_SPEED); |
2614 |
|
|
2615 |
|
} |
2616 |
|
|
2617 |
|
public Point getImageOrigin() { |
2618 |
|
return imageOrigin; |
2619 |
} |
} |
2620 |
|
|
2621 |
} |
} |