295 |
}; |
}; |
296 |
|
|
297 |
/** |
/** |
298 |
* compass and icon are rendered into this image |
* This {@link RenderingExecutor} manages the creation and cancellation of |
299 |
|
* up to one {@link Thread} for rendering the {@link #localContext}. |
300 |
*/ |
*/ |
301 |
// protected BufferedImage gadgetsImage; |
private final RenderingExecutor localExecuter = new RenderingExecutor(this); |
302 |
|
|
303 |
|
/** |
304 |
|
* This {@link RenderingExecutor} manages the creation and cancellation of |
305 |
|
* up to one {@link Thread} for rendering the {@link #bgContext}. |
306 |
|
*/ |
307 |
protected RenderingExecutor bgExecuter; |
protected RenderingExecutor bgExecuter; |
308 |
|
|
309 |
/** |
/** |
310 |
* The Renderer for the LocalLayers uses this Image. When set to null, |
* The {@link #localRenderer} for the {@link #localContext} uses this |
311 |
* please dispose this {@link Graphics2D} |
* {@link Image}. |
312 |
*/ |
*/ |
313 |
private BufferedImage localImage; |
private BufferedImage localImage; |
314 |
|
|
|
private BufferedImage finalImage; |
|
315 |
/** |
/** |
316 |
* If # {@link #bgExecuter} is using {@link #bgRenderer} for the Background |
* The {@link #bgRenderer} for the {@link #bgContext} uses this |
317 |
* uses this Image. When set to null, please dispose the {@link Graphics2D} |
* {@link Image}. |
318 |
*/ |
*/ |
319 |
private BufferedImage bgImage; |
private BufferedImage bgImage; |
320 |
|
|
321 |
|
/** |
322 |
|
* This {@link Image} is a merge of the {@link #bgImage}, |
323 |
|
* {@link #localImage} and {@link #addGadgets(Graphics2D, boolean)}. It is |
324 |
|
* updated with {@link #updateFinalImage()} and used for painting in |
325 |
|
* {@link #paintComponent(Graphics)} |
326 |
|
*/ |
327 |
|
private BufferedImage finalImage; |
328 |
|
|
329 |
|
|
330 |
/** |
/** |
331 |
* Optionally a transparent image to paint over the map in the lower right |
* Optionally a transparent image to paint over the map in the lower right |
344 |
|
|
345 |
@Override |
@Override |
346 |
public void layerChanged(final MapLayerEvent event) { |
public void layerChanged(final MapLayerEvent event) { |
|
// Change of SLD for example |
|
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
347 |
requestStartRendering(); |
requestStartRendering(); |
348 |
} |
} |
349 |
|
|
350 |
@Override |
@Override |
351 |
public void layerHidden(final MapLayerEvent event) { |
public void layerHidden(final MapLayerEvent event) { |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
352 |
requestStartRendering(); |
requestStartRendering(); |
353 |
} |
} |
354 |
|
|
355 |
@Override |
@Override |
356 |
public void layerShown(final MapLayerEvent event) { |
public void layerShown(final MapLayerEvent event) { |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
357 |
requestStartRendering(); |
requestStartRendering(); |
358 |
} |
} |
359 |
}; |
}; |
435 |
} |
} |
436 |
}; |
}; |
437 |
|
|
|
private final RenderingExecutor localExecuter = new RenderingExecutor(this); |
|
|
|
|
438 |
/** |
/** |
439 |
* Listens to each layer in the local {@link MapContext} for changes and |
* Listens to each layer in the local {@link MapContext} for changes and |
440 |
* triggers repaints. |
* triggers repaints. |
540 |
private Map<Object, Object> rendererHints = GTUtil |
private Map<Object, Object> rendererHints = GTUtil |
541 |
.getDefaultGTRendererHints(localRenderer); |
.getDefaultGTRendererHints(localRenderer); |
542 |
|
|
543 |
private volatile Boolean requestStartRendering = false; |
/** If set to <code>true</code>, the {@link #startRenderThreadsTimer} will start rendering a new {@link #localImage} **/ |
544 |
|
private volatile Boolean requestStartRenderingLocal = false; |
545 |
|
|
546 |
|
/** If set to <code>true</code>, the {@link #startRenderThreadsTimer} will start rendering a new {@link #bgImage} **/ |
547 |
|
private volatile Boolean requestStartRenderingBg = false; |
548 |
|
|
549 |
private final Timer resizeTimer; |
private final Timer resizeTimer; |
550 |
|
|
555 |
protected AffineTransform screenToWorld = null; |
protected AffineTransform screenToWorld = null; |
556 |
|
|
557 |
/** |
/** |
558 |
* The flag {@link #requestStartRendering} can be set to true by events. |
* The flag {@link #requestStartRenderingLocal} can be set to true by events. |
559 |
* This {@link Timer} checks the flag regularly and starts one renderer |
* This {@link Timer} checks the flag regularly and starts one renderer |
560 |
* thread. |
* thread. |
561 |
*/ |
*/ |
584 |
/** Is set if a renderer has an error **/ |
/** Is set if a renderer has an error **/ |
585 |
protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>(); |
protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>(); |
586 |
|
|
|
// TODO doku |
|
587 |
public XMapPane() { |
public XMapPane() { |
588 |
this(null, null); |
this(null, null); |
589 |
} |
} |
592 |
* full constructor extending JPanel |
* full constructor extending JPanel |
593 |
* |
* |
594 |
* @param rendererHints |
* @param rendererHints |
595 |
|
* may be <code>null</code>. Otherwise a {@link Map<Object, |
596 |
|
* Object>} of {@link RenderingHints} to override the default |
597 |
|
* from {@link GTUtil#getDefaultGTRendererHints(GTRenderer)} |
598 |
* |
* |
|
* @param layout |
|
|
* - layout (probably shouldn't be set) |
|
|
* @param isDoubleBuffered |
|
|
* - a Swing thing I don't really understand |
|
|
* @param render |
|
|
* - what to draw the map with |
|
599 |
* @param localContext |
* @param localContext |
600 |
* - {@link MapContext} of layer to render. |
* The main {@link MapContext} to use. If <code>null</code>, an |
601 |
|
* empty {@link DefaultMapContext} will be created. |
602 |
*/ |
*/ |
603 |
public XMapPane(final MapContext localContext_, |
public XMapPane(final MapContext localContext_, |
604 |
final Map<Object, Object> rendererHints) { |
final Map<Object, Object> rendererHints) { |
625 |
* Using a ComponentListener doesn't work because, unlike a JFrame, the |
* Using a ComponentListener doesn't work because, unlike a JFrame, the |
626 |
* pane receives a stream of events during drag-resizing. |
* pane receives a stream of events during drag-resizing. |
627 |
*/ |
*/ |
628 |
resizeTimer = new Timer(DEFAULT_RESIZING_PAINT_DELAY, new ActionListener() { |
resizeTimer = new Timer(DEFAULT_RESIZING_PAINT_DELAY, |
629 |
|
new ActionListener() { |
630 |
|
|
631 |
public void actionPerformed(final ActionEvent e) { |
public void actionPerformed(final ActionEvent e) { |
632 |
paneResized = true; |
paneResized = true; |
633 |
|
|
634 |
if (!isWellDefined()) |
if (!isWellDefined()) |
635 |
return; |
return; |
636 |
|
|
637 |
final Rectangle bounds = getVisibleRect(); |
final Rectangle bounds = getVisibleRect(); |
638 |
|
|
639 |
final Envelope geoMapArea = tranformWindowToGeo(bounds.x, |
final Envelope geoMapArea = tranformWindowToGeo( |
640 |
bounds.y, bounds.x + bounds.width, bounds.y |
bounds.x, bounds.y, bounds.x + bounds.width, |
641 |
+ bounds.height); |
bounds.y + bounds.height); |
642 |
|
|
643 |
setMapArea(bestAllowedMapArea(geoMapArea)); |
setMapArea(bestAllowedMapArea(geoMapArea)); |
644 |
} |
} |
645 |
}); |
}); |
646 |
resizeTimer.setRepeats(false); |
resizeTimer.setRepeats(false); |
647 |
this.addComponentListener(new ComponentAdapter() { |
|
648 |
|
// this.addComponentListener(new ComponentAdapter() { |
649 |
@Override |
// |
650 |
public void componentResized(final ComponentEvent e) { |
// @Override |
651 |
if (bgExecuter != null) |
// public void componentResized(final ComponentEvent e) { |
652 |
bgExecuter.cancelTask(); |
// if (bgExecuter != null) |
653 |
if (localExecuter != null) |
// bgExecuter.cancelTask(); |
654 |
localExecuter.cancelTask(); |
// if (localExecuter != null) |
655 |
resizeTimer.restart(); |
// localExecuter.cancelTask(); |
656 |
} |
// resizeTimer.restart(); |
657 |
|
// } |
658 |
}); |
// |
659 |
|
// }); |
660 |
|
|
661 |
/* |
/* |
662 |
* Setting up the repaintTimer. Not started automatically. |
* Setting up the repaintTimer. Not started automatically. |
681 |
|
|
682 |
@Override |
@Override |
683 |
public void actionPerformed(final ActionEvent e) { |
public void actionPerformed(final ActionEvent e) { |
684 |
synchronized (requestStartRendering) { |
synchronized (requestStartRenderingLocal) { |
685 |
if (requestStartRendering && isWellDefined()) { |
if (requestStartRenderingLocal && isWellDefined()) { |
686 |
|
|
687 |
if (localExecuter.isRunning()) { |
if (localExecuter.isRunning()) { |
688 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
689 |
} else { |
} else { |
690 |
requestStartRendering = false; |
requestStartRenderingLocal = false; |
691 |
startRendering(); |
startRendering(); |
692 |
} |
} |
693 |
} |
} |
801 |
|
|
802 |
// LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
803 |
|
|
804 |
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, |
newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea, |
805 |
false); |
false); |
806 |
} |
} |
807 |
} |
} |
825 |
|
|
826 |
// LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
827 |
|
|
828 |
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, |
newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea, |
829 |
false); |
false); |
830 |
} |
} |
831 |
} |
} |
851 |
|
|
852 |
// LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
853 |
|
|
854 |
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, |
newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea, |
855 |
false); |
false); |
856 |
} |
} |
857 |
} |
} |
877 |
|
|
878 |
// LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
879 |
|
|
880 |
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, |
newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea, |
881 |
false); |
false); |
882 |
} |
} |
883 |
} |
} |
916 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
917 |
while (i++ < 10 && localExecuter.isRunning()) { |
while (i++ < 10 && localExecuter.isRunning()) { |
918 |
try { |
try { |
919 |
Thread.sleep(100); |
Thread.sleep(200); |
920 |
} catch (final InterruptedException e) { |
} catch (final InterruptedException e) { |
921 |
// TODO Auto-generated catch block |
LOGGER |
922 |
e.printStackTrace(); |
.warn( |
923 |
|
"while XMapPane we are waiting for the localExcutor to stop", |
924 |
|
e); |
925 |
} |
} |
926 |
} |
} |
927 |
if (localExecuter.isRunning()) { |
if (localExecuter.isRunning()) { |
928 |
System.out |
LOGGER |
929 |
.println("BAD BAD BAD... still running the thread...."); |
.warn("localExecutor Thread still running after 2s! Continuing anyways..."); |
930 |
} |
} |
931 |
localExecuter.dispose(); |
localExecuter.dispose(); |
932 |
} |
} |
933 |
|
|
934 |
disposeImages(); |
disposeImages(); |
935 |
|
|
936 |
// LangUtil.gcTotal(); |
// Remove all mapPaneListeners that have registered with us |
|
|
|
|
// Alle mapPaneListener entfernen |
|
937 |
mapPaneListeners.clear(); |
mapPaneListeners.clear(); |
938 |
|
|
939 |
removeMouseMotionListener(zoomMapPaneMouseListener); |
removeMouseMotionListener(zoomMapPaneMouseListener); |
986 |
*/ |
*/ |
987 |
protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) { |
protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) { |
988 |
|
|
989 |
if (1 == 1)return false; |
// if (1 == 1)return false; |
990 |
|
|
991 |
if (quickPreviewHint == 0) |
if (quickPreviewHint == 0) |
992 |
return false; |
return false; |
993 |
|
|
1062 |
// |
// |
1063 |
if (finalImage == null) { |
if (finalImage == null) { |
1064 |
// Rectangle curPaintArea = getVisibleRect(); |
// Rectangle curPaintArea = getVisibleRect(); |
1065 |
finalImage = new BufferedImage(getBounds().width, |
finalImage = new BufferedImage(getVisibleRect().width, |
1066 |
getBounds().height, IMAGETYPE); |
getVisibleRect().height, IMAGETYPE); |
1067 |
|
|
1068 |
requestStartRendering(); |
requestStartRendering(); |
1069 |
} |
} |
1080 |
private BufferedImage getLocalImage() { |
private BufferedImage getLocalImage() { |
1081 |
|
|
1082 |
if (localImage == null) { |
if (localImage == null) { |
1083 |
localImage = new BufferedImage(getBounds().width, |
localImage = new BufferedImage(getVisibleRect().width, |
1084 |
getBounds().height, IMAGETYPE_withAlpha); |
getVisibleRect().height, IMAGETYPE_withAlpha); |
1085 |
} |
} |
1086 |
|
|
1087 |
return localImage; |
return localImage; |
1162 |
} |
} |
1163 |
|
|
1164 |
// Kartenbereich um 10% vergroessern |
// Kartenbereich um 10% vergroessern |
1165 |
return JTSUtil.fixAspectRatio(this.getBounds(), JTSUtil |
return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil |
1166 |
.expandEnvelope(layerBounds, 0.1), true); |
.expandEnvelope(layerBounds, 0.1), true); |
1167 |
} |
} |
1168 |
return maxExtend; |
return maxExtend; |
1526 |
*/ |
*/ |
1527 |
public void performPan() { |
public void performPan() { |
1528 |
|
|
1529 |
final Rectangle winBounds = getBounds(); |
Rectangle winBounds = getVisibleRect(); |
1530 |
|
|
1531 |
winBounds.translate(-imageOrigin.x, -imageOrigin.y); |
winBounds.translate(-imageOrigin.x, -imageOrigin.y); |
1532 |
final Envelope newMapArea = tranformWindowToGeo(winBounds.x, |
final Envelope newMapArea = tranformWindowToGeo(winBounds.x, |
1533 |
winBounds.y, winBounds.x + winBounds.width, winBounds.y |
winBounds.y, winBounds.x + winBounds.width, winBounds.y |
1592 |
bgExecuter.cancelTask(); |
bgExecuter.cancelTask(); |
1593 |
if (localExecuter != null) |
if (localExecuter != null) |
1594 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
1595 |
requestStartRendering = true; |
requestStartRenderingLocal = true; |
1596 |
|
|
1597 |
} |
} |
1598 |
|
|
1650 |
private void resetTransforms() { |
private void resetTransforms() { |
1651 |
ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea, |
ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea, |
1652 |
getContext().getCoordinateReferenceSystem()); |
getContext().getCoordinateReferenceSystem()); |
1653 |
// |
|
1654 |
Rectangle paintArea = getBounds(); |
Rectangle paintArea = getVisibleRect(); // NOT USE GET BOUNDS! |
1655 |
|
|
|
if (!getBounds().equals(getVisibleRect())) { |
|
|
System.out.println("did we expect that?"); |
|
|
} |
|
1656 |
// |
// |
1657 |
// double xscale = paintArea.getWidth() / refEnv.getWidth(); |
// double xscale = paintArea.getWidth() / refEnv.getWidth(); |
1658 |
// double yscale = paintArea.getHeight() / refEnv.getHeight(); |
// double yscale = paintArea.getHeight() / refEnv.getHeight(); |
2003 |
if (submitted) |
if (submitted) |
2004 |
repaintTimer.restart(); |
repaintTimer.restart(); |
2005 |
else |
else |
2006 |
requestStartRendering = true; // Try to start rendering again in |
requestStartRenderingLocal = true; // Try to start rendering again in |
2007 |
// a moment |
// a moment |
2008 |
} |
} |
2009 |
|
|
2056 |
final AffineTransform at = getScreenToWorld(); |
final AffineTransform at = getScreenToWorld(); |
2057 |
final Point2D geoO = at.transform(new Point2D.Double(ox, oy), null); |
final Point2D geoO = at.transform(new Point2D.Double(ox, oy), null); |
2058 |
final Point2D geoP = at.transform(new Point2D.Double(px, py), null); |
final Point2D geoP = at.transform(new Point2D.Double(px, py), null); |
2059 |
|
|
2060 |
// Mmmmm... don't really understand why its x,x,y,y |
// Mmmmm... don't really understand why its x,x,y,y |
2061 |
// return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY()); |
// return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), |
2062 |
return new Envelope( new Coordinate(geoO.getX(), geoO.getY()), new Coordinate(geoP.getX(), geoP.getY())); |
// geoP.getY()); |
2063 |
|
return new Envelope(new Coordinate(geoO.getX(), geoO.getY()), |
2064 |
|
new Coordinate(geoP.getX(), geoP.getY())); |
2065 |
} |
} |
2066 |
|
|
2067 |
/** |
/** |
2177 |
|
|
2178 |
// Paint a logo to the bottom right if available |
// Paint a logo to the bottom right if available |
2179 |
if (mapImage != null) { |
if (mapImage != null) { |
2180 |
graphics.drawImage(mapImage, getBounds().width |
Rectangle visibleRect = getVisibleRect(); |
2181 |
- mapImage.getWidth() - 10, getBounds().height |
graphics.drawImage(mapImage, visibleRect.width |
2182 |
|
- mapImage.getWidth() - 10, getVisibleRect().height |
2183 |
- mapImage.getHeight() - 10, null); |
- mapImage.getHeight() - 10, null); |
2184 |
} |
} |
2185 |
|
|
2358 |
newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea |
newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea |
2359 |
.getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea |
.getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea |
2360 |
.getHeight()) / 2.); |
.getHeight()) / 2.); |
2361 |
|
|
2362 |
// TODO we actually want that |
// TODO we actually want that |
2363 |
// // Move the newMapArea above the new center |
// // Move the newMapArea above the new center |
2364 |
// newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter |
// newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter |
2365 |
// .getY() |
// .getY() |
2366 |
// - mapArea.centre().y); |
// - mapArea.centre().y); |
2367 |
|
|
2368 |
setMapArea(newMapArea); |
setMapArea(newMapArea); |
2369 |
} |
} |