Class InputEvent

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
KeyEvent, MouseEvent

public abstract class InputEvent extends ComponentEvent
Port of InputEvent. Abstract parent of MouseEvent and KeyEvent. Extends our ComponentEvent — AWT does the same — so the instanceof chain from our leaf event up to ComponentEvent still walks through InputEvent as users expect.

Modifier constants (the *_DOWN_MASK set) have identical values to AWT's so bit arithmetic carries across. The legacy *_MASK set (deprecated since JDK 9) is kept for user code that hasn't migrated yet.

Static utilities delegate to java.awt.event.InputEvent — constants are compatible, so there's no point re-deriving the logic.

Consuming an event marks it; it does not suppress anything

consume() / isConsumed() are ported faithfully and the flag round-trips across listeners exactly as in Swing — the "listener A consumes, listener B checks" idiom works unchanged. What consuming cannot do here is cancel the platform's default action: in Swing, consuming a KEY_PRESSED in a text field stops the character being inserted, whereas the browser has already inserted it by the time the keystroke reaches the server. Nothing in this emulator runs after listener notification for a consume to gate — see Component.processKeyEvent — so the flag is read-back state, not a veto. R_match_swing_errors sub-bucket (c), documented rather than WARNed: the storage half is exactly faithful, so an onUnimplemented on every consume() call would be both wrong and deafening. See D_event_consume.
See Also:
  • Field Details

  • Constructor Details

    • InputEvent

      protected InputEvent(Component source, int id, long when, int modifiers)
  • Method Details

    • getWhen

      public long getWhen()
    • getModifiers

      @Deprecated public int getModifiers()
      Deprecated.
      Legacy modifiers (deprecated). Real AWT stored two fields; we store the extended set and return it unchanged — user code checking specific bits should use getModifiersEx() with the *_DOWN_MASK constants anyway.
    • getModifiersEx

      public int getModifiersEx()
    • isShiftDown

      public boolean isShiftDown()
    • isControlDown

      public boolean isControlDown()
    • isMetaDown

      public boolean isMetaDown()
    • isAltDown

      public boolean isAltDown()
    • isAltGraphDown

      public boolean isAltGraphDown()
    • consume

      public void consume()
      Marks this event consumed. Public here, as in the JDK — AWTEvent declares it protected and conditional on the event id, and InputEvent widens it and drops the condition.

      Sets the flag and nothing more; see the class javadoc for what that does and does not buy you.

      Overrides:
      consume in class AWTEvent
    • isConsumed

      public boolean isConsumed()
      Overrides:
      isConsumed in class AWTEvent
      Returns:
      whether consume() has been called on this event
    • getMaskForButton

      public static int getMaskForButton(int button)
      Bit mask for a 1-indexed button (1 → BUTTON1_DOWN_MASK, …). Delegates to AWT — the constants match, and any bounds handling stays centralised.
    • getModifiersExText

      public static String getModifiersExText(int modifiers)
      Localised "Shift+Ctrl+Button1" string for a modifiersEx value. Delegates to AWT — constants match and the formatting is locale-aware.