Skip to content

Commit e836838

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

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
import org.openstreetmap.josm.tools.ImageProvider;
19+
20+
/**
21+
* An action enabling/disabling the {@linkplain AbstractModifiableLayer#lock() read-only flag}
22+
* of the layer specified in the constructor.
23+
*
24+
* @since XXX
25+
*/
26+
public class ToggleEditLockLayerAction extends AbstractAction implements LayerAction {
27+
28+
private final AbstractModifiableLayer layer;
29+
30+
/**
31+
* Construct a new {@code ToggleEditLockLayerAction}
32+
* @param layer the layer for which to toggle the {@linkplain AbstractModifiableLayer#lock() read-only flag}
33+
*
34+
* @since XXX
35+
*/
36+
public ToggleEditLockLayerAction(AbstractModifiableLayer layer) {
37+
super(tr("Prevent modification"));
38+
putValue(SHORT_DESCRIPTION, tr("Prevent/allow changes being made in this layer"));
39+
new ImageProvider("lock").getResource().attachImageIcon(this, true);
40+
this.layer = layer;
41+
}
42+
43+
@Override
44+
public void actionPerformed(ActionEvent e) {
45+
if (layer.isLocked()) {
46+
layer.unlock();
47+
} else {
48+
layer.lock();
49+
}
50+
51+
layer.invalidate();
52+
LayerListDialog.getInstance().repaint();
53+
}
54+
55+
@Override
56+
public Component createMenuComponent() {
57+
JCheckBoxMenuItem item = new JCheckBoxMenuItem(this);
58+
item.setSelected(layer.isLocked());
59+
return item;
60+
}
61+
62+
@Override
63+
public boolean supportLayers(List<Layer> layers) {
64+
return layers.size() == 1 && layers.get(0) instanceof Lockable;
65+
}
66+
}

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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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)