|
QJCC homepage | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object biz.chitec.quarterback.util.Hotkeys
Low-level hotkey tool.
Knows how to create hotkeys for lists of strings. Normally, these strings will be button or menu labels or something similar which is collected outside Hotkeys (see biz.chitec.quarterback.HotkeyManager). Through the getHotkeys() method, a list of such Strings is given to the Hotkeys class, which will return a list of same size containing the Hotkeys for this bundle of Strings.
Hotkeys uses a recursive depth search with backtracking over all given strings to find an assignment of hotkeys to the given strings so that each one has its unique key. If this is not possible, a second search pass will find a solution where at least some strings get a hotkey. For each string, hotkey preference is: First look at beginnings of words, then at other characters, and search each group from left to right.
Recursive backtracking is notoriously slow. In this case, however, recursion depth isn't that deep (it cannot be deeper than 26, as there are no more hotkeys), and the number of possible alternatives on each level is not that big, either. So, search should normally be really fast. Nevertheless, Hotkeys features a cache which can be made persistent through the standard Java serialisation features. Just serialize the complete Hotkeys instance. To make the cache work properly, you have to pass a unique name for each String list you want to have hotkeys for. If the same name is given again and the MD5 sum over the strings is the same, Hotkeys simply returns the cached value.
Note: Hotkeys is not thread-safe. You should always call the methods in this class from the same thread.
HotkeyMaker
Nested Class Summary | |
private class |
Hotkeys.FindCounter
Counting sentinel to prevent search from going mad. |
Field Summary | |
private java.util.Map |
cache
The cache |
private static java.security.MessageDigest |
md
Message digest for MD5 sum checking |
private java.util.ResourceBundle |
rb
The resource bundle |
Constructor Summary | |
Hotkeys()
Initialize the instance and its cache. |
Method Summary | |
private java.util.List |
computeHotkeys(java.util.List entries,
java.lang.String allowed)
Internal computation method to be called if cache had no entry. |
private java.lang.String |
computeMD5(java.util.List entries,
java.lang.String allowed)
Compute an MD5 sum over a list of Strings and the allowed hotkeys Used internally to detect changes in cached input. |
private java.util.List |
computeRemainingHotkeys(java.util.List remaining,
java.lang.String allowed,
boolean relaxed,
Hotkeys.FindCounter fc)
Recursive hotkey search implementation Walks through first String in the list. |
java.lang.String |
getDefaultAllowedKeys()
Return the default allowed hotkeys. |
java.util.List |
getHotkeys(java.lang.String element,
java.util.List entries,
java.lang.String allowed)
Main method: Returns hotkeys list for given input. |
private java.util.ResourceBundle |
getRB()
Load the instances own resource bundle if it is not already loaded. |
private java.lang.String |
reorderChars(java.lang.String original,
java.lang.String allowed)
Reorder the characters in a String so that leftmost is the best hotkey (and rightmost the worst) Starts with beginnings of words, then rests of words, both from left to right. |
java.lang.String |
shrinkAllowed(java.util.List hotkeys,
java.lang.String allowed)
Shrinks the allowed keys by the ones which are in the hotkeys list. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static transient java.security.MessageDigest md
private java.util.Map cache
private transient java.util.ResourceBundle rb
Constructor Detail |
public Hotkeys()
Method Detail |
private java.util.ResourceBundle getRB()
public java.lang.String getDefaultAllowedKeys()
private java.lang.String reorderChars(java.lang.String original, java.lang.String allowed)
original
- A String to add a hotkey to
private java.lang.String computeMD5(java.util.List entries, java.lang.String allowed)
entries
- List of Stringsallowed
- String containing all allowed hotkeys
public java.util.List getHotkeys(java.lang.String element, java.util.List entries, java.lang.String allowed)
element
- A unique name for the string list (used as cache key)entries
- The list of Stringsallowed
- List of allowed hotkeys. If null, uses built-in default
public java.lang.String shrinkAllowed(java.util.List hotkeys, java.lang.String allowed)
hotkeys
- List of hotkeys already in usageallowed
- String containing all allowed hotkeys
private java.util.List computeHotkeys(java.util.List entries, java.lang.String allowed)
entries
- List of Stringsallowed
- String containing all allowed hotkeys
private java.util.List computeRemainingHotkeys(java.util.List remaining, java.lang.String allowed, boolean relaxed, Hotkeys.FindCounter fc)
remaining
- List to search in, this recursion depth will only handle first entryallowed
- All allowed hotkeysrelaxed
- Flag to indicate relaxed mode, in which it is allowed to be unable to find a hotkeyfc
- global counter to restrict backtrace complexity
|
QJCC homepage | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |