- Timestamp:
- 2009-12-18T08:40:15+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/event/DataChangedEvent.java
r2645 r2652 2 2 package org.openstreetmap.josm.data.osm.event; 3 3 4 import java.util.Collections; 4 5 import java.util.List; 5 6 … … 21 22 @Override 22 23 public List<OsmPrimitive> getPrimitives() { 23 return dataSet.allPrimitives(); 24 if (dataSet == null) 25 return Collections.emptyList(); 26 else 27 return dataSet.allPrimitives(); 24 28 } 25 29 -
trunk/src/org/openstreetmap/josm/data/osm/event/DatasetEventManager.java
r2625 r2652 9 9 import javax.swing.SwingUtilities; 10 10 11 import org.openstreetmap.josm.Main;12 11 import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter.Listener; 13 12 import org.openstreetmap.josm.gui.MapView; 14 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;15 import org.openstreetmap.josm.gui.layer.Layer;16 13 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 17 14 … … 26 23 * 27 24 */ 28 public class DatasetEventManager implements LayerChangeListener, Listener {25 public class DatasetEventManager implements MapView.EditLayerChangeListener, Listener { 29 26 30 27 private static final DatasetEventManager instance = new DatasetEventManager(); … … 40 37 41 38 public DatasetEventManager() { 42 MapView.add LayerChangeListener(this);39 MapView.addEditLayerChangeListener(this); 43 40 } 44 41 … … 62 59 } 63 60 64 /* --------------------------------------------------------------------------- */ 65 /* interface LayerChangeListener */ 66 /* --------------------------------------------------------------------------- */ 67 public void activeLayerChange(Layer a, Layer b) { 68 if (a != null && a instanceof OsmDataLayer) { 69 ((OsmDataLayer)a).data.removeDataSetListener(myListener); 61 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) { 62 if (oldLayer != null) { 63 oldLayer.data.removeDataSetListener(myListener); 70 64 } 71 if (b != null && b instanceof OsmDataLayer) { 72 ((OsmDataLayer)b).data.addDataSetListener(myListener); 73 } 74 if (Main.main.getEditLayer() != null) { 75 processDatasetEvent(new DataChangedEvent(Main.main.getEditLayer().data)); 65 66 if (newLayer != null) { 67 newLayer.data.addDataSetListener(myListener); 68 processDatasetEvent(new DataChangedEvent(newLayer.data)); 69 } else { 70 processDatasetEvent(new DataChangedEvent(null)); 76 71 } 77 72 } 78 public void layerRemoved(Layer a) {/* irrelevant in this context */}79 public void layerAdded(Layer a) {/* irrelevant in this context */}80 73 81 74 public void processDatasetEvent(AbstractDatasetChangedEvent event) { -
trunk/src/org/openstreetmap/josm/gui/MapView.java
r2626 r2652 76 76 } 77 77 78 public interface EditLayerChangeListener { 79 void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer); 80 } 81 78 82 /** 79 83 * the layer listeners 80 84 */ 81 85 private static final Collection<MapView.LayerChangeListener> layerChangeListeners = new CopyOnWriteArrayList<MapView.LayerChangeListener>(); 86 private static final Collection<EditLayerChangeListener> editLayerChangeListeners = new CopyOnWriteArrayList<EditLayerChangeListener>(); 82 87 83 88 /** … … 92 97 } 93 98 99 public static void removeEditLayerChangeListener(EditLayerChangeListener listener) { 100 if (listener != null && editLayerChangeListeners.contains(listener)) { 101 editLayerChangeListeners.remove(listener); 102 } 103 } 104 105 106 94 107 /** 95 108 * Adds a layer change listener … … 103 116 } 104 117 118 public static void addEditLayerChangeListener(EditLayerChangeListener listener) { 119 if (listener != null && ! layerChangeListeners.contains(listener)) { 120 editLayerChangeListeners.add(listener); 121 } 122 } 123 105 124 protected static void fireActiveLayerChanged(Layer oldLayer, Layer newLayer) { 106 125 for (LayerChangeListener l : layerChangeListeners) { … … 121 140 } 122 141 142 protected static void fireEditLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) { 143 for (EditLayerChangeListener l : editLayerChangeListeners) { 144 l.editLayerChanged(oldLayer, newLayer); 145 } 146 } 147 123 148 /** 124 149 * A list of all layers currently loaded. … … 134 159 */ 135 160 private Layer activeLayer; 161 162 private OsmDataLayer editLayer; 136 163 137 164 /** … … 255 282 @Override 256 283 protected DataSet getCurrentDataSet() { 257 if(activeLayer != null && activeLayer instanceof OsmDataLayer) 258 return ((OsmDataLayer)activeLayer).data; 259 return null; 284 if (editLayer != null) 285 return editLayer.data; 286 else 287 return null; 260 288 } 261 289 … … 266 294 */ 267 295 public boolean isActiveLayerDrawable() { 268 return activeLayer != null && activeLayer instanceof OsmDataLayer;296 return editLayer != null; 269 297 } 270 298 … … 275 303 */ 276 304 public boolean isActiveLayerVisible() { 277 return isActiveLayerDrawable() && activeLayer.isVisible();305 return isActiveLayerDrawable() && editLayer.isVisible(); 278 306 } 279 307 … … 290 318 * @return the next active data layer 291 319 */ 292 protected Layer determineNextActiveLayer() { 293 if (layers.isEmpty()) return null; 294 // if possible, activate the first data layer 295 // 296 List<OsmDataLayer> dataLayers = getLayersOfType(OsmDataLayer.class); 297 if (!dataLayers.isEmpty()) 298 return dataLayers.get(0); 299 300 // else the first layer of any type 301 // 302 return layers.get(0); 320 protected Layer determineNextActiveLayer(Layer ignoredLayer) { 321 // First look for data layer 322 for (Layer layer:layers) { 323 if (layer instanceof OsmDataLayer && layer != ignoredLayer) 324 return layer; 325 } 326 327 // Then any layer 328 for (Layer layer:layers) { 329 if (layer != ignoredLayer) 330 return layer; 331 } 332 333 // and then give up 334 return null; 335 303 336 } 304 337 … … 308 341 */ 309 342 public void removeLayer(Layer layer) { 310 boolean deletedLayerWasActiveLayer = false;311 312 343 if (layer == activeLayer) { 313 activeLayer = null; 314 deletedLayerWasActiveLayer = true; 315 fireActiveLayerChanged(layer, null); 344 setActiveLayer(determineNextActiveLayer(activeLayer)); 316 345 } 317 346 if (layers.remove(layer)) { … … 321 350 layer.destroy(); 322 351 AudioPlayer.reset(); 323 if (deletedLayerWasActiveLayer) {324 Layer l = determineNextActiveLayer();325 if (l != null) {326 activeLayer = l;327 fireActiveLayerChanged(null, l);328 }329 }330 352 repaint(); 331 353 } … … 362 384 layers.add(pos, layer); 363 385 } 386 setEditLayer(); 364 387 AudioPlayer.reset(); 365 388 repaint(); … … 561 584 } 562 585 586 private void setEditLayer() { 587 OsmDataLayer newEditLayer = null; 588 OsmDataLayer oldEditLayer = editLayer; 589 590 // Find new edit layer 591 if (activeLayer != editLayer) { 592 if (activeLayer instanceof OsmDataLayer) { 593 newEditLayer = (OsmDataLayer) activeLayer; 594 } else { 595 for (Layer layer:layers) { 596 if (layer instanceof OsmDataLayer) { 597 newEditLayer = (OsmDataLayer) layer; 598 break; 599 } 600 } 601 } 602 } 603 604 // Set new edit layer 605 if (newEditLayer != editLayer) { 606 if (newEditLayer == null) { 607 getCurrentDataSet().setSelected(); 608 } 609 610 editLayer = newEditLayer; 611 fireEditLayerChanged(oldEditLayer, newEditLayer); 612 refreshTitle(); 613 } 614 615 } 616 563 617 /** 564 618 * Sets the active layer to <code>layer</code>. If <code>layer</code> is an instance … … 571 625 if (!layers.contains(layer)) 572 626 throw new IllegalArgumentException(tr("Layer ''{0}'' must be in list of layers", layer.toString())); 573 if (! (layer instanceof OsmDataLayer)) { 574 if (getCurrentDataSet() != null) { 575 getCurrentDataSet().setSelected(); 576 } 577 } 627 628 if (layer == activeLayer) 629 return; 630 578 631 Layer old = activeLayer; 579 632 activeLayer = layer; 580 if (old != layer) { 581 fireActiveLayerChanged(old, layer); 582 } 583 if (layer instanceof OsmDataLayer) { 584 refreshTitle((OsmDataLayer)layer); 585 } 633 fireActiveLayerChanged(old, layer); 634 635 setEditLayer(); 586 636 587 637 /* This only makes the buttons look disabled. Disabling the actions as well requires … … 612 662 */ 613 663 public OsmDataLayer getEditLayer() { 614 if (activeLayer instanceof OsmDataLayer) 615 return (OsmDataLayer)activeLayer; 616 617 // the first OsmDataLayer is the edit layer 618 // 619 for (Layer layer : layers) { 620 if (layer instanceof OsmDataLayer) 621 return (OsmDataLayer)layer; 622 } 623 return null; 664 return editLayer; 624 665 } 625 666 … … 678 719 OsmDataLayer layer = (OsmDataLayer)evt.getSource(); 679 720 if (layer == getEditLayer()) { 680 refreshTitle( layer);681 } 682 } 683 } 684 685 protected void refreshTitle( OsmDataLayer layer) {686 boolean dirty = layer.requiresSaveToFile() || layer.requiresUploadToServer();721 refreshTitle(); 722 } 723 } 724 } 725 726 protected void refreshTitle() { 727 boolean dirty = editLayer != null && (editLayer.requiresSaveToFile() || editLayer.requiresUploadToServer()); 687 728 if (dirty) { 688 729 JOptionPane.getFrameForComponent(Main.parent).setTitle("* " + tr("Java OpenStreetMap Editor")); -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetsInActiveDataLayerListModel.java
r2621 r2652 6 6 import org.openstreetmap.josm.Main; 7 7 import org.openstreetmap.josm.gui.MapView; 8 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;9 8 import org.openstreetmap.josm.gui.layer.DataChangeListener; 10 9 import org.openstreetmap.josm.gui.layer.Layer;
Note:
See TracChangeset
for help on using the changeset viewer.