-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to toggle layer read-only status to popup menu
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/org/openstreetmap/josm/actions/ToggleEditLockLayerAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters