source: josm/trunk/src/org/openstreetmap/josm/actions/MoveNodeAction.java@ 13186

Last change on this file since 13186 was 12641, checked in by Don-vip, 7 years ago

see #15182 - deprecate Main.main.undoRedo. Replacement: gui.MainApplication.undoRedo

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.event.ActionEvent;
8import java.util.Collection;
9
10import org.openstreetmap.josm.Main;
11import org.openstreetmap.josm.command.MoveCommand;
12import org.openstreetmap.josm.data.coor.LatLon;
13import org.openstreetmap.josm.data.osm.Node;
14import org.openstreetmap.josm.data.osm.OsmPrimitive;
15import org.openstreetmap.josm.gui.MainApplication;
16import org.openstreetmap.josm.gui.dialogs.LatLonDialog;
17
18/**
19 * This action displays a dialog with the coordinates of a node where the user can change them,
20 * and when ok is pressed, the node is relocated to the specified position.
21 */
22public final class MoveNodeAction extends JosmAction {
23
24 /**
25 * Constructs a new {@code MoveNodeAction}.
26 */
27 public MoveNodeAction() {
28 super(tr("Move Node..."), "movenode", tr("Edit latitude and longitude of a node."),
29 null, /* no shortcut */
30 true);
31 putValue("help", ht("/Action/MoveNode"));
32 }
33
34 @Override
35 public void actionPerformed(ActionEvent e) {
36 Collection<Node> selNodes = getLayerManager().getEditDataSet().getSelectedNodes();
37 if (!isEnabled() || selNodes.size() != 1)
38 return;
39
40 LatLonDialog dialog = new LatLonDialog(Main.parent, tr("Move Node..."), ht("/Action/MoveNode"));
41 Node n = (Node) selNodes.toArray()[0];
42 dialog.setCoordinates(n.getCoor());
43 dialog.showDialog();
44 if (dialog.getValue() != 1)
45 return;
46
47 LatLon coordinates = dialog.getCoordinates();
48 if (coordinates == null)
49 return;
50
51 // move the node
52 MainApplication.undoRedo.add(new MoveCommand(n, coordinates));
53 MainApplication.getMap().mapView.repaint();
54 }
55
56 @Override
57 protected void updateEnabledState() {
58 updateEnabledStateOnCurrentSelection();
59 }
60
61 @Override
62 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
63 if (selection == null || selection.isEmpty()) {
64 setEnabled(false);
65 return;
66 }
67 if ((selection.size()) == 1 && (selection.toArray()[0] instanceof Node)) {
68 setEnabled(true);
69 } else {
70 setEnabled(false);
71 }
72 }
73}
Note: See TracBrowser for help on using the repository browser.