Class J3Key
KeyBindings.
A J3Key can be identified within KeyBindings.getActionMap() or KeyBindings.getInputMap()
via it's UUID.
This can either be a keystroke to do one task, which can have its action switched out for something else temporarily. Say if you have some key which works on W and you'd like to switch it to work for something else and then switch it back to normal.
A J3Key can also represent a one shot key where it deregisters itself after clicking.
A J3key can also be linked to other keys. See GlobalKeybinds.SELECT_SUBTRACT_DOWN
for example which is the leader of a 4 keychain link. If it's I keybind is changed,
the children will also change along with their own respective keycode.
e.g. if I changes to G+SHIFT, and it was linked to I+CTRL,
that will change to the new parent's code plus the child's original modifiers G+SHIFT+CTRL.
In a chain the leader's KeyEvent is what will cascade and not a child's parent.
It is vital that if you use linking, the parent node (often referred to in these docs as the leader)
should not be identical to any other child node. See KeyBindings.childModifiersClash(J3Key)
however to summarise, a leader keyStroke's AWTKeyStroke.getModifiers() AND AWTKeyStroke.isOnKeyRelease()
cannot clash with any one of the children defined within the chain.
- Author:
- Lehlogonolo Poole
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcall(ActionEvent e) Calls the current action.Returns the action of the key.getId()Returns the id of the key used for identification withinKeyBindings.getActionMap()andKeyBindings.getInputMap().Returns the keystroke of the key.getLink()Returns the child link of this key.getName()Returns the name of the key.booleanWhether the action of this key was replaced temporarily.booleanWhether this key will only execute once or not.Marks another key as the child link of this key.replaceAction(Action newAction) Replaces this key's original action with a new temporary actionResets the action, if replaced, to its normal value.Sets the action of this key.setKeyStroke(KeyStroke keyStroke) Sets the keystroke of this keySets the name of the key.
-
Field Details
-
name
-
id
-
keyStroke
-
oldAction
-
action
-
actionReplaced
private boolean actionReplaced -
oneShot
private boolean oneShot -
link
If this key has a normal version and is paired with another, this stores the key object, and it's modifiers.
-
-
Constructor Details
-
J3Key
Default J3Key constructor- Parameters:
name- the name of the keyoneShot- whether the key is only executed once before being removed.
-
J3Key
J3Key Constructor with all parameters.- Parameters:
name- the name of the keykeyStroke- the keystroke to bind toaction- the action to perform when the keystroke is pressed
-
-
Method Details
-
linkTo
Marks another key as the child link of this key. Such that if this key were updated, the other key is also updated.- Parameters:
otherKey- the other keyotherKeyModifiers- the other key's modifiers- Returns:
- this key for method chaining
-
getName
Returns the name of the key.- Returns:
- the name of the key
-
getKeyStroke
Returns the keystroke of the key.- Returns:
- the keystroke of the key
-
getAction
Returns the action of the key.- Returns:
- the action of the key
-
getId
Returns the id of the key used for identification withinKeyBindings.getActionMap()andKeyBindings.getInputMap().- Returns:
- the id of the key
-
getLink
Returns the child link of this key.- Returns:
- the child link of this key and its modifiers.
-
isActionReplaced
public boolean isActionReplaced()Whether the action of this key was replaced temporarily.- Returns:
- whether the action of this key was replaced temporarily
-
isOneShot
public boolean isOneShot()Whether this key will only execute once or not.- Returns:
- whether this key will only execute once or not
-
setName
Sets the name of the key.- Parameters:
name- the name of the key- Returns:
- this key for method chaining
-
setKeyStroke
Sets the keystroke of this key- Parameters:
keyStroke- the keystroke to bind to- Returns:
- this key for method chaining
-
setAction
Sets the action of this key.- Parameters:
action- the action to perform when the keystroke is pressed- Returns:
- this key for method chaining
-
replaceAction
Replaces this key's original action with a new temporary action- Parameters:
newAction- The new action- Returns:
- this key for method chaining
-
resetAction
Resets the action, if replaced, to its normal value.- Returns:
- this key for method chaining
-
call
Calls the current action.- Parameters:
e- the action event
-
setId
-