ewe.ui
Class TreeTableModel

java.lang.Object
  extended byewe.ui.TableModel
      extended byewe.ui.TreeTableModel
All Implemented Interfaces:
CellConstants, ControlConstants, EventListener, UIConstants
Direct Known Subclasses:
FileTree, TreeModelAdapter

public class TreeTableModel
extends TableModel


Nested Class Summary
 
Nested classes inherited from class ewe.ui.TableModel
TableModel.CellControl, TableModel.ControlProxy
 
Field Summary
static int CanExpand
          A Node status.
static IImage closedFolder
           
 Vector cutNodes
           
protected static int DepthMask
           
 boolean dynamicCanExpand
          If this is true then the "canExpand" state of a node will be queried every time it is displayed.
static IImage expandingIcon
           
 Vector expandingNodes
           
 int expansionLevel
          This is the default number of levels to expand to when the tree is newly displayed.
protected static int FlagMask
           
static int HasChildren
          A Node status.
 boolean hasControls
          This is used to indicate that nodes can have different sizes.
static int HasMoreSiblings
          A Node status.
 boolean hideRoot
          Set this true to hide the Root node.
static int IsExpanded
          A Node status.
static int IsNode
          A Node status.
protected  long[] matrix
           
 boolean noLines
          If this is true then no lines connecting nodes will be drawn.
static IImage openFolder
           
static IImage page
           
protected static int PatternMask
           
 Vector ranges
           
protected  TreeNode rootObject
           
 Color selectedColor
           
 int selectedLine
           
 RangeList selectedLines
           
 boolean selectExpanded
          If this is true then expanding/collapsing a node will automatically select that node.
 boolean showWaitCursor
          If this is true then the wait cursor will be shown when expanding node.
 
Fields inherited from class ewe.ui.TableModel
activeCellControl, allColumnsSameSize, allRowsSameSize, canHScroll, canVScroll, cellInsets, charHeight, charWidth, clipData, controlProxy, cursorSize, fillToEqualHeights, fillToEqualWidths, gap, hasColumnHeaders, hasPreferredSize, hasRowHeaders, hasSpanningColumns, hasSpanningRows, horizontalScrollUnit, insets, numCols, numRows, preferredCols, preferredRows, rect, selectRowWhenEditing, shadeAlternateRows, table, tca, verticalScrollUnit
 
Fields inherited from interface ewe.ui.UIConstants
BDR_DOTTED, BDR_INNER, BDR_NOBORDER, BDR_OUTER, BDR_OUTLINE, BDR_RAISEDINNER, BDR_RAISEDOUTER, BDR_SUNKENINNER, BDR_SUNKENOUTER, BF_BOTTOM, BF_BOTTOMLEFT, BF_BOTTOMRIGHT, BF_BUTTON, BF_DIAGONAL, BF_DIAGONAL_ENDBOTTOMLEFT, BF_DIAGONAL_ENDBOTTOMRIGHT, BF_DIAGONAL_ENDTOPLEFT, BF_DIAGONAL_ENDTOPRIGHT, BF_EXACT, BF_FLAT, BF_LEFT, BF_MIDDLE, BF_MONO, BF_PALM, BF_RECT, BF_RIGHT, BF_SOFT, BF_SQUARE, BF_TOP, BF_TOPLEFT, BF_TOPRIGHT, EDGE_BUMP, EDGE_ETCHED, EDGE_RAISED, EDGE_SUNKEN
 
Fields inherited from interface ewe.ui.CellConstants
BORDER, BOTTOM, CELLFLAG, CELLMASK, CENTER, CONTROLMASK, DONTCHANGE, DONTFILL, DONTSTRETCH, EAST, FILL, FIXEDSIZE, GROW, HCENTER, HCONTRACT, HEXPAND, HFILL, HGROW, HSHRINK, HSTRETCH, INITIALLY_CLOSED, INITIALLY_MINIMIZED, INITIALLY_PREFERRED_SIZE, INSETS, LEFT, MAXIMUMSIZE, MINIMUMSIZE, NORTH, NORTHEAST, NORTHWEST, PREFERREDSIZE, RECT, RIGHT, SHRINK, SOUTH, SOUTHEAST, SOUTHWEST, SPAN, STRETCH, TEXTSIZE, TOP, VCENTER, VCONTRACT, VEXPAND, VFILL, VGROW, VSHRINK, VSTRETCH, WEST
 
Fields inherited from interface ewe.ui.ControlConstants
All, AlwaysEnabled, AlwaysRecalculateSizes, ByDeferredMouse, ByDeferredPen, ByFrameChange, ByKeyboard, ByMouse, ByPen, ByRequest, CalculatedSizes, Disabled, DisablePopupMenu, DisplayOnly, Down, DrawFlat, Flag, ForceResize, HasData, Invisible, KeepImage, KeepSIP, Left, MakeMenuAtLeastAsWide, Maximize, Minimize, MouseSensitive, NoFocus, NotAnEditor, NotEditable, PaintDataOnly, PaintOutsideOnly, PenTransparent, PreferredSizeOnly, Right, SendUpKeyEvents, SendUpPenEvents, ShowSIP, ShrinkToNothing, SmallControl, SpecialBackground, TakeControlEvents, TakesKeyFocus, Transparent, Up, WantDrag, WantHoldDown
 
Constructor Summary
TreeTableModel()
           
 
Method Summary
 int[] addressOf(int line)
          Find the address of the line.
 int[] addressOf(TreeNode tn)
          Return the address of the TreeNode relative to the root TreeNode.
 int calculateColWidth(int col)
          This returns the full width of the column.
 int calculateRowHeight(int row)
          This returns the full height of the row.
 boolean canDoCollapse(int index)
          Returns if the item at the specified index can be collapsed.
 boolean canDoExpand(int index)
          Returns if the item at the specified index can be expanded.
 boolean canScreenScroll()
          This always returns false.
 void clicked(Point where)
           
 int collapse(int whichIndex)
          Collapse the index.
protected  int collapseMatrix(int parent)
           
protected  void collapsing(TreeNode node)
           
 int columnOf(int index)
          Returns the column which contains the '+'/'-' box of the entry at the following index.
 int countChildren(int parent)
          Return the number of children for a node at the specified index.
 int countSelectedLines()
           
 int countTotalChildNodes(int parent)
          Count all child nodes of a parent, including children of its children and so on.
 int delete(int line, int length)
          Remove a set of entries.
 boolean deleted(TreeNode parent, int previousIndexOfDeletedChild)
          This assumes you are using TreeNode objects with the control.
 int doCollapse(int whichIndex)
           
 int doExpand(int whichIndex)
           
 int doExpand(int whichIndex, TreeNode node)
          Override this to do expansion.
 void doubleClicked(Point where)
           
 void drawNodeData(FontMetrics fm, Graphics g, int line, Rect where, Rect whereInTable, TreeNode node)
           
 void drawNodeLine(Graphics g, Rect r, boolean nextTo, int flags, int row, TreeNode node)
           
 int expand(int whichIndex, long[] with, byte[] flags)
          Expand the index with the list of object references and the list of flags.
protected  void expanding(TreeNode node)
           
protected  void expandMatrix(int afterIndex, int length)
           
 int expandTo(int[] address)
          This will expand down the tree until the address specified is displayed.
 int expandTo(int[] address, boolean selectIt)
          This will exapand down the tree until the address specified is displayed.
 void expandToLevel(int level)
          This expands the tree a specified number of levels deep, below the root.
 int findChild(int parent, int whichChild)
          Find the child within the parent.
 int findNextSibling(int where)
          Find the next sibling.
 int findParent(int where)
          Find the parent.
protected  int findParentOrPreviousSibling(int where, boolean parent)
           
 int findPreviousSibling(int where)
          Find the previous sibling.
 void fireSelection()
           
 int flagsAt(int line)
          Returns the flags of the line.
 void fullExpandCollapse(int line)
          This will either expand or collapse a node depending on its current state.
 Object getDataObjectAt(int line)
          This returns getTreeNodeAt(line).
 boolean getDataToDragAndDrop(DragContext dc)
           
 Object getDataToTransfer()
           
 int getDataWidth(int line)
           
 int getDisplayStatus(int forLine)
          Get the display status for the specified line.
 String getDisplayString(int forLine, TreeNode node)
           
protected  int getDrawOptions(int line, TreeNode node)
           
 byte getFlags(int forLine, TreeNode node)
           
 int getHeightOfObject(Object obj)
           
 IImage getIcon(int forLine, TreeNode node)
           
 Menu getMenuFor(int line)
           
protected  TreeNode getNodeToCollapse(int whichIndex)
          This is called by the default doExpand().
protected  TreeNode getNodeToExpand(int whichIndex)
          This is called by the default doExpand().
 TreeNode getRootObject()
           
 int[] getSelectedLines()
           
 RangeList getSelectedRanges()
           
 Rect getTextRect(int index, Rect dest)
           
 TreeNode getTreeNodeAt(int index)
           
 int indexOf(int[] address)
          Finds the index of the address specified.
 int indexOf(TreeNode node)
          Return the line of the specified node IF it is displayed.
 void init(long rootObjectRef, byte flags)
           
 int insert(int parent, int asChild, long[] what, byte[] flags)
          This will only insert IF there are already children.
 boolean inserted(TreeNode parent, TreeNode child, boolean selectChild)
          This assumes you are using TreeNode objects with the control.
 boolean isCut(TreeNode node)
           
 boolean isSelected(int index)
           
 void made()
          This is called after the TableControl has been made.
protected  void modify(int start, int length, int on, int off)
           
 long objectAt(int line)
          Find the object reference number of the line.
 void paintLine(int line)
           
 void paintLine(TableControl tc, Graphics g, int line)
           
 void paintTableCell(TableControl tc, Graphics g, int row, int col)
          The real biz.
 void paintTableCell(TableControl tc, Graphics g, Rect cells)
          This paints a matrix of cells.
 void pressed(Point where)
           
 void reExpandNode(int index)
          This will cause the selected Node to be collapsed and then expanded again.
 void reExpandSelectedNode()
          This will cause the selected Node to be collapsed and then expanded again.
 void released(Point where)
           
protected  int removeEntries(int start, int toRemove)
          If you override this to react to a remove, then make sure you call this.
 int scrollTo(int current, int requested, int scrollAction, boolean horizontal)
          This is called by the table to tell the model that it wants to scroll either vertically or horizontally.
 void select(int line)
          Selects the specified line.
 void select(int index, boolean selected)
           
 void selectAll(boolean selectOn)
          This either clears the selection or selects all.
 void selectOnly(int line)
          Select an item - this does not fire a selection event.
 void setRootObject(TreeNode root)
           
 void setSelectedLines(int[] all)
           
protected  int shrunk(int byHowMany)
           
 byte toFlags(TreeNode what)
          This determines from the TreeNode whether it is a leaf and whether it can expand.
 long toReference(TreeNode what)
          Creates a reference for the TreeNode.
 void update()
           
 void updateFlags(int line, byte newFlags)
          This changes the flags for the node on a line.
 
Methods inherited from class ewe.ui.TableModel
calculateTextCharsInColumn, calculateTextLinesInRow, canSelect, checkControlFor, clearCellAdjustments, closeActiveControl, deferPaintTableCell, doHotKey, findCellsInArea, fixBorder, getCellAttributes, getCellControlFor, getCellData, getCellInsets, getCellPreferredSize, getCellRect, getCellText, getColWidth, getControlFor, getLinesFor, getMaxColWidth, getMaxRowHeight, getMenuFor, getMenuOutsideCells, getMinColWidth, getMinRowHeight, getPreferredSize, getRowHeight, getToolTip, hasActiveControls, inset, isActiveCellControl, notifyDataChange, onEvent, onKeyEvent, paintTableCellData, paintTableCellText, penPressed, popupMenuEvent, remapColumns, resized, select, show, startedEditing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Field Detail

matrix

protected long[] matrix

rootObject

protected TreeNode rootObject

noLines

public boolean noLines
If this is true then no lines connecting nodes will be drawn.


selectExpanded

public boolean selectExpanded
If this is true then expanding/collapsing a node will automatically select that node. By default this is false.


showWaitCursor

public boolean showWaitCursor
If this is true then the wait cursor will be shown when expanding node.


dynamicCanExpand

public boolean dynamicCanExpand
If this is true then the "canExpand" state of a node will be queried every time it is displayed.


hasControls

public boolean hasControls
This is used to indicate that nodes can have different sizes.


expansionLevel

public int expansionLevel
This is the default number of levels to expand to when the tree is newly displayed. By default it is 1.


hideRoot

public boolean hideRoot
Set this true to hide the Root node.


expandingIcon

public static IImage expandingIcon

selectedLine

public int selectedLine

selectedLines

public RangeList selectedLines

ranges

public Vector ranges

cutNodes

public Vector cutNodes

expandingNodes

public Vector expandingNodes

IsNode

public static final int IsNode
A Node status.

See Also:
Constant Field Values

CanExpand

public static final int CanExpand
A Node status.

See Also:
Constant Field Values

HasMoreSiblings

public static final int HasMoreSiblings
A Node status.

See Also:
Constant Field Values

IsExpanded

public static final int IsExpanded
A Node status.

See Also:
Constant Field Values

HasChildren

public static final int HasChildren
A Node status.

See Also:
Constant Field Values

FlagMask

protected static final int FlagMask
See Also:
Constant Field Values

DepthMask

protected static final int DepthMask
See Also:
Constant Field Values

PatternMask

protected static final int PatternMask
See Also:
Constant Field Values

openFolder

public static IImage openFolder

closedFolder

public static IImage closedFolder

page

public static IImage page

selectedColor

public Color selectedColor
Constructor Detail

TreeTableModel

public TreeTableModel()
Method Detail

canScreenScroll

public boolean canScreenScroll()
This always returns false.

Overrides:
canScreenScroll in class TableModel

toFlags

public byte toFlags(TreeNode what)
This determines from the TreeNode whether it is a leaf and whether it can expand.


toReference

public long toReference(TreeNode what)
Creates a reference for the TreeNode. By default this returns 0.


setRootObject

public void setRootObject(TreeNode root)

getRootObject

public TreeNode getRootObject()

scrollTo

public int scrollTo(int current,
                    int requested,
                    int scrollAction,
                    boolean horizontal)
This is called by the table to tell the model that it wants to scroll either vertically or horizontally. The method should return the correct position for the table to scroll to, given the current position and the requested position. By default it returns the requested position.

Overrides:
scrollTo in class TableModel

expandMatrix

protected void expandMatrix(int afterIndex,
                            int length)

countChildren

public int countChildren(int parent)
Return the number of children for a node at the specified index.


countTotalChildNodes

public int countTotalChildNodes(int parent)
Count all child nodes of a parent, including children of its children and so on.


removeEntries

protected int removeEntries(int start,
                            int toRemove)
If you override this to react to a remove, then make sure you call this.


collapseMatrix

protected int collapseMatrix(int parent)

init

public void init(long rootObjectRef,
                 byte flags)

shrunk

protected int shrunk(int byHowMany)

modify

protected void modify(int start,
                      int length,
                      int on,
                      int off)

findNextSibling

public int findNextSibling(int where)
Find the next sibling. Returns -1 if it cannot be found.


findPreviousSibling

public int findPreviousSibling(int where)
Find the previous sibling. Returns -1 if it cannot be found.


findParent

public int findParent(int where)
Find the parent. Returns -1 if it cannot be found.


findChild

public int findChild(int parent,
                     int whichChild)
Find the child within the parent. Returns -1 if it cannot be found.


indexOf

public int indexOf(int[] address)
Finds the index of the address specified. If the address is not displayed it will return -1.


addressOf

public int[] addressOf(TreeNode tn)
Return the address of the TreeNode relative to the root TreeNode.


columnOf

public int columnOf(int index)
Returns the column which contains the '+'/'-' box of the entry at the following index. The column which contains the icon and text is the one after.


expandTo

public int expandTo(int[] address)
This will expand down the tree until the address specified is displayed. It will returns the index of the final item or -1 if it could not expand.


expandToLevel

public void expandToLevel(int level)
This expands the tree a specified number of levels deep, below the root.

Parameters:
level - The number of levels below the root to display.

expandTo

public int expandTo(int[] address,
                    boolean selectIt)
This will exapand down the tree until the address specified is displayed. It will return true if the expansion was successfull.


findParentOrPreviousSibling

protected int findParentOrPreviousSibling(int where,
                                          boolean parent)

collapse

public int collapse(int whichIndex)
Collapse the index. It returns the number of items which have now been hidden.


expand

public int expand(int whichIndex,
                  long[] with,
                  byte[] flags)
Expand the index with the list of object references and the list of flags.


delete

public int delete(int line,
                  int length)
Remove a set of entries. This will only work if the entries are contiguous along the same depth AND none have any children. Collapse any open items you want to delete before calling this. It returns the number of items removed.


insert

public int insert(int parent,
                  int asChild,
                  long[] what,
                  byte[] flags)
This will only insert IF there are already children. If not, then it will do an expand and ignore the asChild parameter.


objectAt

public long objectAt(int line)
Find the object reference number of the line.


flagsAt

public int flagsAt(int line)
Returns the flags of the line.


updateFlags

public void updateFlags(int line,
                        byte newFlags)
This changes the flags for the node on a line. You should only use the flags IsNode and CanExpand.


addressOf

public int[] addressOf(int line)
Find the address of the line. This gives a set of child numbers with the first one being the child of the root. Therefore an address of {1,2,4} means the object is the 5th child(index starts at zero) of the 3rd child of the 2nd child of the root. If the address is of zero length, then it IS the root. If the address is null, then it is not in the tree. Here is a good way to locate an object from the address. Object child = root; for (int i = 0; i

getNodeToExpand

protected TreeNode getNodeToExpand(int whichIndex)
This is called by the default doExpand(). It will call getTreeNodeAt() and then call expanding() as a preparation to expand.


getNodeToCollapse

protected TreeNode getNodeToCollapse(int whichIndex)
This is called by the default doExpand(). It will call getTreeNodeAt() and then call expanding() as a preparation to expand.


canDoExpand

public boolean canDoExpand(int index)
Returns if the item at the specified index can be expanded.


canDoCollapse

public boolean canDoCollapse(int index)
Returns if the item at the specified index can be collapsed.


expanding

protected void expanding(TreeNode node)
                  throws SlowTaskException
Throws:
SlowTaskException

collapsing

protected void collapsing(TreeNode node)

doExpand

public int doExpand(int whichIndex)

doExpand

public int doExpand(int whichIndex,
                    TreeNode node)
Override this to do expansion. This explicitly expands the item at the specified index. It is as if the user pressed the '+' symbol of the node. It returns the number of lines added.


getTreeNodeAt

public TreeNode getTreeNodeAt(int index)

indexOf

public int indexOf(TreeNode node)
Return the line of the specified node IF it is displayed. If it is not displayed it will return -1.


doCollapse

public int doCollapse(int whichIndex)

getDisplayString

public String getDisplayString(int forLine,
                               TreeNode node)

getIcon

public IImage getIcon(int forLine,
                      TreeNode node)

deleted

public boolean deleted(TreeNode parent,
                       int previousIndexOfDeletedChild)
This assumes you are using TreeNode objects with the control. It will delete a single TreeNode as a child of another node ON THE DISPLAY. You must have already deleted it from the object tree. If the parent node was not expanded it will have no effect.


inserted

public boolean inserted(TreeNode parent,
                        TreeNode child,
                        boolean selectChild)
This assumes you are using TreeNode objects with the control. It will insert a single TreeNode as a child of another node ON THE DISPLAY. You must have already inserted it into the object tree. If the parent node was not expanded it will simply expand the parent node and thereby display the new node. If the parent node is not displayed at all it will have no effect. It will not update the display, call update() after to do so.


getDisplayStatus

public int getDisplayStatus(int forLine)
Get the display status for the specified line. This will Additional verbose

Parameters:
forLine -
Returns:

getFlags

public byte getFlags(int forLine,
                     TreeNode node)

calculateRowHeight

public int calculateRowHeight(int row)
Description copied from class: TableModel
This returns the full height of the row. If the requested row is -1 (header row) and there are no column headers it should return 0.

Overrides:
calculateRowHeight in class TableModel

getHeightOfObject

public int getHeightOfObject(Object obj)

calculateColWidth

public int calculateColWidth(int col)
Description copied from class: TableModel
This returns the full width of the column. If the requested col is -1 (header col) and there are no row headers it should return 0.

Overrides:
calculateColWidth in class TableModel

getTextRect

public Rect getTextRect(int index,
                        Rect dest)

isCut

public boolean isCut(TreeNode node)

getDrawOptions

protected int getDrawOptions(int line,
                             TreeNode node)

getDataWidth

public int getDataWidth(int line)

drawNodeData

public void drawNodeData(FontMetrics fm,
                         Graphics g,
                         int line,
                         Rect where,
                         Rect whereInTable,
                         TreeNode node)

drawNodeLine

public void drawNodeLine(Graphics g,
                         Rect r,
                         boolean nextTo,
                         int flags,
                         int row,
                         TreeNode node)

paintTableCell

public void paintTableCell(TableControl tc,
                           Graphics g,
                           int row,
                           int col)
Description copied from class: TableModel
The real biz. Paint a particular table cell. The Graphics g will be translated so that its origin will be the top left of cell(0,0). Remember that headers are on column -1 and row -1.

Overrides:
paintTableCell in class TableModel

paintLine

public void paintLine(int line)

paintLine

public void paintLine(TableControl tc,
                      Graphics g,
                      int line)

paintTableCell

public void paintTableCell(TableControl tc,
                           Graphics g,
                           Rect cells)
Description copied from class: TableModel
This paints a matrix of cells. The graphics has been translated so that the top left of the upper-left cell should be painted at 0,0. cells.width and cell.height give the width and height allocated to the cells. It should not paint any cells which is completely outside the bounds.

Overrides:
paintTableCell in class TableModel

fullExpandCollapse

public void fullExpandCollapse(int line)
This will either expand or collapse a node depending on its current state. It will also auto-select the item if selectExpanded is true.


getDataObjectAt

public Object getDataObjectAt(int line)
This returns getTreeNodeAt(line).


getDataToTransfer

public Object getDataToTransfer()

getDataToDragAndDrop

public boolean getDataToDragAndDrop(DragContext dc)

clicked

public void clicked(Point where)

selectOnly

public void selectOnly(int line)
Select an item - this does not fire a selection event.

Parameters:
line - the index of the line to select.

released

public void released(Point where)

pressed

public void pressed(Point where)

doubleClicked

public void doubleClicked(Point where)

fireSelection

public void fireSelection()

select

public void select(int index,
                   boolean selected)

countSelectedLines

public int countSelectedLines()

getSelectedRanges

public RangeList getSelectedRanges()

getSelectedLines

public int[] getSelectedLines()

isSelected

public boolean isSelected(int index)

selectAll

public void selectAll(boolean selectOn)
This either clears the selection or selects all. It will not do a repaint.


setSelectedLines

public void setSelectedLines(int[] all)

select

public void select(int line)
Selects the specified line.


update

public void update()

made

public void made()
Description copied from class: TableModel
This is called after the TableControl has been made.

Overrides:
made in class TableModel

reExpandSelectedNode

public void reExpandSelectedNode()
This will cause the selected Node to be collapsed and then expanded again.


reExpandNode

public void reExpandNode(int index)
This will cause the selected Node to be collapsed and then expanded again.


getMenuFor

public Menu getMenuFor(int line)