Changeset 10345 in josm


Ignore:
Timestamp:
2016-06-08T23:17:19+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #12937 - Use the new LayerChangeListener (patch by michael2402) - gsoc-core

Location:
trunk/src/org/openstreetmap/josm
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/ExtensionFileFilter.java

    r10299 r10345  
    108108                FileExporter exporter = exporterClass.getConstructor().newInstance();
    109109                exporters.add(exporter);
    110                 MapView.addLayerChangeListener(exporter);
     110                Main.getLayerManager().addAndFireActiveLayerChangeListener(exporter);
    111111            } catch (ReflectiveOperationException e) {
    112112                if (Main.isDebugEnabled()) {
  • trunk/src/org/openstreetmap/josm/actions/JosmAction.java

    r10212 r10345  
    1616import org.openstreetmap.josm.data.osm.DataSet;
    1717import org.openstreetmap.josm.data.osm.OsmPrimitive;
    18 import org.openstreetmap.josm.gui.MapView;
    19 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    20 import org.openstreetmap.josm.gui.layer.Layer;
     18import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     19import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     20import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    2121import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2222import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor;
    23 import org.openstreetmap.josm.gui.util.GuiHelper;
    2423import org.openstreetmap.josm.tools.Destroyable;
    2524import org.openstreetmap.josm.tools.ImageProvider;
     
    184183            Main.unregisterActionShortcut(this);
    185184        }
    186         MapView.removeLayerChangeListener(layerChangeAdapter);
     185        if (layerChangeAdapter != null) {
     186            Main.getLayerManager().removeActiveLayerChangeListener(layerChangeAdapter);
     187        }
    187188        DataSet.removeSelectionListener(selectionChangeAdapter);
    188189    }
     
    226227    protected void installAdapters() {
    227228        // make this action listen to layer change and selection change events
    228         //
    229229        layerChangeAdapter = new LayerChangeAdapter();
    230230        selectionChangeAdapter = new SelectionChangeAdapter();
    231         MapView.addLayerChangeListener(layerChangeAdapter);
     231        Main.getLayerManager().addActiveLayerChangeListener(layerChangeAdapter);
    232232        DataSet.addSelectionListener(selectionChangeAdapter);
    233233        initEnabledState();
     
    291291
    292292    /**
    293      * Adapter for layer change events
    294      *
    295      */
    296     protected class LayerChangeAdapter implements MapView.LayerChangeListener {
    297         private void updateEnabledStateInEDT() {
    298             GuiHelper.runInEDT(new Runnable() {
    299                 @Override public void run() {
    300                     updateEnabledState();
    301                 }
    302             });
    303         }
    304 
     293     * Adapter for layer change events. Runs updateEnabledState() whenever the active layer changed.
     294     */
     295    protected class LayerChangeAdapter implements ActiveLayerChangeListener {
    305296        @Override
    306         public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    307             updateEnabledStateInEDT();
     297        public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
     298            updateEnabledState();
    308299        }
    309300
    310301        @Override
    311         public void layerAdded(Layer newLayer) {
    312             updateEnabledStateInEDT();
    313         }
    314 
    315         @Override
    316         public void layerRemoved(Layer oldLayer) {
    317             updateEnabledStateInEDT();
    318         }
    319     }
    320 
    321     /**
    322      * Adapter for selection change events
     302        public String toString() {
     303            return "LayerChangeAdapter [" + JosmAction.this.toString() + ']';
     304        }
     305    }
     306
     307    /**
     308     * Adapter for selection change events. Runs updateEnabledState() whenever the selection changed.
    323309     */
    324310    protected class SelectionChangeAdapter implements SelectionChangedListener {
     
    327313            updateEnabledState(newSelection);
    328314        }
     315
     316        @Override
     317        public String toString() {
     318            return "SelectionChangeAdapter [" + JosmAction.this.toString() + ']';
     319        }
    329320    }
    330321}
  • trunk/src/org/openstreetmap/josm/actions/relation/RecentRelationsAction.java

    r10134 r10345  
    2121import org.openstreetmap.josm.data.osm.Relation;
    2222import org.openstreetmap.josm.gui.DefaultNameFormatter;
    23 import org.openstreetmap.josm.gui.MapView;
    24 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    2523import org.openstreetmap.josm.gui.SideButton;
    2624import org.openstreetmap.josm.gui.layer.Layer;
     25import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     26import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     27import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
     28import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
     29import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     30import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    2731import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2832import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;
     
    3337 * Action for accessing recent relations.
    3438 */
    35 public class RecentRelationsAction implements ActionListener, CommandQueueListener, LayerChangeListener {
     39public class RecentRelationsAction implements ActionListener, CommandQueueListener, LayerChangeListener, ActiveLayerChangeListener {
    3640
    3741    private final SideButton editButton;
     
    4852        arrow.setToolTipText(tr("List of recent relations"));
    4953        Main.main.undoRedo.addCommandQueueListener(this);
    50         MapView.addLayerChangeListener(this);
     54        Main.getLayerManager().addLayerChangeListener(this);
     55        Main.getLayerManager().addActiveLayerChangeListener(this);
    5156        enableArrow();
    5257        shortcut = Shortcut.registerShortcut(
     
    109114
    110115    @Override
    111     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     116    public void layerAdded(LayerAddEvent e) {
    112117        enableArrow();
    113118    }
    114119
    115120    @Override
    116     public void layerAdded(Layer newLayer) {
     121    public void layerRemoving(LayerRemoveEvent e) {
    117122        enableArrow();
    118123    }
    119124
    120125    @Override
    121     public void layerRemoved(Layer oldLayer) {
     126    public void layerOrderChanged(LayerOrderChangeEvent e) {
     127        enableArrow();
     128    }
     129
     130    @Override
     131    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
    122132        enableArrow();
    123133    }
     
    182192        }
    183193    }
     194
    184195}
  • trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java

    r8510 r10345  
    1010import org.openstreetmap.josm.data.osm.DataSet;
    1111import org.openstreetmap.josm.data.osm.OsmPrimitive;
    12 import org.openstreetmap.josm.gui.MapView;
    1312import org.openstreetmap.josm.gui.layer.Layer;
     13import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     14import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     15import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
     16import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
    1417import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;
    1518import org.openstreetmap.josm.tools.CheckParameterUtil;
    1619
    17 public class UndoRedoHandler implements MapView.LayerChangeListener {
     20public class UndoRedoHandler implements LayerChangeListener {
    1821
    1922    /**
     
    3235     */
    3336    public UndoRedoHandler() {
    34         MapView.addLayerChangeListener(this);
     37        Main.getLayerManager().addLayerChangeListener(this);
    3538    }
    3639
     
    170173
    171174    @Override
    172     public void layerRemoved(Layer oldLayer) {
    173         clean(oldLayer);
     175    public void layerRemoving(LayerRemoveEvent e) {
     176        clean(e.getRemovedLayer());
    174177    }
    175178
    176179    @Override
    177     public void layerAdded(Layer newLayer) {
     180    public void layerAdded(LayerAddEvent e) {
    178181        // Do nothing
    179182    }
    180183
    181184    @Override
    182     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     185    public void layerOrderChanged(LayerOrderChangeEvent e) {
    183186        // Do nothing
    184187    }
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/MultipolygonCache.java

    r10312 r10345  
    2828import org.openstreetmap.josm.data.projection.Projection;
    2929import org.openstreetmap.josm.data.projection.ProjectionChangeListener;
    30 import org.openstreetmap.josm.gui.MapView;
    31 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    3230import org.openstreetmap.josm.gui.NavigatableComponent;
    33 import org.openstreetmap.josm.gui.layer.Layer;
     31import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     32import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     33import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
     34import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
    3435import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    3536
     
    5152        Main.addProjectionChangeListener(this);
    5253        DataSet.addSelectionListener(this);
    53         MapView.addLayerChangeListener(this);
     54        Main.getLayerManager().addLayerChangeListener(this);
    5455    }
    5556
     
    286287
    287288    @Override
    288     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     289    public void layerAdded(LayerAddEvent e) {
    289290        // Do nothing
    290291    }
    291292
    292293    @Override
    293     public void layerAdded(Layer newLayer) {
     294    public void layerOrderChanged(LayerOrderChangeEvent e) {
    294295        // Do nothing
    295296    }
    296297
    297298    @Override
    298     public void layerRemoved(Layer oldLayer) {
    299         if (oldLayer instanceof OsmDataLayer) {
    300             clear(((OsmDataLayer) oldLayer).data);
     299    public void layerRemoving(LayerRemoveEvent e) {
     300        if (e.getRemovedLayer() instanceof OsmDataLayer) {
     301            clear(((OsmDataLayer) e.getRemovedLayer()).data);
    301302        }
    302303    }
  • trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java

    r10173 r10345  
    3333import org.openstreetmap.josm.data.imagery.ImageryLayerInfo;
    3434import org.openstreetmap.josm.data.imagery.Shape;
    35 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    3635import org.openstreetmap.josm.gui.layer.ImageryLayer;
    37 import org.openstreetmap.josm.gui.layer.Layer;
     36import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     37import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     38import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
     39import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
    3840import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreference;
    3941import org.openstreetmap.josm.tools.ImageProvider;
     
    111113        super(trc("menu", "Imagery"));
    112114        setupMenuScroller();
    113         MapView.addLayerChangeListener(this);
     115        Main.getLayerManager().addLayerChangeListener(this);
    114116        // build dynamically
    115117        addMenuListener(new MenuListener() {
     
    210212
    211213    private JMenuItem getNewOffsetMenu() {
    212         if (!Main.isDisplayingMapView()) {
    213             offsetAction.setEnabled(false);
    214             return singleOffset;
    215         }
    216         Collection<ImageryLayer> layers = Main.map.mapView.getLayersOfType(ImageryLayer.class);
     214        Collection<ImageryLayer> layers = Main.getLayerManager().getLayersOfType(ImageryLayer.class);
    217215        if (layers.isEmpty()) {
    218216            offsetAction.setEnabled(false);
     
    239237
    240238    @Override
    241     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    242         // Do nothing
     239    public void layerAdded(LayerAddEvent e) {
     240        if (e.getAddedLayer() instanceof ImageryLayer) {
     241            refreshOffsetMenu();
     242        }
    243243    }
    244244
    245245    @Override
    246     public void layerAdded(Layer newLayer) {
    247         if (newLayer instanceof ImageryLayer) {
     246    public void layerRemoving(LayerRemoveEvent e) {
     247        if (e.getRemovedLayer() instanceof ImageryLayer) {
    248248            refreshOffsetMenu();
    249249        }
     
    251251
    252252    @Override
    253     public void layerRemoved(Layer oldLayer) {
    254         if (oldLayer instanceof ImageryLayer) {
    255             refreshOffsetMenu();
    256         }
     253    public void layerOrderChanged(LayerOrderChangeEvent e) {
     254        refreshOffsetMenu();
    257255    }
    258256
  • trunk/src/org/openstreetmap/josm/gui/MainFrame.java

    r10340 r10345  
    114114                refreshTitle();
    115115            }
    116         }, false);
     116        });
    117117        Main.getLayerManager().addLayerChangeListener(new ManageLayerListeners(), true);
    118118
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r10340 r10345  
    117117import org.openstreetmap.josm.gui.dialogs.MenuItemSearchDialog;
    118118import org.openstreetmap.josm.gui.io.RecentlyOpenedFilesMenu;
    119 import org.openstreetmap.josm.gui.layer.Layer;
     119import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     120import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    120121import org.openstreetmap.josm.gui.mappaint.MapPaintMenu;
    121122import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreference;
     
    822823        windowMenu.addMenuListener(menuSeparatorHandler);
    823824
    824         new PresetsMenuEnabler(presetsMenu).refreshEnabled();
     825        new PresetsMenuEnabler(presetsMenu);
    825826    }
    826827
     
    886887    }
    887888
    888     static class PresetsMenuEnabler implements MapView.LayerChangeListener {
     889    static class PresetsMenuEnabler implements ActiveLayerChangeListener {
    889890        private final JMenu presetsMenu;
    890891
    891892        PresetsMenuEnabler(JMenu presetsMenu) {
    892             MapView.addLayerChangeListener(this);
    893893            this.presetsMenu = presetsMenu;
    894         }
    895 
    896         /**
    897          * Refreshes the enabled state
    898          */
    899         protected void refreshEnabled() {
    900             presetsMenu.setEnabled(Main.main.hasEditLayer());
     894            Main.getLayerManager().addAndFireActiveLayerChangeListener(this);
    901895        }
    902896
    903897        @Override
    904         public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    905             refreshEnabled();
    906         }
    907 
    908         @Override
    909         public void layerAdded(Layer newLayer) {
    910             refreshEnabled();
    911         }
    912 
    913         @Override
    914         public void layerRemoved(Layer oldLayer) {
    915             refreshEnabled();
    916         }
    917     }
    918 
     898        public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
     899            presetsMenu.setEnabled(e.getSource().getEditLayer() != null);
     900        }
     901    }
    919902}
  • trunk/src/org/openstreetmap/josm/gui/MapFrame.java

    r10271 r10345  
    3838import javax.swing.JToolBar;
    3939import javax.swing.KeyStroke;
    40 import javax.swing.SwingUtilities;
    4140import javax.swing.border.Border;
    4241import javax.swing.event.PopupMenuEvent;
     
    5958import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
    6059import org.openstreetmap.josm.data.ViewportData;
    61 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    6260import org.openstreetmap.josm.gui.dialogs.ChangesetDialog;
    6361import org.openstreetmap.josm.gui.dialogs.CommandStackDialog;
     
    7775import org.openstreetmap.josm.gui.layer.Layer;
    7876import org.openstreetmap.josm.gui.layer.LayerManager;
     77import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     78import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     79import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
     80import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
     81import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     82import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    7983import org.openstreetmap.josm.gui.util.AdvancedKeyPressDetector;
    8084import org.openstreetmap.josm.tools.Destroyable;
     
    9094 * @author imi
    9195 */
    92 public class MapFrame extends JPanel implements Destroyable, LayerChangeListener {
     96public class MapFrame extends JPanel implements Destroyable, ActiveLayerChangeListener, LayerChangeListener {
    9397
    9498    /**
     
    285289        // status line below the map
    286290        statusLine = new MapStatus(this);
    287         MapView.addLayerChangeListener(this);
     291        Main.getLayerManager().addLayerChangeListener(this);
     292        Main.getLayerManager().addActiveLayerChangeListener(this);
    288293
    289294        boolean unregisterTab = Shortcut.findShortcut(KeyEvent.VK_TAB, 0) != null;
     
    329334    @Override
    330335    public void destroy() {
    331         MapView.removeLayerChangeListener(this);
     336        Main.getLayerManager().removeLayerChangeListener(this);
     337        Main.getLayerManager().removeActiveLayerChangeListener(this);
    332338        dialogsPanel.destroy();
    333339        Main.pref.removePreferenceChangeListener(sidetoolbarPreferencesChangedListener);
     
    757763
    758764    @Override
    759     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     765    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
    760766        boolean modeChanged = false;
     767        Layer newLayer = e.getSource().getActiveLayer();
    761768        if (mapMode == null || !mapMode.layerIsSupported(newLayer)) {
    762769            MapMode newMapMode = getLastMapMode(newLayer);
     
    771778        }
    772779        // if this is really a change (and not the first active layer)
    773         if (oldLayer != null) {
     780        if (e.getPreviousActiveLayer() != null) {
    774781            if (!modeChanged && mapMode != null) {
    775782                // Let mapmodes know about new active layer
     
    783790        // After all listeners notice new layer, some buttons will be disabled/enabled
    784791        // and possibly need to be hidden/shown.
    785         SwingUtilities.invokeLater(new Runnable() {
    786             @Override public void run() {
    787                 validateToolBarsVisibility();
    788             }
    789         });
     792        validateToolBarsVisibility();
    790793    }
    791794
     
    803806
    804807    @Override
    805     public void layerAdded(Layer newLayer) {
    806         // Do nothing
     808    public void layerAdded(LayerAddEvent e) {
     809        // ignored
    807810    }
    808811
    809812    @Override
    810     public void layerRemoved(Layer oldLayer) {
    811         lastMapMode.remove(oldLayer);
    812     }
     813    public void layerRemoving(LayerRemoveEvent e) {
     814        lastMapMode.remove(e.getRemovedLayer());
     815    }
     816
     817    @Override
     818    public void layerOrderChanged(LayerOrderChangeEvent e) {
     819        // ignored
     820    }
     821
    813822}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

    r10332 r10345  
    186186        DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
    187187        selectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    188         model = new LayerListModel(selectionModel);
     188        model = new LayerListModel(layerManager, selectionModel);
    189189
    190190        // create the list control
    191191        //
    192         layerList = new LayerList(model, layerManager);
     192        layerList = new LayerList(model);
    193193        layerList.setSelectionModel(selectionModel);
    194194        layerList.addMouseListener(new PopupMenuHandler());
     
    330330    @Override
    331331    public void showNotify() {
    332         MapView.addLayerChangeListener(activateLayerAction);
     332        layerManager.addActiveLayerChangeListener(activateLayerAction);
    333333        layerManager.addLayerChangeListener(model);
    334334        layerManager.addAndFireActiveLayerChangeListener(model);
     
    340340        layerManager.removeLayerChangeListener(model);
    341341        layerManager.removeActiveLayerChangeListener(model);
    342         MapView.removeLayerChangeListener(activateLayerAction);
     342        layerManager.removeActiveLayerChangeListener(activateLayerAction);
    343343    }
    344344
     
    649649        private final CopyOnWriteArrayList<LayerListModelListener> listeners;
    650650        private LayerList layerList;
     651        private final MainLayerManager layerManager;
    651652
    652653        /**
    653654         * constructor
    654          *
     655         * @param layerManager The layer manager to use for the list.
    655656         * @param selectionModel the list selection model
    656657         */
    657         LayerListModel(DefaultListSelectionModel selectionModel) {
     658        LayerListModel(MainLayerManager layerManager, DefaultListSelectionModel selectionModel) {
     659            this.layerManager = layerManager;
    658660            this.selectionModel = selectionModel;
    659661            listeners = new CopyOnWriteArrayList<>();
     
    664666        }
    665667
    666         private MainLayerManager getLayerManager() {
    667             // layerList should never be null. But if it is, we should not crash.
    668             if (layerList == null) {
    669                 return new MainLayerManager();
    670             } else {
    671                 return layerList.getLayerManager();
    672             }
     668        /**
     669         * The layer manager this model is for.
     670         * @return The layer manager.
     671         */
     672        public MainLayerManager getLayerManager() {
     673            return layerManager;
    673674        }
    674675
     
    11251126     */
    11261127    static class LayerList extends JTable {
    1127         private final transient MainLayerManager layerManager;
    1128 
    1129         LayerList(LayerListModel dataModel, MainLayerManager layerManager) {
     1128
     1129        LayerList(LayerListModel dataModel) {
    11301130            super(dataModel);
    1131             this.layerManager = layerManager;
    11321131            dataModel.setLayerList(this);
    11331132        }
     
    11421141            viewport.scrollRectToVisible(rect);
    11431142        }
    1144 
    1145         /**
    1146          * Gets you the layer manager used for this list.
    1147          * @return The layer manager.
    1148          * @since 10288
    1149          */
    1150         public MainLayerManager getLayerManager() {
    1151             return layerManager;
    1152         }
    11531143    }
    11541144
  • trunk/src/org/openstreetmap/josm/gui/dialogs/NotesDialog.java

    r10162 r10345  
    3939import org.openstreetmap.josm.data.notes.NoteComment;
    4040import org.openstreetmap.josm.data.osm.NoteData;
    41 import org.openstreetmap.josm.gui.MapView;
    42 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    4341import org.openstreetmap.josm.gui.NoteInputDialog;
    4442import org.openstreetmap.josm.gui.NoteSortDialog;
    4543import org.openstreetmap.josm.gui.SideButton;
    46 import org.openstreetmap.josm.gui.layer.Layer;
     44import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     45import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     46import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
     47import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
    4748import org.openstreetmap.josm.gui.layer.NoteLayer;
    4849import org.openstreetmap.josm.tools.ImageProvider;
     
    99100        uploadAction = new UploadNotesAction();
    100101        buildDialog();
    101         MapView.addLayerChangeListener(this);
     102        Main.getLayerManager().addLayerChangeListener(this);
    102103    }
    103104
     
    170171
    171172    @Override
    172     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    173         // Do nothing
    174     }
    175 
    176     @Override
    177     public void layerAdded(Layer newLayer) {
    178         if (newLayer instanceof NoteLayer) {
    179             noteData = ((NoteLayer) newLayer).getNoteData();
     173    public void layerAdded(LayerAddEvent e) {
     174        if (e.getAddedLayer() instanceof NoteLayer) {
     175            noteData = ((NoteLayer) e.getAddedLayer()).getNoteData();
    180176            model.setData(noteData.getNotes());
    181177            setNotes(noteData.getSortedNotes());
     
    184180
    185181    @Override
    186     public void layerRemoved(Layer oldLayer) {
    187         if (oldLayer instanceof NoteLayer) {
     182    public void layerRemoving(LayerRemoveEvent e) {
     183        if (e.getRemovedLayer() instanceof NoteLayer) {
    188184            noteData = null;
    189185            model.clearData();
     
    192188            }
    193189        }
     190    }
     191
     192    @Override
     193    public void layerOrderChanged(LayerOrderChangeEvent e) {
     194        // ignored
    194195    }
    195196
  • trunk/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java

    r9136 r10345  
    3535import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3636import org.openstreetmap.josm.data.osm.User;
    37 import org.openstreetmap.josm.gui.MapView;
    3837import org.openstreetmap.josm.gui.SideButton;
    3938import org.openstreetmap.josm.gui.layer.Layer;
     39import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     40import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    4041import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    4142import org.openstreetmap.josm.gui.util.GuiHelper;
     
    5051 *
    5152 */
    52 public class UserListDialog extends ToggleDialog implements SelectionChangedListener, MapView.LayerChangeListener {
     53public class UserListDialog extends ToggleDialog implements SelectionChangedListener, ActiveLayerChangeListener {
    5354
    5455    /**
     
    7273    public void showNotify() {
    7374        DataSet.addSelectionListener(this);
    74         MapView.addLayerChangeListener(this);
     75        Main.getLayerManager().addActiveLayerChangeListener(this);
    7576    }
    7677
    7778    @Override
    7879    public void hideNotify() {
    79         MapView.removeLayerChangeListener(this);
     80        Main.getLayerManager().removeActiveLayerChangeListener(this);
    8081        DataSet.removeSelectionListener(this);
    8182    }
     
    113114
    114115    @Override
    115     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    116         if (newLayer instanceof OsmDataLayer) {
    117             refresh(((OsmDataLayer) newLayer).data.getAllSelected());
     116    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
     117        Layer activeLayer = e.getSource().getActiveLayer();
     118        if (activeLayer instanceof OsmDataLayer) {
     119            refresh(((OsmDataLayer) activeLayer).data.getAllSelected());
    118120        } else {
    119121            refresh(null);
    120122        }
    121     }
    122 
    123     @Override
    124     public void layerAdded(Layer newLayer) {
    125         // do nothing
    126     }
    127 
    128     @Override
    129     public void layerRemoved(Layer oldLayer) {
    130         // do nothing
    131123    }
    132124
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java

    r9078 r10345  
    4242import org.openstreetmap.josm.data.validation.TestError;
    4343import org.openstreetmap.josm.data.validation.ValidatorVisitor;
    44 import org.openstreetmap.josm.gui.MapView;
    45 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    4644import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    4745import org.openstreetmap.josm.gui.PopupMenuHandler;
    4846import org.openstreetmap.josm.gui.SideButton;
    4947import org.openstreetmap.josm.gui.dialogs.validator.ValidatorTreePanel;
    50 import org.openstreetmap.josm.gui.layer.Layer;
     48import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     49import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    5150import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    5251import org.openstreetmap.josm.gui.preferences.validator.ValidatorPreference;
     
    6665 * @author frsantos
    6766 */
    68 public class ValidatorDialog extends ToggleDialog implements SelectionChangedListener, LayerChangeListener {
     67public class ValidatorDialog extends ToggleDialog implements SelectionChangedListener, ActiveLayerChangeListener {
    6968
    7069    /** The display tree */
     
    179178            updateSelection(ds.getAllSelected());
    180179        }
    181         MapView.addLayerChangeListener(this);
    182         Layer activeLayer = Main.map.mapView.getActiveLayer();
    183         if (activeLayer != null) {
    184             activeLayerChange(null, activeLayer);
    185         }
     180        Main.getLayerManager().addAndFireActiveLayerChangeListener(this);
    186181    }
    187182
    188183    @Override
    189184    public void hideNotify() {
    190         MapView.removeLayerChangeListener(this);
     185        Main.getLayerManager().removeActiveLayerChangeListener(this);
    191186        DataSet.removeSelectionListener(this);
    192187    }
     
    407402
    408403    @Override
    409     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    410         if (newLayer instanceof OsmDataLayer) {
    411             linkedLayer = (OsmDataLayer) newLayer;
    412             tree.setErrorList(linkedLayer.validationErrors);
    413         }
    414     }
    415 
    416     @Override
    417     public void layerAdded(Layer newLayer) {
    418         // Do nothing
    419     }
    420 
    421     @Override
    422     public void layerRemoved(Layer oldLayer) {
    423         if (oldLayer == linkedLayer) {
     404    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
     405        OsmDataLayer editLayer = e.getSource().getEditLayer();
     406        if (editLayer == null) {
    424407            tree.setErrorList(new ArrayList<TestError>());
     408        } else {
     409            tree.setErrorList(editLayer.validationErrors);
    425410        }
    426411    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/layer/ActivateLayerAction.java

    r10144 r10345  
    1010import javax.swing.AbstractAction;
    1111
    12 import org.openstreetmap.josm.Main;
    13 import org.openstreetmap.josm.gui.MapView;
    1412import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    1513import org.openstreetmap.josm.gui.dialogs.LayerListDialog.LayerListModel;
    1614import org.openstreetmap.josm.gui.help.HelpUtil;
    1715import org.openstreetmap.josm.gui.layer.Layer;
     16import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     17import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    1818import org.openstreetmap.josm.gui.util.GuiHelper;
    1919import org.openstreetmap.josm.tools.CheckParameterUtil;
     
    2626 */
    2727public final class ActivateLayerAction extends AbstractAction
    28 implements IEnabledStateUpdating, MapView.LayerChangeListener, MultikeyShortcutAction {
     28implements IEnabledStateUpdating, ActiveLayerChangeListener, MultikeyShortcutAction {
    2929    private transient Layer layer;
    3030    private transient Shortcut multikeyShortcut;
     
    7777    private void execute(Layer layer) {
    7878        // model is going to be updated via LayerChangeListener and PropertyChangeEvents
    79         Main.map.mapView.setActiveLayer(layer);
     79        model.getLayerManager().setActiveLayer(layer);
    8080        layer.setVisible(true);
    8181    }
    8282
    83     protected boolean isActiveLayer(Layer layer) {
    84         if (!Main.isDisplayingMapView())
    85             return false;
    86         return Main.map.mapView.getActiveLayer() == layer;
     83    boolean isActiveLayer(Layer layer) {
     84        return model.getLayerManager().getActiveLayer() == layer;
    8785    }
    8886
     
    106104
    107105    @Override
    108     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    109         updateEnabledState();
    110     }
    111 
    112     @Override
    113     public void layerAdded(Layer newLayer) {
    114         updateEnabledState();
    115     }
    116 
    117     @Override
    118     public void layerRemoved(Layer oldLayer) {
     106    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
    119107        updateEnabledState();
    120108    }
     
    137125        return null; // Repeating action doesn't make much sense for activating
    138126    }
     127
    139128}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r10332 r10345  
    618618        super.destroy();
    619619        Main.pref.removePreferenceChangeListener(this);
    620         for (JosmAction action : josmActions) {
    621             action.destroy();
    622         }
    623620        Container parent = pluginHook.getParent();
    624621        if (parent != null) {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationDialogManager.java

    r9371 r10345  
    1111import java.util.Objects;
    1212
     13import org.openstreetmap.josm.Main;
    1314import org.openstreetmap.josm.data.osm.Relation;
    14 import org.openstreetmap.josm.gui.MapView;
    1515import org.openstreetmap.josm.gui.layer.Layer;
     16import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     17import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     18import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
     19import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
    1620import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1721
     
    2024 *
    2125 */
    22 public class RelationDialogManager extends WindowAdapter implements MapView.LayerChangeListener {
     26public class RelationDialogManager extends WindowAdapter implements LayerChangeListener {
    2327
    2428    /** keeps track of open relation editors */
     
    3337        if (RelationDialogManager.relationDialogManager == null) {
    3438            RelationDialogManager.relationDialogManager = new RelationDialogManager();
    35             MapView.addLayerChangeListener(RelationDialogManager.relationDialogManager);
     39            Main.getLayerManager().addLayerChangeListener(RelationDialogManager.relationDialogManager);
    3640        }
    3741        return RelationDialogManager.relationDialogManager;
     
    167171    }
    168172
    169     /**
    170      * called when a layer is removed
    171      *
    172      */
    173     @Override
    174     public void layerRemoved(Layer oldLayer) {
     173    @Override
     174    public void layerRemoving(LayerRemoveEvent e) {
     175        Layer oldLayer = e.getRemovedLayer();
    175176        if (!(oldLayer instanceof OsmDataLayer))
    176177            return;
     
    190191
    191192    @Override
    192     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    193         // do nothing
    194     }
    195 
    196     @Override
    197     public void layerAdded(Layer newLayer) {
    198         // do nothing
     193    public void layerAdded(LayerAddEvent e) {
     194        // ignore
     195    }
     196
     197    @Override
     198    public void layerOrderChanged(LayerOrderChangeEvent e) {
     199        // ignore
    199200    }
    200201
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/SelectionTableModel.java

    r10089 r10345  
    1111import org.openstreetmap.josm.data.osm.DataSet;
    1212import org.openstreetmap.josm.data.osm.OsmPrimitive;
    13 import org.openstreetmap.josm.gui.MapView;
    14 import org.openstreetmap.josm.gui.layer.Layer;
     13import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     14import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     15import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
     16import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
     17import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     18import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    1519import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1620import org.openstreetmap.josm.tools.CheckParameterUtil;
    1721
    18 public class SelectionTableModel extends AbstractTableModel implements SelectionChangedListener, MapView.LayerChangeListener {
     22public class SelectionTableModel extends AbstractTableModel implements SelectionChangedListener, ActiveLayerChangeListener, LayerChangeListener {
    1923
    2024    /** this selection table model only displays selected primitives in this layer */
     
    4044    public void register() {
    4145        DataSet.addSelectionListener(this);
    42         MapView.addLayerChangeListener(this);
     46        Main.getLayerManager().addActiveLayerChangeListener(this);
    4347    }
    4448
     
    4852    public void unregister() {
    4953        DataSet.removeSelectionListener(this);
    50         MapView.removeLayerChangeListener(this);
     54        Main.getLayerManager().removeActiveLayerChangeListener(this);
    5155    }
    5256
     
    6973
    7074    @Override
    71     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    72         if (oldLayer  == layer) {
     75    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
     76        if (e.getPreviousActiveLayer()  == layer) {
    7377            cache.clear();
    7478        }
    75         if (newLayer == layer) {
    76             cache.addAll(((OsmDataLayer) newLayer).data.getAllSelected());
     79        if (e.getSource().getActiveLayer() == layer) {
     80            cache.addAll(layer.data.getAllSelected());
    7781        }
    7882        fireTableDataChanged();
     
    8084
    8185    @Override
    82     public void layerAdded(Layer newLayer) {
     86    public void layerAdded(LayerAddEvent e) {
    8387        // do nothing
    8488    }
    8589
    8690    @Override
    87     public void layerRemoved(Layer oldLayer) {
    88         if (oldLayer == layer) {
     91    public void layerRemoving(LayerRemoveEvent e) {
     92        if (e.getRemovedLayer() == layer) {
    8993            unregister();
    9094        }
    9195        this.cache.clear();
    9296        fireTableDataChanged();
     97    }
     98
     99    @Override
     100    public void layerOrderChanged(LayerOrderChangeEvent e) {
     101        // do nothing
    93102    }
    94103
     
    128137        return cache.get(row);
    129138    }
     139
    130140}
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserDialogManager.java

    r10212 r10345  
    2222import org.openstreetmap.josm.data.osm.history.History;
    2323import org.openstreetmap.josm.data.osm.history.HistoryDataSet;
    24 import org.openstreetmap.josm.gui.MapView;
    25 import org.openstreetmap.josm.gui.layer.Layer;
     24import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     25import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     26import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
     27import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
    2628import org.openstreetmap.josm.tools.Predicate;
    2729import org.openstreetmap.josm.tools.Utils;
     
    3335 * @since 2019
    3436 */
    35 public final class HistoryBrowserDialogManager implements MapView.LayerChangeListener {
     37public final class HistoryBrowserDialogManager implements LayerChangeListener {
    3638
    3739    private static final String WINDOW_GEOMETRY_PREF = HistoryBrowserDialogManager.class.getName() + ".geometry";
     
    5456    protected HistoryBrowserDialogManager() {
    5557        dialogs = new HashMap<>();
    56         MapView.addLayerChangeListener(this);
     58        Main.getLayerManager().addLayerChangeListener(this);
    5759    }
    5860
     
    153155    /* ----------------------------------------------------------------------------- */
    154156    @Override
    155     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     157    public void layerAdded(LayerAddEvent e) {
    156158        // Do nothing
    157159    }
    158160
    159161    @Override
    160     public void layerAdded(Layer newLayer) {
     162    public void layerRemoving(LayerRemoveEvent e) {
     163        // remove all history browsers if the number of layers drops to 0
     164        if (e.getSource().getLayers().isEmpty()) {
     165            hideAll();
     166        }
     167    }
     168
     169    @Override
     170    public void layerOrderChanged(LayerOrderChangeEvent e) {
    161171        // Do nothing
    162     }
    163 
    164     @Override
    165     public void layerRemoved(Layer oldLayer) {
    166         // remove all history browsers if the number of layers drops to 0
    167         if (Main.isDisplayingMapView() && Main.map.mapView.getNumLayers() == 0) {
    168             hideAll();
    169         }
    170172    }
    171173
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java

    r10308 r10345  
    4141import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor;
    4242import org.openstreetmap.josm.gui.JosmUserIdentityManager;
    43 import org.openstreetmap.josm.gui.MapView;
    44 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    4543import org.openstreetmap.josm.gui.layer.Layer;
     44import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     45import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    4646import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    4747import org.openstreetmap.josm.gui.util.ChangeNotifier;
     
    7474 * @see HistoryBrowser
    7575 */
    76 public class HistoryBrowserModel extends ChangeNotifier implements LayerChangeListener, DataSetListener {
     76public class HistoryBrowserModel extends ChangeNotifier implements ActiveLayerChangeListener, DataSetListener {
    7777    /** the history of an OsmPrimitive */
    7878    private History history;
     
    111111            }
    112112        }
    113         MapView.addLayerChangeListener(this);
     113        Main.getLayerManager().addActiveLayerChangeListener(this);
    114114    }
    115115
     
    670670            editLayer.data.removeDataSetListener(this);
    671671        }
    672         MapView.removeLayerChangeListener(this);
     672        Main.getLayerManager().removeActiveLayerChangeListener(this);
    673673    }
    674674
     
    747747
    748748    /* ---------------------------------------------------------------------- */
    749     /* LayerChangeListener                                                    */
     749    /* ActiveLayerChangeListener                                              */
    750750    /* ---------------------------------------------------------------------- */
    751751    @Override
    752     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     752    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
     753        Layer oldLayer = e.getPreviousActiveLayer();
    753754        if (oldLayer instanceof OsmDataLayer) {
    754755            OsmDataLayer l = (OsmDataLayer) oldLayer;
    755756            l.data.removeDataSetListener(this);
    756757        }
     758        Layer newLayer = e.getSource().getActiveLayer();
    757759        if (!(newLayer instanceof OsmDataLayer)) {
    758760            latest = null;
     
    773775    }
    774776
    775     @Override
    776     public void layerAdded(Layer newLayer) {
    777         // Do nothing
    778     }
    779 
    780     @Override
    781     public void layerRemoved(Layer oldLayer) {
    782         // Do nothing
    783     }
    784 
    785777    /**
    786778     * Creates a {@link HistoryOsmPrimitive} from a {@link OsmPrimitive}
     
    825817        }
    826818    }
     819
    827820}
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r10300 r10345  
    7878import org.openstreetmap.josm.gui.MapFrame;
    7979import org.openstreetmap.josm.gui.MapView;
    80 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    8180import org.openstreetmap.josm.gui.NavigatableComponent.ZoomChangeListener;
    8281import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    8382import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    8483import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
     84import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     85import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     86import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
     87import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
    8588import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    8689import org.openstreetmap.josm.gui.util.GuiHelper;
     
    164167        setBackgroundLayer(true);
    165168        this.setVisible(true);
    166         MapView.addZoomChangeListener(this);
    167169    }
    168170
     
    626628            }
    627629        };
    628         Main.map.mapView.addMouseListener(adapter);
    629 
    630         MapView.addLayerChangeListener(new LayerChangeListener() {
     630        Main.getLayerManager().addLayerChangeListener(new LayerChangeListener() {
     631
    631632            @Override
    632             public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    633                 //
     633            public void layerRemoving(LayerRemoveEvent e) {
     634                if (e.getRemovedLayer() == AbstractTileSourceLayer.this) {
     635                    Main.map.mapView.removeMouseListener(adapter);
     636                    e.getSource().removeLayerChangeListener(this);
     637                    MapView.removeZoomChangeListener(AbstractTileSourceLayer.this);
     638                }
    634639            }
    635640
    636641            @Override
    637             public void layerAdded(Layer newLayer) {
    638                 //
     642            public void layerOrderChanged(LayerOrderChangeEvent e) {
     643                // ignored
    639644            }
    640645
    641646            @Override
    642             public void layerRemoved(Layer oldLayer) {
    643                 if (oldLayer == AbstractTileSourceLayer.this) {
    644                     Main.map.mapView.removeMouseListener(adapter);
    645                     MapView.removeLayerChangeListener(this);
    646                     MapView.removeZoomChangeListener(AbstractTileSourceLayer.this);
     647            public void layerAdded(LayerAddEvent e) {
     648                if (e.getAddedLayer() == AbstractTileSourceLayer.this) {
     649                    Main.map.mapView.addMouseListener(adapter);
     650                    MapView.addZoomChangeListener(AbstractTileSourceLayer.this);
    647651                }
    648652            }
    649653        });
    650 
    651654        // FIXME: why do we need this? Without this, if you add a WMS layer and do not move the mouse, sometimes, tiles do not
    652655        // start loading.
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java

    r10001 r10345  
    2323
    2424import org.openstreetmap.josm.Main;
    25 import org.openstreetmap.josm.gui.MapView;
    26 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    2725import org.openstreetmap.josm.gui.dialogs.DialogsPanel.Action;
    2826import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
    2927import org.openstreetmap.josm.gui.layer.Layer;
     28import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     29import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     30import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
     31import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
     32import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     33import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    3034import org.openstreetmap.josm.tools.ImageProvider;
    3135import org.openstreetmap.josm.tools.Shortcut;
    3236import org.openstreetmap.josm.tools.date.DateUtils;
    3337
    34 public final class ImageViewerDialog extends ToggleDialog implements LayerChangeListener {
     38public final class ImageViewerDialog extends ToggleDialog implements LayerChangeListener, ActiveLayerChangeListener {
    3539
    3640    private static final String COMMAND_ZOOM = "zoom";
     
    7680        tr("Tool: {0}", tr("Display geotagged images")), KeyEvent.VK_Y, Shortcut.DIRECT), 200);
    7781        build();
    78         MapView.addLayerChangeListener(this);
     82        Main.getLayerManager().addActiveLayerChangeListener(this);
     83        Main.getLayerManager().addLayerChangeListener(this);
    7984    }
    8085
     
    196201    @Override
    197202    public void destroy() {
    198         MapView.removeLayerChangeListener(this);
     203        Main.getLayerManager().removeActiveLayerChangeListener(this);
     204        Main.getLayerManager().removeLayerChangeListener(this);
    199205        super.destroy();
    200206    }
     
    410416
    411417    @Override
    412     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     418    public void layerAdded(LayerAddEvent e) {
     419        showLayer(e.getAddedLayer());
     420    }
     421
     422    @Override
     423    public void layerRemoving(LayerRemoveEvent e) {
     424        // Clear current image and layer if current layer is deleted
     425        if (currentLayer != null && currentLayer.equals(e.getRemovedLayer())) {
     426            showImage(null, null);
     427        }
     428        // Check buttons state in case of layer merging
     429        if (currentLayer != null && e.getRemovedLayer() instanceof GeoImageLayer) {
     430            currentLayer.checkPreviousNextButtons();
     431        }
     432    }
     433
     434    @Override
     435    public void layerOrderChanged(LayerOrderChangeEvent e) {
     436        // ignored
     437    }
     438
     439    @Override
     440    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
     441        showLayer(e.getSource().getActiveLayer());
     442    }
     443
     444    private void showLayer(Layer newLayer) {
    413445        if (currentLayer == null && newLayer instanceof GeoImageLayer) {
    414446            ((GeoImageLayer) newLayer).showFirstPhoto();
     
    416448    }
    417449
    418     @Override
    419     public void layerAdded(Layer newLayer) {
    420         if (currentLayer == null && newLayer instanceof GeoImageLayer) {
    421             ((GeoImageLayer) newLayer).showFirstPhoto();
    422         }
    423     }
    424 
    425     @Override
    426     public void layerRemoved(Layer oldLayer) {
    427         // Clear current image and layer if current layer is deleted
    428         if (currentLayer != null && currentLayer.equals(oldLayer)) {
    429             showImage(null, null);
    430         }
    431         // Check buttons state in case of layer merging
    432         if (currentLayer != null && oldLayer instanceof GeoImageLayer) {
    433             currentLayer.checkPreviousNextButtons();
    434         }
    435     }
    436450}
  • trunk/src/org/openstreetmap/josm/io/FileExporter.java

    r6830 r10345  
    88
    99import org.openstreetmap.josm.actions.ExtensionFileFilter;
    10 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    1110import org.openstreetmap.josm.gui.layer.Layer;
     11import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     12import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    1213
    13 public abstract class FileExporter implements LayerChangeListener {
     14public abstract class FileExporter implements ActiveLayerChangeListener {
    1415
    1516    public final ExtensionFileFilter filter;
     
    5455
    5556    @Override
    56     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     57    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
    5758        // To be overriden by subclasses if their enabled state depends of the active layer nature
    58     }
    59 
    60     @Override
    61     public void layerAdded(Layer newLayer) {
    62         // To be overriden by subclasses if needed
    63     }
    64 
    65     @Override
    66     public void layerRemoved(Layer oldLayer) {
    67         // To be overriden by subclasses if needed
    6859    }
    6960
  • trunk/src/org/openstreetmap/josm/io/WMSLayerExporter.java

    r8526 r10345  
    1212import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer;
    1313import org.openstreetmap.josm.gui.layer.Layer;
     14import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
    1415import org.openstreetmap.josm.tools.CheckParameterUtil;
    1516
     
    4445            }
    4546        }
    46 
    4747    }
    4848
    4949    @Override
    50     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    51         setEnabled(newLayer instanceof AbstractTileSourceLayer);
     50    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
     51        setEnabled(e.getSource().getActiveLayer() instanceof AbstractTileSourceLayer);
    5252    }
    5353}
Note: See TracChangeset for help on using the changeset viewer.