From 2803122626650b798931f95d67a20994f4569dee Mon Sep 17 00:00:00 2001 From: michael2402 Date: Tue, 8 Nov 2016 23:27:35 +0000 Subject: [PATCH] MapView: Allow public access to paintLayer. This allows plugins like the areaselector to access the drawing code of the map view. See https://github.com/JOSM/areaselector/issues/25 git-svn-id: http://josm.openstreetmap.de/svn/trunk@11226 0c6e7542-c601-0410-84e7-c038aed88b3b --- src/org/openstreetmap/josm/gui/MapView.java | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/org/openstreetmap/josm/gui/MapView.java b/src/org/openstreetmap/josm/gui/MapView.java index a811296bfa8..d70a3f6cc50 100644 --- a/src/org/openstreetmap/josm/gui/MapView.java +++ b/src/org/openstreetmap/josm/gui/MapView.java @@ -419,7 +419,14 @@ public void layerOrderChanged(LayerOrderChangeEvent e) { repaint(); } - private void paintLayer(Layer layer, Graphics2D g, Bounds box) { + /** + * Paints the given layer to the graphics object, using the current state of this map view. + * @param layer The layer to draw. + * @param g A graphics object. It should have the width and height of this component + * @throws IllegalArgumentException If the layer is not part of this map view. + * @since 11226 + */ + public void paintLayer(Layer layer, Graphics2D g) { try { LayerPainter painter = registeredLayers.get(layer); if (painter == null) { @@ -434,7 +441,7 @@ private void paintLayer(Layer layer, Graphics2D g, Bounds box) { painter.paint(paintGraphics); g.setPaintMode(); } catch (RuntimeException t) { - BugReport.intercept(t).put("layer", layer).put("bounds", box).warn(); + BugReport.intercept(t).put("layer", layer).warn(); } } @@ -479,7 +486,6 @@ public void paint(Graphics g) { Graphics2D tempG = offscreenBuffer.createGraphics(); tempG.setClip(g.getClip()); - Bounds box = getLatLonBounds(g.getClipBounds()); if (!canUseBuffer || nonChangedLayersBuffer == null) { if (null == nonChangedLayersBuffer @@ -492,7 +498,7 @@ public void paint(Graphics g) { g2.fillRect(0, 0, getWidth(), getHeight()); for (int i = 0; i < nonChangedLayersCount; i++) { - paintLayer(visibleLayers.get(i), g2, box); + paintLayer(visibleLayers.get(i), g2); } } else { // Maybe there were more unchanged layers then last time - draw them to buffer @@ -500,7 +506,7 @@ public void paint(Graphics g) { Graphics2D g2 = nonChangedLayersBuffer.createGraphics(); g2.setClip(g.getClip()); for (int i = nonChangedLayers.size(); i < nonChangedLayersCount; i++) { - paintLayer(visibleLayers.get(i), g2, box); + paintLayer(visibleLayers.get(i), g2); } } } @@ -513,11 +519,11 @@ public void paint(Graphics g) { tempG.drawImage(nonChangedLayersBuffer, 0, 0, null); for (int i = nonChangedLayersCount; i < visibleLayers.size(); i++) { - paintLayer(visibleLayers.get(i), tempG, box); + paintLayer(visibleLayers.get(i), tempG); } try { - drawTemporaryLayers(tempG, box); + drawTemporaryLayers(tempG, getLatLonBounds(g.getClipBounds())); } catch (RuntimeException e) { BugReport.intercept(e).put("temporaryLayers", temporaryLayers).warn(); }