|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object abbot.util.AWTFixtureHelper
public class AWTFixtureHelper
Provides various facilities for setting up, using, and tearing down a test involving UI components. Handles standardized AWTEvent logging and catching exceptions on the AWT event dispatch thread (EDT). This class should be used at setup and teardown of your chosen fixture.
ComponentTestFixture
,
StepRunner
Field Summary | |
---|---|
static int |
EVENT_GENERATION_DELAY
Typical delay to wait for a robot event to be translated into a Java event. |
static int |
POPUP_DELAY
|
static int |
WINDOW_DELAY
|
Constructor Summary | |
---|---|
AWTFixtureHelper()
|
|
AWTFixtureHelper(Hierarchy hierarchy)
Create an instance of AWTFixtureHelper which makes a snapshot of the current VM state. |
Method Summary | |
---|---|
void |
dispose()
Dispose all windows created during this object's lifetime and restore the previous system/UI state, to the extent possible. |
protected void |
disposeAll()
|
void |
disposeWindow(Window w)
Synchronous, safe dispose of a window. |
Throwable |
getEventDispatchError()
Returns the last exception thrown on the event dispatch thread, or null if no such exception has been thrown. |
long |
getEventDispatchErrorTime()
Returns the time of the last exception thrown on the event dispatch thread. |
Hierarchy |
getHierarchy()
|
Robot |
getRobot()
|
WindowTracker |
getWindowTracker()
|
void |
hideWindow(Window w)
Synchronous, safe hide of a window. |
void |
installPopup(Component invoker,
JPopupMenu popup)
Install the given popup on the given component. |
void |
invokeAndWait(Runnable runnable)
Convenience for getRobot().invokeAndWait(Runnable) . |
void |
invokeLater(Runnable runnable)
Convenience for getRobot().invokeLater(Runnable) . |
boolean |
isShowing(String id)
Returns whether a Component is showing. |
boolean |
isShowing(String id,
ComponentFinder finder)
Same as isShowing(String) , but uses the given
ComponentFinder to do the lookup. |
void |
restore()
Restore the state that was preserved when this object was created. |
void |
setModifiers(int modifiers,
boolean pressed)
Convenience method to set key modifiers. |
Frame |
showFrame(Component comp)
This method should be invoked to display the component under test. |
Frame |
showFrame(Component comp,
Dimension size)
This method should be invoked to display the component under test, when a specific size of frame is desired. |
Frame |
showFrame(Component comp,
Dimension size,
String title)
This method should be invoked to display the component under test, when a specific size of frame is desired. |
Dialog |
showModalDialog(Runnable showAction)
Display a modal dialog and wait for it to show. |
Dialog |
showModalDialog(Runnable showAction,
ComponentFinder finder)
Same as showModalDialog(Runnable) , but provides a custom
ComponentFinder to find the dialog. |
void |
showPopup(JPopupMenu popup,
Component invoker)
Safely install and display a popup in the center of the given component, returning when it is visible. |
void |
showPopup(JPopupMenu popup,
Component invoker,
int x,
int y)
Safely install and display a popup, returning when it is visible. |
void |
showWindow(Window w)
Safely display a window with proper EDT synchronization. |
void |
showWindow(Window w,
Dimension size)
Safely display a window with proper EDT synchronization. |
void |
showWindow(Window w,
Dimension size,
boolean pack)
Safely display a window with proper EDT synchronization. |
void |
waitForWindow(Window w,
boolean visible)
Return when the window is ready for input or times out waiting. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int EVENT_GENERATION_DELAY
public static final int WINDOW_DELAY
public static final int POPUP_DELAY
Constructor Detail |
---|
public AWTFixtureHelper()
public AWTFixtureHelper(Hierarchy hierarchy)
Method Detail |
---|
public Robot getRobot()
public WindowTracker getWindowTracker()
public Hierarchy getHierarchy()
public Throwable getEventDispatchError()
null
if no such exception has been thrown.
public long getEventDispatchErrorTime()
public void setModifiers(int modifiers, boolean pressed)
Robot.setModifiers(int,boolean)
or
Robot.keyPress(int)
, since this method's effects will be
automatically undone at the end of the test. If you use the
Robot
methods, you must remember to release any keys pressed
during the test.
modifiers
- mask indicating which modifier keys to usepressed
- whether the modifiers should be in the pressed state.protected void disposeAll()
public void restore()
public void dispose()
public Frame showFrame(Component comp)
Frame
is showing and ready for input.
public Frame showFrame(Component comp, Dimension size)
Frame
is showing and ready for input.
comp
- size
- Desired size of the enclosing frame, or null
to make no explicit adjustments to its size.public Frame showFrame(Component comp, Dimension size, String title)
Frame
is showing and ready for input.
comp
- size
- Desired size of the enclosing frame, or null
to make no explicit adjustments to its size.title
- Title of the wrapping framepublic void showWindow(Window w)
Window
is showing and ready for input.
public void showWindow(Window w, Dimension size)
Window
is showing and ready for input.
public void showWindow(Window w, Dimension size, boolean pack)
null
.Modal dialogs may be shown with this method without blocking.
public void waitForWindow(Window w, boolean visible)
w
- public void hideWindow(Window w)
ComponentEvent.COMPONENT_HIDDEN
or
equivalent has been posted) when this method returns. Note that this
will not trigger a
WindowEvent.WINDOW_CLOSING
event; use
WindowTester.actionClose(Component)
if a window manager window close operation is required.
public void disposeWindow(Window w)
WindowEvent.WINDOW_CLOSED
has been
posted) when this method returns.
public void invokeAndWait(Runnable runnable)
getRobot().invokeAndWait(Runnable)
.
public void invokeLater(Runnable runnable)
getRobot().invokeLater(Runnable)
.
public void installPopup(Component invoker, JPopupMenu popup)
public void showPopup(JPopupMenu popup, Component invoker)
public void showPopup(JPopupMenu popup, Component invoker, int x, int y)
public Dialog showModalDialog(Runnable showAction) throws ComponentSearchException
JFileChooser.showOpenDialog(java.awt.Component)
or
JOptionPane.showInputDialog(Object)
, or any
other instance where the dialog contents are not predefined and
displaying the dialog involves anything more than
show()/setVisible(true
(if show()/setVisible(true)
is all
that is required, use the showWindow(Window)
method instead).
The given Runnable
should contain the code which will show the
modal Dialog
(and thus block); it will be run on the event
dispatch thread.
This method will return when a Dialog
becomes visible which
contains the given component (which may be any component which will
appear on the Dialog
), or the standard timeout (10s) is
reached, at which point a RuntimeException
will be thrown.
For example,
final Frame parent = ...;
Dialog d = showModalDialog(new Runnable) {
public void run() {
JOptionPane.showInputDialog(parent, "Hit me");
}
});
ComponentSearchException
showWindow(java.awt.Window)
,
showWindow(java.awt.Window,java.awt.Dimension)
,
showWindow(java.awt.Window,java.awt.Dimension,boolean)
public Dialog showModalDialog(Runnable showAction, ComponentFinder finder) throws ComponentSearchException
showModalDialog(Runnable)
, but provides a custom
ComponentFinder
to find the dialog.
ComponentSearchException
public boolean isShowing(String id)
public boolean isShowing(String id, ComponentFinder finder)
isShowing(String)
, but uses the given
ComponentFinder to do the lookup.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |