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

Last change on this file since 8210 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
RevLine 
[6380]1// License: GPL. For details, see LICENSE file.
[1130]2package org.openstreetmap.josm.actions;
3
[2531]4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
[1130]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;
[1820]12import org.openstreetmap.josm.data.coor.LatLon;
[1130]13import org.openstreetmap.josm.data.osm.Node;
[3266]14import org.openstreetmap.josm.gui.dialogs.LatLonDialog;
[1130]15import org.openstreetmap.josm.tools.Shortcut;
16
17/**
[1169]18 * This action displays a dialog where the user can enter a latitude and longitude,
[1130]19 * and when ok is pressed, a new node is created at the specified position.
20 */
[1820]21public final class AddNodeAction extends JosmAction {
[3656]22 // remember input from last time
[4314]23 private String textLatLon, textEastNorth;
[3656]24
[6977]25 /**
26 * Constructs a new {@code AddNodeAction}.
27 */
[1130]28 public AddNodeAction() {
[4314]29 super(tr("Add Node..."), "addnode", tr("Add a node by entering latitude / longitude or easting / northing."),
[4942]30 Shortcut.registerShortcut("addnode", tr("Edit: {0}", tr("Add Node...")),
[4982]31 KeyEvent.VK_D, Shortcut.SHIFT), true);
[2323]32 putValue("help", ht("/Action/AddNode"));
[1130]33 }
34
[6084]35 @Override
[1169]36 public void actionPerformed(ActionEvent e) {
[1807]37 if (!isEnabled())
38 return;
39
[3363]40 LatLonDialog dialog = new LatLonDialog(Main.parent, tr("Add Node..."), ht("/Action/AddNode"));
[3656]41
[4314]42 if (textLatLon != null) {
43 dialog.setLatLonText(textLatLon);
[3656]44 }
[4314]45 if (textEastNorth != null) {
46 dialog.setEastNorthText(textEastNorth);
47 }
[3656]48
[4314]49 dialog.showDialog();
[6069]50
[4314]51 if (dialog.getValue() != 1)
[2543]52 return;
[1169]53
[2543]54 LatLon coordinates = dialog.getCoordinates();
55 if (coordinates == null)
56 return;
[3656]57
[4314]58 textLatLon = dialog.getLatLonText();
59 textEastNorth = dialog.getEastNorthText();
[3656]60
[2543]61 Node nnew = new Node(coordinates);
[1169]62
[2543]63 // add the node
[1169]64 Main.main.undoRedo.add(new AddCommand(nnew));
[1814]65 getCurrentDataSet().setSelected(nnew);
[1169]66 Main.map.mapView.repaint();
[1130]67 }
[1807]68
[1820]69 @Override
70 protected void updateEnabledState() {
71 setEnabled(getEditLayer() != null);
[1807]72 }
[1820]73}
Note: See TracBrowser for help on using the repository browser.