|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jdesktop.swingx.table.ColumnFactory
public class ColumnFactory
Creates and configures TableColumnExt
s.
TODO JW: explain types of configuration - initial from tableModel, initial from table context, user triggered at runtime.
JXTable
delegates all TableColumn
creation and
configuration to a ColumnFactory
. Enhanced column
configuration should be implemented in a custom factory subclass. The example
beautifies the column titles to always start with a capital letter:
MyColumnFactory extends ColumnFactory {
//@Override
public void configureTableColumn(TableModel model,
TableColumnExt columnExt) {
super.configureTableColumn(model, columnExt);
String title = columnExt.getTitle();
title = title.substring(0,1).toUpperCase() + title.substring(1).toLowerCase();
columnExt.setTitle(title);
}
};
By default a single instance is shared across all tables of an application.
This instance can be replaced by a custom implementation, preferably "early"
in the application's lifetime.
ColumnFactory.setInstance(new MyColumnFactory());
Alternatively, any instance of JXTable
can be configured
individually with its own ColumnFactory
.
JXTable table = new JXTable();
table.setColumnFactory(new MyColumnFactory());
table.setModel(myTableModel);
JXTable.setColumnFactory(ColumnFactory)
Constructor Summary | |
---|---|
ColumnFactory()
|
Method Summary | |
---|---|
void |
configureColumnWidths(JXTable table,
TableColumnExt columnExt)
Configures column initial widths properties from JXTable . |
void |
configureTableColumn(TableModel model,
TableColumnExt columnExt)
Configure column properties from TableModel. |
TableColumnExt |
createAndConfigureTableColumn(TableModel model,
int modelIndex)
Creates and configures a TableColumnExt. |
TableColumnExt |
createTableColumn(int modelIndex)
Creates a table column with modelIndex. |
int |
getDefaultPackMargin()
Returns the default pack margin. |
static ColumnFactory |
getInstance()
Returns the shared default factory. |
protected int |
getRowCount(JXTable table)
Returns the number of table view rows accessible during row-related config. |
void |
packColumn(JXTable table,
TableColumnExt columnExt,
int margin,
int max)
Configures the column's preferredWidth to fit the content. |
void |
setDefaultPackMargin(int margin)
Sets the default pack margin. |
static void |
setInstance(ColumnFactory factory)
Sets the shared default factory. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ColumnFactory()
Method Detail |
---|
public static ColumnFactory getInstance()
ColumnFactory
setInstance(ColumnFactory)
public static void setInstance(ColumnFactory factory)
JXTable
if none has been set individually.
factory
- the default column factory.getInstance()
,
JXTable.getColumnFactory()
public TableColumnExt createAndConfigureTableColumn(TableModel model, int modelIndex)
JXTable
calls
this method for each column in the TableModel
.
model
- the TableModel to read configuration properties frommodelIndex
- column index in model coordinates
NPE
- if model == null
IllegalStateException
- if the modelIndex is invalid
(in coordinate space of the tablemodel)createTableColumn(int)
,
configureTableColumn(TableModel, TableColumnExt)
,
JXTable.createDefaultColumnsFromModel()
public TableColumnExt createTableColumn(int modelIndex)
The factory's column creation is passed through this method, so subclasses can override to return custom column types.
modelIndex
- column index in model coordinates
modelIndex
createAndConfigureTableColumn(TableModel, int)
public void configureTableColumn(TableModel model, TableColumnExt columnExt)
headerValue
property from the
model's columnName
.
The factory's initial column configuration is passed through this method, so subclasses can override to customize.
model
- the TableModel to read configuration properties fromcolumnExt
- the TableColumnExt to configure.
NullPointerException
- if model or column == null
IllegalStateException
- if column does not have valid modelIndex
(in coordinate space of the tablemodel)createAndConfigureTableColumn(TableModel, int)
public void configureColumnWidths(JXTable table, TableColumnExt columnExt)
JXTable
.
This bare-bones implementation sets the column's preferredWidth
using it's prototype
property. TODO JW - rename method to better convey what's happening, maybe initializeColumnWidths like the old method in JXTable.
table
- the context the column will live in.columnExt
- the Tablecolumn to configure.JXTable.getPreferredScrollableViewportSize()
public void packColumn(JXTable table, TableColumnExt columnExt, int margin, int max)
preferredWidth
to fit the content.
It respects the table context, a margin to add and a maximum width. This is
typically called in response to a user gesture to adjust the column's width
to the "widest" cell content of a column.
This implementation loops through all rows of the given column and measures the renderers pref width (it's a potential performance sink). Subclasses can override to implement a different strategy.
Note: though 2 * margin is added as spacing, this does not imply a left/right symmetry - it's up to the table to place the renderer and/or the renderer/highlighter to configure a border.
table
- the context the column will live in.columnExt
- the column to configure.margin
- the extra spacing to add twice, if -1 uses this factories
defaultmax
- an upper limit to preferredWidth, -1 is interpreted as no
limitsetDefaultPackMargin(int)
,
JXTable.packTable(int)
,
JXTable.packColumn(int, int)
protected int getRowCount(JXTable table)
Subclasses can override to reduce the number (for performance) or support
restrictions due to lazy loading, f.i. Implementors must guarantee that
view row access with 0 <= row < getRowCount(JXTable)
succeeds.
table
- the table to access
public int getDefaultPackMargin()
setDefaultPackMargin(int)
public void setDefaultPackMargin(int margin)
Note: this is not really a margin in the sense of symmetrically adding white space to the left/right of a cell's content. It's simply an amount of space which is added twice to the measured widths in packColumn.
margin
- the default marging to use in packColumn.getDefaultPackMargin()
,
packColumn(JXTable, TableColumnExt, int, int)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |