Class NestedComponents
- java.lang.Object
-
- org.flexdock.util.NestedComponents
-
public class NestedComponents extends java.lang.Object
This is a utility class for small, short-lived object instances used to find nestedComponents
. It models a relationship between nestedComponents
within an AWTContainer
hierarchy such that, given a startingComponent
from which to search, it will find twoComponents
nested within each other of specific class types. The "deeper" component will be a descendent of the "parent" component.For example, given a
JTextField
within a content frame, the application logic may need to check to see if the text field resides within a certain application-specific container set. Perhaps allJTables
embedded withinJSplitPanes
are significant within the particular application. Thefind(Component searchSrc, Class childClass, Class parentClass)
method on this class will be able to return aNestedComponents
instance indicating whether the specified text field resides within aJTable
that is embedded within aJSplitPane
.Although perhaps a bit contrived, this example shows a generic use for this class. The FlexDock framework itself has a particular interest in
Dockable
components that are embedded withinDockingPorts
, especially during drag operations. As aDockable
is dragged over anDockingPort
, this class allows the framework to determine with a single object instance anyDockables
currently embedded within the targetDockingPort
, starting with the deepestComponent
at the current mouse point during the drag.This classes' member fields are
public
and may be both accessed and modified by external code as needed within their particular usage context. This is by design for ease of use within the FlexDock framework. Consequently, instances of this class should only be used for short-lived operations. Since its member fields may be modified publicly, instances of this class should not be cached, nor should its member values be indexed as they are subject to arbitrary changes over the long term.- Author:
- Christopher Butler
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
Returnstrue
if the specifiedObject
is aNestedComponents
instance and all shares all of the same field references (==) as thisNestedComponents
for fieldsearchSrc
,child
, andparent
.static NestedComponents
find(java.awt.Component searchSrc, java.lang.Class childClass, java.lang.Class parentClass)
Creates and returns a newNestedComponents
instance, searching the parentContainer
hierarcy of the specifiedsearchSrc
for an ancestor of typechildClass
and a more senior ancestor of typeparentClass
.int
hashCode()
Overridden to match theequals()
method.boolean
isFull()
Returnstrue
if bothchild
andparent
fields are non-null
;false
otherwise.
-
-
-
Method Detail
-
find
public static NestedComponents find(java.awt.Component searchSrc, java.lang.Class childClass, java.lang.Class parentClass)
Creates and returns a newNestedComponents
instance, searching the parentContainer
hierarcy of the specifiedsearchSrc
for an ancestor of typechildClass
and a more senior ancestor of typeparentClass
.If either
searchSrc
,childClass
, orparentClass
isnull
, this method returnsnull
.If
searchSrc
is an instanceofchildClass
, then thechild
field on the resultingNestedComponents
will be equal (==) to thesearchSrc
field. IfsearchSrc
is an instanceofparentClass
, then theparent
field on the resultingNestedComponents
will be equal (==) to thesearchSrc
field. If an instance ofparentClass
is found beforechildClass
, this the resultingNestedComponents
instance will have anull
child
field.- Parameters:
searchSrc
- theComponent
from which to start searching for parentContainers
.childClass
- theClass
of the desired "child"Component
parentClass
- theClass
of the desired "parent"Component
- Returns:
- a new
NestedComponents
instance based upon the specified parameters.
-
isFull
public boolean isFull()
Returnstrue
if bothchild
andparent
fields are non-null
;false
otherwise.- Returns:
true
if bothchild
andparent
fields are non-null
;false
otherwise.
-
hashCode
public int hashCode()
Overridden to match theequals()
method.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- a hash code value for this object.
- See Also:
equals(Object)
-
equals
public boolean equals(java.lang.Object obj)
Returnstrue
if the specifiedObject
is aNestedComponents
instance and all shares all of the same field references (==) as thisNestedComponents
for fieldsearchSrc
,child
, andparent
.- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- theObject
to test for equality- Returns:
true
if the specifiedObject
is "equal" to thisNestedComponents
instance;false
otherwise.
-
-