| [1130] | 1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
|---|
| 2 | package org.openstreetmap.josm.actions;
|
|---|
| 3 |
|
|---|
| [2531] | 4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
|---|
| [1130] | 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;
|
|---|
| [1820] | 12 | import org.openstreetmap.josm.data.coor.LatLon;
|
|---|
| [1130] | 13 | import org.openstreetmap.josm.data.osm.Node;
|
|---|
| [3266] | 14 | import org.openstreetmap.josm.gui.dialogs.LatLonDialog;
|
|---|
| [1130] | 15 | import org.openstreetmap.josm.tools.Shortcut;
|
|---|
| 16 |
|
|---|
| 17 | /**
|
|---|
| [1169] | 18 | * This action displays a dialog where the user can enter a latitude and longitude,
|
|---|
| [1130] | 19 | * and when ok is pressed, a new node is created at the specified position.
|
|---|
| 20 | */
|
|---|
| [1820] | 21 | public final class AddNodeAction extends JosmAction {
|
|---|
| [2626] | 22 | //static private final Logger logger = Logger.getLogger(AddNodeAction.class.getName());
|
|---|
| [1130] | 23 |
|
|---|
| 24 | public AddNodeAction() {
|
|---|
| [1218] | 25 | super(tr("Add Node..."), "addnode", tr("Add a node by entering latitude and longitude."),
|
|---|
| [1807] | 26 | Shortcut.registerShortcut("addnode", tr("Edit: {0}", tr("Add Node...")), KeyEvent.VK_D, Shortcut.GROUP_EDIT,
|
|---|
| 27 | Shortcut.SHIFT_DEFAULT), true);
|
|---|
| [2323] | 28 | putValue("help", ht("/Action/AddNode"));
|
|---|
| [1130] | 29 | }
|
|---|
| 30 |
|
|---|
| [1169] | 31 | public void actionPerformed(ActionEvent e) {
|
|---|
| [1807] | 32 | if (!isEnabled())
|
|---|
| 33 | return;
|
|---|
| 34 |
|
|---|
| [3363] | 35 | LatLonDialog dialog = new LatLonDialog(Main.parent, tr("Add Node..."), ht("/Action/AddNode"));
|
|---|
| [2543] | 36 | dialog.setVisible(true);
|
|---|
| 37 | if (dialog.isCanceled())
|
|---|
| 38 | return;
|
|---|
| [1169] | 39 |
|
|---|
| [2543] | 40 | LatLon coordinates = dialog.getCoordinates();
|
|---|
| 41 | if (coordinates == null)
|
|---|
| 42 | return;
|
|---|
| 43 | Node nnew = new Node(coordinates);
|
|---|
| [1169] | 44 |
|
|---|
| [2543] | 45 | // add the node
|
|---|
| [1169] | 46 | Main.main.undoRedo.add(new AddCommand(nnew));
|
|---|
| [1814] | 47 | getCurrentDataSet().setSelected(nnew);
|
|---|
| [1169] | 48 | Main.map.mapView.repaint();
|
|---|
| [1130] | 49 | }
|
|---|
| [1807] | 50 |
|
|---|
| [1820] | 51 | @Override
|
|---|
| 52 | protected void updateEnabledState() {
|
|---|
| 53 | setEnabled(getEditLayer() != null);
|
|---|
| [1807] | 54 | }
|
|---|
| [1820] | 55 | }
|
|---|