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