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.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 |
|
---|
23 | public MoveNodeAction() {
|
---|
24 | super(tr("Move Node..."), "movenode", tr("Edit latitude and longitude of a node."),
|
---|
25 | null, /* no shortcut */
|
---|
26 | true);
|
---|
27 | putValue("help", ht("/Action/MoveNode"));
|
---|
28 | }
|
---|
29 |
|
---|
30 | public void actionPerformed(ActionEvent e) {
|
---|
31 | if (!isEnabled() || (getCurrentDataSet().getSelectedNodes().size() != 1))
|
---|
32 | return;
|
---|
33 |
|
---|
34 | LatLonDialog dialog = new LatLonDialog(Main.parent, tr("Move Node..."), ht("/Action/MoveNode"));
|
---|
35 | Node n = (Node) getCurrentDataSet().getSelectedNodes().toArray()[0];
|
---|
36 | dialog.setCoordinates(n.getCoor());
|
---|
37 | dialog.showDialog();
|
---|
38 | if (dialog.getValue() != 1)
|
---|
39 | return;
|
---|
40 |
|
---|
41 | LatLon coordinates = dialog.getCoordinates();
|
---|
42 | if (coordinates == null)
|
---|
43 | return;
|
---|
44 |
|
---|
45 | // move the node
|
---|
46 | Main.main.undoRedo.add(new MoveCommand(n, coordinates));
|
---|
47 | Main.map.mapView.repaint();
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | protected void updateEnabledState() {
|
---|
52 | if (getCurrentDataSet() == null) {
|
---|
53 | setEnabled(false);
|
---|
54 | } else {
|
---|
55 | updateEnabledState(getCurrentDataSet().getSelected());
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | @Override
|
---|
60 | protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
|
---|
61 | if (selection == null || selection.isEmpty()) {
|
---|
62 | setEnabled(false);
|
---|
63 | return;
|
---|
64 | }
|
---|
65 | if ((selection.size()) == 1 && (selection.toArray()[0] instanceof Node) ) {
|
---|
66 | setEnabled(true);
|
---|
67 | } else {
|
---|
68 | setEnabled(false);
|
---|
69 | }
|
---|
70 | }
|
---|
71 | }
|
---|