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 DragDropInfo
private long
private int
private final MouseInfo
private EventNormalizer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
buttons()
Returns the mouse buttons used in the last input event.static Component
Returns the component under the given coordinates in the given parent component.void
clear()
int
Indicates the number of times a mouse button was clicked.Returns the most deeply nested component which currently contains the pointer.void
dispose()
boolean
Indicates there is a drag operation in progress.Returns the coordinates where a drag operation started.Returns the
where a drag operation started.Component
boolean
Indicates whether there is a native drag/drop operation in progress.private boolean
isOld
(InputEvent event) int
Returns the currently pressed key modifiers.long
Returns the time when the last input event occurred.private void
lastEventTime
(InputEvent event) int
Returns all currently active modifiers.private void
modifiers
(int newModifiers) Returns the last known Component to contain the pointer, ornull
if none.Returns the mouse location relative to the component that currently contains the pointer, ornull
if outside all components.Returns the last known mouse location.void
Explicitly update the internal state.private void
updateState
(KeyEvent event) private void
updateState
(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, ornull
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
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
Returns the
where a drag operation started.Component
- Returns:
- the
Component
where 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, ornull
if outside all components.- Returns:
- the mouse location relative to the component that currently contains the pointer, or
null
if 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:
true
if there is a native drag/drop operation in progress,false
otherwise.
-