- Timestamp:
- 2016-06-07T08:22:39+02:00 (8 years ago)
- Location:
- trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/event/DatasetEventManager.java
r10308 r10332 12 12 import javax.swing.SwingUtilities; 13 13 14 import org.openstreetmap.josm.Main; 14 15 import org.openstreetmap.josm.data.osm.DataSet; 15 16 import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter.Listener; 16 import org.openstreetmap.josm.gui. MapView;17 import org.openstreetmap.josm.gui.layer. OsmDataLayer;17 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 18 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 18 19 19 20 /** … … 26 27 * 27 28 */ 28 public class DatasetEventManager implements MapView.EditLayerChangeListener, Listener {29 public class DatasetEventManager implements ActiveLayerChangeListener, Listener { 29 30 30 31 private static final DatasetEventManager instance = new DatasetEventManager(); … … 146 147 */ 147 148 public DatasetEventManager() { 148 Ma pView.addEditLayerChangeListener(this);149 Main.getLayerManager().addActiveLayerChangeListener(this); 149 150 } 150 151 … … 171 172 172 173 @Override 173 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {174 if (oldLayer != null) {175 oldLayer.data.removeDataSetListener(myListener);176 }177 178 if (newLayer != null) { 179 newLayer.data.addDataSetListener(myListener);180 processDatasetEvent(new DataChangedEvent(newLayer.data));181 } else {182 processDatasetEvent(new DataChangedEvent(null));183 }174 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 175 DataSet oldData = e.getPreviousEditDataSet(); 176 if (oldData != null) { 177 oldData.removeDataSetListener(myListener); 178 } 179 180 DataSet newData = e.getSource().getEditDataSet(); 181 if (newData != null) { 182 newData.addDataSetListener(myListener); 183 } 184 processDatasetEvent(new DataChangedEvent(newData)); 184 185 } 185 186 -
trunk/src/org/openstreetmap/josm/gui/MapView.java
r10304 r10332 396 396 LayerChangeAdapter adapter = new LayerChangeAdapter(listener, initialFire); 397 397 Main.getLayerManager().addLayerChangeListener(adapter, false); 398 Main.getLayerManager().addActiveLayerChangeListener(adapter, initialFire); 398 if (initialFire) { 399 Main.getLayerManager().addAndFireActiveLayerChangeListener(adapter); 400 } else { 401 Main.getLayerManager().addActiveLayerChangeListener(adapter); 402 } 399 403 adapter.receiveOneInitialFire = false; 400 404 } … … 414 418 public static void addEditLayerChangeListener(EditLayerChangeListener listener, boolean initialFire) { 415 419 if (listener != null) { 416 Main.getLayerManager().addActiveLayerChangeListener(new EditLayerChangeAdapter(listener), 417 initialFire && Main.isDisplayingMapView() && Main.map.mapView.getEditLayer() != null); 420 boolean doFire = initialFire && Main.isDisplayingMapView() && Main.map.mapView.getEditLayer() != null; 421 if (doFire) { 422 Main.getLayerManager().addAndFireActiveLayerChangeListener(new EditLayerChangeAdapter(listener)); 423 } else { 424 Main.getLayerManager().addActiveLayerChangeListener(new EditLayerChangeAdapter(listener)); 425 } 418 426 } 419 427 } … … 484 492 initialViewport = viewportData; 485 493 layerManager.addLayerChangeListener(this); 486 layerManager.addActiveLayerChangeListener(this , false);494 layerManager.addActiveLayerChangeListener(this); 487 495 Main.pref.addPreferenceChangeListener(this); 488 496 -
trunk/src/org/openstreetmap/josm/gui/dialogs/ChangesetDialog.java
r10179 r10332 43 43 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 44 44 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 45 import org.openstreetmap.josm.gui.MapView;46 45 import org.openstreetmap.josm.gui.SideButton; 47 46 import org.openstreetmap.josm.gui.dialogs.changeset.ChangesetCacheManager; … … 115 114 // let the model for changesets in the current selection listen to various events 116 115 ChangesetCache.getInstance().addChangesetCacheListener(inSelectionModel); 117 Ma pView.addEditLayerChangeListener(inSelectionModel);116 Main.getLayerManager().addActiveLayerChangeListener(inSelectionModel); 118 117 DataSet.addSelectionListener(inSelectionModel); 119 118 … … 121 120 // events and bootstrap it's content 122 121 ChangesetCache.getInstance().addChangesetCacheListener(inActiveDataLayerModel); 123 Ma pView.addEditLayerChangeListener(inActiveDataLayerModel);122 Main.getLayerManager().addActiveLayerChangeListener(inActiveDataLayerModel); 124 123 OsmDataLayer editLayer = Main.main.getEditLayer(); 125 124 if (editLayer != null) { … … 134 133 // 135 134 ChangesetCache.getInstance().removeChangesetCacheListener(inActiveDataLayerModel); 136 Ma pView.removeEditLayerChangeListener(inActiveDataLayerModel);135 Main.getLayerManager().removeActiveLayerChangeListener(inActiveDataLayerModel); 137 136 OsmDataLayer editLayer = Main.main.getEditLayer(); 138 137 if (editLayer != null) { … … 143 142 // listener 144 143 // 145 Ma pView.removeEditLayerChangeListener(inSelectionModel);144 Main.getLayerManager().removeActiveLayerChangeListener(inSelectionModel); 146 145 DataSet.removeSelectionListener(inSelectionModel); 147 146 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java
r9607 r10332 55 55 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 56 56 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; 57 import org.openstreetmap.josm.gui.MapView;58 57 import org.openstreetmap.josm.gui.NavigatableComponent; 59 58 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; … … 62 61 import org.openstreetmap.josm.gui.conflict.pair.ConflictResolver; 63 62 import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType; 63 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 64 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 64 65 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 65 66 import org.openstreetmap.josm.gui.util.GuiHelper; … … 73 74 * @since 86 74 75 */ 75 public final class ConflictDialog extends ToggleDialog implements MapView.EditLayerChangeListener, IConflictListener, SelectionChangedListener {76 public final class ConflictDialog extends ToggleDialog implements ActiveLayerChangeListener, IConflictListener, SelectionChangedListener { 76 77 77 78 /** the collection of conflicts displayed by this conflict dialog */ … … 170 171 public void showNotify() { 171 172 DataSet.addSelectionListener(this); 172 Ma pView.addEditLayerChangeListener(this, true);173 Main.getLayerManager().addAndFireActiveLayerChangeListener(this); 173 174 refreshView(); 174 175 } … … 176 177 @Override 177 178 public void hideNotify() { 178 Ma pView.removeEditLayerChangeListener(this);179 Main.getLayerManager().removeActiveLayerChangeListener(this); 179 180 DataSet.removeSelectionListener(this); 180 181 } … … 279 280 280 281 @Override 281 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) { 282 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 283 OsmDataLayer oldLayer = e.getPreviousEditLayer(); 282 284 if (oldLayer != null) { 283 285 oldLayer.getConflicts().removeConflictListener(this); 284 286 } 287 OsmDataLayer newLayer = e.getSource().getEditLayer(); 285 288 if (newLayer != null) { 286 289 newLayer.getConflicts().addConflictListener(this); -
trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
r10288 r10332 332 332 MapView.addLayerChangeListener(activateLayerAction); 333 333 layerManager.addLayerChangeListener(model); 334 layerManager.addA ctiveLayerChangeListener(model, true);334 layerManager.addAndFireActiveLayerChangeListener(model); 335 335 model.populate(); 336 336 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r10217 r10332 46 46 import org.openstreetmap.josm.data.SelectionChangedListener; 47 47 import org.openstreetmap.josm.data.coor.LatLon; 48 import org.openstreetmap.josm.data.osm.DataSet; 48 49 import org.openstreetmap.josm.data.osm.Node; 49 50 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 65 66 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 66 67 import org.openstreetmap.josm.gui.DefaultNameFormatter; 67 import org.openstreetmap.josm.gui.MapView;68 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;69 68 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 70 69 import org.openstreetmap.josm.gui.PopupMenuHandler; … … 72 71 import org.openstreetmap.josm.gui.datatransfer.PrimitiveTransferable; 73 72 import org.openstreetmap.josm.gui.history.HistoryBrowserDialogManager; 73 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 74 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 74 75 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 75 76 import org.openstreetmap.josm.gui.util.GuiHelper; … … 177 178 @Override 178 179 public void showNotify() { 179 MapView.addEditLayerChangeListener(model);180 180 SelectionEventManager.getInstance().addSelectionListener(actShowHistory, FireMode.IN_EDT_CONSOLIDATED); 181 181 SelectionEventManager.getInstance().addSelectionListener(model, FireMode.IN_EDT_CONSOLIDATED); 182 182 DatasetEventManager.getInstance().addDatasetListener(model, FireMode.IN_EDT); 183 MapView.addEditLayerChangeListener(actSearch); 184 // editLayerChanged also gets the selection history of the level 185 OsmDataLayer editLayer = Main.main.getEditLayer(); 186 model.editLayerChanged(null, editLayer); 187 if (editLayer != null) { 188 model.setJOSMSelection(editLayer.data.getAllSelected()); 189 } 183 Main.getLayerManager().addActiveLayerChangeListener(actSearch); 184 // editLayerChanged also gets the selection history of the level. Listener calls setJOSMSelection when fired. 185 Main.getLayerManager().addAndFireActiveLayerChangeListener(model); 190 186 actSearch.updateEnabledState(); 191 187 } … … 193 189 @Override 194 190 public void hideNotify() { 195 Ma pView.removeEditLayerChangeListener(actSearch);196 Ma pView.removeEditLayerChangeListener(model);191 Main.getLayerManager().removeActiveLayerChangeListener(actSearch); 192 Main.getLayerManager().removeActiveLayerChangeListener(model); 197 193 SelectionEventManager.getInstance().removeSelectionListener(actShowHistory); 198 194 SelectionEventManager.getInstance().removeSelectionListener(model); … … 296 292 * Launches the search dialog 297 293 */ 298 static class SearchAction extends AbstractAction implements EditLayerChangeListener {294 static class SearchAction extends AbstractAction implements ActiveLayerChangeListener { 299 295 /** 300 296 * Constructs a new {@code SearchAction}. … … 318 314 319 315 @Override 320 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {316 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 321 317 updateEnabledState(); 322 318 } … … 480 476 */ 481 477 private static class SelectionListModel extends AbstractListModel<OsmPrimitive> 482 implements EditLayerChangeListener, SelectionChangedListener, DataSetListener {478 implements ActiveLayerChangeListener, SelectionChangedListener, DataSetListener { 483 479 484 480 private static final int SELECTION_HISTORY_SIZE = 10; … … 672 668 673 669 /* ------------------------------------------------------------------------ */ 674 /* interface EditLayerChangeListener*/670 /* interface ActiveLayerChangeListener */ 675 671 /* ------------------------------------------------------------------------ */ 676 672 @Override 677 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) { 678 if (newLayer == null) { 673 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 674 DataSet newData = e.getSource().getEditDataSet(); 675 if (newData == null) { 679 676 setJOSMSelection(null); 680 677 history = null; 681 678 } else { 682 history = new Layer.data.getSelectionHistory();683 setJOSMSelection(new Layer.data.getAllSelected());679 history = newData.getSelectionHistory(); 680 setJOSMSelection(newData.getAllSelected()); 684 681 } 685 682 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentPanel.java
r10212 r10332 42 42 import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive; 43 43 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 44 import org.openstreetmap.josm.gui.MapView;45 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;46 44 import org.openstreetmap.josm.gui.help.HelpUtil; 47 45 import org.openstreetmap.josm.gui.history.HistoryBrowserDialogManager; 48 46 import org.openstreetmap.josm.gui.history.HistoryLoadTask; 49 47 import org.openstreetmap.josm.gui.io.DownloadPrimitivesWithReferrersTask; 48 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 49 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 50 50 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 51 51 import org.openstreetmap.josm.gui.util.GuiHelper; … … 54 54 import org.openstreetmap.josm.tools.ImageProvider; 55 55 import org.openstreetmap.josm.tools.Utils; 56 import org.openstreetmap.josm.tools.bugreport.BugReport; 56 57 import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler; 57 58 … … 90 91 actSelectInCurrentLayerAction = new SelectInCurrentLayerAction(); 91 92 model.getSelectionModel().addListSelectionListener(actSelectInCurrentLayerAction); 92 Ma pView.addEditLayerChangeListener(actSelectInCurrentLayerAction);93 Main.getLayerManager().addActiveLayerChangeListener(actSelectInCurrentLayerAction); 93 94 94 95 actZoomInCurrentLayerAction = new ZoomInCurrentLayerAction(); 95 96 model.getSelectionModel().addListSelectionListener(actZoomInCurrentLayerAction); 96 Ma pView.addEditLayerChangeListener(actZoomInCurrentLayerAction);97 Main.getLayerManager().addActiveLayerChangeListener(actZoomInCurrentLayerAction); 97 98 98 99 addComponentListener( … … 102 103 // make sure the listener is unregistered when the panel becomes 103 104 // invisible 104 MapView.removeEditLayerChangeListener(actSelectInCurrentLayerAction); 105 MapView.removeEditLayerChangeListener(actZoomInCurrentLayerAction); 105 try { 106 Main.getLayerManager().removeActiveLayerChangeListener(actSelectInCurrentLayerAction); 107 Main.getLayerManager().removeActiveLayerChangeListener(actZoomInCurrentLayerAction); 108 } catch (IllegalArgumentException t) { 109 throw BugReport.intercept(t).put("hint", "This Component can only be hidden once."); 110 } 106 111 } 107 112 } … … 325 330 } 326 331 327 abstract class SelectionBasedAction extends AbstractAction implements ListSelectionListener, EditLayerChangeListener {332 abstract class SelectionBasedAction extends AbstractAction implements ListSelectionListener, ActiveLayerChangeListener { 328 333 329 334 protected Set<OsmPrimitive> getTarget() { … … 356 361 357 362 @Override 358 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {363 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 359 364 updateEnabledState(); 360 365 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetDetailPanel.java
r10124 r10332 35 35 import org.openstreetmap.josm.data.osm.OsmPrimitive; 36 36 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 37 import org.openstreetmap.josm.gui.MapView;38 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;39 37 import org.openstreetmap.josm.gui.help.HelpUtil; 38 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 39 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 40 40 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 41 41 import org.openstreetmap.josm.gui.widgets.JosmTextArea; … … 86 86 87 87 tb.add(actSelectInCurrentLayer); 88 Ma pView.addEditLayerChangeListener(actSelectInCurrentLayer);88 Main.getLayerManager().addActiveLayerChangeListener(actSelectInCurrentLayer); 89 89 90 90 tb.add(actZoomInCurrentLayerAction); 91 Ma pView.addEditLayerChangeListener(actZoomInCurrentLayerAction);91 Main.getLayerManager().addActiveLayerChangeListener(actZoomInCurrentLayerAction); 92 92 93 93 addComponentListener( … … 97 97 // make sure the listener is unregistered when the panel becomes 98 98 // invisible 99 Ma pView.removeEditLayerChangeListener(actSelectInCurrentLayer);100 Ma pView.removeEditLayerChangeListener(actZoomInCurrentLayerAction);99 Main.getLayerManager().removeActiveLayerChangeListener(actSelectInCurrentLayer); 100 Main.getLayerManager().removeActiveLayerChangeListener(actZoomInCurrentLayerAction); 101 101 } 102 102 } … … 318 318 * 319 319 */ 320 class SelectInCurrentLayerAction extends AbstractAction implements EditLayerChangeListener {320 class SelectInCurrentLayerAction extends AbstractAction implements ActiveLayerChangeListener { 321 321 322 322 SelectInCurrentLayerAction() { … … 369 369 370 370 @Override 371 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {371 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 372 372 updateEnabledState(); 373 373 } … … 379 379 * 380 380 */ 381 class ZoomInCurrentLayerAction extends AbstractAction implements EditLayerChangeListener {381 class ZoomInCurrentLayerAction extends AbstractAction implements ActiveLayerChangeListener { 382 382 383 383 ZoomInCurrentLayerAction() { … … 431 431 432 432 @Override 433 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {433 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 434 434 updateEnabledState(); 435 435 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetInSelectionListModel.java
r9059 r10332 7 7 8 8 import org.openstreetmap.josm.data.SelectionChangedListener; 9 import org.openstreetmap.josm.data.osm.DataSet; 9 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; 10 import org.openstreetmap.josm.gui. MapView.EditLayerChangeListener;11 import org.openstreetmap.josm.gui.layer. OsmDataLayer;11 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 12 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 12 13 13 public class ChangesetInSelectionListModel extends ChangesetListModel implements SelectionChangedListener, EditLayerChangeListener {14 public class ChangesetInSelectionListModel extends ChangesetListModel implements SelectionChangedListener, ActiveLayerChangeListener { 14 15 15 16 public ChangesetInSelectionListModel(DefaultListSelectionModel selectionModel) { … … 29 30 /* ---------------------------------------------------------------------------- */ 30 31 @Override 31 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) { 32 if (newLayer == null) { 32 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 33 DataSet newData = e.getSource().getEditDataSet(); 34 if (newData == null) { 33 35 setChangesets(null); 34 36 } else { 35 initFromPrimitives( (newLayer).data.getAllSelected());37 initFromPrimitives(newData.getAllSelected()); 36 38 } 37 39 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetsInActiveDataLayerListModel.java
r8413 r10332 13 13 import org.openstreetmap.josm.data.osm.event.TagsChangedEvent; 14 14 import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent; 15 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener; 15 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 16 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 16 17 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 17 18 … … 20 21 * 21 22 */ 22 public class ChangesetsInActiveDataLayerListModel extends ChangesetListModel implements DataSetListener, EditLayerChangeListener {23 public class ChangesetsInActiveDataLayerListModel extends ChangesetListModel implements DataSetListener, ActiveLayerChangeListener { 23 24 24 25 public ChangesetsInActiveDataLayerListModel(DefaultListSelectionModel selectionModel) { … … 70 71 71 72 /* ------------------------------------------------------------------------------ */ 72 /* interface EditLayerListener */73 /* interface ActiveLayerChangeListener */ 73 74 /* ------------------------------------------------------------------------------ */ 74 75 @Override 75 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {76 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 76 77 // just init the model content. Don't register as DataSetListener. The mode 77 78 // is already registered to receive DataChangedEvents from the current edit layer 78 if (newLayer != null) { 79 initFromDataSet(newLayer.data); 79 OsmDataLayer editLayer = e.getSource().getEditLayer(); 80 if (editLayer != null) { 81 initFromDataSet(editLayer.data); 80 82 } else { 81 83 initFromDataSet(null); -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r10254 r10332 85 85 import org.openstreetmap.josm.gui.DefaultNameFormatter; 86 86 import org.openstreetmap.josm.gui.ExtendedDialog; 87 import org.openstreetmap.josm.gui.MapView;88 87 import org.openstreetmap.josm.gui.PopupMenuHandler; 89 88 import org.openstreetmap.josm.gui.SideButton; … … 91 90 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 92 91 import org.openstreetmap.josm.gui.help.HelpUtil; 93 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 92 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 93 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 94 94 import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset; 95 95 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetHandler; 96 96 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType; 97 import org.openstreetmap.josm.gui.util.GuiHelper;98 97 import org.openstreetmap.josm.gui.util.HighlightHelper; 99 98 import org.openstreetmap.josm.gui.widgets.CompileSearchTextDecorator; … … 130 129 */ 131 130 public class PropertiesDialog extends ToggleDialog 132 implements SelectionChangedListener, MapView.EditLayerChangeListener, DataSetListenerAdapter.Listener {131 implements SelectionChangedListener, ActiveLayerChangeListener, DataSetListenerAdapter.Listener { 133 132 134 133 /** … … 590 589 DatasetEventManager.getInstance().addDatasetListener(dataChangedAdapter, FireMode.IN_EDT_CONSOLIDATED); 591 590 SelectionEventManager.getInstance().addSelectionListener(this, FireMode.IN_EDT_CONSOLIDATED); 592 Ma pView.addEditLayerChangeListener(this);591 Main.getLayerManager().addActiveLayerChangeListener(this); 593 592 for (JosmAction action : josmActions) { 594 593 Main.registerActionShortcut(action); … … 601 600 DatasetEventManager.getInstance().removeDatasetListener(dataChangedAdapter); 602 601 SelectionEventManager.getInstance().removeSelectionListener(this); 603 Ma pView.removeEditLayerChangeListener(this);602 Main.getLayerManager().removeActiveLayerChangeListener(this); 604 603 for (JosmAction action : josmActions) { 605 604 Main.unregisterActionShortcut(action); … … 770 769 771 770 /* ---------------------------------------------------------------------------------- */ 772 /* EditLayerChangeListener*/771 /* ActiveLayerChangeListener */ 773 772 /* ---------------------------------------------------------------------------------- */ 774 773 @Override 775 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) { 776 if (newLayer == null) editHelper.saveTagsIfNeeded(); 774 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 775 if (e.getSource().getEditLayer() != null) { 776 editHelper.saveTagsIfNeeded(); 777 } 777 778 // it is time to save history of tags 778 GuiHelper.runInEDT(new Runnable() { 779 @Override public void run() { 780 updateSelection(); 781 } 782 }); 779 updateSelection(); 783 780 } 784 781 -
trunk/src/org/openstreetmap/josm/gui/layer/MainLayerManager.java
r10279 r10332 76 76 } 77 77 78 /** 79 * Gets the data set that was previously used. 80 * @return The data set of {@link #getPreviousEditLayer()}. 81 */ 82 public DataSet getPreviousEditDataSet() { 83 if (previousEditLayer != null) { 84 return previousEditLayer.data; 85 } else { 86 return null; 87 } 88 } 89 78 90 @Override 79 91 public MainLayerManager getSource() { … … 98 110 * 99 111 * @param listener the listener. 100 * @param initialFire fire a fake active-layer-changed-event right after adding 101 * the listener. The previous layers will be null. The listener is notified in the current thread. 102 */ 112 * @param initialFire use {@link #addAndFireActiveLayerChangeListener(ActiveLayerChangeListener)} instead. 113 * @deprecated Do not use the second parameter. To be removed in a few weeks. 114 */ 115 @Deprecated 103 116 public synchronized void addActiveLayerChangeListener(ActiveLayerChangeListener listener, boolean initialFire) { 117 if (initialFire) { 118 addAndFireActiveLayerChangeListener(listener); 119 } else { 120 addActiveLayerChangeListener(listener); 121 } 122 } 123 124 /** 125 * Adds a active/edit layer change listener 126 * 127 * @param listener the listener. 128 */ 129 public synchronized void addActiveLayerChangeListener(ActiveLayerChangeListener listener) { 104 130 if (activeLayerChangeListeners.contains(listener)) { 105 131 throw new IllegalArgumentException("Attempted to add listener that was already in list: " + listener); 106 132 } 107 133 activeLayerChangeListeners.add(listener); 108 if (initialFire) { 109 listener.activeOrEditLayerChanged(new ActiveLayerChangeEvent(this, null, null)); 110 } 134 } 135 136 /** 137 * Adds a active/edit layer change listener. Fire a fake active-layer-changed-event right after adding 138 * the listener. The previous layers will be null. The listener is notified in the current thread. 139 * @param listener the listener. 140 */ 141 public synchronized void addAndFireActiveLayerChangeListener(ActiveLayerChangeListener listener) { 142 addActiveLayerChangeListener(listener); 143 listener.activeOrEditLayerChanged(new ActiveLayerChangeEvent(this, null, null)); 111 144 } 112 145 -
trunk/test/unit/org/openstreetmap/josm/gui/layer/MainLayerManagerTest.java
r10279 r10332 110 110 } 111 111 112 /** 113 * Test {@link MainLayerManager#addActiveLayerChangeListener(ActiveLayerChangeListener)} and 114 * {@link MainLayerManager#addAndFireActiveLayerChangeListener(ActiveLayerChangeListener)} 115 */ 112 116 @Test 113 117 public void testAddActiveLayerChangeListener() { … … 118 122 119 123 CapturingActiveLayerChangeListener listener = new CapturingThreadCheckingActiveLayerChangeListener(); 120 layerManagerWithActive.addActiveLayerChangeListener(listener , false);124 layerManagerWithActive.addActiveLayerChangeListener(listener); 121 125 assertNull(listener.lastEvent); 122 126 123 127 CapturingActiveLayerChangeListener listener2 = new CapturingActiveLayerChangeListener(); 124 layerManagerWithActive.addA ctiveLayerChangeListener(listener2, true);128 layerManagerWithActive.addAndFireActiveLayerChangeListener(listener2); 125 129 assertSame(listener2.lastEvent.getPreviousActiveLayer(), null); 126 130 assertSame(listener2.lastEvent.getPreviousEditLayer(), null); … … 141 145 public void testAddActiveLayerChangeListenerTwice() { 142 146 CapturingActiveLayerChangeListener listener = new CapturingActiveLayerChangeListener(); 143 layerManagerWithActive.addActiveLayerChangeListener(listener , false);144 layerManagerWithActive.addActiveLayerChangeListener(listener , false);147 layerManagerWithActive.addActiveLayerChangeListener(listener); 148 layerManagerWithActive.addActiveLayerChangeListener(listener); 145 149 } 146 150 … … 156 160 157 161 CapturingActiveLayerChangeListener listener = new CapturingActiveLayerChangeListener(); 158 layerManagerWithActive.addActiveLayerChangeListener(listener , false);162 layerManagerWithActive.addActiveLayerChangeListener(listener); 159 163 layerManagerWithActive.removeActiveLayerChangeListener(listener); 160 164
Note:
See TracChangeset
for help on using the changeset viewer.