|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JTable
com.sciapp.table.AdvancedJTable
com.sciapp.tree.TreeTable
public class TreeTable
TreeTable works exactly the same as AdvancedJTable, with the only difference that this component is capable of grouping several similar rows of a table in a single row by using a JTree component. You can control when rows will be put together under a tree by adding or removing TreeTableComparators from a TreeTableModel.
TreeTable uses a TreeTableModel as its TableModel. An IllegalArgumentException is thrown if one tries to set a TableModel that is not an instance of the TreeTableModel class.
A TreeTable component can be created by supplying an instance of ListTableModel. TreeTable takes this parameter and constructs a TreeTableModel, which it uses as its TableModel. A TreeTableModel instance can also be given when constructing a TreeTable.
The view of the TreeTable can be easily customized. In fact, the
getCellRenderer
method has been overriden so that
aggregate rows can have their own renderer. The renderer to use in those cases can be
assigned with setDefaultAggregateRenderer
.
The getAggregateCellRenderer
method can also be
overriden to provide a similar behaviour.
TreeTable will install, by default, aggregate renderers for the basic classes (String, Object, Date, Boolean
and Number). see createDefaultRenderers
A reference to the TreeTableModel can be taken with:
TreeTableModel treeModel = (TreeTableModel) table.getModel();
If you want to enable sorting and filtering capabilities on this component,
the ListTableModel that you pass in the constructor should be created like this:
Say you have a ListTableModel ltm
that holds the tabular data.
FilterTableModel ftm = new FilterTableModel(ltm);
SortTableModel stm = new SortTableModel(ftm);
TreeTable table = new TreeTable(stm);
Of course, you need to register the header in stm for mouse clicks to be processed by the model. stm.setHeader(table.getTableHeader());
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.sciapp.table.AdvancedJTable |
---|
AdvancedJTable.InnerTableColumnModel, AdvancedJTable.InnerTableHeader |
Nested classes/interfaces inherited from class javax.swing.JTable |
---|
JTable.AccessibleJTable |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
---|---|
protected Hashtable |
defaultAggregateRenderers
A table of objects that are responsible for drawing the cells of aggregate rows, indexed by class. |
Fields inherited from class com.sciapp.table.AdvancedJTable |
---|
isFirstColumnFixed, tableReorder |
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
TreeTable()
Constructs a TreeTable object with an empty model as the ListTableModel that contains the
table's data. |
|
TreeTable(ListTableModel model)
Constructs a TreeTable object having model as the ListTableModel that contains the
table's data. |
|
TreeTable(TreeTableModel model)
Constructs a TreeTable object having model as the TreeTableModel. |
Method Summary | |
---|---|
protected void |
createDefaultRenderers()
TreeTable installs a DefaultAggregateRenderer for each of the basic classes (String, Object, Date, Boolean
and Number). |
protected static TreeTableModel |
createDefaultTreeTableModel(ListTableModel tableModel)
Returns a TreeTableModel instance that will be used as the tablemodel of this TreeTable. |
protected TableReorder |
createReorder()
Returns the TableReorder that will handle table selection changes. |
boolean |
editCellAt(int row,
int column,
EventObject e)
Programmatically starts editing the cell at row and
column , if the cell is editable. |
TableCellRenderer |
getAggregateCellRenderer(int row,
int column)
Returns a TableCellRenderer component that will be used to render the aggregate row specified by row and column . |
Rectangle |
getCellRect(int row,
int column,
boolean includeSpacing)
Returns a rectangle for the cell that lies at the intersection of row and column . |
TableCellRenderer |
getCellRenderer(int row,
int column)
For aggregate rows, this method returns the result from calling getAggregateCellRenderer . |
TableCellRenderer |
getDefaultAggregateRenderer(Class columnClass)
Returns the renderer responsible for drawing an aggregate's row column of class specified by columnClass . |
int |
getEditingRow()
Returns the index of the row that contains the cell currently being edited. |
JTree |
getTree()
Returns the JTree component that is displayed on the first column of the table. |
Component |
prepareRenderer(TableCellRenderer renderer,
int row,
int column)
Prepares the renderer by querying the data model for the value and selection state of the cell at row , column . |
void |
setDefaultAggregateRenderer(Class columnClass,
TableCellRenderer renderer)
Set a default aggregate renderer to be used for rendering aggregate rows based on their column's class. |
void |
setEvenColor(Color evenColor)
Sets the color for painting the even rows of the table to all the renderers contained in the defaultRenderersByColumnClass Hashtable (provided the renderer is an instance of DefaultRenderer . |
void |
setModel(TableModel model)
Sets the data model for this table to newModel and registers
with it for listener notifications from the new data model. |
void |
setOddColor(Color oddColor)
Sets the color for painting the odd rows of the table to all the renderers contained in the defaultRenderersByColumnClass Hashtable (provided the renderer is an instance of DefaultRenderer . |
void |
setRowHeight(int rowHeight)
Sets the height, in pixels, of all cells to rowHeight ,
revalidates, and repaints. |
void |
sizeColumnsToFit(int resizingColumn)
This method will resize one or more ot the columns in the table so that the total width of all of the JTable's columns will be equal to the width of the table. |
void |
updateUI()
Notification from the UIManager that the L&F has changed.
Replaces the current UI object with the latest version from the
UIManager . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected transient Hashtable defaultAggregateRenderers
Constructor Detail |
---|
public TreeTable()
model
as the ListTableModel that contains the
table's data.
public TreeTable(ListTableModel model)
model
as the ListTableModel that contains the
table's data.
This constructor will call createDefaultTreeTableModel on model
.
public TreeTable(TreeTableModel model)
model
as the TreeTableModel.
Method Detail |
---|
protected void createDefaultRenderers()
DefaultAggregateRenderer
for each of the basic classes (String, Object, Date, Boolean
and Number).
Creates default cell renderers for objects, numbers, doubles, dates, booleans, and icons.
createDefaultRenderers
in class AdvancedJTable
DefaultTableCellRenderer
protected static TreeTableModel createDefaultTreeTableModel(ListTableModel tableModel)
tableModel
- the ListTableModel that contains the treetable's data.
protected TableReorder createReorder()
createReorder
in class AdvancedJTable
public boolean editCellAt(int row, int column, EventObject e)
row
and
column
, if the cell is editable.
To prevent the JTable
from editing a particular table,
column or cell value, return false from the isCellEditable
method in the TableModel
interface.
editCellAt
in class JTable
row
- the row to be editedcolumn
- the column to be editede
- event to pass into shouldSelectCell
;
note that as of Java 2 platform v1.2, the call to
shouldSelectCell
is no longer made
public TableCellRenderer getAggregateCellRenderer(int row, int column)
row
and column
.
This method returns the appropriate aggregate renderer based on the class of the object found at (row, column). If this value is null, it will return the aggregate renderer for the String class.
row
- the index of the row being renderedcolumn
- the index of the column being rendered
public Rectangle getCellRect(int row, int column, boolean includeSpacing)
row
and column
.
If includeSpacing
is true then the value returned
has the full height and width of the row and column
specified. If it is false, the returned rectangle is inset by the
intercell spacing to return the true bounds of the rendering or
editing component as it will be set during rendering.
If the column index is valid but the row index is less
than zero the method returns a rectangle with the
y
and height
values set appropriately
and the x
and width
values both set
to zero. In general, when either the row or column indices indicate a
cell outside the appropriate range, the method returns a rectangle
depicting the closest edge of the closest cell that is within
the table's range. When both row and column indices are out
of range the returned rectangle covers the closest
point of the closest cell.
In all cases, calculations that use this method to calculate
results along one axis will not fail because of anomalies in
calculations along the other axis. When the cell is not valid
the includeSpacing
parameter is ignored.
getCellRect
in class JTable
row
- the row index where the desired cell
is locatedcolumn
- the column index where the desired cell
is located in the display; this is not
necessarily the same as the column index
in the data model for the table; the
JTable.convertColumnIndexToView(int)
method may be used to convert a data
model column index to a display
column indexincludeSpacing
- if false, return the true cell bounds -
computed by subtracting the intercell
spacing from the height and widths of
the column and row models
row
,column
public TableCellRenderer getCellRenderer(int row, int column)
getAggregateCellRenderer
.
If the value returned is null or if the row is not aggregate, this method
returns the result from it's superclass.
Returns an appropriate renderer for the cell specified by this row and
column. If the TableColumn
for this column has a non-null
renderer, returns that. If not, finds the class of the data in
this column (using getColumnClass
)
and returns the default renderer for this type of data.
Note: Throughout the table package, the internal implementations always use this method to provide renderers so that this default behavior can be safely overridden by a subclass.
getCellRenderer
in class JTable
row
- the row of the cell to render, where 0 is the first rowcolumn
- the column of the cell to render,
where 0 is the first column
null
returns the default renderer
for this type of objectDefaultTableCellRenderer
,
TableColumn.setCellRenderer(javax.swing.table.TableCellRenderer)
,
JTable.setDefaultRenderer(java.lang.Class, javax.swing.table.TableCellRenderer)
public TableCellRenderer getDefaultAggregateRenderer(Class columnClass)
columnClass
.
The renderer is fetched from a Hashtable of entries (defaultAggregateRenderers) according to the
object's class. If there is no entry for this columnClass the method returns
the entry for the most specific superclass.
TreeTable installs entries for Object, Number, Boolean,String and
Date all of which can be modified or replaced.
columnClass
- the column's class
public int getEditingRow()
getEditingRow
in class JTable
JTable.editingColumn
public JTree getTree()
DefaultTreeCellRenderer tcr = (DefaultTreeCellRenderer) treeTable.getTree().getCellRenderer();
ImageIcon leafIcon = new ImageIcon("c:\\icons\\leafIcon.gif");
ImageIcon closedIcon = new ImageIcon("c:\\icons\\closedIcon.gif");
tcr.setLeafIcon(leafIcon);
tcr.setClosedIcon(closedIcon);
public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
row
, column
.
Returns the component (may be a Component
or a JComponent
) under the event location.
Note: Throughout the table package, the internal implementations always use this method to prepare renderers so that this default behavior can be safely overridden by a subclass.
prepareRenderer
in class AdvancedJTable
renderer
- the TableCellRenderer
to preparerow
- the row of the cell to render, where 0 is the first rowcolumn
- the column of the cell to render,
where 0 is the first column
Component
under the event locationpublic void setDefaultAggregateRenderer(Class columnClass, TableCellRenderer renderer)
columnClass
- set the default aggregate renderer for this columnClassrenderer
- default aggregate renderer to be used for this columnClasspublic void setEvenColor(Color evenColor)
DefaultRenderer
.
setEvenColor
in class AdvancedJTable
evenColor
- the even row colorpublic void setModel(TableModel model)
newModel
and registers
with it for listener notifications from the new data model.
setModel
in class AdvancedJTable
model
- the new data source for this tableJTable.getModel()
public void setOddColor(Color oddColor)
DefaultRenderer
.
setOddColor
in class AdvancedJTable
oddColor
- the odd row colorpublic void setRowHeight(int rowHeight)
rowHeight
,
revalidates, and repaints.
The height of the cells will be equal to the row height minus
the row margin.
setRowHeight
in class JTable
rowHeight
- new row heightJTable.getRowHeight()
public void sizeColumnsToFit(int resizingColumn)
sizeColumnsToFit
in class JTable
resizingColumn
- The column whose resizing made this adjustment
necessary or -1 if there is no such column.JTable.doLayout()
public void updateUI()
UIManager
that the L&F has changed.
Replaces the current UI object with the latest version from the
UIManager
.
updateUI
in class AdvancedJTable
JComponent.updateUI()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |