From fa110130405252bbdbe13b8a0827a710c2016899 Mon Sep 17 00:00:00 2001
From: Robert Scott <code@humanleg.org.uk>
Date: Sat, 30 Sep 2017 14:30:06 +0100
Subject: [PATCH 2/2] SlippyMapBBoxChooser: paint extents of downloaded area in
similar style to OsmDataLayer
using a technique which is almost directly lifted therefrom.
---
.../josm/gui/bbox/SlippyMapBBoxChooser.java | 47 +++++++++++++++++++++-
1 file changed, 46 insertions(+), 1 deletion(-)
diff --git a/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java b/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java
index 6451dd8..d40041c 100644
a
|
b
|
import static org.openstreetmap.josm.tools.I18n.tr;
|
6 | 6 | import java.awt.Color; |
7 | 7 | import java.awt.Dimension; |
8 | 8 | import java.awt.Graphics; |
| 9 | import java.awt.Graphics2D; |
9 | 10 | import java.awt.Point; |
10 | 11 | import java.awt.Rectangle; |
| 12 | import java.awt.TexturePaint; |
| 13 | import java.awt.geom.Area; |
| 14 | import java.awt.geom.Path2D; |
| 15 | import java.awt.image.BufferedImage; |
11 | 16 | import java.util.ArrayList; |
12 | 17 | import java.util.Arrays; |
13 | 18 | import java.util.Collections; |
… |
… |
import org.openstreetmap.josm.data.imagery.TMSCachedTileLoader;
|
41 | 46 | import org.openstreetmap.josm.data.imagery.TileLoaderFactory; |
42 | 47 | import org.openstreetmap.josm.data.osm.BBox; |
43 | 48 | import org.openstreetmap.josm.data.preferences.StringProperty; |
| 49 | import org.openstreetmap.josm.gui.MainApplication; |
44 | 50 | import org.openstreetmap.josm.gui.layer.AbstractCachedTileSourceLayer; |
| 51 | import org.openstreetmap.josm.gui.layer.MainLayerManager; |
| 52 | import org.openstreetmap.josm.gui.layer.OsmDataLayer; |
45 | 53 | import org.openstreetmap.josm.gui.layer.TMSLayer; |
46 | 54 | import org.openstreetmap.josm.spi.preferences.Config; |
47 | 55 | import org.openstreetmap.josm.tools.Logging; |
… |
… |
import org.openstreetmap.josm.tools.Logging;
|
49 | 57 | /** |
50 | 58 | * This panel displays a map and lets the user chose a {@link BBox}. |
51 | 59 | */ |
52 | | public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser { |
| 60 | public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser, MainLayerManager.ActiveLayerChangeListener { |
53 | 61 | |
54 | 62 | /** |
55 | 63 | * A list of tile sources that can be used for displaying the map. |
… |
… |
public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser {
|
189 | 197 | iSourceButton.setCurrentMap(tileSources.get(0)); |
190 | 198 | } |
191 | 199 | |
| 200 | MainApplication.getLayerManager().addActiveLayerChangeListener(this); |
| 201 | |
192 | 202 | new SlippyMapControler(this, this); |
193 | 203 | } |
194 | 204 | |
… |
… |
public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser {
|
216 | 226 | @Override |
217 | 227 | public void paintComponent(Graphics g) { |
218 | 228 | super.paintComponent(g); |
| 229 | Graphics2D g2d = (Graphics2D)g; |
| 230 | |
| 231 | // draw shaded area for non-downloaded region of current "edit layer", but only if there *is* a current "edit layer", |
| 232 | // and it has defined bounds. routime is analogous to that in OsmDataLayer's paint routine (but just different |
| 233 | // enough to make sharing code impractical) |
| 234 | final OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer(); |
| 235 | if (editLayer != null && Config.getPref().getBoolean("draw.data.downloaded_area", true) && !editLayer.data.getDataSources().isEmpty()) { |
| 236 | // initialize area with current viewport |
| 237 | Rectangle b = this.getBounds(); |
| 238 | // ensure we comfortably cover full area |
| 239 | b.grow(100, 100); |
| 240 | Path2D p = new Path2D.Float(); |
| 241 | |
| 242 | // combine successively downloaded areas after converting to screen-space |
| 243 | for (Bounds bounds : editLayer.data.getDataSourceBounds()) { |
| 244 | if (bounds.isCollapsed()) { |
| 245 | continue; |
| 246 | } |
| 247 | Rectangle r = new Rectangle(this.getMapPosition(bounds.getMinLat(), bounds.getMinLon(), false)); |
| 248 | r.add(this.getMapPosition(bounds.getMaxLat(), bounds.getMaxLon(), false)); |
| 249 | p.append(r, false); |
| 250 | } |
| 251 | // subtract combined areas |
| 252 | Area a = new Area(b); |
| 253 | a.subtract(new Area(p)); |
| 254 | |
| 255 | // paint remainder |
| 256 | g2d.setPaint(new Color(0, 0, 0, 64)); |
| 257 | g2d.fill(a); |
| 258 | } |
219 | 259 | |
220 | 260 | // draw selection rectangle |
221 | 261 | if (iSelectionRectStart != null && iSelectionRectEnd != null) { |
… |
… |
public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser {
|
230 | 270 | } |
231 | 271 | } |
232 | 272 | |
| 273 | @Override |
| 274 | public void activeOrEditLayerChanged(MainLayerManager.ActiveLayerChangeEvent e) { |
| 275 | this.repaint(); |
| 276 | } |
| 277 | |
233 | 278 | /** |
234 | 279 | * Enables the disk tile cache. |
235 | 280 | * @param enabled true to enable, false to disable |