jbcl.control Package
java.lang.Object +----java.awt.Component +----java.awt.Container +----javax.swing.JComponent +----javax.swing.JScrollPane +----com.borland.jbcl.view.TreeView +----com.borland.jbcl.control.TreeControl
Variables Constructors Properties Methods Event Listeners
Implements GraphModel, BlackBox, GraphView, ImageObserver, MenuContainer, Serializable, Accessible, ScrollPaneConstants
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 TreeControl.jpr project in the samples directory.
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(String[] items)The
items
property is an array of the strings displayed in the tree.
public void setModel(GraphModel model)
Checks for recursive model creation, then calls super.setModel(model), which is com.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(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(GraphLocation parent, GraphLocation aheadOf, 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
aheadOf
data
public GraphLocation addChild(GraphLocation parent, Object data)Appends a data object as the last child in the chain of children of the specified
parent
node.
Parameters:
parent
data
public boolean canSet(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
public void enableModelEvents(boolean enable)Determines whether the broadcasting of graph-model events is enabled or disabled.
Parameters:
enable
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.
public void remove(GraphLocation node)Removes a node from the graph.
Parameters:
node
public void removeAllItems()Removes all items from the tree.
public void removeChildren(GraphLocation parent)Removes all children of the specified node from the tree.
Parameters:
parent
public void set(GraphLocation node, Object data)Sets the specified node to the new data item.
Parameters:
node
data
public GraphLocation setRoot(Object data)Sets the root node of the tree.
public void touched(GraphLocation node)
public void addActionListener(ActionListener l) public void removeActionListener(ActionListener l)
public void addAncestorListener(javax.swing.event.AncestorListener ) public void removeAncestorListener(javax.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 synchronized void removeContainerListener(java.awt.event.ContainerListener )
public void addCustomItemListener(CustomItemListener l) public void removeCustomItemListener(CustomItemListener l)
public void addFocusListener(FocusListener l) public void removeFocusListener(FocusListener l)
public synchronized void addInputMethodListener(java.awt.event.InputMethodListener ) public synchronized void removeInputMethodListener(java.awt.event.InputMethodListener )
public void addKeyListener(KeyListener l) public void removeKeyListener(KeyListener l)
public void addModelListener(GraphModelListener listener) public void removeModelListener(GraphModelListener listener)
public void addMouseListener(MouseListener l) public void removeMouseListener(MouseListener l)
public void addMouseMotionListener(MouseMotionListener l) public void removeMouseMotionListener(MouseMotionListener l)
public synchronized void addPropertyChangeListener(java.beans.PropertyChangeListener ) public synchronized void removePropertyChangeListener(java.beans.PropertyChangeListener )
public void addSelectionListener(GraphSelectionListener listener) public void removeSelectionListener(GraphSelectionListener listener)
public void addSubfocusListener(GraphSubfocusListener l) public void removeSubfocusListener(GraphSubfocusListener l)
public void addTreeListener(TreeListener l) public void removeTreeListener(TreeListener l)
public synchronized void addVetoableChangeListener(java.beans.VetoableChangeListener ) public synchronized void removeVetoableChangeListener(java.beans.VetoableChangeListener )