Class SwingForester

java.lang.Object
eu.bandm.tools.util.SwingForester
Direct Known Subclasses:
Format.Forester

public abstract class SwingForester extends Object
Makes a swing "tree" gui representation for a graph of Java objects. The gui is clickable/expandable/collapsable.

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(..)/..
  
  • Field Details

    • separatorProperty

      public static final String 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

      public TreeNode growRoot(Object x)
      Central service access point: is called with the entry objevt of the data structure to display.
    • grow

      TreeNode grow(@Opt @Opt TreeNode parent, @Opt @Opt String label, Object x)
      Generate representation for oen single object. If the user-overridden growBranch(TreeNode, String, Object) does not return a (complex) TreeNode, here a simple SwingForester.Leaf will be constructed.
      Parameters:
      parent - the tree node under which the new node will be placed
      label - the visible label text
      x - the object to display, often simply a boxed primitiv value.
    • growBranch

      @Opt protected abstract @Opt TreeNode growBranch(TreeNode parent, @Opt @Opt String label, Object x)
      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 of growCollection(String,TreeNode,String,Collection), growMap(TreeNode,String,Map), or growMultimap(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 placed
      label - the visible label text
      x - 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 starts
      label - name of the field (or more general: association) holding the collection data
      seq - data of the collection.
    • growMap

      TreeNode growMap(@Opt @Opt TreeNode parent, @Opt @Opt String label, Map<?,?> map)
      Service called by the user-defined tree rendering method: Start a subree representing a map.
      Parameters:
      parent - under which node the subtree starts
      label - name of the field (or more general: association) holding the collection data
      map - data of the collection.
    • growMultimap

      TreeNode growMultimap(@Opt @Opt TreeNode parent, @Opt @Opt String label, Multimap<?,?> mmap)
      Service called by the user-defined tree rendering method: Start a subree representing a Multimap.
      Parameters:
      parent - under which node the subtree starts
      label - name of the field (or more general: association) holding the collection data
      mmap - data of the collection.