Changeset 1807 in josm for trunk/src/org


Ignore:
Timestamp:
2009-07-19T00:06:29+02:00 (15 years ago)
Author:
Gubaer
Message:

fixed #2987: Can't add Point

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java

    r1415 r1807  
    1717import org.openstreetmap.josm.data.osm.Node;
    1818import org.openstreetmap.josm.data.coor.LatLon;
     19import org.openstreetmap.josm.gui.layer.Layer;
     20import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
    1921import org.openstreetmap.josm.tools.GBC;
    2022import org.openstreetmap.josm.tools.Shortcut;
     
    2426 * and when ok is pressed, a new node is created at the specified position.
    2527 */
    26 public final class AddNodeAction extends JosmAction {
     28public final class AddNodeAction extends JosmAction implements LayerChangeListener {
    2729
    2830    public AddNodeAction() {
    2931        super(tr("Add Node..."), "addnode", tr("Add a node by entering latitude and longitude."),
    30         Shortcut.registerShortcut("addnode", tr("Edit: {0}", tr("Add Node...")), KeyEvent.VK_D, Shortcut.GROUP_EDIT,
    31         Shortcut.SHIFT_DEFAULT), true);
     32                Shortcut.registerShortcut("addnode", tr("Edit: {0}", tr("Add Node...")), KeyEvent.VK_D, Shortcut.GROUP_EDIT,
     33                        Shortcut.SHIFT_DEFAULT), true);
     34        Layer.listeners.add(this);
     35        refreshEnabled();
     36    }
     37
     38    protected void refreshEnabled() {
     39        setEnabled(Main.map != null
     40                && Main.map.mapView != null
     41                && Main.map.mapView.getEditLayer() != null);
    3242    }
    3343
    3444    public void actionPerformed(ActionEvent e) {
     45        // we abort if we are not in the context of an OsmDataLayer
     46        //
     47        if (!isEnabled())
     48            return;
     49
    3550        JPanel p = new JPanel(new GridBagLayout());
    3651        p.add(new JLabel("<html>"+
     
    5671            try {
    5772                LatLon ll = new LatLon(Double.parseDouble(lat.getText()), Double.parseDouble(lon.getText()));
    58                 if (!ll.isOutSideWorld()) nnew = new Node(ll);
     73                if (!ll.isOutSideWorld()) {
     74                    nnew = new Node(ll);
     75                }
    5976            } catch (Exception ex) { }
    6077        }
    6178
    6279        /* Now execute the commands to add the dupicated contents of the paste buffer to the map */
    63 
    6480        Main.main.undoRedo.add(new AddCommand(nnew));
    6581        Main.ds.setSelected(nnew);
    6682        Main.map.mapView.repaint();
    6783    }
     84
     85    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     86        refreshEnabled();
     87    }
     88
     89    public void layerAdded(Layer newLayer) {
     90        refreshEnabled();
     91
     92    }
     93
     94    public void layerRemoved(Layer oldLayer) {
     95        refreshEnabled();
     96    }
    6897}
Note: See TracChangeset for help on using the changeset viewer.