Class KeyBindings
java.lang.Object
com.j3d.engine.interact.input.keyboard.KeyBindings
A class that manages the key bindings for the application. It allows for easy addition and removal
of key bindings, and handles the actions associated with each key binding.
- Author:
- Lehlogonolo Poole
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classUpdatedJ3Key is a return object ofrebindJ3KeyKeystroke(KeyStroke, J3Key)which represents the result of the update. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ActionMapstatic AbstractActionprivate final InputMapList of registered keys.A list of prohibited key bindings that should not be added to the input and action maps. -
Constructor Summary
ConstructorsConstructorDescriptionKeyBindings(InputMap im, ActionMap am) Initialises the key bindings for the application. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanchildModifiersClash(J3Key leader) Inspects whether the leader of a chain of keystroke's updated modifier will clash or cause a clash with any 1 child keystroke.static booleanFlattens aMenuElementinto a stream ofJMenuItems.Returns the action map containing the actions bound to keys.Returns the input map containing the key bindings.rebindJ3KeyKeystroke(KeyStroke old, J3Key key) Updates the keystroke of a J3Key.voidregisterJ3Key(J3Key key) Registers a J3KeyremoveJ3Key(UUID id) Removes a J3KeyvoidRemoves a J3Keyprivate voidRegisters a J3Key. unsafely.private voidupdateLinks(J3Key leader, KeyStroke newKeyStroke)
-
Field Details
-
inputMap
-
actionMap
-
keys
List of registered keys. -
globalKeyStrokes
-
prohibited
A list of prohibited key bindings that should not be added to the input and action maps. This is used to prevent common key bindings that would interfere with the application's functionality from being added by the user.These are defined by
EngineFrame.jMenuBar1using accelerators. -
clearInferredSelectionType
-
-
Constructor Details
-
KeyBindings
-
KeyBindings
Initialises the key bindings for the application.- Parameters:
im- the input map to use for key bindingsam- the action map to use for key bindings
-
-
Method Details
-
flatten
Flattens aMenuElementinto a stream ofJMenuItems.- Parameters:
m- The menu element to flatten.- Returns:
- A stream of JMenuItems.
-
getGlobalKeyStrokes
-
rJ3Key
Registers a J3Key. unsafely.- Parameters:
key- the J3Key to register
-
registerJ3Key
Registers a J3Key- Parameters:
key- the J3Key to register
-
updateLinks
-
childModifiersClash
Inspects whether the leader of a chain of keystroke's updated modifier will clash or cause a clash with any 1 child keystroke.Preamble :
KeyEventare bit masks, meaning combinations are just the bitwise OR and two combinations such asSHIFT | SHIFTbecomeSHIFTIn essence a conflict is made when the bitwise OR of the leader's modifiers with any child modifier is equal to the leader modifier.
(leaderMod | childMod) == leaderModSay we have the following test cases, where the first keystroke is the leader and the rest are childrten.
And we'd like to rebind the leader of each link to1. (I) -> (SHIFT + I) -> (CTRL + I) 2. (P) -> (ALT + P) -> (SHIFT + P) 3. K -> (CTRL + K) -> (ALT + K)ALT + O,SHIFT + SandCTRL + ALT + Jrespectively. (We Only care about the SHIFT, CTRL, ALT, ALT_GRADE and META modifiers, so the letters themselves will be ignored and replaced with a question mark to represent the letter)In link 1 it becomes
No child's modifier conflicts with the leader key's modifier. This is a valid change.(ALT + ?) -> (SHIFT + ALT + ?) -> (CTRL + ALT + ?)In link 2
Here due to the simplification, the leader conflicts with the last child. This is an invalid case.(SHIFT + ?) -> (ALT + SHIFT + ?) -> (SHIFT + SHIFT + ?) // The 2 shifts simplify to a singular shift via bitwise OR (SHIFT + ?) -> (ALT + SHIFT + ?) -> (SHIFT + ?)In link 3
This link, obviously also produces conflicts, accept both children conflict with the parent node. And this method, simply checks for these.(CTRL + ALT + ?) -> (CTRL + CTRl + ALT + ?) -> (ALT + CTRL + ALT + ?) // Again the duplicate shifts OR together (CTRL + ALT + ?) -> (CTRL + ALT + ?) -> (CTRL + ALT + ?)- Parameters:
leader- The leader in question.- Returns:
- Whether any child modifier of this key clash with said key or not.
- See Also:
-
rebindJ3KeyKeystroke
Updates the keystroke of a J3Key. If an existing J3Key with the same keystroke is found, it swaps the 2 keys.- Parameters:
old- The old keystroke of this key.key- The key in question- Returns:
- An
KeyBindings.UpdatedJ3Keyobject that indicates the result of the update.
-
removeJ3Key
Removes a J3Key- Parameters:
id- the id of the J3Key to remove- Returns:
- the J3Key that was removed
-
removeJ3KeyConsumer
Removes a J3Key- Parameters:
id- the id of the J3Key to remove
-
getActionMap
Returns the action map containing the actions bound to keys.- Returns:
- the action map
-
getInputMap
Returns the input map containing the key bindings.- Returns:
- the input map
-
commandPaletteFocusOwner
public static boolean commandPaletteFocusOwner()
-