395 |
* While dragging, the {@link #updateFinalImage()} method is translating the |
* While dragging, the {@link #updateFinalImage()} method is translating the |
396 |
* cached images while setting it together. |
* cached images while setting it together. |
397 |
**/ |
**/ |
398 |
Point imageOrigin = new Point(0, 0); |
private final Point imageOrigin = new Point(0, 0); |
399 |
/** |
/** |
400 |
* For every rendering thread started, |
* For every rendering thread started, |
401 |
* {@link GTUtil#createGTRenderer(MapContext)} is called to create a new |
* {@link GTUtil#createGTRenderer(MapContext)} is called to create a new |
643 |
XMapPaneAction.ZOOM_OUT); |
XMapPaneAction.ZOOM_OUT); |
644 |
|
|
645 |
xMapPaneMouseListener.actions.put(MouseInputType.RDrag, |
xMapPaneMouseListener.actions.put(MouseInputType.RDrag, |
646 |
XMapPaneAction.ZOOM_OUT); |
XMapPaneAction.PAN); |
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 |
1378 |
} |
} |
1379 |
|
|
1380 |
/** |
/** |
1381 |
* 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. |
|
1382 |
* |
* |
1383 |
* @param startPos |
* @param startPos |
1384 |
* in screen coordinates |
* in screen coordinates |
1385 |
* @param lastPos |
* @param lastPos |
1386 |
* in screen coordinates |
* in screen coordinates |
|
* @param event |
|
|
* the {@link MouseEvent} to read the mouse buttons from |
|
1387 |
*/ |
*/ |
1388 |
public void mouseDragged(final Point startPos, final Point lastPos, |
public void pan(final int dX, final int dY) { |
|
final MouseEvent event) { |
|
1389 |
|
|
1390 |
if ((getState() == XMapPane.PAN) |
// if ((getState() == XMapPane.PAN) |
1391 |
|| ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) { |
// || ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) { |
1392 |
|
|
1393 |
// Panning needs a panning coursor |
// Panning needs a panning coursor |
1394 |
if (getCursor() != SwingUtil.PANNING_CURSOR) { |
if (getCursor() != SwingUtil.PANNING_CURSOR) { |
1395 |
setCursor(SwingUtil.PANNING_CURSOR); |
setCursor(SwingUtil.PANNING_CURSOR); |
1396 |
|
|
1397 |
// While panning, we deactivate the rendering. So the tasks are |
// While panning, we deactivate the rendering. So the tasks are |
1398 |
// ready to start when the panning is finished. |
// ready to start when the panning is finished. |
1399 |
if (bgExecuter != null && bgExecuter.isRunning()) |
if (bgExecuter != null && bgExecuter.isRunning()) |
1400 |
bgExecuter.cancelTask(); |
bgExecuter.cancelTask(); |
1401 |
if (localExecuter.isRunning()) |
if (localExecuter.isRunning()) |
1402 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
1403 |
} |
} |
1404 |
|
// |
1405 |
if (lastPos.x > 0 && lastPos.y > 0) { |
// if (lastPos.x > 0 && lastPos.y > 0) { |
1406 |
final int dx = event.getX() - lastPos.x; |
// final int dx = event.getX() - lastPos.x; |
1407 |
final int dy = event.getY() - lastPos.y; |
// final int dy = event.getY() - lastPos.y; |
1408 |
|
|
1409 |
// TODO Stop dragging when the drag would not be valid... |
// TODO Stop dragging when the drag would not be valid... |
1410 |
// boolean dragValid = true; |
// boolean dragValid = true; |
1411 |
// // check if this panning results in a valid mapArea |
// // check if this panning results in a valid mapArea |
1412 |
// { |
// { |
1413 |
// Rectangle winBounds = xMapPane.getBounds(); |
// Rectangle winBounds = xMapPane.getBounds(); |
1414 |
// winBounds.translate(xMapPane.imageOrigin.x, |
// winBounds.translate(xMapPane.imageOrigin.x, |
1415 |
// -xMapPane.imageOrigin.y); |
// -xMapPane.imageOrigin.y); |
1416 |
// Envelope newMapAreaBefore = xMapPane.tranformWindowToGeo( |
// Envelope newMapAreaBefore = xMapPane.tranformWindowToGeo( |
1417 |
// winBounds.x, winBounds.y, winBounds.x |
// winBounds.x, winBounds.y, winBounds.x |
1418 |
// + winBounds.width, winBounds.y |
// + winBounds.width, winBounds.y |
1419 |
// + winBounds.height); |
// + winBounds.height); |
1420 |
// |
// |
1421 |
// |
// |
1422 |
// winBounds = xMapPane.getBounds(); |
// winBounds = xMapPane.getBounds(); |
1423 |
// Point testIng = new Point(xMapPane.imageOrigin); |
// Point testIng = new Point(xMapPane.imageOrigin); |
1424 |
// testIng.translate(dx, dy); |
// testIng.translate(dx, dy); |
1425 |
// winBounds.translate(testIng.x, -testIng.y); |
// winBounds.translate(testIng.x, -testIng.y); |
1426 |
// Envelope newMapAreaAfter = xMapPane.tranformWindowToGeo( |
// Envelope newMapAreaAfter = xMapPane.tranformWindowToGeo( |
1427 |
// winBounds.x, winBounds.y, winBounds.x |
// winBounds.x, winBounds.y, winBounds.x |
1428 |
// + winBounds.width, winBounds.y |
// + winBounds.width, winBounds.y |
1429 |
// + winBounds.height); |
// + winBounds.height); |
1430 |
// |
// |
1431 |
// // If the last drag doesn't change the MapArea anymore cancel |
// // If the last drag doesn't change the MapArea anymore cancel |
1432 |
// it. |
// it. |
1433 |
// if (xMapPane.bestAllowedMapArea(newMapAreaAfter).equals( |
// if (xMapPane.bestAllowedMapArea(newMapAreaAfter).equals( |
1434 |
// xMapPane.bestAllowedMapArea(newMapAreaBefore))){ |
// xMapPane.bestAllowedMapArea(newMapAreaBefore))){ |
1435 |
// dragValid = false; |
// dragValid = false; |
1436 |
// return; |
// return; |
1437 |
// } |
// } |
1438 |
// } |
// } |
1439 |
|
|
1440 |
imageOrigin.translate(dx, dy); |
getImageOrigin().translate(dX, dY); |
1441 |
updateFinalImage(); |
updateFinalImage(); |
1442 |
repaint(); |
repaint(); |
1443 |
} |
// } |
1444 |
|
|
1445 |
} else if ((getState() == XMapPane.ZOOM_IN) |
// } else if ((getState() == XMapPane.ZOOM_IN) |
1446 |
|| (getState() == XMapPane.ZOOM_OUT) |
// || (getState() == XMapPane.ZOOM_OUT) |
1447 |
|| (getState() == XMapPane.SELECT_ALL) |
// || (getState() == XMapPane.SELECT_ALL) |
1448 |
|| (getState() == XMapPane.SELECT_TOP)) { |
// || (getState() == XMapPane.SELECT_TOP)) { |
1449 |
|
// |
1450 |
// Draws a rectangle |
// // Draws a rectangle |
1451 |
final Graphics2D graphics = (Graphics2D) getGraphics(); |
// final Graphics2D graphics = (Graphics2D) getGraphics(); |
1452 |
drawRectangle(graphics, startPos, event.getPoint()); |
// drawRectangle(graphics, startPos, event.getPoint()); |
1453 |
if ((lastPos.x > 0) && (lastPos.y > 0)) |
// if ((lastPos.x > 0) && (lastPos.y > 0)) |
1454 |
drawRectangle(graphics, startPos, lastPos); |
// drawRectangle(graphics, startPos, lastPos); |
1455 |
graphics.dispose(); |
// graphics.dispose(); |
1456 |
} |
// } |
1457 |
} |
} |
1458 |
|
|
1459 |
/** |
/** |
1615 |
} |
} |
1616 |
|
|
1617 |
} |
} |
1618 |
|
// |
1619 |
/** |
// /** |
1620 |
* Performs a {@value #PAN} action. During panning, the displacement is |
// * Performs a {@value #PAN} action. During panning, the displacement is |
1621 |
* stored in {@link #imageOrigin} object. Calling {@link #performPan()} will |
// * stored in {@link #imageOrigin} object. Calling {@link #performPan()} will |
1622 |
* reset the offset and call {@link #setMapArea(Envelope)}. |
// * reset the offset and call {@link #setMapArea(Envelope)}. |
1623 |
*/ |
// */ |
1624 |
public void performPan() { |
// public void performPan() { |
1625 |
|
// |
1626 |
final Rectangle winBounds = getVisibleRect(); |
// final Rectangle winBounds = getVisibleRect(); |
1627 |
|
// |
1628 |
winBounds.translate(-imageOrigin.x, -imageOrigin.y); |
// winBounds.translate(-imageOrigin.x, -imageOrigin.y); |
1629 |
final Envelope newMapArea = tranformWindowToGeo(winBounds.x, |
// final Envelope newMapArea = tranformWindowToGeo(winBounds.x, |
1630 |
winBounds.y, winBounds.x + winBounds.width, winBounds.y |
// winBounds.y, winBounds.x + winBounds.width, winBounds.y |
1631 |
+ winBounds.height); |
// + winBounds.height); |
1632 |
|
// |
1633 |
imageOrigin.x = 0; |
// imageOrigin.x = 0; |
1634 |
imageOrigin.y = 0; |
// imageOrigin.y = 0; |
1635 |
|
// |
1636 |
if (!setMapArea(newMapArea)) { |
// if (!setMapArea(newMapArea)) { |
1637 |
/** |
// /** |
1638 |
* If setMapArea returns true, the finalImage is updated anyways. |
// * If setMapArea returns true, the finalImage is updated anyways. |
1639 |
* This if-case exists to ensure that we repaint a correct image |
// * This if-case exists to ensure that we repaint a correct image |
1640 |
* even if the new panning area has been denied. |
// * even if the new panning area has been denied. |
1641 |
*/ |
// */ |
1642 |
updateFinalImage(); |
// updateFinalImage(); |
1643 |
repaint(); |
// repaint(); |
1644 |
} |
// } |
1645 |
|
// |
1646 |
if (getCursor() == SwingUtil.PANNING_CURSOR) |
// if (getCursor() == SwingUtil.PANNING_CURSOR) |
1647 |
setCursor(SwingUtil.PAN_CURSOR); |
// setCursor(SwingUtil.PAN_CURSOR); |
1648 |
} |
// } |
1649 |
|
|
1650 |
/** |
/** |
1651 |
* Entfernt einen Listener von der Map. |
* Entfernt einen Listener von der Map. |
2225 |
|
|
2226 |
final Graphics2D finalG = getFinalImage().createGraphics(); |
final Graphics2D finalG = getFinalImage().createGraphics(); |
2227 |
finalG.setBackground(getMapBackgroundColor()); |
finalG.setBackground(getMapBackgroundColor()); |
2228 |
finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y, |
finalG.drawImage(getPreFinalImage(), getImageOrigin().x, getImageOrigin().y, |
2229 |
getMapBackgroundColor(), null); |
getMapBackgroundColor(), null); |
2230 |
|
|
2231 |
// When panning, we have to clear the area around the image |
// When panning, we have to clear the area around the image |
2232 |
final Rectangle painedArea = new Rectangle(imageOrigin.x, |
final Rectangle painedArea = new Rectangle(getImageOrigin().x, |
2233 |
imageOrigin.y, getFinalImage().getWidth(), getFinalImage() |
getImageOrigin().y, getFinalImage().getWidth(), getFinalImage() |
2234 |
.getHeight()); |
.getHeight()); |
2235 |
SwingUtil.clearAround(finalG, painedArea, getVisibleRect(), |
SwingUtil.clearAround(finalG, painedArea, getVisibleRect(), |
2236 |
getMapBackgroundColor()); |
getMapBackgroundColor()); |
2237 |
|
|
2238 |
addGadgets(finalG, false); |
// addGadgets(finalG, false); |
2239 |
|
|
2240 |
finalG.dispose(); |
finalG.dispose(); |
2241 |
|
|
2628 |
|
|
2629 |
} |
} |
2630 |
|
|
2631 |
|
public Point getImageOrigin() { |
2632 |
|
return imageOrigin; |
2633 |
|
} |
2634 |
|
|
2635 |
} |
} |