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

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

see #15182 - deprecate Main.main.undoRedo. Replacement: gui.MainApplication.undoRedo

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