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.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 7935
|
---|
20 | */
|
---|
21 | public class ShowThumbnailAction extends AbstractAction implements LayerAction {
|
---|
22 |
|
---|
23 | private final transient 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 e action event
|
---|
38 | */
|
---|
39 | @Override
|
---|
40 | public void actionPerformed(ActionEvent e) {
|
---|
41 | layer.setUseThumbs(!layer.isUseThumbs());
|
---|
42 | }
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Check if there is any suitable image to be toggled.
|
---|
46 | * @param layer image layer
|
---|
47 | * @return {@code true} if there are images to be toggled,
|
---|
48 | * {@code false} otherwise
|
---|
49 | */
|
---|
50 | private static boolean enabled(GeoImageLayer layer) {
|
---|
51 | return layer.data != null && !layer.data.isEmpty();
|
---|
52 | }
|
---|
53 |
|
---|
54 | /** Create actual menu entry and define if it is enabled or not. */
|
---|
55 | @Override
|
---|
56 | public Component createMenuComponent() {
|
---|
57 | JCheckBoxMenuItem toggleItem = new JCheckBoxMenuItem(this);
|
---|
58 | toggleItem.setEnabled(enabled(layer));
|
---|
59 | toggleItem.setState(layer.isUseThumbs());
|
---|
60 | return toggleItem;
|
---|
61 | }
|
---|
62 |
|
---|
63 | /** Check if the current layer is supported. */
|
---|
64 | @Override
|
---|
65 | public boolean supportLayers(List<Layer> layers) {
|
---|
66 | return layers.size() == 1 && layers.get(0) instanceof GeoImageLayer;
|
---|
67 | }
|
---|
68 | }
|
---|