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

Last change on this file since 6806 was 6380, checked in by Don-vip, 10 years ago

update license/copyright information

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
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 // remember input from last time
23 private String textLatLon, textEastNorth;
24
25 public AddNodeAction() {
26 super(tr("Add Node..."), "addnode", tr("Add a node by entering latitude / longitude or easting / northing."),
27 Shortcut.registerShortcut("addnode", tr("Edit: {0}", tr("Add Node...")),
28 KeyEvent.VK_D, Shortcut.SHIFT), true);
29 putValue("help", ht("/Action/AddNode"));
30 }
31
32 @Override
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.