Class brsVisitor.BRSDisplayAdapter


public class BRSDisplayAdapter
extends Object
This class acts as an MVC view adapter for a BiTree to display the tree on a JComponent. The JComponent is assumed to have a null layout. The display process clears the JComponent of all other components and then lays out JLabels on it where each label's text is the String representation of a node's data. Note: If a JScrollPane is used to hold the JComponent, it must be validated after running showTree() method.


Variable Index

 o colOffset
The offset from the left in pixels of the entire display
 o container
The JComponent upon which the BiTree is to be shown
 o displayVisitor
An anonymous inner class IBRSAlgo that is used to traverse the BiTree, calling the showData() method at every non-null node
 o getMaxDepthVisitor
 o labelHeight
The height of the label to make
 o labelWidth
The width of the label to make
 o maxDepth
The maximum depth, in rows, of the tree to be displayed
 o rowOffset
The offset from the top in pixels of the entire display

Constructor Index

 o BRSDisplayAdapter (JComponent, int, int)
Constructor for the class that defaults the label width x height to 100 x 30
 o BRSDisplayAdapter (JComponent, int, int, int, int)
Constructor for the class that also allows the label width and height to be specified

Method Index

 o displayTree (BiTree)
Displays a BiTree on a JComponent by clearing the JComponent of all other components and then laying out a JLabel for every non-null node of the tree
 o getBounds (RowColIdx)
Calculates the bounds of the label for a node, given its row and column index
 o showData (Object, RowColIdx)
Creates a JLabel whose text is the String representation of the supplied data

Variables

 o rowOffset
private int rowOffset = 0
The offset from the top in pixels of the entire display.

 o colOffset
private int colOffset = 0
The offset from the left in pixels of the entire display.

 o labelWidth
private int labelWidth = 100
The width of the label to make.

 o labelHeight
private int labelHeight = 30
The height of the label to make.

 o maxDepth
private int maxDepth = 0
The maximum depth, in rows, of the tree to be displayed. This quantitiy is calculated each time the tree is displayed.

 o container
private JComponent container
The JComponent upon which the BiTree is to be shown.

 o displayVisitor
private IVisitor displayVisitor = new IVisitor() {

            public Object emptyCase(BiTree host, Object param)
            {
              return (null);
            }

            public final Object nonEmptyCase(BiTree host, Object param)
            {
              showData( host.getRootDat(), (RowColIdx) param);
              host.getLeftSubTree().execute(this, ((RowColIdx) param).nextLeft());
              host.getRightSubTree().execute(this,((RowColIdx) param).nextRight());
              return(null);
            }

        }
An anonymous inner class IBRSAlgo that is used to traverse the BiTree, calling the showData() method at every non-null node.

 o getMaxDepthVisitor
private BRSGetMaxDepthVisitor getMaxDepthVisitor = new BRSGetMaxDepthVisitor()

Constructors

 o BRSDisplayAdapter
private  BRSDisplayAdapter(JComponent container, int rowOffset, int colOffset)
Constructor for the class that defaults the label width x height to 100 x 30

Parameters:
container - The JComponent to display the BiTree on.
rowOffset - The vertical offset of the display in pixels.
colOffset - The horizontal offset of the display in pixels.
 o BRSDisplayAdapter
public  BRSDisplayAdapter(JComponent container, int rowOffset, int colOffset, int labelWidth, int labelHeight)
Constructor for the class that also allows the label width and height to be specified..

Parameters:
container - The JComponent to display the BiTree on.
rowOffset - The vertical offset of the display in pixels.
colOffset - The horizontal offset of the display in pixels.
labelWidth - The width of the labels
labelHeight - The hieght of the labels.

Methods

 o getBounds
private Rectangle getBounds(RowColIdx rowColIdx)
Calculates the bounds of the label for a node, given its row and column index.

Parameters:
rowColIdx - The row and column index of the node.
Returns:
A bounds Rectangle object.
 o showData
private void showData(Object data, RowColIdx rowColIdx)
Creates a JLabel whose text is the String representation of the supplied data. The bounds of the label are calculated from the supplied RowColIdx.

Parameters:
data - The data to be displayed.
rowColIdx - The row and column index of the data's node.
 o displayTree
public void displayTree(BiTree tree)
Displays a BiTree on a JComponent by clearing the JComponent of all other components and then laying out a JLabel for every non-null node of the tree.

Parameters:
tree -