Changeset 10031 in josm for trunk/src/org/openstreetmap/josm/gui/MapView.java
- Timestamp:
- 2016-03-23T21:30:27+01:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapView.java
r10008 r10031 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; … … 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; … … 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 … … 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 … … 382 433 383 434 layer.addPropertyChangeListener(this); 435 invalidatedListener.addTo(layer); 384 436 Main.addProjectionChangeListener(layer); 385 437 AudioPlayer.reset(); … … 506 558 Main.removeProjectionChangeListener(layer); 507 559 layer.removePropertyChangeListener(this); 560 invalidatedListener.removeFrom(layer); 508 561 layer.destroy(); 509 562 AudioPlayer.reset(); … … 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 } … … 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 } … … 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 }
Note:
See TracChangeset
for help on using the changeset viewer.