Package resources
Class AcceleratorTable
- java.lang.Object
-
- resources.AcceleratorTable
-
public final class AcceleratorTable extends java.lang.Object
An accelerator table maps command names to keyboard gestures. Like aLanguage
instance, it can load gestures from a resource file and it uses file name patterns to combine a baseline set of definitions with context-sensitive overrides. In the case of an accelerator table, the following patterns are used to create platform-specific variants:basename.properties basename-win.properties basename-mac.properties basename-other.properties
Other variant names may be added in future to support new target platforms.- Since:
- 3.0.3666
- Author:
- Chris Jennings
-
-
Constructor Summary
Constructors Constructor Description AcceleratorTable()
Creates a new, empty accelerator table.AcceleratorTable(java.lang.String baseFile)
Creates a new accelerator table that reads its content from the specified resource file.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static javax.swing.KeyStroke
acceleratorFromString(java.lang.String description)
Converts a string to a single key stroke.void
addAcceleratorsFrom(java.lang.String baseFile)
Adds key mappings from the specified resource file.javax.swing.KeyStroke
get(java.lang.String key)
Returns the key stroke associated with an arbitrary key.static AcceleratorTable
getApplicationTable()
Returns the standard accelerator table for the application.void
set(java.lang.String key, javax.swing.KeyStroke accelerator)
Sets the keystroke associated with an arbitrary key in the user table.static java.lang.String
stringFromAccelerator(javax.swing.KeyStroke accelerator)
Returns a string that can be converted back into the specified key stroke.
-
-
-
Constructor Detail
-
AcceleratorTable
public AcceleratorTable()
Creates a new, empty accelerator table.
-
AcceleratorTable
public AcceleratorTable(java.lang.String baseFile) throws java.io.IOException
Creates a new accelerator table that reads its content from the specified resource file. The table will also check for a file with the same name in thekeys
subfolder of the user storage folder, and load any definitions found there. Tables created using this constructor can null null null null modify the key mappings and save changes back again.- Parameters:
baseFile
- the base file name of the table to load- Throws:
java.io.IOException
- if an I/O error occurs
-
-
Method Detail
-
addAcceleratorsFrom
public void addAcceleratorsFrom(java.lang.String baseFile) throws java.io.IOException
Adds key mappings from the specified resource file. The loaded mappings will not override any user mappings loaded when the table was created.- Parameters:
baseFile
- the base file name of the table to load- Throws:
java.io.IOException
- if an I/O error occurs
-
get
public javax.swing.KeyStroke get(java.lang.String key)
Returns the key stroke associated with an arbitrary key.- Parameters:
key
- the key name- Returns:
- the key stroke associated with the key, or
null
-
set
public void set(java.lang.String key, javax.swing.KeyStroke accelerator)
Sets the keystroke associated with an arbitrary key in the user table. If the accelerator is set to the same value as that loaded from the resource files, then the value will revert to the default instead of modifying the user table.- Parameters:
key
- the key nameaccelerator
- the key stroke to associated with the key (may benull
)
-
acceleratorFromString
public static javax.swing.KeyStroke acceleratorFromString(java.lang.String description)
Converts a string to a single key stroke. The string may use one of two formats: the verbose format use by theKeyStroke
class, or a compact format that requires less typing. The compact format uses the form[modifiers*+]key
. Here,modifiers
represents a sequence of one or more modifier keys. Each modifier is represented by a single letter:Modifier letter codes P
Platform-specific menu accelerator key (Control on most platforms; Command on OS X) M
Meta (Command) C
Control A
Alt S
Shift G
AltGr (not recommended for shortcut keys) Examples:
HOME
ctrl X
ctrl alt DELETE
C+X
CA+DELETE
C + A + Delete
- Parameters:
description
- the string description of the key stroke, in one of the two supported formats- Returns:
- a
KeyStroke
for the string description, ornull
-
stringFromAccelerator
public static java.lang.String stringFromAccelerator(javax.swing.KeyStroke accelerator)
Returns a string that can be converted back into the specified key stroke. Returns an empty string if the key stroke isnull
. The string will use the compact form if possible.- Parameters:
accelerator
- the accelerator to convert- Returns:
- a string representation of the key stroke
-
getApplicationTable
public static AcceleratorTable getApplicationTable()
Returns the standard accelerator table for the application.- Returns:
- application keyboard shortcuts
-
-