Ticket #11556: 11556.patch

File 11556.patch, 4.4 KB (added by Don-vip, 7 months ago)
  • src/org/openstreetmap/josm/actions/ReorderImageryLayersAction.java

     
     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.awt.event.KeyEvent;
     8import java.util.List;
     9import java.util.stream.Collectors;
     10import java.util.stream.Stream;
     11
     12import org.openstreetmap.josm.gui.MainApplication;
     13import org.openstreetmap.josm.gui.layer.ImageryLayer;
     14import org.openstreetmap.josm.tools.Shortcut;
     15
     16/**
     17 * Reorders all non-overlay imagery layers in a cyclic manner.
     18 * @since xxx
     19 */
     20public class ReorderImageryLayersAction extends JosmAction {
     21
     22    private static final int VK_SQUARE = 0x10000b2;
     23
     24    /**
     25     * Constructs a new {@code ReorderImageryLayersAction}.
     26     */
     27    public ReorderImageryLayersAction() {
     28        // TODO: find a suitable icon
     29        super(tr("Reorder imagery layers"), "dialogs/layerlist", tr("Reorders non-overlay imagery layers."),
     30            Shortcut.registerShortcut("imagery:reorder", tr("Reorder imagery layers"), KeyEvent.VK_DEAD_TILDE, Shortcut.DIRECT), true);
     31        // On AZERTY keyboard layour the key displays the character '²'
     32        MainApplication.registerActionShortcut(this,
     33            Shortcut.registerShortcut("imagery:reorderbis", tr("Reorder imagery layers"), VK_SQUARE, Shortcut.DIRECT));
     34    }
     35
     36    @Override
     37    public void actionPerformed(ActionEvent e) {
     38        List<ImageryLayer> layers = getNonOverlayImageryLayers().collect(Collectors.toList());
     39        int size = layers.size();
     40        if (size > 1) {
     41            // Move the first non-overlay layer at the position of the last non-overlay layer
     42            getLayerManager().moveLayer(layers.get(0),
     43                    getLayerManager().getLayers().indexOf(layers.get(size - 1)));
     44        }
     45    }
     46
     47    @Override
     48    protected void updateEnabledState() {
     49        setEnabled(getNonOverlayImageryLayers().count() > 1);
     50    }
     51
     52    private Stream<ImageryLayer> getNonOverlayImageryLayers() {
     53        return getLayerManager().getLayersOfType(ImageryLayer.class).stream()
     54                .filter(l -> !l.getInfo().isOverlay());
     55    }
     56}
  • src/org/openstreetmap/josm/gui/MainMenu.java

    Property changes on: src\org\openstreetmap\josm\actions\ReorderImageryLayersAction.java
    ___________________________________________________________________
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
     
    7979import org.openstreetmap.josm.actions.PreferencesAction;
    8080import org.openstreetmap.josm.actions.PurgeAction;
    8181import org.openstreetmap.josm.actions.RedoAction;
     82import org.openstreetmap.josm.actions.ReorderImageryLayersAction;
    8283import org.openstreetmap.josm.actions.ReportBugAction;
    8384import org.openstreetmap.josm.actions.RestartAction;
    8485import org.openstreetmap.josm.actions.ReverseWayAction;
     
    391392    public final JosmAction moveLeftAction = new MoveAction(MoveAction.Direction.LEFT);
    392393    public final JosmAction moveRightAction = new MoveAction(MoveAction.Direction.RIGHT);
    393394
     395    public final ReorderImageryLayersAction reorderImageryLayersAction = new ReorderImageryLayersAction();
     396
    394397    public final TaggingPresetSearchAction presetSearchAction = new TaggingPresetSearchAction();
    395398    public final TaggingPresetSearchPrimitiveDialog.Action presetSearchPrimitiveAction = new TaggingPresetSearchPrimitiveDialog.Action();
    396399    public final DialogsToggleAction dialogsToggleAction = new DialogsToggleAction();
     
    760763                tr("Click to open the tagging presets tab in the preferences"), TaggingPresetPreference.class));
    761764        presetsMenu.addSeparator();
    762765
     766        add(imageryMenu, reorderImageryLayersAction);
    763767        add(imageryMenu, PreferencesAction.forPreferenceTab(tr("Imagery preferences"),
    764768                tr("Click to open the imagery tab in the preferences"), ImageryPreference.class));
    765769