borland Packages Class Hierarchy jbcl.control Package Index
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
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.
protected String textureName
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.
public String[] getItems() public void setItems(java.lang.String[] items)The items property is an array of the strings displayed in the tree.
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().
public GraphLocation getRoot()
Returns the root node for this graph. Uses getRoot() of the GraphModel.
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.
public boolean isVariableSize()
Uses isVariableSize() of the WriteableGraphModel to check whether the tree control can have items inserted.
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:
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:
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:
public void enableModelEvents(boolean enable)Determines whether the broadcasting of graph-model events is enabled or disabled.
Parameters:
public void remove(borland.jbcl.model.GraphLocation node)Removes a node from the graph.
Parameters:
public void removeAllItems()Removes all items from the tree.
public void removeChildren(borland.jbcl.model.GraphLocation parent)Removes all children of the specified node from the tree.
Parameters:
public void set(borland.jbcl.model.GraphLocation node, java.lang.Object data)Sets the specified node to the new data item.
Parameters:
public GraphLocation setRoot(java.lang.Object data)Sets the root node of the tree.
public void touched(borland.jbcl.model.GraphLocation node)
public void addActionListener(java.awt.event.ActionListener l) public void removeActionListener(java.awt.event.ActionListener l)
public void addAncestorListener(com.sun.java.swing.event.AncestorListener ) public void removeAncestorListener(com.sun.java.swing.event.AncestorListener )
public synchronized void addComponentListener(java.awt.event.ComponentListener ) public synchronized void removeComponentListener(java.awt.event.ComponentListener )
public synchronized void addContainerListener(java.awt.event.ContainerListener ) public void removeContainerListener(java.awt.event.ContainerListener )
public void addCustomItemListener(borland.jbcl.view.CustomItemListener l) public void removeCustomItemListener(borland.jbcl.view.CustomItemListener l)
public void addFocusListener(java.awt.event.FocusListener l) public void removeFocusListener(java.awt.event.FocusListener l)
public void addKeyListener(java.awt.event.KeyListener l) public void removeKeyListener(java.awt.event.KeyListener l)
public void addModelListener(borland.jbcl.model.GraphModelListener listener) public void removeModelListener(borland.jbcl.model.GraphModelListener listener)
public void addMouseListener(java.awt.event.MouseListener l) public void removeMouseListener(java.awt.event.MouseListener l)
public void addMouseMotionListener(java.awt.event.MouseMotionListener l) public void removeMouseMotionListener(java.awt.event.MouseMotionListener l)
public synchronized void addPropertyChangeListener(java.beans.PropertyChangeListener ) public synchronized void removePropertyChangeListener(java.beans.PropertyChangeListener )
public void addSelectionListener(borland.jbcl.model.GraphSelectionListener listener) public void removeSelectionListener(borland.jbcl.model.GraphSelectionListener listener)
public void addSubfocusListener(borland.jbcl.model.GraphSubfocusListener l) public void removeSubfocusListener(borland.jbcl.model.GraphSubfocusListener l)
public void addTreeListener(borland.jbcl.view.TreeListener l) public void removeTreeListener(borland.jbcl.view.TreeListener l)
public synchronized void addVetoableChangeListener(java.beans.VetoableChangeListener ) public synchronized void removeVetoableChangeListener(java.beans.VetoableChangeListener )