Package org.fest.swing.input
Class InputState
java.lang.Object
org.fest.swing.input.InputState
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final DragDropInfoprivate longprivate intprivate final MouseInfoprivate EventNormalizer -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintbuttons()Returns the mouse buttons used in the last input event.static ComponentReturns the component under the given coordinates in the given parent component.voidclear()intIndicates the number of times a mouse button was clicked.Returns the most deeply nested component which currently contains the pointer.voiddispose()booleanIndicates there is a drag operation in progress.Returns the coordinates where a drag operation started.Returns thewhere a drag operation started.ComponentbooleanIndicates whether there is a native drag/drop operation in progress.private booleanisOld(InputEvent event) intReturns the currently pressed key modifiers.longReturns the time when the last input event occurred.private voidlastEventTime(InputEvent event) intReturns all currently active modifiers.private voidmodifiers(int newModifiers) Returns the last known Component to contain the pointer, ornullif none.Returns the mouse location relative to the component that currently contains the pointer, ornullif outside all components.Returns the last known mouse location.voidExplicitly update the internal state.private voidupdateState(KeyEvent event) private voidupdateState(MouseEvent event)
-
Field Details
-
mouseInfo
-
dragDropInfo
-
modifiers
private int modifiers -
lastEventTime
private long lastEventTime -
normalizer
-
-
Constructor Details
-
InputState
-
-
Method Details
-
clear
public void clear() -
dispose
public void dispose() -
update
Explicitly update the internal state.- Parameters:
event- the event to use to update the internal state.
-
updateState
-
updateState
-
isOld
-
lastEventTime
-
modifiers
private void modifiers(int newModifiers) -
deepestComponentUnderMousePointer
Returns the most deeply nested component which currently contains the pointer.- Returns:
- the most deeply nested component which currently contains the pointer.
-
mouseComponent
Returns the last known Component to contain the pointer, ornullif 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
nullif none.
-
childAt
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:
trueif there is a drag operation in progress,falseotherwise.
-
dragSource
Returns thewhere a drag operation started.Component- Returns:
- the
Componentwhere a drag operation started.
-
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
Returns the mouse location relative to the component that currently contains the pointer, ornullif outside all components.- Returns:
- the mouse location relative to the component that currently contains the pointer, or
nullif outside all components.
-
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:
trueif there is a native drag/drop operation in progress,falseotherwise.
-