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

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

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
3 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}
Note: See TracChangeset for help on using the changeset viewer.