All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----java.awt.Component | +----java.awt.Container | +----java.awt.Panel | +----de.unikl.AWTNode.cfContainer | +----de.unikl.AWTNode.NodeContainer
i) A leaf is a tree ii) or it is a inner node which sons a "part"-treesIf 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 binIn this example the directory [root] contains the sub-directories
usr,var,tmp,binIf 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,binIt 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 hidedThe 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.
stdNode description checkThe 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.
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)
public NodeContainer(Component description)
public final Component add(Component comp)
public final Component add(String name, Component comp)
public final Component add(Component comp, int pos)
public final void remove(Component comp)
public final void removeAll()
public final void setRootCheck(boolean lpaint)
public final boolean getRootCheck()
public final ConnectionLinePoints getConnectionLinePoints()
public final Component getDescription()
public final void setDescription(Component newDesc)
public NodeContainer getSonNodeContainer(pmCheckbox check)
public pmCheckbox getCheckComponent()
public void setState(boolean check)
public boolean getState()
public NodeContainer getRoot()
public void showSons()
public void hideSons()
public void validate()
public void paint(Graphics g)
public void itemStateChanged(ItemEvent e)
public String toString()
All Packages Class Hierarchy This Package Previous Next Index