All Packages Class Hierarchy This Package Previous Next Index
Class tea.set.TextGrid
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----java.awt.Panel
|
+----tea.set.Grid
|
+----tea.set.TextGrid
- public class TextGrid
- extends Grid
The TextGrid widget is a specialized version Grid widget. It
handles text cells and editing of the text cells automatically.
Text cells are not populated with components. Therefore it's
much more efficient than using Grid and components to hold
text for each cells. You can import a text delimited file
from an URL and have a table created automatially.
Because TextGrid is derived from Grid class, all Grid features
are available to TextGrid. For example, AWT components can
be placed in grid cells using setCell() method.
Convenience methods, TextGrid.getObject() and TextGrid.setObject(),
are provided to get and set text values of each cell. If a cell
is set to a text string, no component is created for the cell,
the text displaying and editing are handled by TextGrid. The
parameter to setObject() and also be encoded strings, which
will cause a component being created for the cell. For more detail,
see the document for setObject() method.
A TextGrid can either be editable or non-editable. If a TextGrid
is editable, all text cells (cells set using setObject() with
a plain text parameter) are editable. A single mouse click inside
an editable cell switches the cell to editing mode, with a
TextField or TextArea component placed on top of the current
cell for editing. The editable property can be changed for individual
cells. To enable or disable editing for a single cell, using
TextGrid.setEditable(int row, int col, boolean editable).
Per cell editable flag overrides the grid wide editable flag.
Focus traversal is handled automatically by the TextGrid. When
tab key is pressed, the focus is shifted to the next cell in the
grid. The next cell to receive focus is determined by the
editability of the cells. The TextGrid searches from the current
focus position for a cell that either contains a component, or
is an editable text cell. If a new editable text cell receives
focus, the cell is automatically switched to editing mode.
In addition to the cell properties defined in Grid widget,
TextGrid defines several additional cell properties. Foreground
property defines the foreground color of the cell. Font
property defines the text font of the cell. CharSize
property defines the size of the cell in characters.
Editable property defines the editability of a cell, and it
overrides the grid wide editable flag. Background
color defines the background color of a cell. The difference
between Background property of a cell and Color property of
a cell is that the Color property of a cell is the color for
the entire cell area, including gap space. Background
property is the color for the cell display area only. It
is not applied to the gap spaces. The background property
is applied in non-empty text cells and all editable text cells.
If a TextGrid is row selectable, a single mouse click inside
a cell selects a row. If the TextGrid is not row selectable
but is column selectable, a single mouse click inside a cell
selects a column.
When the content of a text cell changes through user editing,
an action event is generated by the TextGrid. The action event
is wrapped in an ObjActionEvent object, where ObjActionEvent.getObject()
points to a Point. The Point.x is the column number of the modified
cell, and Point.y is the row number of the modified cell.
In addition to the properties inherited from Grid, TextGrid supports
the following additional properties:
TextGrid supports the following grid level properties:
Property Name | Property Type | Description |
Editable | boolean |
Allow editing in cells. |
TextGrid supports the following cell level properties:
Property Name | Property Type | Description |
Editable | boolean |
Allow editing in the cells. |
Font | Font |
Text font. |
CharSize | Dimension |
Cell size in characters. |
Foreground | Color |
Text foreground color. |
Background | Color |
Text background color. |
Object | Object |
Cell content. |
TextGrid supports the following row level properties:
Property Name | Property Type | Description |
Row | Object[] (Indexed) |
Row content. |
RowCharHeight | int |
Row height in characters. |
TextGrid supports the following column level properties:
Property Name | Property Type | Description |
Col | Object[] (Indexed) |
Column content. |
ColCharWidth | int |
Column width in characters. |
TextGrid generates the following events:
Event Type | Event ID | Generated |
Description |
ObjActionEvent | ActionEvent.ACTION_PERFORMED |
Text cell content changed (exclude setObject()). |
ActionEvent.getActionCommand() is the new text.
ObjActionEvent.getObject() points to a Point, where Point.x is the
column number of the modified cell, and Point.y is the row number
of the modified cell. |
- See Also:
- Grid
-
TextGrid()
- Construct an empty TextGrid.
-
TextGrid(InputStream, String)
- Construct a text grid from a file.
-
TextGrid(int, int)
- Construct an empty text grid.
-
TextGrid(int, int, int, int)
- Construct a textgrid widget with row rows, col columns.
-
TextGrid(int, int, int[], int[])
- Construct a textgrid widget with row rows, col columns.
-
addActionListener(ActionListener)
- Add an action listener.
-
clear(int, int)
- Clear the content in specified cell(s).
-
createCellInfo()
- Virtual constructor for CellInfo.
-
createColInfo()
- Virtual constructor for ColInfo.
-
createRowInfo()
- Virtual constructor for RowInfo.
-
doLayout()
- Layout text grid.
-
fetchRow(int)
- Fetch the content of the row.
-
getBackground(int, int)
- Return the per cell background color.
-
getCharSize(int, int)
- Return the per cell character size.
-
getColCharWidth(int)
- Return the per column character size.
-
getFont(int, int)
- Return the per cell font.
-
getForeground(int, int)
- Return the per cell foreground color.
-
getObject(int, int)
- Return the object in cell (r, c).
-
getPreferredColWidth(int)
- Calculate the preferred column width.
-
getPreferredRowHeight(int)
- Calculate the preferred row height.
-
getPreferredSize(int, int)
- Override the preferredSize method in Grid to reserve space for
text cells, which do not have component in them.
-
getRowCharWidth(int)
- Return the per row character size.
-
insertCol(int, int)
- Insert n columns at the specified position.
-
insertRow(int, int)
- Insert n rows at the specified position.
-
isEditable()
- Return true if this Grid is editable.
-
isEditable(int, int)
- Return the per cell editable property.
-
load(InputStream, String)
- Populate a text grid from a file.
-
paint(Graphics)
- Paint text cells in addition to grids.
-
processActionEvent(ActionEvent)
- Process and dispatch action event.
-
processMouseEvent(MouseEvent)
- Process mouse click events.
-
removeActionListener(ActionListener)
- Remove an action listener.
-
removeCol(int, int)
- Remove n columns at the specified position.
-
removeRow(int, int)
- Remove n rows at the specified position.
-
setBackground(int, int, Color)
- Set the per cell text background color.
-
setCell(int, int, Component)
- Set the cell component of the specified cell.
-
setCharSize(int, int, Dimension)
- Set the per cell text character size.
-
setCol(int, Object[])
- Set all cells in the specified column to the objects in the array.
-
setColCharWidth(int, int)
- Set the per column text character size.
-
setEditable(boolean)
- If true, set TextGrid to editable mode.
-
setEditable(int, int, boolean)
- Set the per cell editable flag.
-
setFocus(int, int)
- Set the current focus on the specified cell.
-
setFont(int, int, Font)
- Set the per cell text font.
-
setForeground(int, int, Color)
- Set the per cell text foreground color.
-
setObject(int, int, Object)
- Set the text in cell (r, c) to object.
-
setRow(int, Object[])
- Set all cells in the specified row to the objects in the array.
-
setRowCharHeight(int, int)
- Set the per row text character size.
TextGrid
public TextGrid()
- Construct an empty TextGrid.
TextGrid
public TextGrid(int row,
int col)
- Construct an empty text grid. The cells are not initialized.
The default is non-editable. This
- Parameters:
- row - number of rows.
- col - number of columns.
TextGrid
public TextGrid(int row,
int col,
int w,
int h)
- Construct a textgrid widget with row rows, col columns. The
character size of cells are set to (w, h).
characters in each column.
- Parameters:
- row - number of rows.
- col - number of columns.
- w - column width in characters.
- h - row height in characters.
TextGrid
public TextGrid(int row,
int col,
int cwidth[],
int rheight[])
- Construct a textgrid widget with row rows, col columns.
Character size of each cell is set to corresponding
values in cwidth and rheight.
- Parameters:
- row - number of rows.
- col - number of columns.
- cwidth - column width array in characters.
- rheight - row height array in characters.
TextGrid
public TextGrid(InputStream input,
String delim)
- Construct a text grid from a file. They file should be delimited
by the specified delimiter. Each field can contain either a
plain text string, or an encoded string in the same format
as setObject() method.
- Parameters:
- input - import source.
- delim - column delimiter.
setCell
public synchronized void setCell(int r,
int c,
Component cell)
- Set the cell component of the specified cell. It sets the component
properties if the properties are set for this cell.
- Parameters:
- r - row number. All rows if it equals Grid.ALL_CELL.
- c - column number. All columns if it equals Grid.ALL_CELL.
- cell - cell component.
- Overrides:
- setCell in class Grid
setEditable
public synchronized void setEditable(boolean editable)
- If true, set TextGrid to editable mode. Otherwise set this TextGrid
to displaying mode. This method sets the grid wide editable property.
- Parameters:
- editable - editable flag.
isEditable
public boolean isEditable()
- Return true if this Grid is editable. This is the grid wide editable
flag, and can be overriden by per cell editable flag.
- Returns:
- editable flag.
setEditable
public synchronized void setEditable(int r,
int c,
boolean editable)
- Set the per cell editable flag. The per cell editable flag
overrides the grid wide editable flag.
- Parameters:
- r - row number. All rows if it equals Grid.ALL_CELL.
- c - column number. All columns if it equals Grid.ALL_CELL.
- editable - per cell editable flag.
isEditable
public boolean isEditable(int r,
int c)
- Return the per cell editable property.
- Parameters:
- r - row number.
- c - column number.
- Returns:
- true if the cell is editable.
setFont
public synchronized void setFont(int r,
int c,
Font font)
- Set the per cell text font. The per cell font overrides the grid
wide font.
- Parameters:
- r - row number. All rows if it equals Grid.ALL_CELL.
- c - column number. All columns if it equals Grid.ALL_CELL.
- font - text font for the cell.
getFont
public Font getFont(int r,
int c)
- Return the per cell font.
- Parameters:
- r - row number.
- c - column number.
- Returns:
- font for the specified cell.
setCharSize
public synchronized void setCharSize(int r,
int c,
Dimension size)
- Set the per cell text character size. The size is in characters
and number of lines.
- Parameters:
- r - row number. All rows if it equals Grid.ALL_CELL.
- c - column number. All columns if it equals Grid.ALL_CELL.
- size - cell character size.
getCharSize
public Dimension getCharSize(int r,
int c)
- Return the per cell character size.
- Parameters:
- r - row number.
- c - column number.
- Returns:
- character size for the specified cell.
setRowCharHeight
public synchronized void setRowCharHeight(int r,
int size)
- Set the per row text character size. The size is in characters.
- Parameters:
- r - row number. All rows if it equals Grid.ALL_CELL.
- size - row character size.
setColCharWidth
public synchronized void setColCharWidth(int c,
int size)
- Set the per column text character size. The size is in characters.
- Parameters:
- c - column number. All columns if it equals Grid.ALL_CELL.
- size - column character size.
getRowCharWidth
public int getRowCharWidth(int r)
- Return the per row character size.
- Parameters:
- r - row number.
- Returns:
- character size for the specified row.
getColCharWidth
public int getColCharWidth(int c)
- Return the per column character size.
- Parameters:
- c - column number.
- Returns:
- character size for the specified column.
setForeground
public synchronized void setForeground(int r,
int c,
Color foreground)
- Set the per cell text foreground color. The per cell foreground
color overrides the grid wide foreground color.
- Parameters:
- r - row number. All rows if it equals Grid.ALL_CELL.
- c - column number. All columns if it equals Grid.ALL_CELL.
- foreground - cell foreground color.
getForeground
public Color getForeground(int r,
int c)
- Return the per cell foreground color.
- Parameters:
- r - row number.
- c - column number.
- Returns:
- foreground color for the specified cell.
setBackground
public synchronized void setBackground(int r,
int c,
Color background)
- Set the per cell text background color. The per cell background
color overrides the grid wide background color.
- Parameters:
- r - row number. All rows if it equals Grid.ALL_CELL.
- c - column number. All columns if it equals Grid.ALL_CELL.
- background - cell background color.
getBackground
public Color getBackground(int r,
int c)
- Return the per cell background color.
- Parameters:
- r - row number.
- c - column number.
- Returns:
- background color for the specified cell.
load
public synchronized void load(InputStream input,
String delim)
- Populate a text grid from a file. They file should be delimited
by the specified delimiter. Each field can contain either a
plain text string, or an encoded string in the same format
as setObject() method. The current content of the grid is
cleared before the new content is loaded.
- Parameters:
- input - import source.
- delim - column delimiter.
clear
public void clear(int r,
int c)
- Clear the content in specified cell(s).
- Parameters:
- r - row number. All rows if it equals Grid.ALL_CELL.
- c - column number. All columns if it equals Grid.ALL_CELL.
getObject
public Object getObject(int r,
int c)
- Return the object in cell (r, c). The type of the object depends
on the cell type.
- Text cell
- String - the current text content of the cell.
- TextEdit(MaskText, Spinner, ListText, ...) and TextComponent
- String - the current text content of the cell.
- List
- String - the current selected item.
- Choice
- String - the current selection.
- Button and Label
- String - text label.
- ImageCanvas
- Image.
- Checkbox
- Boolean - the current state of the checkbox.
- Parameters:
- r - row number.
- c - column number.
- Returns:
- cell object.
setObject
public synchronized void setObject(int r,
int c,
Object content)
- Set the text in cell (r, c) to object. The following object
types are supported:
- String
- the string can either be a plain text string,
or an encoded string for other types of object. A plain text
is simply displayed in the specified cell space. If this
grid is editable, a single mouse click inside any cell causes
a TextField or a TextArea be added to the cell for editing
purpose. The TextField or TextArea is removed after user
finishes editing.
The encoding is as following:
- <EDIT[:row,col]>string, [row,col] is an optional
specification of the number of row and columns of this
text cell. If it's not specified, the value is derived
from the initial text string. It's same as a plain string
except it overrides the TextGrid editable flag for this
cell to editable.
- <LABEL[:row,col]>string, [row,col] is an optional
specification of the number of row and columns of this
text cell. If it's not specified, the value is derived
from the initial text string. It's same as a plain string
except it overrides the TextGrid editable flag for this
cell to non-editable.
- <TEXTFIELD[:col]>string, col is an optional
specification of the number of columns of this
text field. If it's not specified, the value is derived
from the initial text string.
This create an editable TextField
and it overrides the TextGrid editable flag. The string
is used to initialize the TextCell.
- <TEXTAREA[:row,col]>string, [row,col] is an optional
specification of the number of row and columns of this
text area. If it's not specified, the value is derived
from the initial text string.
This create an editable TextArea
and it overrides the TextGrid editable flag. The string
is used to initialize the TextArea.
- <BUTTON>label, a Button is created with the string as the
button label.
- <MASK>mask-string, the string value is treated as a
edit mask, and a MaskText is created for the cell.
- <STATE>label, a Checkbox is created with the string as the
Checkbox label.
- <IMAGE>url, the string value is treated as an URL and used
to fetch the image data. An ImageCanvas is created for the cell
to contain the image.
- <COMBO[:d]>item-list, d is an optional delimiter that can
be specified in the list tag. The string is a list of items
delimited by the specified delimiter. If no delimiter is
specified, the default delimiter is comma. A ComboBox
component is created for the cell.
- <LIST[:d]>item-list, d is an optional delimiter that can
be specified in the list tag. The string is a list of items
delimited by the specified delimiter. If no delimiter is
specified, the default delimiter is comma. A java.awt.List
component is created for the cell.
- <CHOICE[:d]>item-list, d is an optional delimiter that can
be specified in the choice tag. The string is a list of items
delimited by the specified delimiter. If no delimiter is
specified, the default delimiter is comma. A java.awt.Choice
component is created for the cell.
- <SPIN[:d]>item-list, d is an optional delimiter that can
be specified in the choice tag. The string is a list of items
Delimited By the specified delimiter. If no delimiter is
specified, the default delimiter is comma. A tea.set.Spinner
component is created for the cell.
- <RANGE>lower-higher, the lower and higher values of the
range will be used to create a numeric spinner.
- Image
- the image is added to the grid as ImageCanvas.
- String[]
- a text Spinner is created for the cell with
the list of strings.
- int[]
- the length of the array must equal to 2. A
numeric Spinner is created for the cell with int[0] and int[1]
as the lower and higher bound values respectively.
- Parameters:
- r - row number.
- c - column number.
- content - cell object. Clear the cell if content is null.
setRow
public void setRow(int r,
Object val[])
- Set all cells in the specified row to the objects in the array.
If the length of the object array is less than the number of
columns, only the cells with corresponding object array value
are updated.
- Parameters:
- r - row number.
- val - object array for cell content.
setCol
public void setCol(int c,
Object val[])
- Set all cells in the specified column to the objects in the array.
If the length of the object array is less than the number of
rows, only the cells with corresponding object array value
are updated.
- Parameters:
- c - column number.
- val - object array for cell content.
insertRow
public void insertRow(int pos,
int n)
- Insert n rows at the specified position. Any editing field will
be forced to close.
- Parameters:
- pos - row number.
- n - number of rows.
- Overrides:
- insertRow in class Grid
removeRow
public void removeRow(int pos,
int n)
- Remove n rows at the specified position. Any editing field will
be forced to close.
- Parameters:
- pos - row number.
- n - number of rows.
- Overrides:
- removeRow in class Grid
insertCol
public void insertCol(int pos,
int n)
- Insert n columns at the specified position. Any editing field will
be forced to close.
- Parameters:
- pos - column number.
- n - number of columns.
- Overrides:
- insertCol in class Grid
removeCol
public void removeCol(int pos,
int n)
- Remove n columns at the specified position. Any editing field will
be forced to close.
- Parameters:
- pos - column number.
- n - number of columns.
- Overrides:
- removeCol in class Grid
processMouseEvent
public void processMouseEvent(MouseEvent e)
- Process mouse click events.
- Overrides:
- processMouseEvent in class Grid
paint
public void paint(Graphics g)
- Paint text cells in addition to grids.
- Parameters:
- g - graphics object.
- Overrides:
- paint in class Grid
doLayout
public void doLayout()
- Layout text grid.
- Overrides:
- doLayout in class Grid
addActionListener
public void addActionListener(ActionListener listener)
- Add an action listener.
- Parameters:
- listener - action listener.
removeActionListener
public void removeActionListener(ActionListener listener)
- Remove an action listener.
- Parameters:
- listener - action listener.
processActionEvent
public void processActionEvent(ActionEvent e)
- Process and dispatch action event.
- Parameters:
- e - action event.
fetchRow
public void fetchRow(int r)
- Fetch the content of the row. This is a hook for demand loading.
This method is called before the row is displayed on screen.
- Parameters:
- r - row number.
setFocus
public synchronized void setFocus(int r,
int c)
- Set the current focus on the specified cell.
- Parameters:
- r - row number.
- c - column number.
createCellInfo
protected Grid. CellInfo createCellInfo()
- Virtual constructor for CellInfo. Add TextGrid specific cell
properties to the CellInfo class.
- Returns:
- TextCellInfo object.
- Overrides:
- createCellInfo in class Grid
createRowInfo
protected Grid. RowInfo createRowInfo()
- Virtual constructor for RowInfo. Add TextGrid specific row
properties to the RowInfo class.
- Returns:
- TextRowInfo object.
- Overrides:
- createRowInfo in class Grid
createColInfo
protected Grid. ColInfo createColInfo()
- Virtual constructor for ColInfo. Add TextGrid specific column
properties to the ColInfo class.
- Returns:
- TextColInfo object.
- Overrides:
- createColInfo in class Grid
getPreferredSize
protected Dimension getPreferredSize(int row,
int col)
- Override the preferredSize method in Grid to reserve space for
text cells, which do not have component in them.
- Parameters:
- row - row number.
- col - column number.
- preferred - size of the cell.
- Overrides:
- getPreferredSize in class Grid
getPreferredRowHeight
protected synchronized int getPreferredRowHeight(int r)
- Calculate the preferred row height. The preferred row height
of a row is the maximum preferred height of all cells on
the row.
- Parameters:
- r - row number.
- Returns:
- the preferred row height.
- Overrides:
- getPreferredRowHeight in class Grid
getPreferredColWidth
protected synchronized int getPreferredColWidth(int c)
- Calculate the preferred column width. The preferred column width
of a column is the maximum preferred width of all cells on
the column.
- Parameters:
- r - column number.
- Returns:
- the preferred column width.
- Overrides:
- getPreferredColWidth in class Grid
All Packages Class Hierarchy This Package Previous Next Index