|
Copyright © 2005 Scientific Applications. All Rights Reserved. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sciapp.table.TableAssistant
public class TableAssistant
TableAssistant is a class that provides additional functions to a JTable. More specifically:
1) It automatically resizes the column of a table to the greatest preferred width of all cells under that column, when the column is double-clicked on its border.
2) Provides a popup through which the columns of the table can be dynamically added/removed. The popup is shown upon right-clicking on the table header.
Field Summary | |
---|---|
protected boolean |
allowEditColumn
flag to indicate whether users are able to rename columns in the column dialog |
protected boolean |
allowReorder
flag to indicate whether users are able to reorder columns in the column dialog |
protected int |
columnMargin
the pixels to add to the columns that are resized |
protected int |
columnPopupOrder
defines the ordering of column names in the column popup |
static int |
CONTENT_RESIZE
integer indicating that the column will be resized to its contents should the user double-click on its border |
static int |
DEFAULT_COLUMN_MARGIN
the default column margin |
protected Cursor |
defaultHeaderCursor
the header's default cursor |
protected boolean |
groupingEnabled
flag to indicate whether users are able to group/ungroup columns in the column dialog |
static int |
HEADER_RESIZE
integer indicating that the column will be resized to its header contents should the user double-click on its border |
static int |
IF_LARGER_RESIZE
integer indicating that the column will be resized only if the calculated width is larger than the current one |
protected int |
maxColumns
the maximum number of columns that the column popup is going to display. |
static int |
MODEL_ORDER
defines a column ordering, according to the position of the columns as they appear in the table's data model |
static int |
NO_RESIZE
integer indicating that nothing will happen should the user double-click on a column border |
static int |
PUSH_INVISIBLE_TO_END
a modifier used by the column popup, in which non-visible columns are pushed towards the end of the popup |
protected int |
resizeMode
the resize mode |
protected boolean |
showMore
flag to indicate whether a menuitem is to be added to the column popup, that provides more column options. |
static int |
UNLIMITED_COLUMNS
integer that specifies that an unlimited number of columns will be added to the column popup. |
static int |
VIEW_ORDER
defines a column ordering, according to the position of the columns as they appear in the table's column model (the view) |
Constructor Summary | |
---|---|
TableAssistant(JTable table)
Constructs a TableAssistant having table as the JTable on which this
object acts. |
Method Summary | |
---|---|
protected int |
calcContentWidth(int column)
Calculates the preferred width for a column, based on the its cell contents. |
protected int |
calcHeaderWidth(int column)
Calculates the preferred width for a column, based on the content of its header. |
protected JPopupMenu |
createPopup()
Returns a new instance of the column popup menu. |
void |
deselect(int modelIndex)
Unchecks the column with model index modelIndex from the column popup. |
boolean |
getAllowEditColumn()
Determines whether users are able to rename columns in the column dialog. |
boolean |
getAllowReorder()
Determines whether users are able to reorder columns in the column dialog. |
int |
getColumnMargin()
Determines the pixels to increase the width of a column by, when it is being automatically resized with the resizeColumnToHeader(int) or
resizeColumnToContents(int) methods. |
JPopupMenu |
getColumnPopup()
Returns the popup menu displayed. |
int |
getColumnPopupOrder()
Retrieves the mode according to which, columns in the column popup will be ordered. |
int[] |
getColumnPositions(TableColumn[] columns,
boolean[] isVisible)
Retrieves the position in the column popup for columns . |
Cursor |
getDefaultHeaderCursor()
Retrieves the default header's cursor. |
boolean |
getGroupingEnabled()
Determines whether users are able to group/ungroup columns in the column dialog. |
int |
getMaxColumns()
Returns the maximum number of columns that the column popup is going to display. |
JDialog |
getMoreDialog()
Returns an instance of the 'More...' dialog. |
int |
getResizeMode()
Determines the current resize mode, when a user double clicks on a column border. |
boolean |
getShowMore()
Returns a flag that is true if a menuitem (more) is to be added to the column popup, that provides more column options. |
boolean |
getShowPopup()
Returns true if the column popup is to be shown. |
JTable |
getTable()
Returns the table that is associated with the assistant. |
void |
refreshColumns()
Recreates the column selection popup and dialog with values from the column model. |
void |
refreshPopup()
Reinitializes the popup with values from the column model. |
void |
register(TableColumnModel columnModel)
The component registers itself to the listener list of columnModel . |
void |
resizeColumn(int column)
Resizes the given column according to the current resize mode. |
void |
resizeColumn(int column,
int resizeMode)
Resizes the given column according to the resize mode passed as argument to the method. |
void |
resizeColumns()
Resizes all columns according to the current resize mode. |
void |
resizeColumns(int resizeMode)
Resizes all columns according to the resize mode passed as argument to the method. |
void |
resizeColumnsToContents()
Resizes all columns to their contents. |
void |
resizeColumnsToHeader()
Resizes all columns to the content of their header. |
void |
resizeColumnToContents(int column)
Resizes the given column to its contents. |
void |
resizeColumnToHeader(int column)
Resizes the given column to the content of its header. |
void |
select(int modelIndex)
Checks the column with model index modelIndex from the column popup. |
void |
setAllowEditColumn(boolean allowEditColumn)
Sets a flag that is true if users are able to rename columns in the column dialog. |
void |
setAllowReorder(boolean allowReorder)
Sets a flag that is true if users are able to reorder columns in the column dialog. |
void |
setColumnMargin(int columnMargin)
Assigns the pixels to increase the width of a column by, when it is being automatically resized with the resizeColumnToHeader(int) or
resizeColumnToContents(int) methods. |
void |
setColumnPopupOrder(int columnPopupOrder)
Assigns the mode according to which, columns in the column popup will be ordered. |
void |
setColumnWidth(int column,
int width)
Sets a new column width for the specified column. |
void |
setDefaultHeaderCursor(Cursor cursor)
Assigns the default headers' cursor. |
void |
setGroupingEnabled(boolean groupingEnabled)
Sets a flag that is true if users are able to group/ungroup columns in the column dialog. |
void |
setHeader(JTableHeader newTableHeader)
Associates newTableHeader with this instance of TableAssistant. |
void |
setMaxColumns(int maxColumns)
Sets the maximum number of columns that the column popup is going to display. |
void |
setResizeMode(int resizeMode)
Assigns the resize mode, when a user double clicks on a column border. |
void |
setShowMore(boolean showMore)
Sets a flag that is true if a menuitem (more) is to be added to the column popup, that provides more column options. |
void |
setShowPopup(boolean showPopup)
Sets a flag that is true if the column popup is to be shown. |
void |
setTable(JTable newTable)
Assigns a new table to the assistant. |
void |
showColumnDialog()
Makes the column dialog visible. |
void |
unregister(TableColumnModel columnModel)
The component unregisters itself from the listener list of columnModel . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected int columnPopupOrder
public static final int MODEL_ORDER
public static final int VIEW_ORDER
public static final int PUSH_INVISIBLE_TO_END
protected boolean allowReorder
protected boolean groupingEnabled
protected boolean allowEditColumn
public static final int NO_RESIZE
public static final int CONTENT_RESIZE
public static final int HEADER_RESIZE
public static final int IF_LARGER_RESIZE
public static final int DEFAULT_COLUMN_MARGIN
protected int columnMargin
protected int resizeMode
protected boolean showMore
protected Cursor defaultHeaderCursor
public static final int UNLIMITED_COLUMNS
protected int maxColumns
Constructor Detail |
---|
public TableAssistant(JTable table)
table
as the JTable on which this
object acts.
table
- the tableMethod Detail |
---|
protected int calcContentWidth(int column)
column
- the column for which the width is calculated
protected int calcHeaderWidth(int column)
column
- the column for which the width is calculated
protected JPopupMenu createPopup()
public void deselect(int modelIndex)
modelIndex
from the column popup.
modelIndex
- the model index of the table's columnpublic boolean getAllowEditColumn()
public boolean getAllowReorder()
public int getColumnMargin()
resizeColumnToHeader(int)
or
resizeColumnToContents(int)
methods.
public JPopupMenu getColumnPopup()
public int getColumnPopupOrder()
public int[] getColumnPositions(TableColumn[] columns, boolean[] isVisible)
columns
.
The isVisible
array contains booleans, according to whether
columns are visible or not.
An integer value of -1 implies that the column should not be added to the
column popup at all.
columns
- an array containing the available columns to show in the popupisVisible
- denoting whether or not a column is visible
public Cursor getDefaultHeaderCursor()
public boolean getGroupingEnabled()
public int getMaxColumns()
public JDialog getMoreDialog()
public int getResizeMode()
The mode may be:
NO_RESIZE: nothing will happen
CONTENT_RESIZE: column will be resized to its contents
HEADER_RESIZE: column will be resized to its header contents
CONTENT_RESIZE | HEADER_RESIZE: column will be resized to the maximum width
of its cell AND header contents
If the mask IF_LARGER_RESIZE is used, then the column will be resized only
if the calculated width is larger than the current one
The default mode is CONTENT_RESIZE.
public boolean getShowMore()
public boolean getShowPopup()
public JTable getTable()
public void refreshColumns()
public void refreshPopup()
public void register(TableColumnModel columnModel)
columnModel
.
columnModel
- the TableColumnModelpublic void resizeColumn(int column)
column
- the table column to resizepublic void resizeColumn(int column, int resizeMode)
column
- the table column to resizeresizeMode
- the resize modepublic void resizeColumns()
public void resizeColumns(int resizeMode)
resizeMode
- the resize modepublic void resizeColumnsToContents()
public void resizeColumnsToHeader()
public void resizeColumnToContents(int column)
column
- the table column to resizepublic void resizeColumnToHeader(int column)
column
- the table column to resizepublic void select(int modelIndex)
modelIndex
from the column popup.
modelIndex
- the model index of the table's columnpublic void setAllowEditColumn(boolean allowEditColumn)
allowEditColumn
- true if column renaming is enabled, false otherwisepublic void setAllowReorder(boolean allowReorder)
allowReorder
- true if column reordering is enabled, false otherwisepublic void setColumnMargin(int columnMargin)
resizeColumnToHeader(int)
or
resizeColumnToContents(int)
methods.
columnMargin
- the number of pixelspublic void setColumnPopupOrder(int columnPopupOrder)
The popup order mode is taken into account solely by the getColumnPositions
method, which returns the column positions in the popup.
Examples for setting the popup order:
setColumnPopupOrder(VIEW_ORDER);
setColumnPopupOrder(MODEL_ORDER | PUSH_INVISIBLE_TO_END);
columnPopupOrder
- the column popup's order modepublic void setColumnWidth(int column, int width)
column
- the table column to resizewidth
- the new column width to assign to the columnpublic void setDefaultHeaderCursor(Cursor cursor)
cursor
- the default header cursor to assignpublic void setGroupingEnabled(boolean groupingEnabled)
groupingEnabled
- true if column grouping is enabled, false otherwisepublic void setHeader(JTableHeader newTableHeader)
newTableHeader
with this instance of TableAssistant.
newTableHeader
- the JTableHeader to associate with this TableAssistant.public void setMaxColumns(int maxColumns)
maxColumns
is UNLIMITED_COLUMNS
, an unlimited number
of columns will be added to the column popup.
maxColumns
- the maximum number of columns that the column popup is going to display.public void setResizeMode(int resizeMode)
The mode may be:
NO_RESIZE: nothing will happen
CONTENT_RESIZE: column will be resized to its contents
HEADER_RESIZE: column will be resized to its header contents
CONTENT_RESIZE | HEADER_RESIZE: column will be resized to the maximum width
of its cell AND header contents
If the mask IF_LARGER_RESIZE is used, then the column will be resized only
if the calculated width is larger than the current one
The default mode is CONTENT_RESIZE.
resizeMode
- an integer that denotes the resize modepublic void setShowMore(boolean showMore)
showMore
- true if the more menuitem is to be shown, false otherwise.public void setShowPopup(boolean showPopup)
showPopup
- the show popup value to setpublic void setTable(JTable newTable)
newTable
- the table to assignpublic void showColumnDialog()
public void unregister(TableColumnModel columnModel)
columnModel
.
columnModel
- the TableColumnModel
|
Copyright © 2005 Scientific Applications. All Rights Reserved. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |