Changeset 3099 in josm for trunk


Ignore:
Timestamp:
2010-03-09T13:27:07+01:00 (15 years ago)
Author:
Gubaer
Message:

fixed #4691: Exception when clicking 'Select'

File:
1 edited

Legend:

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

    r2930 r3099  
    1919import java.util.NoSuchElementException;
    2020
     21import javax.swing.AbstractAction;
    2122import javax.swing.BorderFactory;
    2223import javax.swing.DefaultListModel;
     
    4647import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
    4748import org.openstreetmap.josm.gui.SideButton;
     49import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;
    4850import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     51import org.openstreetmap.josm.tools.ImageProvider;
    4952import org.openstreetmap.josm.tools.Shortcut;
    5053
     
    7578    private JPopupMenu popupMenu;
    7679    private JMenuItem zoomToElement;
     80
     81    private SelectAction actSelect;
    7782
    7883    /**
     
    113118
    114119        JPanel buttonPanel = getButtonPanel(2);
    115 
    116         selectButton = new SideButton(marktr("Select"), "select", "SelectionList",
    117                 tr("Set the selected elements on the map to the selected items in the list above."),
    118                 new ActionListener() {
    119             public void actionPerformed(ActionEvent e) {
    120                 updateMap();
    121             }
    122         });
     120        //
     121        //        selectButton = new SideButton(marktr("Select"), "select", "SelectionList",
     122        //                tr("Set the selected elements on the map to the selected items in the list above."),
     123        //                new ActionListener() {
     124        //            public void actionPerformed(ActionEvent e) {
     125        //                updateMap();
     126        //            }
     127        //        });
     128        selectButton = new SideButton(actSelect = new SelectAction());
    123129        buttonPanel.add(selectButton);
    124130        BasicArrowButton selectionHistoryMenuButton = createArrowButton(selectButton);
     
    167173        SelectionEventManager.getInstance().addSelectionListener(this, FireMode.IN_EDT_CONSOLIDATED);
    168174        MapView.addEditLayerChangeListener(this);
     175        MapView.addEditLayerChangeListener(actSelect);
    169176        updateSelection();
    170177    }
     
    174181        SelectionEventManager.getInstance().removeSelectionListener(this);
    175182        MapView.removeEditLayerChangeListener(this);
     183        MapView.removeEditLayerChangeListener(actSelect);
    176184        updateTitle(0, 0, 0);
    177185    }
     
    391399        updateSelection();
    392400    }
     401
     402    class SelectAction extends AbstractAction implements EditLayerChangeListener {
     403        public SelectAction() {
     404            putValue(NAME, tr("Select"));
     405            putValue(SHORT_DESCRIPTION,  tr("Set the selected elements on the map to the selected items in the list above."));
     406            putValue(SMALL_ICON, ImageProvider.get("dialogs","select"));
     407            updateEnabledState();
     408        }
     409
     410        @Override
     411        public void actionPerformed(ActionEvent e) {
     412            updateMap();
     413        }
     414
     415        public void updateEnabledState() {
     416            setEnabled(Main.main != null && Main.main.getEditLayer() != null);
     417        }
     418
     419        @Override
     420        public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {
     421            updateEnabledState();
     422        }
     423    }
    393424}
Note: See TracChangeset for help on using the changeset viewer.