root/trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java

Revision 3363, 1.9 KB (checked in by stoecker, 2 months ago)

fix #5204 - wrong window title

  • 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.LatLon;
13import org.openstreetmap.josm.data.osm.Node;
14import org.openstreetmap.josm.gui.dialogs.LatLonDialog;
15import org.openstreetmap.josm.tools.Shortcut;
16
17/**
18 * This action displays a dialog where the user can enter a latitude and longitude,
19 * and when ok is pressed, a new node is created at the specified position.
20 */
21public final class AddNodeAction extends JosmAction {
22    //static private final Logger logger = Logger.getLogger(AddNodeAction.class.getName());
23
24    public AddNodeAction() {
25        super(tr("Add Node..."), "addnode", tr("Add a node by entering latitude and longitude."),
26                Shortcut.registerShortcut("addnode", tr("Edit: {0}", tr("Add Node...")), KeyEvent.VK_D, Shortcut.GROUP_EDIT,
27                        Shortcut.SHIFT_DEFAULT), true);
28        putValue("help", ht("/Action/AddNode"));
29    }
30
31    public void actionPerformed(ActionEvent e) {
32        if (!isEnabled())
33            return;
34
35        LatLonDialog dialog = new LatLonDialog(Main.parent, tr("Add Node..."), ht("/Action/AddNode"));
36        dialog.setVisible(true);
37        if (dialog.isCanceled())
38            return;
39
40        LatLon coordinates = dialog.getCoordinates();
41        if (coordinates == null)
42            return;
43        Node nnew = new Node(coordinates);
44
45        // add the node
46        Main.main.undoRedo.add(new AddCommand(nnew));
47        getCurrentDataSet().setSelected(nnew);
48        Main.map.mapView.repaint();
49    }
50
51    @Override
52    protected void updateEnabledState() {
53        setEnabled(getEditLayer() != null);
54    }
55}
Note: See TracBrowser for help on using the browser.