Changeset 14012 in josm


Ignore:
Timestamp:
2018-07-08T00:27:14+02:00 (6 years ago)
Author:
Don-vip
Message:

see #16453 - proper support of different keyboard layouts

Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/JosmAction.java

    r13925 r14012  
    77import java.awt.event.KeyEvent;
    88import java.util.Collection;
     9import java.util.List;
    910import java.util.concurrent.CancellationException;
    1011import java.util.concurrent.ExecutionException;
     
    186187
    187188    /**
     189     * Constructs a new {@code JosmAction}.
     190     *
     191     * Use this super constructor to setup your action.
     192     *
     193     * @param name the action's text as displayed on the menu (if it is added to a menu)
     194     * @param iconName the filename of the icon to use
     195     * @param tooltip  a longer description of the action that will be displayed in the tooltip. Please note
     196     *           that html is not supported for menu actions on some platforms.
     197     * @param shortcuts ready-created shortcut objects
     198     * @since 14012
     199     */
     200    public JosmAction(String name, String iconName, String tooltip, List<Shortcut> shortcuts) {
     201        this(name, iconName, tooltip, shortcuts.get(0), true, null, true);
     202        for (int i = 1; i < shortcuts.size(); i++) {
     203            MainApplication.registerActionShortcut(this, shortcuts.get(i));
     204        }
     205    }
     206
     207    /**
    188208     * Installs the listeners to this action.
    189209     * <p>
  • trunk/src/org/openstreetmap/josm/actions/ReorderImageryLayersAction.java

    r13891 r14012  
    55
    66import java.awt.event.ActionEvent;
    7 import java.awt.event.KeyEvent;
    87import java.util.List;
    98import java.util.stream.Collectors;
    109import java.util.stream.Stream;
    1110
    12 import org.openstreetmap.josm.gui.MainApplication;
    1311import org.openstreetmap.josm.gui.layer.ImageryLayer;
     12import org.openstreetmap.josm.tools.KeyboardUtils;
    1413import org.openstreetmap.josm.tools.Shortcut;
    1514
     
    2019public class ReorderImageryLayersAction extends JosmAction {
    2120
    22     private static final int VK_SQUARE = 0x10000b2;
    23 
    2421    /**
    2522     * Constructs a new {@code ReorderImageryLayersAction}.
     
    2825        // TODO: find a suitable icon
    2926        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));
     27            Shortcut.registerMultiShortcuts("imagery:reorder", tr("Reorder imagery layers"),
     28                    KeyboardUtils.getCharactersForKey('E', 0), Shortcut.DIRECT));
    3429    }
    3530
  • trunk/src/org/openstreetmap/josm/gui/preferences/shortcut/PrefJPanel.java

    r12987 r14012  
    1414import java.awt.Toolkit;
    1515import java.awt.event.KeyEvent;
     16import java.awt.im.InputContext;
    1617import java.lang.reflect.Field;
    1718import java.util.ArrayList;
     
    5051import org.openstreetmap.josm.gui.widgets.JosmTextField;
    5152import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator;
     53import org.openstreetmap.josm.tools.KeyboardUtils;
    5254import org.openstreetmap.josm.tools.Logging;
    5355import org.openstreetmap.josm.tools.Shortcut;
     
    114116            }
    115117        }
     118        KeyboardUtils.getExtendedKeyCodes(InputContext.getInstance().getLocale()).entrySet()
     119            .forEach(e -> list.put(e.getKey(), e.getValue().toString()));
    116120        list.put(Integer.valueOf(-1), "");
    117121        return list;
     
    333337                    int row = panel.shortcutTable.convertRowIndexToModel(lsm.getMinSelectionIndex());
    334338                    Shortcut sc = (Shortcut) panel.model.getValueAt(row, -1);
     339                    Object selectedKey = panel.tfKey.getSelectedItem();
    335340                    if (panel.cbDisable.isSelected()) {
    336341                        sc.setAssignedModifier(-1);
    337                     } else if (panel.tfKey.getSelectedItem() == null || "".equals(panel.tfKey.getSelectedItem())) {
     342                    } else if (selectedKey == null || "".equals(selectedKey)) {
    338343                        sc.setAssignedModifier(KeyEvent.VK_CANCEL);
    339344                    } else {
     
    345350                        );
    346351                        for (Map.Entry<Integer, String> entry : keyList.entrySet()) {
    347                             if (entry.getValue().equals(panel.tfKey.getSelectedItem())) {
     352                            if (entry.getValue().equals(selectedKey)) {
    348353                                sc.setAssignedKey(entry.getKey());
    349354                            }
  • trunk/src/org/openstreetmap/josm/tools/Shortcut.java

    r13852 r14012  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.Toolkit;
    67import java.awt.event.KeyEvent;
    78import java.util.ArrayList;
     
    440441
    441442    /**
     443     * Register a shortcut linked to several characters.
     444     *
     445     * @param shortText an ID. re-use a {@code "system:*"} ID if possible, else use something unique.
     446     * {@code "menu:*"} is reserved for menu mnemonics, {@code "core:*"} is reserved for
     447     * actions that are part of JOSM's core. Use something like
     448     * {@code <pluginname>+":"+<actionname>}.
     449     * @param longText this will be displayed in the shortcut preferences dialog. Better
     450     * use something the user will recognize...
     451     * @param characters the characters you'd prefer
     452     * @param requestedGroup the group this shortcut fits best. This will determine the
     453     * modifiers your shortcut will get assigned. Use the constants defined above.
     454     * @return the shortcut
     455     */
     456    public static List<Shortcut> registerMultiShortcuts(String shortText, String longText, List<Character> characters, int requestedGroup) {
     457        List<Shortcut> result = new ArrayList<>();
     458        int i = 1;
     459        Map<Integer, Integer> regularKeyCodes = KeyboardUtils.getRegularKeyCodesMap();
     460        for (Character c : characters) {
     461            Integer code = (int) c;
     462            result.add(registerShortcut(
     463                    new StringBuilder(shortText).append(" (").append(i).append(')').toString(), longText,
     464                    // Add extended keyCode if not a regular one
     465                    regularKeyCodes.containsKey(code) ? regularKeyCodes.get(code) : c | KeyboardUtils.EXTENDED_KEYCODE_FLAG,
     466                    requestedGroup));
     467            i++;
     468        }
     469        return result;
     470    }
     471
     472    /**
    442473     * Register a shortcut.
    443474     *
Note: See TracChangeset for help on using the changeset viewer.