Ticket #5515: LayerShortcuts.diff

File LayerShortcuts.diff, 4.0 KB (added by AlfonZ, 14 years ago)

patch

  • src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

     
    190190        );
    191191
    192192        add(createButtonPanel(), BorderLayout.SOUTH);
     193
     194        // create direct actions
     195        for (int i = 0; i<10; i++) {
     196            ShowHideLayerNAction showHideLayerNAction = new ShowHideLayerNAction(i);
     197        }
     198        for (int i = 0; i<10; i++) {
     199            ActivateLayerNAction activateLayerNAction = new ActivateLayerNAction(i);
     200        }
    193201    }
    194202
    195203    @Override
     
    341349        }
    342350    }
    343351
     352    /**
     353     * The action to toggle visible state of the currently selected layer(s)
     354     */
    344355    public final class ShowHideLayerAction extends AbstractAction implements IEnabledStateUpdating, LayerAction {
    345356        private  Layer layer;
    346357
     
    411422    }
    412423
    413424    /**
     425     * The action to toggle visible state of the index-specified layer
     426     */
     427    public final class ShowHideLayerNAction extends AbstractAction {
     428        private int n;
     429
     430        /**
     431         * Creates a {@see ShowHideLayerNAction} which will toggle the visibility of
     432         * a index-specified layer
     433         *
     434         * @param n index of a layer
     435         */
     436        public ShowHideLayerNAction(int n) {
     437            this.n = n;
     438            Main.registerActionShortcut(this, Shortcut.registerShortcut("layer:showhide." + n,
     439                    tr("{0}: {1} {2}", tr("Layers"), tr("Show/Hide layer"), Integer.toString(n+1)),
     440                    KeyEvent.VK_0 + ((n+1)%10), Shortcut.GROUP_NONE));
     441        }
     442
     443        public void actionPerformed(ActionEvent e) {
     444            Layer layer = model.getLayer(n);
     445            if (layer == null) {
     446                return;
     447            }
     448            layer.toggleVisible();
     449        }
     450
     451        @Override
     452        public boolean equals(Object obj) {
     453            if (!(obj instanceof ShowHideLayerNAction)) return false;
     454            ShowHideLayerNAction other = (ShowHideLayerNAction) obj;
     455            return (other.n == this.n);
     456        }
     457
     458        @Override
     459        public int hashCode() {
     460            return getClass().hashCode();
     461        }
     462
     463    }
     464
     465    /**
    414466     * The action to activate the currently selected layer
    415467     */
    416468
     
    476528    }
    477529
    478530    /**
     531     * The action to activate the index-specified layer
     532     */
     533    public final class ActivateLayerNAction extends AbstractAction {
     534        private int n;
     535
     536        /**
     537         * Creates a {@see ActivateLayerNAction} which will activate
     538         * a index-specified layer
     539         *
     540         * @param n index of a layer
     541         */
     542        public ActivateLayerNAction(int n) {
     543            this.n = n;
     544            Main.registerActionShortcut(this, Shortcut.registerShortcut("layer:activate." + n,
     545                    tr("{0}: {1} {2}", tr("Layers"), tr("Activate layer"), Integer.toString(n+1)),
     546                    KeyEvent.VK_0 + ((n+1)%10), Shortcut.GROUP_NONE));
     547        }
     548
     549        public void actionPerformed(ActionEvent e) {
     550            Layer layer = model.getLayer(n);
     551            if (layer == null) {
     552                return;
     553            }
     554            // model is  going to be updated via LayerChangeListener
     555            // and PropertyChangeEvents
     556            Main.map.mapView.setActiveLayer(layer);
     557            layer.setVisible(true);
     558        }
     559
     560        @Override
     561        public boolean equals(Object obj) {
     562            if (!(obj instanceof ActivateLayerNAction)) return false;
     563            ActivateLayerNAction other = (ActivateLayerNAction) obj;
     564            return (other.n == this.n);
     565        }
     566
     567        @Override
     568        public int hashCode() {
     569            return getClass().hashCode();
     570        }
     571
     572    }
     573
     574    /**
    479575     * The action to merge the currently selected layer into another layer.
    480576     */
    481577    public final class MergeAction extends AbstractAction implements IEnabledStateUpdating {