Skip to content

Commit 705978b

Browse files
committed
Add option to toggle layer read-only status to popup menu
1 parent 0f1bb9b commit 705978b

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// License: GPL. For details, see LICENSE file.
2+
package org.openstreetmap.josm.actions;
3+
4+
import static org.openstreetmap.josm.tools.I18n.tr;
5+
6+
import java.awt.Component;
7+
import java.awt.event.ActionEvent;
8+
import java.util.List;
9+
10+
import javax.swing.AbstractAction;
11+
import javax.swing.JCheckBoxMenuItem;
12+
13+
import org.openstreetmap.josm.data.osm.Lockable;
14+
import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
15+
import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer;
16+
import org.openstreetmap.josm.gui.layer.Layer;
17+
import org.openstreetmap.josm.gui.layer.Layer.LayerAction;
18+
19+
/**
20+
* An action enabling/disabling the {@linkplain AbstractModifiableLayer#lock() read-only flag}
21+
* of the layer specified in the constructor.
22+
*
23+
* @since XXX
24+
*/
25+
public class ToggleEditLockLayerAction extends AbstractAction implements LayerAction {
26+
27+
private final AbstractModifiableLayer layer;
28+
29+
/**
30+
* Construct a new {@code ToggleEditLockLayerAction}
31+
* @param layer the layer for which to toggle the {@linkplain AbstractModifiableLayer#lock() read-only flag}
32+
*
33+
* @since XXX
34+
*/
35+
public ToggleEditLockLayerAction(AbstractModifiableLayer layer) {
36+
super(tr("Prevent modification"));
37+
putValue(SHORT_DESCRIPTION, tr("Prevent/allow changes being made in this layer"));
38+
this.layer = layer;
39+
}
40+
41+
@Override
42+
public void actionPerformed(ActionEvent e) {
43+
if (layer.isLocked()) {
44+
layer.unlock();
45+
} else {
46+
layer.lock();
47+
}
48+
49+
layer.invalidate();
50+
LayerListDialog.getInstance().repaint();
51+
}
52+
53+
@Override
54+
public Component createMenuComponent() {
55+
JCheckBoxMenuItem item = new JCheckBoxMenuItem(this);
56+
item.setSelected(layer.isLocked());
57+
return item;
58+
}
59+
60+
@Override
61+
public boolean supportLayers(List<Layer> layers) {
62+
return layers.size() == 1 && layers.get(0) instanceof Lockable;
63+
}
64+
}

src/org/openstreetmap/josm/actions/ToggleUploadDiscouragedLayerAction.java

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class ToggleUploadDiscouragedLayerAction extends AbstractAction implement
3131
*/
3232
public ToggleUploadDiscouragedLayerAction(OsmDataLayer layer) {
3333
super(tr("Discourage upload"));
34+
putValue(SHORT_DESCRIPTION, tr("Allow/disallow upload of changes made in this layer"));
3435
new ImageProvider("no_upload").getResource().attachImageIcon(this, true);
3536
this.layer = layer;
3637
setEnabled(layer.isUploadable());

src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.openstreetmap.josm.actions.AutoScaleAction;
5353
import org.openstreetmap.josm.actions.ExpertToggleAction;
5454
import org.openstreetmap.josm.actions.RenameLayerAction;
55+
import org.openstreetmap.josm.actions.ToggleEditLockLayerAction;
5556
import org.openstreetmap.josm.actions.ToggleUploadDiscouragedLayerAction;
5657
import org.openstreetmap.josm.data.APIDataSet;
5758
import org.openstreetmap.josm.data.Bounds;
@@ -743,6 +744,7 @@ public Action[] getMenuEntries() {
743744
new RenameLayerAction(getAssociatedFile(), this)));
744745
if (ExpertToggleAction.isExpert()) {
745746
actions.add(new ToggleUploadDiscouragedLayerAction(this));
747+
actions.add(new ToggleEditLockLayerAction(this));
746748
}
747749
actions.addAll(Arrays.asList(
748750
new ConsistencyTestAction(),

0 commit comments

Comments
 (0)