junit.extensions.awt
Class DefaultComponentFinder

java.lang.Object
  |
  +--junit.extensions.awt.DefaultComponentFinder
All Implemented Interfaces:
ComponentFinder

public class DefaultComponentFinder
extends java.lang.Object
implements ComponentFinder

Basic component lookup implementation.


Constructor Summary
DefaultComponentFinder()
           
DefaultComponentFinder(ComponentFinder parent)
           
 
Method Summary
 void closeWindows()
          Send an explicit window close event to all showing windows.
 boolean componentsMatch(java.awt.Component comp, ComponentReference ref)
          Determine the best we can whether the component is the one referred to by the reference.
 void discardComponent(java.awt.Component comp)
          Discard and no longer reference the given component.
 void disposeWindows()
          Dispose of all available windows, and does not return until they have been disposed of.
 void filterComponent(java.awt.Component comp)
          Don't return the given component in any queries.
 java.awt.Component findActivePopupMenu(java.awt.Component root, java.awt.Component invoker)
          Find the active popup menu invoked by the given component.
 java.awt.Component findComponent(ComponentReference ref)
          Attempt to find the given component.
protected  java.awt.Component findDescendent(java.awt.Component ancestor, ComponentReference ref)
          Return the first component matching the reference's hierarchy.
 java.awt.Component findMenuItemByName(java.awt.Component root, java.lang.String name)
          Look up the first menu item below root with the given title.
 java.awt.Window findWindow(java.lang.String nameOrTitle)
          Return the window with the given name or title.
 java.awt.Window findWindowByName(java.lang.String match)
          Find the first window with the given name.
 java.awt.Window findWindowByTitle(java.lang.String title)
          Find the first window with the given title pattern.
 java.awt.Component getComponentFrame(java.awt.Component comp)
          Return the nearest Frame or Dialog ancestor of the given component.
 java.lang.String getComponentFrameTitle(java.awt.Component comp)
          Return the title of the Frame for the given component, if any.
 java.lang.String getComponentName(java.awt.Component comp)
          Return the component's name (null if it's auto-generated)
 java.awt.Component getComponentParent(java.awt.Component comp)
          Look up the apparent parent of a component.
 java.awt.Component[] getComponents(java.awt.Container c)
          Returns all components below the GUI hierarchy of the given Container, including Windows and MenuElements.
 java.awt.Window getComponentWindow(java.awt.Component comp)
          Return the nearest Window ancestor of the given Component.
 java.awt.EventQueue getEventQueue(java.awt.Component comp)
          Return the AWT event queue for the given component.
 java.awt.Frame[] getFrames()
          Return an array of all available Frames.
 java.lang.String getTag(java.awt.Component comp)
          Return a reasonable identifier for the given component.
 java.lang.Class getTestedClass(ComponentTester tester)
          Return the class tested by the given tester.
 ComponentTester getTester(java.lang.Class forClass)
          Return the tester registered for the given class, chaining up the inheritance tree if necessary.
 ComponentTester getTester(java.awt.Component comp)
          Return the tester registered for the given component's class.
 ComponentTester getTester(ComponentReference ref)
          Return the tester registered for the given component reference's class.
 java.awt.Window[] getWindows()
          Returns the set of all available windows that have not been filtered.
 java.awt.Window[] getWindows(java.awt.Window parent)
          Return all windows owned by the given window.
 boolean isFiltered(java.awt.Component comp)
          Is the given component being filtered?
 void setFilterEnabled(boolean enable)
          Indicate whether to filter component lists.
static boolean stringContainsMatch(java.lang.String regexp, java.lang.String test)
          Return whether there is a match for the given regular expression within the given string.
 boolean stringMatch(java.lang.String regexp, java.lang.String test)
          Return whether the given regular expression matches the given string exactly.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultComponentFinder

public DefaultComponentFinder(ComponentFinder parent)

DefaultComponentFinder

public DefaultComponentFinder()
Method Detail

findComponent

public java.awt.Component findComponent(ComponentReference ref)
                                 throws ComponentNotFoundException
Attempt to find the given component. Use tightest bindings first
Specified by:
findComponent in interface ComponentFinder

findWindowByName

public java.awt.Window findWindowByName(java.lang.String match)
Description copied from interface: ComponentFinder
Find the first window with the given name.
Specified by:
findWindowByName in interface ComponentFinder

findWindowByTitle

public java.awt.Window findWindowByTitle(java.lang.String title)
Description copied from interface: ComponentFinder
Find the first window with the given title pattern.
Specified by:
findWindowByTitle in interface ComponentFinder

findWindow

public java.awt.Window findWindow(java.lang.String nameOrTitle)
Return the window with the given name or title. Attempts to find a named window first, since that search is more restrictive.
Specified by:
findWindow in interface ComponentFinder

findActivePopupMenu

public java.awt.Component findActivePopupMenu(java.awt.Component root,
                                              java.awt.Component invoker)
Description copied from interface: ComponentFinder
Find the active popup menu invoked by the given component.
Specified by:
findActivePopupMenu in interface ComponentFinder

findMenuItemByName

public java.awt.Component findMenuItemByName(java.awt.Component root,
                                             java.lang.String name)
Description copied from interface: ComponentFinder
Look up the first menu item below root with the given title.
Specified by:
findMenuItemByName in interface ComponentFinder

findDescendent

protected java.awt.Component findDescendent(java.awt.Component ancestor,
                                            ComponentReference ref)
Return the first component matching the reference's hierarchy. Assumes the parent reference is only null if the child is a top-most frame. This would be the place to check for appropriate index as well.

getComponentName

public java.lang.String getComponentName(java.awt.Component comp)
Return the component's name (null if it's auto-generated)
Specified by:
getComponentName in interface ComponentFinder

componentsMatch

public boolean componentsMatch(java.awt.Component comp,
                               ComponentReference ref)
Determine the best we can whether the component is the one referred to by the reference.
Specified by:
componentsMatch in interface ComponentFinder

getFrames

public java.awt.Frame[] getFrames()
Return an array of all available Frames.
Specified by:
getFrames in interface ComponentFinder

getWindows

public java.awt.Window[] getWindows(java.awt.Window parent)
Return all windows owned by the given window.
Specified by:
getWindows in interface ComponentFinder

getWindows

public java.awt.Window[] getWindows()
Returns the set of all available windows that have not been filtered.
Specified by:
getWindows in interface ComponentFinder

getComponents

public java.awt.Component[] getComponents(java.awt.Container c)
Returns all components below the GUI hierarchy of the given Container, including Windows and MenuElements.
Specified by:
getComponents in interface ComponentFinder

getComponentParent

public java.awt.Component getComponentParent(java.awt.Component comp)
Look up the apparent parent of a component. Basically makes a menu item's parent be the menu it's in, and the popup menu's parent the menu or component that spawned it.
Specified by:
getComponentParent in interface ComponentFinder

getComponentWindow

public java.awt.Window getComponentWindow(java.awt.Component comp)
Return the nearest Window ancestor of the given Component.
Specified by:
getComponentWindow in interface ComponentFinder

getComponentFrameTitle

public java.lang.String getComponentFrameTitle(java.awt.Component comp)
Return the title of the Frame for the given component, if any.
Specified by:
getComponentFrameTitle in interface ComponentFinder

getComponentFrame

public java.awt.Component getComponentFrame(java.awt.Component comp)
Return the nearest Frame or Dialog ancestor of the given component.
Specified by:
getComponentFrame in interface ComponentFinder

getEventQueue

public java.awt.EventQueue getEventQueue(java.awt.Component comp)
Description copied from interface: ComponentFinder
Return the AWT event queue for the given component.
Specified by:
getEventQueue in interface ComponentFinder

getTag

public java.lang.String getTag(java.awt.Component comp)
Return a reasonable identifier for the given component.
Specified by:
getTag in interface ComponentFinder

getTester

public ComponentTester getTester(ComponentReference ref)
Return the tester registered for the given component reference's class.
Specified by:
getTester in interface ComponentFinder

getTester

public ComponentTester getTester(java.awt.Component comp)
Return the tester registered for the given component's class.
Specified by:
getTester in interface ComponentFinder

getTester

public ComponentTester getTester(java.lang.Class forClass)
                          throws java.lang.IllegalArgumentException
Return the tester registered for the given class, chaining up the inheritance tree if necessary.
Specified by:
getTester in interface ComponentFinder

getTestedClass

public java.lang.Class getTestedClass(ComponentTester tester)
Return the class tested by the given tester.
Specified by:
getTestedClass in interface ComponentFinder

isFiltered

public boolean isFiltered(java.awt.Component comp)
Description copied from interface: ComponentFinder
Is the given component being filtered?
Specified by:
isFiltered in interface ComponentFinder

filterComponent

public void filterComponent(java.awt.Component comp)
Description copied from interface: ComponentFinder
Don't return the given component in any queries. Makes the given component unavailable unless filtering is turned off.
Specified by:
filterComponent in interface ComponentFinder

discardComponent

public void discardComponent(java.awt.Component comp)
Discard and no longer reference the given component.
Specified by:
discardComponent in interface ComponentFinder

setFilterEnabled

public void setFilterEnabled(boolean enable)
Description copied from interface: ComponentFinder
Indicate whether to filter component lists.
Specified by:
setFilterEnabled in interface ComponentFinder

closeWindows

public void closeWindows()
Send an explicit window close event to all showing windows. Note that this is not guaranteed to actually make the window go away.
Specified by:
closeWindows in interface ComponentFinder

disposeWindows

public void disposeWindows()
Dispose of all available windows, and does not return until they have been disposed of.
Specified by:
disposeWindows in interface ComponentFinder

stringContainsMatch

public static boolean stringContainsMatch(java.lang.String regexp,
                                          java.lang.String test)
Return whether there is a match for the given regular expression within the given string.

stringMatch

public boolean stringMatch(java.lang.String regexp,
                           java.lang.String test)
Return whether the given regular expression matches the given string exactly.
Specified by:
stringMatch in interface ComponentFinder