All Packages Class Hierarchy This Package Previous Next Index
Class tea.set.Grid
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----java.awt.Panel
|
+----tea.set.Grid
- public class Grid
- extends Panel
- implements ItemSelectable, Scrollable
Grid widget provides a flexible interface for managing grid layout.
A cell in the grid can be any AWT components, and any components
derived from the basic AWT components.
There are two ways of managing the space assignment. If absolute
is set to false, which is the default, cells are resized to fit
the display area. In this mode,
the space assignment for rows and columns are automatic based on
the preferred size of row and columns. The
preferred size of a grid is the sum of preferred row heights and
sum of preferred column widths. A preferred row height is the maximum
preferred height of any components in a row, and similarly for
preferred column width. The automatic space assignment can be
overriden by calling setRowHeight() and setColWidth() methods.
Alternatively, a Grid can be set to absolute mode. In this mode
cells are not resized to fit the screen. Instead, they are sized
to their preferred row and column size. Notice since all cells
on a row share same height and all cells on a column share same
width, cells ARE resized to their preferred row height and
preferred column width, as defined above. But no effort is made
to fit all cells into the display area. This mode is primarily
for scrolling.
The absolute mode can be specified for either horizontal, vertical,
or both directions. To set both direction to absolute mode,
call Grid.setAbsolute(Grid.VERTICAL | Grid.HORIZONTAL). If
we want to fit the grid columns into the grid area, but let
the grid rows having their preferred size, we can set one direction
to absolute, Grid.setAbsolute(Grid.VERTICAL).
Users can resize rows or columns by dragging ruling lines
separating rows and columns. If this happens, the layout mode
of the Grid switches to absolute and row height/column width
override mode automatically. This means no effort will be
made by the Grid to layout cells to make everything fit into
the display area from the point on. To disable user resizing,
set resizable to false using setResizable().
To enable scrolling of Grid, simply attach a Scroller to the
Grid widget. Since Grid implements the Scrollable interface,
the scrolling will be by row and column instead of pixels.
When a Scroller is attached to the Grid, the Grid is
automatically switched to absolute mode. To attached a Scroller
to a Grid, pass the Grid as the component managed by the
Scroller, e.g. add(new Scroller(grid));
Rows and columns can be frozen. If a row is frozen, it will
not be scrolled with other rows. If a column is frozen, it
will not be scrolled with other column. Only rows and columns
at the start of a grid can be frozen. If other rows/columns
need to freezed, move them to the start of the grid first
using moveRow() and moveCol(). To freeze n rows/columns at start
of a grid, call Grid.setFrozenRow(n) or Grid.setFrozenCol(n).
Grid supports three cell selection mode, region, row, and column.
Region selection is the most general. It can be enabled by calling
Grid.setRegionSelectable() method. When region selection is
enabled, an user can select a rectangular area of the grid by
dragging the mouse over the area. An ItemEvent.SELECTED and
ItemEvent.DESELECTED are generated for region selection and
de-selection. To get the currently selected region,
call Grid.getSelectedRegion().
Rows and columns can be selected by users if they are set to
selectable. If multiSelect option is true, more than one row and
column can be selected. Otherwise only one selection can exists
at one time. Arrow keys can be used to move the row/column
selections respectively if one is already selected. When a row or
column is selected, an ItemEvent.SELECTED event is posted.
When a row or column is deselected, a ItemEvent.DESELECTED event
is posted.
Row/column can be set to selectable by calling Grid.setRowSelectable()
and Grid.setColSelectable() methods. By default, if region is
selectable, a mouse click starts a region selection. when row/column
are selectable and region is not selectable, a mouse click
inside any cell will select the row if row is selectable, or
select the column if row is not selectable and column is
selectable. Note however Grid does not track mouse events of its
children, so if a cell holds an other component, the mouse
event is not detected by the Grid and therefore would not cause
any region/row/column selections.
Optionally, if row/column headers exist, a row or column can
be selected by clicking on header cells. To force users to
select row/column using row/column header, call
Grid.setRowSelectable(true, true) or
Grid.setColSelectable(true, true). In this case, if no header
exists, an empty header is created to serve as row/column
selectors. This mode also disables row/column selection
from grid cells. The users are forced to select row/column
from row/column headers only.
Note the row/column selector setting in Grid.setRowSelectable()
and Grid.setColSelectable() only controls the creation of the
row/column selectors. If row/column headers are set using
Grid.setRowHeader() or Grid.setColHeader(), the headers
are always able to be used for selecting row/column, regardless
the flag values in the Grid.setRowSelectable() and
Grid.setColSelectable().
A grid can be optionally drawn. There are two options available.
VERTICAL option
draws vertical lines between columns. HORIZONTAL option draws
horizontal lines between rows. These options can be combined by
bitwise OR them together. ALL flag is supplied to enable both
grid lines. The width of border lines can be controlled by
Grid.setLineWidth() method. The default width for lines
is 2 pixels.
To change the ruling option, call Grid.setRuling(int) with one
of the flags described above. This sets the grid wise ruling.
The grid wise ruling option can be override for each cell
by calling Grid.setRuling(int r, int c, int ruling).
Per cell ruling
option overrides the grid wise ruling. The ruling option of
individual cells controls the grid line to the right of a
cell and below a cell. For example, when the VERTICAL ruling flag
is set for a cell, a vertical grid line is drawn at the right
border of the cell. When the HORIZONTAL ruling flag
is set for a cell, a horizontal grid line is drawn at the bottom
border of the cell. If one or both are not set, the corresponding
grid lines are not drawn for the particular cell.
The lines in a grid can be drawn in three different styles. The
line style is controlled by the set3D() method. If PLAIN is
specified, a single pixel line is drawn. If RAISED is specified,
the line will be drawn in a 3D style raised above the grid
surface. If LOWERED is specified, the line will be drawn in a
3D style embedded into the surface of the grid.
Row and column headers can be specified. If row headers are
specified and row is selectable, then the row header is also
the row selector. If row is selectable but there is not row
header, then an empty row selector is added for each row.
The same rule is used for column header and column selector.
Row/column header is independent of row/column selectable
setting. However, if row/column is selectable, the row/column
header will always serve as row/column selector.
Row and column can be dynamically inserted or removed from
the grid. When a row/column is inserted, the cells in the
row/column are empty. User must call setCell() method to
add components to the cells to make the row/column visible.
Row and column can also be moved dynamically. When rows/columns
are moved, all information about the row/column, such as
select status, color, size, are carried with the moved
row/column.
One or more rows and/or columns can be hiden. If a row or a
column is hiden, it will not be displayed in the grid. However,
the numbering of rows and columns will not change. For example,
if row 2 is hiden, only rows 0, 1, 3, ... are displayed on
screen. The original row 3 will remain row number 3 and will
not be renumbered to row 2. The same is true for columns.
Spanning cells are supported. A spanning cell is a cell that takes
more than one rows and/or columns. A spanning cell can be added
to the grid using setCell(int, int, Component, int, int) method.
When inserting or deleting row/column, the insertion or deletion
point should not be at the middle of a spanning cell. Otherwise
the screen layout will be not correct after the operation.
Color of individual cell can be set using Grid.setColor() method.
When a cell's color is set using this
method, the background color of the component inside the cell
is changed to the color, in addition the cell will be filled
with the cell color if cell component does not take all space
inside the cell. The foreground of a cell can be changed
through the Component interface of the cell component. If
cell background color is not set using the methods mentioned
above, the cell area is not painted if there is no component
in the cell, and the areas leftover by a component inside
a cell is not painted neither.
Gap spaces can be added to a cell component using Grid.setGap().
Spaces on four sides of the component can be specified. The
gap spaces are added to the cell component's preferred size
during space assignment calculation. Gap spaces are per cell
attribute. There is not grid wide global gap attribute.
Cell components can be aligned in many different ways. The
default cell alignment resize a cell component to fit the
entire cell area. User can override this behavior by setting
cell alignment explicitly. There are 15 possible alignments.
Horizontally, you can choose from H_LEFT, H_CENTER, H_RIGHT.
Vertically, you can choose from V_TOP, V_CENTER, and V_BOTTOM.
The two can be bitwise or'ed to produce an alignment, or
used by itself. If only one direction is specified, the other
direction is to fit. For example, if alignment is set to
V_TOP, the cell component is going to be aligned to the
top of the cell area, and the width of the component is
resized to the same width as the cell area.
For methods that take row/column number as parameter,
the row/column number can be replaced with Grid.HEADER
constant value. If Grid.HEADER is passed in as a row number,
it specifies the column header row instead of the body row.
If Grid.HEADER is passed in as a column number, it specifies
the row header column instead of the body column. For example,
to change the color of column header to red, call
Grid.setColor(Grid.HEADER, Grid.ALL_CELL, Color.red).
Only one of row and
column parameter can have a value of HEADER. For methods
For methods that work on per cell bases, a special flag
ALL_CELL is supplied to apply the operation to entire rows or
columns. The grid.ALL_CELL can be used in place of a row or a
column number in methods that expects both row and column number.
When Grid.ALL_CELL is passed in as a row number, it means all rows.
When Grid.ALL_CELL is passed in as a column number, it means
all columns. If Grid.ALL_CELL is passed in for both row and
column number, it means all cells in the grid. For example,
to enable the horizontal ruling line for the header row, call
grid.setRuling(Grid.HEADER, Grid.ALL_CELL, Grid.HORIZONTAL).
By default, any state changing method invocation will automatically
cause a layout and repaint. This can be very expensive when a large
number of invocation is expected. To optimize, AutoRepaint property
is provided to control the layout/repaint activity. If AutoRepaint
is set to false, no implicit repaint will be generated. User of
the Grid has to explicitly invoke repaint after the sequence of
method calls.
Known Bug:
On Solaris, there is no way to force a component to the front
when one overlays another. Therefore the resize line may or may not be
visible when resizing row/column (It may be hiden by other cell
components).
Netscape 2.x has a bug causing components inside grid to change
location undetectedly. This may cause strange behavior inside
a grid. This bug is fixed in Netscape 3.0.
Grid supports four types of properties, cell, row, column, and grid
level properties. Grid level properties are properties apply to the
entire grid. They are accessed using the regular get...() and set...()
methods. Cell properties apply to specific cells, they are accessed
using get...(int row, int col, ...) and set...(int row, int col, ...)
methods. The row and column properties apply to individual rows and
columns. They are accessed using get...(int row, ...) and
set...(int row, ...) methods. For property setting methods, the row
and column numbers can be either
normal row/column numbers, or the special number HEADER and ALL_CELL.
Grid supports the following grid level properties:
Property Name | Property Type | Description |
RowCount | int |
Number of rows. Setting the number other than the current number
of rows causes the grid to expend or shrink. |
ColCount | int |
Number of columns. Setting the number other than the current number
of columns causes the grid to expend or shrink. |
Absolute | int |
Absolute flag, NONE, VERTICAL, or HORIZONTAL. |
Resizable | boolean |
Allow user resizing of rows and columns. |
InPlaceResize | boolean |
Resizing affects both rows/columns next to the resizing line. |
Ruling | int |
Grid wide ruling flag, NONE, VERTICAL, or HORIZONTAL. |
3D | boolean |
Border line 3D style. |
LineWidth | int |
Border line width in pixels. |
MultiSelect | boolean |
Allow multiple rows or columns to be selected. |
RowSelectable | boolean |
Allow rows to be selected. |
ColSelectable | boolean |
Allow columns to be selected. |
RegionSelectable | boolean |
Allow grid region to be selected. |
RowHeaderExist | boolean (Readonly) |
True if row header column exists. |
ColHeaderExist | boolean (Readonly) |
True if column header row exists. |
Alignment | int |
Grid level alignment flag. |
SelectedRow | int (Readonly) |
The index of the first selected row. |
SelectedRows | int (Indexed, Readonly) |
Indexes of selected rows. |
SelectedCol | int (Readonly) |
The index of the first selected column. |
SelectedCols | int (Indexed, Readonly) |
Indexes of selected columns. |
SelectedObjects | Object(Indexed, Readonly) |
Row headers of selected rows. |
SelectedRegion | Region (Readonly) |
Current selected region, or null if no region is selected. |
RowRoot | int |
The topmost visible row. |
ColRoot | int |
The leftmost visible column. |
RowLast | int (Readonly) |
Index of last visible row on screen. |
ColLast | int (Readonly) |
Index of the last visible column on screen. |
FrozenRow | int |
The number of rows frozen from the top. |
FrozenCol | int |
The number of columns frozen from the left. |
AutoRepaint | boolean |
True if repaint requests are generated automatically whenever needed.
|
Grid supports the following cell level properties:
Property Name | Property Type | Description |
Gap | Insets |
Gap space around the child component. |
Ruling | int |
Per cell ruling flag, NONE, VERTICAL, or HORIZONTAL. |
Cell | Component |
Cell component. |
Spanning | Dimension |
Spanning cell dimension. |
Alignment | int |
Cell component alignment flagb. |
Color | Color |
Cell background filling color. |
Selected | boolean (Readonly) |
True if the cell is selected (as part of row, column, or region) |
Bounds | Rectangle |
Bounds of the cell, excluding gap space and aligned. |
Grid supports the following row level properties:
Property Name | Property Type | Description |
RowHeight | int (Indexed) |
Preferred row height in pixels. |
RowHeader | String (Indexed) |
Row header text string. |
VisibleRow | boolean (Readonly) |
True if the row is not hiden and is not scrolled off screen. |
SelectedRow | boolean |
True if the row is selected. |
Grid supports the following column level properties:
Property Name | Property Type | Description |
ColWidth | int (Indexed) |
Preferred column width in pixels. |
ColHeader | String (Indexed) |
Column header text string. |
VisibleCol | boolean (Readonly) |
True if the column is not hiden and is not scrolled off screen. |
SelectedCol | boolean |
True if the column is selected. |
Grid generates the following events:
Event Type | Event ID | Generated |
Description |
ItemEvent | ItemEvent.SELECTED |
Row/Column/Region selection |
For row/column selection, ItemEvent.getItem() contains an Integer
with the row/column number value. For region selection,
ItemEvent.getItem() is a reference to a Grid.Region object of the
selected region. When mouse drags during region selection, an
ItemEvent is generated for every new row/column the mouse moves
across. The ItemEvent.getStateChange() contains 0 for the ItemEvents
generated by mouse drag, and contains 1 when the ItemEvent is
generated when the mouse is released. |
ItemEvent | ItemEvent.DESELECTED |
Row/Column/Region deselection. |
ItemEvent.getItem() contains the deselected row/column number, or
Grid.Region of the deselected region. ItemEvent.getStateChange() is 1.
|
- See Also:
- Scroller, TextGrid
-
ALL
- Draw both horizontal and vertical ruling lines.
-
ALL_CELL
- ALL_CELL can be used in place of a row or a column number
in methods that expects both row and column number.
-
CENTER_BOTTOM
- Center and bottom alignment.
-
CENTER_CENTER
- Center and center alignment.
-
CENTER_TOP
- Center and top alignment.
-
eventMgr
- EventMgr object handles added event processing and dispatching.
-
FILL
- Resize the component to fill the cell.
-
H_CENTER
- Center at horizontal direction.
-
H_LEFT
- Alignment flag determines how the cell components are aligned
inside a cell.
-
H_RIGHT
- Right align at horizontal direction.
-
HEADER
- HEADER can be used as a parameter value where a row/column
number is expected.
-
HORIZONTAL
- This is used to specify horizontal ruling and horizontal absolute
mode.
-
LEFT_BOTTOM
- Left and bottom alignment.
-
LEFT_CENTER
- Left and center alignment.
-
LEFT_TOP
- Left and top alignment.
-
LOWERED
- Draw lowered 3D lines.
-
NIL
- NIL is used to serve as an argument to handleProperty to signal
the absence of a particular parameter.
-
NONE
- Don't draw any ruling.
-
PLAIN
- Non-3D mode.
-
RAISED
- Draw raised 3D lines.
-
RIGHT_BOTTOM
- Right and bottom alignment.
-
RIGHT_CENTER
- Right and center alignment.
-
RIGHT_TOP
- Right and top alignment.
-
V_BOTTOM
- Bottom align at vertical direction.
-
V_CENTER
- Center at vertical direction.
-
V_TOP
- Top align at vertical direction.
-
VERTICAL
- This is used to specify vertical ruling and vertical absolute
mode.
-
Grid()
- Construct an empty Grid.
-
Grid(int, int)
- Construct a grid with row rows and col columns.
-
addCol(int)
- Add specified number of columns at the end of grid.
-
addItemListener(ItemListener)
- Add an item listener.
-
addRow(int)
- Add specified number of rows at the end of grid.
-
adjustRegion(Grid. Region, int, int, int, int)
- Adjust a particular region.
-
adjustRegion(int, int, int, int)
- Called when regions need to be adjusted, such as row/column move,
insert, remove, etc..
-
alignCell(Rectangle, Dimension, int)
- Align a rectangle area inside another rectangle area according
to the alignment flag.
-
createCellInfo()
- This method can be overriden by subclasses to provide a
different CellInfo class.
-
createColInfo()
- This method can be overriden by subclasses to provide a
different ColInfo class.
-
createRowInfo()
- This method can be overriden by subclasses to provide a
different RowInfo class.
-
deselect()
- Deselect all rows/columns/regions.
-
deselectCol(int)
- Unselect a column.
-
deselectRegion()
- Deselect a region.
-
deselectRow(int)
- Unselect a row.
-
doLayout()
- Layout the grid cells.
-
doRepaint(boolean, boolean)
- This method should used by all derived class of Grid to send
repaint request.
-
get3D()
- Return the line 3D mode.
-
getAbsolute()
- Return absolute flag, which is a bitwise OR of Grid.HORIZONTAL
and Grid.VERTICAL.
-
getAlignment()
- Return the current alignment.
-
getAlignment(int, int)
- Return the per cell alignment.
-
getBottomCol()
- Return the index of last visible column on screen.
-
getBottomRow()
- Return the index of the last visible row on screen.
-
getBounds(int, int)
- Get the cell location and cell size.
-
getCell(int, int)
- Return the component at cell.
-
getCellInfo(int, int)
- Get the per cell attributes.
-
getColCount()
- Return the number of columns in the grid (excluding header column).
-
getColHeader()
- Get the column header array.
-
getColHeader(int)
- Get the column header for the specified column.
-
getColInfo(int)
- Get the per column attributes.
-
getColor(int, int)
- Return the per cell background color.
-
getColRoot()
- Return the current col root.
-
getColWidth()
- Get the current column width setting.
-
getFrozenCol()
- Get the current number of frozen columns.
-
getFrozenRow()
- Get the current number of frozen rows.
-
getGap(int, int)
- Return the cell gap space.
-
getIncrement(int, int)
- Get the increment for scrollbars.
-
getLineWidth()
- Get the border line width.
-
getMaximum(int)
- Return scrollbar maximum (columns).
-
getMinimum(int)
- Return scrollbar minimum (columns).
-
getMinimumSize()
- Return the minimum size of grid.
-
getPreferredColWidth(int)
- Calculate the preferred column width.
-
getPreferredRowHeight(int)
- Calculate the preferred row height.
-
getPreferredSize()
- Return the preferred size of grid.
-
getPreferredSize(int, int)
- Get the preferred size of the specified cell.
-
getRowCount()
- Return the number of rows in the grid (excluding header row).
-
getRowHeader()
- Get the row header array.
-
getRowHeader(int)
- Get the row header for the specified row.
-
getRowHeight()
- Get the current row heights setting.
-
getRowInfo(int)
- Get the per row attributes.
-
getRowRoot()
- Return the current row root.
-
getRuling()
- Return the current ruling style.
-
getRuling(int, int)
- Return the per cell ruling style.
-
getSelectedCol()
- Return the selected column index.
-
getSelectedCols()
- Return all selected column indexes.
-
getSelectedObjects()
- Get the row headers of the selected rows.
-
getSelectedRegion()
- Get the selected region.
-
getSelectedRow()
- Return the selected row index.
-
getSelectedRows()
- Return all selected row indexes.
-
getSpanning(int, int)
- Return the spanning setting for the cell.
-
getValue(int)
- Return the current value of the specified scrollbar.
-
getVisibleAmount(int)
- Get the visible portion for the specified direction.
-
handleProperty(int, int, Object, Class, String)
- This method is called by set property methods to handle
ALL_CELL flag for row and column numbers.
-
hideCol(int)
- Hide a column.
-
hideRow(int)
- Hide a row.
-
highlight(int, int, boolean)
- Highlight the specified cell.
-
insertCol(int, int)
- Insert specified number of columns at the position specified.
-
insertRow(int, int)
- Insert specified number of rows at the position specified.
-
isAutoRepaint()
- Return true if auto repaint is on.
-
isColHeaderExist()
- Return true if column header row exists.
-
isColSelectable()
- Return true if column is selectable.
-
isInPlaceResize()
- Get the InPlaceResize property.
-
isMultiSelect()
- Return true if multiSelect is enabled.
-
isRegionSelectable()
- Check the region selectable setting.
-
isResizable()
- Return user resize flag.
-
isRowHeaderExist()
- Return true if row header column exists.
-
isRowSelectable()
- Return true if row is selectable.
-
isSelected(int, int)
- Return true if the cell is selected as part of row, column, or region.
-
isSelectedCol(int)
- Return true if specified column is selected.
-
isSelectedRow(int)
- Return true if specified row is selected.
-
isSuspended()
- Check if the paint is currently suspended.
-
isVisibleCol(int)
- Return true if the specified column is visible.
-
isVisibleRow(int)
- Return true if the specified row is currently visible.
-
locateCell(int, int)
- Find the cell where the pointer is in.
-
moveCol(int, int)
- Move a col from one position to a new position.
-
moveRow(int, int)
- Move a row from one position to a new position.
-
paint(Graphics)
- Paint the grid.
-
paintColHeader(Graphics, int)
- Paint the specified column header cell if it's not empty.
-
paintRowHeader(Graphics, int)
- Paint the specified row header cell if it's not empty.
-
paintText(Graphics, String, Rectangle, int)
- Generate the pressed and unpressed image.
-
processEvent(AWTEvent)
- Process and dispatch event.
-
processItemEvent(ItemEvent)
- Process and dispatch item event.
-
processMouseEvent(MouseEvent)
- Process mouse click events.
-
processMouseMotionEvent(MouseEvent)
- Handle cell resize, row/column selection, tab keys and next
focus, and arrow keys.
-
registerScroller(Scroller)
- This function is called by Scroller at initialization time.
-
removeCol(int, int)
- Remove specified number of columns at the position specified.
-
removeItemListener(ItemListener)
- Remove an item listener.
-
removeRow(int, int)
- Remove specified number of rows at the position specified.
-
repaint()
- Explicit repaint cause the grid to be re-layed out.
-
selectCol(int)
- Select a column.
-
selectCol(int, boolean)
- Select of deselect a column.
-
selectRegion(Grid. Region)
- Select the region specified in the region.
-
selectRow(int)
- Select a row.
-
selectRow(int, boolean)
- Select or deselect a row according to the select flag.
-
set3D(int)
- Set the line 3D mode.
-
setAbsolute(int)
- If absolute is set to true, cells will not be resized to fit the
area.
-
setAlignment(int)
- Set the alignment for the grid.
-
setAlignment(int, int, int)
- Set the alignment for a particular cell.
-
setAutoRepaint(boolean)
- If auto repaint mode is turned off (default to true), a repaint
will not be generated by this Grid.
-
setCell(int, int, Component)
- Set the component for a grid cell.
-
setCell(int, int, Component, int, int)
- Set the component for a spanning cell.
-
setColCount(int)
- Set the number of columns in this grid.
-
setColHeader(int, String)
- Set one column header.
-
setColHeader(String[])
- Set column headers.
-
setColor(int, int, Color)
- Set the specified cell to the color.
-
setColRoot(int)
- The col root is the column which will be displayed as the leftmost
column.
-
setColSelectable(boolean)
- Set column selectable to true or false.
-
setColSelectable(boolean, boolean)
- Set column selectable to true or false.
-
setColWidth(int, int)
- Set the specified column to the width.
-
setColWidth(int[])
- Explicitly specify the column widths in the grid.
-
setFrozenCol(int)
- Freeze the number of columns from the top column(0).
-
setFrozenRow(int)
- Freeze the number of rows from the top row(0).
-
setGap(int, int, Insets)
- Set a cell gap.
-
setInPlaceResize(boolean)
- Is InPlaceResize property is true, user resize will resize the
two rows/columns next to the resize line.
-
setLineWidth(int)
- Set the border line width for 3D border lines.
-
setMultiSelect(boolean)
- Set multiSelect mode to true or false.
-
setProperty(int, int, Object, Class, String)
- This method calls the actual set property methods.
-
setRegionSelectable(boolean)
- Enable or disable region selectability.
-
setResizable(boolean)
- Enable/disable user resize through dragging ruling lines.
-
setRowCount(int)
- Set the number of rows in this grid.
-
setRowHeader(int, String)
- Set one row header.
-
setRowHeader(String[])
- Set row headers.
-
setRowHeight(int, int)
- Set the specified row to the height.
-
setRowHeight(int[])
- Explicitly specify the row heights in the grid.
-
setRowRoot(int)
- The row root is the row which will be displayed as the top row.
-
setRowSelectable(boolean)
- Set row selectable to true or false.
-
setRowSelectable(boolean, boolean)
- Set row selectable to true or false.
-
setRuling(int)
- Set the ruling style.
-
setRuling(int, int, int)
- Set the ruling for a particular cell.
-
setSpanning(int, int, Dimension)
- Set the cell spanning dimension.
-
setSpanning(int, int, int, int)
- Set the spanning cell size.
-
setSuspended(boolean)
- Suspend layout and paint if the flag is true.
-
setValue(int, int)
- Scroll the grid according to scrollbar value.
-
showCol(int)
- Show a hiden column.
-
showCol(int, boolean)
- Show or hide a column.
-
showRow(int)
- Show a hiden row.
-
showRow(int, boolean)
- Show or hide a row.
-
update(Graphics)
- Override for double buffering.
HEADER
public static final int HEADER
- HEADER can be used as a parameter value where a row/column
number is expected. This specifies the method would be
applied to the header row/column instead of the body
row/column. In methods that takes both row and column number,
only one of the parameter can be HEADER because they
are mutually exclusive.
ALL_CELL
public static final int ALL_CELL
- ALL_CELL can be used in place of a row or a column number
in methods that expects both row and column number. If
ALL_CELL is passed in as a row number, it means all rows.
If ALL_CELL is passed in as a column number, it means
all columns. If ALL_CELL is passed in for both row and
column number, it means all cells in the grid.
NIL
protected static final int NIL
- NIL is used to serve as an argument to handleProperty to signal
the absence of a particular parameter.
NONE
public static final int NONE
- Don't draw any ruling.
HORIZONTAL
public static final int HORIZONTAL
- This is used to specify horizontal ruling and horizontal absolute
mode.
VERTICAL
public static final int VERTICAL
- This is used to specify vertical ruling and vertical absolute
mode.
ALL
public static final int ALL
- Draw both horizontal and vertical ruling lines.
PLAIN
public static final int PLAIN
- Non-3D mode.
RAISED
public static final int RAISED
- Draw raised 3D lines.
LOWERED
public static final int LOWERED
- Draw lowered 3D lines.
H_LEFT
public static final int H_LEFT
- Alignment flag determines how the cell components are aligned
inside a cell. The default is FILL. You can use either the
final flags, e.g. LEFT_TOP, which is a product of OR of
H_ and V_ flags. Or you can compose the flags using H_
and V_ flags explicitly. For example, if H_LEFT is passed
as the alignment, the cell will be aligned to the left
of the cell space, and the height of the cell component
will be stretched to fit the cell height, and the cell component
with will be the preferred width of the component if
it's less than the cell space width. If LEFT_TOP is used,
which is equivalent to H_LEFT|V_TOP, the cell component
will be aligned to top left of cell space, and the component
will not be stretched to fit neither dimension of the
cell space.
H_CENTER
public static final int H_CENTER
- Center at horizontal direction.
H_RIGHT
public static final int H_RIGHT
- Right align at horizontal direction.
V_TOP
public static final int V_TOP
- Top align at vertical direction.
V_CENTER
public static final int V_CENTER
- Center at vertical direction.
V_BOTTOM
public static final int V_BOTTOM
- Bottom align at vertical direction.
FILL
public static final int FILL
- Resize the component to fill the cell.
LEFT_TOP
public static final int LEFT_TOP
- Left and top alignment.
LEFT_CENTER
public static final int LEFT_CENTER
- Left and center alignment.
LEFT_BOTTOM
public static final int LEFT_BOTTOM
- Left and bottom alignment.
CENTER_TOP
public static final int CENTER_TOP
- Center and top alignment.
CENTER_CENTER
public static final int CENTER_CENTER
- Center and center alignment.
CENTER_BOTTOM
public static final int CENTER_BOTTOM
- Center and bottom alignment.
RIGHT_TOP
public static final int RIGHT_TOP
- Right and top alignment.
RIGHT_CENTER
public static final int RIGHT_CENTER
- Right and center alignment.
RIGHT_BOTTOM
public static final int RIGHT_BOTTOM
- Right and bottom alignment.
eventMgr
protected EventMgr eventMgr
- EventMgr object handles added event processing and dispatching.
Grid
public Grid()
- Construct an empty Grid.
Grid
public Grid(int nrow,
int ncol)
- Construct a grid with row rows and col columns. The grid is
empty after construction.
- Parameters:
- nrow - number of rows.
- ncol - number of columns.
getRowCount
public int getRowCount()
- Return the number of rows in the grid (excluding header row).
- Returns:
- number of rows in grid.
setRowCount
public void setRowCount(int nrow)
- Set the number of rows in this grid. If the new number of rows is
greater than the existing number of rows, additional empty rows are
added to the grid. If the new number of rows is less than the
existing number of rows, extra rows are removed from grid from
the bottom.
- Parameters:
- nrow - number of rows.
getColCount
public int getColCount()
- Return the number of columns in the grid (excluding header column).
- Returns:
- number of columns in grid.
setColCount
public void setColCount(int ncol)
- Set the number of columns in this grid. If the new number of columns is
greater than the existing number of columns, additional empty columns are
added to the grid. If the new number of columns is less than the
existing number of columns, extra columns are removed from grid from
the right.
- Parameters:
- ncol - number of columns.
addRow
public void addRow(int n)
- Add specified number of rows at the end of grid. The newly added
rows are empty initially. Consequently, the rows will not show up
until components are added to the rows using setCell() method.
Return the row number of the new row.
- Parameters:
- n - number of rows to add.
insertRow
public synchronized void insertRow(int pos,
int n)
- Insert specified number of rows at the position specified. The
newly inserted rows are empty initially. Consequently, the rows
will not show up until components are added to the rows using
setCell() method.
Return the row number of the newly inserted rows.
- Parameters:
- pos - position to insert row.
- n - number of rows to add.
removeRow
public synchronized void removeRow(int pos,
int n)
- Remove specified number of rows at the position specified.
- Parameters:
- pos - row number.
- n - number of rows to remove.
moveRow
public synchronized void moveRow(int from,
int to)
- Move a row from one position to a new position. The spanning,
alignment, and possible row height override information are
carried along.
Row selection and row hiding information are correctly
maintained.
- Parameters:
- from - row number to move a row from.
- to - row number to move a row to.
addCol
public void addCol(int n)
- Add specified number of columns at the end of grid. The newly added
columns are empty initially. Consequently, the columns will not show up
until components are added to the columns using setCell() method.
Return the column number of the added column.
- Parameters:
- n - number of columns.
insertCol
public synchronized void insertCol(int pos,
int n)
- Insert specified number of columns at the position specified. The
newly inserted columns are empty initially. Consequently, the columns
will not show up until components are added to the columns using
setCell() method.
Return the column number of the inserted columns.
- Parameters:
- pos - column number.
- n - number of columns.
removeCol
public synchronized void removeCol(int pos,
int n)
- Remove specified number of columns at the position specified.
- Parameters:
- pos - column number.
- n - number of columns.
moveCol
public synchronized void moveCol(int from,
int to)
- Move a col from one position to a new position. The spanning,
alignment, and possible col width override information are
carried along.
Column selection and column hiding information are correctly
maintained.
- Parameters:
- from - column number to move a column from.
- to - column number to move a column to.
setGap
public synchronized void setGap(int r,
int c,
Insets gap)
- Set a cell gap. The Insets specifies the space around the cell
component inside a cell.
- Parameters:
- r - row number. All rows if it equals Grid.ALL_CELL.
- c - column number. All columns if it equals Grid.ALL_CELL.
- gap - cell component gap space.
getGap
public Insets getGap(int r,
int c)
- Return the cell gap space.
- Returns:
- cell gap space.
setAbsolute
public synchronized void setAbsolute(int f)
- If absolute is set to true, cells will not be resized to fit the
area. If user supplied sizes exists, they are treated as absolute
pixel size. Otherwise, preferred sizes are used to layout cells.
No consideration is given if all cells fits into the area. This
mode is automatically enabled when a Scroller is attached to
a Grid.
- Parameters:
- f - a bitwise OR of Grid.HORIZONTAL or Grid.VERTICAL.
getAbsolute
public int getAbsolute()
- Return absolute flag, which is a bitwise OR of Grid.HORIZONTAL
and Grid.VERTICAL.
- Returns:
- absolute mode.
setResizable
public synchronized void setResizable(boolean ok)
- Enable/disable user resize through dragging ruling lines.
If Grid has been resized by user, it will be switched to
absolute and row/column size override mode. Setting resizable
to false with this function will NOT change the layout
mode. In another word, the Grid will stay in absolute and
size override mode even resizable is set to false.
You need to call setAbsolute(Grid.NONE) and setRowHeight(null)
and setColWidth(null) explicitly to restore to default
layout mode.
- Parameters:
- ok - true to enable user resize, false to enable.
isResizable
public boolean isResizable()
- Return user resize flag.
- Returns:
- resizable flag.
- See Also:
- setResizable
setInPlaceResize
public synchronized void setInPlaceResize(boolean f)
- Is InPlaceResize property is true, user resize will resize the
two rows/columns next to the resize line. The overall size of
the rows/columns will not be changed.
- Parameters:
- f - inplace resize flag.
isInPlaceResize
public boolean isInPlaceResize()
- Get the InPlaceResize property.
- Returns:
- true if inplace resize mode is on.
setRowHeight
public synchronized void setRowHeight(int r,
int h)
- Set the specified row to the height. If absolute is true, this
size is the actual pixel size for each row. Otherwise, it specifies
the preferred height of this row, but the actual
height of the rows is dependent on the display area size.
- Parameters:
- r - row number. All rows if it equals to Grid.ALL_CELL.
- h - row height.
setRowHeight
public synchronized void setRowHeight(int rheight[])
- Explicitly specify the row heights in the grid. If absolute mode
is true, the values in the array is the actual pixel size of
each row. Otherwise, the values in the array is treated as the
preferred size of the rows.
The row height specification includes the header row.
If the argument
array has less elements than the number of rows, the remaining
row heights will not be changed.
Passing a null pointer will cancel row height override mode.
- Parameters:
- rheight - row heights array.
getRowHeight
public int[] getRowHeight()
- Get the current row heights setting. The meaning of row heights
depends on the absolute setting. For details, see setRowHeight().
- Returns:
- row heights.
setColWidth
public synchronized void setColWidth(int c,
int w)
- Set the specified column to the width. If absolute is true, this
size is the actual pixel size for each column. Otherwise, it specifies
the preferred width of this column, but the actual
width of the col is dependent on the display area size.
- Parameters:
- c - column number. All columns if it equals Grid.ALL_CELL.
- w - column width.
setColWidth
public synchronized void setColWidth(int cwidth[])
- Explicitly specify the column widths in the grid. If absolute mode
is true, the values in the array is the actual pixel size of
each column. Otherwise, the values in the array is treated as the
preferred size of the columns.
The column width specification includes the header column.
If the argument
array has less elements than the number of columns, the remaining
column widths will not be changed.
Passing a null pointer will cancel column width override mode.
- Parameters:
- cwidth - column widths array.
getColWidth
public int[] getColWidth()
- Get the current column width setting. The meaning of column widths
depends on the absolute setting. For details, see setColWidth().
- Returns:
- column widths.
setRuling
public synchronized void setRuling(int ruling)
- Set the ruling style. The argument can be a product of bitwise OR
of the available flags. For example, HORIZONTAL|VERTICAL will cause
both horizontal and vertical ruling to be drawn. This method
sets the grid wide ruling style. It can be overriden by per cell
ruling style.
- Parameters:
- ruling - ruling flag.
setRuling
public synchronized void setRuling(int r,
int c,
int ruling)
- Set the ruling for a particular cell. The argument can be a product
of bitwise OR of the available flags. The per cell ruling flag
controls the drawing of the ruling lines below and to the right of
the specified cell. For example, HORIZONTAL|VERTICAL will cause
both horizontal and vertical ruling to be drawn below and at right
side of the specified cell. The per cell ruling flag overrides
the grid wise ruling flag.
- Parameters:
- r - row number. All rows if it equals Grid.ALL_CELL.
- c - column number. All columns if it equals Grid.ALL_CELL.
- ruling - ruling flag.
getRuling
public int getRuling()
- Return the current ruling style. Use bitwise AND to check if a
flag is set.
- Returns:
- ruling flag.
getRuling
public int getRuling(int r,
int c)
- Return the per cell ruling style. Use bitwise AND to check if a
flag is set. If the specified cell is part of a spanning cell,
the spanning cell ruling option is returned.
- Parameters:
- r - row number.
- c - column number.
- Returns:
- cell ruling flag.
set3D
public synchronized void set3D(int mode)
- Set the line 3D mode. The value can be one of: PLAIN, RAISED,
and LOWERED. The mode defaults to RAISED.
- Parameters:
- mode - 3D mode.
get3D
public int get3D()
- Return the line 3D mode.
- Returns:
- 3D mode.
setLineWidth
public synchronized void setLineWidth(int w)
- Set the border line width for 3D border lines. This does not
affect non-3D lines.
- Parameters:
- w - line width in pixels.
getLineWidth
public int getLineWidth()
- Get the border line width.
setMultiSelect
public synchronized void setMultiSelect(boolean s)
- Set multiSelect mode to true or false. If multiSelect is enabled,
more than one row and/or column can be selected. Otherwise, only
one row or column can be selected at any given time. MultiSelect
defaults to false.
- Parameters:
- true - for multiple select mode.
isMultiSelect
public boolean isMultiSelect()
- Return true if multiSelect is enabled.
- Returns:
- multi-select mode.
setRowSelectable
public synchronized void setRowSelectable(boolean s)
- Set row selectable to true or false. If row is selectable, a
mouse click inside a cell selects the row where the cell is
in (Note: Some components do not pass mouse events up. In this
case a mouse click inside those cells will not select a row).
If row headers exist, the row header will serve as the row
selector. RowSelectable defaults to false.
- Parameters:
- s - true to make row selectable.
setRowSelectable
public synchronized void setRowSelectable(boolean s,
boolean sel)
- Set row selectable to true or false. If row is selectable, a row
selector will be added to each row if useRowHeader is true.
If row headers exist, the row header will serve as the row selector.
RowSelectable and useRowHeader defaults to false.
If row is selectable and no row selector exists, row
can be selected by clicking in any cell inside a row.
- Parameters:
- s - true to make row selectable.
- sel - create row selector if true.
setColSelectable
public synchronized void setColSelectable(boolean s)
- Set column selectable to true or false. If column is selectable, a
mouse click inside a cell selects the column where the cell is
in (Note: Some components do not pass mouse events up. In this
case a mouse click inside those cells will not select a column).
If column headers exist, the column header will serve as the column
selector. ColSelectable defaults to false.
- Parameters:
- s - true to make column selectable.
setColSelectable
public synchronized void setColSelectable(boolean s,
boolean sel)
- Set column selectable to true or false. If column is selectable,
a column selector will be added to each column if useColHeader
is true. If column headers exist, the column header will serve
as the column selector. ColSelectable and
useColHeader defaults to true. If column is selectable and
no column selector exists, column can be selected by clicking
in any cell inside a column.
- Parameters:
- s - true to make column selectable.
- sel - true to create column selector.
isRowSelectable
public boolean isRowSelectable()
- Return true if row is selectable.
- Returns:
- true if row is selectable.
isColSelectable
public boolean isColSelectable()
- Return true if column is selectable.
- Returns:
- true if column is selectable.
setRegionSelectable
public synchronized void setRegionSelectable(boolean f)
- Enable or disable region selectability.
- Parameters:
- f - true to enable and false to disable.
isRegionSelectable
public boolean isRegionSelectable()
- Check the region selectable setting.
- Returns:
- true if region is selected.
setRowHeader
public synchronized void setRowHeader(int r,
String header)
- Set one row header. If row is selectable, the row header also
serves as the row selector.
Newline '\n' can be embedded inside the header. Text separated
by newline are drawn as separate lines.
- Parameters:
- r - row number.
- header - row header string.
setRowHeader
public synchronized void setRowHeader(String header[])
- Set row headers. If row is selectable, the row header also
serves as the row selector.
Newline '\n' can be embedded inside the header. Text separated
by newline are drawn as separate lines.
- Parameters:
- header - row header string array.
getRowHeader
public synchronized String[] getRowHeader()
- Get the row header array. If no row header is set, it returns
an array of all nulls. Otherwise the header cell labels are
returned in an array.
- Returns:
- row header strings.
getRowHeader
public synchronized String getRowHeader(int r)
- Get the row header for the specified row. If the row header is
not set, it returns a null.
- Parameters:
- r - row number.
- Returns:
- row header for the row.
isRowHeaderExist
public boolean isRowHeaderExist()
- Return true if row header column exists.
- Returns:
- true if row header exists.
setColHeader
public synchronized void setColHeader(int c,
String header)
- Set one column header. If column is selectable, the column header
also serves as the column selector.
Newline '\n' can be embedded inside the header. Text separated
by newline are drawn as separate lines.
- Parameters:
- c - column number.
- header - column header string.
setColHeader
public synchronized void setColHeader(String header[])
- Set column headers. If column is selectable, the column header
also serves as the column selector.
Newline '\n' can be embedded inside the header. Text separated
by newline are drawn as separate lines.
- Parameters:
- header - column header string array.
getColHeader
public synchronized String[] getColHeader()
- Get the column header array. If no column header is set, it returns
an array of all nulls. Otherwise the header cell labels are returned
in an array.
- Returns:
- column header strings.
getColHeader
public String getColHeader(int c)
- Get the column header for the specified column. If the column
header is not set, returns null.
- Parameters:
- c - column number.
- Returns:
- column header for the column.
isColHeaderExist
public boolean isColHeaderExist()
- Return true if column header row exists.
- Returns:
- true if column header exists.
setCell
public synchronized void setCell(int r,
int c,
Component cell)
- Set the component for a grid cell. If a component is already
attached to the cell, it will be removed from the grid and
replaced with the new component. If the cell is inside the
spanning area of another cell, the spanning will be removed.
If the component passed into setCell() is null, the current
cell component is removed from the grid, and the cell becomes
empty. The Grid.ALL_CELL can be used as the row or column
number to set multiple cells components. But since a component
can only be at one place, the only reasonable component
for multiple cells is the null component. In another word,
Grid.ALL_CELL can be used to clear multiple cell components,
but would not work for setting multiple cell components.
- 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.
setCell
public synchronized void setCell(int r,
int c,
Component cell,
int spanRow,
int spanCol)
- Set the component for a spanning cell. If a component is already
attached to the cell, it will be removed from the grid and
replaced with the new component. The spanning cell occupies
number of rows and columns specified by spanRow and spanCol.
The spanRow and spanCol parameters must both be greater than
zero.
- Parameters:
- r - row number.
- c - column number.
- cell - cell component.
- spanRow - number of rows for spanning cell.
- spanCol - number of columns for spanning cell.
getCell
public Component getCell(int r,
int c)
- Return the component at cell. If not component is attached to the
cell, a null will be returned.
- Parameters:
- r - row number.
- c - column number.
- Returns:
- cell component.
setSpanning
public synchronized void setSpanning(int r,
int c,
int spanRow,
int spanCol)
- Set the spanning cell size. The spanRow and spanCol must be
greater than zero.
- Parameters:
- r - row number. All rows if it equals Grid.ALL_CELL.
- c - column number. All columns if it equals Grid.ALL_CELL.
- spanRow - number of rows for spanning cell.
- spanCol - number of columns for spanning cell.
setSpanning
public synchronized void setSpanning(int r,
int c,
Dimension span)
- Set the cell spanning dimension.
- Parameters:
- r - row number. All rows if it equals Grid.ALL_CELL.
- c - column number. All columns if it equals Grid.ALL_CELL.
- span - spanning dimension, Dimension.width is the number
of columns, and Dimension.height is the number of rows.
getSpanning
public Dimension getSpanning(int r,
int c)
- Return the spanning setting for the cell. If the specified cell
is not a spanning cell, it returns null. Otherwise it returns
a Dimension object with Dimension.width equals to the number
of columns and Dimension.height equals to the number of rows
of the spanning cell.
- Parameters:
- r - row number.
- c - column number.
- Returns:
- spanning cell dimension.
setAlignment
public synchronized void setAlignment(int alignment)
- Set the alignment for the grid. This method sets the grid wide
alignment flag. It's overriden by per cell alignment flag
if per cell alignment flag is set.
- Parameters:
- alignment - cell alignment flag.
setAlignment
public synchronized void setAlignment(int r,
int c,
int alignment)
- Set the alignment for a particular cell. This overrides the
grid wise alignment flag.
- Parameters:
- r - row number. All rows if it equals Grid.ALL_CELL.
- c - column number. All columns if it equals Grid.ALL_CELL.
- alignment - cell alignment flag.
getAlignment
public int getAlignment()
- Return the current alignment.
- Returns:
- grid wise alignment.
getAlignment
public int getAlignment(int r,
int c)
- Return the per cell alignment.
- Parameters:
- r - row number.
- c - column number.
- Returns:
- cell alignment.
setColor
public synchronized void setColor(int r,
int c,
Color color)
- Set the specified cell to the color. It clears the explicit
color if color parameter is null, in which case the cell
component's own color is used. The different between setting
color using Grid.setColor(), and setting color through the Component
interface of cell component is: 1. If there are colors in
a cell, the color in the color area will not be affected if
color is set through Component interface of component cell.
2. If a cell is empty, the color can only be set using
Grid.setColor().
- Parameters:
- r - row number. All rows if it equals Grid.ALL_CELL.
- c - column number. All columns if it equals Grid.ALL_CELL.
- color - cell color. Clear explicit color if null.
getColor
public Color getColor(int r,
int c)
- Return the per cell background color.
- Parameters:
- r - row number.
- c - column number.
- Returns:
- cell background color.
hideRow
public void hideRow(int r)
- Hide a row.
- Parameters:
- r - row number. All rows if it equals Grid.ALL_CELL.
showRow
public void showRow(int r)
- Show a hiden row.
- Parameters:
- r - row number. All rows if it equals Grid.ALL_CELL.
showRow
public synchronized void showRow(int r,
boolean showit)
- Show or hide a row.
- Parameters:
- r - row number. All rows if it equals Grid.ALL_CELL.
- showit - true to show a hiden row, false to hide a row.
isVisibleRow
public boolean isVisibleRow(int r)
- Return true if the specified row is currently visible. Rows above
row root and below frozen rows are counted as hiden.
- Parameters:
- r - row number.
- Returns:
- true if row is visible.
hideCol
public void hideCol(int c)
- Hide a column.
- Parameters:
- c - column number. All columns if it equals Grid.ALL_CELL.
showCol
public void showCol(int c)
- Show a hiden column.
- Parameters:
- c - column number. All columns if it equals Grid.ALL_CELL.
showCol
public synchronized void showCol(int c,
boolean showit)
- Show or hide a column.
- Parameters:
- c - column number. All columns if it equals Grid.ALL_CELL.
- showit - true to show a hiden column, false to hide a column.
isVisibleCol
public boolean isVisibleCol(int c)
- Return true if the specified column is visible. Columns left of column
root and right of frozen columns are counted as hiden.
- Parameters:
- c - column number.
- Returns:
- true if column is visible.
deselectRow
public void deselectRow(int r)
- Unselect a row. A LIST_DESELECT event is generated when a row
is deselected.
- Parameters:
- r - row number. All rows if it equals Grid.ALL_CELL.
deselectCol
public void deselectCol(int c)
- Unselect a column. A LIST_DESELECT event is generated when a column
is deselected.
- Parameters:
- c - column number. All columns if it equals Grid.ALL_CELL.
selectRow
public void selectRow(int r)
- Select a row. If multiSelect is not enabled, this will cause
other selections to be cleared. A LIST_SELECT event is
generated when a row is selected.
- Parameters:
- r - row number. All rows if it equals Grid.ALL_CELL.
selectRow
public synchronized void selectRow(int r,
boolean sel)
- Select or deselect a row according to the select flag.
- Parameters:
- r - row number. All rows if it equals Grid.ALL_CELL.
- sel - select flag. True to select a row.
selectCol
public void selectCol(int c)
- Select a column. If multiSelect is not enabled, this will cause
other selections to be cleared. A LIST_SELECT event is
generated when a row is selected.
- Parameters:
- c - column number.
selectCol
public synchronized void selectCol(int c,
boolean sel)
- Select of deselect a column.
- Parameters:
- c - column number. All columns if it equals to Grid.ALL_CELL.
- sel - select or deselect the column.
getSelectedRow
public synchronized int getSelectedRow()
- Return the selected row index. If more than one row is selected,
the first selected row is returned.
- Returns:
- row number of selected row. -1 if no row is selected.
getSelectedRows
public synchronized int[] getSelectedRows()
- Return all selected row indexes.
- Returns:
- row numbers of selected rows.
getSelectedCol
public synchronized int getSelectedCol()
- Return the selected column index. If more than one column is selected,
the first selected column is returned.
- Returns:
- column number of selected column. -1 if no column is selected.
getSelectedCols
public synchronized int[] getSelectedCols()
- Return all selected column indexes.
- Returns:
- column numbers of selected columns.
getSelectedObjects
public Object[] getSelectedObjects()
- Get the row headers of the selected rows.
- Returns:
- row headers of the selected rows.
isSelectedRow
public boolean isSelectedRow(int r)
- Return true if specified row is selected.
- Parameters:
- r - row number.
- Returns:
- true if row is selected.
isSelectedCol
public boolean isSelectedCol(int c)
- Return true if specified column is selected.
- Parameters:
- c - column number.
- Returns:
- true if column is selected.
deselect
public synchronized void deselect()
- Deselect all rows/columns/regions. This is more efficient than calling
deselectRow(Grid.ALL_CELL) or deselectCol(Grid.ALL_CELL).
selectRegion
public synchronized void selectRegion(Grid. Region reg)
- Select the region specified in the region. Generates an ItemEvent
SELECTED event.
- Parameters:
- reg - grid region.
deselectRegion
public synchronized void deselectRegion()
- Deselect a region. Generates an ItemEvent DESELECTED event.
getSelectedRegion
public Grid. Region getSelectedRegion()
- Get the selected region. If no region is selected, return null.
- Returns:
- selected region or null if not region is selected.
isSelected
public boolean isSelected(int r,
int c)
- Return true if the cell is selected as part of row, column, or region.
- Returns:
- true if the cell is selected.
setRowRoot
public synchronized void setRowRoot(int row)
- The row root is the row which will be displayed as the top row.
Rows above the row root is not displayed. Frozen rows override
row root. This is used mostly for scrolling.
- Parameters:
- row - row number.
setColRoot
public synchronized void setColRoot(int col)
- The col root is the column which will be displayed as the leftmost
column. Columns left of the column root is not displayed. Frozen
columns override column root. This is used mostly for scrolling.
- Parameters:
- col - column number.
getRowRoot
public int getRowRoot()
- Return the current row root. See setRowRoot() for an explanation of
row root.
- Returns:
- the root row number.
getBottomRow
public int getBottomRow()
- Return the index of the last visible row on screen.
- Returns:
- index of last visible row.
getColRoot
public int getColRoot()
- Return the current col root. See setColRoot() for an explanation of
col root.
- Returns:
- the root column number.
getBottomCol
public int getBottomCol()
- Return the index of last visible column on screen.
- Returns:
- the index of last visible column.
setFrozenRow
public synchronized void setFrozenRow(int nrow)
- Freeze the number of rows from the top row(0). Rows freezing are
not affected by the row root setting. Set freeze row to zero(0)
to unfreeze all rows.
- Parameters:
- nrow - number of rows.
setFrozenCol
public synchronized void setFrozenCol(int ncol)
- Freeze the number of columns from the top column(0). Columns freezing
are not affected by the column root setting. Set freeze column
to zero(0) to unfreeze all columns.
- Parameters:
- ncol - number of columns.
getFrozenRow
public int getFrozenRow()
- Get the current number of frozen rows.
- Returns:
- number of frozen rows.
getFrozenCol
public int getFrozenCol()
- Get the current number of frozen columns.
- Returns:
- number of frozen columns.
setAutoRepaint
public void setAutoRepaint(boolean f)
- If auto repaint mode is turned off (default to true), a repaint
will not be generated by this Grid. The user of the Grid is
responsible for explicitly calling repaint() method on the
Grid.
- Parameters:
- f - auto repaint flag.
isAutoRepaint
public boolean isAutoRepaint()
- Return true if auto repaint is on.
- Returns:
- auto repaint mode.
getPreferredSize
public Dimension getPreferredSize()
- Return the preferred size of grid. The preferred size is the
sum of preferred row heights and sum of preferred column
width. The preferred row height is defined as the maximum
preferred height of cells in one row. Similarly for preferred
column width. If coordinates are explicitly supplied, the
preferred size is simply calculated using the coordinates.
- Returns:
- preferred size.
- Overrides:
- getPreferredSize in class Container
getMinimumSize
public Dimension getMinimumSize()
- Return the minimum size of grid. It's currently same as preferred
size.
- Returns:
- minimum size.
- Overrides:
- getMinimumSize in class Container
doLayout
public void doLayout()
- Layout the grid cells. Called automatically.
- Overrides:
- doLayout in class Container
paint
public void paint(Graphics g)
- Paint the grid.
- Parameters:
- g - Graphics context of this component.
- Overrides:
- paint in class Container
update
public void update(Graphics g)
- Override for double buffering.
- Parameters:
- g - Graphics context of this component.
- Overrides:
- update in class Component
repaint
public void repaint()
- Explicit repaint cause the grid to be re-layed out.
- Overrides:
- repaint in class Component
addItemListener
public void addItemListener(ItemListener listener)
- Add an item listener.
- Parameters:
- listener - item listener.
removeItemListener
public void removeItemListener(ItemListener listener)
- Remove an item listener.
- Parameters:
- listener - item listener.
processEvent
public void processEvent(AWTEvent e)
- Process and dispatch event.
- Parameters:
- e - event object.
- Overrides:
- processEvent in class Container
processItemEvent
public void processItemEvent(ItemEvent e)
- Process and dispatch item event.
- Parameters:
- e - item event.
processMouseMotionEvent
public synchronized void processMouseMotionEvent(MouseEvent e)
- Handle cell resize, row/column selection, tab keys and next
focus, and arrow keys.
- Parameters:
- e - event object.
- Overrides:
- processMouseMotionEvent in class Component
processMouseEvent
public void processMouseEvent(MouseEvent e)
- Process mouse click events. This handles row/column resize, row
and column selection, and region selection.
- Overrides:
- processMouseEvent in class Component
registerScroller
public synchronized void registerScroller(Scroller scr)
- This function is called by Scroller at initialization time. The Grid
will call Scroller.notifyUpdate() when scrollbar values need to be
recalculated.
- Parameters:
- scr - Scroller where this grid is attached to.
getMinimum
public int getMinimum(int orientation)
- Return scrollbar minimum (columns).
- Parameters:
- orientation - VERTICAL or HORIZONTAL.
- Returns:
- minimum scrollbar value for the orientation.
getMaximum
public synchronized int getMaximum(int orientation)
- Return scrollbar maximum (columns).
- Parameters:
- orientation - VERTICAL or HORIZONTAL.
- Returns:
- maximum scrollbar value for the orientation.
getValue
public int getValue(int orientation)
- Return the current value of the specified scrollbar.
- Parameters:
- orientation - VERTICAL or HORIZONTAL.
- Returns:
- scrollbar value for the orientation.
getVisibleAmount
public int getVisibleAmount(int orientation)
- Get the visible portion for the specified direction. This
is only an approximate.
- Parameters:
- orientation - VERTICAL or HORIZONTAL.
- Returns:
- scrollbar visible value for the orientation.
getIncrement
public synchronized int getIncrement(int orientation,
int direction)
- Get the increment for scrollbars.
- Parameters:
- orientation - VERTICAL or HORIZONTAL.
- direction - UNIT_DECREMENT, UNIT_INCREMENT, BLOCK_DECREMENT,
or BLOCK_INCREMENT.
- Returns:
- scrollbar increments for the orientation.
setValue
public void setValue(int orientation,
int v)
- Scroll the grid according to scrollbar value.
- Parameters:
- orientation - VERTICAL or HORIZONTAL.
- v - scrollbar value for the orientation.
getBounds
public Rectangle getBounds(int r,
int c)
- Get the cell location and cell size. The location of the cell
is relative to this grid. The size is adjusted for border lines
and cell gaps.
- Parameters:
- r - row number.
- c - column number.
- Returns:
- cell location and size.
locateCell
public Point locateCell(int x,
int y)
- Find the cell where the pointer is in.
The calculation is based on coordinates and spanning cell information.
If the cell is in a column header or a row header, the row
number or the column number would be set to Grid.HEADER.
If the point does not fall into any cell area, a null is
returned.
- Parameters:
- x - x coordinate. Relative to grid.
- y - y coordinate. Relative to grid.
- Returns:
- column and row number. Point.x is the column number.
Point.y is the row number.
highlight
public synchronized void highlight(int r,
int c,
boolean hl)
- Highlight the specified cell. Highlight the same row twice
return the color to its original state.
- Parameters:
- r - row number.
getCellInfo
protected Grid. CellInfo getCellInfo(int r,
int c)
- Get the per cell attributes. The attributes are maintained by
Grid and the derived classes only need to make sure to case
the object returned by this method to the correct class type.
- Parameters:
- r - row number.
- c - column number.
- Returns:
- cell attributes.
createCellInfo
protected Grid. CellInfo createCellInfo()
- This method can be overriden by subclasses to provide a
different CellInfo class.
- Returns:
- a new CellInfo object.
getRowInfo
protected Grid. RowInfo getRowInfo(int r)
- Get the per row attributes. The attributes are maintained by
Grid and the derived classes only need to make sure to case
the object returned by this method to the correct class type.
- Parameters:
- r - row number.
- Returns:
- row attributes.
createRowInfo
protected Grid. RowInfo createRowInfo()
- This method can be overriden by subclasses to provide a
different RowInfo class.
- Returns:
- a new RowInfo object.
getColInfo
protected Grid. ColInfo getColInfo(int r)
- Get the per column attributes. The attributes are maintained by
Grid and the derived classes only need to make sure to case
the object returned by this method to the correct class type.
- Parameters:
- r - column number.
- Returns:
- column attributes.
createColInfo
protected Grid. ColInfo createColInfo()
- This method can be overriden by subclasses to provide a
different ColInfo class.
- Returns:
- a new ColInfo object.
getPreferredSize
protected Dimension getPreferredSize(int r,
int c)
- Get the preferred size of the specified cell. The default is the
preferred size of the component in the cell. It can be override
by derived class to provide a different semantics.
- Parameters:
- r - row number.
- c - column number.
- Returns:
- the preferred size of the specified cell.
handleProperty
protected synchronized boolean handleProperty(int n1,
int n2,
Object val,
Class type,
String prop)
- This method is called by set property methods to handle
ALL_CELL flag for row and column numbers. It in turn calls
setProperty() to set the property. If row and/or column number
are ALL_CELL, this method provides the loop to call
setProperty for all the specified cells, and it returns true.
If none of the row and column number is ALL_CELL, it simply
returns false. This method is normally not overriden, but
can be used by derived class to handle ALL_CELL for properties.
- Parameters:
- n1 - index one.
- n2 - index two.
- val - property value.
- prop - method name.
- Returns:
- true if property has been properly set.
setProperty
protected void setProperty(int n1,
int n2,
Object val,
Class type,
String prop)
- This method calls the actual set property methods. It decides
which method to call based on the property name. Derived class
can override this method to check for additional properties.
If this method is derived, it's important it's chained back
to the super class method.
For methods that only take on index, the first index will be
used unless its value is NIL, in which case the second index
will be used.
- Parameters:
- n1 - index one.
- n2 - index two.
- val - property value.
- prop - property name.
doRepaint
protected void doRepaint(boolean dolayout,
boolean calcsize)
- This method should used by all derived class of Grid to send
repaint request. It honors the AutoRepaint property.
setSuspended
protected synchronized void setSuspended(boolean t)
- Suspend layout and paint if the flag is true. This is for advance
uses where a large amount of activities are performed, in which
case frequent layout and paint will degrade the performance.
When suspension is lefted, a repaint is issued automatically
to bring everything in sync.
- Parameters:
- t - true to suspend layout and repaint.
isSuspended
protected boolean isSuspended()
- Check if the paint is currently suspended.
- Returns:
- true if paint is suspended.
alignCell
protected Rectangle alignCell(Rectangle box,
Dimension psize,
int align)
- Align a rectangle area inside another rectangle area according
to the alignment flag.
- Parameters:
- box - outer rectangle area.
- psize - inner rectangle area.
- align - alignment flag.
- Returns:
- aligned rectangle area position and size.
adjustRegion
protected synchronized void adjustRegion(int r,
int c,
int nrow,
int ncol)
- Called when regions need to be adjusted, such as row/column move,
insert, remove, etc..
- Parameters:
- r - row number.
- c - column number.
- nrow - the row adjustment.
- ncol - the column adjustment.
adjustRegion
protected synchronized void adjustRegion(Grid. Region reg,
int r,
int c,
int nrow,
int ncol)
- Adjust a particular region.
- Parameters:
- r - row number.
- c - column number.
- nrow - the row adjustment.
- ncol - the column adjustment.
getPreferredRowHeight
protected 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.
getPreferredColWidth
protected 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.
paintText
protected void paintText(Graphics g,
String str,
Rectangle bound,
int align)
- Generate the pressed and unpressed image. The graphics object
parameter is clipped to the area of this cell.
- Parameters:
- g - graphics object.
- str - text string.
- text - alignment flag.
paintRowHeader
protected void paintRowHeader(Graphics g,
int r)
- Paint the specified row header cell if it's not empty.
- Parameters:
- g - Graphics object.
- r - row number.
paintColHeader
protected void paintColHeader(Graphics g,
int c)
- Paint the specified column header cell if it's not empty.
- Parameters:
- g - Graphics object.
- c - column number.
All Packages Class Hierarchy This Package Previous Next Index