Changeset 1917 in josm


Ignore:
Timestamp:
2009-08-06T10:51:28+02:00 (15 years ago)
Author:
Gubaer
Message:

fixed #3195: No layer is highlighted by default
new: delete layer with DEL

File:
1 edited

Legend:

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

    r1913 r1917  
    2525import javax.swing.DefaultListSelectionModel;
    2626import javax.swing.Icon;
     27import javax.swing.JComponent;
    2728import javax.swing.JLabel;
    2829import javax.swing.JList;
     
    3031import javax.swing.JPanel;
    3132import javax.swing.JScrollPane;
     33import javax.swing.KeyStroke;
    3234import javax.swing.ListModel;
    3335import javax.swing.ListSelectionModel;
     
    129131        //-- delete layer action
    130132        DeleteLayerAction deleteLayerAction = new DeleteLayerAction();
     133        layerList.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
     134                KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0),"deleteLayer"
     135        );
     136        layerList.getActionMap().put("deleteLayer", deleteLayerAction);
    131137        adaptTo(deleteLayerAction, selectionModel);
    132138        buttonPanel.add(new SideButton(deleteLayerAction, "delete"));
     
    136142
    137143    /**
    138      * Create an layerlist and attach it to the given mapView.
     144     * Create an layer list and attach it to the given mapView.
    139145     */
    140146    protected LayerListDialog(MapFrame mapFrame) {
     
    186192    }
    187193
     194    /**
     195     * Wires <code>listener</code> to <code>listSelectionModel</code> in such a way, that
     196     * <code>listener</code> receives a {@see IEnabledStateUpdating#updateEnabledState()}
     197     * on every {@see ListSelectionEvent}.
     198     *
     199     * @param listener  the listener
     200     * @param listSelectionModel  the source emitting {@see ListSelectionEvent}s
     201     */
    188202    protected void adaptTo(final IEnabledStateUpdating listener, ListSelectionModel listSelectionModel) {
    189203        listSelectionModel.addListSelectionListener(
     
    196210    }
    197211
     212    /**
     213     * Wires <code>listener</code> to <code>listModel</code> in such a way, that
     214     * <code>listener</code> receives a {@see IEnabledStateUpdating#updateEnabledState()}
     215     * on every {@see ListDataEvent}.
     216     *
     217     * @param listener  the listener
     218     * @param listSelectionModel  the source emitting {@see ListDataEvent}s
     219     */
    198220    protected void adaptTo(final IEnabledStateUpdating listener, ListModel listModel) {
    199221        listModel.addListDataListener(
     
    213235        );
    214236    }
    215 
     237    /**
     238     * Wires <code>listener</code> to {@see MapView} in such a way, that
     239     * <code>listener</code> receives a {@see IEnabledStateUpdating#updateEnabledState()}
     240     * on every {@see LayerChangeListener}-event emitted by {@see MapView}.
     241     *
     242     * @param listener  the listener
     243     */
    216244    protected void adaptToLayerChanges(final IEnabledStateUpdating listener) {
    217245        Layer.listeners.add(
     
    374402            if (this.layer == null) {
    375403                List<Layer> selectedLayers = getModel().getSelectedLayers();
     404                if (selectedLayers.isEmpty())
     405                    return;
    376406                if (selectedLayers.size() == 1) {
    377407                    deleteSingleLayer(selectedLayers.get(0));
     
    473503                toActivate = model.getSelectedLayers().get(0);
    474504            }
    475             getModel().activateLayer(toActivate);
     505            // model is  going to be updated via LayerChangeListener
     506            // and PropertyChangeEvents
     507            Main.map.mapView.setActiveLayer(toActivate);
     508            toActivate.setVisible(true);
    476509        }
    477510
     
    662695    /**
    663696     * The layer list model. The model manages a list of layers and provides methods for
    664      * moving layers up and down, for toggling their visibiliy, for activating a layer.
     697     * moving layers up and down, for toggling their visibility, and for activating a layer.
    665698     *
    666699     * The model is a {@see ListModel} and it provides a {@see ListSelectionModel}. It expectes
     
    670703     * The model manages a list of {@see LayerListModelListener} which are mainly notified if
    671704     * the model requires views to make a specific list entry visible.
     705     *
     706     * It also listens to {@see PropertyChangeEvent}s of every {@see Layer} it manages, in particular to
     707     * the properties {@see Layer#VISIBLE_PROP} and {@see Layer#NAME_PROP}.
    672708     */
    673709    public class LayerListModel extends DefaultListModel implements LayerChangeListener, PropertyChangeListener{
     
    811847            if (layer == null)
    812848                return;
     849            layer.removePropertyChangeListener(this);
    813850            int size = getSize();
    814851            List<Integer> rows = getSelectedRows();
     
    829866            layer.addPropertyChangeListener(this);
    830867            fireContentsChanged(this, 0, getSize());
     868            int idx = getLayers().indexOf(layer);
     869            selectionModel.setSelectionInterval(idx, idx);
     870            ensureSelectedIsVisible();
    831871        }
    832872
     
    958998
    959999        /**
    960          * Activates the layer <code>layer</code>
    961          *
    962          * @param layer the layer
    963          */
    964         public void activateLayer(Layer layer) {
    965             if (layer == null)
    966                 return;
    967             Main.map.mapView.setActiveLayer(layer);
    968             layer.setVisible(true);
    969             int idx = getLayers().indexOf(layer);
    970             selectionModel.setSelectionInterval(idx,idx);
    971             ensureSelectedIsVisible();
    972         }
    973 
    974         /**
    9751000         * Replies the list of layers currently managed by {@see MapView}.
    9761001         * Never null, but can be empty.
     
    9831008                return Collections.<Layer>emptyList();
    9841009            return Main.map.mapView.getAllLayersAsList();
     1010        }
     1011
     1012        /**
     1013         * Ensures that at least one layer is selected in the layer dialog
     1014         *
     1015         */
     1016        protected void ensureActiveSelected() {
     1017            if (getLayers().size() == 0) return;
     1018            if (getActiveLayer() != null) {
     1019                // there's an active layer - select it and make it
     1020                // visible
     1021                int idx = getLayers().indexOf(getActiveLayer());
     1022                selectionModel.setSelectionInterval(idx, idx);
     1023                ensureSelectedIsVisible();
     1024            } else {
     1025                // no active layer - select the first one and make
     1026                // it visible
     1027                selectionModel.setSelectionInterval(0, 0);
     1028                ensureSelectedIsVisible();
     1029            }
     1030        }
     1031
     1032        /**
     1033         * Replies the active layer. null, if no active layer is available
     1034         *
     1035         * @return the active layer. null, if no active layer is available
     1036         */
     1037        protected Layer getActiveLayer() {
     1038            if (Main.map == null || Main.map.mapView == null) return null;
     1039            return Main.map.mapView.getActiveLayer();
    9851040        }
    9861041
     
    10171072                }
    10181073            }
     1074            ensureActiveSelected();
    10191075        }
    10201076
     
    10581114    }
    10591115
     1116    /**
     1117     * Creates a {@see ShowHideLayerAction} for <code>layer</code> in the
     1118     * context of this {@see LayerListDialog}.
     1119     *
     1120     * @param layer the layer
     1121     * @return the action
     1122     */
    10601123    public ShowHideLayerAction createShowHideLayerAction(Layer layer) {
    10611124        return new ShowHideLayerAction(layer);
    10621125    }
    10631126
     1127    /**
     1128     * Creates a {@see DeleteLayerAction} for <code>layer</code> in the
     1129     * context of this {@see LayerListDialog}.
     1130     *
     1131     * @param layer the layer
     1132     * @return the action
     1133     */
    10641134    public DeleteLayerAction createDeleteLayerAction(Layer layer) {
    10651135        return new DeleteLayerAction(layer);
    10661136    }
    10671137
     1138    /**
     1139     * Creates a {@see ActivateLayerAction} for <code>layer</code> in the
     1140     * context of this {@see LayerListDialog}.
     1141     *
     1142     * @param layer the layer
     1143     * @return the action
     1144     */
    10681145    public ActivateLayerAction createActivateLayerAction(Layer layer) {
    10691146        return new ActivateLayerAction(layer);
    10701147    }
    10711148
     1149    /**
     1150     * Creates a {@see MergeLayerAction} for <code>layer</code> in the
     1151     * context of this {@see LayerListDialog}.
     1152     *
     1153     * @param layer the layer
     1154     * @return the action
     1155     */
    10721156    public MergeAction createMergeLayerAction(Layer layer) {
    10731157        return new MergeAction(layer);
Note: See TracChangeset for help on using the changeset viewer.