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

Last change on this file since 3734 was 3656, checked in by bastiK, 13 years ago

applied #5604 (patch by m.zdila) - support different formats of GPS coordinates in Add Node

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
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 text;
24
25 //static private final Logger logger = Logger.getLogger(AddNodeAction.class.getName());
26
27 public AddNodeAction() {
28 super(tr("Add Node..."), "addnode", tr("Add a node by entering latitude and longitude."),
29 Shortcut.registerShortcut("addnode", tr("Edit: {0}", tr("Add Node...")), KeyEvent.VK_D, Shortcut.GROUP_EDIT,
30 Shortcut.SHIFT_DEFAULT), true);
31 putValue("help", ht("/Action/AddNode"));
32 }
33
34 public void actionPerformed(ActionEvent e) {
35 if (!isEnabled())
36 return;
37
38 LatLonDialog dialog = new LatLonDialog(Main.parent, tr("Add Node..."), ht("/Action/AddNode"));
39
40 if (text != null) {
41 dialog.setText(text);
42 }
43
44 dialog.setVisible(true);
45 if (dialog.isCanceled())
46 return;
47
48 LatLon coordinates = dialog.getCoordinates();
49 if (coordinates == null)
50 return;
51
52 text = dialog.getText();
53
54 Node nnew = new Node(coordinates);
55
56 // add the node
57 Main.main.undoRedo.add(new AddCommand(nnew));
58 getCurrentDataSet().setSelected(nnew);
59 Main.map.mapView.repaint();
60 }
61
62 @Override
63 protected void updateEnabledState() {
64 setEnabled(getEditLayer() != null);
65 }
66}
Note: See TracBrowser for help on using the repository browser.