brf.j2me.dynaworks.ui
Class Tree

java.lang.Object
  |
  +--brf.j2me.dynaworks.ui.BasicWidget
        |
        +--brf.j2me.dynaworks.ui.Tree
All Implemented Interfaces:
UserWidget

public class Tree
extends BasicWidget

Provides a class that does hierarchical layout of information.

It implements a Windows Explorer-like hiearchical tree type view of a Vector of TreeItems. When an item-specific event happens (ie. a double-click on an icon or label) an Event is generated, whose argument is the TreeItem affected.

Version:
1.0
Author:
Bernd R. Fix
See Also:
BasicWidget, UserWidget

Field Summary
static int COLLAPSE
          Event sent when a drawer is closed.
private  TreeItem currItem
          reference to currently active item.
protected  java.util.Vector displayedList
          Items able to be displayed
protected  int displayNum
          Default value for how many items we can display.
private  int dragState
          current dragging mode
private  int dragX
          we are dragging from here (x-coordinate).
private  int dragY
          we are dragging from here (y-coordinate).
static int EXPAND
          Event sent when a drawer is opened.
private  int firstVisible
          index of first visible tree item.
private  int height
          height of a tree control.
private  ScrollBar hs
          horizontal scrollbar.
private static Bitmap minusSign
          Bitmap "-"
private static Bitmap plusSign
          Bitmap "+"
protected  java.util.Vector rootItems
          The items in this Tree.
private  int scrollX
          horizontal scroll position.
private  int scrollXmax
          maximum x-scroll value for current layout.
private  int scrollY
          vertical scroll position.
private  int scrollYmax
          maximum y-scroll value for current layout.
static int SIMPLE
          Style mode flags.
private  int syncState
          status of synchronization: 0 = up-to-date
private  ScrollBar vs
          vertical scrollbar.
private  int width
          width of the tree canvas.
 
Fields inherited from class brf.j2me.dynaworks.ui.BasicWidget
g, h, w, x, y
 
Constructor Summary
Tree(int x, int y, int w, int h, int style)
          Creates an empty Tree.
 
Method Summary
(package private) static void ()
           
 void addRoot(TreeItem item)
          Inserts the item as a root item in the tree.
private  int addToDisplayedList(TreeItem item, int level)
          add an item to the list of displayed list.
 void collapse(TreeItem item)
          Collapses a branch.
 void expand(TreeItem item)
          Makes the subtree visible
private  boolean expandIconClick(TreeItem item)
          branch is expanding (true) or collapsing (false).
 TreeItem getSelectedItem()
          Return the selected item in the tree, null if the tree is empty.
 ActionEvent handlePenDown(int xc, int yc)
          Handle a "pen down" event.
 ActionEvent handlePenMove(int xc, int yc)
          Handle a "pen move" event.
 ActionEvent handlePenUp(int xc, int yc)
          Handle a "pen up" event.
private  void initStyle(int style)
          setup the style.
 void paint()
          paint the graphics area.
 void removeAll()
          deletes all items in the tree.
 boolean removeRoot(TreeItem item)
          Deletes the item from the list of root items.
 void selectItem(TreeItem item)
          selects the item
protected  void setHorizontalOffset(int offset)
          Sets the horizontal offset for painting the tree anf can be used e.g.
protected  void setVerticalOffset(int offset)
          Sets the vertical offset for painting the tree anf can be used e.g.
private  void sync()
          synchronize inner state (list of displayed tree items.
 
Methods inherited from class brf.j2me.dynaworks.ui.BasicWidget
contains, handleKeyDown, handleSysKeyDown, hasFocus, loseFocus, setFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

SIMPLE

public static final int SIMPLE
Style mode flags.


EXPAND

public static final int EXPAND
Event sent when a drawer is opened.


COLLAPSE

public static final int COLLAPSE
Event sent when a drawer is closed.


width

private int width
width of the tree canvas.


height

private int height
height of a tree control.


hs

private ScrollBar hs
horizontal scrollbar.


scrollX

private int scrollX
horizontal scroll position.


scrollXmax

private int scrollXmax
maximum x-scroll value for current layout.


vs

private ScrollBar vs
vertical scrollbar.


scrollY

private int scrollY
vertical scroll position.


scrollYmax

private int scrollYmax
maximum y-scroll value for current layout.


dragState

private int dragState
current dragging mode

dragX

private int dragX
we are dragging from here (x-coordinate).


dragY

private int dragY
we are dragging from here (y-coordinate).


rootItems

protected java.util.Vector rootItems
The items in this Tree.


currItem

private TreeItem currItem
reference to currently active item.


firstVisible

private int firstVisible
index of first visible tree item.


displayedList

protected java.util.Vector displayedList
Items able to be displayed

displayNum

protected int displayNum
Default value for how many items we can display. Will be adjusted according to the window size.

syncState

private int syncState
status of synchronization: 0 = up-to-date

plusSign

private static Bitmap plusSign
Bitmap "+"

minusSign

private static Bitmap minusSign
Bitmap "-"
Constructor Detail

Tree

public Tree(int x,
            int y,
            int w,
            int h,
            int style)
Creates an empty Tree.

Parameters:
x - int - x-ccordinate of upper-left corner.
y - int - y-coordinate of upper left corner.
w - int - width of control.
h - int - height of control.
Method Detail

static void ()

paint

public void paint()
paint the graphics area.
Overrides:
paint in class BasicWidget

initStyle

private void initStyle(int style)
setup the style.

Parameters:
style - int - tree style to be used.

getSelectedItem

public TreeItem getSelectedItem()
Return the selected item in the tree, null if the tree is empty.

Returns:
TreeItem - reference to selected item or null

setHorizontalOffset

protected void setHorizontalOffset(int offset)
Sets the horizontal offset for painting the tree anf can be used e.g. for a scrollbar.

Parameters:
offset - int - use value as new horizontal offset.

setVerticalOffset

protected void setVerticalOffset(int offset)
Sets the vertical offset for painting the tree anf can be used e.g. for a scrollbar.

Parameters:
offset - int - use value as new vertical offset.

addRoot

public void addRoot(TreeItem item)
Inserts the item as a root item in the tree.

Parameters:
item - TreeItem - item to be inserted.

removeRoot

public boolean removeRoot(TreeItem item)
Deletes the item from the list of root items.

Parameters:
item - TreeItem - item to be removed
Returns:
true if the argument was part of the tree; false otherwise

removeAll

public void removeAll()
deletes all items in the tree.


expand

public void expand(TreeItem item)
Makes the subtree visible
Parameters:
item - TreeItem - item to be expanded

collapse

public void collapse(TreeItem item)
Collapses a branch.

Parameters:
item - TreeItem - branch to collapse.

selectItem

public void selectItem(TreeItem item)
selects the item
Parameters:
item - TreeItem - item to be selected

addToDisplayedList

private int addToDisplayedList(TreeItem item,
                               int level)
add an item to the list of displayed list. If the item is a parent, it's children are added to the list recursively.

Parameters:
item - TreeItem - item to be added
Returns:
int - number of lines added to the list.

sync

private void sync()
synchronize inner state (list of displayed tree items.


expandIconClick

private boolean expandIconClick(TreeItem item)
branch is expanding (true) or collapsing (false).

Parameters:
item - TreeItem - toggle collapse/expand for this item.

handlePenDown

public ActionEvent handlePenDown(int xc,
                                 int yc)
Handle a "pen down" event.

Overrides:
handlePenDown in class BasicWidget
Parameters:
xc - int - x coordinate of point
yc - int - y coordinate of point
Returns:
ActionEvent - ActionEvent code (or null)

handlePenMove

public ActionEvent handlePenMove(int xc,
                                 int yc)
Handle a "pen move" event.

Overrides:
handlePenMove in class BasicWidget
Parameters:
xc - int - x coordinate of current point
yc - int - y coordinate of current point
Returns:
ActionEvent - ActionEvent code (or null)

handlePenUp

public ActionEvent handlePenUp(int xc,
                               int yc)
Handle a "pen up" event.

Overrides:
handlePenUp in class BasicWidget
Parameters:
xc - int - x coordinate of current point
yc - int - y coordinate of current point
Returns:
ActionEvent - ActionEvent code (or null)