org.zaval.lw.grid
Class LwTreeGrid

java.lang.Object
  |
  +--org.zaval.util.ValidationObject
        |
        +--org.zaval.lw.LwCanvas
              |
              +--org.zaval.lw.LwPanel
                    |
                    +--org.zaval.lw.grid.LwGrid
                          |
                          +--org.zaval.lw.grid.LwTreeGrid
All Implemented Interfaces:
Drawable, java.util.EventListener, Layoutable, LayoutContainer, LwActionListener, LwChildrenListener, LwComponent, LwComposite, LwContainer, LwFocusListener, LwGridMetrics, LwGridViewProvider, LwKeyListener, LwLayout, LwMouseListener, MatrixListener, MatrixModel, PosInfo, PosListener, ScrollObj, TreeListener, Validationable

public class LwTreeGrid
extends LwGrid
implements LwGridViewProvider, MatrixModel, TreeListener, LwActionListener, LwComposite

This is light weight tree grid component. The functionality of the component bases on light weight grid component, but there are several essential differences:

The sample below illustrates the component usage:
   ...
   LwTreeGrid tg = new LwTreeGrid();
   // Creates tree model
   Item root = new Item(new Item("root"));
   TreeModel model = new Tree(root);
   model.add (root, new Item("Item 1"));
   model.add (root, new Item("Item 2"));
   model.add (root, new Item("Item 3"));
   // Sets tree model
   tg.setTreeModel(model);
   // Fills grid cells
   tg.getModel().put (0, 1, "Column[1] bound with root");
   tg.getModel().put (0, 2, "Column[2] bound with root");
   tg.getModel().put (1, 1, "Column[1] bound with item 1");
   // Sets cells editor provider
   tg.setEditorProvider(new LwDefEditors());
   // Adds top grid caption
   LwGridCaption cap = LwGridCaption(tg);
   tg.add (LwGrid.TOP_CAPTION_EL, cap);
   ...
 


Fields inherited from class org.zaval.lw.grid.LwGrid
colWidths, DEF_COLWIDTH, DEF_ROWHEIGHT, DRAW_HLINES, DRAW_VLINES, dx, dy, EDITOR_EL, ENABLE_COLRESIZE, LEFT_CAPTION_EL, rowHeights, TOP_CAPTION_EL, USE_PSMETRIC
 
Fields inherited from class org.zaval.lw.LwPanel
children
 
Fields inherited from class org.zaval.lw.LwCanvas
bits, height, insets, parent, psHeight, psWidth, skins, width, x, y
 
Fields inherited from class org.zaval.util.ValidationObject
isValidFlag
 
Constructor Summary
LwTreeGrid()
          Constructs the component with the default data model and tree model.
LwTreeGrid(TreeModel model)
          Constructs the component with the specified tree data model.
 
Method Summary
 void actionPerformed(LwActionEvent e)
          Invoked when an action event occured.
 void addMatrixListener(MatrixListener m)
          Adds the matrix listener to be notified whenever the matrix cell has been updated or the matrix dimension has been changed.
 boolean catchInput(LwComponent child)
          Checks if input events for the specified child component should be caught.
protected  java.lang.Object dataToPaint(int row, int col)
          Invoked whenever the component paints the specified cell to fetch data from the grid data model.
 java.lang.Object get(int row, int col)
          Gets the value of the specified cell.
 java.awt.Color getCellColor(int row, int col)
          Gets the the specified grid cell color.
 int getCols()
          Gets the number of columns.
protected  java.lang.Object getDataToEdit(int row, int col)
          Invoked whenever the component wants fetch data from the data model for the specified cell editing.
 int getGridCols()
          Gets the number of the grid columns.
 int getGridRows()
          Gets the number of the grid rows.
 Item getItemByRow(int row)
          Returns the tree item by the specified model row.
 int getModelRow(int gridRow)
          Converts and returns the model row by the specified grid row.
 int getRows()
          Gets the number of rows.
 Item getSelectedItem()
          Gets the selected tree item.
 TreeModel getTreeModel()
          Gets the tree model.
 LwView getView(int row, int col, java.lang.Object o)
          Gets the view of the specified cell and the given data model value.
 LwGridViewProvider getViewProvider()
          Gets the view provider.
 int getXAlignment(int row, int col)
          Gets the horizontal alignment for the specified grid cell.
 int getYAlignment(int row, int col)
          Gets the vertical alignment for the specified grid cell.
 void itemInserted(TreeEvent e)
          Invoked when the item has been inserted as a memeber of the source tree.
 void itemModified(TreeEvent e)
          Invoked when the item of the source tree has been modified.
 void itemRemoved(TreeEvent e)
          Invoked when the item has been removed from the source tree.
 void keyPressed(LwKeyEvent e)
          Invoked when a key has been pressed.
 void layout(LayoutContainer target)
          Lays out the child layoutable components inside the layout container.
 void mousePressed(LwMouseEvent e)
          Invoked when the mouse button has been pressed on a light weight component.
protected  void perform(MatrixEvent e)
          Performs the specified matrix event.
 void put(int row, int col, java.lang.Object o)
          Updates the specified cell with the specified value.
 void put(Item item, int row, int col, java.lang.Object o)
           
protected  void rCustomMetric()
          Invoked by vMetric method to calculate custom metric type.
 void removeMatrixListener(MatrixListener l)
          Removes the matrix listener.
protected  int rowHeight(int r)
          Returns the specified row height.
protected  void rPsMetric()
          Invoked by vMetric method to calculate preferred size metric type.
protected  void setEditedData(int row, int col, java.lang.Object value)
          Invoked whenever the component wants applies the edited value (for the specified cell) to the grid data model.
 void setExtraRowHeight(int h)
          Sets the extra rows height.
 void setModel(MatrixModel m)
          Sets the matrix model.
 void setRowHeight(int row, int h)
          It is impossible to use the method to define the row height.
 void setSOLocation(int dx, int dy)
          Sets the specified scroll object location.
 void setTreeElView(int id, LwView v)
          Sets the specified view for the specified tree view element.
 void setTreeModel(TreeModel m)
          Sets the tree model.
 void setTreeViewProvider(LwViewProvider p)
           
 void setViewProvider(LwGridViewProvider p)
          Sets the view provider.
 void startEditing(int row, int col)
          Starts editing of the specified grid cell.
 
Methods inherited from class org.zaval.lw.grid.LwGrid
calcPreferredSize, canHaveFocus, cellByLocation, cellModified, childPerformed, colWidth, componentAdded, componentRemoved, enableColResize, focusGained, focusLost, getCellInsets, getCellsVisibility, getColWidth, getColX, getDefaultLayout, getLines, getLineSize, getMaxOffset, getModel, getNetColor, getNetGap, getNetMask, getOrigin, getPosController, getRowHeight, getRowY, getSelectColor, getSOLocation, getSOSize, getTopCaption, getTopCaptionHeight, iColVisibility, iMetric, invalidate, iRowVisibility, isMetricValid, isUsePsMetric, keyReleased, keyTyped, matrixResized, mouseClicked, mouseEntered, mouseExited, mouseReleased, moveContent, pageSize, paint, paintData, paintMarker, paintNet, paintOnTop, posChanged, rPs, setCellInsets, setColWidth, setEditorProvider, setNetColor, setNetMask, setPosController, setScrollMan, setSelectColor, stopEditing, usePsMetric, validate, vMetric, vVisibility
 
Methods inherited from class org.zaval.lw.LwPanel
add, add, calcPreferredSize, count, get, getLayoutOffset, getLwComponentAt, getLwLayout, indexOf, insert, insert, recalc, remove, remove, removeAll, setBackground, setLwLayout, setOpaque, toFront, updateCashedPs
 
Methods inherited from class org.zaval.lw.LwCanvas
getBackground, getBounds, getHeight, getInsets, getLocation, getLwParent, getPreferredSize, getSize, getViewMan, getVisiblePart, getWidth, getX, getY, hasFocus, isEnabled, isOpaque, isVisible, repaint, repaint, requestFocus, setEnabled, setInsets, setLocation, setLwParent, setPSSize, setSize, setViewMan, setVisible, toString, update, viewManChanged, vrp
 
Methods inherited from class org.zaval.util.ValidationObject
isValid
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.zaval.lw.LwContainer
add, add, getLwLayout, indexOf, insert, paintOnTop, remove, removeAll, setLwLayout
 
Methods inherited from interface org.zaval.lw.LwComponent
canHaveFocus, getLwComponentAt, getLwParent, getViewMan, getVisiblePart, setBackground, setEnabled, setLwParent, setViewMan, setVisible
 
Methods inherited from interface org.zaval.lw.Drawable
getBackground, getOrigin, isEnabled, isOpaque, paint, repaint, repaint, setOpaque, update
 
Methods inherited from interface org.zaval.util.Validationable
invalidate, isValid, validate
 
Methods inherited from interface org.zaval.lw.Layoutable
getBounds, getHeight, getInsets, getLocation, getPreferredSize, getSize, getWidth, getX, getY, isVisible, setLocation, setSize
 
Methods inherited from interface org.zaval.lw.LayoutContainer
count, get, getLayoutOffset
 

Constructor Detail

LwTreeGrid

public LwTreeGrid()
Constructs the component with the default data model and tree model.

LwTreeGrid

public LwTreeGrid(TreeModel model)
Constructs the component with the specified tree data model.
Parameters:
model - the specified tree data model.
Method Detail

setModel

public void setModel(MatrixModel m)
Sets the matrix model. It is impossible to set own matrix model for the component because the matrix model has specific implementation to be bound with the tree model. The method is empty.
Overrides:
setModel in class LwGrid
Parameters:
m - the matrix model.

catchInput

public boolean catchInput(LwComponent child)
Description copied from interface: LwComposite
Checks if input events for the specified child component should be caught.
Specified by:
catchInput in interface LwComposite
Following copied from interface: org.zaval.lw.LwComposite
Parameters:
child - the specified child component.
Returns:
true if input events for the child component should be caught by this component; false otherwise.

setExtraRowHeight

public void setExtraRowHeight(int h)
Sets the extra rows height. The extra height defines value to increase rows heights from below and top.
Parameters:
h - the extra rows height.

getViewProvider

public LwGridViewProvider getViewProvider()
Description copied from class: LwGrid
Gets the view provider.
Overrides:
getViewProvider in class LwGrid
Following copied from class: org.zaval.lw.grid.LwGrid
Returns:
a view provider.

setTreeViewProvider

public void setTreeViewProvider(LwViewProvider p)

setTreeElView

public void setTreeElView(int id,
                          LwView v)
Sets the specified view for the specified tree view element. Use one of the following constants as the element view id:
Parameters:
id - the specified element id.
v - the specified view.

setViewProvider

public void setViewProvider(LwGridViewProvider p)
Description copied from class: LwGrid
Sets the view provider.
Overrides:
setViewProvider in class LwGrid
Following copied from class: org.zaval.lw.grid.LwGrid
Parameters:
p - the view provider.

mousePressed

public void mousePressed(LwMouseEvent e)
Description copied from interface: LwMouseListener
Invoked when the mouse button has been pressed on a light weight component.
Overrides:
mousePressed in class LwGrid
Following copied from interface: org.zaval.lw.event.LwMouseListener
Parameters:
e - the specified mouse event.

keyPressed

public void keyPressed(LwKeyEvent e)
Description copied from interface: LwKeyListener
Invoked when a key has been pressed.
Overrides:
keyPressed in class LwGrid
Following copied from interface: org.zaval.lw.event.LwKeyListener
Parameters:
e - the specified key event.

layout

public void layout(LayoutContainer target)
Description copied from interface: LwLayout
Lays out the child layoutable components inside the layout container.
Overrides:
layout in class LwGrid
Following copied from interface: org.zaval.lw.LwLayout
Parameters:
target - the layout container that needs to be laid out.

getView

public LwView getView(int row,
                      int col,
                      java.lang.Object o)
Description copied from interface: LwGridViewProvider
Gets the view of the specified cell and the given data model value.
Specified by:
getView in interface LwGridViewProvider
Following copied from interface: org.zaval.lw.grid.LwGridViewProvider
Parameters:
row - the specified cell row.
col - the specified cell column.
o - the specified data model value.
Returns:
a view.

getXAlignment

public int getXAlignment(int row,
                         int col)
Description copied from interface: LwGridViewProvider
Gets the horizontal alignment for the specified grid cell. The method should return one of the following values:
Specified by:
getXAlignment in interface LwGridViewProvider
Following copied from interface: org.zaval.lw.grid.LwGridViewProvider
Parameters:
row - the specified cell row.
col - the specified cell column.
Returns:
a horizontal alignment.

getYAlignment

public int getYAlignment(int row,
                         int col)
Description copied from interface: LwGridViewProvider
Gets the vertical alignment for the specified grid cell. The method should return one of the following values:
Specified by:
getYAlignment in interface LwGridViewProvider
Following copied from interface: org.zaval.lw.grid.LwGridViewProvider
Parameters:
row - the specified cell row.
col - the specified cell column.
Returns:
a vertical alignment.

getCellColor

public java.awt.Color getCellColor(int row,
                                   int col)
Description copied from interface: LwGridViewProvider
Gets the the specified grid cell color. The color is used to fill the cell background. If the cell has not own background than the method should return null.
Specified by:
getCellColor in interface LwGridViewProvider
Following copied from interface: org.zaval.lw.grid.LwGridViewProvider
Parameters:
row - the specified cell row.
col - the specified cell column.
Returns:
a color.

setTreeModel

public void setTreeModel(TreeModel m)
Sets the tree model.
Parameters:
m - the tree model.

getTreeModel

public TreeModel getTreeModel()
Gets the tree model.
Returns:
a tree model.

getRows

public int getRows()
Description copied from interface: MatrixModel
Gets the number of rows.
Specified by:
getRows in interface MatrixModel
Following copied from interface: org.zaval.data.MatrixModel
Returns:
a number of rows.

getCols

public int getCols()
Description copied from interface: MatrixModel
Gets the number of columns.
Specified by:
getCols in interface MatrixModel
Following copied from interface: org.zaval.data.MatrixModel
Returns:
a number of columns.

getGridRows

public int getGridRows()
Description copied from interface: LwGridMetrics
Gets the number of the grid rows.
Overrides:
getGridRows in class LwGrid
Following copied from interface: org.zaval.lw.grid.LwGridMetrics
Returns:
a number of the grid rows.

getGridCols

public int getGridCols()
Description copied from interface: LwGridMetrics
Gets the number of the grid columns.
Overrides:
getGridCols in class LwGrid
Following copied from interface: org.zaval.lw.grid.LwGridMetrics
Returns:
a number of the grid columns.

get

public java.lang.Object get(int row,
                            int col)
Description copied from interface: MatrixModel
Gets the value of the specified cell.
Specified by:
get in interface MatrixModel
Following copied from interface: org.zaval.data.MatrixModel
Parameters:
row - the specified row.
col - the specified column.
Returns:
a value.

actionPerformed

public void actionPerformed(LwActionEvent e)
Description copied from interface: LwActionListener
Invoked when an action event occured. The specified action event is passed to the method.
Specified by:
actionPerformed in interface LwActionListener
Following copied from interface: org.zaval.lw.event.LwActionListener
Parameters:
e - the specified action event.

put

public void put(int row,
                int col,
                java.lang.Object o)
Description copied from interface: MatrixModel
Updates the specified cell with the specified value.
Specified by:
put in interface MatrixModel
Following copied from interface: org.zaval.data.MatrixModel
Parameters:
row - the specified row.
col - the specified column.
obj - the specified value to update the cell value.

put

public void put(Item item,
                int row,
                int col,
                java.lang.Object o)

addMatrixListener

public void addMatrixListener(MatrixListener m)
Description copied from interface: MatrixModel
Adds the matrix listener to be notified whenever the matrix cell has been updated or the matrix dimension has been changed.
Specified by:
addMatrixListener in interface MatrixModel
Following copied from interface: org.zaval.data.MatrixModel
Parameters:
l - the matrix listener.

removeMatrixListener

public void removeMatrixListener(MatrixListener l)
Description copied from interface: MatrixModel
Removes the matrix listener.
Specified by:
removeMatrixListener in interface MatrixModel
Following copied from interface: org.zaval.data.MatrixModel
Parameters:
l - the matrix listener.

itemInserted

public void itemInserted(TreeEvent e)
Description copied from interface: TreeListener
Invoked when the item has been inserted as a memeber of the source tree.
Specified by:
itemInserted in interface TreeListener
Following copied from interface: org.zaval.data.event.TreeListener
Parameters:
e - the specified event.

itemRemoved

public void itemRemoved(TreeEvent e)
Description copied from interface: TreeListener
Invoked when the item has been removed from the source tree.
Specified by:
itemRemoved in interface TreeListener
Following copied from interface: org.zaval.data.event.TreeListener
Parameters:
e - the specified event.

itemModified

public void itemModified(TreeEvent e)
Description copied from interface: TreeListener
Invoked when the item of the source tree has been modified.
Specified by:
itemModified in interface TreeListener
Following copied from interface: org.zaval.data.event.TreeListener
Parameters:
e - the specified event.

setSOLocation

public void setSOLocation(int dx,
                          int dy)
Description copied from interface: ScrollObj
Sets the specified scroll object location. The method defines a mechanism that will be used to scrool the object.
Overrides:
setSOLocation in class LwGrid
Following copied from interface: org.zaval.misc.ScrollObj
Parameters:
x - the specified x coordinate.
y - the specified y coordinate.

setRowHeight

public void setRowHeight(int row,
                         int h)
It is impossible to use the method to define the row height. In this case the runtime exception will be thrown.
Overrides:
setRowHeight in class LwGrid
Following copied from interface: org.zaval.lw.grid.LwGridMetrics
Parameters:
row - the specified row.
h - the specified height.

getModelRow

public int getModelRow(int gridRow)
Converts and returns the model row by the specified grid row.
Parameters:
gridRow - the specified grid row.
Returns:
a model row.

getSelectedItem

public Item getSelectedItem()
Gets the selected tree item.
Returns:
a selected tree item.

startEditing

public void startEditing(int row,
                         int col)
Description copied from class: LwGrid
Starts editing of the specified grid cell. The method initiates editing process if the editor provider has been defined for the grid component and the editor component exists.
Overrides:
startEditing in class LwGrid
Following copied from class: org.zaval.lw.grid.LwGrid
Parameters:
row - the specified cell row.
col - the specified cell column.

getItemByRow

public Item getItemByRow(int row)
Returns the tree item by the specified model row. Draw attention that the method requires model row not a visible grid row.
Parameters:
row - the specified model row.
Returns:
a tree item.

perform

protected void perform(MatrixEvent e)
Performs the specified matrix event.
Parameters:
e - the specified matrix event.

rCustomMetric

protected void rCustomMetric()
Description copied from class: LwGrid
Invoked by vMetric method to calculate custom metric type.
Overrides:
rCustomMetric in class LwGrid

rPsMetric

protected void rPsMetric()
Description copied from class: LwGrid
Invoked by vMetric method to calculate preferred size metric type.
Overrides:
rPsMetric in class LwGrid

dataToPaint

protected java.lang.Object dataToPaint(int row,
                                       int col)
Description copied from class: LwGrid
Invoked whenever the component paints the specified cell to fetch data from the grid data model.
Overrides:
dataToPaint in class LwGrid
Following copied from class: org.zaval.lw.grid.LwGrid
Parameters:
row - the specified row.
col - the specified column.
Returns:
data to be painted.

getDataToEdit

protected java.lang.Object getDataToEdit(int row,
                                         int col)
Description copied from class: LwGrid
Invoked whenever the component wants fetch data from the data model for the specified cell editing.
Overrides:
getDataToEdit in class LwGrid
Following copied from class: org.zaval.lw.grid.LwGrid
Parameters:
row - the specified row.
col - the specified column.
Returns:
data model value to edit.

setEditedData

protected void setEditedData(int row,
                             int col,
                             java.lang.Object value)
Description copied from class: LwGrid
Invoked whenever the component wants applies the edited value (for the specified cell) to the grid data model.
Overrides:
setEditedData in class LwGrid
Following copied from class: org.zaval.lw.grid.LwGrid
Parameters:
row - the specified row.
col - the specified column.
value - the specified edited value.

rowHeight

protected int rowHeight(int r)
Description copied from class: LwGrid
Returns the specified row height. The method is used by all other methods (except recalculation) to get the actual row height.
Overrides:
rowHeight in class LwGrid
Following copied from class: org.zaval.lw.grid.LwGrid
Parameters:
row - the specified row.
Returns:
the specified row height.


Copyright © Zaval Creative Engineering Group, 2000-2005.
http://www.zaval.org