| 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 | //static private final Logger logger = Logger.getLogger(AddNodeAction.class.getName()); |
|---|
| 23 | |
|---|
| 24 | public AddNodeAction() { |
|---|
| 25 | super(tr("Add Node..."), "addnode", tr("Add a node by entering latitude and longitude."), |
|---|
| 26 | Shortcut.registerShortcut("addnode", tr("Edit: {0}", tr("Add Node...")), KeyEvent.VK_D, Shortcut.GROUP_EDIT, |
|---|
| 27 | Shortcut.SHIFT_DEFAULT), true); |
|---|
| 28 | putValue("help", ht("/Action/AddNode")); |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | public void actionPerformed(ActionEvent e) { |
|---|
| 32 | if (!isEnabled()) |
|---|
| 33 | return; |
|---|
| 34 | |
|---|
| 35 | LatLonDialog dialog = new LatLonDialog(Main.parent, tr("Add Node..."), ht("/Action/AddNode")); |
|---|
| 36 | dialog.setVisible(true); |
|---|
| 37 | if (dialog.isCanceled()) |
|---|
| 38 | return; |
|---|
| 39 | |
|---|
| 40 | LatLon coordinates = dialog.getCoordinates(); |
|---|
| 41 | if (coordinates == null) |
|---|
| 42 | return; |
|---|
| 43 | Node nnew = new Node(coordinates); |
|---|
| 44 | |
|---|
| 45 | // add the node |
|---|
| 46 | Main.main.undoRedo.add(new AddCommand(nnew)); |
|---|
| 47 | getCurrentDataSet().setSelected(nnew); |
|---|
| 48 | Main.map.mapView.repaint(); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | @Override |
|---|
| 52 | protected void updateEnabledState() { |
|---|
| 53 | setEnabled(getEditLayer() != null); |
|---|
| 54 | } |
|---|
| 55 | } |
|---|