java.lang.Object
com.j3d.engine.interact.input.keyboard.J3Key

public class J3Key extends Object
A singular key on the keyboard or keystroke that gets put into 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 Details

    • name

      private String name
    • id

      private UUID id
    • keyStroke

      private KeyStroke keyStroke
    • oldAction

      private Action oldAction
    • action

      private Action action
    • actionReplaced

      private boolean actionReplaced
    • oneShot

      private boolean oneShot
  • Constructor Details

    • J3Key

      public J3Key(String name, boolean oneShot)
      Default J3Key constructor
      Parameters:
      name - the name of the key
      oneShot - whether the key is only executed once before being removed.
    • J3Key

      public J3Key(String name, KeyStroke keyStroke, Action action)
      J3Key Constructor with all parameters.
      Parameters:
      name - the name of the key
      keyStroke - the keystroke to bind to
      action - the action to perform when the keystroke is pressed
  • Method Details

    • linkTo

      public J3Key linkTo(J3Key otherKey, int otherKeyModifiers)
      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 key
      otherKeyModifiers - the other key's modifiers
      Returns:
      this key for method chaining
    • getName

      public String getName()
      Returns the name of the key.
      Returns:
      the name of the key
    • getKeyStroke

      public KeyStroke getKeyStroke()
      Returns the keystroke of the key.
      Returns:
      the keystroke of the key
    • getAction

      public Action getAction()
      Returns the action of the key.
      Returns:
      the action of the key
    • getId

      public UUID getId()
      Returns the id of the key used for identification within KeyBindings.getActionMap() and KeyBindings.getInputMap().
      Returns:
      the id of the key
    • getLink

      public Pair<J3Key,Integer> 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

      public J3Key setName(String name)
      Sets the name of the key.
      Parameters:
      name - the name of the key
      Returns:
      this key for method chaining
    • setKeyStroke

      public J3Key setKeyStroke(KeyStroke keyStroke)
      Sets the keystroke of this key
      Parameters:
      keyStroke - the keystroke to bind to
      Returns:
      this key for method chaining
    • setAction

      public J3Key setAction(Action action)
      Sets the action of this key.
      Parameters:
      action - the action to perform when the keystroke is pressed
      Returns:
      this key for method chaining
    • replaceAction

      public J3Key replaceAction(Action newAction)
      Replaces this key's original action with a new temporary action
      Parameters:
      newAction - The new action
      Returns:
      this key for method chaining
    • resetAction

      public J3Key resetAction()
      Resets the action, if replaced, to its normal value.
      Returns:
      this key for method chaining
    • call

      public void call(ActionEvent e)
      Calls the current action.
      Parameters:
      e - the action event
    • setId

      public J3Key setId(UUID id)