Class KeystrokeChooser

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
com.inductiveautomation.factorypmi.designer.scripteditor.KeystrokeChooser
All Implemented Interfaces:
ItemListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible

public class KeystrokeChooser extends JPanel implements ItemListener
See Also:
  • Constructor Details

    • KeystrokeChooser

      public KeystrokeChooser(KeystrokeKey keystrokeKey)
    • KeystrokeChooser

      public KeystrokeChooser()
  • Method Details

    • reset

      public void reset()
    • createDefaultKeystrokeKey

      public static KeystrokeKey createDefaultKeystrokeKey()
    • getKeyStrokeString

      public KeystrokeKey getKeyStrokeString() throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • getStroke

      public String getStroke()
      The keystroke the chooser currently shows, as a stroke string — for example "ctrl pressed S" or "typed !" — even while it is mid-edit: a "Typed" action carries the character box's text as-is, so it may hold no character or several.

      Read-only counterpart to getKeyStrokeString(): it never shows an error dialog and never throws, so callers that merely observe the panel — reporting the binding to the AI assist popup, say — cannot interrupt the user with a validation error just by looking.

      Returns:
      the stroke string, which is only bindable when getKeyStrokeString() accepts it.
    • keyNames

      public static Set<String> keyNames()
      The key names the Key list offers for "Pressed" and "Released" keystrokes — KeyEvent names without the VK_ prefix, such as "F1", "ENTER", or "1". Any other key can only be bound as a "Typed" character.
      Returns:
      the key names, in the Key list's order.
    • setKeystroke

      public void setKeystroke(KeystrokeKey keystrokeKey)
      Loads a keystroke into every widget: selects the action, key or character, and modifiers its stroke string names, clearing any others. The action is the first word after the modifiers; a stroke without one there leaves the action, key, and character unchanged. A key the Key list does not offer leaves the list's selection unchanged, so check it against keyNames() first.

      A "Typed" stroke that names modifiers, which the chooser no longer lets a user build, loads exactly as saved: its modifiers show checked but disabled, so saving without changes keeps the binding as it was rather than turning it into one that fires on the bare character. Switching to "Pressed" or "Released" makes them editable.

      Parameters:
      keystrokeKey - the keystroke to show; only its stroke string is read.
    • itemStateChanged

      public void itemStateChanged(ItemEvent e)
      Specified by:
      itemStateChanged in interface ItemListener