public class SwingMapping extends Object
This mapping is build upon the name property: starting from the root,
all elements in the component tree that have a a non-null name property
(all their parents must also have a non-null name property!) are
mapped to name by concatenating the names of all components on the
path separated with a "/".
As a special case, a Viewport inside a ScrollPane is silently skipped
After a mapping was constructed, components can be accessed by name, e.g.
"myPanel/subPanel/okButton".
As a very useful feature ".." can be used inside a name to navigate to another component, e.g. "myPanel/subPanel/okButton/../textField" can be used to access a the component "textField" that is also a child of "subPanel". With this feature, it is very easy to access the "needed" components inside an ActionEvent callback. In addition to the hierarcical namespace a flat (but not uniq) namespace is provided.
| Modifier and Type | Method and Description |
|---|---|
static SwingMapping |
createMapping(JComponent pRoot)
This factory method creates a new SwingMapping, starting from the handed
root component.
|
JComponent |
getByShortName(String pName)
This method returns null or the component matching the handed
short name.
|
JComponent |
getComponentByName(String pName)
This method returns null or the component matching the handed name
after resolving ".." shortcuts.
|
String |
getNameByComponent(JComponent pComponent)
This method returns the full qualified name of the handed component.
|
String |
toString()
toString() generates a line-by-line description of all mappings,
separated with " = " and containing first the full mapping name
and second the class name of the mapped to object.
|
public static SwingMapping createMapping(JComponent pRoot)
pRoot - the root componentIllegalArgumentException - if the names inside the component are not
uniq or pRoot is nullpublic JComponent getComponentByName(String pName)
pName - component name (may be null), inside the
name all ".."'s are resolved first, so it is o.k. to
use "somePanel/someButton/../someTextField" to get
from any component to any other.IllegalArgumentException - the name is not resolvable due too many ".."'spublic JComponent getByShortName(String pName)
pName - component short name (may be null)public String getNameByComponent(JComponent pComponent)
pComponent - the component we want the name forIllegalArgumentException - if pComponent is not inside the hierarchy
the SwingMapping object was created withpublic String toString()
Copyright © 2017 Jürgen Zeller (privat). All rights reserved.