Changeset 2697 in josm


Ignore:
Timestamp:
2009-12-28T20:45:40+01:00 (15 years ago)
Author:
Gubaer
Message:

fixed #4222: Layerlist right click menu does not handle multiselection

Location:
trunk
Files:
1 added
2 edited

Legend:

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

    r2677 r2697  
    55import java.awt.BorderLayout;
    66import java.awt.Component;
    7 import java.awt.GridLayout;
     7import java.awt.FlowLayout;
    88import java.awt.Point;
    99import java.awt.Rectangle;
     
    2929import javax.swing.JPanel;
    3030import javax.swing.JScrollPane;
     31import javax.swing.JToolBar;
    3132import javax.swing.KeyStroke;
    3233import javax.swing.ListModel;
     
    4243import org.openstreetmap.josm.gui.MapFrame;
    4344import org.openstreetmap.josm.gui.MapView;
    44 import org.openstreetmap.josm.gui.SideButton;
     45import org.openstreetmap.josm.gui.help.HelpUtil;
    4546import org.openstreetmap.josm.gui.io.SaveLayersDialog;
    4647import org.openstreetmap.josm.gui.layer.Layer;
    4748import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     49import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
    4850import org.openstreetmap.josm.tools.ImageProvider;
    4951import org.openstreetmap.josm.tools.Shortcut;
     
    9698
    9799    protected JPanel createButtonPanel() {
    98         JPanel buttonPanel = new JPanel(new GridLayout(1, 5));
     100        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT,0,0));
     101
     102        JToolBar tb = new JToolBar(JToolBar.HORIZONTAL);
     103        tb.setFloatable(false);
    99104
    100105        // -- move up action
     
    102107        adaptTo(moveUpAction, model);
    103108        adaptTo(moveUpAction,selectionModel);
    104         buttonPanel.add(new SideButton(moveUpAction));
     109        tb.add(moveUpAction);
    105110
    106111        // -- move down action
     
    108113        adaptTo(moveDownAction, model);
    109114        adaptTo(moveDownAction,selectionModel);
    110         buttonPanel.add(new SideButton(moveDownAction));
     115        tb.add(moveDownAction);
    111116
    112117        // -- activate action
     
    114119        adaptTo(activateLayerAction, selectionModel);
    115120        MapView.addLayerChangeListener(activateLayerAction);
    116         buttonPanel.add(new SideButton(activateLayerAction, "activate"));
     121        tb.add(activateLayerAction);
    117122
    118123        // -- show hide action
    119124        ShowHideLayerAction showHideLayerAction = new ShowHideLayerAction();
    120125        adaptTo(showHideLayerAction, selectionModel);
    121         buttonPanel.add(new SideButton(showHideLayerAction, "showhide"));
     126        tb.add(showHideLayerAction);
    122127
    123128        // -- merge layer action
     
    125130        adaptTo(mergeLayerAction, model);
    126131        adaptTo(mergeLayerAction,selectionModel);
    127         buttonPanel.add(new SideButton(mergeLayerAction));
     132        tb.add(mergeLayerAction);
     133
    128134
    129135        //-- delete layer action
     
    134140        layerList.getActionMap().put("deleteLayer", deleteLayerAction);
    135141        adaptTo(deleteLayerAction, selectionModel);
    136         buttonPanel.add(new SideButton(deleteLayerAction, "delete"));
    137 
     142        tb.add(deleteLayerAction);
     143
     144        buttonPanel.add(tb);
    138145        return buttonPanel;
    139146    }
     
    157164        layerList = new LayerList(model);
    158165        layerList.setSelectionModel(selectionModel);
    159         layerList.addMouseListener(new LayerListMouseAdapter());
     166        layerList.addMouseListener(new DblClickAdapter());
     167        layerList.addMouseListener(new PopupMenuHandler());
    160168        layerList.setBackground(UIManager.getColor("Button.background"));
    161169        layerList.setCellRenderer(new LayerListCellRenderer());
     
    172180                        layerList.ensureIndexIsVisible(index);
    173181                    }
    174 
    175182                    public void refresh() {
    176183                        layerList.repaint();
     
    244251     */
    245252    public final  class DeleteLayerAction extends AbstractAction implements IEnabledStateUpdating {
    246         private  Layer layer;
    247 
    248         /**
    249          * Creates a {@see DeleteLayerAction} for a specific layer.
    250          *
    251          * @param layer the layer. Must not be null.
    252          * @exception IllegalArgumentException thrown, if layer is null
    253          */
    254         public DeleteLayerAction(Layer layer) {
    255             this();
    256             if (layer == null)
    257                 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "layer"));
    258             this.layer = layer;
    259             putValue(NAME, tr("Delete"));
    260             updateEnabledState();
    261         }
    262 
    263253        /**
    264254         * Creates a {@see DeleteLayerAction} which will delete the currently
     
    268258        public DeleteLayerAction() {
    269259            putValue(SMALL_ICON,ImageProvider.get("dialogs", "delete"));
    270             putValue(SHORT_DESCRIPTION, tr("Delete the selected layer."));
    271             putValue("help", "Action/LayerDelete");
     260            putValue(SHORT_DESCRIPTION, tr("Delete the selected layers."));
     261            putValue(NAME, tr("Delete"));
     262            putValue("help", HelpUtil.ht("/Dialog/LayerDialog#DeleteLayer"));
    272263            updateEnabledState();
    273264        }
     
    299290
    300291        public void actionPerformed(ActionEvent e) {
    301             List<Layer> selectedLayers;
    302             if (this.layer == null) {
    303                 selectedLayers = getModel().getSelectedLayers();
    304             } else {
    305                 selectedLayers = Collections.singletonList(this.layer);
    306             }
     292            List<Layer> selectedLayers = getModel().getSelectedLayers();
    307293            if (selectedLayers.isEmpty())
    308294                return;
     
    315301
    316302        public void updateEnabledState() {
    317             if (layer == null) {
    318                 setEnabled(! getModel().getSelectedLayers().isEmpty());
    319             } else {
    320                 setEnabled(true);
    321             }
     303            setEnabled(! getModel().getSelectedLayers().isEmpty());
    322304        }
    323305    }
     
    350332            putValue(SMALL_ICON, ImageProvider.get("dialogs", "showhide"));
    351333            putValue(SHORT_DESCRIPTION, tr("Toggle visible state of the selected layer."));
    352             putValue("help", "Action/LayerShowHide");
     334            putValue("help", HelpUtil.ht("/Dialog/LayerDialog#ShowHideLayer"));
    353335            updateEnabledState();
    354336        }
     
    392374            putValue(SMALL_ICON, ImageProvider.get("dialogs", "activate"));
    393375            putValue(SHORT_DESCRIPTION, tr("Activate the selected layer"));
    394             putValue("help", "Action/ActivateLayer");
     376            putValue("help", HelpUtil.ht("/Dialog/LayerDialog#ActivateLayer"));
    395377            updateEnabledState();
    396378        }
     
    457439            putValue(SMALL_ICON, ImageProvider.get("dialogs", "mergedown"));
    458440            putValue(SHORT_DESCRIPTION, tr("Merge this layer into another layer"));
    459             putValue("help", "Action/MergeLayer");
     441            putValue("help", HelpUtil.ht("/Dialog/LayerDialog#MergeLayer"));
    460442            updateEnabledState();
    461443        }
     
    521503    }
    522504
    523     class LayerListMouseAdapter extends MouseAdapter {
    524 
    525         private void openPopup(MouseEvent e) {
    526             Point p = e.getPoint();
     505    class PopupMenuHandler extends PopupMenuLauncher {
     506        @Override
     507        public void launch(MouseEvent evt) {
     508            Point p = evt.getPoint();
    527509            int index = layerList.locationToIndex(p);
    528510            if (index < 0) return;
    529             if (!layerList.getCellBounds(index, index).contains(e.getPoint()))
     511            if (!layerList.getCellBounds(index, index).contains(evt.getPoint()))
    530512                return;
    531513            if (!layerList.isSelectedIndex(index)) {
     
    536518            menu.show(LayerListDialog.this, p.x, p.y-3);
    537519        }
    538         @Override public void mousePressed(MouseEvent e) {
    539             if (e.isPopupTrigger()) {
    540                 openPopup(e);
    541             }
    542         }
    543         @Override public void mouseReleased(MouseEvent e) {
    544             if (e.isPopupTrigger()) {
    545                 openPopup(e);
    546             }
    547         }
     520    }
     521
     522    class DblClickAdapter extends MouseAdapter {
    548523        @Override public void mouseClicked(MouseEvent e) {
    549524            if (e.getClickCount() == 2) {
     
    10421017     */
    10431018    public DeleteLayerAction createDeleteLayerAction(Layer layer) {
    1044         return new DeleteLayerAction(layer);
     1019        // the delete layer action doesn't depend on the current layer
     1020        return new DeleteLayerAction();
    10451021    }
    10461022
Note: See TracChangeset for help on using the changeset viewer.