org.openstreetmap.josm.tools
Class Shortcut

java.lang.Object
  extended by org.openstreetmap.josm.tools.Shortcut

public class Shortcut
extends java.lang.Object

Global shortcut class. Note: This class represents a single shortcut, contains the factory to obtain shortcut objects from, manages shortcuts and shortcut collisions, and finally manages loading and saving shortcuts to/from the preferences. Action authors: You only need the registerShortcut(java.lang.String, java.lang.String, int, int) factory. Ignore everything else. All: Use only public methods that are also marked to be used. The others are public so the shortcut preferences can use them.


Field Summary
static int ALT
           
static int ALT_CTRL
           
static int ALT_CTRL_SHIFT
           
static int ALT_SHIFT
           
private  boolean assignedDefault
           
private  int assignedKey
           
private  int assignedModifier
           
private  boolean assignedUser
           
private  boolean automatic
           
static int CTRL
           
static int CTRL_SHIFT
           
static int DIRECT
           
private static java.util.Map<java.lang.Integer,java.lang.Integer> groups
           
private static boolean initdone
           
private static int[] keys
           
private  java.lang.String longText
           
static int MNEMONIC
           
private static int[] mods
           
static int NONE
           
private  int requestedGroup
           
private  int requestedKey
           
static int RESERVED
           
private  boolean reset
           
static int SHIFT
           
private static java.util.Map<java.lang.String,Shortcut> shortcuts
           
private  java.lang.String shortText
           
 
Constructor Summary
private Shortcut(java.lang.String prefString)
           
private Shortcut(java.lang.String shortText, java.lang.String longText, int requestedKey, int requestedGroup, int assignedKey, int assignedModifier, boolean assignedDefault, boolean assignedUser)
           
 
Method Summary
private static void doInit()
           
private static int findModifier(int group, java.lang.Integer modifier)
           
private static Shortcut findShortcut(int requestedKey, int modifier)
           
 boolean getAssignedDefault()
           
 int getAssignedKey()
           
 int getAssignedModifier()
           
 boolean getAssignedUser()
           
 boolean getAutomatic()
           
static javax.swing.KeyStroke getCopyKeyStroke()
          Replies the platform specific key stroke for the 'Copy' command, i.e.
static javax.swing.KeyStroke getCutKeyStroke()
          Replies the platform specific key stroke for the 'Cut' command, i.e.
private static int getGroupModifier(int group)
           
 javax.swing.KeyStroke getKeyStroke()
          Use this to register the shortcut with Swing
 java.lang.String getKeyText()
          use this to get a human readable text for your shortcut
 java.lang.String getLongText()
           
static javax.swing.KeyStroke getPasteKeyStroke()
          Replies the platform specific key stroke for the 'Paste' command, i.e.
 int getRequestedGroup()
           
private  int getRequestedKey()
           
private  boolean getReset()
           
 java.lang.String getShortText()
           
 boolean isChangeable()
           
 boolean isEvent(java.awt.event.KeyEvent e)
           
private  boolean isSame(int isKey, int isModifier)
           
static java.util.List<Shortcut> listAll()
          FOR PREF PANE ONLY
static Shortcut registerShortcut(java.lang.String shortText, java.lang.String longText, int requestedKey, int requestedGroup)
          Register a shortcut.
private static Shortcut registerShortcut(java.lang.String shortText, java.lang.String longText, int requestedKey, int requestedGroup, java.lang.Integer modifier)
           
static Shortcut registerSystemShortcut(java.lang.String shortText, java.lang.String longText, int key, int modifier)
          FOR PLATFORMHOOK USE ONLY This registers a system shortcut.
private  boolean save()
           
private  void saveDefault()
           
static boolean savePrefs()
           
 void setAccelerator(javax.swing.AbstractAction action)
          use this to set a actions's accelerator
 void setAssignedKey(int assignedKey)
          FOR PREF PANE ONLY
 void setAssignedModifier(int assignedModifier)
          FOR PREF PANE ONLY
 void setAssignedUser(boolean assignedUser)
          FOR PREF PANE ONLY
 void setAutomatic()
          FOR PREF PANE ONLY
private  void setLongText(java.lang.String longText)
           
 void setMnemonic(javax.swing.AbstractButton button)
          use this to set a buttons's mnemonic
 void setMnemonic(javax.swing.JMenu menu)
          use this to set a menu's mnemonic
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

shortText

private java.lang.String shortText

longText

private java.lang.String longText

requestedKey

private int requestedKey

requestedGroup

private int requestedGroup

assignedKey

private int assignedKey

assignedModifier

private int assignedModifier

assignedDefault

private boolean assignedDefault

assignedUser

private boolean assignedUser

automatic

private boolean automatic

reset

private boolean reset

shortcuts

private static java.util.Map<java.lang.String,Shortcut> shortcuts

groups

private static java.util.Map<java.lang.Integer,java.lang.Integer> groups

NONE

public static final int NONE
See Also:
Constant Field Values

MNEMONIC

public static final int MNEMONIC
See Also:
Constant Field Values

RESERVED

public static final int RESERVED
See Also:
Constant Field Values

DIRECT

public static final int DIRECT
See Also:
Constant Field Values

ALT

public static final int ALT
See Also:
Constant Field Values

SHIFT

public static final int SHIFT
See Also:
Constant Field Values

CTRL

public static final int CTRL
See Also:
Constant Field Values

ALT_SHIFT

public static final int ALT_SHIFT
See Also:
Constant Field Values

ALT_CTRL

public static final int ALT_CTRL
See Also:
Constant Field Values

CTRL_SHIFT

public static final int CTRL_SHIFT
See Also:
Constant Field Values

ALT_CTRL_SHIFT

public static final int ALT_CTRL_SHIFT
See Also:
Constant Field Values

mods

private static int[] mods

keys

private static int[] keys

initdone

private static boolean initdone
Constructor Detail

Shortcut

private Shortcut(java.lang.String shortText,
                 java.lang.String longText,
                 int requestedKey,
                 int requestedGroup,
                 int assignedKey,
                 int assignedModifier,
                 boolean assignedDefault,
                 boolean assignedUser)

Shortcut

private Shortcut(java.lang.String prefString)
Method Detail

getShortText

public java.lang.String getShortText()

getLongText

public java.lang.String getLongText()

setLongText

private void setLongText(java.lang.String longText)

getRequestedKey

private int getRequestedKey()

getRequestedGroup

public int getRequestedGroup()

getAssignedKey

public int getAssignedKey()

getAssignedModifier

public int getAssignedModifier()

getAssignedDefault

public boolean getAssignedDefault()

getAssignedUser

public boolean getAssignedUser()

getAutomatic

public boolean getAutomatic()

isChangeable

public boolean isChangeable()

getReset

private boolean getReset()

setAutomatic

public void setAutomatic()
FOR PREF PANE ONLY


setAssignedModifier

public void setAssignedModifier(int assignedModifier)
FOR PREF PANE ONLY


setAssignedKey

public void setAssignedKey(int assignedKey)
FOR PREF PANE ONLY


setAssignedUser

public void setAssignedUser(boolean assignedUser)
FOR PREF PANE ONLY


getKeyStroke

public javax.swing.KeyStroke getKeyStroke()
Use this to register the shortcut with Swing


saveDefault

private void saveDefault()

save

private boolean save()

isSame

private boolean isSame(int isKey,
                       int isModifier)

isEvent

public boolean isEvent(java.awt.event.KeyEvent e)

setMnemonic

public void setMnemonic(javax.swing.JMenu menu)
use this to set a menu's mnemonic


setMnemonic

public void setMnemonic(javax.swing.AbstractButton button)
use this to set a buttons's mnemonic


setAccelerator

public void setAccelerator(javax.swing.AbstractAction action)
use this to set a actions's accelerator


getKeyText

public java.lang.String getKeyText()
use this to get a human readable text for your shortcut


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

findShortcut

private static Shortcut findShortcut(int requestedKey,
                                     int modifier)

listAll

public static java.util.List<Shortcut> listAll()
FOR PREF PANE ONLY


doInit

private static void doInit()

getGroupModifier

private static int getGroupModifier(int group)

findModifier

private static int findModifier(int group,
                                java.lang.Integer modifier)

savePrefs

public static boolean savePrefs()

registerSystemShortcut

public static Shortcut registerSystemShortcut(java.lang.String shortText,
                                              java.lang.String longText,
                                              int key,
                                              int modifier)
FOR PLATFORMHOOK USE ONLY This registers a system shortcut. See PlatformHook for details.


registerShortcut

public static Shortcut registerShortcut(java.lang.String shortText,
                                        java.lang.String longText,
                                        int requestedKey,
                                        int requestedGroup)
Register a shortcut. Here you get your shortcuts from. The parameters are:

Parameters:
shortText - an ID. re-use a "system:*" ID if possible, else use something unique. "menu:*" is reserved for menu mnemonics, "core:*" is reserved for actions that are part of JOSM's core. Use something like <pluginname>+":"+<actionname>.
longText - this will be displayed in the shortcut preferences dialog. Better use something the user will recognize...
requestedKey - the key you'd prefer. Use a KeyEvent.VK_* constant here.
requestedGroup - the group this shortcut fits best. This will determine the modifiers your shortcut will get assigned. Use the constants defined above.

registerShortcut

private static Shortcut registerShortcut(java.lang.String shortText,
                                         java.lang.String longText,
                                         int requestedKey,
                                         int requestedGroup,
                                         java.lang.Integer modifier)

getCopyKeyStroke

public static javax.swing.KeyStroke getCopyKeyStroke()
Replies the platform specific key stroke for the 'Copy' command, i.e. 'Ctrl-C' on windows or 'Meta-C' on a Mac. null, if the platform specific copy command isn't known.

Returns:
the platform specific key stroke for the 'Copy' command

getPasteKeyStroke

public static javax.swing.KeyStroke getPasteKeyStroke()
Replies the platform specific key stroke for the 'Paste' command, i.e. 'Ctrl-V' on windows or 'Meta-V' on a Mac. null, if the platform specific paste command isn't known.

Returns:
the platform specific key stroke for the 'Paste' command

getCutKeyStroke

public static javax.swing.KeyStroke getCutKeyStroke()
Replies the platform specific key stroke for the 'Cut' command, i.e. 'Ctrl-X' on windows or 'Meta-X' on a Mac. null, if the platform specific 'Cut' command isn't known.

Returns:
the platform specific key stroke for the 'Cut' command


JOSM