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

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

fix some sonar issues recently introduced

  • 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 /**
26 * Constructs a new {@code AddNodeAction}.
27 */
28 public AddNodeAction() {
29 super(tr("Add Node..."), "addnode", tr("Add a node by entering latitude / longitude or easting / northing."),
30 Shortcut.registerShortcut("addnode", tr("Edit: {0}", tr("Add Node...")),
31 KeyEvent.VK_D, Shortcut.SHIFT), true);
32 putValue("help", ht("/Action/AddNode"));
33 }
34
35 @Override
36 public void actionPerformed(ActionEvent e) {
37 if (!isEnabled())
38 return;
39
40 LatLonDialog dialog = new LatLonDialog(Main.parent, tr("Add Node..."), ht("/Action/AddNode"));
41
42 if (textLatLon != null) {
43 dialog.setLatLonText(textLatLon);
44 }
45 if (textEastNorth != null) {
46 dialog.setEastNorthText(textEastNorth);
47 }
48
49 dialog.showDialog();
50
51 if (dialog.getValue() != 1)
52 return;
53
54 LatLon coordinates = dialog.getCoordinates();
55 if (coordinates == null)
56 return;
57
58 textLatLon = dialog.getLatLonText();
59 textEastNorth = dialog.getEastNorthText();
60
61 Node nnew = new Node(coordinates);
62
63 // add the node
64 Main.main.undoRedo.add(new AddCommand(nnew));
65 getCurrentDataSet().setSelected(nnew);
66 Main.map.mapView.repaint();
67 }
68
69 @Override
70 protected void updateEnabledState() {
71 setEnabled(getEditLayer() != null);
72 }
73}
Note: See TracBrowser for help on using the repository browser.