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

Last change on this file since 13685 was 13611, checked in by Don-vip, 6 years ago

fix #16176 - NPE

  • Property svn:eol-style set to native
File size: 2.3 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.data.osm.OsmUtils;
16import org.openstreetmap.josm.gui.MainApplication;
17import org.openstreetmap.josm.gui.dialogs.LatLonDialog;
18
19/**
20 * This action displays a dialog with the coordinates of a node where the user can change them,
21 * and when ok is pressed, the node is relocated to the specified position.
22 */
23public final class MoveNodeAction extends JosmAction {
24
25 /**
26 * Constructs a new {@code MoveNodeAction}.
27 */
28 public MoveNodeAction() {
29 super(tr("Move Node..."), "movenode", tr("Edit latitude and longitude of a node."),
30 null, /* no shortcut */
31 true);
32 putValue("help", ht("/Action/MoveNode"));
33 }
34
35 @Override
36 public void actionPerformed(ActionEvent e) {
37 Collection<Node> selNodes = getLayerManager().getEditDataSet().getSelectedNodes();
38 if (!isEnabled() || selNodes.size() != 1)
39 return;
40
41 LatLonDialog dialog = new LatLonDialog(Main.parent, tr("Move Node..."), ht("/Action/MoveNode"));
42 Node n = (Node) selNodes.toArray()[0];
43 dialog.setCoordinates(n.getCoor());
44 dialog.showDialog();
45 if (dialog.getValue() != 1)
46 return;
47
48 LatLon coordinates = dialog.getCoordinates();
49 if (coordinates == null)
50 return;
51
52 // move the node
53 MainApplication.undoRedo.add(new MoveCommand(n, coordinates));
54 MainApplication.getMap().mapView.repaint();
55 }
56
57 @Override
58 protected void updateEnabledState() {
59 updateEnabledStateOnCurrentSelection();
60 }
61
62 @Override
63 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
64 setEnabled(OsmUtils.isOsmCollectionEditable(selection) && selection.size() == 1 && selection.toArray()[0] instanceof Node);
65 }
66}
Note: See TracBrowser for help on using the repository browser.