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

Last change on this file since 8812 was 8443, checked in by Don-vip, 9 years ago

remove extra whitespaces

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