| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.actions;
|
|---|
| 3 |
|
|---|
| 4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
|---|
| 5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 6 |
|
|---|
| 7 | import java.awt.Component;
|
|---|
| 8 | import java.awt.event.ActionEvent;
|
|---|
| 9 | import java.util.List;
|
|---|
| 10 |
|
|---|
| 11 | import javax.swing.AbstractAction;
|
|---|
| 12 | import javax.swing.JCheckBoxMenuItem;
|
|---|
| 13 |
|
|---|
| 14 | import javax.swing.JOptionPane;
|
|---|
| 15 | import org.openstreetmap.josm.gui.Notification;
|
|---|
| 16 | import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
|
|---|
| 17 | import org.openstreetmap.josm.gui.layer.Layer;
|
|---|
| 18 | import org.openstreetmap.josm.gui.layer.Layer.LayerAction;
|
|---|
| 19 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
|---|
| 20 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
|---|
| 21 | import org.openstreetmap.josm.tools.ImageProvider;
|
|---|
| 22 |
|
|---|
| 23 | /**
|
|---|
| 24 | * An action enabling/disabling the {@linkplain OsmDataLayer#setUploadDiscouraged(boolean) discouraged upload flag}
|
|---|
| 25 | * of the layer specified in the constructor.
|
|---|
| 26 | */
|
|---|
| 27 | public class ToggleUploadDiscouragedLayerAction extends AbstractAction implements LayerAction {
|
|---|
| 28 |
|
|---|
| 29 | private final transient OsmDataLayer layer;
|
|---|
| 30 |
|
|---|
| 31 | /**
|
|---|
| 32 | * Constructs a new {@code ToggleUploadDiscouragedLayerAction}.
|
|---|
| 33 | * @param layer the layer for which to toggle the {@linkplain OsmDataLayer#setUploadDiscouraged(boolean) discouraged upload flag}
|
|---|
| 34 | */
|
|---|
| 35 | public ToggleUploadDiscouragedLayerAction(OsmDataLayer layer) {
|
|---|
| 36 | super(tr("Discourage upload"));
|
|---|
| 37 | new ImageProvider("no_upload").getResource().attachImageIcon(this, true);
|
|---|
| 38 | this.layer = layer;
|
|---|
| 39 | setEnabled(layer.isUploadable());
|
|---|
| 40 | putValue("help", ht("/Action/EncourageDiscourageUpload"));
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | @Override
|
|---|
| 44 | public void actionPerformed(ActionEvent e) {
|
|---|
| 45 | layer.setUploadDiscouraged(!layer.isUploadDiscouraged());
|
|---|
| 46 | String msg = layer.isUploadDiscouraged() ? tr("Upload is discouraged") : tr("Upload is encouraged");
|
|---|
| 47 | GuiHelper.runInEDT(() -> new Notification(msg).setIcon(JOptionPane.INFORMATION_MESSAGE).show());
|
|---|
| 48 | LayerListDialog.getInstance().repaint();
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | @Override
|
|---|
| 52 | public Component createMenuComponent() {
|
|---|
| 53 | JCheckBoxMenuItem item = new JCheckBoxMenuItem(this);
|
|---|
| 54 | item.setSelected(layer.isUploadDiscouraged() || !layer.isUploadable());
|
|---|
| 55 | return item;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | @Override
|
|---|
| 59 | public boolean supportLayers(List<Layer> layers) {
|
|---|
| 60 | return layers.size() == 1 && layers.get(0) instanceof OsmDataLayer;
|
|---|
| 61 | }
|
|---|
| 62 | }
|
|---|