Ticket #12937: patch-layer-manager-migrate-layer-change.patch

File patch-layer-manager-migrate-layer-change.patch, 64.3 KB (added by michael2402, 8 years ago)
  • src/org/openstreetmap/josm/actions/ExtensionFileFilter.java

    diff --git a/src/org/openstreetmap/josm/actions/ExtensionFileFilter.java b/src/org/openstreetmap/josm/actions/ExtensionFileFilter.java
    index fcd933e..707537d 100644
    a b public class ExtensionFileFilter extends FileFilter implements java.io.FileFilte  
    107107            try {
    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()) {
    113113                    Main.debug(e.getMessage());
  • src/org/openstreetmap/josm/actions/JosmAction.java

    diff --git a/src/org/openstreetmap/josm/actions/JosmAction.java b/src/org/openstreetmap/josm/actions/JosmAction.java
    index 5e450aa..76686c9 100644
    a b import org.openstreetmap.josm.Main;  
    1515import org.openstreetmap.josm.data.SelectionChangedListener;
    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;
    2625import org.openstreetmap.josm.tools.Shortcut;
    public abstract class JosmAction extends AbstractAction implements Destroyable {  
    183182        if (sc != null) {
    184183            Main.unregisterActionShortcut(this);
    185184        }
    186         MapView.removeLayerChangeListener(layerChangeAdapter);
     185        if (layerChangeAdapter != null) {
     186            Main.getLayerManager().removeActiveLayerChangeListener(layerChangeAdapter);
     187        }
    187188        DataSet.removeSelectionListener(selectionChangeAdapter);
    188189    }
    189190
    public abstract class JosmAction extends AbstractAction implements Destroyable {  
    225226
    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();
    234234    }
    public abstract class JosmAction extends AbstractAction implements Destroyable {  
    290290    }
    291291
    292292    /**
    293      * Adapter for layer change events
    294      *
     293     * Adapter for layer change events. Runs updateEnabledState() whenever the active layer changed.
    295294     */
    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 
     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();
     302        public String toString() {
     303            return "LayerChangeAdapter [" + JosmAction.this.toString() + "]";
    318304        }
    319305    }
    320306
    321307    /**
    322      * Adapter for selection change events
     308     * Adapter for selection change events. Runs updateEnabledState() whenever the selection changed.
    323309     */
    324310    protected class SelectionChangeAdapter implements SelectionChangedListener {
    325311        @Override
    326312        public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    327313            updateEnabledState(newSelection);
    328314        }
     315
     316        @Override
     317        public String toString() {
     318            return "SelectionChangeAdapter [" + JosmAction.this.toString() + "]";
     319        }
    329320    }
    330321}
  • src/org/openstreetmap/josm/actions/relation/RecentRelationsAction.java

    diff --git a/src/org/openstreetmap/josm/actions/relation/RecentRelationsAction.java b/src/org/openstreetmap/josm/actions/relation/RecentRelationsAction.java
    index 6c79832..f6e1fcb 100644
    a b import javax.swing.plaf.basic.BasicArrowButton;  
    2020import org.openstreetmap.josm.Main;
    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;
    2933import org.openstreetmap.josm.tools.ImageProvider;
    import org.openstreetmap.josm.tools.Shortcut;  
    3236/**
    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;
    3842    private final BasicArrowButton arrow;
    public class RecentRelationsAction implements ActionListener, CommandQueueListen  
    4751        arrow = editButton.createArrow(this);
    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(
    5358            "relationeditor:editrecentrelation",
    public class RecentRelationsAction implements ActionListener, CommandQueueListen  
    108113    }
    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    }
    124134
    public class RecentRelationsAction implements ActionListener, CommandQueueListen  
    181191            EditRelationAction.launchEditor(relation);
    182192        }
    183193    }
     194
    184195}
  • src/org/openstreetmap/josm/data/UndoRedoHandler.java

    diff --git a/src/org/openstreetmap/josm/data/UndoRedoHandler.java b/src/org/openstreetmap/josm/data/UndoRedoHandler.java
    index bb07a61..c15ebfc 100644
    a b import org.openstreetmap.josm.Main;  
    99import org.openstreetmap.josm.command.Command;
    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    /**
    2023     * All commands that were made on the dataset. Don't write from outside!
    public class UndoRedoHandler implements MapView.LayerChangeListener {  
    3134     * Constructs a new {@code UndoRedoHandler}.
    3235     */
    3336    public UndoRedoHandler() {
    34         MapView.addLayerChangeListener(this);
     37        Main.getLayerManager().addLayerChangeListener(this);
    3538    }
    3639
    3740    /**
    public class UndoRedoHandler implements MapView.LayerChangeListener {  
    169172    }
    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    }
    185188
  • src/org/openstreetmap/josm/data/osm/visitor/paint/relations/MultipolygonCache.java

    diff --git a/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/MultipolygonCache.java b/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/MultipolygonCache.java
    index d76fc027..16650ca 100644
    a b import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;  
    2727import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon.PolyData;
    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
    3637/**
    public final class MultipolygonCache implements DataSetListener, LayerChangeList  
    5051        this.selectedPolyData = new ArrayList<>();
    5152        Main.addProjectionChangeListener(this);
    5253        DataSet.addSelectionListener(this);
    53         MapView.addLayerChangeListener(this);
     54        Main.getLayerManager().addLayerChangeListener(this);
    5455    }
    5556
    5657    /**
    public final class MultipolygonCache implements DataSetListener, LayerChangeList  
    285286    }
    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    }
    303304
  • src/org/openstreetmap/josm/gui/ImageryMenu.java

    diff --git a/src/org/openstreetmap/josm/gui/ImageryMenu.java b/src/org/openstreetmap/josm/gui/ImageryMenu.java
    index 45ee187..a6359bc 100644
    a b import org.openstreetmap.josm.data.coor.LatLon;  
    3232import org.openstreetmap.josm.data.imagery.ImageryInfo;
    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;
    4042
    public class ImageryMenu extends JMenu implements LayerChangeListener {  
    110112        /* I18N: mnemonic: I */
    111113        super(trc("menu", "Imagery"));
    112114        setupMenuScroller();
    113         MapView.addLayerChangeListener(this);
     115        Main.getLayerManager().addLayerChangeListener(this);
    114116        // build dynamically
    115117        addMenuListener(new MenuListener() {
    116118            @Override
    public class ImageryMenu extends JMenu implements LayerChangeListener {  
    209211    }
    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);
    219217            return singleOffset;
    public class ImageryMenu extends JMenu implements LayerChangeListener {  
    238236    }
    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        }
    250250    }
    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
    259257    /**
  • src/org/openstreetmap/josm/gui/MainFrame.java

    diff --git a/src/org/openstreetmap/josm/gui/MainFrame.java b/src/org/openstreetmap/josm/gui/MainFrame.java
    index 8fa96e5..75ac489 100644
    a b public class MainFrame extends JFrame {  
    113113            public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
    114114                refreshTitle();
    115115            }
    116         }, false);
     116        });
    117117        Main.getLayerManager().addLayerChangeListener(new ManageLayerListeners(), true);
    118118
    119119        refreshTitle();
  • src/org/openstreetmap/josm/gui/MainMenu.java

    diff --git a/src/org/openstreetmap/josm/gui/MainMenu.java b/src/org/openstreetmap/josm/gui/MainMenu.java
    index 8ab7575..be35785 100644
    a b import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;  
    116116import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
    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;
    122123import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference;
    public class MainMenu extends JMenuBar {  
    821822
    822823        windowMenu.addMenuListener(menuSeparatorHandler);
    823824
    824         new PresetsMenuEnabler(presetsMenu).refreshEnabled();
     825        new PresetsMenuEnabler(presetsMenu);
    825826    }
    826827
    827828    /**
    public class MainMenu extends JMenuBar {  
    885886        }
    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());
    901         }
    902 
    903         @Override
    904         public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    905             refreshEnabled();
    906         }
    907 
    908         @Override
    909         public void layerAdded(Layer newLayer) {
    910             refreshEnabled();
     894            Main.getLayerManager().addAndFireActiveLayerChangeListener(this);
    911895        }
    912896
    913897        @Override
    914         public void layerRemoved(Layer oldLayer) {
    915             refreshEnabled();
     898        public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
     899            presetsMenu.setEnabled(e.getSource().getEditLayer() != null);
    916900        }
    917901    }
    918902
  • src/org/openstreetmap/josm/gui/MapFrame.java

    diff --git a/src/org/openstreetmap/josm/gui/MapFrame.java b/src/org/openstreetmap/josm/gui/MapFrame.java
    index 6c0e557..62030d9 100644
    a b import javax.swing.JPopupMenu;  
    3737import javax.swing.JSplitPane;
    3838import javax.swing.JToolBar;
    3939import javax.swing.KeyStroke;
    40 import javax.swing.SwingUtilities;
    4140import javax.swing.border.Border;
    4241import javax.swing.event.PopupMenuEvent;
    4342import javax.swing.event.PopupMenuListener;
    import org.openstreetmap.josm.data.Preferences;  
    5857import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
    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;
    6462import org.openstreetmap.josm.gui.dialogs.ConflictDialog;
    import org.openstreetmap.josm.gui.dialogs.ValidatorDialog;  
    7674import org.openstreetmap.josm.gui.dialogs.properties.PropertiesDialog;
    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;
    8185import org.openstreetmap.josm.tools.GBC;
    import org.openstreetmap.josm.tools.Shortcut;  
    8993 *
    9094 * @author imi
    9195 */
    92 public class MapFrame extends JPanel implements Destroyable, LayerChangeListener {
     96public class MapFrame extends JPanel implements Destroyable, ActiveLayerChangeListener, LayerChangeListener {
    9397
    9498    /**
    9599     * The current mode, this frame operates.
    public class MapFrame extends JPanel implements Destroyable, LayerChangeListener  
    284288
    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;
    290295        if (unregisterTab) {
    public class MapFrame extends JPanel implements Destroyable, LayerChangeListener  
    328333     */
    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);
    334340        for (int i = 0; i < toolBarActions.getComponentCount(); ++i) {
    public class MapFrame extends JPanel implements Destroyable, LayerChangeListener  
    756762    }
    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);
    763770            modeChanged = newMapMode != mapMode;
    public class MapFrame extends JPanel implements Destroyable, LayerChangeListener  
    770777            }
    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
    776783                mapMode.exitMode();
    public class MapFrame extends JPanel implements Destroyable, LayerChangeListener  
    782789
    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
    792795    private MapMode getLastMapMode(Layer newLayer) {
    public class MapFrame extends JPanel implements Destroyable, LayerChangeListener  
    802805    }
    803806
    804807    @Override
    805     public void layerAdded(Layer newLayer) {
    806         // Do nothing
     808    public void layerAdded(LayerAddEvent e) {
     809        // ignored
     810    }
     811
     812    @Override
     813    public void layerRemoving(LayerRemoveEvent e) {
     814        lastMapMode.remove(e.getRemovedLayer());
    807815    }
    808816
    809817    @Override
    810     public void layerRemoved(Layer oldLayer) {
    811         lastMapMode.remove(oldLayer);
     818    public void layerOrderChanged(LayerOrderChangeEvent e) {
     819        // ignored
    812820    }
     821
    813822}
  • src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java b/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
    index 84ee5e8..f2ef962 100644
    a b public class LayerListDialog extends ToggleDialog {  
    185185        //
    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());
    195195        layerList.setBackground(UIManager.getColor("Button.background"));
    public class LayerListDialog extends ToggleDialog {  
    329329
    330330    @Override
    331331    public void showNotify() {
    332         MapView.addLayerChangeListener(activateLayerAction);
     332        layerManager.addActiveLayerChangeListener(activateLayerAction);
    333333        layerManager.addLayerChangeListener(model);
    334334        layerManager.addAndFireActiveLayerChangeListener(model);
    335335        model.populate();
    public class LayerListDialog extends ToggleDialog {  
    339339    public void hideNotify() {
    340340        layerManager.removeLayerChangeListener(model);
    341341        layerManager.removeActiveLayerChangeListener(model);
    342         MapView.removeLayerChangeListener(activateLayerAction);
     342        layerManager.removeActiveLayerChangeListener(activateLayerAction);
    343343    }
    344344
    345345    /**
    public class LayerListDialog extends ToggleDialog {  
    648648        private final DefaultListSelectionModel selectionModel;
    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<>();
    660662        }
    public class LayerListDialog extends ToggleDialog {  
    663665            this.layerList = layerList;
    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
    675676        /**
    public class LayerListDialog extends ToggleDialog {  
    11241125     * This component displays a list of layers and provides the methods needed by {@link LayerListModel}.
    11251126     */
    11261127    static class LayerList extends JTable {
    1127         private final transient MainLayerManager layerManager;
    11281128
    1129         LayerList(LayerListModel dataModel, MainLayerManager layerManager) {
     1129        LayerList(LayerListModel dataModel) {
    11301130            super(dataModel);
    1131             this.layerManager = layerManager;
    11321131            dataModel.setLayerList(this);
    11331132        }
    11341133
    public class LayerListDialog extends ToggleDialog {  
    11411140            rect.setLocation(rect.x - pt.x, rect.y - pt.y);
    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
    11551145    /**
  • src/org/openstreetmap/josm/gui/dialogs/NotesDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/NotesDialog.java b/src/org/openstreetmap/josm/gui/dialogs/NotesDialog.java
    index 7659768..56dde01 100644
    a b import org.openstreetmap.josm.data.notes.Note;  
    3838import org.openstreetmap.josm.data.notes.Note.State;
    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;
    4950import org.openstreetmap.josm.tools.date.DateUtils;
    public class NotesDialog extends ToggleDialog implements LayerChangeListener {  
    9899        sortAction = new SortAction();
    99100        uploadAction = new UploadNotesAction();
    100101        buildDialog();
    101         MapView.addLayerChangeListener(this);
     102        Main.getLayerManager().addLayerChangeListener(this);
    102103    }
    103104
    104105    private void buildDialog() {
    public class NotesDialog extends ToggleDialog implements LayerChangeListener {  
    168169        }
    169170    }
    170171
    171     @Override
    172     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    173         // Do nothing
    174     }
    175172
    176173    @Override
    177     public void layerAdded(Layer newLayer) {
    178         if (newLayer instanceof NoteLayer) {
    179             noteData = ((NoteLayer) newLayer).getNoteData();
     174    public void layerAdded(LayerAddEvent e) {
     175        if (e.getAddedLayer() instanceof NoteLayer) {
     176            noteData = ((NoteLayer) e.getAddedLayer()).getNoteData();
    180177            model.setData(noteData.getNotes());
    181178            setNotes(noteData.getSortedNotes());
    182179        }
    183180    }
    184181
    185182    @Override
    186     public void layerRemoved(Layer oldLayer) {
    187         if (oldLayer instanceof NoteLayer) {
     183    public void layerRemoving(LayerRemoveEvent e) {
     184        if (e.getRemovedLayer() instanceof NoteLayer) {
    188185            noteData = null;
    189186            model.clearData();
    190187            if (Main.map.mapMode instanceof AddNoteAction) {
    public class NotesDialog extends ToggleDialog implements LayerChangeListener {  
    193190        }
    194191    }
    195192
     193    @Override
     194    public void layerOrderChanged(LayerOrderChangeEvent e) {
     195        // ignored
     196    }
     197
    196198    /**
    197199     * Sets the list of notes to be displayed in the dialog.
    198200     * The dialog should match the notes displayed in the note layer.
  • src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java b/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java
    index 57ac553..e452b71 100644
    a b import org.openstreetmap.josm.data.SelectionChangedListener;  
    3434import org.openstreetmap.josm.data.osm.DataSet;
    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;
    4243import org.openstreetmap.josm.tools.ImageProvider;
    import org.openstreetmap.josm.tools.Utils;  
    4950 * selection area, along with the number of objects.
    5051 *
    5152 */
    52 public class UserListDialog extends ToggleDialog implements SelectionChangedListener, MapView.LayerChangeListener {
     53public class UserListDialog extends ToggleDialog implements SelectionChangedListener, ActiveLayerChangeListener {
    5354
    5455    /**
    5556     * The display list.
    public class UserListDialog extends ToggleDialog implements SelectionChangedList  
    7172    @Override
    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    }
    8283
    public class UserListDialog extends ToggleDialog implements SelectionChangedList  
    112113    }
    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        }
    121123    }
    122124
    123     @Override
    124     public void layerAdded(Layer newLayer) {
    125         // do nothing
    126     }
    127 
    128     @Override
    129     public void layerRemoved(Layer oldLayer) {
    130         // do nothing
    131     }
    132 
    133125    /**
    134126     * Refreshes user list from given collection of OSM primitives.
    135127     * @param fromPrimitives OSM primitives to fetch users from
  • src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java b/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java
    index 93cd671..e49b466 100644
    a b import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;  
    4141import org.openstreetmap.josm.data.validation.OsmValidator;
    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;
    5352import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    import org.xml.sax.SAXException;  
    6564 *
    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 */
    7170    public ValidatorTreePanel tree;
    public class ValidatorDialog extends ToggleDialog implements SelectionChangedLis  
    178177        if (ds != null) {
    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    }
    193188
    public class ValidatorDialog extends ToggleDialog implements SelectionChangedLis  
    406401    }
    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    }
    427412
  • src/org/openstreetmap/josm/gui/dialogs/layer/ActivateLayerAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/layer/ActivateLayerAction.java b/src/org/openstreetmap/josm/gui/dialogs/layer/ActivateLayerAction.java
    index ad661ea..ddb5173 100644
    a b import java.util.List;  
    99
    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;
    2020import org.openstreetmap.josm.tools.ImageProvider;
    import org.openstreetmap.josm.tools.Shortcut;  
    2525 * The action to activate the currently selected layer
    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;
    3131    private final LayerListModel model;
    implements IEnabledStateUpdating, MapView.LayerChangeListener, MultikeyShortcutA  
    7676
    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
    8987    @Override
    implements IEnabledStateUpdating, MapView.LayerChangeListener, MultikeyShortcutA  
    105103    }
    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    }
    121109
    implements IEnabledStateUpdating, MapView.LayerChangeListener, MultikeyShortcutA  
    136124    public MultikeyInfo getLastMultikeyAction() {
    137125        return null; // Repeating action doesn't make much sense for activating
    138126    }
     127
    139128}
  • src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java b/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
    index 527a72a..001d244 100644
    a b implements SelectionChangedListener, ActiveLayerChangeListener, DataSetListenerA  
    617617    public void destroy() {
    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) {
    625622            parent.remove(pluginHook);
  • src/org/openstreetmap/josm/gui/dialogs/relation/RelationDialogManager.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/RelationDialogManager.java b/src/org/openstreetmap/josm/gui/dialogs/relation/RelationDialogManager.java
    index a2eb0a8..7f492f7 100644
    a b import java.util.Map;  
    1010import java.util.Map.Entry;
    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
    1822/**
    1923 * RelationDialogManager keeps track of the open relation editors.
    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 */
    2529    private static RelationDialogManager relationDialogManager;
    public class RelationDialogManager extends WindowAdapter implements MapView.Laye  
    3236    public static RelationDialogManager getRelationDialogManager() {
    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;
    3842    }
    public class RelationDialogManager extends WindowAdapter implements MapView.Laye  
    166170        return openDialogs.get(context);
    167171    }
    168172
    169     /**
    170      * called when a layer is removed
    171      *
    172      */
    173173    @Override
    174     public void layerRemoved(Layer oldLayer) {
     174    public void layerRemoving(LayerRemoveEvent e) {
     175        Layer oldLayer = e.getRemovedLayer();
    175176        if (!(oldLayer instanceof OsmDataLayer))
    176177            return;
    177178        OsmDataLayer dataLayer = (OsmDataLayer) oldLayer;
    public class RelationDialogManager extends WindowAdapter implements MapView.Laye  
    189190    }
    190191
    191192    @Override
    192     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    193         // do nothing
     193    public void layerAdded(LayerAddEvent e) {
     194        // ignore
    194195    }
    195196
    196197    @Override
    197     public void layerAdded(Layer newLayer) {
    198         // do nothing
     198    public void layerOrderChanged(LayerOrderChangeEvent e) {
     199        // ignore
    199200    }
    200201
    201202    @Override
  • src/org/openstreetmap/josm/gui/dialogs/relation/SelectionTableModel.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/SelectionTableModel.java b/src/org/openstreetmap/josm/gui/dialogs/relation/SelectionTableModel.java
    index fe71e33..365e8ac 100644
    a b import org.openstreetmap.josm.Main;  
    1010import org.openstreetmap.josm.data.SelectionChangedListener;
    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 */
    2125    private final transient OsmDataLayer layer;
    public class SelectionTableModel extends AbstractTableModel implements Selection  
    3943     */
    4044    public void register() {
    4145        DataSet.addSelectionListener(this);
    42         MapView.addLayerChangeListener(this);
     46        Main.getLayerManager().addActiveLayerChangeListener(this);
    4347    }
    4448
    4549    /**
    public class SelectionTableModel extends AbstractTableModel implements Selection  
    4751     */
    4852    public void unregister() {
    4953        DataSet.removeSelectionListener(this);
    50         MapView.removeLayerChangeListener(this);
     54        Main.getLayerManager().removeActiveLayerChangeListener(this);
    5155    }
    5256
    5357    @Override
    public class SelectionTableModel extends AbstractTableModel implements Selection  
    6872    }
    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();
    7983    }
    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();
    public class SelectionTableModel extends AbstractTableModel implements Selection  
    9397    }
    9498
    9599    @Override
     100    public void layerOrderChanged(LayerOrderChangeEvent e) {
     101        // do nothing
     102    }
     103
     104    @Override
    96105    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    97106        if (layer == Main.main.getEditLayer()) {
    98107            cache.clear();
    public class SelectionTableModel extends AbstractTableModel implements Selection  
    127136    public OsmPrimitive getPrimitive(int row) {
    128137        return cache.get(row);
    129138    }
     139
    130140}
  • src/org/openstreetmap/josm/gui/history/HistoryBrowserDialogManager.java

    diff --git a/src/org/openstreetmap/josm/gui/history/HistoryBrowserDialogManager.java b/src/org/openstreetmap/josm/gui/history/HistoryBrowserDialogManager.java
    index 1aae5c4..73cdcfc 100644
    a b import org.openstreetmap.josm.Main;  
    2121import org.openstreetmap.josm.data.osm.PrimitiveId;
    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;
    2830import org.openstreetmap.josm.tools.WindowGeometry;
    import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler;  
    3234 * Manager allowing to show/hide history dialogs.
    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";
    3840
    public final class HistoryBrowserDialogManager implements MapView.LayerChangeLis  
    5355
    5456    protected HistoryBrowserDialogManager() {
    5557        dialogs = new HashMap<>();
    56         MapView.addLayerChangeListener(this);
     58        Main.getLayerManager().addLayerChangeListener(this);
    5759    }
    5860
    5961    /**
    public final class HistoryBrowserDialogManager implements MapView.LayerChangeLis  
    152154    /* LayerChangeListener                                                           */
    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) {
    161         // Do nothing
    162     }
    163 
    164     @Override
    165     public void layerRemoved(Layer oldLayer) {
     162    public void layerRemoving(LayerRemoveEvent e) {
    166163        // remove all history browsers if the number of layers drops to 0
    167         if (Main.isDisplayingMapView() && Main.map.mapView.getNumLayers() == 0) {
     164        if (e.getSource().getLayers().isEmpty()) {
    168165            hideAll();
    169166        }
    170167    }
    171168
     169    @Override
     170    public void layerOrderChanged(LayerOrderChangeEvent e) {
     171        // Do nothing
     172    }
     173
    172174    /**
    173175     * Show history dialog(s) for the given primitive(s).
    174176     * @param primitives The primitive(s) for which history will be displayed
  • src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java

    diff --git a/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java b/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java
    index 2b25290..ba4d0bd 100644
    a b import org.openstreetmap.josm.data.osm.history.HistoryRelation;  
    4040import org.openstreetmap.josm.data.osm.history.HistoryWay;
    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;
    4848import org.openstreetmap.josm.tools.CheckParameterUtil;
    import org.openstreetmap.josm.tools.date.DateUtils;  
    7373 *
    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;
    7979    private HistoryOsmPrimitive reference;
    public class HistoryBrowserModel extends ChangeNotifier implements LayerChangeLi  
    110110                editLayer.data.addDataSetListener(this);
    111111            }
    112112        }
    113         MapView.addLayerChangeListener(this);
     113        Main.getLayerManager().addActiveLayerChangeListener(this);
    114114    }
    115115
    116116    /**
    public class HistoryBrowserModel extends ChangeNotifier implements LayerChangeLi  
    669669        if (editLayer != null) {
    670670            editLayer.data.removeDataSetListener(this);
    671671        }
    672         MapView.removeLayerChangeListener(this);
     672        Main.getLayerManager().removeActiveLayerChangeListener(this);
    673673    }
    674674
    675675    /* ---------------------------------------------------------------------- */
    public class HistoryBrowserModel extends ChangeNotifier implements LayerChangeLi  
    746746    }
    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;
    759761            fireModelChange();
    public class HistoryBrowserModel extends ChangeNotifier implements LayerChangeLi  
    772774        fireModelChange();
    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}
    787779     *
    public class HistoryBrowserModel extends ChangeNotifier implements LayerChangeLi  
    824816            return clone;
    825817        }
    826818    }
     819
    827820}
  • src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    diff --git a/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java b/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java
    index 4b3a885..d475296 100644
    a b import org.openstreetmap.josm.data.preferences.IntegerProperty;  
    7777import org.openstreetmap.josm.gui.ExtendedDialog;
    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;
    8790import org.openstreetmap.josm.io.WMSLayerImporter;
    implements ImageObserver, TileLoaderListener, ZoomChangeListener {  
    163166        super(info);
    164167        setBackgroundLayer(true);
    165168        this.setVisible(true);
    166         MapView.addZoomChangeListener(this);
    167169    }
    168170
    169171    protected abstract TileLoaderFactory getTileLoaderFactory();
    implements ImageObserver, TileLoaderListener, ZoomChangeListener {  
    625627                }
    626628            }
    627629        };
    628         Main.map.mapView.addMouseListener(adapter);
     630        Main.getLayerManager().addLayerChangeListener(new LayerChangeListener() {
    629631
    630         MapView.addLayerChangeListener(new LayerChangeListener() {
    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.
    653656        Main.map.repaint(500);
  • src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java b/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java
    index 8a57ab9..f2a95b7 100644
    a b import javax.swing.JPanel;  
    2222import javax.swing.JToggleButton;
    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";
    3741    private static final String COMMAND_CENTERVIEW = "centre";
    public final class ImageViewerDialog extends ToggleDialog implements LayerChange  
    7579        super(tr("Geotagged Images"), "geoimage", tr("Display geotagged images"), Shortcut.registerShortcut("tools:geotagged",
    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
    8186    protected void build() {
    public final class ImageViewerDialog extends ToggleDialog implements LayerChange  
    195200
    196201    @Override
    197202    public void destroy() {
    198         MapView.removeLayerChangeListener(this);
     203        Main.getLayerManager().removeActiveLayerChangeListener(this);
     204        Main.getLayerManager().removeLayerChangeListener(this);
    199205        super.destroy();
    200206    }
    201207
    public final class ImageViewerDialog extends ToggleDialog implements LayerChange  
    409415    }
    410416
    411417    @Override
    412     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    413         if (currentLayer == null && newLayer instanceof GeoImageLayer) {
    414             ((GeoImageLayer) newLayer).showFirstPhoto();
    415         }
     418    public void layerAdded(LayerAddEvent e) {
     419        showLayer(e.getAddedLayer());
    416420    }
    417421
    418422    @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) {
     423    public void layerRemoving(LayerRemoveEvent e) {
    427424        // Clear current image and layer if current layer is deleted
    428         if (currentLayer != null && currentLayer.equals(oldLayer)) {
     425        if (currentLayer != null && currentLayer.equals(e.getRemovedLayer())) {
    429426            showImage(null, null);
    430427        }
    431428        // Check buttons state in case of layer merging
    432         if (currentLayer != null && oldLayer instanceof GeoImageLayer) {
     429        if (currentLayer != null && e.getRemovedLayer() instanceof GeoImageLayer) {
    433430            currentLayer.checkPreviousNextButtons();
    434431        }
    435432    }
     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) {
     445        if (currentLayer == null && newLayer instanceof GeoImageLayer) {
     446            ((GeoImageLayer) newLayer).showFirstPhoto();
     447        }
     448    }
     449
    436450}
  • src/org/openstreetmap/josm/io/FileExporter.java

    diff --git a/src/org/openstreetmap/josm/io/FileExporter.java b/src/org/openstreetmap/josm/io/FileExporter.java
    index 7191b92..fd8e09d 100644
    a b import java.io.File;  
    77import java.io.IOException;
    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;
    1617
    public abstract class FileExporter implements LayerChangeListener {  
    5354    }
    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
    5859    }
    5960
    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
    68     }
    69 
    7061    /**
    7162     * Determines if this exporter has been canceled during export.
    7263     * @return true if this {@code FileExporter} has been canceled
  • src/org/openstreetmap/josm/io/WMSLayerExporter.java

    diff --git a/src/org/openstreetmap/josm/io/WMSLayerExporter.java b/src/org/openstreetmap/josm/io/WMSLayerExporter.java
    index 15e765a..ce0d46d 100644
    a b import org.openstreetmap.josm.data.Preferences;  
    1111import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryPreferenceEntry;
    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
    1617/**
    public class WMSLayerExporter extends FileExporter {  
    4647
    4748    }
    4849
     50
    4951    @Override
    50     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    51         setEnabled(newLayer instanceof AbstractTileSourceLayer);
     52    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
     53        setEnabled(e.getSource().getActiveLayer() instanceof AbstractTileSourceLayer);
    5254    }
    5355}