Changeset 3454 in josm for trunk/src/org
- Timestamp:
- 2010-08-21T17:43:56+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r3450 r3454 10 10 import java.awt.event.MouseWheelListener; 11 11 import java.util.ArrayList; 12 import java.util.HashMap; 12 13 import java.util.List; 14 import java.util.Map; 13 15 import java.util.concurrent.CopyOnWriteArrayList; 14 16 … … 33 35 import org.openstreetmap.josm.actions.mapmode.SelectAction; 34 36 import org.openstreetmap.josm.actions.mapmode.ZoomAction; 37 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 35 38 import org.openstreetmap.josm.gui.dialogs.ChangesetDialog; 36 39 import org.openstreetmap.josm.gui.dialogs.CommandStackDialog; … … 45 48 import org.openstreetmap.josm.gui.dialogs.UserListDialog; 46 49 import org.openstreetmap.josm.gui.dialogs.properties.PropertiesDialog; 50 import org.openstreetmap.josm.gui.layer.Layer; 47 51 import org.openstreetmap.josm.tools.Destroyable; 48 52 … … 53 57 * @author imi 54 58 */ 55 public class MapFrame extends JPanel implements Destroyable {59 public class MapFrame extends JPanel implements Destroyable, LayerChangeListener { 56 60 57 61 /** … … 59 63 */ 60 64 public MapMode mapMode; 65 66 private final List<MapMode> mapModes = new ArrayList<MapMode>(); 61 67 /** 62 68 * The view control displayed. … … 90 96 * Default width of the toggle dialog area. 91 97 */ 92 public final int DEF_TOGGLE_DLG_WIDTH = 330; 98 public static final int DEF_TOGGLE_DLG_WIDTH = 330; 99 100 private final Map<Layer, MapMode> lastMapMode = new HashMap<Layer, MapMode>(); 93 101 94 102 public MapFrame(JPanel contentPane) { … … 168 176 // status line below the map 169 177 statusLine = new MapStatus(this); 178 MapView.addLayerChangeListener(this); 170 179 } 171 180 … … 190 199 */ 191 200 public void destroy() { 201 MapView.removeLayerChangeListener(this); 192 202 dialogsPanel.destroy(); 193 203 for (int i = 0; i < toolBarActions.getComponentCount(); ++i) … … 243 253 toolBarActions.add(b); 244 254 toolGroup.add(b); 255 if (b.getAction() instanceof MapMode) { 256 mapModes.add((MapMode) b.getAction()); 257 } else 258 throw new IllegalArgumentException("MapMode action must be subclass of MapMode"); 245 259 } 246 260 … … 261 275 * @param mapMode The new mode to set. 262 276 */ 263 public voidselectMapMode(MapMode newMapMode) {277 public boolean selectMapMode(MapMode newMapMode) { 264 278 MapMode oldMapMode = this.mapMode; 265 279 if (newMapMode == oldMapMode) 266 return ;280 return false; 267 281 if (oldMapMode != null) { 268 282 oldMapMode.exitMode(); … … 270 284 this.mapMode = newMapMode; 271 285 newMapMode.enterMode(); 286 lastMapMode.put(mapView.getActiveLayer(), newMapMode); 272 287 fireMapModeChanged(oldMapMode, newMapMode); 288 return true; 273 289 } 274 290 … … 361 377 } 362 378 } 379 380 @Override 381 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 382 boolean modeChanged = false; 383 if (mapMode == null || !mapMode.layerIsSupported(newLayer)) { 384 MapMode newMapMode = lastMapMode.get(newLayer); 385 if (newMapMode != null) { 386 modeChanged = selectMapMode(newMapMode); 387 } // it would be nice to select first supported mode when layer is first selected, but it don't work well with for example editgpx layer 388 } 389 if (!modeChanged && mapMode != null) { 390 // Let mapmodes know about new active layer 391 mapMode.exitMode(); 392 mapMode.enterMode(); 393 } 394 } 395 396 @Override 397 public void layerAdded(Layer newLayer) { } 398 399 @Override 400 public void layerRemoved(Layer oldLayer) { 401 lastMapMode.remove(oldLayer); 402 } 363 403 }
Note:
See TracChangeset
for help on using the changeset viewer.