Class de.unikl.AWTNode.NodeContainer
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class de.unikl.AWTNode.NodeContainer

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----java.awt.Panel
                           |
                           +----de.unikl.AWTNode.cfContainer
                                   |
                                   +----de.unikl.AWTNode.NodeContainer

public class NodeContainer
extends cfContainer
The class NodeContainer implements a tree.

What is a tree?

A tree consists of nodes and leafs and edges, edges go from a node to another node (or leaf) A tree has a recusive definition:
           i)  A leaf is a tree
           ii) or it is a inner node which sons a "part"-trees
    
If you put a treeimplemenation into Java-class hierarchy you have to consider a few things.

The main obstacle is that a Container in Java does not have a graphical representation of its own. A container is a component (Container extends component) but all show-methods (or in JDK1.1: setVisible(..)) only shows the components which are contained in a container. But if you look at a typical tree-implemenatation, like a file/directory tree each directory (Container) has a graphical representation of its own. Thus a directory has a graphical Component as representation.

    eg:
    root
      usr
      var
      tmp
      bin
    
In this example the directory [root] contains the sub-directories
          usr,var,tmp,bin
    
If you put this together with the Java-class hierarchy, you need a show-method which:
        1. first displays the [root] component
        2. then displays the sub-container : usr,var,tmp,bin
    
It is important to understand what this mean, because now a few other problems comes up:

     1. What should be done if you call the method setVisible(false)
        (2 possibilities)
        a) only the contained components are hided (usr,var,tmp,bin)
        b) the contained component as well as the own graphical            representation are hided
    
The NodeContainer implements behaviour b.

But you also need a method to realize solution a. If you look at typical tree-implementation (Windows95-explorer) there you see that in front of each directory is a box which shows a + if the directory is "closed" or a - if its "open". The Nodecontainer does the same approach. It displays in front of each node in the tree a CheckComponent. This CheckComponent does the same as the box in the W95-expoloer. This CheckComponent allows a user to select whether only the sons are hided or show and a call to setVisiblie(false) would hide the whole container as you expect it.(in the example root+[rest] are hided)

Up to now all the main aspects are mentioned.The class ConnectionLinePoints is a rather boring class, which only stores lines. A line consists out of two points its startpoint and its endpoint. This class is used by the LayoutManager to store the connectionline between the nodes in a tree. The connectionline is painted in the NodeContainerīs paint method. (The connectionlines are the edges in a tree) Thus the connectionline object if filled in the LayoutManager but painted in the NodeContainer.

The internal implementation

Like in Borderlayout I have used "identifiers" to distinguish between the "kind" of component in the container(NodeConatainer). There are three important identifiers:
      stdNode
      description
      check
    
The identifer "stdNode" describes standard Components. These are the sons in a tree. A component which has the identifer "stdNode" may be a ordinary Component or a NodeContainer. All Components (sons) are added with the method :
    add(Component son)
    
This call as a default the add method:
    add("stdNode",comp)
    
Thus each component gets its identifer "stdNode" as default.

But there are other identifiers like "check" and "description". If a Component has the identifer "check" this means that this component is the CheckComponnent. If you click on a CheckComponent all the sons are hided/shown. Then there is the identifier "description" this is a component which is a grpahical representation for the NodeContainer itsself. In the example the components: root,usr, var... would have the following identifiers:

    ("description",root)
    ("stdNode",usr)
    ("stdNode",var)
    (But there are other elements in the container, described
    later in the text)
    
In general you have not to deal with the identifiers "check" and "description".

Now a few words how a tree is actuallised.In genral you can say that the whole tree has to be layouted if you add another Component to the tree or if you delete (remove) a component. Thus we need a mechanism which lays out all the Node from the root Node of the tree to the leafs. This is done with the method :

    getRoot()
    
Whith this method you get the root node of the whole tree, even if you invoke this call on a leaf in your tree.(internally the method walk up the NodeContainer hierarchy until there is no NodeContainer as a parent)

Now a word about the CheckComponents: It would be nice if the root-Node, which has no NodeContainer as a parent may have a CheckComponent in front of it. In W95 exporer this is possible. If the user click on this checkbox the whole tree is hided. To implement this there is another identifier. Apart from the idntifers "stdNode","description" and "check" there is a new identifier "thischeck". If a Component has the identifier "thischeck" this means, that this Component is the Checkbox for the "root" Node of the tree.

But what happens if you merge a tree with another?

    Answer:
    The Checkbox is transferred between the NodeContainers.
    
    Example:
    
You have a NodeContainer B and a NodeContainer A. And you call:

    A.add(B);
    
Then the "thischeck"-box from NodeContainer B is deleted from the NodeContainer and is inserted in NodeContainer A but with the Identifier "check" Now you call :

    A.remove(B);
    
then the Checkbox for B (stored in A) is removed from A and is insert with the indentifer "thischeck" in B. Thus you can say: If you build a tree the checkboxe are transferred between the NodeContainers. (This approach makes the Layou-process more easily)

Constructor Index

 o NodeContainer(Component)
Constructs a NodeContainer with a description-Component.

Method Index

 o add(Component)
Adds Component to the tree.
 o add(Component, int)
Adds Component as "stdNode" to the NodeConatainer
 o add(String, Component)
Adds Component under the specified classification.
 o getCheckComponent()
returns the Check Component
 o getConnectionLinePoints()
usually only used by the NodeLayout Managers, when the layout the "ConnectionLine" between the Nodes of the tree
 o getDescription()
returns the description Component
 o getRoot()
 o getRootCheck()
returns whether we draw a Checkbox in front of the root-Node or not
 o getSonNodeContainer(pmCheckbox)
returns the correspondig NodeContainer for the given Checkbox.
 o getState()
 o hideSons()
 o itemStateChanged(ItemEvent)
we implement the Standard behavior if a checkBox is clicked
 o paint(Graphics)
PAINTS THE CONNECTION-LINE.The ConnectioLine is stored as a Structure of Points.
 o remove(Component)
We remove first the Component, and if the Component is an instance of NodeContainer, we must also remove the Checkbox and add it to the son under the identifier "thischeck" We add it at the first position!
 o removeAll()
remove all Components from this NodeContainer.
 o setDescription(Component)
sets a new Description Component for this NodeContainer
 o setRootCheck(boolean)
select whether the root-Node draws a Checkbox or not If the NodeContainer has a parent, which is no NodeContainer, then this Nodecontainer is the root-Node of all its "sons" Sometime yout want the Checkbox to this NodeContainer in order to setVisible(false) the whole tree.
 o setState(boolean)
if set to true, alle Components IN the Node get setVisible(false)
 o showSons()
 o toString()
Returns the String representation of this NodeContainer values.
 o validate()
Validates this Container and all of the components contained within it.

Constructors

 o NodeContainer
  public NodeContainer(Component description)
Constructs a NodeContainer with a description-Component. The default Layout is : FileTreeLayout The default value for the Checkbox is : true

Methods

 o add
  public final Component add(Component comp)
Adds Component to the tree. Default specifier is "stdNode".
Overrides:
add in class cfContainer
 o add
  public final Component add(String name,
                             Component comp)
Adds Component under the specified classification. Note: it ist possible to pass a NodeContainer in the Constructor of a NodeContainer.(as a description)
Parameters:
name - the classification ("stdNode","description","check")
comp - the Component to add
Overrides:
add in class cfContainer
 o add
  public final Component add(Component comp,
                             int pos)
Adds Component as "stdNode" to the NodeConatainer
Overrides:
add in class cfContainer
 o remove
  public final void remove(Component comp)
We remove first the Component, and if the Component is an instance of NodeContainer, we must also remove the Checkbox and add it to the son under the identifier "thischeck" We add it at the first position!
Overrides:
remove in class cfContainer
 o removeAll
  public final void removeAll()
remove all Components from this NodeContainer. Note: The Checkboxes are transferred to their "real" owners. (this is because we have to overload the method)
Overrides:
removeAll in class cfContainer
 o setRootCheck
  public final void setRootCheck(boolean lpaint)
select whether the root-Node draws a Checkbox or not If the NodeContainer has a parent, which is no NodeContainer, then this Nodecontainer is the root-Node of all its "sons" Sometime yout want the Checkbox to this NodeContainer in order to setVisible(false) the whole tree. You can select wether this checkbox is drawn with this NodeContainer(corressponding to the Layoutmanager, or not. The default is : true, we draw it
Parameters:
lpaint - true, paints the Checkbox in front of the root-Node
 o getRootCheck
  public final boolean getRootCheck()
returns whether we draw a Checkbox in front of the root-Node or not
 o getConnectionLinePoints
  public final ConnectionLinePoints getConnectionLinePoints()
usually only used by the NodeLayout Managers, when the layout the "ConnectionLine" between the Nodes of the tree
Returns:
s ConnectionLinePoints-object
 o getDescription
  public final Component getDescription()
returns the description Component
 o setDescription
  public final void setDescription(Component newDesc)
sets a new Description Component for this NodeContainer
 o getSonNodeContainer
  public NodeContainer getSonNodeContainer(pmCheckbox check)
returns the correspondig NodeContainer for the given Checkbox. the getParent() method of a checkbox does NOT return the NodeContainer which it belongs to, but the parent NodeContainer! With this method you get the "real" NodeContainer.
Parameters:
Check - the Checkbox for which we determine the NodeContainer
Returns:
s the correspoding NodeContainer we found or null otherwise
 o getCheckComponent
  public pmCheckbox getCheckComponent()
returns the Check Component
 o setState
  public void setState(boolean check)
if set to true, alle Components IN the Node get setVisible(false)
 o getState
  public boolean getState()
Returns:
s the state of the Checkbox(!)
 o getRoot
  public NodeContainer getRoot()
 o showSons
  public void showSons()
 o hideSons
  public void hideSons()
 o validate
  public void validate()
Validates this Container and all of the components contained within it. First all sons are validated, the the NodeContainer is validated.
Overrides:
validate in class Container
See Also:
validate, invalidate
 o paint
  public void paint(Graphics g)
PAINTS THE CONNECTION-LINE.The ConnectioLine is stored as a Structure of Points. The x,y Points gets calculated by the LayoutManager, then it must be drawn in this paint-Method.
Parameters:
g - the specified Graphics window
Overrides:
paint in class Component
See Also:
paint, paintAll
 o itemStateChanged
  public void itemStateChanged(ItemEvent e)
we implement the Standard behavior if a checkBox is clicked
 o toString
  public String toString()
Returns the String representation of this NodeContainer values.
Overrides:
toString in class cfContainer

All Packages  Class Hierarchy  This Package  Previous  Next  Index