Ignore:
Timestamp:
2011-11-21T22:16:25+01:00 (12 years ago)
Author:
jttt
Message:

Multikey action improvements (see #5515):

  • show text in status bar after shortcut is pressed
  • number layers from 1
  • do not allow Repeat for last layer if layer index conflicts with shortcut
Location:
trunk/src/org/openstreetmap/josm/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/MultikeyActionsHandler.java

    r4595 r4604  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.tools;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
    35
    46import java.awt.KeyEventDispatcher;
     
    2123public class MultikeyActionsHandler {
    2224
    23     private static final long DIALOG_DELAY = 2000;
     25    private static final long DIALOG_DELAY = 1000;
     26    private static final String STATUS_BAR_ID = new String("multikeyShortcut");
    2427
    2528    private class MyKeyEventDispatcher implements KeyEventDispatcher {
     
    3134
    3235            if (lastAction != null && e.getID() == KeyEvent.KEY_PRESSED) {
    33                 if (e.getKeyCode() == lastAction.shortcut.getKeyCode()) {
    34                     lastAction.action.repeateLastMultikeyAction();
    35                 } else {
    36                     int index = getIndex(e.getKeyChar());
    37                     if (index >= 0) {
    38                         lastAction.action.executeMultikeyAction(index);
    39                     }
     36                int index = getIndex(e.getKeyCode());
     37                if (index >= 0) {
     38                    lastAction.action.executeMultikeyAction(index, e.getKeyCode() == lastAction.shortcut.getKeyCode());
    4039                }
    4140                lastAction = null;
     41                Main.map.statusLine.resetHelpText(STATUS_BAR_ID);
    4242                return true;
    4343            }
     
    4545        }
    4646
    47         private int getIndex(char lastKey) {
    48             if (lastKey >= KeyEvent.VK_0 && lastKey <= KeyEvent.VK_9)
    49                 return lastKey - KeyEvent.VK_0;
     47        private int getIndex(int lastKey) {
     48            if (lastKey >= KeyEvent.VK_1 && lastKey <= KeyEvent.VK_9)
     49                return lastKey - KeyEvent.VK_1;
     50            else if (lastKey == KeyEvent.VK_0)
     51                return 9;
    5052            else if (lastKey >= KeyEvent.VK_A && lastKey <= KeyEvent.VK_Z)
    5153                return lastKey - KeyEvent.VK_A + 10;
     
    7072            lastAction = this;
    7173            timer.schedule(new MyTimerTask(lastTimestamp, lastAction), DIALOG_DELAY);
     74            Main.map.statusLine.setHelpText(STATUS_BAR_ID, tr("{0}... [please type its number]", (String) action.getValue(SHORT_DESCRIPTION)));
    7275        }
    7376
     
    132135        layers.add(lbTitle);
    133136
     137        char repeatKey = (char) action.shortcut.getKeyCode();
     138        boolean repeatKeyUsed = false;
     139
    134140
    135141        for (final MultikeyInfo info: action.action.getMultikeyCombinations()) {
     142
     143            if (info.getShortcut() == repeatKey) {
     144                repeatKeyUsed = true;
     145            }
     146
    136147            JMenuItem item = new JMenuItem(formatMenuText(action.shortcut, String.valueOf(info.getShortcut()), info.getDescription()));
    137148            item.setMnemonic(info.getShortcut());
     
    139150                @Override
    140151                public void actionPerformed(ActionEvent e) {
    141                     action.action.executeMultikeyAction(info.getIndex());
     152                    Main.map.statusLine.resetHelpText(STATUS_BAR_ID);
     153                    action.action.executeMultikeyAction(info.getIndex(), false);
    142154                }
    143155            });
     
    145157        }
    146158
    147         MultikeyInfo lastLayer = action.action.getLastMultikeyAction();
    148         if (lastLayer != null) {
    149             JMenuItem repeateItem = new JMenuItem(formatMenuText(action.shortcut,
    150                     KeyEvent.getKeyText(action.shortcut.getKeyCode()),
    151                     "Repeat " + lastLayer.getDescription()));
    152             repeateItem.addActionListener(new ActionListener() {
    153                 @Override
    154                 public void actionPerformed(ActionEvent e) {
    155                     action.action.repeateLastMultikeyAction();
    156                 }
    157             });
    158             layers.add(repeateItem);
     159        if (!repeatKeyUsed) {
     160            MultikeyInfo lastLayer = action.action.getLastMultikeyAction();
     161            if (lastLayer != null) {
     162                JMenuItem repeateItem = new JMenuItem(formatMenuText(action.shortcut,
     163                        KeyEvent.getKeyText(action.shortcut.getKeyCode()),
     164                        "Repeat " + lastLayer.getDescription()));
     165                repeateItem.setMnemonic(action.shortcut.getKeyCode());
     166                repeateItem.addActionListener(new ActionListener() {
     167                    @Override
     168                    public void actionPerformed(ActionEvent e) {
     169                        Main.map.statusLine.resetHelpText(STATUS_BAR_ID);
     170                        action.action.executeMultikeyAction(-1, true);
     171                    }
     172                });
     173                layers.add(repeateItem);
     174            }
    159175        }
    160176
  • trunk/src/org/openstreetmap/josm/tools/MultikeyShortcutAction.java

    r4595 r4604  
    2222
    2323        public char getShortcut() {
    24             if (index < 10)
    25                 return (char)('0' + index);
     24            if (index < 9)
     25                return (char)('1' + index);
     26            else if (index == 9)
     27                return '0';
    2628            else
    2729                return (char)('A' +  index - 10);
     
    3335    }
    3436
    35     void executeMultikeyAction(int index);
    36     void repeateLastMultikeyAction();
     37    void executeMultikeyAction(int index, boolean repeatLastAction);
    3738    List<MultikeyInfo> getMultikeyCombinations();
    3839    MultikeyInfo getLastMultikeyAction();
Note: See TracChangeset for help on using the changeset viewer.