Ignore:
Timestamp:
2010-08-03T07:52:26+02:00 (16 years ago)
Author:
jttt
Message:

Show only actions that can work on all selected layers in LayerListDialog popup menu

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

    r3237 r3408  
    2626import javax.swing.JLabel;
    2727import javax.swing.JList;
     28import javax.swing.JMenuItem;
    2829import javax.swing.JPanel;
    2930import javax.swing.JScrollPane;
     
    4748import org.openstreetmap.josm.gui.layer.Layer;
    4849import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     50import org.openstreetmap.josm.gui.layer.Layer.LayerAction;
    4951import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
    5052import org.openstreetmap.josm.tools.CheckParameterUtil;
     
    265267     * The action to delete the currently selected layer
    266268     */
    267     public final  class DeleteLayerAction extends AbstractAction implements IEnabledStateUpdating {
     269    public final class DeleteLayerAction extends AbstractAction implements IEnabledStateUpdating, LayerAction {
    268270        /**
    269271         * Creates a {@see DeleteLayerAction} which will delete the currently
     
    318320            setEnabled(! getModel().getSelectedLayers().isEmpty());
    319321        }
    320     }
    321 
    322     public final class ShowHideLayerAction extends AbstractAction implements IEnabledStateUpdating {
     322
     323        @Override
     324        public Component createMenuComponent() {
     325            return new JMenuItem(this);
     326        }
     327
     328        @Override
     329        public boolean supportLayers(List<Layer> layers) {
     330            return true;
     331        }
     332
     333        @Override
     334        public boolean equals(Object obj) {
     335            return obj instanceof DeleteLayerAction;
     336        }
     337
     338        @Override
     339        public int hashCode() {
     340            return getClass().hashCode();
     341        }
     342    }
     343
     344    public final class ShowHideLayerAction extends AbstractAction implements IEnabledStateUpdating, LayerAction {
    323345        private  Layer layer;
    324346
     
    334356            CheckParameterUtil.ensureParameterNotNull(layer, "layer");
    335357            this.layer = layer;
    336             putValue(NAME, tr("Show/Hide"));
    337358            updateEnabledState();
    338359        }
     
    347368            putValue(SHORT_DESCRIPTION, tr("Toggle visible state of the selected layer."));
    348369            putValue("help", HelpUtil.ht("/Dialog/LayerDialog#ShowHideLayer"));
     370            putValue(NAME, tr("Show/Hide"));
    349371            updateEnabledState();
    350372        }
     
    366388                setEnabled(true);
    367389            }
     390        }
     391
     392        @Override
     393        public Component createMenuComponent() {
     394            return new JMenuItem(this);
     395        }
     396
     397        @Override
     398        public boolean supportLayers(List<Layer> layers) {
     399            return true;
     400        }
     401
     402        @Override
     403        public boolean equals(Object obj) {
     404            return obj instanceof ShowHideLayerAction;
     405        }
     406
     407        @Override
     408        public int hashCode() {
     409            return getClass().hashCode();
    368410        }
    369411    }
     
    576618            }
    577619            Layer layer = model.getLayer(index);
    578             LayerListPopup menu = new LayerListPopup(layerList, layer);
     620            LayerListPopup menu = new LayerListPopup(getModel().getSelectedLayers(), layer);
    579621            menu.show(LayerListDialog.this, p.x, p.y-3);
    580622        }
     
    10641106     * @return the action
    10651107     */
    1066     public ShowHideLayerAction createShowHideLayerAction(Layer layer) {
    1067         return new ShowHideLayerAction(layer);
     1108    public ShowHideLayerAction createShowHideLayerAction() {
     1109        return new ShowHideLayerAction();
    10681110    }
    10691111
     
    10751117     * @return the action
    10761118     */
    1077     public DeleteLayerAction createDeleteLayerAction(Layer layer) {
     1119    public DeleteLayerAction createDeleteLayerAction() {
    10781120        // the delete layer action doesn't depend on the current layer
    10791121        return new DeleteLayerAction();
Note: See TracChangeset for help on using the changeset viewer.