|
QJCC homepage | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object biz.chitec.quarterback.swing.TableCellSizeAdjustor
Adjusts width and height of table colums according to their content. TableCellSizeAdjustor listens for changes in data or column arrangement of a table and readjusts the table's column widths, so that for each column, the widest content of all rows fits into the table. Furthermore, it adjusts the cell heights so that the largest content fits, either row by row (default) or globally. Cell size is determined through the renderer object's preferred size. It is possible to advise TableCellSizeAdjustor to additionally take the editor's size into consideration and use the width and height maximum of renderer and editor.
TableCellSizeAdjustor doesn't make any assumptions about the content of the table, apart from the model object itself not changing. Otherwise, it just uses the normal interfaces and methods. TableCellSizeAdjustor turns the table in AUTO_RESIZE_OFF mode as the resizing is now managed completely by the adjustor.
TableCellSizeAdjustor is bound to its table by using the static method adjustorForTable(JTable):
... JTable jt=new JTable(); TableCellSizeAdjustor tcsa=TableCellSizeAdjustor.adjustorForTable(jt); ...After changes of the table's model or column model (with Table.setModel() or Table.setColumnModel()) the TableCellSizeAdjustor must be informed through its method rebindListeners():
... jt.setModel(newmodel); tcsa.rebindListeners(); ...Implementation notes:
MultiLineTableRenderer
, TCSA can handle maximum-sized columns, i.e. columns which
are automatically made as wide as possible with regard to the viewport width. Each column which has MLTR set
as renderer will be widened as much as possible.
Note that the current implementation of this object may be somehow inefficient or slow on larger tables.
Nested Class Summary | |
private class |
TableCellSizeAdjustor.AdjustmentInstruction
Wrapper for instructions on what to recalculate. |
private class |
TableCellSizeAdjustor.RowHeightStorage
Internal class to store special row heights. |
Field Summary | |
static int |
ADJUST_BOTH
Constant for creation method: adjust width and height of the cells. |
static int |
ADJUST_BOTH_HEIGHT_GLOBALLY
Constant for creation method: adjust widths and heights of cells, handle heights globally. |
static int |
ADJUST_HEIGHT
Constant for creation method: adjust only the height of the cells. |
static int |
ADJUST_HEIGHT_GLOBALLY
Constant for creation method: adjust height globally, i.e. all cells get height of highest one |
static int |
ADJUST_WIDTH
Constant for creation method: adjust only the width of the cells. |
private boolean |
adjustheight
Internal flag: Adjust height? |
private boolean |
adjustheightglobally
Internal flag: Adjust height globally? |
private boolean |
adjustwidth
Internal flag: Adjust width? |
private java.util.List |
ajis
List of adjustment instructions |
private int |
allmaxheight
maximum height for all rows |
private boolean |
checkeditor
Internal flag: Adjust by CellEditor size? |
private boolean |
checkheader
Change by msouthern 10-Mar-04: use column header names in column width calculations |
private int |
columncount
column count |
private int |
divident
fraction of change for maximum value to shrink before column size is recalculated completely |
private int |
divisor
fraction of change for maximum value to shrink before column size is recalculated completely |
private static int |
DONOTHING
internal constant: no new maximum values found in last computation |
private boolean |
enabled
Flag: adjustor enabled? |
private QuickIntArray |
fillingcolumns
Index of row to be resized so that the viewport is completely filled up. |
private int |
fixedwidth
Cumulated width of all automatically sized rows |
private javax.swing.table.TableCellRenderer |
headerrenderer
Compatibility code for Java 1.3 |
private javax.swing.JTable |
jt
The JTable this Adjustor is working on. |
private QuickIntArray |
lockedcolumns
Index of rows to be left alone regarding width, i.e. |
private int[] |
maxheight
maximum needed height for columns |
private int[] |
maxheightidx
row index of heighest entry in column |
private int |
maxrow
maximum handled row index so far (for optimisation of inserts at the end) |
private int[] |
maxwidth
maximum needed width for columns |
private int[] |
maxwidthidx
row index of widest entry in column |
private javax.swing.JViewport |
parentviewport
Viewport containing the table. |
private boolean |
postponeadjustment
Internal flag: Are there any postponed adjustments due to disabling? |
private boolean |
recalccompletely
flag: Everything must be calculated |
private static int |
RESIZECOMPLETELY
internal constant: recalculate column sizes with respect to all cells |
private java.util.Set |
rowheightproviders
Set with row height providers the cell size adjustor listens to |
private TableCellSizeAdjustor.RowHeightStorage |
rowheightstorage
Storage for row heights of dynamic cells |
private static java.lang.Integer |
ROWMAX
internal constant: maximum value for row height cache |
private static int |
SETBOTH
internal constant: use width and height of last computation |
private static int |
SETHEIGHT
internal constant: take maximum height of currently handled column into consideration to be new maximum height |
private static int |
SETWIDTH
internal constant: set width of currently handled column |
private javax.swing.table.TableColumn[] |
tablecolumn
the table's columns |
private javax.swing.table.TableColumnModel |
tcm
The TableColumnModel of the JTable. |
private javax.swing.table.TableModel |
tm
The TableModel of the JTable. |
private boolean |
toggleadjust
Internal flag: Do the adjustment? |
static int |
WIDTHOFFSET
Offset for computed column width. |
Constructor Summary | |
private |
TableCellSizeAdjustor(javax.swing.JTable jtx,
int mode,
boolean checkeditorx,
boolean checkheaderx)
"Real" constructor of the class. |
Method Summary | |
private int |
adjustColumnPart(int firstrow,
int lastrow,
int column)
Adjust the part of a column. |
private int |
adjustCompleteColumn(int column)
Adjusts a complete column including header |
private void |
adjustFillingColumns(boolean recalcfixedwidth)
Adjusts the columns which are defined as "filling", i.e. get the rest of the space. |
static TableCellSizeAdjustor |
adjustorForTable(javax.swing.JTable jt)
Creates new Adjustor for width and height, puts it to table, returns it. |
static TableCellSizeAdjustor |
adjustorForTable(javax.swing.JTable jt,
boolean checkeditorx)
Creates new Adjustor for width and height, puts it to table, returns it. |
static TableCellSizeAdjustor |
adjustorForTable(javax.swing.JTable jt,
int mode)
Creates new Adjustor with given adjustments, puts it to table, returns it. |
static TableCellSizeAdjustor |
adjustorForTable(javax.swing.JTable jt,
int mode,
boolean checkeditorx)
Creates new Adjustor with given adjustments, puts it to table, returns it. |
static TableCellSizeAdjustor |
adjustorForTable(javax.swing.JTable jt,
int mode,
boolean checkeditorx,
boolean chn)
Creates new Adjustor with given adjustments, puts it to table, returns it. |
private int |
collectHeights()
Collect height values for all columns. |
void |
columnAdded(javax.swing.event.TableColumnModelEvent e)
From TableColumnModelListener. |
void |
columnMarginChanged(javax.swing.event.ChangeEvent e)
From TableColumnModelListener. |
void |
columnMoved(javax.swing.event.TableColumnModelEvent e)
From TableColumnModelListener. |
void |
columnRemoved(javax.swing.event.TableColumnModelEvent e)
From TableColumnModelListener. |
void |
columnSelectionChanged(javax.swing.event.ListSelectionEvent e)
From TableColumnModelListener. |
private void |
finishSingleAdjustment(int instr,
int column)
Performs the real adjustment for one column after calculations have been done. |
private void |
handleCellRenderer(int col,
javax.swing.table.TableCellRenderer tcr)
Special handling of renderers which handle multi line rendering or give special hints to cell height |
private void |
initArrays()
Init internal storages. |
private void |
insertAJI(TableCellSizeAdjustor.AdjustmentInstruction aji)
Insert a new AdjustmentInstruction into the vector. |
boolean |
isEnabled()
Return enabling state. |
void |
preferredTableRowHeightChange(TableRowHeightEvent e)
From TableRowHeightListener: preferred height has changed somewhere. |
void |
propertyChange(java.beans.PropertyChangeEvent evt)
From PropertyChangeListener to the JTable. |
void |
reBindListeners()
Deprecated. Adjustor listens on its own for model changes and rebinds itself internally. |
private void |
rebindToColumnModel()
Rebinds the adjustor to the table's column model. |
private void |
rebindToModel()
Rebinds the adjustor to the table's model. |
private void |
runAdjustment()
Main method of adjustment performance. |
void |
setEnabled(boolean ex)
Enable and disable adjustor. |
void |
setLockedColumns(QuickIntArray qia)
Set the columns which should not be changed in width. |
void |
setReadjustFraction(int dividentx,
int divisorx)
change the "complete readjustment" fraction. |
private void |
setTableRowHeight()
|
private void |
setTableRowHeight(int row)
|
private void |
shiftIndices(int begin,
int offset)
Helper method to shift indices on insertion or deletion of rows. |
void |
stateChanged(javax.swing.event.ChangeEvent e)
From ChangeListener for the JViewport Notices the adjustor of size changes in the JViewport |
void |
tableChanged(javax.swing.event.TableModelEvent e)
From TableModelListener. |
void |
tableRowHeightChange(TableRowHeightEvent e)
From TableRowHeightListener: row height has changed. |
void |
tableRowHeightDropCache(TableRowHeightEvent e)
From TableRowHeightListener: all known row height information is dropped. |
void |
toggleAdjustment()
Inserts a call for runAdjustment() into the GUI Event Queue. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int ADJUST_WIDTH
public static final int ADJUST_HEIGHT
public static final int ADJUST_BOTH
public static final int ADJUST_HEIGHT_GLOBALLY
public static final int ADJUST_BOTH_HEIGHT_GLOBALLY
public static final int WIDTHOFFSET
private static final int RESIZECOMPLETELY
private static final int SETHEIGHT
private static final int SETWIDTH
private static final int SETBOTH
private static final int DONOTHING
private static final java.lang.Integer ROWMAX
private javax.swing.JTable jt
private javax.swing.table.TableModel tm
private javax.swing.table.TableColumnModel tcm
private boolean adjustwidth
private boolean adjustheight
private boolean adjustheightglobally
private boolean toggleadjust
private boolean checkeditor
private boolean enabled
private boolean postponeadjustment
private int[] maxwidth
private int[] maxwidthidx
private int[] maxheight
private int[] maxheightidx
private javax.swing.table.TableColumn[] tablecolumn
private int maxrow
private int allmaxheight
private int columncount
private boolean recalccompletely
private java.util.List ajis
private int divident
private int divisor
private javax.swing.table.TableCellRenderer headerrenderer
private javax.swing.JViewport parentviewport
private int fixedwidth
private QuickIntArray fillingcolumns
private QuickIntArray lockedcolumns
private TableCellSizeAdjustor.RowHeightStorage rowheightstorage
private java.util.Set rowheightproviders
private boolean checkheader
Constructor Detail |
private TableCellSizeAdjustor(javax.swing.JTable jtx, int mode, boolean checkeditorx, boolean checkheaderx)
Change by msouthern 10-Mar-04: use column header names in column width calculations
Method Detail |
public static TableCellSizeAdjustor adjustorForTable(javax.swing.JTable jt)
public static TableCellSizeAdjustor adjustorForTable(javax.swing.JTable jt, int mode)
public static TableCellSizeAdjustor adjustorForTable(javax.swing.JTable jt, boolean checkeditorx)
public static TableCellSizeAdjustor adjustorForTable(javax.swing.JTable jt, int mode, boolean checkeditorx)
public static TableCellSizeAdjustor adjustorForTable(javax.swing.JTable jt, int mode, boolean checkeditorx, boolean chn)
public void reBindListeners()
private void rebindToModel()
private void rebindToColumnModel()
public void setReadjustFraction(int dividentx, int divisorx)
The default value for the fraction is three fourth (3/4).
public void setLockedColumns(QuickIntArray qia)
qia
- Array of columns not to resize. Null to remove all non-resizing.public void tableChanged(javax.swing.event.TableModelEvent e)
tableChanged
in interface javax.swing.event.TableModelListener
public void columnAdded(javax.swing.event.TableColumnModelEvent e)
columnAdded
in interface javax.swing.event.TableColumnModelListener
public void columnRemoved(javax.swing.event.TableColumnModelEvent e)
columnRemoved
in interface javax.swing.event.TableColumnModelListener
public void columnMoved(javax.swing.event.TableColumnModelEvent e)
columnMoved
in interface javax.swing.event.TableColumnModelListener
public void columnMarginChanged(javax.swing.event.ChangeEvent e)
columnMarginChanged
in interface javax.swing.event.TableColumnModelListener
public void columnSelectionChanged(javax.swing.event.ListSelectionEvent e)
columnSelectionChanged
in interface javax.swing.event.TableColumnModelListener
public void stateChanged(javax.swing.event.ChangeEvent e)
stateChanged
in interface javax.swing.event.ChangeListener
public void propertyChange(java.beans.PropertyChangeEvent evt)
propertyChange
in interface java.beans.PropertyChangeListener
public void preferredTableRowHeightChange(TableRowHeightEvent e)
preferredTableRowHeightChange
in interface TableRowHeightListener
public void tableRowHeightChange(TableRowHeightEvent e)
tableRowHeightChange
in interface TableRowHeightListener
public void tableRowHeightDropCache(TableRowHeightEvent e)
tableRowHeightDropCache
in interface TableRowHeightListener
public void toggleAdjustment()
Note that should call this method only from within the AWT event handling thread itself and that such a call should normally not be needed anyhow as the table and its model should generate appropriate events on changes that affect the TableCellSizeAdjustor.
public void setEnabled(boolean ex)
public boolean isEnabled()
private void shiftIndices(int begin, int offset)
private void insertAJI(TableCellSizeAdjustor.AdjustmentInstruction aji)
private void runAdjustment()
private void setTableRowHeight(int row)
private void setTableRowHeight()
private void finishSingleAdjustment(int instr, int column)
private void adjustFillingColumns(boolean recalcfixedwidth)
This method is always called if any other columns have been resized or the size of the viewport has changed.
recalcfixedwidth
- indicates whether width of all other rows has to be recalculatedprivate int collectHeights()
private void handleCellRenderer(int col, javax.swing.table.TableCellRenderer tcr)
private void initArrays()
private int adjustCompleteColumn(int column)
private int adjustColumnPart(int firstrow, int lastrow, int column)
Note that this methods works on the internal fields of the object rather than passing any parameters forth and back. It does however return a handling instruction informing about any changes that have occured.
|
QJCC homepage | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |