ewe.ui
Class TableModel

java.lang.Object
  extended byewe.ui.TableModel
All Implemented Interfaces:
CellConstants, ControlConstants, EventListener, UIConstants
Direct Known Subclasses:
FieldTableModel, FileListTableModel, GridTableModel, HexTableModel, IconTableModel, InputPanelTableModel, TreeTableModel

public class TableModel
extends Object
implements UIConstants, EventListener


Nested Class Summary
 class TableModel.CellControl
          This class is used to contain and control a Control that is used to edit data within a Cell in the TableModel.
static class TableModel.ControlProxy
           
 
Field Summary
 TableModel.CellControl activeCellControl
           
 boolean allColumnsSameSize
          This will result in an adjustment to one column affecting all columns.
 boolean allRowsSameSize
          This will result in an adjustment to one row affecting all row.
 boolean canHScroll
          Specifies whether the table can scroll horizontally.
 boolean canVScroll
          Specifies whether the table can scroll vertically.
 Insets cellInsets
          Set this to be the default insets for each cell.
 int charHeight
          This is set to the height of the Font of the table once the control has been made.
 int charWidth
          This is set to the width of the 'X' character of the Font of the table once the control has been made.
 boolean clipData
          If this is true then the data will be clipped to fit into the cells.
protected static TableModel.ControlProxy controlProxy
           
 Dimension cursorSize
          This specifies the size of the cursor, in cells.
 boolean fillToEqualHeights
          Specifies whether the table should have all cell heights equal and fit exactly in the display area.
 boolean fillToEqualWidths
          Specifies whether the table should have all cell widths equal and fit exactly in the display area.
 int gap
          This is the gap (in pixels) between the data in a cell and its borders.
 boolean hasColumnHeaders
          Specifies whether the table has column headers.
 boolean hasPreferredSize
          Specifies whether the table has a preferred size.
 boolean hasRowHeaders
          Specifies whether the table has row headers.
 boolean hasSpanningColumns
          This must be set true if you have data in columns which span across multiple columns.
 boolean hasSpanningRows
          This must be set true if you have data in rows which span across multiple rows.
 int horizontalScrollUnit
          This specifies how many columns you can scroll as a unit.
protected  Insets insets
           
 int numCols
          The number of columns in the table.
 int numRows
          The number of rows in the table.
 int preferredCols
           
 int preferredRows
           
protected  Rect rect
           
 boolean selectRowWhenEditing
          This tells the model to select the row of a cell whenever that cell is edited.
 boolean shadeAlternateRows
          This will shade every other row.
protected  TableControl table
          This is the table which contains the model.
protected  TableCellAttributes tca
           
 int verticalScrollUnit
          This specifies how many rows you can scroll as a unit.
 
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
TableModel()
           
 
Method Summary
 int calculateColWidth(int col)
          This returns the full width of the column.
 int calculateRowHeight(int row)
          This returns the full height of the row.
protected  int calculateTextCharsInColumn(int col)
          This is called by calculateColWidth().
protected  int calculateTextLinesInRow(int row)
          This is called by calculateColWidth().
 boolean canScreenScroll()
          This is used to report whether a quick pixel scroll can be done on the table.
 boolean canSelect(int row, int col)
          This should return whether or not a particular cell may be selected.
protected  boolean checkControlFor(Point onTable, Point cell, int how)
           
 void clearCellAdjustments()
           
 boolean closeActiveControl()
          This tells the model to close any active control.
protected  void deferPaintTableCell(TableControl tc, Graphics g, int row, int col)
           
 boolean doHotKey(KeyEvent ev)
           
 void findCellsInArea(Rect area, boolean onlyCompletely)
          This finds the range of cells in the given area.
protected  int fixBorder(int style, int row, int col, boolean flat)
           
 TableCellAttributes getCellAttributes(int row, int col, boolean isSelected, TableCellAttributes ta)
          Get the attributes for a cell.
protected  TableModel.CellControl getCellControlFor(Point cell)
          Get a Control to edit data within a particular cell within a CellControl object.
 Object getCellData(int row, int col)
          This may return any object.
 Insets getCellInsets(int row, int col, Insets insets)
          Get the insets of the data in the specified cell.
 Dimension getCellPreferredSize(int row, int col, FontMetrics fm, Dimension dest)
           
 boolean getCellRect(int row, int col, Rect dest)
          Get the bounds of the specified cell within the table - with 0,0 being the upper left corner of cell(table.firstRow,table.firstCol) - Note that the headers are considered outside of the table in this case (header indexes are -1).
 Object getCellText(int row, int col)
          This may return a String or an array of Strings (for multiline text) or it may return null.
 int getColWidth(int col)
          Do not override this.
protected  Control getControlFor(int row, int col)
          This is called by getCellControlFor() and is used to return a Control to allow editing of a cell's contents.
protected  String[] getLinesFor(Object obj)
           
protected  int getMaxColWidth(int col)
          If this returns -1 there will be no maximum.
protected  int getMaxRowHeight(int row)
          If this returns -1 there will be no maximum.
 Menu getMenuFor(int row, int col)
           
 Menu getMenuOutsideCells(Point screenPoint)
           
protected  int getMinColWidth(int col)
           
protected  int getMinRowHeight(int row)
           
 Dimension getPreferredSize(Dimension dest)
          In order for this to do anything you must set "hasPreferredSize" to true.
 int getRowHeight(int row)
          Do not override this.
 Object getToolTip(int x, int y)
          Return a Tool Tip for the x,y position (in pixels) on the table.
 boolean hasActiveControls()
           
protected  void inset(int row, int col, Rect rect)
           
 boolean isActiveCellControl(int row, int column)
          Returns if there is an active CellControl at the specified row and column.
 void made()
          This is called after the TableControl has been made.
protected  void notifyDataChange(Point cell)
          This is called by a CellControl when it gets a DataChanged event from its Control.
 void onEvent(Event ev)
           
 boolean onKeyEvent(KeyEvent ev)
          This is called by the TableControl before it processes the event.
 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.
protected  void paintTableCellData(TableControl tc, Graphics g, int row, int col, TableCellAttributes tca, Rect r, Object data)
          Paint the data within the cell.
protected  void paintTableCellText(TableControl tc, Graphics g, int row, int col, TableCellAttributes tca, Rect r, Object text)
          Paint the data within the cell.
 boolean penPressed(Point onTable, Point cell)
          If this returns true, then the TableControl will not process a pen press any further.
 boolean popupMenuEvent(MenuEvent ev)
           
protected  void remapColumns(int[] oldPositions)
           
 void resized(int width, int height)
          This is called after the TableControl has been resized.
 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 row, int col, boolean selectOn)
          This is called by the table to tell the model that it wants to select a particular cell.
protected  void show(TableModel.CellControl cc, int how)
           
protected  void startedEditing(Point cell)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Field Detail

gap

public int gap
This is the gap (in pixels) between the data in a cell and its borders. If getCellInsets() returns null, then this gap will be used as the top,left,bottom and right insets.


clipData

public boolean clipData
If this is true then the data will be clipped to fit into the cells. If you know the data will not need clipping then switching this off will produce faster cell drawing. By default it is off.


numRows

public int numRows
The number of rows in the table.


numCols

public int numCols
The number of columns in the table.


hasColumnHeaders

public boolean hasColumnHeaders
Specifies whether the table has column headers.


hasRowHeaders

public boolean hasRowHeaders
Specifies whether the table has row headers.


fillToEqualWidths

public boolean fillToEqualWidths
Specifies whether the table should have all cell widths equal and fit exactly in the display area.


fillToEqualHeights

public boolean fillToEqualHeights
Specifies whether the table should have all cell heights equal and fit exactly in the display area.


hasPreferredSize

public boolean hasPreferredSize
Specifies whether the table has a preferred size.


canHScroll

public boolean canHScroll
Specifies whether the table can scroll horizontally.


canVScroll

public boolean canVScroll
Specifies whether the table can scroll vertically.


table

protected TableControl table
This is the table which contains the model.


horizontalScrollUnit

public int horizontalScrollUnit
This specifies how many columns you can scroll as a unit.


verticalScrollUnit

public int verticalScrollUnit
This specifies how many rows you can scroll as a unit.


hasSpanningColumns

public boolean hasSpanningColumns
This must be set true if you have data in columns which span across multiple columns.


hasSpanningRows

public boolean hasSpanningRows
This must be set true if you have data in rows which span across multiple rows.


shadeAlternateRows

public boolean shadeAlternateRows
This will shade every other row.


allColumnsSameSize

public boolean allColumnsSameSize
This will result in an adjustment to one column affecting all columns. It does not count for the header column.


allRowsSameSize

public boolean allRowsSameSize
This will result in an adjustment to one row affecting all row. It does not count for the header row.


charWidth

public int charWidth
This is set to the width of the 'X' character of the Font of the table once the control has been made. It is set in the made() method.


charHeight

public int charHeight
This is set to the height of the Font of the table once the control has been made. It is set in the made() method.


preferredRows

public int preferredRows

preferredCols

public int preferredCols

cursorSize

public Dimension cursorSize
This specifies the size of the cursor, in cells. A null value indicates a standard cursor one cell wide and high. A Dimension with either width or height being 0 indicates no cursor. A Dimension with width being -1 indicates that the entire row must be selected. A Dimension with height being -1 indicates that the entire column must be selected.


cellInsets

public Insets cellInsets
Set this to be the default insets for each cell. By default it is null.


tca

protected TableCellAttributes tca

rect

protected Rect rect

insets

protected Insets insets

activeCellControl

public TableModel.CellControl activeCellControl

selectRowWhenEditing

public boolean selectRowWhenEditing
This tells the model to select the row of a cell whenever that cell is edited. By default it is true.


controlProxy

protected static TableModel.ControlProxy controlProxy
Constructor Detail

TableModel

public TableModel()
Method Detail

hasActiveControls

public boolean hasActiveControls()

onEvent

public void onEvent(Event ev)
Specified by:
onEvent in interface EventListener

select

public void select(int row,
                   int col,
                   boolean selectOn)
This is called by the table to tell the model that it wants to select a particular cell. The model should then call table.addToSelection() to add it to the selection. Alternately the model can add more or different cells.


canScreenScroll

public boolean canScreenScroll()
This is used to report whether a quick pixel scroll can be done on the table.


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.


remapColumns

protected final void remapColumns(int[] oldPositions)

clearCellAdjustments

public void clearCellAdjustments()

getMinColWidth

protected int getMinColWidth(int col)

getMaxColWidth

protected int getMaxColWidth(int col)
If this returns -1 there will be no maximum.


getMaxRowHeight

protected int getMaxRowHeight(int row)
If this returns -1 there will be no maximum.


getMinRowHeight

protected int getMinRowHeight(int row)

getColWidth

public final int getColWidth(int col)
Do not override this. Instead override calculateColWidth().


getRowHeight

public final int getRowHeight(int row)
Do not override this. Instead override calculateRowHeight().


calculateTextCharsInColumn

protected int calculateTextCharsInColumn(int col)
This is called by calculateColWidth(). It should give the number of characters that should fit in a column.


calculateTextLinesInRow

protected int calculateTextLinesInRow(int row)
This is called by calculateColWidth(). It should give the number of text lines that should fit in a row.


calculateColWidth

public int calculateColWidth(int col)
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.


calculateRowHeight

public int calculateRowHeight(int row)
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.


getCellInsets

public Insets getCellInsets(int row,
                            int col,
                            Insets insets)
Get the insets of the data in the specified cell. If "insets" is null a new one will be created. If this function returns null it is to be interpreted as zero insets. Insets are used for all data EXCEPT Controls.


getCellRect

public boolean getCellRect(int row,
                           int col,
                           Rect dest)
Get the bounds of the specified cell within the table - with 0,0 being the upper left corner of cell(table.firstRow,table.firstCol) - Note that the headers are considered outside of the table in this case (header indexes are -1). This is done because when the table is being scrolled the headers will not move and be handled separately. Dest must NOT be null.

Parameters:
row -
col -
dest -
Returns:
true if the cell is at least partly visible, false if the cell is not visible at all.

getCellData

public Object getCellData(int row,
                          int col)
This may return any object. If getCellText() returns a String or array of Strings then the data returned by this will be ignored and the text will be displayed as the contents via paintTableCellText(). Otherwise - if getCellText() return null - a call to paintTableCellData() will be used, with the data returned by this method. By default, paintTableCellData() calls toString() on the data and displays it in the cell. To display other things, you will have to override paintTableCellData().


getCellText

public Object getCellText(int row,
                          int col)
This may return a String or an array of Strings (for multiline text) or it may return null. If it returns null then the value returned by getCellData(r,c) will be used to paint the cell contents.


getCellPreferredSize

public Dimension getCellPreferredSize(int row,
                                      int col,
                                      FontMetrics fm,
                                      Dimension dest)

getPreferredSize

public Dimension getPreferredSize(Dimension dest)
In order for this to do anything you must set "hasPreferredSize" to true.


fixBorder

protected int fixBorder(int style,
                        int row,
                        int col,
                        boolean flat)

isActiveCellControl

public boolean isActiveCellControl(int row,
                                   int column)
Returns if there is an active CellControl at the specified row and column.


getCellAttributes

public TableCellAttributes getCellAttributes(int row,
                                             int col,
                                             boolean isSelected,
                                             TableCellAttributes ta)
Get the attributes for a cell. Note that even though a TableCellAttributes is passed to the method, for effeciency a completely different one may be returned. You should therefore not attempt to modify or reuse the one that is returned.


canSelect

public boolean canSelect(int row,
                         int col)
This should return whether or not a particular cell may be selected. Note that selecting a column or row header (row == -1 or col == -1) results in the entire row/column being selected.


findCellsInArea

public void findCellsInArea(Rect area,
                            boolean onlyCompletely)
This finds the range of cells in the given area. The area parameter must be set up as follows: area.x = col of top left cell. area.y = row of top left cell. area.width = width of area on the screen. area.height = height of area on the screen. When the function returns area.width and area.height will be modified as: area.width = number of cells displayed horizontally. area.height = number of cells displayed vertically. If onlyCompletely is true the number of cells shows how many cells are COMPLETELY in the area.


inset

protected void inset(int row,
                     int col,
                     Rect rect)

paintTableCell

public void paintTableCell(TableControl tc,
                           Graphics g,
                           int row,
                           int col)
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.


deferPaintTableCell

protected void deferPaintTableCell(TableControl tc,
                                   Graphics g,
                                   int row,
                                   int col)

paintTableCell

public void paintTableCell(TableControl tc,
                           Graphics g,
                           Rect cells)
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.


getLinesFor

protected String[] getLinesFor(Object obj)

paintTableCellData

protected void paintTableCellData(TableControl tc,
                                  Graphics g,
                                  int row,
                                  int col,
                                  TableCellAttributes tca,
                                  Rect r,
                                  Object data)
Paint the data within the cell. This can print text, IImages and Controls.


paintTableCellText

protected void paintTableCellText(TableControl tc,
                                  Graphics g,
                                  int row,
                                  int col,
                                  TableCellAttributes tca,
                                  Rect r,
                                  Object text)
Paint the data within the cell.


made

public void made()
This is called after the TableControl has been made.


resized

public void resized(int width,
                    int height)
This is called after the TableControl has been resized.


getToolTip

public Object getToolTip(int x,
                         int y)
Return a Tool Tip for the x,y position (in pixels) on the table. In this method you can do:
        Point cell = table.cellAtPoint(x,y,null);
        if (cell == null) return null; //Not on a cell.
        // Now cell.x will have the column and cell.y will have the row
        // of the cell the mouse is over and you can then display a tool tip for that cell.
        

Parameters:
x - The x co-ordinate in pixels of the mouse.
y - The y co-ordinate in pixels of the mouse.
Returns:
An acceptable ToolTip object.

getMenuFor

public Menu getMenuFor(int row,
                       int col)

getMenuOutsideCells

public Menu getMenuOutsideCells(Point screenPoint)

popupMenuEvent

public boolean popupMenuEvent(MenuEvent ev)

penPressed

public boolean penPressed(Point onTable,
                          Point cell)
If this returns true, then the TableControl will not process a pen press any further.


closeActiveControl

public boolean closeActiveControl()
This tells the model to close any active control. It returns true if a control was actually active.


startedEditing

protected void startedEditing(Point cell)

onKeyEvent

public boolean onKeyEvent(KeyEvent ev)
This is called by the TableControl before it processes the event. If this method returns true, then the TableControl will not process the key.


doHotKey

public boolean doHotKey(KeyEvent ev)

checkControlFor

protected final boolean checkControlFor(Point onTable,
                                        Point cell,
                                        int how)

show

protected final void show(TableModel.CellControl cc,
                          int how)

getCellControlFor

protected TableModel.CellControl getCellControlFor(Point cell)
Get a Control to edit data within a particular cell within a CellControl object. This is called when the pen is pressed on a Control. By default this method calls getControlFor() and if that does not return null, then a new CellControl is created and returned for that Control.

Parameters:
cell - the cell the CellControl is for.
Returns:
a CellControl used to edit data for a particular cell, or null if editing that cell data is not allowed.

getControlFor

protected Control getControlFor(int row,
                                int col)
This is called by getCellControlFor() and is used to return a Control to allow editing of a cell's contents. By default this method returns null.

Parameters:
row - the row of the cell.
col - the column of the cell.
Returns:
a Control used to edit data for a particular cell, or null if editing that cell data is not allowed.

notifyDataChange

protected void notifyDataChange(Point cell)
This is called by a CellControl when it gets a DataChanged event from its Control.

Parameters:
cell - the cell containing the Control. By default this will call notifyDataChange() in the containing TableControl with the cause field being set to the Point indicating the cell that the data was changed in.