Package org.netbeans.jemmy
Class EventDispatcher
java.lang.Object
org.netbeans.jemmy.EventDispatcher
- All Implemented Interfaces:
Outputable
,Timeoutable
Provides low level functions for reproducing user actions.
One dispatch model uses the managed component's event queue to dispatch
events. The other dispatch model uses
EventDispatcher.WaitQueueEmptyTimeout - to wait event queue empty.
EventDispatcher.RobotAutoDelay - param for java.awt.Robot.setAutoDelay method.
EventDispatcher.WaitComponentUnderMouseTimeout - time to wait component under mouse.
java.awt.Robot
to
generate native events. It is an option in the Robot dispatch model
to wait for the managed component's event queue to empty before dispatching
events.
Timeouts used: EventDispatcher.WaitQueueEmptyTimeout - to wait event queue empty.
EventDispatcher.RobotAutoDelay - param for java.awt.Robot.setAutoDelay method.
EventDispatcher.WaitComponentUnderMouseTimeout - time to wait component under mouse.
- Author:
- Alexandre Iline (alexandre.iline@sun.com)
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
checkComponentUnderMouse
(boolean yesOrNo) Wait (or not) for the mouse to move over a Java component before pressing.void
delayRobot
(long time) Delays robot.void
dispatchEvent
(AWTEvent event) DispatchesAWTEvent
to component passed in constructor.void
dispatchKeyEvent
(int id, int mods, int keyCode) Dispatches KeyEvent.void
dispatchKeyEvent
(int id, int mods, int keyCode, char keyChar) Dispatches KeyEvent.void
dispatchMouseEvent
(int id, int mods, int clickCount, boolean popup) Dispatches MouseEvent at the center of component.void
dispatchMouseEvent
(int id, int mods, int clickCount, int x, int y, boolean popup) Dispatches a MouseEvent.void
dispatchWindowEvent
(int id) Dispatches WindowEvent.protected int
getAbsoluteX
(int x) Bind horizontal relative cursor coordinate to screen coordinate.protected int
getAbsoluteY
(int y) Bind vertical relative cursor coordinate to screen coordinate.int
Gets the dispatching model value.getExistingField
(String field_name) Gets component field value throughSwingUtilities.invokeAndWait(Runnable)
.getExistingField
(String field_name, TestOut out) Gets component field value throughSwingUtilities.invokeAndWait(Runnable)
.Gets component field value throughSwingUtilities.invokeAndWait(Runnable)
.static String
getKeyDescription
(int keyCode) Returns a string representation for a keyboard event.static String
getModifiersString
(int modifiers) Get a string representation for key modifiers.static String
getMouseButtonDescription
(int button) Returns a mouse button string representation.Returns print output streams or writers.Return current timeouts.invokeExistingMethod
(String method_name, Object[] params, Class[] params_classes) Invokes component method throughSwingUtilities.invokeAndWait(Runnable)
.invokeExistingMethod
(String method_name, Object[] params, Class[] params_classes, TestOut out) Invokes component method throughSwingUtilities.invokeAndWait(Runnable)
.invokeMethod
(String method_name, Object[] params, Class[] params_classes) Invokes component method throughSwingUtilities.invokeAndWait(Runnable)
.static void
void
robotMoveMouse
(int x, int y) Moves mouse by robot.void
robotPressKey
(int keyCode) Press key with no modifiers usingjava.awt.Robot
.void
robotPressKey
(int keyCode, int modifiers) Press a key usingjava.awt.Robot
.void
robotPressMouse
(int button) Press mouse button with 0 modifiers.void
robotPressMouse
(int button, int modifiers) Press mouse button by robot.void
robotReleaseKey
(int keyCode) Releases key with 0 modifiers.void
robotReleaseKey
(int keyCode, int modifiers) Releases key by robot.void
robotReleaseMouse
(int button) Releases mouse button with 0 modifiers.void
robotReleaseMouse
(int button, int modifiers) Releases mouse button by robot.void
setDispatchingModel
(int m) Defines dispatching model.void
setExistingField
(String field_name, Object newValue) Sets component field value throughSwingUtilities.invokeAndWait(Runnable)
.void
setExistingField
(String field_name, Object newValue, TestOut out) Sets component field value throughSwingUtilities.invokeAndWait(Runnable)
.void
Sets component field value throughSwingUtilities.invokeAndWait(Runnable)
.void
Defines print output streams or writers.void
setTimeouts
(Timeouts timeouts) Defines current timeouts.void
Waits until all events currently on the event queue have been processed.static void
Waits for the managed component'sjava.awt.EventQueue
to empty.static void
waitQueueEmpty
(long emptyTime) Waits for the managed component'sjava.awt.EventQueue
to stay empty.static void
waitQueueEmpty
(long emptyTime, TestOut output, Timeouts timeouts) Waits for the managed component'sjava.awt.EventQueue
to stay empty.static void
waitQueueEmpty
(TestOut output, Timeouts timeouts) Waits for the managed component'sjava.awt.EventQueue
to empty.
-
Field Details
-
component
Component to dispatch events to.
-
-
Constructor Details
-
EventDispatcher
Constructor.- Parameters:
comp
- Component to operate with.
-
-
Method Details
-
waitQueueEmpty
Waits for the managed component'sjava.awt.EventQueue
to empty. The timeout for this wait is EventDispatcher.WaitQueueEmptyTimeout.- Parameters:
output
- Output to print exception into.timeouts
- A collection of timeout assignments.- Throws:
TimeoutExpiredException
- See Also:
-
waitQueueEmpty
public static void waitQueueEmpty()Waits for the managed component'sjava.awt.EventQueue
to empty. Uses default output and timeouts. The timeout for this wait is EventDispatcher.WaitQueueEmptyTimeout.- Throws:
TimeoutExpiredException
- See Also:
-
waitQueueEmpty
Waits for the managed component'sjava.awt.EventQueue
to stay empty. The timeout for this wait is EventDispatcher.WaitQueueEmptyTimeout.- Parameters:
emptyTime
- The time that the event queue has to stay empty to avoid a TimeoutExpiredException.output
- Output to print exception intotimeouts
- A collection of timeout assignments.- Throws:
TimeoutExpiredException
- See Also:
-
waitQueueEmpty
public static void waitQueueEmpty(long emptyTime) Waits for the managed component'sjava.awt.EventQueue
to stay empty. Uses default output and timeouts. The timeout for this wait is EventDispatcher.WaitQueueEmptyTimeout.- Parameters:
emptyTime
- The time that the event queue has to stay empty to avoid a TimeoutExpiredException.- Throws:
TimeoutExpiredException
- See Also:
-
getModifiersString
Get a string representation for key modifiers. Used to print trace.- Parameters:
modifiers
- Bit mask of keyboard event modifiers.- Returns:
- a string representation for the keyboard event modifiers.
-
getKeyDescription
Returns a string representation for a keyboard event. Used to print trace.- Parameters:
keyCode
- Key code (KeyEvent.VK_*
value)- Returns:
- the KeyEvent field name.
-
getMouseButtonDescription
Returns a mouse button string representation. Used to print trace.- Parameters:
button
- Mouse button (InputEvent.BUTTON1/2/3_MASK
value).- Returns:
- InputEvent field name.
-
performInit
public static void performInit() -
checkComponentUnderMouse
public void checkComponentUnderMouse(boolean yesOrNo) Wait (or not) for the mouse to move over a Java component before pressing. This option is relevant when usingjava.awt.Robot
to generate mouse events. If a mouse press occurs at a position not occupied by a known Java component then aNoComponentUnderMouseException
will be thrown.- Parameters:
yesOrNo
- iftrue
then the test system will wait for the mouse to move over a Java component before pressing. therwise, mouse presses can take place anywhere on the screen.
-
setOutput
Defines print output streams or writers.- Specified by:
setOutput
in interfaceOutputable
- Parameters:
out
- Identify the streams or writers used for print output.- See Also:
-
getOutput
Returns print output streams or writers.- Specified by:
getOutput
in interfaceOutputable
- Returns:
- an object that contains references to objects for printing to output and err streams.
- See Also:
-
setTimeouts
Defines current timeouts.- Specified by:
setTimeouts
in interfaceTimeoutable
- Parameters:
timeouts
- A collection of timeout assignments.- See Also:
-
getTimeouts
Return current timeouts.- Specified by:
getTimeouts
in interfaceTimeoutable
- Returns:
- the collection of current timeout assignments.
- See Also:
-
setDispatchingModel
public void setDispatchingModel(int m) Defines dispatching model.- Parameters:
m
- New model value.- See Also:
-
getDispatchingModel
public int getDispatchingModel()Gets the dispatching model value.- Returns:
- the model value.
- See Also:
-
dispatchEvent
DispatchesAWTEvent
to component passed in constructor. If(getDispatchingModel invalid input: '&' JemmyProperties.QUEUE_MODEL_MASK) == 0
dispatched event directly, otherwise usesjavax.swing.SwingUtilities.invokeAndWait(Runnable)
- Parameters:
event
- AWTEvent instance to be dispatched.- Throws:
ComponentIsNotVisibleException
ComponentIsNotFocusedException
-
dispatchMouseEvent
public void dispatchMouseEvent(int id, int mods, int clickCount, int x, int y, boolean popup) Dispatches a MouseEvent.- Parameters:
id
-MouseEvent.MOUSE_*
valuemods
-InputEvent.MOUSE1/2/3_BUTTON
| (modiviers value)clickCount
- Click countx
- Horizontal click point coordinate.y
- vertical click point coordinate.popup
- Difines if mouse event is popup event.- See Also:
-
dispatchMouseEvent
public void dispatchMouseEvent(int id, int mods, int clickCount, boolean popup) Dispatches MouseEvent at the center of component.- Parameters:
id
-MouseEvent.MOUSE_*
valuemods
-InputEvent.MOUSE1/2/3_BUTTON
| (modiviers value)clickCount
- Click countpopup
- Difines if mouse event is popup event.- See Also:
-
dispatchWindowEvent
public void dispatchWindowEvent(int id) Dispatches WindowEvent.- Parameters:
id
-WindowEvent.WINDOW_*
value- See Also:
-
dispatchKeyEvent
public void dispatchKeyEvent(int id, int mods, int keyCode) Dispatches KeyEvent.- Parameters:
id
-KeyEvent.KEY_PRESSED
orKeyEvent.KEY_RELEASED
value.mods
- Modifiers.keyCode
- Key code,- See Also:
-
dispatchKeyEvent
public void dispatchKeyEvent(int id, int mods, int keyCode, char keyChar) Dispatches KeyEvent.- Parameters:
id
-KeyEvent.KEY_TYPED
value.mods
- Modifiers.keyCode
- Key code,keyChar
- Char to be tiped- See Also:
-
waitForIdle
public void waitForIdle()Waits until all events currently on the event queue have been processed. -
getAbsoluteX
protected int getAbsoluteX(int x) Bind horizontal relative cursor coordinate to screen coordinate.- Parameters:
x
- Relative coordinate- Returns:
- Absolute coordinate
-
getAbsoluteY
protected int getAbsoluteY(int y) Bind vertical relative cursor coordinate to screen coordinate.- Parameters:
y
- Relative coordinate- Returns:
- Absolute coordinate
-
delayRobot
public void delayRobot(long time) Delays robot.- Parameters:
time
- Time to dalay robot for.
-
robotMoveMouse
public void robotMoveMouse(int x, int y) Moves mouse by robot.- Parameters:
x
- Component relative horizontal coordinate.y
- Component relative vertical coordinate.- Throws:
ComponentIsNotVisibleException
-
robotPressMouse
public void robotPressMouse(int button, int modifiers) Press mouse button by robot.- Parameters:
button
- Mouse button (InputEvent.MOUSE1/2/3_BUTTON value)modifiers
- Modifiers- Throws:
ComponentIsNotVisibleException
-
robotPressMouse
public void robotPressMouse(int button) Press mouse button with 0 modifiers.- Parameters:
button
- Mouse button (InputEvent.MOUSE1/2/3_BUTTON
value)- See Also:
-
robotReleaseMouse
public void robotReleaseMouse(int button, int modifiers) Releases mouse button by robot.- Parameters:
button
- Mouse button (InputEvent.MOUSE1/2/3_BUTTON
value)modifiers
- Modifiers- Throws:
ComponentIsNotVisibleException
-
robotReleaseMouse
public void robotReleaseMouse(int button) Releases mouse button with 0 modifiers.- Parameters:
button
- Mouse button (InputEvent.MOUSE1/2/3_BUTTON
value)- See Also:
-
robotPressKey
public void robotPressKey(int keyCode, int modifiers) Press a key usingjava.awt.Robot
.- Parameters:
keyCode
- Key (KeyEvent.VK_*
value)modifiers
- Mask of KeyEvent modifiers.- Throws:
ComponentIsNotVisibleException
ComponentIsNotFocusedException
-
robotPressKey
public void robotPressKey(int keyCode) Press key with no modifiers usingjava.awt.Robot
.- Parameters:
keyCode
- Key (KeyEvent.VK_*
value)- See Also:
-
robotReleaseKey
public void robotReleaseKey(int keyCode, int modifiers) Releases key by robot.- Parameters:
keyCode
- Key (KeyEvent.VK_*
value)modifiers
- Mask of KeyEvent modifiers.- Throws:
ComponentIsNotVisibleException
ComponentIsNotFocusedException
-
robotReleaseKey
public void robotReleaseKey(int keyCode) Releases key with 0 modifiers.- Parameters:
keyCode
- Key (KeyEvent.VK_*
value)- See Also:
-
invokeMethod
public Object invokeMethod(String method_name, Object[] params, Class[] params_classes) throws InvocationTargetException, IllegalStateException, NoSuchMethodException, IllegalAccessException Invokes component method throughSwingUtilities.invokeAndWait(Runnable)
.- Parameters:
method_name
- Name of a method to be invokedparams
- Method paramsparams_classes
- Method params' classes- Returns:
- an Object - methods result.
- Throws:
IllegalAccessException
NoSuchMethodException
IllegalStateException
InvocationTargetException
- See Also:
-
getField
public Object getField(String field_name) throws InvocationTargetException, IllegalStateException, NoSuchFieldException, IllegalAccessException Gets component field value throughSwingUtilities.invokeAndWait(Runnable)
.- Parameters:
field_name
- Name of a field- Returns:
- an Object - field value
- Throws:
IllegalAccessException
IllegalStateException
InvocationTargetException
NoSuchFieldException
- See Also:
-
setField
public void setField(String field_name, Object newValue) throws InvocationTargetException, IllegalStateException, NoSuchFieldException, IllegalAccessException Sets component field value throughSwingUtilities.invokeAndWait(Runnable)
.- Parameters:
field_name
- Name of a fieldnewValue
- New field value- Throws:
IllegalAccessException
IllegalStateException
InvocationTargetException
NoSuchFieldException
- See Also:
-
invokeExistingMethod
public Object invokeExistingMethod(String method_name, Object[] params, Class[] params_classes, TestOut out) Invokes component method throughSwingUtilities.invokeAndWait(Runnable)
. and catch all exceptions.- Parameters:
method_name
- Name of a method to be invokedparams
- Method paramsparams_classes
- Method params' classesout
- TestOut instance to print exceptions stack trace to.- Returns:
- an Object - method result
- See Also:
-
getExistingField
Gets component field value throughSwingUtilities.invokeAndWait(Runnable)
. and catch all exceptions.- Parameters:
field_name
- Name of a fieldout
- TestOut instance to print exceptions stack trace to.- Returns:
- an Object - fields value
- See Also:
-
setExistingField
Sets component field value throughSwingUtilities.invokeAndWait(Runnable)
. and catch all exceptions.- Parameters:
field_name
- Name of a fieldnewValue
- New field valueout
- TestOut instance to print exceptions stack trace to.- See Also:
-
invokeExistingMethod
Invokes component method throughSwingUtilities.invokeAndWait(Runnable)
. and catch all exceptions. Exceptions are printed into TestOut object defined by setOutput(TestOut) method.- Parameters:
method_name
- Name of a method to be invokedparams
- Method paramsparams_classes
- Method params' classes- Returns:
- an Object - method result
- See Also:
-
getExistingField
Gets component field value throughSwingUtilities.invokeAndWait(Runnable)
. and catch all exceptions. Exceptions are printed into TestOut object defined by setOutput(TestOut) method.- Parameters:
field_name
- Name of a field- Returns:
- an Object - fields value
- See Also:
-
setExistingField
Sets component field value throughSwingUtilities.invokeAndWait(Runnable)
. and catch all exceptions. Exceptions are printed into TestOut object defined by setOutput(TestOut) method.- Parameters:
field_name
- Name of a fieldnewValue
- New field value- See Also:
-