1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 |
|
---|
7 | import java.awt.event.ActionEvent;
|
---|
8 | import java.awt.event.KeyEvent;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.Main;
|
---|
11 | import org.openstreetmap.josm.command.AddCommand;
|
---|
12 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
13 | import org.openstreetmap.josm.data.osm.Node;
|
---|
14 | import org.openstreetmap.josm.gui.dialogs.LatLonDialog;
|
---|
15 | import 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 | */
|
---|
21 | public 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 | }
|
---|