|
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--java.awt.Panel | +--vipratech.beans.standardbeans.TreeView
Creates an "outline view" of text headings and, optionally, images. The headings are arranged in a hierarchical fashion, and can be expanded to show their sub-headings or collapsed, hiding their sub-headings.
A TreeView is typically used to display information that is organized in a hierarchical fashion like an index or table of contents such as seen in Microsoft Windows Explorer. The example code below demonstrates how to set up a simple collapsable tree strucutre.
public class TreeExample extends Applet
//{{REGISTER_LISTENERS
//{{DECLARE_CONTROLS
class SymItem implements java.awt.event.ItemListener
void treeView1_itemStateChanged(java.awt.event.ItemEvent event)
Object o = event.getItem();
if(o==null) s = "null";
//{{CONNECTION
import java.awt.*;
import java.applet.*;
import vipratech.beans.*;
import vipratech.beans.TreeNode;
{
public void init()
{
//{{INIT_CONTROLS
setLayout(null);
setSize(555,487);
treeView1 = new vipratech.beans.TreeView();
{
java.lang.String[] tempString = new java.lang.String[5];
tempString[0] = new java.lang.String("Root");
tempString[1] = new java.lang.String(" Folder1");
tempString[2] = new java.lang.String(" Folder 2");
tempString[3] = new java.lang.String(" Folder 3");
tempString[4] = new java.lang.String("Level 1");
treeView1.setTreeStructure(tempString);
}
treeView1.setBounds(84,84,120,48);
add(treeView1);
label1 = new java.awt.Label("text");
label1.setBounds(252,84,234,50);
add(label1);
//}}
SymItem lSymItem = new SymItem();
treeView1.addItemListener(lSymItem);
//}}
}
vipratech.beans.TreeView treeView1;
java.awt.Label label1;
//}}
{
public void itemStateChanged(java.awt.event.ItemEvent event)
{
Object object = event.getSource();
if (object == treeView1)
treeView1_itemStateChanged(event);
}
}
{
// to do: code goes here.
TreeNode tn = (TreeNode)o;
String s = tn.getText();
// Set the text for Label...
label1.setText(s);
//}}
}
}
A TreeNode object is used for each heading.
This bean was developed from bean orgininally available in Symantec Visual Cafe version 2.
TreeNode
, Serialized FormField Summary | |
static int |
CHILD
Constant indicating that the new node is to be a child of the existing node. |
static int |
LAST
Constant indicating that the new node is to be the last sibling of the existing node. |
static int |
NEXT
Constant indicating that the new node is to be the next sibling of the existing node. |
Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT,
CENTER_ALIGNMENT,
LEFT_ALIGNMENT,
RIGHT_ALIGNMENT,
TOP_ALIGNMENT |
Constructor Summary | |
TreeView()
Constructs an empty TreeView. |
|
TreeView(TreeNode head)
Constructs a TreeView with the given node. |
Method Summary | |
void |
addActionListener(java.awt.event.ActionListener l)
Adds the specified action listener to receive action events from this button. |
void |
addChild(TreeNode newNode,
TreeNode relativeNode)
Adds the specified child node to the specified parent node |
void |
addItemListener(java.awt.event.ItemListener l)
Add a listener to recieve item events when the state of an item changes. |
void |
addNotify()
Tells this component that it has been added to a container. |
void |
addSibling(TreeNode newNode,
TreeNode siblingNode)
Adds the specified node as a sibling to the specified node |
void |
addSibling(TreeNode newNode,
TreeNode siblingNode,
boolean asLastSibling)
Adds the specified node as a sibling to the specified node |
void |
append(TreeNode newNode)
Adds a new node at root level. |
void |
clear()
Clears the tree structure and redraws. |
void |
drawTree()
Draws the TreeView into an offscreen image. |
boolean |
exists(java.lang.String s)
Determines if the node with the given text is in the TreeView. |
boolean |
exists(TreeNode node)
Determines if the given node is in the TreeView. |
int |
getCount()
Returns the total number of nodes in the tree. |
java.awt.Dimension |
getMinimumSize()
Returns the minimum dimensions to properly display this component. |
java.awt.Dimension |
getPreferredSize()
Returns the recommended dimensions to properly display this component. |
TreeNode |
getRootNode()
Returns the "root" node. |
TreeNode |
getSelectedNode()
Gets the currently selected node. |
java.lang.Object[] |
getSelectedObjects()
Returns the selected items or null if no items are selected. |
java.lang.String |
getSelectedText()
Gets the text of the currently selected node. |
java.lang.String[] |
getTreeStructure()
Gets a string array that reflects the current TreeView's contents. |
int |
getViewCount()
Returns the total number of viewable nodes in the tree. |
void |
insert(TreeNode newNode,
TreeNode relativeNode,
int position)
Inserts a new node relative to an existing node in the tree. |
boolean |
isFocusTraversable()
|
void |
paint(java.awt.Graphics g)
Paints this component using the given graphics context. |
void |
printTree(TreeNode node)
Print out the text of each node in the TreeView beginning with the given node. |
void |
printTree(TreeNode node,
boolean isIndented)
Print out the text of each node in the TreeView beginning with the given node. |
void |
redraw()
Lays out the vertical scrollbar as needed, then draws the TreeView into an offscreen image. |
void |
redraw(java.awt.Graphics g)
Lays out the vertical scrollbar as needed, then draws the TreeView into an offscreen image. |
TreeNode |
remove(java.lang.String s)
Removes the node with the given text from the TreeView. |
void |
remove(TreeNode node)
Removes the given node from the TreeView. |
void |
removeActionListener(java.awt.event.ActionListener l)
Removes the specified action listener so it no longer receives action events from this button. |
void |
removeItemListener(java.awt.event.ItemListener l)
Removes an item listener. |
void |
removeNotify()
Tells this component that it is being removed from a container. |
void |
removeSelected()
Removes the currently selected node from the TreeView. |
void |
setLayout(java.awt.LayoutManager lm)
Takes no action. |
void |
setTreeStructure(java.lang.String[] s)
Initializes the TreeView from a string array. |
void |
triggerRedraw()
Triggers redrawing the entire image, even if the size of the component has not changed. |
void |
update(java.awt.Graphics g)
Handles redrawing of this component on the screen. |
Methods inherited from class java.awt.Container |
add,
add,
add,
add,
add,
addContainerListener,
countComponents,
deliverEvent,
doLayout,
findComponentAt,
findComponentAt,
getAlignmentX,
getAlignmentY,
getComponent,
getComponentAt,
getComponentAt,
getComponentCount,
getComponents,
getInsets,
getLayout,
getMaximumSize,
insets,
invalidate,
isAncestorOf,
layout,
list,
list,
locate,
minimumSize,
paintComponents,
preferredSize,
print,
printComponents,
remove,
remove,
removeAll,
removeContainerListener,
setFont,
validate |
Methods inherited from class java.awt.Component |
action,
add,
addComponentListener,
addFocusListener,
addInputMethodListener,
addKeyListener,
addMouseListener,
addMouseMotionListener,
addPropertyChangeListener,
addPropertyChangeListener,
bounds,
checkImage,
checkImage,
contains,
contains,
createImage,
createImage,
disable,
dispatchEvent,
enable,
enable,
enableInputMethods,
getBackground,
getBounds,
getBounds,
getColorModel,
getComponentOrientation,
getCursor,
getDropTarget,
getFont,
getFontMetrics,
getForeground,
getGraphics,
getHeight,
getInputContext,
getInputMethodRequests,
getLocale,
getLocation,
getLocation,
getLocationOnScreen,
getName,
getParent,
getPeer,
getSize,
getSize,
getToolkit,
getTreeLock,
getWidth,
getX,
getY,
gotFocus,
handleEvent,
hasFocus,
hide,
imageUpdate,
inside,
isDisplayable,
isDoubleBuffered,
isEnabled,
isLightweight,
isOpaque,
isShowing,
isValid,
isVisible,
keyDown,
keyUp,
list,
list,
list,
location,
lostFocus,
mouseDown,
mouseDrag,
mouseEnter,
mouseExit,
mouseMove,
mouseUp,
move,
nextFocus,
paintAll,
postEvent,
prepareImage,
prepareImage,
printAll,
remove,
removeComponentListener,
removeFocusListener,
removeInputMethodListener,
removeKeyListener,
removeMouseListener,
removeMouseMotionListener,
removePropertyChangeListener,
removePropertyChangeListener,
repaint,
repaint,
repaint,
repaint,
requestFocus,
reshape,
resize,
resize,
setBackground,
setBounds,
setBounds,
setComponentOrientation,
setCursor,
setDropTarget,
setEnabled,
setForeground,
setLocale,
setLocation,
setLocation,
setName,
setSize,
setSize,
setVisible,
show,
show,
size,
toString,
transferFocus |
Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
public static final int CHILD
insert(vipratech.beans.standardbeans.TreeNode, vipratech.beans.standardbeans.TreeNode, int)
public static final int NEXT
insert(vipratech.beans.standardbeans.TreeNode, vipratech.beans.standardbeans.TreeNode, int)
public static final int LAST
insert(vipratech.beans.standardbeans.TreeNode, vipratech.beans.standardbeans.TreeNode, int)
Constructor Detail |
public TreeView()
public TreeView(TreeNode head)
head
- the root node of the constructed treeMethod Detail |
public void setTreeStructure(java.lang.String[] s)
s
- the string array used for initialization.
If null, the tree will be cleared.getTreeStructure()
public java.lang.String[] getTreeStructure()
setTreeStructure(java.lang.String[])
public java.lang.Object[] getSelectedObjects()
This is a standard method of the ItemSelectable interface.
public void insert(TreeNode newNode, TreeNode relativeNode, int position)
newNode
- the new node to insert into the treerelativeNode
- the existing node used for a position referenceposition
- where to insert the new node relative to relativeNode.
Legal values are CHILD, NEXT and LAST.CHILD
,
NEXT
,
LAST
,
append(vipratech.beans.standardbeans.TreeNode)
public void clear()
public TreeNode getRootNode()
public int getCount()
public int getViewCount()
public boolean exists(TreeNode node)
node
- the node to checkexists(java.lang.String)
public boolean exists(java.lang.String s)
s
- the node text to find#exists(symantec.itools.awt.TreeNode)
public void append(TreeNode newNode)
newNode
- the new node to add
Does not redraw the component. Allows you to call repeatedly without
causing the component to flicker while nodes are manipulated. After all
manipulation is done, repaint the tree.insert(vipratech.beans.standardbeans.TreeNode, vipratech.beans.standardbeans.TreeNode, int)
public void addChild(TreeNode newNode, TreeNode relativeNode)
newNode
- the node to add as a childrelativeNode
- the node to add the child to.
Does not redraw the component. Allows you to call repeatedly without
causing the component to flicker while nodes are manipulated. After all
manipulation is done, repaint the tree.public void addSibling(TreeNode newNode, TreeNode siblingNode)
newNode
- the node to add as a siblingsiblingNode
- a sibling node to the new node.
Does not redraw the component. Allows you to call repeatedly without
causing the component to flicker while nodes are manipulated. After all
manipulation is done, repaint the tree.addSibling(TreeNode newNode, TreeNode siblingNode, boolean asLastSibling)
public void addSibling(TreeNode newNode, TreeNode siblingNode, boolean asLastSibling)
newNode
- the node to add as a siblingsiblingNode
- a sibling node to the new node.asLastSibling
- if true, then add the new node as the last (bottommost)
sibling node to the specified sibling node.
Does not redraw the component. Allows you to call repeatedly without
causing the component to flicker while nodes are manipulated. After all
manipulation is done, repaint the tree.addSibling(TreeNode newNode, TreeNode siblingNode)
public TreeNode remove(java.lang.String s)
s
- the node text to find#remove(symantec.itools.awt.TreeNode)
,
removeSelected()
public void removeSelected()
#remove(symantec.itools.awt.TreeNode)
,
remove(java.lang.String)
public void remove(TreeNode node)
node
- the node to removeremove(java.lang.String)
,
removeSelected()
public void printTree(TreeNode node)
node
- the first node to printpublic void printTree(TreeNode node, boolean isIndented)
node
- the first node to printisIndented,
- if true, nodes will have hierarchical indenting,
if false, all nodes will pe printed at the same level.public TreeNode getSelectedNode()
public java.lang.String getSelectedText()
public void update(java.awt.Graphics g)
g
- the graphics contextComponent.repaint()
,
paint(java.awt.Graphics)
public void paint(java.awt.Graphics g)
g
- the graphics context used for paintingComponent.repaint()
,
update(java.awt.Graphics)
public void redraw()
public void redraw(java.awt.Graphics g)
g
- the graphics object use for drawingpublic void drawTree()
public java.awt.Dimension getPreferredSize()
getMinimumSize()
public java.awt.Dimension getMinimumSize()
getPreferredSize()
public void setLayout(java.awt.LayoutManager lm)
lm
- the layout manager to use to layout this container's components
(IGNORED)Container.getLayout()
public boolean isFocusTraversable()
public void addNotify()
removeNotify()
public void removeNotify()
addNotify()
public void triggerRedraw()
public void addActionListener(java.awt.event.ActionListener l)
l
- the action listenerpublic void removeActionListener(java.awt.event.ActionListener l)
l
- the action listenerpublic void addItemListener(java.awt.event.ItemListener l)
This is a standard method of the ItemSelectable interface.
l
- the listener to recieve eventsItemEvent
public void removeItemListener(java.awt.event.ItemListener l)
This is a standard method of the ItemSelectable interface.
l
- the listener being removedItemEvent
|
dathe@chemie.uni-leipzig.de" | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |