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

Last change on this file since 6162 was 6084, checked in by bastiK, 11 years ago

see #8902 - add missing @Override annotations (patch by shinigami)

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
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.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 */
21public 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 @Override
31 public void actionPerformed(ActionEvent e) {
32 if (!isEnabled() || (getCurrentDataSet().getSelectedNodes().size() != 1))
33 return;
34
35 LatLonDialog dialog = new LatLonDialog(Main.parent, tr("Move Node..."), ht("/Action/MoveNode"));
36 Node n = (Node) getCurrentDataSet().getSelectedNodes().toArray()[0];
37 dialog.setCoordinates(n.getCoor());
38 dialog.showDialog();
39 if (dialog.getValue() != 1)
40 return;
41
42 LatLon coordinates = dialog.getCoordinates();
43 if (coordinates == null)
44 return;
45
46 // move the node
47 Main.main.undoRedo.add(new MoveCommand(n, coordinates));
48 Main.map.mapView.repaint();
49 }
50
51 @Override
52 protected void updateEnabledState() {
53 if (getCurrentDataSet() == null) {
54 setEnabled(false);
55 } else {
56 updateEnabledState(getCurrentDataSet().getSelected());
57 }
58 }
59
60 @Override
61 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
62 if (selection == null || selection.isEmpty()) {
63 setEnabled(false);
64 return;
65 }
66 if ((selection.size()) == 1 && (selection.toArray()[0] instanceof Node) ) {
67 setEnabled(true);
68 } else {
69 setEnabled(false);
70 }
71 }
72}
Note: See TracBrowser for help on using the repository browser.