Changeset 10031 in josm
- Timestamp:
- 2016-03-23T21:30:27+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java
r9572 r10031 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; … … 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 … … 90 90 91 91 protected String oldModeHelpText; 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 }; 92 99 93 100 /** … … 136 143 Main.map.mapView.addMouseListener(this); 137 144 Main.map.mapView.addMouseMotionListener(this); 138 Main.map.mapView.addTemporaryLayer(t his);145 Main.map.mapView.addTemporaryLayer(temporaryLayer); 139 146 DataSet.addSelectionListener(this); 140 147 … … 161 168 Main.map.mapView.removeMouseListener(this); 162 169 Main.map.mapView.removeMouseMotionListener(this); 163 Main.map.mapView.removeTemporaryLayer(t his);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 … … 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 @Override217 226 public void paint(Graphics2D g, MapView mv, Bounds bbox) { 218 227 if (mousePos == null) { … … 357 366 updateCursor(); 358 367 updateStatusLine(); 359 Main.map.mapView.repaint();368 temporaryLayer.invalidate(); 360 369 } 361 370 … … 386 395 updateCursor(); 387 396 updateStatusLine(); 388 Main.map.mapView.repaint();397 temporaryLayer.invalidate(); 389 398 } 390 399 … … 512 521 updateCursor(); 513 522 updateStatusLine(); 514 Main.map.mapView.repaint();523 temporaryLayer.invalidate(); 515 524 } 516 525 … … 524 533 mousePos = null; 525 534 } 526 Main.map.mapView.repaint();535 temporaryLayer.invalidate(); 527 536 } 528 537 … … 598 607 targetWay = null; 599 608 600 mv.repaint();609 temporaryLayer.invalidate(); 601 610 updateStatusLine(); 602 611 } … … 623 632 this.candidateSegment = null; 624 633 625 mv.repaint();634 temporaryLayer.invalidate(); 626 635 updateStatusLine(); 627 636 } -
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 } -
trunk/src/org/openstreetmap/josm/gui/SelectionManager.java
r9078 r10031 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 … … 89 89 * @author Michael Zangl 90 90 */ 91 private class SelectionHintLayer implementsMapViewPaintable {91 private class SelectionHintLayer extends AbstractMapViewPaintable { 92 92 @Override 93 93 public void paint(Graphics2D g, MapView mv, Bounds bbox) { … … 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 … … 383 381 */ 384 382 public Collection<OsmPrimitive> getSelectedObjects(boolean alt) { 385 386 383 Collection<OsmPrimitive> selection = new LinkedList<>(); 387 384 -
trunk/src/org/openstreetmap/josm/gui/layer/Layer.java
r10011 r10031 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 /** -
trunk/src/org/openstreetmap/josm/gui/layer/MapViewPaintable.java
r9230 r10031 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 { 17 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 } 10 62 11 63 /** -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r9971 r10031 917 917 @Override 918 918 public void processDatasetEvent(AbstractDatasetChangedEvent event) { 919 i sChanged = true;919 invalidate(); 920 920 setRequiresSaveToFile(true); 921 921 setRequiresUploadToServer(true); … … 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 -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
r9999 r10031 970 970 public void updateBufferAndRepaint() { 971 971 updateOffscreenBuffer = true; 972 Main.map.mapView.repaint();972 invalidate(); 973 973 } 974 974 -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java
r10001 r10031 158 158 mousePressed = true; 159 159 if (isVisible()) { 160 Main.map.mapView.repaint();160 invalidate(); 161 161 } 162 162 } … … 176 176 } 177 177 } 178 Main.map.mapView.repaint();178 invalidate(); 179 179 } 180 180 });
Note:
See TracChangeset
for help on using the changeset viewer.