ElegantJBeans – Trees

 

 

Programmers’ Guide

 

 


Table of Content

 

1    Preface  4

1.1    Purpose of this document  4

1.2    Assumptions  4

1.3    Document Organization   4

1.4    Conventions Used   5

2    About ElegantJ Trees  6

2.1    What’s New    6

2.2    Toolkit  6

3    Features  7

3.1    ElegantJ AWT Tree  7

3.1.1    Appearance and Visual Appeal 7

3.1.2    Navigation and Use  8

3.1.3    Data Handling and Management  8

3.1.4    Setup and Configure  8

3.1.5    Validation  9

3.2    ElegantJ JFC Tree  9

3.2.1    Appearance and Visual Appeal 9

3.2.2    Navigation and Use  11

3.2.3    Data Handling and Management  11

3.2.4    Setup and Configure  12

3.2.5    Validation  12

4    Product Demo   13

4.1    Installing Demo   13

4.2    View Demo   13

5    Installation and Registration   14

5.1    Prerequisite  14

5.2    Installation Procedure  14

5.3    Using with Different IDEs  15

5.3.1    Borland JBuilder  15

5.3.2    Oracle JDeveloper  16

5.4    Getting Registered   16

5.4.1    How to Purchase  16

5.4.2    Using with Graphical User Interface of IDE  17

5.4.3    Using directly with source code  17

6    Programmers’ Guide  18

6.1    ElegantJ AWT Tree  18

6.1.1    Creating an instance of AWTTree  18

6.1.2    Applying General Appearance and formatting  19

6.1.3    Configuring node attributes for whole tree  19

6.1.4    Configuring level wise node attributes  21

6.1.5    Setting up the Root  24

6.1.6    Setting Row height attributes  24

6.1.7    Configuring Selection functionality  24

6.1.8    Configuring Editing  25

6.1.9    Using Insert key and Delete key  25

6.1.10     Configuring Drag and Drop  26

6.1.11     Configuring Search Panel 26

6.1.12     Handling Searching  27

6.1.13     Configuring Popup Menu  28

6.1.14     Configuring Check Box Tree and features under Check Box tree  28

6.1.15     Configuring Child-Parent relationship in Checkbox-Tree  29

6.1.16     Restricting duplicate nodes  30

6.1.17     Making use of Advanced Implementation for creating custom Cell Renderers  30

6.1.18     AWTTree Listeners and Events  31

6.2    ElegantJ JFC Tree  31

6.2.1    Creating an instance of JFCTree  31

6.2.2    Configuring General Appearance  33

6.2.3    Configuring level wise node attributes  35

6.2.4    Configuring root of tree  38

6.2.5    Configuring row attributes  39

6.2.6    Configuring selection  39

6.2.7    Configuring Editing  40

6.2.8    Use of Insert key and Delete key  40

6.2.9    Configuring drag and drop  41

6.2.10     Configuring search panel 41

6.2.11     Searching for Information  42

6.2.12     Handling Sorting  44

6.2.13     Setting Visibility of Popup menu  44

6.2.14     Configuring Check Box Tree and features under Check Box tree  45

6.2.15     Configuring Child-Parent relationship in Checkbox-Tree  46

6.2.16     Restricting duplicate nodes  46

7    Product and Support Information   48

 

 

 


 

1       Preface

This preface describes the document. The preface contains the following sections:

 

 

Section

Page

Purpose of this document

4

Assumptions

4

Document Organization

4

Conventions Used

5

 

 

1.1  Purpose of this document

The purpose of this document is to provide the fundamental skills necessary to productively install, program, integrate, and use the ElegantJ DataTree. This document provides both programmer and user perspective to the audience.

 

 

1.2  Assumptions

This manual assumes that readers are having reasonable level of exposure to fundamentals of Java programming and various architectures.

 

 

1.3  Document Organization

This document is organized as described in following tables.

Table 1 – Organization of the document

Chapter

Contents

About ElegantJ Trees

Ø       What’s New

Ø       Toolkit

Features

Ø       ElegantJ AWT Tree

Ø       ElegantJ JFC Tree

Product Demo

Ø       Installing Demo

Ø       View Demo

Installation and Registration

Ø       PrerequisiteInstallation ProcedureUsing with Different IDEsGetting Registered

Programmers’ Guide

Ø       Core components and definitions for different tree beans

Ø       Programmer's guide to frequently asked questions

 

 

 

 

 

 

1.4  Conventions Used

 

File

Italic (slanted) type indicates variable values, instruction operands.

[ | ]

{ | }

In syntax definitions, brackets indicate items that are optional and braces indicate items that are required. Vertical bars separating items inside brackets or braces indicate that you choose one item from among those listed.

. . .

In syntax definitions, a horizontal ellipsis indicates that the preceding item can be repeated one or more times.

//

An explanation of a particular function performed by preceding code.

 


 

2       About ElegantJ Trees

ElegantJ Trees Bean has all the features that you need to create a dynamically created data driven tree.  It provides the best performance to suit your need of large number of nodes and levels in a tree.  This Java Bean can handle large volume of data at unmatched speeds.

 

Ø       Completely configurable.

Ø       Use any component as node.

Ø       Format controls for whole tree, for selected level as well as a node.

Ø       Use ready to use functionalities of Search Panel and Sort.

Ø       Also, functionality of insert, delete and add node.

 

Using ElegantJ Trees Bean, you can manage more information in the minimum space.

 

2.1       What’s New

This collection is derived from our Tree collection.  ElegantJ Trees is a whole new Java Beans collection designed to cater when you wish to work with data in tree form.  Use this bean specially when you do not need Data Aware Trees.  Read Overview for more information.

 

In case you are using evaluation, an Evaluation Dialog used to popup every 10 minutes.  This dialog will now appear only once, making evaluation without interruption.

 

2.2       Toolkit

ElegantJ Trees Bean is shipped with two set of Beans - ElegantJ Trees Beans and ElegantJ Data Providers Beans.

 

ElegantJ Trees Beans

 

ElegantJ Trees Beans includes AWT and JFC Tree Beans –

 

Ø       AWT Tree Beans

o        ElegantJ AWT Tree (awttree.jar)

Ø       JFC Tree Beans

o        ElegantJ JFC Tree (jfctree.jar) 

 


 

3       Features

3.1  ElegantJ AWT Tree

ElegantJ AWT JAVA Tree Beans provide you with match-less features - Be it performance, visual appeal or data handling.  Features of AWTTree –

 

3.1.1Appearance and Visual Appeal

Ø       General appearance control features like background, borders, fonts, cursor type, etc.

o        Background of tree can be set.

o        Background color for node that is selected and not selected can be set.

o        Text color for node that is s elected and not selected can be set.

o        In this JavaBean, you can set Font properties.

o        Border color for node that is selected and not selected.

o        Locale can be set in ElegantJ AWT Tree Java Bean.

o        Cursor styles can be customized.

Ø       Appearance control - Level wise or for whole tree.

o        You can set visual properties for entire tree or for a level of node.

o        The properties that you can set are -

§         Background color for Selected / Not selected node

§         Text color for Selected / Not selected node

§         Image for opened (expanded) node / closed (collapsed) node and Leaf node.

§         Border color for selected node.

o        Cell Renderers and Cell Editors can be applied to whole tree as well as to selected level using ElegantJ AWT Tree JavaBean.

o        You can choose from following cell renderers that come with this Java Bean,

§         Check box cell renderer

§         Choice (combo box) cell renderer

§         Label cell renderer

§         Text area cell renderer.

o        You can choose from following cell editors that come with this Java Bean,

§         Check box cell editor

§         Choice (combo box) cell editor

§         Text editor and 

§         Text area cell editor.

Ø       Appearance for line that connects nodes.

o        A line connects nodes.  You can set appearance for this line using ElegantJ AWT Tree Java Beans.

o        You may have a line that is straight or dotted.  You can set color of line too.

Ø       With this JavaBean, you can set gap between each line of information.

o        You have option to set gap between two row of information.  Gap can be reduced to have more information in available area.  In ElegantJ JavaBeans, gap can be increased to make information easier to read.  It is set in terms of pixels.

Ø       Root / root handle - Make it Visible / Invisible.

o        If there is a need of hiding root, you can do it using ElegantJ AWT Tree JavaBeans.

o        ElegantJ AWT Tree Java Beans also gives facility to hide root handle.

 

3.1.2Navigation and Use

Ø       Option to select single node or multiple nodes.

o        Your application can provide ability for selection of single node as well as multiple nodes.

Ø       Insert and Delete a node using Insert and Delete key respectively on the keyboard.  If used with Tree, this will insert / delete a record respectively in the database.

 

Ø       In ElegantJ AWT Tree Java Bean, F2 key stroke can be used to start editing of a node.  You can get the same functionality on mouse-clicks.  Also setup number of mouse-clicks required to start editing.

 

Ø       Drag-and-drop functionality for tree nodes.  Child branches, moved with respective parent.

 

3.1.3Data Handling and Management

Ø       Ready to use Right-click menu with frequently used options.  Customization is possible.

o        ElegantJ AWT Tree Java Bean is shipped with feature to implement Right click menu having four options (Add Child, Insert Node, Delete Node and Edit Node).

o        If needed, APIs are available as part of ElegantJ AWT Tree JavaBean can be used to create menu as per requirement.

Ø       Ready to use, feature packed Search Panel.  Search at selected level or entire tree.

o        Availability of ready-to-use search panel.  You can locate it on the top or bottom of the screen.

§         Search is the first step for to view and manage information.  Using ElegantJ AWT Tree Java Bean, your application can have feature to search for a text in a tree.  Search can be performed on entire tree or at selected level.

§         Search can be performed downwards from first node / selected node, upwards from last node / selected node.

§         In ElegantJ AWTTrees JavaBean, search can be performed for total equality, availability of search string as part of value in tree nodes, for value in tree nodes starting with search string as well as for value in tree nodes ending with search string.

§         Search is conducted with or without case sensitivity.

 

3.1.4Setup and Configure

Ø       Using ElegantJ AWT Tree Java Bean, you can use different cell editors and cell renderers.  To make things faster, you can have same cell editor or cell renderer for entire tree or different cell editor or renderer at different levels.

o        Node Cell Renderer: In ElegantJ AWTTree Java Bean, you can set cell renderer to whole tree or level wise.  That is, different cell renderer for nodes for different level.  Bean is shipped with following renderers -

§         Checkbox cell renderer

§         Choice (combo box) cell renderer

§         Label cell renderer

§         Text area cell renderer

o        Node Cell Editor: In ElegantJ AWTTree JavaBean, you can set cell editor to whole tree or level wise.  That is, different cell editor for nodes for different level.  Bean is shipped with following renderers -

§         Checkbox cell editor

§         Choice (combo box) cell editor

§         Text editor

§         Text area cell editor

Ø       Facility to setup Check box tree with child parent relationship.  Developer can give user, a functionality to have entire tree as a check box tree.  This feature of ElegantJ AWT Tree Bean has other functionalities too.  You can have entire tree with check boxes.

o        You can have entire tree with check boxes.

o        ElegantJ AWTTree maintains Child Parent relationship.  This means,  if a user checks any node then all its children (recursive) becomes checked.  If user unchecks any node then all the parents (recursive) become unchecked, so every checked node has all the children (recursive) as checked and every unchecked node has all the parents (recursive) as unchecked.

o        ElegantJ AWTTree Java Bean facilitates user to get the checked or unchecked nodes for the whole tree or at specific level.

 

3.1.5Validation

Ø       If required, validations can be implemented for not accepting two nodes with same value (name) for any parent node.

 

3.2  ElegantJ JFC Tree

Talking about features, ElegantJ JFC Trees JavaBean is packed with ever-wanted set of power-features.  It is about visual appearance or navigation or customizing or data handling.  All at high speeds.  You can add a lot to your application using ElegantJ JFC Trees Java Bean.

 

3.2.1Appearance and Visual Appeal

Ø       General appearance like background, borders, fonts, cursor type, etc.

o        In this Java Bean, you can set basic look and feel properties - Background, Foreground, Font, Locale, Cursor style, enable / disable, Visible / Invisible.  

o        Swing Look and feel properties that this JavaBean support are - Lightweight, Opaque, Tool-tip text, Double buffering, Ability to receive and manage Focus, Border, Auto-scrolling.

Ø       In this Java Bean, you can set appearance control based on level.

o        You can set visual properties for a level of node.

o        Level wise node attributes available in ElegantJ JFCTree Java Bean are,

§         Background non selection color

§         Background selection color

§         Text non selection color

§         Text selection color

§         Border selection color

§         Opened image icon

§         Closed image icon

§         Leaf image icon

§         Cell renderer

§         Cell editor

o        You can apply same cell renderers and cell editors to whole tree as well as different cell renderers and cell editors at different levels.

o        You can choose from following cell renderers that come with ElegantJ JFCTree JavaBean,

§         Boolean cell renderer

§         Checkbox cell renderer

§         Choice cell renderer

§         Color cell renderer

§         Date cell renderer

§         Default cell renderer

§         Icon cell renderer

§         MultiLine cell renderer

§         MultiOption cell renderer

§         Number cell renderer

§         Progress cell renderer

§         RadioButton cell renderer

§         Text cell renderer

o        You can choose from following cell editors that come with ElegantJ JFCTree Java Bean,

§         Boolean cell editor

§         Checkbox cell editor

§         Choice cell editor

§         Color cell editor

§         Date cell editor

§         Default cell editor

§         Icon cell editor

§         MultiLine cell editor

§         MultiOption cell editor

§         Number cell editor

§         RadioButton cell editor

§         Slider cell editor

Ø       Gap between each line of information.

o        In ElegantJ JFCTrees Java Bean, you have option to set gap between two row of information.  Gap can be reduced to have more information in available area.  Gap can be increased to make information easier to read.

o        This JavaBean allows you to set number of rows to be displayed without scrollbars.

Ø       Appearance of root / root handle.  Make it invisible to give a feel of independent trees.

o        If there is a need of hiding root, you can do it using ElegantJ JFCTree JavaBeans.  

o        ElegantJ JFCTree Java Beans also gives facility to hide root handle.

 

3.2.2Navigation and Use

Ø       Option to select single node or multiple nodes.

o        Your application can have feature to be able to select one cell as well as multiple cells.  This JavaBean supports selection that is single, multiple or set of selections.

Ø       Insert and Delete a node using Insert and Delete key.  For Data Tree, this will insert / delete a record respectively.

Ø       In ElegantJ JFCTree Java Bean, F2 key stroke can be used to start editing of a node.  Same functionality can be implemented on mouse-clicks.

Ø       ElegantJ JFCTrees JavaBean provides Drag-and-drop functionality for tree nodes.  For node with child branches, it moves all the branches along with respective parent.

Ø       Ready to use Fully featured Search Panel.

o        Search is the first step for to view and manage information.  Using ElegantJ JFCTree Java Bean, your application can have feature to search for a text in a tree.  You can perform search on selected level or entire tree.

o        Search can be performed downwards from first node or selected node, upwards from last node or selected node.

o        Search can be performed for - 

§         Exact match with search string

§         For nodes having search string

§         For nodes starting with search string, as well as 

§         For nodes ending with search string.

o        In this JavaBean, you have an option to conduct a search with or without case sensitivity

Ø       Ready to use and customizable Right-click menu with frequently used options.

o        ElegantJ JFCTree JavaBean is shipped with feature of Right click menu having options - Add Child, Insert Node, Delete Node, Edit Node as well as Sort.  ElegantJ JFCTree Java Bean can be used to create menu as per requirement.

Ø       AutoSave with Accidental Interruption.  If a node is being edited, and control is transferred out of the node, the changed work will be automatically saved.

Ø       Auto-scroll node's descendents when a node is expanded.  Available as Customizable property.

 

3.2.3Data Handling and Management

Ø       Search for a text on node or entire tree.  Ready to use Search Panel. 

o        Search is the first step for to view and manage information.  Using ElegantJ JFCTree Java Bean, your application can have feature to search for a text in a tree.  You can perform search on selected level or entire tree.

o        Search can be performed downwards from first node or selected node, upwards from last node or selected node.

o        Search can be performed for - 

§         Exact match with search string

§         For nodes having search string

§         For nodes starting with search string, as well as 

§         For nodes ending with search string.

o        In this JavaBean, you have an option to conduct a search with or without case sensitivity.

Ø       ElegantJ JFC Tree Java Bean has feature to sort children of any node or whole tree in ascending or descending order. 

 

3.2.4Setup and Configure

Ø       Node Cell Renderers and Renderers.  Using ElegantJ Trees Java Bean, you can use different editors and renderers.  To make things faster, you can have same cell editor and cell randerer for entire tree as well as different ones for different levels.

Node Cell Renderer

o        In ElegantJ JFCTree Java Bean, you can set cell renderer to whole tree or level wise.  That is, different cell renderer for nodes for different level.  Bean is shipped with following renderers -

§         Boolean cell renderer

§         Checkbox cell renderer

§         Choice cell renderer

§         Color cell renderer

§         Date cell renderer

§         Default cell renderer

§         Icon cell renderer

§         MultiLine cell renderer

§         MultiOption cell renderer

§         Number cell renderer

§         Progress cell renderer

§         RadioButton cell renderer

§         Text cell renderer

Node Cell Editor

o        In ElegantJ JFCTree JavaBean, you can set cell editor to whole tree or level wise.  That is, different cell editor for nodes for different level.  Bean is shipped with following renderers -

§         Boolean cell editor

§         Checkbox cell editor

§         Choice cell editor

§         Color cell editor

§         Date cell editor

§         Default cell editor

§         Icon cell editor

§         MultiLine cell editor

§         MultiOption cell editor

§         Number cell editor

§         RadioButton cell editor

§         Slider cell editor

Ø       Facility to setup Check box tree with child parent relationship.  Set entire tree as a check box tree.  This feature of ElegantJ JFC Tree Beans has other functionalities too.  More»

Ø       You have option to make a tree View Only.  It can also be set for Edit (where user can make changes into existing tree).

Ø       Node can be opened for edit by pressing F2 key.  Same functionality can be implemented through mouse-clicks.  You can setup number of mouse clicks for Editing.

 

3.2.5Validation

Ø       If required, validations can be implemented for not accepting two nodes with same value (name) for any parent node.


 

4       Product Demo

4.1  Installing Demo

Extracted file(archive) contains demos directory.  All the demos are located in this demos directory. 

Your classpath environment variables must be set correctly in order to run the demos.  For windows users we have provided rundemo.bat file which will run demo directly.  All Demo Applets contain HTML file to run an Applet associated with it. or more information on how to set classpath, refer Installation procedure.

 

4.2  View Demo

AWT Tree applet

Description: This applet demonstrates use of ElegantJ AWT Tree bean.

 

To run this demo application,

 

Go to ElegantJTrees\demos\applets\awt directory, and then open treesawtapplet.html in any java compliant web browser.

 

 

AWT Tree application

Description: This application demonstrates use of ElegantJ AWT Tree bean.

 

To run this demo application,

 

Go to ElegantJTrees\demos\applications\awt directory,

Then execute 

java -jar treesawtapp.jar 

command.

 

JFC Tree application

Description: This application demonstrates use of ElegantJ JFC Tree bean.

 

To run this demo application,

 

Go to ElegantJTrees\demos\applications\jfc directory, then execute java -jar treesjfcapp.jar command.

 

Note: For windows users we have provided the rundemo.bat file to run respective demo application.

 


 

5       Installation and Registration

 

5.1  Prerequisite

Before installing ElegantJBeans, please ensure that your computer system and development environment are setup and working as per expectations. Person evaluating ElegantJBeans is expected to be able to write and execute simple JAVA applications.

We provide free pre-purchase technical support to help you complete process of evaluation.  Mail to support@elegantJBeans.com for pre-purchase technical support.

 

To be able to use ElegantJBeans, your computer systems are required to have -

 

Ø       An IDE that supports Java 2 or higher, or

Ø       JDK 1.2.2 or higher

 

Please note that evaluation version of ElegantJBeans cannot be deployed for commercial, non-commercial or any other purpose in any possible way.  You may not build any software, applets or applications for distribution with evaluation version of ElegantJBeans.

 

This evaluation version is to be solely used by you to evaluate suitability of ElegantJBeans for your needs.  For more details please go through License Agreement.

 

5.2  Installation Procedure

On extracting ejtrees_v1.zip, following directories will be created inside ElegantJTrees directory -

 

Directory [jars] contains Jar file(s)

Directory [demos] contains demo application(s) with source code

Directory [docs] contains path for document(s) access

 

 

Installing on Windows 95/98

 

To include ElegantJ Beanery in CLASSPATH, add following statement to your autoexec.bat file,

 

set CLASSPATH= %CLASSPATH%;C:\ELEGANTJ\<ELEGANTJ_BENARY_HOME>

\jars\<ELEGANTJ_BEAN>.jar;

 

Restart Windows to make changes effective.

 

 

Installing on Windows NT / 2000

 

Go to Control Panel and select System. You will find environment variables on Environment tab in Windows NT systems and on Advanced tab in Windows 2000 systems.

 

Find CLASSPATH environment variable or create it.

To include ElegantJ Beanary in the CLASSPATH, specify or add following value for variable -

 

[EXISTING-CLASSES];C:\<ELEGANTJ_BEANARY_HOME>\jars\<ELEGANTJ_BEAN>.jar

 

 

Installing on UNIX / Linux

 

Before you begin using ElegantJ Beanary, you must manually configure CLASSPATH environment variable.  CLASSPATH must point to the location of classes and installation directory.

 

For example, to set CLASSPATH for ElegantJ Beanary,

 

 

setenv CLASSPATH .:/usr/local/<ELEGANTJ_BEANARY_HOME>/jars/

<ELEGANTJ_BEAN>.jar:

 

If you are using Bourne Shell, commands are,

 

CLASSPATH= $CLASSPATH:.:/usr/local/<ELEGANTJ_BEANARY_HOME>/jars/

<ELEGANTJ_BEAN>.jar:export CLASSPATH

 

 

5.3  Using with Different IDEs

 

5.3.1Borland JBuilder

Follow the steps given below to create a new category and install Bean into Borland JBuilder.

 

Create a New Category

Ø       Click menu Tools > Configure Palette. It opens Palette Properties dialog box.

Ø       Click Add button. It opens Add Page Dialog box. Specify name (for example ElegantJ) and click OK.  New Category gets created.

 

Create New Library and Install / Import Bean

 

Ø       On Palette Properties dialog box, click Pages tab.  Select Newly created page (for example ElegantJ).

Ø       Click button Select Library. Select a Different Library dialog box opens.

Ø       Click New button on Select a Different Library dialog box. New Library Wizard dialog box opens.

Ø       Specify name for library and click Add button.  Select One or More Directory dialog box opens.

Ø       Select directory where jar files are located, or select jar file to be imported. Click OK. Dialog box gets closed and New Library Wizard dialog box appears in front.

Ø       Click OK on New Library Wizard. It opens Select a Different Library dialog box.

Ø       Confirm that newly created library is selected. Click OK. It opens Add Components under Palette Properties.

Ø       Click Add from Selected Libraries button.  It opens Results dialog box, click OK.

Ø       Results dialog box disappears.  Click OK on Palette Properties dialog box.

Ø       Beans are ready to use.

 

 

5.3.2Oracle JDeveloper

Follow the steps given below to import ElegantJBeans in Oracle JDeveloper.

 

To Import beans into a project

 

Ø       Click menu Project > Project Settings.  It opens Project Settings dialog box.

Ø       Click Libraries entry appearing on the pane on left side.

Ø       Click New button.  It opens New Library dialog box.

Ø       In Library Name entry box, specify Library name. In Location entry box, specify location where you want the library to be located.  In Class Path entry box, specify path of jar file of Bean. Browse the location by clicking Edit... button if required.

Ø       Click OK. The library you selected appears in Available Libraries list of Project Properties dialog box.

Ø       Select the library you want and click > button to add it to Selected Libraries list.

Ø       Click menu Tools > Configure Component Palette.  It opens Configure Component Palette dialog box.

Ø       To create a new palette page, click New Page... button.  It opens New Palette Page dialog box.  Specify Page Name and Page Type.  Click OK.  A new page with specified name will be created.

 

To add component to page

 

Ø       On Configure Component dialog box, from Pages list, select the page and click Add Component button.  It opens Add JavaBeans dialog box with available libraries.

Ø       Select a library from Library combo box.

Ø       Browse the hierarchy and select a component.  It displays preview of icon for selected component.  Click OK.  It shows Palette Confirmation dialog box.

Ø       Click Yes on Palette Confirmation dialog box to complete the process.

Ø       Beans are ready to use.

 

 

5.4  Getting Registered

 

5.4.1How to Purchase

You can purchase a license from our web site www.elegantJBeans.com

You can also contact our sales team sales@elegantJBeans.com

 

On purchasing a license, you will receive a mail having your license key.

 

License key can be applied to ElegantJ Java Bean using any of the following ways,

 

Ø       Using with Graphical User Interface of IDE

Ø       Using directly with source code

 

5.4.2Using with Graphical User Interface of IDE

While Designing an application or an applet graphically in an Integrated Development Environment, you will find a property named licensekey along with other properties of the bean.  Specify key (serial number) in LicenseKey Property.

 

Note: Instead of typing the license key, we suggest you to copy the license key from mail and paste it at required place.  Make sure that the selection does not have any leading or trailing spaces.

 

 

5.4.3Using directly with source code

 

When you use the Bean within code, you need to set the key by providing value in setLicenseKey Method.

 

Note: Instead of typing the license key, we suggest you to copy the license key from mail and paste it at required place.  Make sure that the selection does not have leading or trailing spaces.

 

 

ClassName object = new ClassName();

object.setLicenseKey("LICENSE_KEY");

 

 

Example

 

AWTTree awtTree = new AWTTree();

awtTree.setLicenseKey("LICENSE_KEY");

 

 


 

6       Programmers’ Guide

6.1  ElegantJ AWT Tree

6.1.1Creating an instance of AWTTree

Ø       AWTTree can be created in following ways, 

 

First way:

 

com.elegantj.awt.tree.AWTTree awtTree =

new com.elegantj.awt.tree.AWTTree();

 

Creates ElegantJ AWTTree using default constructor.

 

Second way:

 

com.elegantj.awt.tree.AWTTreeNode root =

new com.elegantj.awt.tree.AWTTreeNode("Root");

com.elegantj.awt.tree.AWTTree awtTree =

new com.elegantj.awt.tree.AWTTree(root);

 

Creates ElegantJ AWTTree with specified root node.

 

Third way:

 

Object rootUserObject = "Root";

com.elegantj.awt.tree.AWTTreeNode nodes[] = {

new com.elegantj.awt.tree.AWTTreeNode("node1"),

new com.elegantj.awt.tree.AWTTreeNode("node2"),

new com.elegantj.awt.tree.AWTTreeNode("node3")};

com.elegantj.awt.tree.AWTTree awtTree =

new com.elegantj.awt.tree.AWTTree(rootUserObject, nodes);

 

Create an ElegantJ AWTTree with specified root's user object and AWT Tree Nodes array.

 

Fourth way:

 

Object rootUserObject = "Root";

java.util.Vector nodes = new java.util.Vector();

nodes.addElement(new com.elegantj.awt.tree.AWTTreeNode("node1"));

nodes.addElement(new com.elegantj.awt.tree.AWTTreeNode("node2"));

nodes.addElement(new com.elegantj.awt.tree.AWTTreeNode("node3"));

com.elegantj.awt.tree.AWTTree awtTree =

new com.elegantj.awt.tree.AWTTree(rootUserObject, nodes);

 

Create an ElegantJ AWTTree with specified root's user object and AWT Tree Nodes vector.

 

6.1.2Applying General Appearance and formatting

Ø       To set value for background color for tree

 

awtTree.setTreeBackground(java.awt.Color.cyan); // sets the background color as cyan

 

Ø       To set visibility property for tree

 

awtTree.setVisible(true); // makes the tree visible

 

Ø       To set enability property

 

awtTree.setEnabled(true); // sets enability property as true

 

Ø       To set Locale

 

awtTree.setLocale(java.util.Locale.ENGLISH);  // sets locale as English

 

Ø       To set cursor type

 

awtTree.setCursor

(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); 

// sets cursor as hand cursor

 

Ø       To set Tree dimension (bounds)

 

int x = 5;

int y = 5;

int width = 300;

int height = 200;

awtTree.setBounds(x, y, width, height);

 

Ø       To set Border properties

 

awtTree.setBorder(new com.elegnatj.editors.AWTBorder

(com.elegnatj.editors.AWTBorder.SIMPLE, 2, java.awt.Color.black));  // sets SIMPLE, 2 pixel wide

and black colored border

 

6.1.3Configuring node attributes for whole tree

ElegantJ AWTTree provides whole tree node's attributes like -

 

Ø       Background non selection color

Ø       Background selection color

Ø       Text non selection color

Ø       Text selection color

Ø       Border selection color

Ø       Expanded image icon

Ø       Collapsed image icon

Ø       Leaf image icon

Ø       Cell renderer

Ø       Cell editor

 

Ø       To set background non selection color for whole tree nodes

 

awtTree.setBackgroundNonSelectionColor(java.awt.Color.cyan); 

// sets background non selection color for whole tree nodes as cyan

 

Ø       To set background selection color for whole tree nodes

 

awtTree.setBackgroundSelectionColor(java.awt.Color.blue);

// sets background selection color for whole tree nodes as blue

 

Ø       To set text non selection color for whole tree nodes

 

awtTree.setTextNonSelectionColor(java.awt.Color.black); 

// sets text non selection color for whole tree nodes as black

 

Ø       To set text selection color for whole tree nodes

 

awtTree.setTextSelectionColor(java.awt.Color.white);

// sets text selection color for whole tree nodes as white

 

Ø       To set border selection color for whole tree nodes

 

awtTree.setBorderSelectionColor(java.awt.Color.black);

// sets border selection color for whole tree nodes as black

 

Ø       To set expanded image for expanded nodes by specifying image path

 

String expandedImagePath = "c:/images/expanded.gif";

awtTree.setExpandedImageIcon(expandedImagePath);

 

Ø       To set expanded image for expanded nodes by specifying java.awt.Image object

 

java.awt.Image expandedImage = java.awt.Toolkit.getDefaultToolkit().

createImage(getClass().getResrouce("expanded.gif"));

awtTree.setExpandedImageIcon(expandedImage);

 

Ø       To set collapsed image for collapsed nodes by specifying image path

 

String collapsedImagePath = "c:/images/collapsed.gif";

awtTree.setCollapsedImageIcon(collapsedImagePath);

 

Ø       To set collapsed image for collapsed nodes by specifying java.awt.Image object

 

java.awt.Image collapsedImage = java.awt.Toolkit.getDefaultToolkit().

createImage(getClass().getResrouce("collapsed.gif"));

awtTree.setCollapsedImageIcon(collapsedImage);

 

Ø       To set leaf image for leaf nodes by specifying image path

 

String leafImagePath = "c:/images/leaf.gif";

awtTree.setLeafImageIcon(leafImagePath);

 

Ø       To set leaf image for leaf nodes by specifying java.awt.Image object

 

java.awt.Image leafImage = java.awt.Toolkit.getDefaultToolkit().

createImage(getClass().getResrouce("leaf.gif"));

awtTree.setLeafImageIcon(leafImage);

 

Ø       To set cell renderer for whole tree,

 

You will receive following cell renderers for ready to use with this package,

 

o        Checkbox cell renderer –

com.elegantj.awt.tree.CheckboxAWTTreeCellRenderer

o        Choice (combo box) cell renderer –

com.elegantj.awt.tree.ChoiceAWTTreeCellRenderer

o        Text cell renderer –

com.elegantj.awt.tree.DefaultAWTTreeCellRenderer

o        Text area cell renderer –

com.elegantj.awt.tree.TextAreaAWTTreeCellRenderer

 

com.elegantj.awt.tree.CheckboxAWTTreeCellRenderer renderer = new

com.elegantj.awt.tree.CheckboxAWTTreeCellRenderer();

awtTree.setCellRenderer(renderer);

 

which sets checkbox as a cell renderer for whole tree.

 

Ø       To set the cell editor for whole tree,

 

You will receive following cell editors for ready to use with this package, 

 

o        Checkbox cell editor –

com.elegantj.awt.tree.CheckboxAWTTreeCellEditor

o        Choice (combo box) cell editor –

com.elegantj.awt.tree.ChoiceAWTTreeCellEditor

o        Text editor –

com.elegantj.awt.tree.DefaultAWTTreeCellEditor

o        Text area cell editor –

com.elegantj.awt.tree.TextAreaAWTTreeCellEditor

 

com.elegantj.awt.tree.CheckboxAWTTreeCellEditor editor = new

com.elegantj.awt.tree.CheckboxAWTTreeCellEditor();

awtTree.setCellEditor(editor);

 

which sets checkbox as a cell editor for whole tree.

 

6.1.4Configuring level wise node attributes

ElegantJ AWTTree provides level wise tree node's attributes like -

 

Ø       Background non selection color

Ø       Background selection color

Ø       Text non selection color

Ø       Text selection color

Ø       Border selection color

Ø       Expanded image icon

Ø       Collapsed image icon

Ø       Leaf image icon

Ø       Cell renderer

Ø       Cell editor

 

Ø       To set background non selection color for nodes at specific level

 

int level = 1;

Color backgroundNonSelectionColor = java.awt.Color.cyan;

awtTree.setBackgroundNonSelectionColorAt

(level, backgroundNonSelectionColor);

// sets background non selection color as cyan for nodes at level 1

 

Ø       To set background selection color for nodes at specific level

 

int level = 1;

Color backgroundSelectionColor = java.awt.Color.blue;

awtTree.setBackgroundSelectionColorAt

(level, backgroundSelectionColor);

// sets background selection color as blue for nodes at level 1

 

Ø       To set text non selection color for nodes at specific level

 

int level = 1;

Color textNonSelectionColor = java.awt.Color.black;

awtTree.setTextNonSelectionColorAt

(level, textNonSelectionColor);

// sets text non selection as black for nodes at level 1

 

Ø       To set text selection color for nodes at specific level

 

int level = 1;

Color textSelectionColor = java.awt.Color.white;

awtTree.setTextSelectionColorAt

(level, textSelectionColor);

// sets text selection as white for nodes at level 1

 

Ø       To set expanded image for expanded nodes at specific level using image path 

 

int level = 1;

String expandedImagePath = "c:/images/expanded.gif";

awtTree.setExpandedImageIconAt

(level, expandedImagePath);

// sets expanded image for expanded nodes at level 1 using image path

 

Ø       To set expanded image for expanded nodes at specific level using java.awt.Image

 

int level = 1;

java.awt.Image expandedImage = java.awt.Toolkit.getDefaultToolkit().

createImage(getClass().getResrouce("expanded.gif"));

awtTree.setExpandedImageIconAt

(level, expandedImage);

// sets expanded image using java.awt.Image for for expanded nodes at level 1

 

Ø       To set collapsed image for collapsed nodes at specific level using image path

 

int level = 1;

String collapsedImagePath = "c:/images/collapsed.gif";

awtTree.setCollapsedImageIconAt

(level, collapsedImagePath);

// sets collapsed image for collapsed nodes at level 1 using image path

 

Ø       To set collapsed image for collapsed nodes at specific level using java.awt.Image

 

int level = 1;

java.awt.Image collapsedImage = java.awt.Toolkit.getDefaultToolkit().

createImage(getClass().getResrouce("collapsed.gif"));

awtTree.setCollapsedImageIconAt

(level, collapsedImage);

// sets collapsed image for for expanded nodes at level 1 using java.awt.Image

 

Ø       To set leaf image for leaf nodes at specific level using image path 

 

int level = 1;

String leafImagePath = "c:/images/leaf.gif";

awtTree.setLeafImageIconAt

(level, leafImagePath);

// sets leaf image for leaf nodes at level 1 using image path

 

Ø       To set leaf image for leaf nodes at specific level using java.awt.Image

 

int level = 1;

java.awt.Image leafImage = java.awt.Toolkit.getDefaultToolkit().

createImage(getClass().getResrouce("leaf.gif"));

awtTree.setLeafImageIconAt

(level, leafImage);

// sets leaf image for for leaf nodes at level 1 using java.awt.Image

 

Ø       To set cell renderer for specific level

 

You will receive following cell renderers for ready to use with this package,

 

o        Checkbox cell renderer -

com.elegantj.awt.tree.CheckboxAWTTreeCellRenderer

o        Choice (combo box) cell renderer -

com.elegantj.awt.tree.ChoiceAWTTreeCellRenderer

o        Text cell renderer -

com.elegantj.awt.tree.DefaultAWTTreeCellRenderer

o        Text area cell renderer -

com.elegantj.awt.tree.TextAreaAWTTreeCellRenderer

 

int level = 1;

com.elegantj.awt.tree.CheckboxAWTTreeCellRenderer renderer = new

com.elegantj.awt.tree.CheckboxAWTTreeCellRenderer();

awtTree.setCellRendererAt(level, renderer);

 

which sets checkbox as a cell renderer for nodes at level 1.

 

Ø       To set cell editor for specific level,

 

You will receive following cell editors for ready to use with this package, 

 

o        Checkbox cell editor -

com.elegantj.awt.tree.CheckboxAWTTreeCellEditor

o        Choice (combo box) cell editor -

com.elegantj.awt.tree.ChoiceAWTTreeCellEditor

o        Text editor -

com.elegantj.awt.tree.DefaultAWTTreeCellEditor

o        Text area cell editor -

com.elegantj.awt.tree.TextAreaTreeCellEditor

 

int level = 1;

com.elegantj.awt.tree.CheckboxAWTTreeCellEditor editor = new

com.elegantj.awt.tree.CheckboxAWTTreeCellEditor();

awtTree.setCellEditor(editor);

 

which sets checkbox as a cell editor for nodes at level 1.

 

6.1.5Setting up the Root

Ø       To set root of AWT Tree

 

com.elegantj.awt.tree.AWTTreeNode root = new

com.elegantj.awt.tree.AWTTreeNode("Root");

awtTree.setRoot(root); // sets the root of the tree with "Root" as user object

 

Ø       To set visibility of root node

 

awtTree.setRootVisible(false); // which makes search panel invisible

 

Ø       To set visibility of root handles

 

awtTree.setShowRootHandles(true); // which makes root handles visible

 

6.1.6Setting Row height attributes

Ø       To set row height

 

awtTree.setRowHeight(20); // sets row height as 20 pixels

 

6.1.7Configuring Selection functionality

Ø       AWTTree supports two types of selection

o        Single selection -

com.elegantj.awt.tree.AWTTree.SINGLE_SELECTION

o        Multiple selection -

com.elegantj.awt.tree.AWTTree.MULTIPLE_SELECTION

 

Ø       To set selection style as SINGLE_SELECTION

 

awtTree.setSelectionStyle(com.elegantj.awt.tree.

AWTTree.SINGLE_SELECTION);

// sets selection style as single selection

 

Ø       To set selection style as MULTIPLE_SELECTION

 

awtTree.setSelectionStyle(com.elegantj.awt.tree.AWTTree.

MULTIPLE_SELECTION);

// sets selection style as multiple selection

 

Ø       To provide / remove selection functionality on tree

 

awtTree.setSelectionAllowed(true); // allows selection on tree

 

Ø       Do not allow selection functionality on tree

 

awtTree.setSelectionAllowed(false); // disallows selection functionality on tree

 

Ø       To select a specific node

 

awtTree.setSelectionNode(awtTreeNode); // selects specified node

 

Ø       To select a specific Row

 

awtTree.setSelectionRow(rowIndex); // selects node exist at specified rowIndex

 

Ø       To select a range of nodes

 

awtTree.setSelectionInterval(startRowIndex, endRowIndex);

 

6.1.8Configuring Editing

Ø       To set editability of AWTTree

 

awtTree.setEditable(false); // makes AWTTree uneditable

 

Ø       To start editing of a specific node

 

awtTree.startEditing(node); // starts editing of specified node

 

Ø       To stop editing

 

awtTree.stopEditing(); // stops editing

 

Ø       To cancel editing

 

awtTree.cancelEditing(); // cancels editing

 

Ø       To check if tree is being edited or not

 

awtTree.isEditing(); // which returns boolean value, returns true if currently it is being edited

 

6.1.9Using Insert key and Delete key

Ø       To allow inserting of node on INSERT key of keyboard

 

awtTree.setInsertNodeOnInsertKey(true); // which allows to insert node on INSERT key of keyboard

 

Ø       To allow deleting of node on DELETE key of keyboard

 

awtTree.setDeleteNodeOnDeleteKey(true); // which allows to delete node on DELETE key of keyboard

 

6.1.10                  Configuring Drag and Drop

ElegantJ AWTTree provides feature of drag and drop.  Also provides property to activate or deactivate drag and drop functionality for a tree.

 

The drag and drop functionality works in following way,

 

Ø       A node can only be dropped to the node. It can not be dropped outside the tree or any position in tree except the hierarchical node's region.

Ø       A parent node can not be dropped to the it's any of the child node.

Ø       If allowSameNodeAtSameLevel's value is false then same child node as the dragged node should not be exist in the node on which it is being dropped.

 

Ø       To allow Drag and Drop functionality on tree,

 

awtTree.setDragAndDrop(true); // which allows drag and drop on tree

 

6.1.11                  Configuring Search Panel

ElegantJ AWTTree beans has collection of methods that can be used to set up search panel to implement Search functionality in your application.  User can search down from first node or selected node and up from last node or selected node. You can perform case sensitive / case insensitive search if required.

 

You can perform search for total equality, availability of search string as part of value in tree nodes, for value in tree nodes starting with search string as well as for value in tree nodes ending with search string

 

ElegantJ AWTTree provides the following properties to configure the search panel

 

Ø       Search Panel Visiblity

Ø       Search Panel Background

Ø       Search Panel Foreground

Ø       Search Panel Font

Ø       Search Panel Placement

Ø       Search Level Identifiers

 

Ø       To set search panel visibility

 

awtTree.setSearchPanelVisible(true); // sets search panel visibility to true

 

Ø       To set search panel background

 

Color searchPanelBackground = java.awt.Color.cyan;

awtTree.setSearchPanelBackground(searchPanelBackground);

// sets search panel background color as cyan

 

Ø       To set search panel foreground

 

Color searchPanelForeground = java.awt.Color.black;

awtTree.setSearchPanelForeground(searchPanelForeground);

// sets search panel foreground color as black

 

Ø       To set search panel font

 

Font searchPanelFont = new java.awt.Font("Dialog", java.awt.Font.BOLD, 12); awtTree.setSearchPanelFont(searchPanelFont);  

// sets search panel font as dialog, bold and of size 12

 

Ø       To set the search panel's placement (top or bottom)

 

awtTree.setSearchPanelLocation(com.elegantj.awt.tree.AWTTree.TOP); // sets search panel location to top

 

Ø       To set search level-wise identifiers

 

java.util.Vector levelWiseSearchIDs = new java.util.Vector();

levelWiseSearchIDs.addElement("Country");

levelWiseSearchIDs.addElement("State");

levelWiseSearchIDs.addElement("City");

awtTree.setLevelWiseIDs(levelWiseSearchIDs); // which sets search panel wise identifiers to fill combo box of search panel

 

6.1.12                  Handling Searching

Searching feature's ElegantJ Trees bean provides facility for searching node values.  To make things easier for developer, ElegantJ also provides ready-to-use Search panel.  You can search tree in four different ways (up as well as down).  You have option of a case sensitive / case insensitive search, if required.

 

Options for search progress and Comparison

 

Search Progress from

Options for search Progress

First node

com.elegantj.awt.tree.AWTTree.

SEARCH_FROM_FIRST_NODE

Last Node

com.elegantj.awt.tree.AWTTree.

SEARCH_FROM_LAST_NODE

Upwards from selected node

com.elegantj.awt.tree.AWTTree.

SEARCH_FROM_SELECTED_NODE_TO_UP

Downwards from selected node

com.elegantj.awt.tree.AWTTree.

SEARCH_FROM_SELECTED_NODE_TO_DOWN

 

Comparison Options

 

Comparison requirement

Option for comparison

Search node for value that starts with given search string

com.elegantj.awt.tree.AWTTree.

STARTS_WITH

Search node for value that ends with given search string

com.elegantj.awt.tree.AWTTree.

ENDS_WITH

Search node for value or its part equals given search string

com.elegantj.awt.tree.AWTTree.

CONTAINS

 

Search node for value for given string for exact match

com.elegantj.awt.tree.AWTTree.

EQUALS

 

Ø       To search for text "Employees" at node level 2,

 

String searchText = "Employees";

int searchFrom = com.elegantj.awt.tree.AWTTree.SEARCH_FROM_FIRST_NODE;

int serachWith = com.elegantj.awt.tree.AWTTree.STARTS_WITH;

int serachOnLevel = 2;

boolean isCaseSensitive = false;

com.elegantj.awt.tree.AWTTreeNode node = searchTreeNode(searchText, searchFrom, searchWith, searchOnLevel, isCaseSensitive);   // This returns the selected node if found. Search level must be greater than or equal to zero.  To search whole tree, specify searchOnLevel as 0.

 

6.1.13                  Configuring Popup Menu

ElegantJ AWT Tree is shipped with ready-to-use popup with following functionalities:

 

Ø       Insert the node

Ø       Delete the node

Ø       Edit the node

Ø       Add the child node

 

To make right-click functionality available or not available.

 

Ø       To make Right-click functionality available

 

awtTree.setShowPopupMenu(true);

 

Note: For Remove operations, If more than one nodes are selected then all nodes will be removed while For Add, Edit as well as Insert operations, action is performed on the node where mouse pointer is located while right-clicking.

 

6.1.14                  Configuring Check Box Tree and features under Check Box tree

Using ElegantJ AWTTree Beans, you can make entire tree as a CheckBox tree.  In a Checkbox tree, all the nodes will be checkboxes.  The process to create a check box tree is -

 

Ø       Create a tree object

Ø       Set it as a CheckBox Tree.

 

Ø       Set tree as a check box tree

 

awtTree.setCheckboxTree(true);

 

In a check box tree, all the nodes are rendered by checkboxes.

 

Ø       ElegntJ AWTTree provides following methods to get checked / unchecked nodes in case of Checkbox tree.

 

o        To get a vector containing checked nodes from whole check box tree,

 

java.util.Vector nodes = awtTree.getTreeNodes();

 

o        To get a vector containing checked / unchecked nodes from whole check box tree,

 

boolean bChecked = false;

java.util.Vector nodes = awtTree.getTreeNodes(bChecked);

// returns vector containing unchecked nodes.

 

o        To get a vector containing checked / unchecked nodes for specific level, 

 

boolean bChecked = false;

int level = 2;

java.util.Vector nodes = awtTree.getTreeNodes(bChecked, level);

// returns vector containing unchecked nodes at level 2.

 

o        To get a vector containing checked / unchecked nodes from sub tree, 

 

boolean bChecked = false;

com.elegantj.awt.tree.AWTTreeNode parentNode = awtTree.getRoot();

java.util.Vector nodes = awtTree.getTreeNodes(bChecked, parentNode); // returns a vector containing unchecked nodes from sub tree whose root is parentNode.

 

o        To get a vector containing checked / unchecked nodes at level 2 from sub tree

 

boolean bChecked = false;

int level = 2;

com.elegantj.awt.tree.AWTTreeNode parentNode = awtTree.getRoot();

Vector nodes = awtTree.getTreeNodes(bChecked, level, parentNode); // returns the vector containing the unchecked nodes at level 2 from subtree whose root is parentNode.

 

6.1.15                  Configuring Child-Parent relationship in Checkbox-Tree

A checkbox tree with Child-Parent relationship implemented improves speed of working with a tree.  This feature of a tree, an action carried out on a parent is repeated on its children.  For example,

 

Ø       If parent node is checked, all children (directly or indirectly under that parent) will get checked.

Ø       If parent node is unchecked, all children (directly or indirectly under that parent) also become unchecked.

Ø       If any child is unchecked, it's direct-parent also become unchecked.

 

Ø       To activate Child Parent relationship in check box tree

 

awtTree.setChildParentRelationship(true);

 

6.1.16                  Restricting duplicate nodes

You can restrict creation of duplicate child nodes at same level (for any parent node).  This means, user can be restricted from changing values in nodes, if values are getting duplicated at the same level (for any parent node).  User will not be able to do this by carrying out operations like editing, inserting, drag and drop or even programmatically.  This is specially useful when you want the data be unique.

 

Ø       Do not allow nodes with same values at same level (for any parent node)

 

awtTree.setSameNodeAtSameLevel(false);

 

By default, it is set as true.

 

If SameNodeAtSameLevel is false,

 

Ø       Duplicate child node cannot be positioned as parent node's child.

Ø       If value entered makes same value, either the changes needs to be truncated or new value needs to be entered.

Ø       Restricts the duplicate nodes at any depth of the inserted node.

 

SameNodeAtSameLevel works even in following cases also, 

 

Ø       On drag and drop

Ø       While node is inserted by insert key

Ø       While node is inserted programmatically

Ø       While root is set programmatically

 

6.1.17                  Making use of Advanced Implementation for creating custom Cell Renderers

ElegantJ AWTTree Beans is shipped with following cell renderers for ready to use -

 

Ø       Checkbox cell renderer –

com.elegantj.awt.tree.CheckboxAWTTreeCellRenderer

Ø       Choice (combo box) cell renderer –

com.elegantj.awt.tree.ChoiceAWTTreeCellRenderer

Ø       Text cell renderer –

com.elegantj.awt.tree.DefaultAWTTreeCellRenderer

Ø       Text area cell renderer –

com.elegantj.awt.tree.TextAreaAWTTreeCellRenderer

 

If you wish to use the custom component as a cell renderer, Then you need to create your own class for cell renderer and follow following steps,

 

Ø       extend the cell renderer (your own class for cell renderer) from desired component, 

Ø       implement com.elegantj.awt.tree.AWTTreeCellRenderer and then,

Ø       override paint(java.awt.Graphics g) method, which is called internally to paint the custom renderer.

 

 

 

6.1.18                  AWTTree Listeners and Events

Listener Name

com.elegantj.awt.tree.AWTTreeListener

Event that it receives

com.elegantj.awt.tree.AWTTreeEvent

When it fires

Ø       tree node(s) is changed

Ø       tree node(s) are inserted

Ø       tree node(s) are removed or

Ø       tree structure is changed

 

Listener Name 

com.elegantj.awt.tree.AWTTreeExpansionListner

Event that it receives

com.elegantj.awt.tree.AWTTreeExpansionEvent

When it fires

Ø       after a tree node is collapsed or

Ø       after a tree node is expanded

 

Listener Name

com.elegantj.awt.tree.AWTTreeWillExpandListener

Event that it receives

com.elegantj.awt.tree.AWTTreeExpansionEvent

When it fires

Ø       before a tree node is expanded or

Ø       before a tree node is collapsed

 

Listener Name

com.elegantj.awt.tree.AWTTreeSelectionListener

Event that it receives

com.elegantj.awt.tree.AWTTreeSelectionEvent

When it fires

Ø       after tree selection changes

 

Listener Name

com.elegantj.awt.tree.AWTTreeCellEditListener

Event that it receives

com.elegantj.awt.tree.AWTTreeCellEditEvent

When it fires

Ø       before cell editing

Ø       after cell editing

 

 

For more information on Listeners / Events see JAVA API for this package

 

 

6.2  ElegantJ JFC Tree

This guide provides technical documentation for ElegantJ JFCTree.

 

6.2.1Creating an instance of JFCTree

ElegantJ JFCTree can be created using any one of following classes -

 

Ø       com.elegantj.jfc.tree.JFCTree - to create an instance of JFC tree without JScrollPane.

Ø       com.elegantj.jfc.tree.JFCTreePanel - to create an instnace of JFC tree with JScrollPane.

 

So, If you want to use JFCTree with JScrollPane then create instance of JFCTreePanel otherwise create instance of JFCTree. In this JFCTrees programmers guide we have created JFCTreePanel's object throughout.

 

ElegantJ JFCTree can be created in following ways,

 

Ø       To create the JFCTree with sample model,

 

com.elegantj.jfc.tree.JFCTreePanel jfcTree =

new com.elegantj.jfc.tree.JFCTreePanel();

 

Ø       To create a rootless JFCTree with specified hashtable,

 

java.util.Hashtable hashtable = new java.util.Hashtable();

hashtable.put("node1", "node1");

hashtable.put("node2", "node2");

hashtable.put("node3", "node3");

 

com.elegantj.jfc.tree.JFCTreePanel jfcTree =

new com.elegantj.jfc.tree.JFCTreePanel(hashtable);

 

Ø       To create a JFCTree with specified root,

 

javax.swing.tree.DefaultMutableTreeNode root =

new javax.swing.tree.DefaultMutableTreeNode("Root");

root.insert(new javax.swing.tree.DefaultMutableTreeNode("node 1"), 0);

root.insert(new javax.swing.tree.DefaultMutableTreeNode("node 2"), 1);

root.insert(new javax.swing.tree.DefaultMutableTreeNode("node 3"), 2);

 

com.elegantj.jfc.tree.JFCTreePanel jfcTreePanel =

new com.elegantj.jfc.tree.JFCTreePanel(root);

 

Ø       To create rootless JFCTree with specified nodes using array.

 

Object nodes[] =

new Object[]{new javax.swing.tree.DefaultMutableTreeNode("node 1"),

new javax.swing.tree.DefaultMutableTreeNode("node 2"),

new javax.swing.tree.DefaultMutableTreeNode("node 3")};

 

com.elegantj.jfc.tree.JFCTreePanel jfcTreePanel =

new com.elegantj.jfc.tree.JFCTreePanel(nodes);

 

Ø       To create rootless JFCTree with specified nodes using vector.

 

java.util.Vector nodes = new java.util.Vector();

vector.addElemetn(new javax.swing.tree.DefaultMutableTreeNode("node 1"));

vector.addElemetn(new javax.swing.tree.DefaultMutableTreeNode("node 2"));

vector.addElemetn(new javax.swing.tree.DefaultMutableTreeNode("node 3"));

 

com.elegantj.jfc.tree.JFCTreePanel jfcTreePanel =

new com.elegantj.jfc.tree.JFCTreePanel(nodes);

 

Ø       To create an instance of JFCTree with specified tree node.

 

javax.swing.tree.DefaultMutableTreeNode root =

new javax.swing.tree.DefaultMutableTreeNode("Root");

root.insert(new javax.swing.tree.DefaultMutableTreeNode("node1"), 0);

root.insert(new javax.swing.tree.DefaultMutableTreeNode("node2"), 1);

root.insert(new javax.swing.tree.DefaultMutableTreeNode("node3"), 2);

 

com.elegantj.jfc.tree.JFCTreePanel jfcTreePanel =

new com.elegantj.jfc.tree.JFCTreePanel(root);

 

Ø       To create an instance of JFCTree with the specified tree node and boolean value for asksAllowsChildren.

 

javax.swing.tree.DefaultMutableTreeNode root =

new javax.swing.tree.DefaultMutableTreeNode("Root");

root.insert(new javax.swing.tree.DefaultMutableTreeNode("node1"), 0);

root.insert(new javax.swing.tree.DefaultMutableTreeNode("node2"), 1);

root.insert(new javax.swing.tree.DefaultMutableTreeNode("node3"), 2);

boolean asksAllowsChildren = false;

//if false, any node without children is a leaf node; if true, only nodes that do not allow children are leaf nodes

 

com.elegantj.jfc.tree.JFCTreePanel jfcTreePanel =

new com.elegantj.jfc.tree.JFCTreePanel(root, false);

 

6.2.2Configuring General Appearance

JFCTree provides the following basic look & feel,

 

Ø       Font

Ø       Background

Ø       Foreground

Ø       Visibility

Ø       Enabled

Ø       Locale

Ø       Cursor

Ø       Bounds

Ø       Lightweight

Ø       Opaque

Ø       Tool-Tip Text

Ø       DoubleBuffered

Ø       Autoscrolls

Ø       RequestFocusEnabled

Ø       Border

Ø       ManagingFocus

 

Ø       To set Background color,

 

jfcTreePanel.setBackground(java.awt.Color.cyan); // sets the background color as cyan

 

Ø       To set Foreground color,

 

jfcTreePanel.setForeground(java.awt.Color.black);  // sets foreground color as black

 

Ø       To set Font properties,

 

jfcTreePanel.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12)); // sets the dialog font of size 12

 

Ø       To set Visibility property,

 

jfcTreePanel.setVisible(true); // sets visibility property as true

 

Ø       To set Enable property,

 

jfcTreePanel.setEnabled(true); // sets enable property as true

 

Ø       To set Locale property,

 

jfcTreePanel.setLocale(java.util.Locale.ENGLISH); // sets the locale property to English

 

Ø       To set Cursor property,

 

jfcTreePanel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

// sets the cursor property to hand cursor

 

Ø       To set Bounds,

 

int x = 5;

int y = 5;

int width = 300;

int height = 200;

jfcTreePanel.setBounds(x, y, width, height);

// sets bounds to x, y, width and height

 

Ø       To set Lightweight

 

jfcTreePanel.setLightweight(true);  // sets Lightweight to true

 

Ø       To set Opaque,

 

jfcTreePanel.setOpaque(true);  // sets opaque to true

 

Ø       To set Tool-tip text,

 

jfcTreePanel.setTooltipText("JFCTree");  // sets Tooltip text as "JFCTree"

 

Ø       To set Double Buffering property,

 

jfcTreePanel.setDoubleBuffered(true);  // enables the double buffering

 

Ø       To set Auto Scroll property,

 

jfcTreePanel.setAutoScrolls(true);  // sets the auto scrolls to true

 

Ø       To set RequestFocusEnabled,

 

jfcTreePanel.setRequestFocusEnabled(true);

 

Ø       To set Border color,

 

javax.swing.Border border =

javax.swing.BorderFactory.createLineBorder(java.awt.Color.black); 

// sets the border as black

jfcTreePanel.setBorder(border);

 

Ø       To set ManagingFocus property,

 

jfcTreePanel.setManagingFocus(true);  // sets the ManagingFocus to true.

 

6.2.3Configuring level wise node attributes

The level wise node attributes such as,

 

Ø       Background non selection color

Ø       Background selection color

Ø       Text non selection color

Ø       Text selection color

Ø       Border selection color

Ø       Opened image icon

Ø       Closed image icon

Ø       Leaf image icon

Ø       Cell renderer

Ø       Cell editor

 

Ø       To set level wise BackgroundNonSelectionColor, 

 

int level = 1;

jva.awt.Color backgroundNonSelectionColor = java.awt.Color.cyan;

jfcTreePanel.setBackgroundNonSelectionColor(backgroundNonSelectionColor, level); 

// sets background non selection color for nodes at level 1 to cyan.

 

Ø       To set level wise BackgroundSelectionColor

 

int level = 1;

java.awt.Color backgroundSelectionColor = java.awt.Color.blue;

jfcTreePanel.setBackgroundSelectionColor(backgroundSelectionColor, level); 

// sets background selection color for nodes at level 1 to blue.

 

Ø       To set level wise TextNonSelectionColor,

 

int level = 1;

java.awt.Color textNonSelectionColor = java.awt.Color.black;

jfcTreePanel.setTextNonSelectionColor(textNonSelectionColor, level); 

// sets text non selection color for nodes at level 1 to black.

 

Ø       To set level wise TextSelectionColor,

 

int level = 1;

java.awt.Color textSelectionColor = java.awt.Color.white;

jfcTreePanel.setTextSelectionColor(textSelectionColor, level); 

// sets text selection color for nodes at  level 1 to white.

 

Ø       To set level wise BorderSelectionColor,

 

int level = 1;

java.awt.Color borderSelectionColor = java.awt.Color.black;

jfcTreePanel.setBorderSelectionColor(borderSelectionColor, level); 

// sets border selection color for nodes at level 1 to black.

 

Ø       To set level wise open image icon,

 

o        To set open image icon with specified image path for nodes at specific level, 

 

int level = 1;

String path = "c:/images/opened.gif";

jfcTreePanel.setOpenIconPath(path ,level);

// sets open image icon for nodes at level 1

 

o        To set open image icon with specified image icon for nodes at specific level, 

 

int level = 1;

javax.swing.ImageIcon imageIcon = new javax.swing.ImageIcon("c:/my_folder/opened.gif");

jfcTreePanel.setOpenIcon(imageIcon, level);

// sets open image icon for nodes at level 1

 

Ø       To set level wise close image icon,

 

o        To set close image icon with specified image path for nodes at specific level, 

 

int level = 1;

String path = "c:/images/closed.gif";

jfcTreePanel.setCloseIconPath(path ,level);

// sets close image icon for nodes at level 1

 

o        To set close image icon with specified image icon for nodes at specific level, 

 

int level = 1;

javax.swing.ImageIcon imageIcon = new javax.swing.ImageIcon("c:/my_folder/closed.gif");

jfcTreePanel.setCloseIcon(imageIcon, level);

// sets close image icon for nodes at level 1

 

Ø       To set level wise leaf image icon,

 

o        To set leaf image icon with specified image path for nodes at specific level,

 

int level = 1;

String path = "c:/images/leaf.gif";

jfcTreePanel.setLeafIconPath(path ,level);

// sets leaf image icon for nodes at level 1

 

o        To set leaf image icon with specified image icon for nodes at specific level, 

 

int level = 1;

javax.swing.ImageIcon imageIcon = new javax.swing.ImageIcon("c:/my_folder/leaf.gif");

jfcTreePanel.setLeafIcon(imageIcon, level);

// sets leaf image icon for nodes at level 1

 

Ø       To set cell renderer,

 

o        Following cell renderers comes with the ElegantJ JFCTree beanary,

 

§         Boolean cell renderer –

com.elegantj.jfc.common.renderers.BooleanRenderer

§         Checkbox cell renderer –

com.elegantj.jfc.common.renderers.CheckboxRenderer

§         Choice cell renderer –

com.elegantj.jfc.common.renderers.ChoiceRenderer

§         Color cell renderer –

com.elegantj.jfc.common.renderers.ColorRenderer

§         Date cell renderer –

com.elegantj.jfc.common.renderers.DateRenderer

§         Default cell renderer –

com.elegantj.jfc.common.renderers.DefaultRenderer

§         Icon cell renderer –

com.elegantj.jfc.common.renderers.IconRenderer

§         MultiLine cell renderer –

com.elegantj.jfc.common.renderers.MultiLineRenderer

§         MultiOption cell renderer –

com.elegantj.jfc.common.renderers.MultiOptionRenderer

§         Number cell renderer –

com.elegantj.jfc.common.renderers.NumberRenderer

§         Progress cell renderer –

com.elegantj.jfc.common.renderers.ProgressRenderer

§         RadioButton cell renderer –

com.elegantj.jfc.common.renderers.RadioButtonRenderer

§         Text cell renderer –

com.elegantj.jfc.common.renderers.TextRenderer

 

o        To set level wise cell renderer for nodes at specific level

 

int level = 1;

com.elegantj.jfc.common.renderers.CheckboxRenderer checkboxRenderer = new com.elegantj.jfc.common.renderers.CheckboxRenderer();

jfcTreePanel.setCellRenderer(checkboxRenderer, level);

// sets cell renderer as checkbox renderer for nodes at level 1

 

o        To set default cell renderer (applicable when level wise renderer is not set, This default renderer renders all the nodes when level wise renderers are not set.)

 

com.elegantj.jfc.common.renderers.CheckboxRenderer checkboxRenderer = new com.elegantj.jfc.common.renderers.CheckboxRenderer();

jfcTreePanel.setDefaultCellRenderer(checkboxRenderer);

// sets default cell renderer as checkbox renderer for whole tree,

 

Ø       To set cell editor

 

o        Following cell editors come with the ElegantJ JFCTree benary,

 

§         Boolean cell editor –

com.elegantj.jfc.common.editors.BooleanEditor

§         Checkbox cell editor –

com.elegantj.jfc.common.editors.CheckboxEditor

§         Choice cell editor –

com.elegantj.jfc.common.editors.ChoiceEditor

§         Color cell editor –

com.elegantj.jfc.common.editors.ColorEditor

§         Date cell editor –

com.elegantj.jfc.common.editors.DateEditor

§         Default cell editor –

com.elegantj.jfc.common.editors.DefaultEditor

§         Icon cell editor –

com.elegantj.jfc.common.editors.IconEditor

§         MultiLine cell editor –

com.elegantj.jfc.common.editors.MultiLineEditor

§         MultiOption cell editor –

com.elegantj.jfc.common.editors.MultiOptionEditor

§         Number cell editor –

com.elegantj.jfc.common.editors.NumberEditor

§         RadioButton cell editor –

com.elegantj.jfc.common.editors.RadioButtonEditor

§         Slider cell editor –

com.elegantj.jfc.common.editors.SliderEditor

 

o        To set level wise cell editor for nodes at specific level

 

int level = 1;

com.elegantj.jfc.common.editors.CheckboxEditor checkboxEditor =

new com.elegantj.jfc.common.editors.CheckboxEditor();

jfcTreePanel.setCellEditor(checkboxEditor, level);

// sets cell editor as checkbox editor for nodes at level 1

 

o        To set default cell editor  (applicable when level wise editor is not set, This default editor provides editor for all the nodes when level wise editors are not set.)

 

com.elegantj.jfc.common.editors.CheckboxEditor checkboxEditor =

new com.elegantj.jfc.common.editors.CheckboxEditor();

jfcTreePanel.setDefaultCellEditor(checkboxEditor);

// sets default cell editor as checkbox editor for whole tree

 

6.2.4Configuring root of tree

Ø       To set the root for the JFCTree,

 

javax.swing.tree.DefaultMutableTreeNode root =

new javax.swing.tree.DefaultMutableTreeNode("Root");

jfcTreePanel.setRoot(root); 

// sets the root for the JFCTree

 

Ø       To set the visibility of the root node,

 

jfcTreePanel.setRootVisible(false); 

// makes root invisible.

 

Ø       To set visibility of root handles

 

jfcTreePanel.setShowRootHandles(true); 

// which makes root handles visible,

// root handles means (+) & (-) images to expand and collapse the node.

 

 

6.2.5Configuring row attributes

Ø       To set row height, 

 

int rowHeight = 20;

jfcTreePanel.setRowHeight(rowHeight); //  which sets the row height to 20.

 

Note: If the specified value is less than or equal to zero then current cell renderer is queried for each row's height.

 

Ø       To set number of rows that should be visible, 

 

jfcTreePanel.setVisibleRowCount(10); // which sets the visible row count to 10.

 

Ø       To set fixed row height, If height of each display row is a fixed size or varied, that can be set through the method setFixedRowHeight.

 

jfcTreePanel.setFixedRowHeight(true);  // which sets the fixed row height to true.

 

6.2.6Configuring selection

ElegantJ Trees Beans' JFCTree provides three type of selection style,

 

Ø       javax.swing.ListSelectionModel.SINGLE_SELECTION - only one path can be selected at a time

Ø       javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION - only contiguous paths can be selected

Ø       javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION - any path can be selected

 

Ø       To set the selection mode to SINGLE_SELECTION,

 

jfcTreePanel.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);  // sets the selection to SINGLE_SELECTION.

 

Ø       To add the selection interval,

 

int index0 = 2;

int index1 = 5;

jfcTreePanel.addSelectionInterval(index0, index1);

// adds rows from index1 to index1 to selection

 

Ø       To add tree path to selection,

 

javax.swing.tree.TreePath treePath = jfcTreePanel.getPathForRow(1);

jfcTreePanel.addSelectionPath(treePath);   // adds tree path to selection.

 

Ø       To add selection paths,

 

javax.swing.tree.TreePath treePaths[] = new javax.swing.tree.TreePath[]{jfcTreePanel.getPathForRow(1), jfcTreePanel.getPathForRow(2), jfcTreePanel.getPathForRow(3)};

jfcTreePanel.addSelectionPaths(treePaths);   // adds the 1st, 2nd and 3rd row's path to the selection

 

Ø       To add row to selection, 

 

int selectionRow = 2;

jfcTreePanel.addSelectionRow(selectionRow);   // adds 2nd row to the selection

 

Ø       To add more than one rows to selection, 

 

int selectionRows[] = new int[]{1, 2, 3};

jfcTreePanel.addSelectionRow(selectionRows);  // adds the 1st, 2nd and 3rd row to the selection.

 

 

6.2.7Configuring Editing

Ø       To set the Editable property JFCTree,

 

jfcTreePanel.setEditable(false); // sets Editable property to false making it not editable

 

Ø       InvokesStopCellEditing - When set to true, this determines what happens when editing is interrupted by selecting another node in the tree, a change in the tree's data, or by some other means.

 

jfcTreePanel.setInvokesStopCellEditing(true); // sets InvokesStopCellEditing to true

 

Ø       To stop editing,

 

jfcTreePanel.stopEditing(); // stops the editing.

 

Ø       To start editing at the specified path.

 

javax.swing.tree.TreePath treePath = jfcTreePanel.getPathForRow(1);

jfcTreePanel.startEditingPath(treePath);  // starts editing at the tree path for row at index 1

 

Ø       To cancel editing,

 

jfcTreePanel.cancelEditing();  // cancels editing

 

Ø       To check whether tree is being edited,

 

jfcTreePanel.isEditing();  // checks whether tree is being edited.

 

6.2.8Use of Insert key and Delete key

ElegatnJ JFCTree provides the action on following key strokes,

 

Ø       INSERT key - which allows to insert node on insert key

Ø       DELETE key - which allows to delete node on delete key

 

Note: These keystrokes works on selected node only.

 

Ø       To enable the insertion of  node on insert key,

 

jfcTreePanel.setInsertNodeOnInsertKey(true); 

// enables the insertion of node on insert key.

 

Ø       Enable the deletion of node on delete key,

 

jfcTreePanel.setRemoveNodeOnDeleteKey(true); 

//  enables the deletion of node on delete key.

 

 

6.2.9Configuring drag and drop

ElegantJ JFCTree allows to drag the tree node and drop it to the tree, by drag and drop functionality the tree node can be moved very easily. Drag and Drop functionality can be disabled or enabled through the method setDragAndDrop.

 

The drag and drop functionality works in following way,

 

Ø       A node can only be dropped to the node. It can not be dropped outside the tree or any position in tree except the hierarchical node's region.

Ø       A parent node can not be dropped to the it's any of the child node.

 

If allowSameNodeAtSameLevel's value is false then same child node as the dragged node should not be exist in the node on which it is being dropped.

 

Ø       To enable the drag and drop functionality,

 

jfcTreePanel.setDragAndDrop(true); 

// enables the drag and drop functionality, the default value is true.

 

6.2.10                  Configuring search panel

ElegantJ JFCTree provides the following attributes for the search panel,

 

Ø       Search panel visibility

Ø       Search panel background

Ø       Search panel foreground

Ø       Search panel font

Ø       Search panel placement

Ø       Search panel identifiers

 

Ø       To set search panel's visibility property,

 

jfcTreePanel.setSearchPanelVisible(false); 

//  this hides the search panel

 

Ø       To set background color of search panel,

 

jfcTreePanel.setSearchPanelBackground(java.awt.Color.gray); 

// which sets the search panel background to gray

 

Ø       To set the search panel foreground,

 

jfcTreePanel.setSearchPanelForeground(java.awt.Color.black); 

// which sets the foreground color on search panel to black.

 

Ø       To set search panel font,

 

jfcTreePanel.setSearchPanelFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 12)); 

// sets the search panel font to Dialog, style as bold and size as 12.

 

Ø       To set search panel placement, 

 

Possible values for the search panel placement are.

 

javax.swing.SwingConstants.TOP

javax.swing.SwingConstants.LEFT

javax.swing.SwingConstants.BOTTOM

javax.swing.SwingConstants.RIGHT

 

Ø       To set search panel placement

 

jfcTreePanel.setSearchPanelPlacement

(com.elegantj.jfc.table.javax.swing.SwingConstants.TOP); 

// sets the search panel placement to top.

 

Ø       To set search panel identifiers.

 

java.util.Vector identifiers = new java.util.Vector();

identifiers.addElement("Region");

identifiers.addElement("Country");

identifiers.addElement("State");

 

jfcTreePanel.setSearchLevelIdentifiers(identifiers); 

// sets search level identifiers for the first three level.

 

6.2.11                  Searching for Information

Searching feature of ElegantJ Trees bean provides facility for searching node values.  To make things easier for developer, ElegantJ also provides ready-to-use Search panel.  You can search tree in four different ways (up as well as down).  You have an option of a case sensitive search, if required.

 

Options for search progress and Comparison

 

Search Progress from

Options for search Progress

First node

com.elegantj.jfc.tree.JFCTreePanel. SEARCH_FROM_FIRST_NODE

Last Node

com.elegantj.jfc.tree.JFCTreePanel. SEARCH_FROM_LAST_NODE

Selected node, upwards

com.elegantj.jfc.tree.JFCTreePanel. SEARCH_FROM_SELECTED_ NODE_TO_UP

Selected node, downwards

com.elegantj.jfc.tree.JFCTreePanel. SEARCH_FROM_SELECTED_ NODE_TO_DOWN

 

Comparison Options

 

Comparison requirement

Option for comparison

Search node for value that starts with given search string

com.elegantj.jfc.tree.JFCTreePanel.STARTS_WITH

Search node for value that ends with given search string

com.elegantj.jfc.tree.JFCTreePanel.ENDS_WITH

Search node for value or its part equals given search string

com.elegantj.jfc.tree.JFCTreePanel.CONTAINS_WITH

Search node for value for given string for exact match

com.elegantj.jfc.tree.JFCTreePanel.EQUALS

 

Ø       To search tree node with specified node text, specified level, comparison mode and case sensitivity,

 

String sNode = "node";

int nSearchLevel = 1;

int nCompareMode = com.elegantj.jfc.tree.JFCTreePanel.EQUALS;

boolean bCaseSensitive = false;

 

javax.swing.tree.DefaultMutableTreeNode node =

jfcTreePanel.searchTreeNode(sNode, nSearchLevel, nCompareMode, bCaseSensitive);

 

If search string is found, this returns default mutable tree node.

 

Ø       To search tree node with specified node text, specified level, search mode, comparison mode and case sensitivity,

 

String sNode = "node";

int nSearchLevel = 1;

int nSearchMode = com.elegantj.jfc.tree.JFCTreePanel.SEARCH_FROM_FIRST_NODE;

int nCompareMode = com.elegantj.jfc.tree.JFCTreePanel.EQUALS;

boolean bCaseSensitive = false;

 

javax.swing.tree.DefaultMutableTreeNode node =

jfcTreePanel.searchTreeNode(sNode, nSearchLevel, nSearchMode,  nCompareMode, bCaseSensitive);

 

If search string is found, this returns default mutable tree node.

 

Ø       To search tree node with specified user object,

 

Object userObject = "search node";

javax.swing.tree.DefaultMutableTreeNode node =

jfcTreePanel.searchTreeNode(userObject);

 

If user object is found, this returns default mutable tree node.

 

Ø       To search tree node with specified user object and level,

 

Object userObject = "search node";

int level = 1;

javax.swing.tree.DefaultMutableTreeNode node =

jfcTreePanel.searchTreeNode(userObject, 1);

 

If user object is found, this returns default mutable tree node.

 

Ø       To search tree node with the specified user object and parent user object,

 

Object userObject = "search node";

Object userObjectOfParent = "parent node";

javax.swing.tree.DefaultMutableTreenode node =

jfcTreePanel.searchTreeNode(userObject, userObjectOfParent);

 

If user object is found, this returns the default mutable tree node.

 

6.2.12                  Handling Sorting

Sorting is possible with ElegantJ JFCTree.

 

A tree may have any of the three state of arrangement –

 

Arrangement

How to set it

Not sorted

com.elegantj.jfc.tree.JFCTreePanel.NON_SORT

Sorted in Ascending order

com.elegnatj.jfc.tree.JFCTreePanel.ASCENDING_SORT

Sorted in Descending order

com.elegantj.jfc.tree.JFCTreePanel.DESCENDING_SORT

 

Ø        To sort the tree in ascending order,

 

jfcTreePanel.setSortedTree(com.elegnatj.jfc.tree.JFCTreePanel.ASCENDING_SORT); 

//  sorts the tree in ascending order.

 

Ø       To sort the whole tree in ascending or descending order using boolean value,

 

jfcTreePanel.sortTree(true); 

// sorts the whole tree in ascending order.

 

Ø       To sort particular node's child i.e. particular parent node,

 

jfcTreePanel.sortTree(parentNode, true); 

// sorts the parent node in ascending order.

 

6.2.13                  Setting Visibility of Popup menu

ElegantJ JFCTree provides the pop-up menu for the following functionalities,

 

Ø       Insert node

Ø       Delete node

Ø       Edit node

Ø       Add child node

Ø       Sort node

 

All the pop-up menu operations are carried out on selected node.

 

Ø       To set popup visibility to true,

 

jfcTreePanel.setPopupVisible(true); 

// which sets the value of ShowPopupVisible to true, so it will be opened on right click on JFCTree.

 

6.2.14                  Configuring Check Box Tree and features under Check Box tree

ElegantJ JFCTree allows you to make the whole tree as a Checkbox Tree.  In a checkbox tree, all the nodes are renderered as checkboxes.

 

Ø       To make checkbox tree, create instance of JFCTree and then set checkbox tree to true in following way,

 

jfcTreePanel.setCheckboxTree(true);  // which sets the tree as checkbox tree.

 

ElegantJ JFCTree set the default checkbox renderer and editor on checkbox tree.  If you want to set your own renderer or editor then you can do that using following methods,

 

Ø       To set checkbox tree cell renderer, which is used in case of checkbox tree 

 

com.elegantj.jfc.common.renderers.CheckboxRenderer checkboxRenderer = new com.elegantj.jfc.common.renderers.CheckboxRenderer();

jfcTreePanel.setCheckboxTreeCellRenderer(checkboxRenderer); 

//  sets the checkbox cell renderer.

 

Ø       To set checkbox tree cell editor, which is used in case of checkbox tree

 

com.elegantj.jfc.common.editors.CheckboxEditor checkboxEditor =

new com.elegantj.jfc.common.editors.CheckboxEditor();

jfcTreePanel.setCheckboxTreeCellEditor(checkboxEditor); 

// sets the checkbox cell editor.

 

Ø       ElegntJ JFCTree provides following methods to get checked / unchecked nodes in case of Checkbox tree.

 

o        To get a vector containing checked nodes from whole check box tree, 

 

java.util.Vector nodes = jfcTreePanel.getTreeNodes();

 

o        To get a vector containing checked / unchecked nodes from whole check box tree,

 

boolean bChecked = false;

java.util.Vector nodes = jfcTreePanel.getTreeNodes(bChecked); 

// returns vector containing unchecked nodes.

 

o        To get a vector containing checked / unchecked nodes for specific level, 

 

boolean bChecked = false;

int level = 2;

java.util.Vector nodes = jfcTreePanel.getTreeNodes(bChecked, level); 

// returns vector containing unchecked nodes at level 2.

 

o        To get a vector containing checked / unchecked nodes from sub tree, 

 

boolean bChecked = false;

javax.swing.tree.DefaultMutableTreeNode parentNode = jfcTreePanel.getRoot(); java.util.Vector nodes = jfcTreePanel.getTreeNodes(bChecked, parentNode); 

// returns a vector containing unchecked nodes from sub tree whose root is parentNode.

 

o        To get a vector containing checked / unchecked nodes at level 2 from sub tree

 

boolean bChecked = false;

int level = 2;

javax.swing.tree.DefaultMutableTreeNode parentNode = jfcTreePanel.getRoot(); Vector nodes = jfcTreePanel.getTreeNodes(bChecked, level, parentNode); 

// returns the vector containing the unchecked nodes at level 2 from subtree whose root is parentNode.

 

6.2.15                  Configuring Child-Parent relationship in Checkbox-Tree

A checkbox tree with Child-Parent relationship implemented improves speed of working with a tree.  This works in following way,

 

Ø       If parent node is checked, all children (directly or indirectly under that parent) will get checked.

Ø       If parent node is unchecked, all children (directly or indirectly under that parent) also become unchecked.

Ø       If any child is unchecked, it's direct-parent also become unchecked.

 

Ø       To activate Child Parent relationship in check box tree

 

jfcTreePanel.setChildParentRelationship(true);

 

6.2.16                  Restricting duplicate nodes

You can restrict creation of duplicate child nodes at same level (for any parent node).  This means, user can be restricted from changing values in nodes, if values are getting duplicated at the same level (for any parent node).  User will not be able to do this by carrying out operations like editing, inserting, drag and drop or even programmatically.  This is specially useful when you want the data be unique.

 

Ø       Do not allow nodes with same values at same level (for any parent node)

 

jfcTreePanel.setSameNodeAtSameLevel(false);

 

By default, it is set as true.

 

If SameNodeAtSameLevel is false,

 

Ø       Duplicate child node cannot be positioned as parent node's child.

Ø       If value entered makes same value, either the changes needs to be truncated or new value needs to be entered.

Ø       Restricts the duplicate nodes at any depth of the inserted node.

 

SameNodeAtSameLevel works even in following cases also, 

 

Ø       On drag and drop

Ø       While node is inserted by insert key

Ø       While node is inserted programmatically

Ø       While root is set programmatically

 


7       Product and Support Information

 

Product and Support Information:

Ø       You can find more information about ElegantJ Trees and its features on www.ElegantJBeans.com.

Ø       Forward your support related mails to support@ElegantJBeans.com.

Ø       Forward your sales related mails to sales@ElegantJBeans.com.

 

Feedback and Suggestions:

Ø       We will be pleased to get your feedback as well as suggestions about our product.

Ø       Forward any feedback or suggestions related mails to support@ElegantJBeans.com.