Changeset 2629 in josm for trunk/src/org
- Timestamp:
- 2009-12-13T19:31:06+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r2613 r2629 9 9 import java.awt.event.MouseWheelListener; 10 10 import java.util.ArrayList; 11 import java.util.Collection; 11 12 import java.util.List; 13 import java.util.concurrent.CopyOnWriteArrayList; 12 14 13 15 import javax.swing.AbstractButton; … … 216 218 217 219 /** 218 * 220 * 219 221 */ 220 222 public void tearDownDialogsPane() { … … 257 259 * @param mapMode The new mode to set. 258 260 */ 259 public void selectMapMode(MapMode mapMode) { 260 if (mapMode == this.mapMode) 261 public void selectMapMode(MapMode newMapMode) { 262 MapMode oldMapMode = this.mapMode; 263 if (newMapMode == oldMapMode) 261 264 return; 262 if (this.mapMode != null) { 263 this.mapMode.exitMode(); 264 } 265 this.mapMode = mapMode; 266 mapMode.enterMode(); 265 if (oldMapMode != null) { 266 oldMapMode.exitMode(); 267 } 268 this.mapMode = newMapMode; 269 newMapMode.enterMode(); 270 fireMapModeChanged(oldMapMode, newMapMode); 267 271 } 268 272 … … 319 323 return dialogsPanel.getWidth(); 320 324 } 325 326 /** 327 * Interface to notify listeners of the change of the mapMode. 328 */ 329 public interface MapModeChangeListener { 330 void mapModeChange(MapMode oldMapMode, MapMode newMapMode); 331 } 332 333 /** 334 * the mapMode listeners 335 */ 336 private static final Collection<MapModeChangeListener> mapModeChangeListeners = new CopyOnWriteArrayList<MapModeChangeListener>(); 337 /** 338 * Adds a mapMode change listener 339 * 340 * @param listener the listener. Ignored if null or already registered. 341 */ 342 public static void addMapModeChangeListener(MapModeChangeListener listener) { 343 if (listener != null && ! mapModeChangeListeners.contains(listener)) { 344 mapModeChangeListeners.add(listener); 345 } 346 } 347 /** 348 * Removes a mapMode change listener 349 * 350 * @param listener the listener. Ignored if null or already registered. 351 */ 352 public static void removeMapModeChangeListener(MapModeChangeListener listener) { 353 if (listener != null && mapModeChangeListeners.contains(listener)) { 354 mapModeChangeListeners.remove(listener); 355 } 356 } 357 358 protected static void fireMapModeChanged(MapMode oldMapMode, MapMode newMapMode) { 359 for (MapModeChangeListener l : mapModeChangeListeners) { 360 l.mapModeChange(oldMapMode, newMapMode); 361 } 362 } 321 363 } -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
r2627 r2629 46 46 import org.openstreetmap.josm.Main; 47 47 import org.openstreetmap.josm.actions.RenameLayerAction; 48 import org.openstreetmap.josm.actions.mapmode.MapMode; 48 49 import org.openstreetmap.josm.data.Bounds; 49 50 import org.openstreetmap.josm.data.coor.CachedLatLon; … … 51 52 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 52 53 import org.openstreetmap.josm.gui.ExtendedDialog; 54 import org.openstreetmap.josm.gui.MapFrame; 55 import org.openstreetmap.josm.gui.MapFrame.MapModeChangeListener; 53 56 import org.openstreetmap.josm.gui.MapView; 54 57 import org.openstreetmap.josm.gui.PleaseWaitRunnable; … … 646 649 647 650 private MouseAdapter mouseAdapter = null; 651 private MapModeChangeListener mapModeListener = null; 648 652 649 653 private void hook_up_mouse_events() { … … 689 693 } 690 694 }; 691 Main.map.mapView.addMouseListener(mouseAdapter); 695 696 mapModeListener = new MapModeChangeListener() { 697 public void mapModeChange(MapMode oldMapMode, MapMode newMapMode) { 698 if (newMapMode instanceof org.openstreetmap.josm.actions.mapmode.SelectAction) { 699 Main.map.mapView.addMouseListener(mouseAdapter); 700 } else { 701 Main.map.mapView.removeMouseListener(mouseAdapter); 702 } 703 } 704 }; 705 706 Main.map.addMapModeChangeListener(mapModeListener); 707 mapModeListener.mapModeChange(null, Main.map.mapMode); 708 692 709 MapView.addLayerChangeListener(new LayerChangeListener() { 693 710 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 694 if (newLayer == GeoImageLayer.this && currentPhoto >= 0) {695 Main.main.map.repaint();696 ImageViewerDialog.showImage(GeoImageLayer.this, data.get(currentPhoto));711 if (newLayer == GeoImageLayer.this) { 712 // only in select mode it is possible to click the images 713 Main.map.selectSelectTool(false); 697 714 } 698 715 } … … 707 724 } 708 725 Main.map.mapView.removeMouseListener(mouseAdapter); 726 Main.map.removeMapModeChangeListener(mapModeListener); 709 727 currentPhoto = -1; 710 728 data.clear();
Note:
See TracChangeset
for help on using the changeset viewer.