borland Packages  Class Hierarchy  jbcl.control Package  Index 

TreeControl component

java.lang.Object
   +----java.awt.Component
           +----java.awt.Container
                   +----com.sun.java.swing.JComponent
                           +----com.sun.java.swing.JScrollPane
                                   +----borland.jbcl.view.TreeView
                                           +----borland.jbcl.control.TreeControl

About the TreeControl component

Variables  Constructors  Properties  Methods  Event Listeners

Implements GraphModel, BlackBox, GraphView, Accessible, ScrollPaneConstants, ImageObserver, MenuContainer, Serializable

The TreeControl component displays a hierarchical list of items (nodes), such as the headings of a document, the entries in an index, or the directories and files on a disk. Each node (except the root node, or origin of the tree) has a parent node from which it descends. It may or may not have one or more sibling nodes (descendants from the same parent) and one or more children nodes (descendants from itself). By clicking on the icon beside a node, the user can expand and collapse the associated list of child nodes. Nodes in a TreeControl are of type LinkedTreeNode.

When you add TreeControl to the UI Designer, the control appears as an empty box. You can use the Component Inspector to set many of the attributes of the TreeControl, but you can't actually create the tree at design time. To add data to create a hierarchical tree, you must call the setRoot() method to add the root node for the tree and then call the addChild() methods to add the nodes that descend from the root.

The items property contains the strings displayed in the tree. To remove items, call the remove(), removeChildren(), or removeAllItems() methods.

Note: The removeAll() method has been deprecated in TreeControl. Use the removeAllItems() method instead.

Most of the properties you can set in the Component Inspector come from the TreeView component. Many of them determine how the tree appears. For example, the style property lets you select from a list of platform-specific display styles. The value of the expandByDefault property determines whether the tree is expanded when it first appears. hIndent determines the number of pixels a child node is indented beneath a parent node.

Properties such as hIndent, itemMargins, itemOffset, and vgap, leftMargin, and topMargin determine the spacing used among elements of the tree hierarchy and the box in which it is displayed. snapOrigin and hSnap affect the scrolling behavior of the tree. readOnly determines whether a node can be edited. editInPlace determines whether the user can edit the node within the tree, and autoEdit determines if typing on a selected node begins the editing of that node.

You can show both text and a graphic on each TreeControl node. For example, you can create a basic file-manager directory tree with folder images and strings showing the directories. The default item viewer (SelectableTextItemViewer) won't work for this. You need a CompositeItemViewer made up of a ImageItemViewer (or StateImageItemViewer to show open and closed folders) and a SelectableTextItemViewer. You can use these classes with the TreeControl and LinkedTreeContainer. To use TreeControl this way, first select a TreeControl from the Component Palette and drop it in the UI Designer. Everything else for such composite nodes needs to be coded.

Here is some sample code using a TreeControl:

  TreeControl tree = new TreeControl();

  GraphLocation root = tree.setRoot("Monkey");
                root = tree.setRoot(new Color(234, 234, 22));
                root = tree.setRoot(myCustomClassThingie);

  GraphLocation node = tree.addChild(root, "Monkeys");
                node = tree.addChild(root, new Color(24, 4, 2));
                node = tree.addChild(myCustomClassThingie2);

  GraphLocation found = tree.find("Monkeys");
  System.out.println("This should print out 'Monkeys' = " + tree.get(found));

  System.out.println("A node's value : " + tree.get(node));
  System.out.println("The root : " + tree.get(tree.getRoot()));

To see a more complex code example using a TreeControl, see the JBuilder/samples/borland/samples/jbcl/treecontrol/TreeControl.jpr project.


TreeControl variables

Variables implemented in this class

Variables implemented in borland.jbcl.view.TreeView

Variables implemented in com.sun.java.swing.JComponent

Variables implemented in com.sun.java.swing.JScrollPane

Variables implemented in java.awt.Component

TreeControl constructors

TreeControl properties

*Read-only properties **Write-only properties

Properties implemented in this class

Properties implemented in borland.jbcl.view.TreeView

Properties implemented in com.sun.java.swing.JComponent

Properties implemented in com.sun.java.swing.JScrollPane

Properties implemented in java.awt.Component

Properties implemented in java.awt.Container

Properties implemented in java.lang.Object

TreeControl methods

Methods implemented in this class

Methods implemented in borland.jbcl.view.TreeView

Methods implemented in com.sun.java.swing.JComponent

Methods implemented in com.sun.java.swing.JScrollPane

Methods implemented in java.awt.Component

Methods implemented in java.awt.Container

Methods implemented in java.lang.Object

TreeControl event listeners


TreeControl variables

textureName

  protected String textureName

TreeControl constructors

TreeControl()

  public TreeControl()
Constructs an empty TreeControl. The constructor sets the model property value to be a BasicTreeContainer object. It also sets the item painter and item editor to be used for painting and editing the nodes of the tree. The item painter is a SelectableTextItemPainter object, and the item editor is an ExpandingTextItemEditor object. The view manager is a BasicViewManager. Finally, the value of the selection property is set as a BasicGraphSelection object.


TreeControl properties

items

 public String[] getItems()
 public void setItems(java.lang.String[] items)
The items property is an array of the strings displayed in the tree.

model

 public void setModel(borland.jbcl.model.GraphModel model)

Checks for recursive model creation, then calls super.setModel(model), which is borland.jbcl.view.TreeView.setModel().

root

 public GraphLocation getRoot()

Returns the root node for this graph. Uses getRoot() of the GraphModel.

textureName

 public String getTextureName()
 public void setTextureName(java.lang.String path)
Determines the name of the Image file that is tiled on the background of the control to give the appearance of texture. Specify the file name and directory using the path parameter.

variableSize

 public boolean isVariableSize()

Uses isVariableSize() of the WriteableGraphModel to check whether the tree control can have items inserted.


TreeControl methods

addChild(borland.jbcl.model.GraphLocation, borland.jbcl.model.GraphLocation, java.lang.Object)

  public GraphLocation addChild(borland.jbcl.model.GraphLocation parent, borland.jbcl.model.GraphLocation aheadOf, java.lang.Object data)
Inserts a data object in the chain of children of the specified parent node and returns the location of the inserted object.

Parameters:

parent
The node whose chain of children node the data object is inserted into.
aheadOf
The node the data object is inserted before in the chain of child nodes.
data
The data object added to the tree.

addChild(borland.jbcl.model.GraphLocation, java.lang.Object)

  public GraphLocation addChild(borland.jbcl.model.GraphLocation parent, java.lang.Object data)
Appends a data object as the last child in the chain of children of the specified parent node.

Parameters:

parent
The node whose chain of children the data object is appended to.
data
The data object that is appended to the chain of children.

canSet(borland.jbcl.model.GraphLocation)

  public boolean canSet(borland.jbcl.model.GraphLocation node)
Determines whether the data object at the specified node can be modified. If canSet() returns true, the data object can be modified.

Parameters:

node
The node whose edit state is being determined.

enableModelEvents(boolean)

  public void enableModelEvents(boolean enable)
Determines whether the broadcasting of graph-model events is enabled or disabled.

Parameters:

enable
If enable is true, the broadcasting of graph-model events is enabled and a STRUCTURE_CHANGED event is fired to all graph-model listeners. If it is false, graph-model events are not broadcast.

remove(borland.jbcl.model.GraphLocation)

  public void remove(borland.jbcl.model.GraphLocation node)
Removes a node from the graph.

Parameters:

node
The node to be removed from the graph.

removeAllItems()

  public void removeAllItems()
Removes all items from the tree.

removeChildren(borland.jbcl.model.GraphLocation)

  public void removeChildren(borland.jbcl.model.GraphLocation parent)
Removes all children of the specified node from the tree.

Parameters:

parent
The node whose children are to be removed.

set(borland.jbcl.model.GraphLocation, java.lang.Object)

  public void set(borland.jbcl.model.GraphLocation node, java.lang.Object data)
Sets the specified node to the new data item.

Parameters:

node
The location of the new data item.
data
The new data item.

setRoot(java.lang.Object)

  public GraphLocation setRoot(java.lang.Object data)
Sets the root node of the tree.

touched(borland.jbcl.model.GraphLocation)

  public void touched(borland.jbcl.model.GraphLocation node)

TreeControl event listeners

This component is a source for the following event sets. For information on the standard AWT event sets, see Standard Java events. For information on the JBCL event sets, see Events in JBCL.

action

 public void addActionListener(java.awt.event.ActionListener l)
 public void removeActionListener(java.awt.event.ActionListener l)

ancestor

 public void addAncestorListener(com.sun.java.swing.event.AncestorListener )
 public void removeAncestorListener(com.sun.java.swing.event.AncestorListener )

component

 public synchronized void addComponentListener(java.awt.event.ComponentListener )
 public synchronized void removeComponentListener(java.awt.event.ComponentListener )

container

 public synchronized void addContainerListener(java.awt.event.ContainerListener )
 public void removeContainerListener(java.awt.event.ContainerListener )

customItem

 public void addCustomItemListener(borland.jbcl.view.CustomItemListener l)
 public void removeCustomItemListener(borland.jbcl.view.CustomItemListener l)

focus

 public void addFocusListener(java.awt.event.FocusListener l)
 public void removeFocusListener(java.awt.event.FocusListener l)

key

 public void addKeyListener(java.awt.event.KeyListener l)
 public void removeKeyListener(java.awt.event.KeyListener l)

model

 public void addModelListener(borland.jbcl.model.GraphModelListener listener)
 public void removeModelListener(borland.jbcl.model.GraphModelListener listener)

mouse

 public void addMouseListener(java.awt.event.MouseListener l)
 public void removeMouseListener(java.awt.event.MouseListener l)

mouseMotion

 public void addMouseMotionListener(java.awt.event.MouseMotionListener l)
 public void removeMouseMotionListener(java.awt.event.MouseMotionListener l)

propertyChange

 public synchronized void addPropertyChangeListener(java.beans.PropertyChangeListener )
 public synchronized void removePropertyChangeListener(java.beans.PropertyChangeListener )

selection

 public void addSelectionListener(borland.jbcl.model.GraphSelectionListener listener)
 public void removeSelectionListener(borland.jbcl.model.GraphSelectionListener listener)

subfocus

 public void addSubfocusListener(borland.jbcl.model.GraphSubfocusListener l)
 public void removeSubfocusListener(borland.jbcl.model.GraphSubfocusListener l)

tree

 public void addTreeListener(borland.jbcl.view.TreeListener l)
 public void removeTreeListener(borland.jbcl.view.TreeListener l)

vetoableChange

 public synchronized void addVetoableChangeListener(java.beans.VetoableChangeListener )
 public synchronized void removeVetoableChangeListener(java.beans.VetoableChangeListener )