Class SwingForester
- Direct Known Subclasses:
FormatTree
Usage: A subclass must be defined. Examples can be found in
format/Format.java
and umod/runtime/Swingbrowser
.
The method SwingForester.LazyNode.eval()
overridden by the user decides which data
to show with the node which represents a particular object.
Normally: For fields of primitive
type a SwingForester.Leaf
will be added, showing the name of the field as its
label and some representation of the field value.
For fields of reference type the same may be done, or a SwingForester.LazyNode
,
which will display a subtree. The same for fields of a collection type.
The latter nodes (representing objects and collections) behave lazy: They will call the generation of (again lazy) subnodes not before they are clicked explcitly for expansion. Therefore cyclic data can be displayed: The data can be called "tree" only insofar there is one single entry object. But cycles are not recognized and thus visually marked, but naively displayed by the repetition of the data (on demand).
A separator between label and primitive values can be set by the user via the system property "eu.bandm.tools.umod.runtime.SwingForester.TreeProxy.separator".
Finally the display is initiated by new JTree (mySwingForester.growRoot(myData));
,
see JTree
.
Swing runtime system needs getChildAt(..)/getChildCount()/... | | | v v LeafNode.getChildAt(..)/getChildCount()/.. LazyNode.getChildAt(..)/getChildCount()/.. | +----- user derived class ----+ | : UserNode extends LazyNode: : v : : LazyNode.demand() ----------------------------> UserNode.eval() generate subtrees according to type of the represented data object: | add(..) <--------------------------------------------+ | add representation of a single object reference | V | grow(..) -----------------------> growBranch() | <------------------------ | returns a LazyNode for a complex object display | OR | add a LeafNode for a field with primitive value | | addMAP(..)/addSEQ(..)/.. <---------------------------+ | add a specialized subclass of LazyNode for a field of collection type v growMap(..)/growCollection(..)/..
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
Lazy node which will display sub-nodes on demand.final class
Tree node with no sub-nodes, representing a field of primitive type.class
Common superclass of the two kinds of nodes which are displayed: lazy subtrees or simple leafs. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Property name for the separator between field name and value representation. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
getHTML()
(package private) TreeNode
Generate representation for oen single object.growBranch
(TreeNode parent, @Opt String label, Object x) Generate representation for oen single object.(package private) TreeNode
growCollection
(String constructor, @Opt TreeNode parent, @Opt String label, Collection<?> seq) Service called by the user-defined tree rendering method: Start a subtree.(package private) TreeNode
Service called by the user-defined tree rendering method: Start a subree representing a map.(package private) TreeNode
Service called by the user-defined tree rendering method: Start a subree representing a Multimap.Central service access point: is called with the entry objevt of the data structure to display.void
setHTML
(boolean html) Whether the label text for GUI nodes shall be formatted using HTML mark-up.
-
Field Details
-
separatorProperty
Property name for the separator between field name and value representation.- See Also:
-
-
Constructor Details
-
SwingForester
public SwingForester()
-
-
Method Details
-
setHTML
public void setHTML(boolean html) Whether the label text for GUI nodes shall be formatted using HTML mark-up. In this case all strings to print will be transformed accordingly. Is used whenever a node is created. (Changing it on the fly will result in inconsistent node appearance.) -
getHTML
public boolean getHTML()- See Also:
-
growRoot
Central service access point: is called with the entry objevt of the data structure to display. -
grow
Generate representation for oen single object. If the user-overriddengrowBranch(TreeNode, String, Object)
does not return a (complex) TreeNode, here a simpleSwingForester.Leaf
will be constructed.- Parameters:
parent
- the tree node under which the new node will be placedlabel
- the visible label textx
- the object to display, often simply a boxed primitiv value.
-
growBranch
Generate representation for oen single object. Derived class must differentiated whether the type of the object shall be displayed as a subtree. In this case it will call return the result of one ofgrowCollection(String,TreeNode,String,Collection)
,growMap(TreeNode,String,Map)
, orgrowMultimap(TreeNode,String,Multimap)
. Otherwise it simply returns null, and a graphic leaf node will be generated by the caller =grow(@eu.bandm.tools.annotations.Opt javax.swing.tree.TreeNode,@eu.bandm.tools.annotations.Opt java.lang.String,java.lang.Object)
..- Parameters:
parent
- the tree node under which the new node will be placedlabel
- the visible label textx
- the object to display, often simply a boxed primitiv value.
-
growCollection
TreeNode growCollection(String constructor, @Opt @Opt TreeNode parent, @Opt @Opt String label, Collection<?> seq) Service called by the user-defined tree rendering method: Start a subtree.- Parameters:
constructor
- text of the type constructor for the collection (List, Seq, Set, etc.)parent
- under which node the subtree startslabel
- name of the field (or more general: association) holding the collection dataseq
- data of the collection.
-
growMap
Service called by the user-defined tree rendering method: Start a subree representing a map.- Parameters:
parent
- under which node the subtree startslabel
- name of the field (or more general: association) holding the collection datamap
- data of the collection.
-
growMultimap
Service called by the user-defined tree rendering method: Start a subree representing a Multimap.- Parameters:
parent
- under which node the subtree startslabel
- name of the field (or more general: association) holding the collection datammap
- data of the collection.
-