Changeset 10332 in josm


Ignore:
Timestamp:
2016-06-07T08:22:39+02:00 (4 years ago)
Author:
stoecker
Message:

Do not use deprecated EditLayerChangedListener - patch my Michael Zangl - gsoc-core - fix #12924

Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/event/DatasetEventManager.java

    r10308 r10332  
    1212import javax.swing.SwingUtilities;
    1313
     14import org.openstreetmap.josm.Main;
    1415import org.openstreetmap.josm.data.osm.DataSet;
    1516import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter.Listener;
    16 import org.openstreetmap.josm.gui.MapView;
    17 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     17import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     18import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    1819
    1920/**
     
    2627 *
    2728 */
    28 public class DatasetEventManager implements MapView.EditLayerChangeListener, Listener {
     29public class DatasetEventManager implements ActiveLayerChangeListener, Listener {
    2930
    3031    private static final DatasetEventManager instance = new DatasetEventManager();
     
    146147     */
    147148    public DatasetEventManager() {
    148         MapView.addEditLayerChangeListener(this);
     149        Main.getLayerManager().addActiveLayerChangeListener(this);
    149150    }
    150151
     
    171172
    172173    @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));
    184185    }
    185186
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r10304 r10332  
    396396            LayerChangeAdapter adapter = new LayerChangeAdapter(listener, initialFire);
    397397            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            }
    399403            adapter.receiveOneInitialFire = false;
    400404        }
     
    414418    public static void addEditLayerChangeListener(EditLayerChangeListener listener, boolean initialFire) {
    415419        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            }
    418426        }
    419427    }
     
    484492        initialViewport = viewportData;
    485493        layerManager.addLayerChangeListener(this);
    486         layerManager.addActiveLayerChangeListener(this, false);
     494        layerManager.addActiveLayerChangeListener(this);
    487495        Main.pref.addPreferenceChangeListener(this);
    488496
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ChangesetDialog.java

    r10179 r10332  
    4343import org.openstreetmap.josm.data.osm.event.DatasetEventManager;
    4444import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
    45 import org.openstreetmap.josm.gui.MapView;
    4645import org.openstreetmap.josm.gui.SideButton;
    4746import org.openstreetmap.josm.gui.dialogs.changeset.ChangesetCacheManager;
     
    115114        // let the model for changesets in the current selection listen to various events
    116115        ChangesetCache.getInstance().addChangesetCacheListener(inSelectionModel);
    117         MapView.addEditLayerChangeListener(inSelectionModel);
     116        Main.getLayerManager().addActiveLayerChangeListener(inSelectionModel);
    118117        DataSet.addSelectionListener(inSelectionModel);
    119118
     
    121120        // events and bootstrap it's content
    122121        ChangesetCache.getInstance().addChangesetCacheListener(inActiveDataLayerModel);
    123         MapView.addEditLayerChangeListener(inActiveDataLayerModel);
     122        Main.getLayerManager().addActiveLayerChangeListener(inActiveDataLayerModel);
    124123        OsmDataLayer editLayer = Main.main.getEditLayer();
    125124        if (editLayer != null) {
     
    134133        //
    135134        ChangesetCache.getInstance().removeChangesetCacheListener(inActiveDataLayerModel);
    136         MapView.removeEditLayerChangeListener(inActiveDataLayerModel);
     135        Main.getLayerManager().removeActiveLayerChangeListener(inActiveDataLayerModel);
    137136        OsmDataLayer editLayer = Main.main.getEditLayer();
    138137        if (editLayer != null) {
     
    143142        // listener
    144143        //
    145         MapView.removeEditLayerChangeListener(inSelectionModel);
     144        Main.getLayerManager().removeActiveLayerChangeListener(inSelectionModel);
    146145        DataSet.removeSelectionListener(inSelectionModel);
    147146    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java

    r9607 r10332  
    5555import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    5656import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
    57 import org.openstreetmap.josm.gui.MapView;
    5857import org.openstreetmap.josm.gui.NavigatableComponent;
    5958import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
     
    6261import org.openstreetmap.josm.gui.conflict.pair.ConflictResolver;
    6362import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
     63import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     64import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    6465import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    6566import org.openstreetmap.josm.gui.util.GuiHelper;
     
    7374 * @since 86
    7475 */
    75 public final class ConflictDialog extends ToggleDialog implements MapView.EditLayerChangeListener, IConflictListener, SelectionChangedListener {
     76public final class ConflictDialog extends ToggleDialog implements ActiveLayerChangeListener, IConflictListener, SelectionChangedListener {
    7677
    7778    /** the collection of conflicts displayed by this conflict dialog */
     
    170171    public void showNotify() {
    171172        DataSet.addSelectionListener(this);
    172         MapView.addEditLayerChangeListener(this, true);
     173        Main.getLayerManager().addAndFireActiveLayerChangeListener(this);
    173174        refreshView();
    174175    }
     
    176177    @Override
    177178    public void hideNotify() {
    178         MapView.removeEditLayerChangeListener(this);
     179        Main.getLayerManager().removeActiveLayerChangeListener(this);
    179180        DataSet.removeSelectionListener(this);
    180181    }
     
    279280
    280281    @Override
    281     public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {
     282    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
     283        OsmDataLayer oldLayer = e.getPreviousEditLayer();
    282284        if (oldLayer != null) {
    283285            oldLayer.getConflicts().removeConflictListener(this);
    284286        }
     287        OsmDataLayer newLayer = e.getSource().getEditLayer();
    285288        if (newLayer != null) {
    286289            newLayer.getConflicts().addConflictListener(this);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

    r10288 r10332  
    332332        MapView.addLayerChangeListener(activateLayerAction);
    333333        layerManager.addLayerChangeListener(model);
    334         layerManager.addActiveLayerChangeListener(model, true);
     334        layerManager.addAndFireActiveLayerChangeListener(model);
    335335        model.populate();
    336336    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r10217 r10332  
    4646import org.openstreetmap.josm.data.SelectionChangedListener;
    4747import org.openstreetmap.josm.data.coor.LatLon;
     48import org.openstreetmap.josm.data.osm.DataSet;
    4849import org.openstreetmap.josm.data.osm.Node;
    4950import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    6566import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    6667import org.openstreetmap.josm.gui.DefaultNameFormatter;
    67 import org.openstreetmap.josm.gui.MapView;
    68 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;
    6968import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
    7069import org.openstreetmap.josm.gui.PopupMenuHandler;
     
    7271import org.openstreetmap.josm.gui.datatransfer.PrimitiveTransferable;
    7372import org.openstreetmap.josm.gui.history.HistoryBrowserDialogManager;
     73import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     74import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    7475import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    7576import org.openstreetmap.josm.gui.util.GuiHelper;
     
    177178    @Override
    178179    public void showNotify() {
    179         MapView.addEditLayerChangeListener(model);
    180180        SelectionEventManager.getInstance().addSelectionListener(actShowHistory, FireMode.IN_EDT_CONSOLIDATED);
    181181        SelectionEventManager.getInstance().addSelectionListener(model, FireMode.IN_EDT_CONSOLIDATED);
    182182        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);
    190186        actSearch.updateEnabledState();
    191187    }
     
    193189    @Override
    194190    public void hideNotify() {
    195         MapView.removeEditLayerChangeListener(actSearch);
    196         MapView.removeEditLayerChangeListener(model);
     191        Main.getLayerManager().removeActiveLayerChangeListener(actSearch);
     192        Main.getLayerManager().removeActiveLayerChangeListener(model);
    197193        SelectionEventManager.getInstance().removeSelectionListener(actShowHistory);
    198194        SelectionEventManager.getInstance().removeSelectionListener(model);
     
    296292     * Launches the search dialog
    297293     */
    298     static class SearchAction extends AbstractAction implements EditLayerChangeListener {
     294    static class SearchAction extends AbstractAction implements ActiveLayerChangeListener {
    299295        /**
    300296         * Constructs a new {@code SearchAction}.
     
    318314
    319315        @Override
    320         public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {
     316        public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
    321317            updateEnabledState();
    322318        }
     
    480476     */
    481477    private static class SelectionListModel extends AbstractListModel<OsmPrimitive>
    482     implements EditLayerChangeListener, SelectionChangedListener, DataSetListener {
     478    implements ActiveLayerChangeListener, SelectionChangedListener, DataSetListener {
    483479
    484480        private static final int SELECTION_HISTORY_SIZE = 10;
     
    672668
    673669        /* ------------------------------------------------------------------------ */
    674         /* interface EditLayerChangeListener                                        */
     670        /* interface ActiveLayerChangeListener                                      */
    675671        /* ------------------------------------------------------------------------ */
    676672        @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) {
    679676                setJOSMSelection(null);
    680677                history = null;
    681678            } else {
    682                 history = newLayer.data.getSelectionHistory();
    683                 setJOSMSelection(newLayer.data.getAllSelected());
     679                history = newData.getSelectionHistory();
     680                setJOSMSelection(newData.getAllSelected());
    684681            }
    685682        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentPanel.java

    r10212 r10332  
    4242import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
    4343import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    44 import org.openstreetmap.josm.gui.MapView;
    45 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;
    4644import org.openstreetmap.josm.gui.help.HelpUtil;
    4745import org.openstreetmap.josm.gui.history.HistoryBrowserDialogManager;
    4846import org.openstreetmap.josm.gui.history.HistoryLoadTask;
    4947import org.openstreetmap.josm.gui.io.DownloadPrimitivesWithReferrersTask;
     48import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     49import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    5050import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    5151import org.openstreetmap.josm.gui.util.GuiHelper;
     
    5454import org.openstreetmap.josm.tools.ImageProvider;
    5555import org.openstreetmap.josm.tools.Utils;
     56import org.openstreetmap.josm.tools.bugreport.BugReport;
    5657import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler;
    5758
     
    9091        actSelectInCurrentLayerAction = new SelectInCurrentLayerAction();
    9192        model.getSelectionModel().addListSelectionListener(actSelectInCurrentLayerAction);
    92         MapView.addEditLayerChangeListener(actSelectInCurrentLayerAction);
     93        Main.getLayerManager().addActiveLayerChangeListener(actSelectInCurrentLayerAction);
    9394
    9495        actZoomInCurrentLayerAction = new ZoomInCurrentLayerAction();
    9596        model.getSelectionModel().addListSelectionListener(actZoomInCurrentLayerAction);
    96         MapView.addEditLayerChangeListener(actZoomInCurrentLayerAction);
     97        Main.getLayerManager().addActiveLayerChangeListener(actZoomInCurrentLayerAction);
    9798
    9899        addComponentListener(
     
    102103                        // make sure the listener is unregistered when the panel becomes
    103104                        // 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                        }
    106111                    }
    107112                }
     
    325330    }
    326331
    327     abstract class SelectionBasedAction extends AbstractAction implements ListSelectionListener, EditLayerChangeListener {
     332    abstract class SelectionBasedAction extends AbstractAction implements ListSelectionListener, ActiveLayerChangeListener {
    328333
    329334        protected Set<OsmPrimitive> getTarget() {
     
    356361
    357362        @Override
    358         public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {
     363        public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
    359364            updateEnabledState();
    360365        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetDetailPanel.java

    r10124 r10332  
    3535import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3636import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    37 import org.openstreetmap.josm.gui.MapView;
    38 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;
    3937import org.openstreetmap.josm.gui.help.HelpUtil;
     38import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     39import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    4040import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    4141import org.openstreetmap.josm.gui.widgets.JosmTextArea;
     
    8686
    8787        tb.add(actSelectInCurrentLayer);
    88         MapView.addEditLayerChangeListener(actSelectInCurrentLayer);
     88        Main.getLayerManager().addActiveLayerChangeListener(actSelectInCurrentLayer);
    8989
    9090        tb.add(actZoomInCurrentLayerAction);
    91         MapView.addEditLayerChangeListener(actZoomInCurrentLayerAction);
     91        Main.getLayerManager().addActiveLayerChangeListener(actZoomInCurrentLayerAction);
    9292
    9393        addComponentListener(
     
    9797                        // make sure the listener is unregistered when the panel becomes
    9898                        // invisible
    99                         MapView.removeEditLayerChangeListener(actSelectInCurrentLayer);
    100                         MapView.removeEditLayerChangeListener(actZoomInCurrentLayerAction);
     99                        Main.getLayerManager().removeActiveLayerChangeListener(actSelectInCurrentLayer);
     100                        Main.getLayerManager().removeActiveLayerChangeListener(actZoomInCurrentLayerAction);
    101101                    }
    102102                }
     
    318318     *
    319319     */
    320     class SelectInCurrentLayerAction extends AbstractAction implements EditLayerChangeListener {
     320    class SelectInCurrentLayerAction extends AbstractAction implements ActiveLayerChangeListener {
    321321
    322322        SelectInCurrentLayerAction() {
     
    369369
    370370        @Override
    371         public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {
     371        public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
    372372            updateEnabledState();
    373373        }
     
    379379     *
    380380     */
    381     class ZoomInCurrentLayerAction extends AbstractAction implements EditLayerChangeListener {
     381    class ZoomInCurrentLayerAction extends AbstractAction implements ActiveLayerChangeListener {
    382382
    383383        ZoomInCurrentLayerAction() {
     
    431431
    432432        @Override
    433         public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {
     433        public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
    434434            updateEnabledState();
    435435        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetInSelectionListModel.java

    r9059 r10332  
    77
    88import org.openstreetmap.josm.data.SelectionChangedListener;
     9import org.openstreetmap.josm.data.osm.DataSet;
    910import org.openstreetmap.josm.data.osm.OsmPrimitive;
    10 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;
    11 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     11import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     12import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    1213
    13 public class ChangesetInSelectionListModel extends ChangesetListModel implements SelectionChangedListener, EditLayerChangeListener {
     14public class ChangesetInSelectionListModel extends ChangesetListModel implements SelectionChangedListener, ActiveLayerChangeListener {
    1415
    1516    public ChangesetInSelectionListModel(DefaultListSelectionModel selectionModel) {
     
    2930    /* ---------------------------------------------------------------------------- */
    3031    @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) {
    3335            setChangesets(null);
    3436        } else {
    35             initFromPrimitives((newLayer).data.getAllSelected());
     37            initFromPrimitives(newData.getAllSelected());
    3638        }
    3739    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetsInActiveDataLayerListModel.java

    r8413 r10332  
    1313import org.openstreetmap.josm.data.osm.event.TagsChangedEvent;
    1414import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
    15 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;
     15import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     16import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    1617import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1718
     
    2021 *
    2122 */
    22 public class ChangesetsInActiveDataLayerListModel extends ChangesetListModel implements DataSetListener, EditLayerChangeListener {
     23public class ChangesetsInActiveDataLayerListModel extends ChangesetListModel implements DataSetListener, ActiveLayerChangeListener {
    2324
    2425    public ChangesetsInActiveDataLayerListModel(DefaultListSelectionModel selectionModel) {
     
    7071
    7172    /* ------------------------------------------------------------------------------ */
    72     /* interface EditLayerListener                                                    */
     73    /* interface ActiveLayerChangeListener                                                    */
    7374    /* ------------------------------------------------------------------------------ */
    7475    @Override
    75     public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {
     76    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
    7677        // just init the model content. Don't register as DataSetListener. The mode
    7778        // 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);
    8082        } else {
    8183            initFromDataSet(null);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r10254 r10332  
    8585import org.openstreetmap.josm.gui.DefaultNameFormatter;
    8686import org.openstreetmap.josm.gui.ExtendedDialog;
    87 import org.openstreetmap.josm.gui.MapView;
    8887import org.openstreetmap.josm.gui.PopupMenuHandler;
    8988import org.openstreetmap.josm.gui.SideButton;
     
    9190import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
    9291import org.openstreetmap.josm.gui.help.HelpUtil;
    93 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     92import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     93import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    9494import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset;
    9595import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetHandler;
    9696import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType;
    97 import org.openstreetmap.josm.gui.util.GuiHelper;
    9897import org.openstreetmap.josm.gui.util.HighlightHelper;
    9998import org.openstreetmap.josm.gui.widgets.CompileSearchTextDecorator;
     
    130129 */
    131130public class PropertiesDialog extends ToggleDialog
    132 implements SelectionChangedListener, MapView.EditLayerChangeListener, DataSetListenerAdapter.Listener {
     131implements SelectionChangedListener, ActiveLayerChangeListener, DataSetListenerAdapter.Listener {
    133132
    134133    /**
     
    590589        DatasetEventManager.getInstance().addDatasetListener(dataChangedAdapter, FireMode.IN_EDT_CONSOLIDATED);
    591590        SelectionEventManager.getInstance().addSelectionListener(this, FireMode.IN_EDT_CONSOLIDATED);
    592         MapView.addEditLayerChangeListener(this);
     591        Main.getLayerManager().addActiveLayerChangeListener(this);
    593592        for (JosmAction action : josmActions) {
    594593            Main.registerActionShortcut(action);
     
    601600        DatasetEventManager.getInstance().removeDatasetListener(dataChangedAdapter);
    602601        SelectionEventManager.getInstance().removeSelectionListener(this);
    603         MapView.removeEditLayerChangeListener(this);
     602        Main.getLayerManager().removeActiveLayerChangeListener(this);
    604603        for (JosmAction action : josmActions) {
    605604            Main.unregisterActionShortcut(action);
     
    770769
    771770    /* ---------------------------------------------------------------------------------- */
    772     /* EditLayerChangeListener                                                            */
     771    /* ActiveLayerChangeListener                                                          */
    773772    /* ---------------------------------------------------------------------------------- */
    774773    @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        }
    777778        // it is time to save history of tags
    778         GuiHelper.runInEDT(new Runnable() {
    779             @Override public void run() {
    780                 updateSelection();
    781             }
    782         });
     779        updateSelection();
    783780    }
    784781
  • trunk/src/org/openstreetmap/josm/gui/layer/MainLayerManager.java

    r10279 r10332  
    7676        }
    7777
     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
    7890        @Override
    7991        public MainLayerManager getSource() {
     
    98110     *
    99111     * @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
    103116    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) {
    104130        if (activeLayerChangeListeners.contains(listener)) {
    105131            throw new IllegalArgumentException("Attempted to add listener that was already in list: " + listener);
    106132        }
    107133        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));
    111144    }
    112145
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/MainLayerManagerTest.java

    r10279 r10332  
    110110    }
    111111
     112    /**
     113     * Test {@link MainLayerManager#addActiveLayerChangeListener(ActiveLayerChangeListener)} and
     114     * {@link MainLayerManager#addAndFireActiveLayerChangeListener(ActiveLayerChangeListener)}
     115     */
    112116    @Test
    113117    public void testAddActiveLayerChangeListener() {
     
    118122
    119123        CapturingActiveLayerChangeListener listener = new CapturingThreadCheckingActiveLayerChangeListener();
    120         layerManagerWithActive.addActiveLayerChangeListener(listener, false);
     124        layerManagerWithActive.addActiveLayerChangeListener(listener);
    121125        assertNull(listener.lastEvent);
    122126
    123127        CapturingActiveLayerChangeListener listener2 = new CapturingActiveLayerChangeListener();
    124         layerManagerWithActive.addActiveLayerChangeListener(listener2, true);
     128        layerManagerWithActive.addAndFireActiveLayerChangeListener(listener2);
    125129        assertSame(listener2.lastEvent.getPreviousActiveLayer(), null);
    126130        assertSame(listener2.lastEvent.getPreviousEditLayer(), null);
     
    141145    public void testAddActiveLayerChangeListenerTwice() {
    142146        CapturingActiveLayerChangeListener listener = new CapturingActiveLayerChangeListener();
    143         layerManagerWithActive.addActiveLayerChangeListener(listener, false);
    144         layerManagerWithActive.addActiveLayerChangeListener(listener, false);
     147        layerManagerWithActive.addActiveLayerChangeListener(listener);
     148        layerManagerWithActive.addActiveLayerChangeListener(listener);
    145149    }
    146150
     
    156160
    157161        CapturingActiveLayerChangeListener listener = new CapturingActiveLayerChangeListener();
    158         layerManagerWithActive.addActiveLayerChangeListener(listener, false);
     162        layerManagerWithActive.addActiveLayerChangeListener(listener);
    159163        layerManagerWithActive.removeActiveLayerChangeListener(listener);
    160164
Note: See TracChangeset for help on using the changeset viewer.