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

Revision 4314, 2.3 KB checked in by bastiK, 9 months ago (diff)

add east/north input to 'add node' and 'move node' actions

  • Property svn:eol-style set to native
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    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}
Note: See TracBrowser for help on using the repository browser.