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

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

fix #8039, fix #10456: final fixes for the read-only/locked layers:

  • rename "read-only" to "locked" (in XML and Java classes/interfaces)
  • add a new download policy (true/never) to allow private layers forbidding only to download data, but allowing everything else

This leads to:

  • normal layers: download allowed, modifications allowed, upload allowed
  • private layers: download allowed or not (download=true/never), modifications allowed, upload allowed or not (upload=true/discouraged/never)
  • locked layers: nothing allowed, the data cannot be modified in any way
  • Property svn:eol-style set to native
File size: 2.5 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.DataSet;
14import org.openstreetmap.josm.data.osm.Node;
15import org.openstreetmap.josm.data.osm.OsmPrimitive;
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 if (selection == null || selection.isEmpty()
65 || selection.stream().map(OsmPrimitive::getDataSet).anyMatch(DataSet::isLocked)) {
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.