Skip to content

Commit

Permalink
MapView: Allow public access to paintLayer.
Browse files Browse the repository at this point in the history
This allows plugins like the areaselector to access the drawing code of the map view.

See JOSM/areaselector#25



git-svn-id: http://josm.openstreetmap.de/svn/trunk@11226 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
michael2402 committed Nov 8, 2016
1 parent 8a8c244 commit 2803122
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/org/openstreetmap/josm/gui/MapView.java
Expand Up @@ -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) {
Expand All @@ -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();
}
}

Expand Down Expand Up @@ -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
Expand All @@ -492,15 +498,15 @@ 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
if (nonChangedLayers.size() != nonChangedLayersCount) {
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);
}
}
}
Expand All @@ -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();
}
Expand Down

0 comments on commit 2803122

Please sign in to comment.