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

Last change on this file since 13193 was 12726, checked in by Don-vip, 7 years ago

see #13036 - deprecate Command() default constructor, fix unit tests and java warnings

  • Property svn:eol-style set to native
File size: 2.7 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;
[8790]9import java.util.Collections;
[1130]10
11import org.openstreetmap.josm.Main;
12import org.openstreetmap.josm.command.AddCommand;
[1820]13import org.openstreetmap.josm.data.coor.LatLon;
[12726]14import org.openstreetmap.josm.data.osm.DataSet;
[1130]15import org.openstreetmap.josm.data.osm.Node;
[8790]16import org.openstreetmap.josm.data.osm.OsmPrimitive;
[12630]17import org.openstreetmap.josm.gui.MainApplication;
18import org.openstreetmap.josm.gui.MapView;
[3266]19import org.openstreetmap.josm.gui.dialogs.LatLonDialog;
[1130]20import org.openstreetmap.josm.tools.Shortcut;
21
22/**
[1169]23 * This action displays a dialog where the user can enter a latitude and longitude,
[1130]24 * and when ok is pressed, a new node is created at the specified position.
25 */
[1820]26public final class AddNodeAction extends JosmAction {
[3656]27 // remember input from last time
[4314]28 private String textLatLon, textEastNorth;
[3656]29
[6977]30 /**
31 * Constructs a new {@code AddNodeAction}.
32 */
[1130]33 public AddNodeAction() {
[4314]34 super(tr("Add Node..."), "addnode", tr("Add a node by entering latitude / longitude or easting / northing."),
[4942]35 Shortcut.registerShortcut("addnode", tr("Edit: {0}", tr("Add Node...")),
[4982]36 KeyEvent.VK_D, Shortcut.SHIFT), true);
[2323]37 putValue("help", ht("/Action/AddNode"));
[1130]38 }
39
[6084]40 @Override
[1169]41 public void actionPerformed(ActionEvent e) {
[1807]42 if (!isEnabled())
43 return;
44
[3363]45 LatLonDialog dialog = new LatLonDialog(Main.parent, tr("Add Node..."), ht("/Action/AddNode"));
[3656]46
[4314]47 if (textLatLon != null) {
48 dialog.setLatLonText(textLatLon);
[3656]49 }
[4314]50 if (textEastNorth != null) {
51 dialog.setEastNorthText(textEastNorth);
52 }
[3656]53
[4314]54 dialog.showDialog();
[6069]55
[4314]56 if (dialog.getValue() != 1)
[2543]57 return;
[1169]58
[2543]59 LatLon coordinates = dialog.getCoordinates();
60 if (coordinates == null)
61 return;
[3656]62
[4314]63 textLatLon = dialog.getLatLonText();
64 textEastNorth = dialog.getEastNorthText();
[3656]65
[2543]66 Node nnew = new Node(coordinates);
[1169]67
[2543]68 // add the node
[12726]69 DataSet ds = getLayerManager().getEditDataSet();
70 MainApplication.undoRedo.add(new AddCommand(ds, nnew));
71 ds.setSelected(nnew);
[12630]72 MapView mapView = MainApplication.getMap().mapView;
73 if (mapView != null && !mapView.getRealBounds().contains(nnew.getCoor())) {
[12104]74 AutoScaleAction.zoomTo(Collections.<OsmPrimitive>singleton(nnew));
[8790]75 }
[1130]76 }
[1807]77
[1820]78 @Override
79 protected void updateEnabledState() {
[10382]80 setEnabled(getLayerManager().getEditLayer() != null);
[1807]81 }
[1820]82}
Note: See TracBrowser for help on using the repository browser.