source: josm/trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java @ 4314

Revision 4314, 2.3 KB checked in by bastiK, 6 months ago (diff)

add east/north input to 'add node' and 'move node' actions

  • Property svn:eol-style set to native
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.event.ActionEvent;
8import java.awt.event.KeyEvent;
9
10import org.openstreetmap.josm.Main;
11import org.openstreetmap.josm.command.AddCommand;
12import org.openstreetmap.josm.data.coor.EastNorth;
13import org.openstreetmap.josm.data.coor.LatLon;
14import org.openstreetmap.josm.data.osm.Node;
15import org.openstreetmap.josm.gui.dialogs.LatLonDialog;
16import org.openstreetmap.josm.tools.Shortcut;
17
18/**
19 * This action displays a dialog where the user can enter a latitude and longitude,
20 * and when ok is pressed, a new node is created at the specified position.
21 */
22public final class AddNodeAction extends JosmAction {
23    // remember input from last time
24    private String textLatLon, textEastNorth;
25
26    public AddNodeAction() {
27        super(tr("Add Node..."), "addnode", tr("Add a node by entering latitude / longitude or easting / northing."),
28                Shortcut.registerShortcut("addnode", tr("Edit: {0}", tr("Add Node...")), KeyEvent.VK_D, Shortcut.GROUP_EDIT,
29                        Shortcut.SHIFT_DEFAULT), true);
30        putValue("help", ht("/Action/AddNode"));
31    }
32
33    public void actionPerformed(ActionEvent e) {
34        if (!isEnabled())
35            return;
36
37        LatLonDialog dialog = new LatLonDialog(Main.parent, tr("Add Node..."), ht("/Action/AddNode"));
38
39        if (textLatLon != null) {
40            dialog.setLatLonText(textLatLon);
41        }
42        if (textEastNorth != null) {
43            dialog.setEastNorthText(textEastNorth);
44        }
45
46        dialog.showDialog();
47       
48        if (dialog.getValue() != 1)
49            return;
50
51        LatLon coordinates = dialog.getCoordinates();
52        if (coordinates == null)
53            return;
54
55        textLatLon = dialog.getLatLonText();
56        textEastNorth = dialog.getEastNorthText();
57
58        Node nnew = new Node(coordinates);
59
60        // add the node
61        Main.main.undoRedo.add(new AddCommand(nnew));
62        getCurrentDataSet().setSelected(nnew);
63        Main.map.mapView.repaint();
64    }
65
66    @Override
67    protected void updateEnabledState() {
68        setEnabled(getEditLayer() != null);
69    }
70}
Note: See TracBrowser for help on using the repository browser.