diff --git a/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java b/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java
index 87599f2..e5ca19e 100644
a
|
b
|
import org.openstreetmap.josm.data.osm.WaySegment;
|
38 | 38 | import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors; |
39 | 39 | import org.openstreetmap.josm.gui.MapFrame; |
40 | 40 | import org.openstreetmap.josm.gui.MapView; |
| 41 | import org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable; |
41 | 42 | import org.openstreetmap.josm.gui.layer.Layer; |
42 | | import org.openstreetmap.josm.gui.layer.MapViewPaintable; |
43 | 43 | import org.openstreetmap.josm.gui.layer.OsmDataLayer; |
44 | 44 | import org.openstreetmap.josm.gui.util.GuiHelper; |
45 | 45 | import org.openstreetmap.josm.gui.util.ModifierListener; |
… |
… |
import org.openstreetmap.josm.tools.Shortcut;
|
50 | 50 | /** |
51 | 51 | * @author Alexander Kachkaev <alexander@kachkaev.ru>, 2011 |
52 | 52 | */ |
53 | | public class ImproveWayAccuracyAction extends MapMode implements MapViewPaintable, |
| 53 | public class ImproveWayAccuracyAction extends MapMode implements |
54 | 54 | SelectionChangedListener, ModifierListener { |
55 | 55 | |
56 | 56 | enum State { |
… |
… |
public class ImproveWayAccuracyAction extends MapMode implements MapViewPaintabl
|
90 | 90 | |
91 | 91 | protected String oldModeHelpText; |
92 | 92 | |
| 93 | private final AbstractMapViewPaintable temporaryLayer = new AbstractMapViewPaintable() { |
| 94 | @Override |
| 95 | public void paint(Graphics2D g, MapView mv, Bounds bbox) { |
| 96 | ImproveWayAccuracyAction.this.paint(g, mv, bbox);; |
| 97 | } |
| 98 | }; |
| 99 | |
93 | 100 | /** |
94 | 101 | * Constructs a new {@code ImproveWayAccuracyAction}. |
95 | 102 | * @param mapFrame Map frame |
… |
… |
public class ImproveWayAccuracyAction extends MapMode implements MapViewPaintabl
|
135 | 142 | |
136 | 143 | Main.map.mapView.addMouseListener(this); |
137 | 144 | Main.map.mapView.addMouseMotionListener(this); |
138 | | Main.map.mapView.addTemporaryLayer(this); |
| 145 | Main.map.mapView.addTemporaryLayer(temporaryLayer); |
139 | 146 | DataSet.addSelectionListener(this); |
140 | 147 | |
141 | 148 | Main.map.keyDetector.addModifierListener(this); |
… |
… |
public class ImproveWayAccuracyAction extends MapMode implements MapViewPaintabl
|
160 | 167 | |
161 | 168 | Main.map.mapView.removeMouseListener(this); |
162 | 169 | Main.map.mapView.removeMouseMotionListener(this); |
163 | | Main.map.mapView.removeTemporaryLayer(this); |
| 170 | Main.map.mapView.removeTemporaryLayer(temporaryLayer); |
164 | 171 | DataSet.removeSelectionListener(this); |
165 | 172 | |
166 | 173 | Main.map.keyDetector.removeModifierListener(this); |
167 | | Main.map.mapView.repaint(); |
| 174 | temporaryLayer.invalidate(); |
168 | 175 | } |
169 | 176 | |
170 | 177 | @Override |
… |
… |
public class ImproveWayAccuracyAction extends MapMode implements MapViewPaintabl
|
212 | 219 | /** |
213 | 220 | * Redraws temporary layer. Highlights targetWay in select mode. Draws |
214 | 221 | * preview lines in improve mode and highlights the candidateNode |
| 222 | * @param g The graphics |
| 223 | * @param mv The map view |
| 224 | * @param bbox The bounding box |
215 | 225 | */ |
216 | | @Override |
217 | 226 | public void paint(Graphics2D g, MapView mv, Bounds bbox) { |
218 | 227 | if (mousePos == null) { |
219 | 228 | return; |
… |
… |
public class ImproveWayAccuracyAction extends MapMode implements MapViewPaintabl
|
356 | 365 | updateCursorDependentObjectsIfNeeded(); |
357 | 366 | updateCursor(); |
358 | 367 | updateStatusLine(); |
359 | | Main.map.mapView.repaint(); |
| 368 | temporaryLayer.invalidate(); |
360 | 369 | } |
361 | 370 | |
362 | 371 | @Override |
… |
… |
public class ImproveWayAccuracyAction extends MapMode implements MapViewPaintabl
|
385 | 394 | updateCursorDependentObjectsIfNeeded(); |
386 | 395 | updateCursor(); |
387 | 396 | updateStatusLine(); |
388 | | Main.map.mapView.repaint(); |
| 397 | temporaryLayer.invalidate(); |
389 | 398 | } |
390 | 399 | |
391 | 400 | @Override |
… |
… |
public class ImproveWayAccuracyAction extends MapMode implements MapViewPaintabl
|
511 | 520 | mousePos = null; |
512 | 521 | updateCursor(); |
513 | 522 | updateStatusLine(); |
514 | | Main.map.mapView.repaint(); |
| 523 | temporaryLayer.invalidate(); |
515 | 524 | } |
516 | 525 | |
517 | 526 | @Override |
… |
… |
public class ImproveWayAccuracyAction extends MapMode implements MapViewPaintabl
|
523 | 532 | if (!dragging) { |
524 | 533 | mousePos = null; |
525 | 534 | } |
526 | | Main.map.mapView.repaint(); |
| 535 | temporaryLayer.invalidate(); |
527 | 536 | } |
528 | 537 | |
529 | 538 | // ------------------------------------------------------------------------- |
… |
… |
public class ImproveWayAccuracyAction extends MapMode implements MapViewPaintabl
|
597 | 606 | |
598 | 607 | targetWay = null; |
599 | 608 | |
600 | | mv.repaint(); |
| 609 | temporaryLayer.invalidate(); |
601 | 610 | updateStatusLine(); |
602 | 611 | } |
603 | 612 | |
… |
… |
public class ImproveWayAccuracyAction extends MapMode implements MapViewPaintabl
|
622 | 631 | this.candidateNode = null; |
623 | 632 | this.candidateSegment = null; |
624 | 633 | |
625 | | mv.repaint(); |
| 634 | temporaryLayer.invalidate(); |
626 | 635 | updateStatusLine(); |
627 | 636 | } |
628 | 637 | |
diff --git a/src/org/openstreetmap/josm/gui/MapView.java b/src/org/openstreetmap/josm/gui/MapView.java
index f509eac..002941a 100644
a
|
b
|
import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
54 | 54 | import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors; |
55 | 55 | import org.openstreetmap.josm.data.osm.visitor.paint.Rendering; |
56 | 56 | import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache; |
| 57 | import org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable; |
57 | 58 | import org.openstreetmap.josm.gui.layer.GpxLayer; |
58 | 59 | import org.openstreetmap.josm.gui.layer.ImageryLayer; |
59 | 60 | import org.openstreetmap.josm.gui.layer.Layer; |
60 | 61 | import org.openstreetmap.josm.gui.layer.LayerPositionStrategy; |
61 | 62 | import org.openstreetmap.josm.gui.layer.MapViewPaintable; |
| 63 | import org.openstreetmap.josm.gui.layer.MapViewPaintable.PaintableInvalidationEvent; |
| 64 | import org.openstreetmap.josm.gui.layer.MapViewPaintable.PaintableInvalidationListener; |
62 | 65 | import org.openstreetmap.josm.gui.layer.NativeScaleLayer; |
63 | 66 | import org.openstreetmap.josm.gui.layer.OsmDataLayer; |
64 | 67 | import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer; |
… |
… |
implements PropertyChangeListener, PreferenceChangedListener, OsmDataLayer.Layer
|
124 | 127 | void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer); |
125 | 128 | } |
126 | 129 | |
| 130 | /** |
| 131 | * An invalidation listener that simply calls repaint() for now. |
| 132 | * @author Michael Zangl |
| 133 | */ |
| 134 | private class LayerInvalidatedListener implements PaintableInvalidationListener { |
| 135 | private boolean ignoreRepaint; |
| 136 | @Override |
| 137 | public void paintablInvalidated(PaintableInvalidationEvent event) { |
| 138 | ignoreRepaint = true; |
| 139 | repaint(); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Temporary until all {@link MapViewPaintable}s support this. |
| 144 | * @param p The paintable. |
| 145 | */ |
| 146 | public void addTo(MapViewPaintable p) { |
| 147 | if (p instanceof AbstractMapViewPaintable) { |
| 148 | ((AbstractMapViewPaintable) p).addInvalidationListener(this); |
| 149 | } |
| 150 | } |
| 151 | /** |
| 152 | * Temporary until all {@link MapViewPaintable}s support this. |
| 153 | * @param p The paintable. |
| 154 | */ |
| 155 | public void removeFrom(MapViewPaintable p) { |
| 156 | if (p instanceof AbstractMapViewPaintable) { |
| 157 | ((AbstractMapViewPaintable) p).removeInvalidationListener(this); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Attempts to trace repaints that did not originate from this listener. Good to find missed {@link MapView#repaint()}s in code. |
| 163 | */ |
| 164 | protected synchronized void traceRandomRepaint() { |
| 165 | if (!ignoreRepaint) { |
| 166 | System.err.println("Repaint:"); |
| 167 | Thread.dumpStack(); |
| 168 | } |
| 169 | ignoreRepaint = false; |
| 170 | } |
| 171 | } |
| 172 | |
127 | 173 | public boolean viewportFollowing; |
128 | 174 | |
129 | 175 | /** |
… |
… |
implements PropertyChangeListener, PreferenceChangedListener, OsmDataLayer.Layer
|
268 | 314 | private transient MapMover mapMover; |
269 | 315 | |
270 | 316 | /** |
| 317 | * The listener that listens to invalidations of all layers. |
| 318 | */ |
| 319 | private final LayerInvalidatedListener invalidatedListener = new LayerInvalidatedListener(); |
| 320 | |
| 321 | /** |
271 | 322 | * Constructs a new {@code MapView}. |
272 | 323 | * @param contentPane The content pane used to register shortcuts in its |
273 | 324 | * {@link InputMap} and {@link ActionMap} |
… |
… |
implements PropertyChangeListener, PreferenceChangedListener, OsmDataLayer.Layer
|
381 | 432 | } |
382 | 433 | |
383 | 434 | layer.addPropertyChangeListener(this); |
| 435 | invalidatedListener.addTo(layer); |
384 | 436 | Main.addProjectionChangeListener(layer); |
385 | 437 | AudioPlayer.reset(); |
386 | 438 | } |
… |
… |
implements PropertyChangeListener, PreferenceChangedListener, OsmDataLayer.Layer
|
505 | 557 | layers.remove(layer); |
506 | 558 | Main.removeProjectionChangeListener(layer); |
507 | 559 | layer.removePropertyChangeListener(this); |
| 560 | invalidatedListener.removeFrom(layer); |
508 | 561 | layer.destroy(); |
509 | 562 | AudioPlayer.reset(); |
510 | 563 | } |
… |
… |
implements PropertyChangeListener, PreferenceChangedListener, OsmDataLayer.Layer
|
1034 | 1087 | */ |
1035 | 1088 | public boolean addTemporaryLayer(MapViewPaintable mvp) { |
1036 | 1089 | synchronized (temporaryLayers) { |
1037 | | return temporaryLayers.add(mvp); |
| 1090 | boolean added = temporaryLayers.add(mvp); |
| 1091 | if (added) { |
| 1092 | invalidatedListener.addTo(mvp); |
| 1093 | } |
| 1094 | return added; |
1038 | 1095 | } |
1039 | 1096 | } |
1040 | 1097 | |
… |
… |
implements PropertyChangeListener, PreferenceChangedListener, OsmDataLayer.Layer
|
1045 | 1102 | */ |
1046 | 1103 | public boolean removeTemporaryLayer(MapViewPaintable mvp) { |
1047 | 1104 | synchronized (temporaryLayers) { |
1048 | | return temporaryLayers.remove(mvp); |
| 1105 | boolean removed = temporaryLayers.remove(mvp); |
| 1106 | if (removed) { |
| 1107 | invalidatedListener.removeFrom(mvp); |
| 1108 | } |
| 1109 | return removed; |
1049 | 1110 | } |
1050 | 1111 | } |
1051 | 1112 | |
… |
… |
implements PropertyChangeListener, PreferenceChangedListener, OsmDataLayer.Layer
|
1205 | 1266 | } |
1206 | 1267 | super.repaint(tm, x, y, width, height); |
1207 | 1268 | } |
| 1269 | |
| 1270 | @Override |
| 1271 | public void repaint() { |
| 1272 | if (Main.isTraceEnabled()) { |
| 1273 | invalidatedListener.traceRandomRepaint(); |
| 1274 | } |
| 1275 | super.repaint(); |
| 1276 | } |
1208 | 1277 | } |
diff --git a/src/org/openstreetmap/josm/gui/SelectionManager.java b/src/org/openstreetmap/josm/gui/SelectionManager.java
index c0d87e4..eacb9ba 100644
a
|
b
|
import org.openstreetmap.josm.data.osm.Node;
|
22 | 22 | import org.openstreetmap.josm.data.osm.OsmPrimitive; |
23 | 23 | import org.openstreetmap.josm.data.osm.Way; |
24 | 24 | import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors; |
25 | | import org.openstreetmap.josm.gui.layer.MapViewPaintable; |
| 25 | import org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable; |
26 | 26 | import org.openstreetmap.josm.tools.Utils; |
27 | 27 | |
28 | 28 | /** |
… |
… |
public class SelectionManager implements MouseListener, MouseMotionListener, Pro
|
88 | 88 | * |
89 | 89 | * @author Michael Zangl |
90 | 90 | */ |
91 | | private class SelectionHintLayer implements MapViewPaintable { |
| 91 | private class SelectionHintLayer extends AbstractMapViewPaintable { |
92 | 92 | @Override |
93 | 93 | public void paint(Graphics2D g, MapView mv, Bounds bbox) { |
94 | 94 | if (mousePos == null || mousePosStart == null || mousePos == mousePosStart) |
… |
… |
public class SelectionManager implements MouseListener, MouseMotionListener, Pro
|
367 | 367 | } |
368 | 368 | } |
369 | 369 | |
370 | | private static void selectionAreaChanged() { |
371 | | // Trigger a redraw of the map view. |
372 | | // A nicer way would be to provide change events for the temporary layer. |
373 | | Main.map.mapView.repaint(); |
| 370 | private void selectionAreaChanged() { |
| 371 | selectionHintLayer.invalidate(); |
374 | 372 | } |
375 | 373 | |
376 | 374 | /** |
… |
… |
public class SelectionManager implements MouseListener, MouseMotionListener, Pro
|
382 | 380 | * @return The collection of selected objects. |
383 | 381 | */ |
384 | 382 | public Collection<OsmPrimitive> getSelectedObjects(boolean alt) { |
385 | | |
386 | 383 | Collection<OsmPrimitive> selection = new LinkedList<>(); |
387 | 384 | |
388 | 385 | // whether user only clicked, not dragged. |
diff --git a/src/org/openstreetmap/josm/gui/layer/AbstractMapViewPaintable.java b/src/org/openstreetmap/josm/gui/layer/AbstractMapViewPaintable.java
new file mode 100644
index 0000000..761a7df
-
|
+
|
|
| 1 | // License: GPL. For details, see LICENSE file. |
| 2 | package org.openstreetmap.josm.gui.layer; |
| 3 | |
| 4 | import java.util.concurrent.CopyOnWriteArrayList; |
| 5 | |
| 6 | /** |
| 7 | * This class implements the invalidation listener mechanism suggested by {@link MapViewPaintable}. |
| 8 | * |
| 9 | * @author Michael Zangl |
| 10 | */ |
| 11 | public abstract class AbstractMapViewPaintable implements MapViewPaintable { |
| 12 | |
| 13 | /** |
| 14 | * A list of invalidation listeners to call when this layer is invalidated. |
| 15 | */ |
| 16 | private final CopyOnWriteArrayList<PaintableInvalidationListener> invalidationListeners = new CopyOnWriteArrayList<>(); |
| 17 | |
| 18 | /** |
| 19 | * Adds a new paintable invalidation listener. |
| 20 | * @param l The listener to add. |
| 21 | */ |
| 22 | public void addInvalidationListener(PaintableInvalidationListener l) { |
| 23 | invalidationListeners.add(l); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Removes an added paintable invalidation listener. |
| 28 | * @param l The listener to remove. |
| 29 | */ |
| 30 | public void removeInvalidationListener(PaintableInvalidationListener l) { |
| 31 | invalidationListeners.remove(l); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * This needs to be called whenever the content of this view was invalidated. |
| 36 | */ |
| 37 | public void invalidate() { |
| 38 | for (PaintableInvalidationListener l : invalidationListeners) { |
| 39 | l.paintablInvalidated(new PaintableInvalidationEvent(this)); |
| 40 | } |
| 41 | } |
| 42 | } |
diff --git a/src/org/openstreetmap/josm/gui/layer/Layer.java b/src/org/openstreetmap/josm/gui/layer/Layer.java
index 8a4acfa..88cddc5 100644
a
|
b
|
import org.openstreetmap.josm.tools.Utils;
|
47 | 47 | * |
48 | 48 | * @author imi |
49 | 49 | */ |
50 | | public abstract class Layer implements Destroyable, MapViewPaintable, ProjectionChangeListener { |
| 50 | public abstract class Layer extends AbstractMapViewPaintable implements Destroyable, ProjectionChangeListener { |
51 | 51 | |
52 | 52 | /** |
53 | 53 | * Action related to a single layer. |
diff --git a/src/org/openstreetmap/josm/gui/layer/MapViewPaintable.java b/src/org/openstreetmap/josm/gui/layer/MapViewPaintable.java
index fa0fc7b..9eab095 100644
a
|
b
|
import java.awt.Graphics2D;
|
6 | 6 | import org.openstreetmap.josm.data.Bounds; |
7 | 7 | import org.openstreetmap.josm.gui.MapView; |
8 | 8 | |
| 9 | /** |
| 10 | * This is a component that can be painted on the map view. |
| 11 | * <p> |
| 12 | * You might want to extend {@link AbstractMapViewPaintable} to ease implementation of this. |
| 13 | * <p> |
| 14 | * That class allows you to listen to paintable change events. Those methods may be moved here some time in the future. |
| 15 | */ |
9 | 16 | public interface MapViewPaintable { |
10 | 17 | |
11 | 18 | /** |
| 19 | * This event is fired whenever the paintable got invalidated and needs repainting some time in the future. |
| 20 | * <p> |
| 21 | * Note: We might add an area in the future. |
| 22 | * |
| 23 | * @author Michael Zangl |
| 24 | */ |
| 25 | class PaintableInvalidationEvent { |
| 26 | private final MapViewPaintable paintable; |
| 27 | |
| 28 | /** |
| 29 | * Creates a new {@link PaintableInvalidationEvent} |
| 30 | * @param paintable The paintable that is invalidated. |
| 31 | */ |
| 32 | public PaintableInvalidationEvent(MapViewPaintable paintable) { |
| 33 | super(); |
| 34 | this.paintable = paintable; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Gets the layer that was invalidated. |
| 39 | * @return The layer. |
| 40 | */ |
| 41 | public MapViewPaintable getLayer() { |
| 42 | return paintable; |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public String toString() { |
| 47 | return "LayerInvalidationEvent [layer=" + paintable + "]"; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * This is a listener that listens to {@link PaintableInvalidationEvent}s |
| 53 | * @author Michael Zangl |
| 54 | */ |
| 55 | interface PaintableInvalidationListener { |
| 56 | /** |
| 57 | * Called whenever a {@link PaintableInvalidationEvent} is fired. This might be called from any thread. |
| 58 | * @param event The event |
| 59 | */ |
| 60 | void paintablInvalidated(PaintableInvalidationEvent event); |
| 61 | } |
| 62 | |
| 63 | /** |
12 | 64 | * Paint the dataset using the engine set. |
13 | 65 | * @param g Graphics |
14 | 66 | * @param mv The object that can translate GeoPoints to screen coordinates. |
diff --git a/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java b/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
index 55d352b..f33cfd7 100644
a
|
b
|
public class OsmDataLayer extends AbstractModifiableLayer implements Listener, S
|
916 | 916 | |
917 | 917 | @Override |
918 | 918 | public void processDatasetEvent(AbstractDatasetChangedEvent event) { |
919 | | isChanged = true; |
| 919 | invalidate(); |
920 | 920 | setRequiresSaveToFile(true); |
921 | 921 | setRequiresUploadToServer(true); |
922 | 922 | } |
923 | 923 | |
924 | 924 | @Override |
925 | 925 | public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { |
| 926 | invalidate(); |
| 927 | } |
| 928 | |
| 929 | @Override |
| 930 | public void invalidate() { |
926 | 931 | isChanged = true; |
| 932 | super.invalidate(); |
927 | 933 | } |
928 | 934 | |
929 | 935 | @Override |
diff --git a/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java b/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
index 39dfe55..4286aab 100644
a
|
b
|
public class GeoImageLayer extends AbstractModifiableLayer implements PropertyCh
|
969 | 969 | |
970 | 970 | public void updateBufferAndRepaint() { |
971 | 971 | updateOffscreenBuffer = true; |
972 | | Main.map.mapView.repaint(); |
| 972 | invalidate(); |
973 | 973 | } |
974 | 974 | |
975 | 975 | /** |
diff --git a/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java b/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java
index 543835d..f687a40 100644
a
|
b
|
public class MarkerLayer extends Layer implements JumpToMarkerLayer {
|
157 | 157 | return; |
158 | 158 | mousePressed = true; |
159 | 159 | if (isVisible()) { |
160 | | Main.map.mapView.repaint(); |
| 160 | invalidate(); |
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
… |
… |
public class MarkerLayer extends Layer implements JumpToMarkerLayer {
|
175 | 175 | } |
176 | 176 | } |
177 | 177 | } |
178 | | Main.map.mapView.repaint(); |
| 178 | invalidate(); |
179 | 179 | } |
180 | 180 | }); |
181 | 181 | } |