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
JTree typedict
 
A JTree is the interface to the Java Swing JTree Component. Yoix programs normally interact with a JTree using event handlers and by reading or writing the following fields:
action(int flag[, Object arg1[, Object arg2]]) A built-in for manipulating the tree or getting information about it and its components. The initial argument, an integer flag, indicates the action to take. The remaining arguments, if any, depend on the type of action. The forty-one integer flags, which are defined in yoix.swing, their indicated actions and the associated arguments, if any, are described in the following list.
  • ADD_CHILD indicates that the JTreeNode provided as arg1 is to be added to the tree as a child of the JTreeNode provided as arg2. The child is added last among its siblings, if any. The added node is returned.
  • ADD_SIBLING_ABOVE indicates that the JTreeNode provided as arg1 is to be added to the tree as a sibling of the JTreeNode provided as arg2. The sibling is added above, namely before, the given sibling. The added node is returned.
  • ADD_SIBLING_BELOW indicates that the JTreeNode provided as arg1 is to be added to the tree as a sibling of the JTreeNode provided as arg2. The sibling is added below, namely after, the given sibling. The added node is returned.
  • BREADTH_FIRST returns an Array of nodes resulting from a breadth first traversal of the tree starting at and including the JTreeNode provided as arg1.
  • COLLAPSE_NODE updates the JTree display, as appropriate, so that the JTreeNode provided as arg1 is collapsed, namely its descendants are no longer displayed and its icon and handle is updated appropriately.
  • DELETE_NODE removes the JTreeNode provided as arg1 and all of its descendants, if any, from this tree.
  • DEPTH_FIRST returns an Array of nodes resulting from a depth first traversal of the tree starting at and including the JTreeNode provided as arg1.
  • DESELECT_INTERVAL causes all nodes inclusive to the range of rows starting at the int provided as arg1 and ending at the int provided as arg2 to be deselected.
  • DESELECT_NODE deselects the JTreeNode provided as arg1.
  • DESELECT_NODES deselects the Array of nodes provided as arg1.
  • EDIT_CANCEL cancels the current interactive node label editing session. Any changes made in the session are discarded. An editing session is started in one of three ways: by means of the action associated with the EDIT_START flag, by triple-clicking on a node displayed in the tree or by clicking on the text of an already selected node displayed in the tree.
  • EDIT_START starts an interactive node label editing session on the JTreeNode provided as arg1.
  • EDIT_STOP stops the current interactive node label editing session. Any changes made in the session are accepted. An editing session is started in one of three ways: by means of the action associated with the EDIT_START flag, by triple-clicking on a node displayed in the tree or by clicking on the text of an already selected node displayed in the tree.
  • ELEMENT_COUNT returns a count of the nodes that descend from the supplied node including supplied node. If no JTreeNode argument is supplied or it is NULL, then a count of all nodes in the current tree is returned.
  • EXPAND_ALL updates the JTree display, as appropriate, so that all the nodes that have children are expanded, namely all descendants are displayed. Icons and handles are updated appropriately.
  • EXPAND_NODE updates the JTree display, as appropriate, so that the JTreeNode provided as arg1 is expanded, namely its descendants are displayed and its icon and handle is updated appropriately.
  • GET_EXPANDED_NODES returns a growable Array of nodes currently expanded in the tree.
  • GET_NODE_FOR_ROW returns the JTreeNode associated with the currently displayed row of the tree indicated by the int supplied as arg1.
  • GET_PARENT returns the JTreeNode that is the parent of the JTreeNode provided as arg1.
  • GET_ROW_COUNT returns an int indicating, for this tree, the number of rows currently displayed.
  • GET_ROW_FOR_NODE returns an int corresponding to the displayed row containing the JTreeNode provided as arg1. Row numbering starts at zero. The value -1 is returned when the supplied node is not displayed.
  • GET_SELECTED_NODES returns a growable Array of nodes currently selected in the tree.
  • GET_SELECTED_COUNT returns an int giving a count of nodes currently selected in the tree.
  • GET_SIBLING_ABOVE returns a JTreeNode that is the sibling within the tree which is above, namely before, the JTreeNode provided as arg1. If there is no such sibling, a NULL is returned.
  • GET_SIBLING_BELOW returns a JTreeNode that is the sibling within the tree which is below, namely after, the JTreeNode provided as arg1. If there is no such sibling, a NULL is returned.
  • MAKE_NODE_VISIBLE causes the display of the tree to be expanded so that the JTreeNode provided as arg1 is made visible, namely all its ancestors are expanded. Moreover, if possible, the node will be scrolled into the display area.
  • NEW_FOR_OLD replaces the JTreeNode provided as arg2 with the JTreeNode provided as arg1. All descendants of these nodes are also removed or installed, as appropriate.
  • NODE_HAS_BEEN_EXPANDED returns a non-zero int if the JTreeNode provided as arg1 has ever been expanded.
  • NODE_IS_EXPANDED returns a non-zero int if the JTreeNode provided as arg1 is currently expanded. A zero value is always returned for the case of a leaf node.
  • NODE_IS_SELECTED returns a non-zero int if the JTreeNode provided as arg1 is currently selected.
  • NODE_IS_VISIBLE returns a non-zero int if the JTreeNode provided as arg1 is currently visible.
  • SCROLL_NODE scrolls the JTreeNode provided as arg1 into the display area, if scrolling is possible.
  • SCROLL_ROW scrolls the row provided as arg1 into the display area, if scrolling is possible.
  • SELECT_ALL causes all nodes in the tree to be visible and selected.
  • SELECT_ALL_VISIBLE causes all nodes in the tree that are currently visible to be selected.
  • SELECT_INTERVAL causes all nodes inclusive to the range of rows starting at the int provided as arg1 and ending at the int provided as arg2 to be selected.
  • SELECT_NODE selects the JTreeNode provided as arg1 and, if possible, scrolls to move the selected node into the display area.
  • SELECT_NODES selects the Array of nodes provided as arg1.
  • SELECT_NONE deselects all nodes.
  • SELECT_TOGGLE toggles the selection state of the JTreeNode provided as arg1. Namely, an unselected node will become selected and a selected node will become unselected.
  • TAGGED_COPY returns a copy of the JTreeNode provided as arg1 and all of its descendants, if any, but leaves them unaffiliated with a particular tree, namely the root field is NULL, and the children and tag fields are writeable. The tag field is forced to NULL.
  • UNTAGGED_COPY returns a copy of the JTreeNode provided as arg1 and all of its descendants, if any, but leaves them unaffiliated with a particular tree, namely the root field is NULL, and the children and tag fields are writeable. The tag field is the same as the corresponding original node.
  • UPDATE_TREE uses the fields in the JTreeNode provided as arg1, except the children field, to update the node in the tree that has the matching tag value.
  • UPDATE_COPY returns a copy of the JTreeNode provided as arg1, but includes none of its descendants, if any. The returned node is unaffiliated with a particular tree, namely the root field is NULL. The tag field is the same as the corresponding original node. The children field is forced to NULL. This sort of copy is useful in conjunction with the UPDATE_TREE action described above since the children field is ignored by that action.
background The Color that is used to paint the background of the tree. Reading returns a snapshot of the current color. Writing immediately changes the background to the new color. Storing NULL in background is special and means use the background of the nearest component that contains the tree and was assigned a background color other than NULL; if no component qualifies the tree uses VM.screen.background. This value also serves as the default background for any nodes in the tree.
border An Object that should be a Border, Insets, Number, or String that describes the border that is drawn around this tree. A NULL value, which is the default, means no border. A border that is an Insets or Number is an easy way to describe margins (i.e., an EmptyBorder), in units of 72 dots per inch, that are left around the sides of this tree. A border that is a String is a quick way to surround this tree with a border that uses the String as its title. Reading returns a snapshot of the current border. Writing immediately sets the tree's border to the new value.
bordercolor The default Color that is used to paint the border of nodes in the tree which are selected. Reading returns a snapshot of the current color. Writing immediately changes the default border color to the new color.
closedicon An Image or indicator, if it is an int, that serves as the default icon displayed by nodes in this tree when the 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.
components A Dictionary maintained by the interpreter's layout machinery that maps tag fields to tree nodes; every node contained in the tree has an entry in the dictionary. In addition, the root field in each node is automatically set to this tree, so the components dictionary is easy to find when given a node, and that means individual nodes can find each other by name using the root.components dictionary in each node.
cursor An Object that should be an int, Image, or String that selects the cursor shown when the pointer is over the tree. A cursor that is an int should be one of the cursors defined in the yoix.awt.Cursor dictionary. A cursor that is an Image can describe the cursor using its size and hotspot fields and often draws it using its paint function. A cursor that is a String should be the name of a cursor that is already defined in yoix.awt.Cursor or the name a local a file or URL that contains a GIF or JPEG image that will be used as the cursor.

Reading returns the current cursor. Writing immediately changes the tree's cursor to the new value. Storing STANDARD_CURSOR (the default) or NULL in cursor is special and means use the cursor assigned to the nearest component that contains the tree and was assigned a cursor other than STANDARD_CURSOR; if no component qualifies the tree uses DEFAULT_CURSOR.

doublebuffered An int that is 1 when the tree uses double-buffering to draw itself, 0 when it does not, and starts with a default value that is selected by Java for the tree. Reading returns the current double-buffering behavior. Writing immediately sets the tree's double-buffering behavior to the new value. Note that double-buffering may be required when transparent components are used.
dragenabled An int that should be set to 1 when this tree wants to use the automatic drag handling that Swing provides for some components, and 0 (the default) when it does not. Components that do not provide automatic drag handling always return 0 when their dragenabled field is read, so storing 1 in dragenabled should only be viewed as a request for a service that may not be available. Swing components can always take complete control of their drag and drop handling using their transferhandler field or special drag and drop event handlers.
edit An int that is 1 when the node text can be edited interactively, and 0 otherwise. Reading returns the current state. Writing immediately sets the tree's interactive editing state to the new value.
enabled An Object that is 1 when the tree can respond to user input, 0 when it can not respond, and NULL (the default) when the tree inherits the value from the nearest lightweight container, like a JPanel, that contains the tree and has its enabled field set to something other than NULL. The top-level application window that contains the tree always gets the final say, so disabling that window always disables the tree. Reading returns the current state. Writing immediately sets the tree's state to the new value.
expandsselectednodes An int that is 1 when the tree will expanded all nodes leading to a selected node, and 0 otherwise. Reading returns the current state. Writing immediately sets the tree's selection expansion criterion to the new value.
focusowner A read-only int that is non-zero when the tree has the focus.
font The Font, or font name if it is a String, used to paint the characters stored in the text field of nodes by default. Reading returns a snapshot of the current font. Writing immediately repaints the text of nodes not specifically assigned a font in the new font.
foreground The Color that is used to paint the characters stored in the text field of nodes by default. Reading returns a snapshot of the current color. Writing immediately repaints the tree text of nodes not specifically assigned a foreground in the new color. Storing NULL in foreground is special and means use the foreground of the nearest component that contains the tree and was assigned a foreground color other than NULL; if no component qualifies the tree uses VM.screen.foreground.
item(Number x, Number y) A Builtin that returns the node in the tree at the specified coordinates.
layer An int, often a small number between 0 and 99, that identifies the depth of this tree when it is added to a JLayeredPane or JDesktopPane. Components assigned to lower numbered layers are drawn before the components in higher numbered layers. Writing immediately changes the tree's layer, which usually means the JLayeredPane or JDesktopPane that contains the tree will be repainted.
leaficon An Image or indicator, if it is an int, that serves as the default icon displayed by nodes in this tree when the node has no children (i.e., the node is a leaf node). A NULL value mean that leaf nodes should display no icon by default. The int value yoix.swing.DEFAULT_ICON indicates the default leaf icon should be used. Reading returns an int, an Image, or a NULL, as appropriate.
location A Point that determines the location of the tree in a coordinate system that has its origin at the upper left corner of the container closest to the tree (in the component hierarchy) that actually contains it, positive x to the right, positive y down, and a resolution of 72 dots per inch. Reading returns a snapshot of the current location. Writing is allowed, but layout managers usually get the final say, so setting location should be viewed as a request that may not be honored.
multiplemode An int that determines how many nodes may be selected at one time and in what manner.
nextfocus An Object that is the component that receives the focus after this tree when the focus traverses from one component to the next (usually by means of the keyboard TAB character). A NULL value indicates that the default Java focus traversal is in effect. Reading returns the value last stored. Writing immediately sets the new focus traversal behavior.
opaque An Object that is 1 when the tree is opaque, 0 when it is transparent, and NULL (the default) when the tree inherits the value from the nearest component that contains the tree and has its opaque field set to something other than NULL.
openicon An Image or indicator, if it is an int, that serves as the default icon displayed by nodes in this tree when the node has children, and they are currently displayed (i.e., the node is expanded or open). A NULL value mean that no icon should be displayed when the node is open. The int value yoix.swing.DEFAULT_ICON indicates the default open icon should be used. Reading returns an int, an Image, or a NULL, as appropriate.
popup A JPopupMenu that is associated with the tree. Reading returns the current popup menu. Writing immediately shows the popup menu at the point in the tree's coordinate system specified by the popup menu's location field, assuming of course that the tree is showing on the screen. Storing TRUE in the popup menu's visible field, which was added in release 1.2.0, is an easy way to show the popup menu that currently belongs to the tree.
preferredsize A Dimension that is used by layout managers when they need to know the tree's preferred size in units of 72 dots per inch. A NULL value means the tree has no preference. A non-positive height or width is allowed and simply means the tree has no preference for that dimension. Reading returns the current preferred size. Writing changes the preferred size and immediately notifies root.layoutmanager, which means the components contained in root may be repositioned and resized.
requestfocus An int that can be used to request or transfer the keyboard focus. Storing a non-zero value in requestfocus tries to get the focus. Storing 0 tries to transfer the focus. Reading requestfocus does not currently return any useful information.
requestfocusenabled An int that is 1 (the default) when actions, like mouse clicks or changes to the requestfocus field, can steal the keyboard focus and 0 when they can not. Note that this field does not affect acceptance of the keyboard focus during normal focus traversal. Reading returns the current state. Writing immediately sets the tree's state to the new value.
root An Object that is automatically updated by the interpreter's layout machinery so it is always the top-level object that contains the tree. For example, put a tree in a panel and root will be set to that panel; add the panel to a frame and the tree's root field will be set to that frame. A tree's event handlers can use root when they need to interact with the other components in the container.
roothandle An int that is 1 when the root node should have a handle for opening or closing the display of its children, and 0 otherwise. Reading returns the current roothandle visibility. Writing immediately sets the tree's roothandle visibility to the new state.
scrollsonexpand An int that is 1 when the tree will attempt to scroll whenever node is expanded to display as many of the newly exposed children as possible, and 0 otherwise. Naturally, the tree needs to be in a scrolling pane for this feature to have meaning. Reading returns the current expansion scrolling criterion. Writing immediately sets the tree's expansion scrolling criterion to the new state.
selectionbackground The default Color that is used to paint the background of nodes in the tree which are selected. Reading returns a snapshot of the current color. Writing immediately changes the default selection background color to the new color.
selectionforeground The default Color that is used to paint the text of nodes in the tree which are selected. Reading returns a snapshot of the current color. Writing immediately changes the default selection text color to the new color.
showing A read-only int that is non-zero when the tree is showing on the screen.
size A Dimension that determines the size of the tree in units of 72 dots per inch. Reading returns a snapshot of the current size. Writing is allowed, but layout managers usually get the final say, so setting size should be viewed as a request that may not be honored.
tag A String used to identify the tree that is either supplied when the tree is declared, or automatically generated otherwise. Add a tree to a container, like a JFrame or JPanel, and the interpreter's layout machinery updates the root field so it points at the top-level container and then adds the tree, as tag, to the root.components dictionary.
tooltips An int that is 1 when node tooltips, if any, are active, and 0 otherwise. Reading returns the current tooltip mode. Writing immediately sets the tree's tooltip mode to the new state.
tooltiptext A String of characters that is displayed in a tightly sized pop-up window that appears near the cursor whenever the cursor lingers over the tree. Setting this value to NULL (the default) disables the tooltip mechanism. Reading returns the current tooltip text. Writing immediately sets the new tooltip text.
top A JTreeNode or String objects that define the root node of the tree. Additional depth is possible by assigning additional nodes to the children field of this root node. Supplying a String is equivalent to using that a default JTreeNode object whose text field has been assigned the given string. In this latter case, the tree would only have one node in it, since a default node is childless.
transferhandler An Object that should be a TransferHandler or String that determines how the tree handles data transfer operations like drag and drop. A value that is a String but not "" means the field named by the String should be used as the source and sink of the data that is transferred by the tree. The result is the same as assigning the String to the property field in a TransferHandler and then assigning that TransferHandler to transferhandler. The empty String "" is special and refers to the TransferHandler that Swing uses for automatic drag handling, if there is one.

Swing components that provide automatic drag handling start out with a transferhandler field that is not NULL, but the automatic drag handling is not enabled until 1 is stored in dragenabled. Swing components that provide their own drag and drop event handlers currently must store NULL in transferhandler before those event handlers will start working.

visible An int that is 1 when the tree is visible, and 0 otherwise. Reading returns the current visibility. Writing immediately sets the tree's visibility to the new state.
Several permanent fields have not been documented and should not be used in Yoix applications. Event handlers are functions that must be added to a label when it is declared. The handlers that work with labels are listed below; the names should be familiar if you have done some Java programming with the exception of invocationBrowse. The actionPerformed and itemStateChanged event handlers are only for menus.
 
 Event Handlers:   actionPerformed, componentHidden, componentMoved, componentResized, componentShown, dragDropEnd, dragEnter, dragExit, dragGestureRecognized, dragMouseMoved, dragOver, drop, dropActionChanged, focusGained, focusLost, invocationBrowse, invocationRun, itemStateChanged, keyPressed, keyReleased, keyTyped, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, mouseWheelMoved, valueChanged
 
 Example:   The program,
import yoix.*.*;

JTree original = {
 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";
      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";
       },
      };
     },
    };
   },
  };
 };
};

JTreeNode copy = original.action(UNTAGGED_COPY, original.top);

JFrame jf = {
 Color background = yoix.xcolor.antiquewhite1;
 int   visible = 1;
 Array layout = {
  new JScrollPane {
   Array layout = {
    new JTree {
     String tag = "$_jt";
     int tooltips = 1;
     String font = "TimesRoman-14";
     JTreeNode top = copy;

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

      if (node != null) {
       copy = original.action(UNTAGGED_COPY, original.top);
       node.root.action(NEW_FOR_OLD, copy, node);
      }
     }
    },
   };
  }, CENTER,
 };
};
displays a tree within a scrolling pane. Whenever a node is selected, it is replaced with a copy of the original tree.
 
 See Also:   BevelBorder, Border, EmptyBorder, EtchedBorder, invokeLater, JButton, JCanvas, JCheckBox, JCheckBoxMenuItem, JChoice, JColorChooser, JComboBox, JDesktopPane, JDialog, JFileChooser, JFileDialog, JFrame, JInternalFrame, JLabel, JLayeredPane, JList, JMenu, JMenuBar, JMenuItem, JPanel, JPasswordField, JPopupMenu, JProgressBar, JRadioButton, JRadioButtonMenuItem, JScrollBar, JScrollPane, JSeparator, JSlider, JSplitPane, JTabbedPane, JTable, JTextArea, JTextCanvas, JTextField, JTextPane, JTextTerm, JToggleButton, JToolBar, JTreeNode, JWindow, LineBorder, MatteBorder, postEvent SoftBevelBorder, TransferHandler

 

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