1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.layer.imagery;
|
---|
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.AbstractTileSourceLayer;
|
---|
14 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
15 | import org.openstreetmap.josm.gui.layer.Layer.LayerAction;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Auto zoom.
|
---|
19 | * @since 11950 (extracted from {@link AbstractTileSourceLayer})
|
---|
20 | */
|
---|
21 | public class AutoZoomAction extends AbstractAction implements LayerAction {
|
---|
22 |
|
---|
23 | private final AbstractTileSourceLayer<?> layer;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Constructs a new {@code AutoZoomAction}.
|
---|
27 | * @param layer imagery layer
|
---|
28 | */
|
---|
29 | public AutoZoomAction(AbstractTileSourceLayer<?> layer) {
|
---|
30 | super(tr("Auto zoom"));
|
---|
31 | this.layer = layer;
|
---|
32 | }
|
---|
33 |
|
---|
34 | @Override
|
---|
35 | public void actionPerformed(ActionEvent ae) {
|
---|
36 | TileSourceDisplaySettings settings = layer.getDisplaySettings();
|
---|
37 | settings.setAutoZoom(!settings.isAutoZoom());
|
---|
38 | }
|
---|
39 |
|
---|
40 | @Override
|
---|
41 | public Component createMenuComponent() {
|
---|
42 | JCheckBoxMenuItem item = new JCheckBoxMenuItem(this);
|
---|
43 | item.setSelected(layer.getDisplaySettings().isAutoZoom());
|
---|
44 | return item;
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Override
|
---|
48 | public boolean supportLayers(List<Layer> layers) {
|
---|
49 | return AbstractTileSourceLayer.actionSupportLayers(layers);
|
---|
50 | }
|
---|
51 | }
|
---|