org.fest.swing.input
Class InputState

java.lang.Object
  extended by 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.


Constructor Summary
InputState(Toolkit toolkit)
           
 
Method Summary
 int buttons()
          Returns the mouse buttons used in the last input event.
static Component childAt(Component parent, Point where)
          Returns the component under the given coordinates in the given parent component.
 void clear()
           
 int clickCount()
          Indicates the number of times a mouse button was clicked.
 Component deepestComponentUnderMousePointer()
          Returns the most deeply nested component which currently contains the pointer.
 void dispose()
           
 boolean dragInProgress()
          Indicates there is a drag operation in progress.
 Point dragOrigin()
          Returns the coordinates where a drag operation started.
 Component dragSource()
          Returns the Component where a drag operation started.
 boolean isNativeDragActive()
          Indicates whether there is a native drag/drop operation in progress.
 int keyModifiers()
          Returns the currently pressed key modifiers.
 long lastEventTime()
          Returns the time when the last input event occurred.
 int modifiers()
          Returns all currently active modifiers.
 Component mouseComponent()
          Returns the last known Component to contain the pointer, or null if none.
 Point mouseLocation()
          Returns the mouse location relative to the component that currently contains the pointer, or null if outside all components.
 Point mouseLocationOnScreen()
          Returns the last known mouse location.
 void update(AWTEvent event)
          Explicitly update the internal state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InputState

public InputState(Toolkit toolkit)
Method Detail

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.

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.


Copyright © 2007-2011 FEST (Fixtures for Easy Software Testing). All Rights Reserved.