Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

abbot
Class DefaultComponentFinder  view DefaultComponentFinder download DefaultComponentFinder.java

java.lang.Object
  extended byabbot.DefaultComponentFinder
All Implemented Interfaces:
ComponentFinder

public class DefaultComponentFinder
extends java.lang.Object
implements ComponentFinder

Basic component lookup implementation.


Nested Class Summary
private  class DefaultComponentFinder.ContextTracker
          Whenever we get a window that's on a new event dispatch thread, take note of the thread, since it may correspond to a new event queue and AppContext.
 
Field Summary
private  java.util.WeakHashMap contexts
          Keep track of all app contexts we can.
private  DefaultComponentFinder.ContextTracker contextTracker
           
private static DefaultComponentFinder defaultFinder
           
private  boolean filter
           
private  java.util.WeakHashMap filteredComponents
           
private static int MW_CLASS
           
static int MW_FAILURE
          Match weight corresponding to no possible match.
private static int MW_INDEX
           
private static int MW_INVOKER
           
private static int MW_NAME
           
private static int MW_PARENT
           
static int MW_STRONG_MATCH
          Match weight for a strong match.
private static int MW_TAG
           
private static int MW_TITLE
           
static int MW_WEAK_MATCH
          Match weight for a weak match.
private static int MW_WINDOW
           
private  ComponentFinder parent
          Allow chaining to existing filter sets.
static int POPUP_TIMEOUT
          Timeout for waiting on a popup menu.
 
Fields inherited from interface abbot.ComponentFinder
MATCH_EXACT, MATCH_STRONG, MATCH_WEAK
 
Constructor Summary
private DefaultComponentFinder(ComponentFinder parent)
          Only factory creation is allowed.
 
Method Summary
 void closeWindows()
          Send an explicit window close event to all showing windows.
 boolean componentsMatch(java.awt.Component comp, abbot.script.ComponentReference ref, int type)
          Determine the best we can whether the component is the one referred to by the reference.
 void discardAllComponents()
          Discard all currently available components from any future queries.
 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 invoker)
          Returns the currently active popup menu with the given invoker.
private  java.awt.Component findActivePopupMenu(java.awt.Component root, java.awt.Component invoker)
           
 java.awt.Component findComponent(abbot.script.ComponentReference ref)
          Attempt to find the component corresponding to the given reference among existing, visible components.
private  java.util.HashSet findMatches(java.awt.Component ancestor, abbot.script.ComponentReference ref, int type)
          Return the the set of all components under the given component's hierarchy (inclusive) which match the given reference.
 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)
          Locates a window using the name as the match critia.
 java.awt.Window findWindowByTitle(java.lang.String title)
          Return the first visible window whose title matches the given pattern.
 java.awt.Frame getComponentFrame(java.awt.Component comp)
          Return the component's owning frame.
(package private)  int getComponentMatchWeight(java.awt.Component comp, abbot.script.ComponentReference ref)
          Return a measure of how well the given component matches the given component reference.
 java.lang.String getComponentName(java.awt.Component comp)
          Return the component's name, ensuring that null is returned if the name appears to be 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 getComponentTitledWindow(java.awt.Component comp)
          Return the component's owning frame or dialog.
 java.awt.Window getComponentWindow(java.awt.Component comp)
          Return the nearest Window ancestor of the given Component.
 java.lang.String getComponentWindowTitle(java.awt.Component comp)
          Return the title of the nearest ancestor window with a title.
private  int getExactMatchWeight(abbot.script.ComponentReference ref)
          Return the total weight required for an exact match.
static ComponentFinder getFinder()
          This is the factory method to use unless you already know otherwise :)
static ComponentFinder getFinder(ComponentFinder context)
          This factory method allows the finder to be used where a finder already exists and is filtering components.
private  java.util.ArrayList getFrameList()
          Return all available frames, unfiltered.
 java.awt.Frame[] getFrames()
          Return an array of all available Frames, across all known contexts.
private  java.util.ArrayList getWindowList(java.awt.Window parent, boolean filter, boolean recurse)
          Return all windows owned by the given window, optionally filtered.
 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 that have not been filtered.
private  boolean isAncestorFiltered(java.awt.Component comp)
          Returns whether any window or frame ancestor is filtered.
private  boolean isComponentFiltered(java.awt.Component comp)
           
 boolean isFiltered(java.awt.Component comp)
          Returns true if the component or its Window ancestor is filtered.
 boolean isWindowShowing(java.awt.Window w)
          A window's "showing" flag may be set true before the WINDOW_OPENED event is generated.
 abbot.script.ComponentReference matchComponent(java.awt.Component comp, java.util.Iterator iter, int matchType)
          Find the best match for the given component among the given ComponentReferences.
 void setFilterEnabled(boolean enable)
          Indicate whether to filter component lists.
private  boolean titlesMatch(java.lang.String pattern, java.lang.String actual)
          Return whether the the given title matches the given pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MW_STRONG_MATCH

public static final int MW_STRONG_MATCH
Match weight for a strong match.

See Also:
Constant Field Values

MW_WEAK_MATCH

public static final int MW_WEAK_MATCH
Match weight for a weak match.

See Also:
Constant Field Values

MW_NAME

private static final int MW_NAME
See Also:
Constant Field Values

MW_TAG

private static final int MW_TAG
See Also:
Constant Field Values

MW_PARENT

private static final int MW_PARENT
See Also:
Constant Field Values

MW_INVOKER

private static final int MW_INVOKER
See Also:
Constant Field Values

MW_INDEX

private static final int MW_INDEX
See Also:
Constant Field Values

MW_WINDOW

private static final int MW_WINDOW
See Also:
Constant Field Values

MW_TITLE

private static final int MW_TITLE
See Also:
Constant Field Values

MW_CLASS

private static final int MW_CLASS
See Also:
Constant Field Values

MW_FAILURE

public static final int MW_FAILURE
Match weight corresponding to no possible match.

See Also:
Constant Field Values

POPUP_TIMEOUT

public static int POPUP_TIMEOUT
Timeout for waiting on a popup menu.


filteredComponents

private java.util.WeakHashMap filteredComponents

parent

private ComponentFinder parent
Allow chaining to existing filter sets.


filter

private boolean filter

contexts

private java.util.WeakHashMap contexts
Keep track of all app contexts we can.


contextTracker

private DefaultComponentFinder.ContextTracker contextTracker

defaultFinder

private static DefaultComponentFinder defaultFinder
Constructor Detail

DefaultComponentFinder

private DefaultComponentFinder(ComponentFinder parent)
Only factory creation is allowed.

Method Detail

getFinder

public static ComponentFinder getFinder()
This is the factory method to use unless you already know otherwise :)


getFinder

public static ComponentFinder getFinder(ComponentFinder context)
This factory method allows the finder to be used where a finder already exists and is filtering components. This should only be required in very rare cases like when the script editor needs to test itself.


findComponent

public java.awt.Component findComponent(abbot.script.ComponentReference ref)
                                 throws ComponentNotFoundException,
                                        MultipleComponentsFoundException
Attempt to find the component corresponding to the given reference among existing, visible components.

Specified by:
findComponent in interface ComponentFinder

findWindowByName

public java.awt.Window findWindowByName(java.lang.String match)
Locates a window using the name as the match critia.

Specified by:
findWindowByName in interface ComponentFinder

findWindowByTitle

public java.awt.Window findWindowByTitle(java.lang.String title)
Return the first visible window whose title matches the given 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 invoker)
Returns the currently active popup menu with the given invoker.

Specified by:
findActivePopupMenu in interface ComponentFinder

findActivePopupMenu

private java.awt.Component findActivePopupMenu(java.awt.Component root,
                                               java.awt.Component invoker)

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

findMatches

private java.util.HashSet findMatches(java.awt.Component ancestor,
                                      abbot.script.ComponentReference ref,
                                      int type)
Return the the set of all components under the given component's hierarchy (inclusive) which match the given reference.


titlesMatch

private boolean titlesMatch(java.lang.String pattern,
                            java.lang.String actual)
Return whether the the given title matches the given pattern.


getComponentName

public java.lang.String getComponentName(java.awt.Component comp)
Return the component's name, ensuring that null is returned if the name appears to be auto-generated.

Specified by:
getComponentName in interface ComponentFinder

getExactMatchWeight

private int getExactMatchWeight(abbot.script.ComponentReference ref)
Return the total weight required for an exact match.


matchComponent

public abbot.script.ComponentReference matchComponent(java.awt.Component comp,
                                                      java.util.Iterator iter,
                                                      int matchType)
Description copied from interface: ComponentFinder
Find the best match for the given component among the given ComponentReferences.

Specified by:
matchComponent in interface ComponentFinder

getComponentMatchWeight

int getComponentMatchWeight(java.awt.Component comp,
                            abbot.script.ComponentReference ref)
Return a measure of how well the given component matches the given component reference.


componentsMatch

public boolean componentsMatch(java.awt.Component comp,
                               abbot.script.ComponentReference ref,
                               int type)
Determine the best we can whether the component is the one referred to by the reference. The match may be a strong or a weak one.

Specified by:
componentsMatch in interface ComponentFinder

getFrames

public java.awt.Frame[] getFrames()
Return an array of all available Frames, across all known contexts. NOTE: this assumes that each context has an associated event queue.

Specified by:
getFrames in interface ComponentFinder

getFrameList

private java.util.ArrayList getFrameList()
Return all available frames, unfiltered.


getWindowList

private java.util.ArrayList getWindowList(java.awt.Window parent,
                                          boolean filter,
                                          boolean recurse)
Return all windows owned by the given window, optionally filtered.


getWindows

public java.awt.Window[] getWindows(java.awt.Window parent)
Return all windows owned by the given window that have not been filtered.

Specified by:
getWindows in interface ComponentFinder

getWindows

public java.awt.Window[] getWindows()
Returns the set of all available windows that have not been filtered. This includes frames and windows.

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 (instead of a JPopupMenu), and the popup menu's parent the menu or component that spawned it.

Specified by:
getComponentParent in interface ComponentFinder

getComponentFrame

public java.awt.Frame getComponentFrame(java.awt.Component comp)
Return the component's owning frame. There will always one of these; even a frameless window will have a temporary frame generated for it.

Specified by:
getComponentFrame 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

getComponentWindowTitle

public java.lang.String getComponentWindowTitle(java.awt.Component comp)
Return the title of the nearest ancestor window with a title. If no title is found, return null.

Specified by:
getComponentWindowTitle in interface ComponentFinder

getComponentTitledWindow

public java.awt.Window getComponentTitledWindow(java.awt.Component comp)
Return the component's owning frame or dialog. There will always one of these; even a frameless window will have a temporary frame generated for it.

Specified by:
getComponentTitledWindow in interface ComponentFinder

isComponentFiltered

private boolean isComponentFiltered(java.awt.Component comp)

isAncestorFiltered

private boolean isAncestorFiltered(java.awt.Component comp)
Returns whether any window or frame ancestor is filtered.


isFiltered

public boolean isFiltered(java.awt.Component comp)
Returns true if the component or its Window ancestor is 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

discardAllComponents

public void discardAllComponents()
Description copied from interface: ComponentFinder
Discard all currently available components from any future queries.

Specified by:
discardAllComponents 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

isWindowShowing

public boolean isWindowShowing(java.awt.Window w)
A window's "showing" flag may be set true before the WINDOW_OPENED event is generated.

Specified by:
isWindowShowing in interface ComponentFinder