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

Last change on this file since 4191 was 4191, checked in by stoecker, 13 years ago

remove old debug stuff

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