public class TableModel extends Object implements UIConstants, EventListener
Modifier and Type | Class and Description |
---|---|
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 |
Modifier and Type | Field and Description |
---|---|
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 |
canMoveColumnHeaders
Set this true to allow the re-arranging of column headers.
|
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 Vector |
colAdjustments |
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.
|
boolean |
keepSIP
If this is true, then when a Control within the table becomes active the
SIP will be kept on if it already is.
|
protected Point |
mouseIsOverCell |
int |
numCols
The number of columns in the table.
|
int |
numRows
The number of rows in the table.
|
int |
preferredCols
If hasPreferredSize is false, then the preferred width of the table is calculated
using this number of columns.
|
int |
preferredRows
If hasPreferredSize is false, then the preferred height of the table is calculated
using this number of rows.
|
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.
|
Color |
shadeColor
The Color to use for shading alternate rows.
|
protected TableControl |
table
This is the table which contains the model.
|
int |
verticalScrollUnit
This specifies how many rows you can scroll as a unit.
|
BDR_DOTTED, BDR_INNER, BDR_NOBORDER, BDR_OUTER, BDR_OUTLINE, BDR_RAISEDINNER, BDR_RAISEDOUTER, BDR_SUNKENINNER, BDR_SUNKENOUTER, BF_ABUT_ANY, BF_ABUT_BOTTOM, BF_ABUT_LEFT, BF_ABUT_RIGHT, BF_ABUT_TOP, 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
ALWAYS_STRETCHABLE, BOTTOM, CELLFLAG, CELLMASK, CENTER, CONTROLMASK, DONTCHANGE, DONTFILL, DONTSTRETCH, EAST, FILL, GROW, HCENTER, HCONTRACT, HEXPAND, HFILL, HGROW, HSHRINK, HSTRETCH, INITIALLY_CLOSED, INITIALLY_HIDDEN, INITIALLY_MINIMIZED, INITIALLY_PREFERRED_SIZE, INSETS, LEFT, MAXIMUMSIZE, MINIMUMSIZE, NORTH, NORTHEAST, NORTHWEST, PREFERREDSIZE, RECT, RIGHT, SHRINK, SOUTH, SOUTHEAST, SOUTHWEST, SPAN, STRETCH, TAG_BACKGROUND_IMAGE, TAG_BUSY_DISPLAY, TAG_COLORS, TAG_CONTROL_PAINTER, TAG_EXPOSE_GROUP, TAG_FIXEDSIZE, TAG_GRAY_BACKGROUND, TAG_HIDE_CONTROL_OBJECT, TAG_HIDE_PARENT, TAG_INNER_TEXT_INSETS, TAG_INPUT_STACK_PARENT, TAG_INSETS, TAG_MAKE_VISIBLE, TAG_MAXIMUMSIZE, TAG_MINIMUMSIZE, TAG_PAINT_CONTROL_LIST, TAG_PREFERRED_TEXT_SIZE, TAG_PREFERRED_TEXT_SIZE_HEIGHT, TAG_PREFERRED_TEXT_SIZE_WIDTH, TAG_PREFERREDSIZE, TAG_RECT, TAG_SHADOW_INSETS, TAG_SPAN, TAG_SWIPER, TAG_TEMPORARY_ERROR, TAG_TEXT_INSETS, TAG_TEXTSIZE, TEXTSIZE, TOP, VCENTER, VCONTRACT, VEXPAND, VFILL, VGROW, VSHRINK, VSTRETCH, WEST
All, AlwaysEnabled, AlwaysRecalculateSizes, ByDeferredMouse, ByDeferredPen, ByFrameChange, ByKeyboard, ByMouse, ByPen, ByRequest, CalculatedSizes, ContainerDontPaintChildren, Disabled, DisablePopupMenu, DisplayOnly, DontBuffer, Down, DrawFlat, Flag, ForceResize, HasData, Invisible, KeepImage, KeepSIP, Left, MakeMenuAtLeastAsWide, Maximize, Minimize, ModifiersInheritedFromWindow, MouseSensitive, NoFocus, NotAnEditor, NotEditable, PaintDataOnly, PaintOutsideOnly, PenTransparent, PreferredSizeOnly, Right, SendUpUIEvents, ShowSIP, ShrinkToNothing, SmallControl, TakeChildUIEvents, TakeControlEvents, TakesKeyFocus, Transparent, Up, WantDrag, WantHoldDown
Constructor and Description |
---|
TableModel() |
Modifier and Type | Method and Description |
---|---|
protected void |
acceptColumnMoved(int oldIndex,
int newIndex)
Call this in a columnMoved() call if the column moved has been accepted and implemented.
|
int |
calculateColWidth(int col)
This returns the full width of the column.
|
int |
calculatePreferredColWidth(int col)
By default, this calls calculateColWidth().
|
int |
calculatePreferredRowHeight(int row)
By default, this calls calculateRowHeight().
|
static boolean |
calculatePreferredSize(Object data,
FontMetrics fm,
Dimension dest)
Calculate the exact size of the provided data depending on the type of data.
|
int |
calculateRowHeight(int row)
This returns the full height of the row.
|
void |
calculateSizes()
This is called after the TableControl has been made.
|
protected int |
calculateTextCharsInColumn(int col)
This is called by calculateColWidth().
|
protected int |
calculateTextLinesInRow(int row)
This is called by calculateColWidth().
|
boolean |
canScreenScroll(boolean horizontally)
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() |
protected void |
clearColumnWidthAdjustments()
Remove all adjustments made by the user to the column widths.
|
boolean |
clearSelectionOnClick() |
boolean |
closeActiveControl()
This tells the model to close any active control.
|
protected void |
columnMoved(int oldIndex,
int newIndex)
This is a request from the TableControl that the column should be moved from the oldIndex to the newIndex.
|
protected void |
deferPaintTableCell(TableControl tc,
Graphics g,
int row,
int col) |
boolean |
doHotKey(KeyEvent ev) |
boolean |
editNow(Point cell,
boolean byPen) |
boolean |
editNow(Point cell,
int how,
boolean penPressOnTable) |
protected void |
endEditing(Point cell) |
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) |
Closes |
freezeUpdate(boolean updateOnClose) |
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.
|
boolean |
getCellText(int row,
int col,
StringList destination)
Override this to provide text data to display in a cell.
|
int |
getColWidth(int col)
Do not override this.
|
int |
getColXPointInTable(int col) |
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.
|
ReadWriteLock |
getLock() |
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)
Get the preferred size of the TableModel.
|
int |
getRowHeight(int row)
Do not override this.
|
int |
getRowYPointInTable(int row) |
TableControl |
getTable() |
Object |
getToolTip(int x,
int y)
Return a Tool Tip for the x,y position (in pixels) on the table.
|
boolean |
handleEvent(Event ev) |
boolean |
hasActiveControls() |
protected boolean |
hasCellControlFor(Point cell) |
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() |
void |
makeActiveControlVisible() |
void |
mouseMoving(boolean isOnValidCell,
PenEvent pe,
int cellRow,
int cellCol) |
protected void |
mouseOverChanged(Point was,
Point isNow) |
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,
StringList text)
Paint the data within the cell.
|
boolean |
penClicked(Point onTable,
Point 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 |
positionCellControl(int row,
int col,
Control c) |
protected void |
remapColumns(int[] oldPositions) |
void |
resized(int width,
int height)
This is called after the TableControl has been resized.
|
protected void |
restoreColumnWidthAdjustments(Vector newColumnObjects,
Map saved) |
protected void |
saveColumnWidthAdjustments(Vector columnObjects,
Map destination)
Save the column adjustments into a destination map.
|
void |
scrolled(TableControl table,
int newFirstRow,
int newFirstCol,
int oldFirstRow,
int oldFirstCol) |
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.
|
void |
setColAdjust(int col,
int dx) |
void |
setColWidth(int col,
int width) |
protected void |
show(TableModel.CellControl cc,
int how) |
protected void |
showingMenuFor(int row,
int col)
This is called just before the popup menu for a cell is shown.
|
void |
sizeColumnToFitData(int column) |
protected void |
startedEditing(Point cell) |
protected void |
updateControls(boolean start) |
public int gap
public boolean clipData
public int numRows
public int numCols
public boolean hasColumnHeaders
public boolean hasRowHeaders
public boolean fillToEqualWidths
public boolean fillToEqualHeights
public boolean hasPreferredSize
public boolean canHScroll
public boolean canVScroll
protected TableControl table
public int horizontalScrollUnit
public int verticalScrollUnit
public boolean hasSpanningColumns
public boolean hasSpanningRows
public boolean shadeAlternateRows
public boolean allColumnsSameSize
public boolean allRowsSameSize
public int charWidth
public int charHeight
public int preferredRows
public int preferredCols
public Dimension cursorSize
public boolean keepSIP
public boolean canMoveColumnHeaders
public Color shadeColor
protected Vector colAdjustments
public Insets cellInsets
public TableModel.CellControl activeCellControl
public boolean selectRowWhenEditing
protected Point mouseIsOverCell
protected static TableModel.ControlProxy controlProxy
public ReadWriteLock getLock()
protected void showingMenuFor(int row, int col)
row
- the row of the cell the menu is for - this may be -2 if it
is not on a valid row.col
- the column of the cell the menu is for - this may be -2 if it
is not on a valid column.protected void columnMoved(int oldIndex, int newIndex)
You should update the table yourself as necessary and if the column move is accepted and implemented then you should call acceptColumnMoved() to allow the col width adjustments to stay in effect.
oldIndex
- newIndex
- protected final void acceptColumnMoved(int oldIndex, int newIndex)
oldIndex
- newIndex
- protected void clearColumnWidthAdjustments()
protected void saveColumnWidthAdjustments(Vector columnObjects, Map destination)
columnObjects
- a vector of objects where each item corresponds to each column (except
for the column at -1 (the row header column) if it exists.)destination
- the destination map.protected void restoreColumnWidthAdjustments(Vector newColumnObjects, Map saved)
public int getColXPointInTable(int col)
public int getRowYPointInTable(int row)
public TableControl getTable()
public boolean hasActiveControls()
public void onEvent(Event ev)
public boolean handleEvent(Event ev)
public void select(int row, int col, boolean selectOn)
public boolean canScreenScroll(boolean horizontally)
horizontally
- true if a check on horizontal scrolling is being done, false
if a check on vertical scrolling is being done.public int scrollTo(int current, int requested, int scrollAction, boolean horizontal)
protected final void remapColumns(int[] oldPositions)
public void clearCellAdjustments()
public void setColWidth(int col, int width)
public void setColAdjust(int col, int dx)
protected int getMinColWidth(int col)
protected int getMaxColWidth(int col)
protected int getMaxRowHeight(int row)
protected int getMinRowHeight(int row)
public final int getColWidth(int col)
public final int getRowHeight(int row)
protected int calculateTextCharsInColumn(int col)
protected int calculateTextLinesInRow(int row)
public int calculateColWidth(int col)
public int calculateRowHeight(int row)
public Insets getCellInsets(int row, int col, Insets insets)
public boolean getCellRect(int row, int col, Rect dest)
row
- col
- dest
- public Object getCellData(int row, int col)
Otherwise - if this is not 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().
public boolean getCellText(int row, int col, StringList destination)
row
- the table row.col
- the table column.destination
- a non-null StringList - use one of the add() methods
to add your text.public final Object getCellText(int row, int col)
public static boolean calculatePreferredSize(Object data, FontMetrics fm, Dimension dest)
data
- this can be a StringList or a String or an IImage or a Control.fm
- the FontMetrics to be used by the Table.dest
- a non-null destination dimension.public Dimension getCellPreferredSize(int row, int col, FontMetrics fm, Dimension dest)
public int calculatePreferredRowHeight(int row)
public int calculatePreferredColWidth(int col)
public Dimension getPreferredSize(Dimension dest)
protected int fixBorder(int style, int row, int col, boolean flat)
public boolean isActiveCellControl(int row, int column)
public TableCellAttributes getCellAttributes(int row, int col, boolean isSelected, TableCellAttributes ta)
public boolean canSelect(int row, int col)
public void findCellsInArea(Rect area, boolean onlyCompletely)
area.x = col of top left cell.
area.y = row of top left cell.
area.width = width of area in pixels on the screen.
area.height = height of area in pixels 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.
protected void inset(int row, int col, Rect rect)
public void paintTableCell(TableControl tc, Graphics g, int row, int col)
protected void deferPaintTableCell(TableControl tc, Graphics g, int row, int col)
public void paintTableCell(TableControl tc, Graphics g, Rect cells)
tc
- The TableControl for the TableModel.g
- the Graphics to draw on.cells
- the x and y value of this specifies the column and row co-ordinate
of the first cell to paint. The width and height give the width and height in
pixels that should be painted.public void makeActiveControlVisible()
protected void updateControls(boolean start)
protected void positionCellControl(int row, int col, Control c)
protected void paintTableCellData(TableControl tc, Graphics g, int row, int col, TableCellAttributes tca, Rect r, Object data)
protected void paintTableCellText(TableControl tc, Graphics g, int row, int col, TableCellAttributes tca, Rect r, StringList text)
public void calculateSizes()
public void made()
public void resized(int width, int height)
public Object getToolTip(int x, int y)
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.
x
- The x co-ordinate in pixels of the mouse.y
- The y co-ordinate in pixels of the mouse.public Menu getMenuFor(int row, int col)
public boolean popupMenuEvent(MenuEvent ev)
public boolean penPressed(Point onTable, Point cell)
public boolean clearSelectionOnClick()
public boolean closeActiveControl()
protected void startedEditing(Point cell)
public boolean onKeyEvent(KeyEvent ev)
public boolean doHotKey(KeyEvent ev)
public boolean editNow(Point cell, boolean byPen)
public boolean editNow(Point cell, int how, boolean penPressOnTable)
public Closes freezeUpdate(boolean updateOnClose)
protected final void show(TableModel.CellControl cc, int how)
protected boolean hasCellControlFor(Point cell)
protected TableModel.CellControl getCellControlFor(Point cell)
cell
- the cell the CellControl is for.protected Control getControlFor(int row, int col)
row
- the row of the cell.col
- the column of the cell.protected void endEditing(Point cell)
public void scrolled(TableControl table, int newFirstRow, int newFirstCol, int oldFirstRow, int oldFirstCol)
public void mouseMoving(boolean isOnValidCell, PenEvent pe, int cellRow, int cellCol)
public void sizeColumnToFitData(int column)
protected void notifyDataChange(Point cell)
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.