| | 1 | // License: GPL. See LICENSE file for details. |
| | 2 | package org.openstreetmap.josm.gui.layer.geoimage; |
| | 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 | import javax.swing.AbstractAction; |
| | 10 | import javax.swing.JCheckBoxMenuItem; |
| | 11 | |
| | 12 | import org.openstreetmap.josm.Main; |
| | 13 | import org.openstreetmap.josm.gui.layer.Layer; |
| | 14 | import org.openstreetmap.josm.gui.layer.Layer.LayerAction; |
| | 15 | import org.openstreetmap.josm.tools.ImageProvider; |
| | 16 | |
| | 17 | /** |
| | 18 | * Toggle the image display between thumbnails and symbols. |
| | 19 | * @since tbd |
| | 20 | */ |
| | 21 | public class ShowThumbnailAction extends AbstractAction implements LayerAction { |
| | 22 | |
| | 23 | private final GeoImageLayer layer; |
| | 24 | |
| | 25 | /** |
| | 26 | * Constructs a new {@code ToggleGeoImageThumbAction} action. |
| | 27 | * @param layer image layer |
| | 28 | */ |
| | 29 | public ShowThumbnailAction(GeoImageLayer layer) { |
| | 30 | super(tr("Show thumbnails"), ImageProvider.get("dialogs/geoimage/togglegit")); |
| | 31 | putValue(SHORT_DESCRIPTION, tr("Show image thumbnails instead of icons.")); |
| | 32 | this.layer = layer; |
| | 33 | } |
| | 34 | |
| | 35 | /** |
| | 36 | * This is called after the menu entry was selected. |
| | 37 | * @param arg0 action event |
| | 38 | */ |
| | 39 | @Override |
| | 40 | public void actionPerformed(ActionEvent arg0) { |
| | 41 | layer.setUseThumbs(!layer.isUseThumbs()); |
| | 42 | Main.map.mapView.repaint(); |
| | 43 | } |
| | 44 | |
| | 45 | /** |
| | 46 | * Check if there is any suitable image to be toggled. |
| | 47 | * @param layer image layer |
| | 48 | * @return {@code true} if there are images to be toggled, |
| | 49 | * {@code false} otherwise |
| | 50 | */ |
| | 51 | private static boolean enabled(GeoImageLayer layer) { |
| | 52 | return !layer.data.isEmpty(); |
| | 53 | } |
| | 54 | |
| | 55 | /** Create actual menu entry and define if it is enabled or not. */ |
| | 56 | @Override |
| | 57 | public Component createMenuComponent() { |
| | 58 | JCheckBoxMenuItem toggleItem = new JCheckBoxMenuItem(this); |
| | 59 | toggleItem.setEnabled(enabled(layer)); |
| | 60 | toggleItem.setState(layer.isUseThumbs()); |
| | 61 | return toggleItem; |
| | 62 | } |
| | 63 | |
| | 64 | /** Check if the current layer is supported. */ |
| | 65 | @Override |
| | 66 | public boolean supportLayers(List<Layer> layers) { |
| | 67 | return layers.size() == 1 && layers.get(0) instanceof GeoImageLayer; |
| | 68 | } |
| | 69 | } |