AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YDAT | YWAIT | Byzgraf | FAQs
JTreeNode typedict
 
A JTreeNode provides a means for specifying the elements, or nodes, in a JTree. Once a node is added to a tree, its fields become read-only. The JTree built-in, action, provides ways to obtain wrtieable copies of nodes, but even so, changes to the nodes will not be reflected in the tree unless additional explicit action is taken. Outside of the previously mentioned JTree built-in, Yoix programs normally interact with a JTreeNode by reading or writing the following fields:
background The Color that is used to paint the background of the node. Reading returns a snapshot of the current color. After the node is installed in a tree, writing to this field changes the background to the new color only after a suitable UPDATE or NEW_FOR_OLD action is performed on the containing tree. Storing NULL in background means use the value of the corresponding field in the containing tree.
bordercolor The Color that is used to paint the selection border color of the node. Reading returns a snapshot of the current color. After the node is installed in a tree, writing to this field changes the selection border color to the new color only after a suitable UPDATE or NEW_FOR_OLD action is performed on the containing tree. Storing NULL in bordercolor means use the value of the corresponding field in the containing tree.
children An Array of JTreeNode objects nested as descendants of the current tree node in the JTree. These objects will be visible in the JTree display when the tree node is expanded. Changes to the children array after the node is installed requires the JTree action built-in.
closedicon An Image or indicator, if it is an int, that determines what is displayed by the JTree containing this node when this node has children, but they are not currently displayed (i.e., the node is not expanded or closed). A NULL value mean that no icon should be displayed when the node is closed. The int value yoix.swing.DEFAULT_ICON indicates the default closed icon should be used. Reading returns an int, an Image, or a NULL, as appropriate. After the node is installed in a tree, writing to this field changes the icon only after a suitable UPDATE or NEW_FOR_OLD action is performed on the containing tree.
content An arbitrary Object that can be associated with a tree node to carry useful application specific information related to the tree node. The field remains writeable even after the node is attached to a tree.
font The Font, or font name if it is a String, used to paint the characters stored in the text field. Reading returns a snapshot of the current font. After the node is installed in a tree, writing to this field repaints the text in the new font only after a suitable UPDATE or NEW_FOR_OLD action is performed on the containing tree.
foreground The Color that is used to paint the foreground of the node, namely the text color. Reading returns a snapshot of the current color. After the node is installed in a tree, writing to this field changes the foreground to the new color only after a suitable UPDATE or NEW_FOR_OLD action is performed on the containing tree. Storing NULL in foreground means use the value of the corresponding field in the containing tree.
leaficon An Image or indicator, if it is an int, that determines what is displayed by the JTree containing this node when this node has no children (i.e., it is a leaf node and thus cannot be either opened or closed). A NULL value for this field means no icon should be displayed for this node. The int value yoix.swing.DEFAULT_ICON means that the default leaf icon should be used. Reading returns an int, an Image, or a NULL, as appropriate. After the node is installed in a tree, writing to this field changes the icon only after a suitable UPDATE or NEW_FOR_OLD action is performed on the containing tree.
openicon An Image or indicator, if it is an int, that determines what is displayed by the JTree containing this node when this node has children and they are currently displayed (i.e., the node is opened). A NULL value for this field means no icon should be displayed when the node is expanded or open. The int value yoix.swing.DEFAULT_ICON means that the default open icon should be used. Reading returns an int, an Image, or a NULL, as appropriate. After the node is installed in a tree, writing to this field changes the icon only after a suitable UPDATE or NEW_FOR_OLD action is performed on the containing tree.
root A read-only variable that is automatically set to the JTree containing this node. This field is NULL when the node is unattached.
selectionbackground The Color that is used to paint the selection background of the node, namely the background when the node is selected. Reading returns a snapshot of the current color. After the node is installed in a tree, writing to this field changes the selection background to the new color only after a suitable UPDATE or NEW_FOR_OLD action is performed on the containing tree. Storing NULL in selectionbackground means use the value of the corresponding field in the containing tree.
selectionforeground The Color that is used to paint the selection foreground of the node, namely the text color when the node is selected. Reading returns a snapshot of the current color. After the node is installed in a tree, writing to this field changes the selection foreground to the new color only after a suitable UPDATE or NEW_FOR_OLD action is performed on the containing tree. Storing NULL in selectionforeground means use the value of the corresponding field in the containing tree.
tag A String used to identify this tree node that is either supplied when the tree node is declared, or automatically generated otherwise. Add a tree node to a JTree and the interpreter adds the tree node, as tag, to the JTree component dictionary, thus providing an easy way to reference nodes in the JTree. As long as this node is attached to a tree, the tag field remains read-only.
text A String that serves as the label for this tree node in the displayed JTree. Reading returns a snapshot of the current text. After the node is installed in a tree, writing to this field changes the displayed text only after a suitable UPDATE or NEW_FOR_OLD action is performed on the containing tree.
tooltiptext A String that is displayed by the JTree whenever the mouse cursor is over this tree node. Reading returns a snapshot of the current tool tip text. After the node is installed in a tree, writing to this field changes the displayed tip text only after a suitable UPDATE or NEW_FOR_OLD action is performed on the containing tree.
Several permanent fields have not been documented and should not be used in Yoix applications.
 
 Example:   The program
import yoix.*.*;

JFrame f = {
    Color background = yoix.xcolor.antiquewhite1;
    Array layout = {
        new JTree {
            int tooltips = 1;
            String font = "TimesRoman-14";
            JTreeNode top = {
                String text = "The C Programming Language";
                String tooltiptext =
                    "by Brian W. Kernighan and Dennis M. Ritchie";
                Array children = {
                    new JTreeNode {
                        String text = "Introduction";
                        String tooltiptext = "Chapter 0";
                        String font = "TimesRoman-bold-14";
                    },
                    new JTreeNode {
                        String text = "A Tutorial Introduction";
                        String tooltiptext = "Chapter 1";
                        Array children = {
                            new JTreeNode {
                                String text = "Getting Started";
                                String tooltiptext = "Section 1.1";
                            },
                            new JTreeNode {
                                String text = "Variables and Arithmetic";
                                String tooltiptext = "Section 1.2";
                            },
                        };
                    },
                    new JTreeNode {
                        String text = "Types, Operators and Expressions";
                        String tooltiptext = "Chapter 2";
                        Image openicon = null;
                        Array children = {
                            new JTreeNode {
                                String text = "Variable Names";
                                String tooltiptext = "Section 2.1";
                            },
                            new JTreeNode {
                                String text = "Data Types and Sizes";
                                String tooltiptext = "Section 2.2";
                            },
                        };
                    },
                };
            };

            mouseClicked(MouseEvent e) {
                JTreeNode node = item(e.location.x, e.location.y);

                if (node != null) {
                    JTreeNode copy = node.root.action(UPDATE_COPY, node);
                    copy.text += ".";
                    node.root.action(UPDATE, copy);
                }
            }
        }, CENTER,
    };
};

f.visible = TRUE;
constructs a frame containing just a JTree with tree nodes listing some chapters and sections of a book. Each node has a tool tip associated with it. Each click on a tree node causes the text of the selected node to be augmented with a trailing period. Note that when the chapter 2 node is opened, there is no icon displayed. Compare this behavior to that which occurs when the chapter 1 node is opened.
 
 See Also:   JTree

 

Yoix is a registered trademark of AT&T Intellectual Property.