Skip to content

Commit

Permalink
Add option to toggle layer read-only status to popup menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Woazboat committed Aug 22, 2022
1 parent 0f1bb9b commit 705978b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/org/openstreetmap/josm/actions/ToggleEditLockLayerAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.actions;

import static org.openstreetmap.josm.tools.I18n.tr;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.util.List;

import javax.swing.AbstractAction;
import javax.swing.JCheckBoxMenuItem;

import org.openstreetmap.josm.data.osm.Lockable;
import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer;
import org.openstreetmap.josm.gui.layer.Layer;
import org.openstreetmap.josm.gui.layer.Layer.LayerAction;

/**
* An action enabling/disabling the {@linkplain AbstractModifiableLayer#lock() read-only flag}
* of the layer specified in the constructor.
*
* @since XXX
*/
public class ToggleEditLockLayerAction extends AbstractAction implements LayerAction {

private final AbstractModifiableLayer layer;

/**
* Construct a new {@code ToggleEditLockLayerAction}
* @param layer the layer for which to toggle the {@linkplain AbstractModifiableLayer#lock() read-only flag}
*
* @since XXX
*/
public ToggleEditLockLayerAction(AbstractModifiableLayer layer) {
super(tr("Prevent modification"));
putValue(SHORT_DESCRIPTION, tr("Prevent/allow changes being made in this layer"));
this.layer = layer;
}

@Override
public void actionPerformed(ActionEvent e) {
if (layer.isLocked()) {
layer.unlock();
} else {
layer.lock();
}

layer.invalidate();
LayerListDialog.getInstance().repaint();
}

@Override
public Component createMenuComponent() {
JCheckBoxMenuItem item = new JCheckBoxMenuItem(this);
item.setSelected(layer.isLocked());
return item;
}

@Override
public boolean supportLayers(List<Layer> layers) {
return layers.size() == 1 && layers.get(0) instanceof Lockable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class ToggleUploadDiscouragedLayerAction extends AbstractAction implement
*/
public ToggleUploadDiscouragedLayerAction(OsmDataLayer layer) {
super(tr("Discourage upload"));
putValue(SHORT_DESCRIPTION, tr("Allow/disallow upload of changes made in this layer"));
new ImageProvider("no_upload").getResource().attachImageIcon(this, true);
this.layer = layer;
setEnabled(layer.isUploadable());
Expand Down
2 changes: 2 additions & 0 deletions src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.openstreetmap.josm.actions.AutoScaleAction;
import org.openstreetmap.josm.actions.ExpertToggleAction;
import org.openstreetmap.josm.actions.RenameLayerAction;
import org.openstreetmap.josm.actions.ToggleEditLockLayerAction;
import org.openstreetmap.josm.actions.ToggleUploadDiscouragedLayerAction;
import org.openstreetmap.josm.data.APIDataSet;
import org.openstreetmap.josm.data.Bounds;
Expand Down Expand Up @@ -743,6 +744,7 @@ public Action[] getMenuEntries() {
new RenameLayerAction(getAssociatedFile(), this)));
if (ExpertToggleAction.isExpert()) {
actions.add(new ToggleUploadDiscouragedLayerAction(this));
actions.add(new ToggleEditLockLayerAction(this));
}
actions.addAll(Arrays.asList(
new ConsistencyTestAction(),
Expand Down

0 comments on commit 705978b

Please sign in to comment.