Class InputState

java.lang.Object
org.fest.swing.input.InputState

@ThreadSafe public class InputState extends Object
Class to keep track of a given input state. Includes mouse/pointer position and keyboard modifier key state.

Synchronization assumes that any given instance might be called from more than one event dispatch thread.

  • Field Details

    • mouseInfo

      private final MouseInfo mouseInfo
    • dragDropInfo

      private final DragDropInfo dragDropInfo
    • modifiers

      private int modifiers
    • lastEventTime

      private long lastEventTime
    • normalizer

      private EventNormalizer normalizer
  • Constructor Details

    • InputState

      public InputState(Toolkit toolkit)
  • Method Details

    • clear

      public void clear()
    • dispose

      public void dispose()
    • update

      public void update(AWTEvent event)
      Explicitly update the internal state.
      Parameters:
      event - the event to use to update the internal state.
    • updateState

      private void updateState(KeyEvent event)
    • updateState

      private void updateState(MouseEvent event)
    • isOld

      private boolean isOld(InputEvent event)
    • lastEventTime

      private void lastEventTime(InputEvent event)
    • modifiers

      private void modifiers(int newModifiers)
    • deepestComponentUnderMousePointer

      public Component deepestComponentUnderMousePointer()
      Returns the most deeply nested component which currently contains the pointer.
      Returns:
      the most deeply nested component which currently contains the pointer.
    • mouseComponent

      public Component mouseComponent()
      Returns the last known Component to contain the pointer, or null if none. Note that this may not correspond to the component that actually shows up in AWTEvents.
      Returns:
      the last known Component to contain the pointer, or null if none.
    • childAt

      public static Component childAt(Component parent, Point where)
      Returns the component under the given coordinates in the given parent component. Events are often generated only for the outermost container, so we have to determine if the pointer is actually within a child. Basically the same as Component.getComponentAt, but recurses to the lowest-level component instead of only one level. Point is in component coordinates.

      The default Component.getComponentAt can return invisible components (JRootPane has an invisible JPanel (glass pane?) which will otherwise swallow everything).

      NOTE: childAt grabs the TreeLock, so this should *only* be invoked on the event dispatch thread, preferably with no other locks held. Use it elsewhere at your own risk.

      Parameters:
      parent - the given parent.
      where - the given coordinates.
      Returns:
      the component under the given coordinates in the given parent component.
    • dragInProgress

      public boolean dragInProgress()
      Indicates there is a drag operation in progress.
      Returns:
      true if there is a drag operation in progress, false otherwise.
    • dragSource

      public Component dragSource()
      Returns the Component where a drag operation started.
      Returns:
      the Component where a drag operation started.
    • dragOrigin

      public Point dragOrigin()
      Returns the coordinates where a drag operation started.
      Returns:
      the coordinates where a drag operation started.
    • clickCount

      public int clickCount()
      Indicates the number of times a mouse button was clicked.
      Returns:
      the number of times a mouse button was clicked.
    • lastEventTime

      public long lastEventTime()
      Returns the time when the last input event occurred.
      Returns:
      the time when the last input event occurred.
    • modifiers

      public int modifiers()
      Returns all currently active modifiers.
      Returns:
      all currently active modifiers.
    • keyModifiers

      public int keyModifiers()
      Returns the currently pressed key modifiers.
      Returns:
      the currently pressed key modifiers.
    • buttons

      public int buttons()
      Returns the mouse buttons used in the last input event.
      Returns:
      the mouse buttons used in the last input event.
    • mouseLocation

      public Point mouseLocation()
      Returns the mouse location relative to the component that currently contains the pointer, or null if outside all components.
      Returns:
      the mouse location relative to the component that currently contains the pointer, or null if outside all components.
    • mouseLocationOnScreen

      public Point mouseLocationOnScreen()
      Returns the last known mouse location.
      Returns:
      the last known mouse location.
    • isNativeDragActive

      public boolean isNativeDragActive()
      Indicates whether there is a native drag/drop operation in progress.
      Returns:
      true if there is a native drag/drop operation in progress, false otherwise.