[6380] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[3720] | 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.util.Collection;
|
---|
| 9 |
|
---|
| 10 | import org.openstreetmap.josm.Main;
|
---|
| 11 | import org.openstreetmap.josm.command.MoveCommand;
|
---|
| 12 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
| 13 | import org.openstreetmap.josm.data.osm.Node;
|
---|
| 14 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
| 15 | import org.openstreetmap.josm.gui.dialogs.LatLonDialog;
|
---|
| 16 |
|
---|
| 17 | /**
|
---|
| 18 | * This action displays a dialog with the coordinates of a node where the user can change them,
|
---|
| 19 | * and when ok is pressed, the node is relocated to the specified position.
|
---|
| 20 | */
|
---|
| 21 | public final class MoveNodeAction extends JosmAction {
|
---|
| 22 |
|
---|
[7859] | 23 | /**
|
---|
| 24 | * Constructs a new {@code MoveNodeAction}.
|
---|
| 25 | */
|
---|
[3720] | 26 | public MoveNodeAction() {
|
---|
| 27 | super(tr("Move Node..."), "movenode", tr("Edit latitude and longitude of a node."),
|
---|
| 28 | null, /* no shortcut */
|
---|
| 29 | true);
|
---|
| 30 | putValue("help", ht("/Action/MoveNode"));
|
---|
| 31 | }
|
---|
| 32 |
|
---|
[6084] | 33 | @Override
|
---|
[3720] | 34 | public void actionPerformed(ActionEvent e) {
|
---|
[10382] | 35 | Collection<Node> selNodes = getLayerManager().getEditDataSet().getSelectedNodes();
|
---|
| 36 | if (!isEnabled() || selNodes.size() != 1)
|
---|
[3720] | 37 | return;
|
---|
| 38 |
|
---|
| 39 | LatLonDialog dialog = new LatLonDialog(Main.parent, tr("Move Node..."), ht("/Action/MoveNode"));
|
---|
[10382] | 40 | Node n = (Node) selNodes.toArray()[0];
|
---|
[3720] | 41 | dialog.setCoordinates(n.getCoor());
|
---|
[4314] | 42 | dialog.showDialog();
|
---|
| 43 | if (dialog.getValue() != 1)
|
---|
[3720] | 44 | return;
|
---|
| 45 |
|
---|
| 46 | LatLon coordinates = dialog.getCoordinates();
|
---|
| 47 | if (coordinates == null)
|
---|
| 48 | return;
|
---|
| 49 |
|
---|
| 50 | // move the node
|
---|
| 51 | Main.main.undoRedo.add(new MoveCommand(n, coordinates));
|
---|
| 52 | Main.map.mapView.repaint();
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | @Override
|
---|
| 56 | protected void updateEnabledState() {
|
---|
[10548] | 57 | updateEnabledStateOnCurrentSelection();
|
---|
[3720] | 58 | }
|
---|
| 59 |
|
---|
| 60 | @Override
|
---|
| 61 | protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
|
---|
| 62 | if (selection == null || selection.isEmpty()) {
|
---|
| 63 | setEnabled(false);
|
---|
| 64 | return;
|
---|
| 65 | }
|
---|
[8443] | 66 | if ((selection.size()) == 1 && (selection.toArray()[0] instanceof Node)) {
|
---|
[3720] | 67 | setEnabled(true);
|
---|
| 68 | } else {
|
---|
| 69 | setEnabled(false);
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 | }
|
---|