Tree Applet documentation v.
2.6
Copyright SCAND LLC 2005
Tree applet can load content in two modes:
initialize it from PARAM tags, present in HTML that contain the applet (these tags are descirbed below in section "Tree parameters")
load items located on sub-levels dynamically from the server where the applet is loaded from
In both cases it is possible to manage items of the tree applet using public methods of it. This can be done as from another Java applet that uses Tree applet, so from browser using JavaScript. The public methods are described below in the section "Tree methods".
To populate tree with data you should specify for every item set of required parameters, listed below.
Name | Required | Possible values | Description |
---|---|---|---|
ITEMi | Yes | according to IDC parameter | Item's identifier. Used as reference to item while accessing from script functions. |
TEXTi | Yes | Any string value | Visible name of tree item, which will be displayed on screen. |
ACTIONi | Yes | Valid parameters for script function | List of parameters, transmitted to script function, described by
EVAL parameter. Can accept: 1. Integer value 2. String value in single or double quotation marks. 3. Collection of (1) and (2), separated by commas. |
LEVELi | Yes | Integer | Level of current node. Must be from 0 till previous item's level + 1. |
SELECTi | No | Any value | If specified, then current item will be selected.(Cursor will be placed on last selected item.) |
IM0i, IM1i | No | Integer | Indexes of images (given by IMAGEi parameters), associated with current item. Ignored if no
ICONS_PERMANENT parameter specified.
It is possible to specify a file name directly in this parameter. In this case the parameter should have value in format f<file_name> |
CHILDi | No | Any value | Use in dynamical tree only. Not null value means non-terminal node - children for it will be loaded from server. (See also Dynamic loading section) |
COLORi | No | HTML color format | The color of item's text |
SELCOLORi | No | HTML color format | The color of text for selected items |
OPENEDi | No | Any value | Sets item initially to open state |
CHECKEDi | No | Any value | If specified, then current item will be checked (See Check items section) |
CHECK_DISABLEDi | No | Any value | If specified, then current item will have disabled checkbox (See Check items section) |
UNDERLINEi | No | Any value | If specified, then current item will be underlined. |
FONTi | No | Java font format | The font of item's text in format <font_name>-<font_style>-<font_size> |
USERDATAi | No | Values in format <key>='<value>' | User-defined data for node |
Example 1. Possible item definition.
<PARAM NANE='ITEM0' VALUE='0'> <PARAM NANE='NAME0' VALUE='Root item'> <PARAM NANE='ACTION0' VALUE="'r13'"> <PARAM NANE='LEVEL0' VALUE='0'> <PARAM NANE='SELECT0' VALUE='1'>This set of parameters describes the color, fonts and other attributes of tree applet. Attributes of fonts and attributes can be redefined for each tree item using Items parameters and Items Properties Control.
This set of parameters describes the color model of
the tree applet.
Name | Description |
---|---|
BG_COLOR | Background color. |
FG_COLOR | Color of non-selected item's label. |
BGSEL_COLOR | Background of selected item. |
FGSEL_COLOR | Color of selected item's label. |
LINES_COLOR | Color of lines in tree |
CROSSES_COLOR | Color of crosses for non-terminal items |
CONTOUR_COLOR | Color of selected items' contour color |
This set of parameters describes sizes of tree components:
The height of node. All nodes in tree has the same height. Default value is 18.
Size of icons in tree. If real size of any image differs from this value, image will be resized. Default value is 16x16.
Indent between two levels in tree. Default value is 4.
MARGIN_LEFT / MARGIN_TOP / MARGIN_RIGHT / MARGIN_BOTTOM
Define margin values from left/top/right/bottom borders correspondingly.
This set of parameters specifies the image list of tree items and behavior of showing images.
Specifies the list of images for the tree items. Has structure IMAGE0, IMAGE1, ... ,IMAGEn. This numbers can be passed in IM0 and IM1 parameters of an item (see Items parameters).Specifies image name for background of the applet
Sets position of background image in format <x>;<y>. If not specified, background image will be repeated in the background.
Important: If this parameter specified, minimum one of images (IM0 or IM1) must be specified for each node. Otherwise the tree will not be initialized.
If this parameter has non-empty value, non-terminal items will be marked with "+" on the left side
If this parameter has 0 value, root items displayed without "+" expand symbol
Font of tree applet in Java font format: <font_name>-<font_style>-<font_size>
Default value is "Verdana", size 13, style PLAIN.
Allows you to collapse root nodes with LEVEL=0. Disabled by default.
This set of parameters permits to use checkboxes as items in tree
Creates tree with checkboxes for all nodes. Images for checkboxes has fixed size 11x11 pt and can be specified with followed parameters:
Name | Description | Default value |
---|---|---|
IMAGE_CHECKED | Image for checked item | icons/item_checked.gif |
IMAGE_UNCHECKED | Image for unchecked item | icons/item_unchecked.gif |
IMAGE_SHADEN | Image for unchecked item, who has checked children on next levels | icons/item_shaden.gif |
Shows checkboxes with images. Default value is "1".
Size of images for checked/unchecked items. Default value is 11x11 ps..
Processing of checks is automatic - if item checked, all subnodes becomes to checked state too and all parents came into shadow mode. Default value is "1".
Dynamic loadingIn case of huge set of data reasonable to load only root nodes from HTML page and load additionally subnodes as required. For this possibility parameter GET_DOC is using.
Important: This possibility available only in full version of jtree.
Used in dynamical trees. It means the name of document, which
will load the data from server. Loading happens when:
1. This parameter is not null,
2. Node hasn't child subnodes
3. Parameter CHILD for this node is not null.
The document can get identifier of called node through id parameter and must return the list of strings,
ended by empty string. Every string contains information about single child node in
the next format:
"Name","id","action",hasChildren,im0,im1,UNDERLINE
Where id - identifier of the node, name - its name, action - the same meaning as ACTION parameter, hasChildren - CHILD parameter, im0,im1 - IM0,IM1 parameters.
If UNDERLINE world specified in last position item will be underlined.
<%
id = request("id")
sqlStr ="select KeyField, NameField from DataTable where ParentKeyFied="
& id
set ResultSet = DBConnection.execute(sqlStr)
while not ResultSet.eof
Key = ResultSet("KeyField")
Name = ResultSet("NameField")
response.writeln(""""
& Name & """,""" & Key & ""","""
& Key & """,0,1,2" )
ResultSet.moveNext
wend
response.writeln("")
%>
If name of document starts with javascript: prefix, information will be loaded from javascript function, the name of wich should follow specified prefix.
Example 3. Declaration of JavaScript initialization function
<html>
<head>
<script>
function getDoc()
{
return "'Root Node','Root Node',\"'Root Node'\",0,1,2"
}
</script>
</head>
<body>
...
<applet>
<param name="GET_DOC" value="getDoc">
</applet>
...
</body>
</html>
The name of document for initial loading of tree. (See GET_DOC parameter)
Enabling menu in tree applet. It will be called after right-button clicking on node. The value of this parameter is the name of script function, wich will be called after selection in menu. It must have two parameters - the identifier of node and number of selected item in menu (started from 0). If this parameter specified, next parameters will be processed:
Specifies the name of menu item. Can has any string values or 'SEPARATOR' for inserting menu separator between menu items.
Specifies menu initialization script function. This function should be used for customizing popup menu and is called directly before displaying menu and takes two parameters: identifier of node and TreeMenu object. Initially this object contains parameters defined with MENUi parameters. See Menu object for additional information..
Enables menu for multi-selected items in tree. If not set (default), selection moved only to last selected item (other will be clean)
This object is passes into ON_MENU_PRE function and make possible to change structure of the menu in run-time. It has the next set of public functions:
void addSeparator() Adds seperator into menu.
void addString(String txt) Adds new item with specified label into menu.
void void remove(int index) Removes item from menu.
void removeAll() Removes all items from menu.
String getLabel() Gets label of specified item.
setEnable(int index, boolean isEnable)() Sets specified item to enabled or disabled state.
void void setLabel(int index, String txt) Sets label of specified item.
This set of functions specifies script functions to process events from the tree.
The name of script function, which will be called when any item in tree is selected. Values specified in ACTION parameter will be passed to this function.
Example 4. Function with single argument.
function foo( s ) { } <PARAM name="EVAL" VALUE="foo"> <PARAM name="ACTION0" VALUE="0"> // foo(0) will be called <PARAM name="ACTION1" VALUE="'test'"> // foo('test') will be calledExample 5. Function with two arguments.
function foo( s1, s2 ) { } <PARAM name="EVAL" VALUE="foo"> <PARAM name="ACTION0" VALUE="0,0"> // foo(0,0) will be called <PARAM name="ACTION0" VALUE="'test',28"> // foo('test',28) will be called <PARAM name="ACTION0" VALUE="28"> // Invalid, function does't take one argument.
The name of script function, which will be called when all items have been loaded into the tree and you can call any tree applet's method.
The name of script function, which will be called after doubleclicking on node. Function takes single parameter - the identifier of node.
The name of script function, which will be called after changing of checked state of item. It has two parameters - identifier of item and boolean value of current checked state.
The name of script function, which will be called after expanding/collupsing of the node. Function takes two arguments - identifier of node and expanding boolean flag
The name of script function, which will be called after any of key pressing, when
jtree applet has input focus. This function has single argument - instance of java.awt.event.KeyEvent object - you can get all information about event (key
code, key character, ctrl- and shift mofofiers, etc) from it (see JDK documentation).
If this function return "false" value, standard processing of this event will be
skiped by applet.
The name of script function, which will be called when mouse pointer is entered into item, function receives identifier of item as parameter
The name of script function, which will be called when mouse pointer is leaved item' area, function receives identifier of item as parameter
Hierarchical selection flag. By default you cannot select node item and its child simultaneously. To enable child selection you should set this parameter to any nonempty value.
Enabling (1) or disabling (0) multiple selection mode of tree. Default it's enabled.
Allows to select several items in tree only in subset of single parent node
Specified name of tree. In this case state of tree will be stored in internal java variable and restored after page reloading.
Tree structure can be loaded from separated XML document. In this case applet should have only one parameter - XML - wich describes location of xml document, started from html document base. Important: this possibily can be used only in internet or intranet applications, becouse applet can't load another file from local drive. Below you can see simple example of xml document for tree:
Example 6. XML-code with simple tree structure<tree image0 = "icons/item_root.gif" image1 = "icons/item_node.gif" image2 = "icons/item_open.gif" image3="icons/item_closed.gif" eval = "TreeSel" crosses = "1"> <item id='item0' text='Root' action='0'> <item id='item1' text='node1000' action='a'/> <item id='item8' text='node2000' action='b'/> <item id='item10' text='node3000' action='c'/> </item> </tree>
TREE tag attributes
Inside of tree tag all tree attributes (see Initialization) section can be used. In single XML document only one tree structure can be described.
Each item can be described as single xml tag or start/end tags. All items wich are described inside of start/end couple will be subitems of outside item. Besides, in this couple can be placed label of item (as text) and user-defined data (as <userdata/> tag).
Example 7. XML-code for item with label 'Single item' and user-defined data:<item id='128'> Single item <userdata key='some key' value='some value'/> </item>
Another possibility to define label of item - using of text attribute of item tag (see example 5). All other attributes, desribed in Items parameters section can be used inside of item tag.
Example 8. Definition of menu:<menu on_menu='onMenu' on_menu_pre='on_menu_pre'> <menuitem name='Open item'/> <menuitem name='Close item'/> <separator/> <menuitem name='Delete item'/> </menu>
If get_doc attribute is specified for tree, algorithm of work will be similar to tree without XML (see GET_DOC parameter description). But response should contain tree structure in XML format (without tree tag), wich will be inserted as subtree of source item.
public String findRef(java.lang.String ref)
public String findRefByLabel(java.lang.String lbl)
public boolean hasData()
public String getSelectedItems()
public String getSelectedItemsId()
public String getSelectedItemsId(java.lang.String delimiter)
public String getSelectedItemsId(int sortType)
public String getSelectedItemsId(int sortType, java.lang.String delimiter)
public String getLastSelectedId()
public boolean isLastItemSelected()
public void selectItem(java.lang.String id)
public void selectItem(java.lang.String id, boolean isCall)
public void addSelection(java.lang.String id, boolean isCall)
public void unselectAll()
public String getSubItems(java.lang.String id)
public String getAllSubItems(java.lang.String id)
public String getLastAllSubItems(java.lang.String id)
public String getNextItem(java.lang.String id)
public String getNextSibling(java.lang.String id)
public void setLabel(java.lang.String id, java.lang.String text)Available in full version only
public String getParentId(java.lang.String id)
public String getAction(java.lang.String id)
public String getLabel(java.lang.String id)
public void openItem(java.lang.String id)
public void setItemColor(java.lang.String id, java.lang.String strNormColor, java.lang.String strSelColor)Available in full version only
public void setFont(java.lang.String id, java.lang.String font)Available in full version only
public String getFont(java.lang.String id)
public void setUnderline(java.lang.String id, boolean isUnderline)Available in full version only
public int getItemImage(java.lang.String id)
public int getItemImage(java.lang.String id, int index)
public String getImageName(int index)
public void setItemImage(java.lang.String id, java.lang.String im)
public void setItemImage(java.lang.String id, java.lang.String im1, java.lang.String im2)
public int getLevel(java.lang.String id)
public boolean isOpen(java.lang.String id)
public boolean hasChildren(java.lang.String id)Available in full version only
public void setColor(java.lang.String pattern, java.lang.String strColor)
public void deleteSelectedItem()
public void deleteAllItems()
public void deleteItem(java.lang.String id)
public void deleteItem(java.lang.String id, boolean isSel)
public void deleteWithoutChildren(java.lang.String id)
public void insertNewChild(java.lang.String pId, java.lang.String id, java.lang.String label, java.lang.String action)
public void insertNewChild(java.lang.String pId, java.lang.String id, java.lang.String label, java.lang.String action, java.lang.String options)
public void insertNewChild(java.lang.String pId, java.lang.String id, java.lang.String label, java.lang.String action, java.lang.String im0, java.lang.String im1)
public void insertNewChild(java.lang.String pId, java.lang.String id, java.lang.String label, java.lang.String action, java.lang.String im0, java.lang.String im1, java.lang.String options)
public void insertNewNext(java.lang.String pId, java.lang.String id, java.lang.String label, java.lang.String action)
public void insertNewNext(java.lang.String pId, java.lang.String id, java.lang.String label, java.lang.String action, java.lang.String options)
public void insertNewNext(java.lang.String pId, java.lang.String id, java.lang.String label, java.lang.String action, java.lang.String im0, java.lang.String im1)
public void insertNewNext(java.lang.String pId, java.lang.String id, java.lang.String label, java.lang.String action, java.lang.String im0, java.lang.String im1, java.lang.String options)
public void insertNewRoot(java.lang.String id, java.lang.String label, java.lang.String action)
public void insertNewRoot(java.lang.String id, java.lang.String label, java.lang.String action, java.lang.String options)
public void insertNewRoot(java.lang.String id, java.lang.String label, java.lang.String action, java.lang.String im0, java.lang.String im1)
public void insertNewRoot(java.lang.String id, java.lang.String label, java.lang.String action, java.lang.String im0, java.lang.String im1, java.lang.String options)
public void deleteAllNext(java.lang.String id)Available in full version only
Expanding/collapsing functions
public void expandAllChildren(java.lang.String id)
public void expandAllSelectedChildren(java.lang.String id)
public void collapseAllChildren(java.lang.String id)
public int doCut()
public int doPaste(java.lang.String id)
public int doPaste(java.lang.String id, java.lang.String new_ids)
public void clearCut()
User specified data manipulation functions
public boolean setUserData(java.lang.String id, java.lang.String key, java.lang.String value)
public String getUserData(java.lang.String id, java.lang.String key)
Checkboxes operations functions
public boolean isItemChecked(java.lang.String id)Available in full version only
public void setCheck(java.lang.String id, boolean isCheck)Available in full version only
public void setCheckEnabled(java.lang.String id, int isEnable)Available in full version only
public String getAllChecked(boolean isSubitems)Available in full version only
public void setSubChecked(java.lang.String id, boolean isCheck)Available in full version only
public String getAboveChecked(java.lang.String id)Available in full version only
public String getBelowChecked(java.lang.String id)Available in full version only
public String getCheckedParents(java.lang.String id)Available in full version only
public String getCheckedChildren(java.lang.String id)Available in full version only
public void updateItem(java.lang.String id)Available in full version only
public void storeTree(java.lang.String treeName)Available in full version only
public void dropStaticTree(java.lang.String treeName)Available in full version only
public boolean restoreTree(java.lang.String treeName)Available in full version only
public void reloadTree(java.lang.String docName)Available in full version only
public void loadXML(java.lang.String xml)
public void showApplet(java.lang.String name, int x, int y, int width, int height)
public void hideApplet()
public Applet getChildApplet()
public void moveSelectionRight()Available in full version only
public void moveSelectionLeft()Available in full version only
public void moveSelectionUp()Available in full version only
public void moveSelectionDown()Available in full version only
public String getAppletInfo()
public void updateTree()
public String getTreeDeclaration()
public void enablePopup(boolean b)Available in full version only
public TreeMenu createMenu(java.lang.String menu_fun, java.lang.String menu_pre_fun)
public void sortChildrenByName(java.lang.String id)