prolog.treeview
Class Tree

java.lang.Object
  |
  +--prolog.treeview.Tree

public class Tree
extends java.lang.Object

implements a tree class able to layout and paint a amount of nodes. the tree must me contained in a container


Field Summary
protected  javax.swing.JComponent container
          the container containing this tree
protected  java.awt.Rectangle rect
          the position this tree has in the containing container
protected  RootNode root
          the root node of this tree
 
Constructor Summary
Tree()
          constructor
 
Method Summary
 void doLayout()
          layouts this tree
protected  void doLayout(Node n, int x, int y)
          the recursive layout method
 boolean exportXml(java.lang.String filename)
          saves the tree as xml
 void genXml(java.io.Writer out)
          generates xml representing this object
protected  int getChildsWidth(Node n)
          returns the width of the childs of this node
 javax.swing.JComponent getContainer()
          returns the container which contains this tree
 java.awt.Rectangle getPosition()
          returns the position the tree has in container
 java.awt.Dimension getPreferredSize()
          returns the preferred size of this tree
protected  int getRecursiveWidth(Node n)
          returns recusive the total width of the given node and all of its child nodes
protected  int getRecursiveWidth(Node n, int layer)
          returns recusive the total width of the given node and all of its child nodes
 RootNode getRoot()
          returns the root of this tree
 void paint(java.awt.Graphics g)
          paints this tree
 void paintLines(java.awt.Graphics2D g)
          paints all lines between the nodes
protected  void paintNodes(java.awt.Graphics2D g)
          paints all nodes
 void repaint()
          invokes the containers repaint method
 void setContainer(javax.swing.JComponent c)
          sets the container which contains this tree
 void setPosition(java.awt.Rectangle r)
          sets the position the tree has in the container
 void setRoot(RootNode node)
          sets the root of this tree
 void updateTree()
          layouts the tree and invokes repaint
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

root

protected RootNode root
the root node of this tree

rect

protected java.awt.Rectangle rect
the position this tree has in the containing container

container

protected javax.swing.JComponent container
the container containing this tree
Constructor Detail

Tree

public Tree()
constructor
Method Detail

setPosition

public void setPosition(java.awt.Rectangle r)
sets the position the tree has in the container

getPosition

public java.awt.Rectangle getPosition()
returns the position the tree has in container

setContainer

public void setContainer(javax.swing.JComponent c)
sets the container which contains this tree

getContainer

public javax.swing.JComponent getContainer()
returns the container which contains this tree

repaint

public void repaint()
invokes the containers repaint method

setRoot

public void setRoot(RootNode node)
sets the root of this tree

getRoot

public RootNode getRoot()
returns the root of this tree
Returns:
the root node of this tree

paintNodes

protected void paintNodes(java.awt.Graphics2D g)
paints all nodes
Parameters:
g - - the graphics context to paint in

paintLines

public void paintLines(java.awt.Graphics2D g)
paints all lines between the nodes
Parameters:
g - - the graphics context to paint in

paint

public void paint(java.awt.Graphics g)
paints this tree
Parameters:
g - - the graphics context to paint in

doLayout

public void doLayout()
layouts this tree

updateTree

public void updateTree()
layouts the tree and invokes repaint

doLayout

protected void doLayout(Node n,
                        int x,
                        int y)
the recursive layout method
Parameters:
n - - the current node
x - - the middle of the new node
y - - the new y

getChildsWidth

protected int getChildsWidth(Node n)
returns the width of the childs of this node

getRecursiveWidth

protected int getRecursiveWidth(Node n)
returns recusive the total width of the given node and all of its child nodes

getRecursiveWidth

protected int getRecursiveWidth(Node n,
                                int layer)
returns recusive the total width of the given node and all of its child nodes

genXml

public void genXml(java.io.Writer out)
            throws java.io.IOException
generates xml representing this object
Parameters:
out - - the writer where to append the xml
Throws:
java.io.IOException -  

exportXml

public boolean exportXml(java.lang.String filename)
saves the tree as xml
Parameters:
filename - - the filename to save the file

getPreferredSize

public java.awt.Dimension getPreferredSize()
returns the preferred size of this tree