Class Shortcut
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.
- Since:
- 1084
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intAlt groupstatic final intAlt-Command group.static final intAlt-Command-Shift group.static final intAlt-Shift groupprivate booleantrue if it got assigned what was requested.private intthe key that actually is usedprivate intthe modifiers that are usedprivate booleantrue if the user changed this shortcutprivate booleantrue if the user cannot change this shortcut (Note: it also will not be saved into the preferences)static final intCommand group.static final intCommand-Shift group.static final intDirect group: no modifierprivate static booleanprivate static final int[]private Stringa human readable description that will be shown in the preferencesstatic final intprivate static final int[]static final intNone group: used with KeyEvent.CHAR_UNDEFINED if no shortcut is definedprivate final intthe group, the caller requestedprivate final intthe key, the caller requestedstatic final intReserved group: for system shortcuts onlyprivate booleantrue if the user requested this shortcut to be set to its default value (will happen on next restart, as this shortcut will not be saved to the preferences)static final intShift groupprivate static final Shortcut.ShortcutCollectionprivate final Stringthe unique ID of the shortcut -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voiddoInit()private static intfindModifier(int group, Integer modifier) private static intfindNewOsxModifier(int requestedGroup) findShortcut(int requestedKey, int modifier) Returns the registered shortcut fot the key and modifierfindShortcutByKeyOrShortText(int requestedKey, int modifier, String shortText) intintstatic KeyStrokeReplies the platform specific key stroke for the 'Copy' command, i.e.static KeyStrokeReplies the platform specific key stroke for the 'Cut' command, i.e.private static intgetGroupModifier(int group) Use this to register the shortcut with Swingprivate static KeyStrokegetKeyStrokeForShortKey(String shortKey) Returns a human readable text for the shortcut.static StringgetKeyText(KeyStroke keyStroke) Returns a human readable text for the key stroke.static KeyStrokeReplies the platform specific key stroke for the 'Paste' command, i.e.booleanbooleanbooleanboolean(package private) static booleanisDeadKey(int keyCode) booleanprivate booleanisReset()private booleanisSame(int isKey, int isModifier) listAll()Returns a list of all shortcuts.static StringmakeTooltip(String tooltip, KeyStroke keyStroke) Returns the tooltip text plus the key stroke text.private static ShortcutreassignShortcut(String shortText, String longText, int requestedKey, Shortcut conflict, int m, int k, int newmodifier) registerMultiShortcuts(String shortText, String longText, List<Character> characters, int requestedGroup) Register a shortcut linked to several characters.static ShortcutregisterShortcut(String shortText, String longText, int requestedKey, int requestedGroup) Register a shortcut.private static ShortcutregisterShortcut(String shortText, String longText, int requestedKey, int requestedGroup, Integer modifier) static ShortcutregisterSystemShortcut(String shortText, String longText, int key, int modifier) FOR PLATFORMHOOK USE ONLY.private booleansave()private voidstatic booleanSave shortcuts to preferencesvoidsetAccelerator(AbstractAction action) use this to set a actions's acceleratorvoidsetAssignedKey(int assignedKey) FOR PREF PANE ONLY.voidsetAssignedModifier(int assignedModifier) FOR PREF PANE ONLY.voidsetAssignedUser(boolean assignedUser) FOR PREF PANE ONLY.voidFOR PREF PANE ONLYvoidsetFocusAccelerator(JTextComponent component) Sets the mnemonic key on a text component.private voidsetLongText(String longText) voidsetMnemonic(AbstractButton button) use this to set a buttons's mnemonicvoidsetMnemonic(JMenu menu) use this to set a menu's mnemonicvoidsetTooltip(Action action, String tooltip) Sets the action tooltip to the tooltip text plus the key stroke text this shortcut represents.static voidsetTooltip(Action action, String tooltip, KeyStroke keyStroke) Sets the action tooltip to the tooltip text plus the key stroke text.toString()
-
Field Details
-
shortText
the unique ID of the shortcut -
longText
a human readable description that will be shown in the preferences -
requestedKey
the key, the caller requested -
requestedGroup
the group, the caller requested -
assignedKey
the key that actually is used -
assignedModifier
the modifiers that are used -
assignedDefault
true if it got assigned what was requested. (Note: modifiers will be ignored in favour of group when loading it from the preferences then.) -
assignedUser
true if the user changed this shortcut -
automatic
true if the user cannot change this shortcut (Note: it also will not be saved into the preferences) -
reset
true if the user requested this shortcut to be set to its default value (will happen on next restart, as this shortcut will not be saved to the preferences) -
shortcuts
-
groups
-
NONE
None group: used with KeyEvent.CHAR_UNDEFINED if no shortcut is defined- See Also:
-
MNEMONIC
- See Also:
-
RESERVED
Reserved group: for system shortcuts only- See Also:
-
DIRECT
Direct group: no modifier- See Also:
-
ALT
Alt group- See Also:
-
SHIFT
Shift group- See Also:
-
CTRL
Command group. Matches CTRL modifier on Windows/Linux but META modifier on OS X- See Also:
-
ALT_SHIFT
Alt-Shift group- See Also:
-
ALT_CTRL
Alt-Command group. Matches ALT-CTRL modifier on Windows/Linux but ALT-META modifier on OS X- See Also:
-
CTRL_SHIFT
Command-Shift group. Matches CTRL-SHIFT modifier on Windows/Linux but META-SHIFT modifier on OS X- See Also:
-
ALT_CTRL_SHIFT
Alt-Command-Shift group. Matches ALT-CTRL-SHIFT modifier on Windows/Linux but ALT-META-SHIFT modifier on OS X- See Also:
-
mods
-
keys
-
initdone
-
-
Constructor Details
-
Shortcut
-
Shortcut
-
-
Method Details
-
getShortText
-
getLongText
-
setLongText
-
getAssignedKey
-
getAssignedModifier
-
isAssignedDefault
-
isAssignedUser
-
isAutomatic
-
isChangeable
-
isReset
-
setAutomatic
FOR PREF PANE ONLY -
setAssignedModifier
FOR PREF PANE ONLY.Sets the modifiers that are used.
- Parameters:
assignedModifier- assigned modifier
-
setAssignedKey
FOR PREF PANE ONLY.Sets the key that actually is used.
- Parameters:
assignedKey- assigned key
-
setAssignedUser
FOR PREF PANE ONLY.Sets whether the user has changed this shortcut.
- Parameters:
assignedUser-trueif the user has changed this shortcut
-
getKeyStroke
Use this to register the shortcut with Swing- Returns:
- the key stroke
-
saveDefault
-
save
-
isSame
-
isEvent
-
setMnemonic
use this to set a menu's mnemonic- Parameters:
menu- menu
-
setMnemonic
use this to set a buttons's mnemonic- Parameters:
button- button
-
setFocusAccelerator
Sets the mnemonic key on a text component.- Parameters:
component- component
-
setAccelerator
use this to set a actions's accelerator- Parameters:
action- action
-
getKeyText
Returns a human readable text for the shortcut.- Returns:
- a human readable text for the shortcut
-
getKeyText
Returns a human readable text for the key stroke.- Parameters:
keyStroke- key stroke to convert to human readable text- Returns:
- a human readable text for the key stroke
- Since:
- 12520
-
setTooltip
Sets the action tooltip to the tooltip text plus the key stroke text this shortcut represents.- Parameters:
action- actiontooltip- Tooltip text to display- Since:
- 14689
-
setTooltip
Sets the action tooltip to the tooltip text plus the key stroke text.- Parameters:
action- actiontooltip- Tooltip text to displaykeyStroke- Key stroke associated (to display accelerator between parenthesis)- Since:
- 14689
-
toString
-
findShortcut
Returns the registered shortcut fot the key and modifier- Parameters:
requestedKey- the requested keymodifier- the modifier- Returns:
- an
Optionalregistered shortcut, nevernull
-
findShortcutByKeyOrShortText
private static Optional<Shortcut> findShortcutByKeyOrShortText(int requestedKey, int modifier, String shortText) -
listAll
Returns a list of all shortcuts.- Returns:
- a list of all shortcuts
-
doInit
-
getGroupModifier
-
findModifier
-
savePrefs
Save shortcuts to preferences- Returns:
trueif preferences were changed
-
registerSystemShortcut
public static Shortcut registerSystemShortcut(String shortText, String longText, int key, int modifier) FOR PLATFORMHOOK USE ONLY.This registers a system shortcut. See PlatformHook for details.
- Parameters:
shortText- an ID. re-use a"system:*"ID if possible, else use something unique.longText- this will be displayed in the shortcut preferences dialog. Better use something the user will recognize...key- the key. Use aKeyEvent.VK_*constant here.modifier- the modifier. Use aKeyEvent.*_MASKconstant here.- Returns:
- the system shortcut
-
registerMultiShortcuts
public static List<Shortcut> registerMultiShortcuts(String shortText, String longText, List<Character> characters, int requestedGroup) Register a shortcut linked to several characters.- 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...characters- the characters you'd preferrequestedGroup- the group this shortcut fits best. This will determine the modifiers your shortcut will get assigned. Use the constants defined above.- Returns:
- the shortcut
-
isDeadKey
-
registerShortcut
public static Shortcut registerShortcut(String shortText, 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 aKeyEvent.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.- Returns:
- the shortcut
-
registerShortcut
private static Shortcut registerShortcut(String shortText, String longText, int requestedKey, int requestedGroup, Integer modifier) -
findNewOsxModifier
-
reassignShortcut
private static Shortcut reassignShortcut(String shortText, String longText, int requestedKey, Shortcut conflict, int m, int k, int newmodifier) -
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
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
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
-
getKeyStrokeForShortKey
-
makeTooltip
Returns the tooltip text plus the key stroke text.Tooltips are usually not system dependent, unless the JVM is too dumb to provide correct names for all the keys.
Some LAFs don't understand HTML, such as the OSX LAFs.
- Parameters:
tooltip- Tooltip text to displaykeyStroke- Key stroke associated (to display accelerator between parenthesis)- Returns:
- Full tooltip text (tooltip + accelerator)
- Since:
- 14689
-