source: josm/trunk/src/org/openstreetmap/josm/actions/ReorderImageryLayersAction.java @ 14012

Last change on this file since 14012 was 14012, checked in by Don-vip, 4 months ago

see #16453 - proper support of different keyboard layouts

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7import java.util.List;
8import java.util.stream.Collectors;
9import java.util.stream.Stream;
10
11import org.openstreetmap.josm.gui.layer.ImageryLayer;
12import org.openstreetmap.josm.tools.KeyboardUtils;
13import org.openstreetmap.josm.tools.Shortcut;
14
15/**
16 * Reorders all non-overlay imagery layers in a cyclic manner.
17 * @since 13891
18 */
19public class ReorderImageryLayersAction extends JosmAction {
20
21    /**
22     * Constructs a new {@code ReorderImageryLayersAction}.
23     */
24    public ReorderImageryLayersAction() {
25        // TODO: find a suitable icon
26        super(tr("Reorder imagery layers"), "dialogs/layerlist", tr("Reorders non-overlay imagery layers."),
27            Shortcut.registerMultiShortcuts("imagery:reorder", tr("Reorder imagery layers"),
28                    KeyboardUtils.getCharactersForKey('E', 0), Shortcut.DIRECT));
29    }
30
31    @Override
32    public void actionPerformed(ActionEvent e) {
33        List<ImageryLayer> layers = getNonOverlayImageryLayers().collect(Collectors.toList());
34        int size = layers.size();
35        if (size > 1) {
36            // Move the first non-overlay layer at the position of the last non-overlay layer
37            getLayerManager().moveLayer(layers.get(0),
38                    getLayerManager().getLayers().indexOf(layers.get(size - 1)));
39        }
40    }
41
42    @Override
43    protected void updateEnabledState() {
44        setEnabled(getNonOverlayImageryLayers().count() > 1);
45    }
46
47    private Stream<ImageryLayer> getNonOverlayImageryLayers() {
48        return getLayerManager().getLayersOfType(ImageryLayer.class).stream()
49                .filter(l -> !l.getInfo().isOverlay());
50    }
51}
Note: See TracBrowser for help on using the repository browser.