com.sas.swing.visuals.tableview
Class ColumnHeader

com.sas.swing.visuals.tableview.ColumnHeader
All Implemented Interfaces:
HoldInterface, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.TableColumnModelListener, javax.swing.SwingConstants
Direct Known Subclasses:
OLAPColumnHeader

public class ColumnHeader
implements HoldInterface, javax.swing.SwingConstants

See Also:
Serialized Form

Field Summary
protected  int cellsToSizeCount
           
protected  int height
           
protected  boolean heightSet
           
protected  boolean holdingEnabled
           
protected  int lastColumnSized
           
 boolean printing
           
static java.lang.String RB_KEY
           
 
Constructor Summary
ColumnHeader()
          Constructs a ColumnHeader with a default TableColumnModel.
ColumnHeader(javax.swing.table.TableColumnModel model)
          Constructs a ColumnHeader which is initialized with model as the Column model.
 
Method Summary
 int calculatePreferredWidthForColumn(int column)
          Calculates the preferred width for the given column based on it's label and data.
 int[] calculatePreferredWidthForColumns(int[] columns)
          Calculates the preferred width for the given column based on it's label and data.
 int columnAtPoint(java.awt.Point point)
          Returns the index of the column that point lies in, or -1 if it lies out of bounds.
 int columnAtPoint(java.awt.Point point, boolean accountForHolds)
          Returns the index of the column that point lies in, or -1 if it lies out of bounds.
protected  javax.swing.table.TableCellRenderer createDefaultRenderer()
          Returns a default renderer to be used when no header renderer is defined by a TableColumn.
 int getCellsToSizeCount()
          Returns the number of cells in a column to measure when calculating the width of the column.
 java.awt.Rectangle getHeaderRect(int column)
          Returns the rectangle containing the header tile at row.
 int getHeight()
          Returns the height of the column header.
 java.util.List getHeldIndices()
          Returns a list of the indices that are being held.
 java.util.List getHeldIndices(int orientation)
          Returns a list of the indices that are being held for the given orientation.
 HoldInterface getHold()
           
 int getLeadingHeldWidth()
          Returns the width in pixels of the leading held columns, or 0 if no leading columns are held.
protected  int getPreferredHeaderWidthForColumn(int column)
           
 int getTrailingHeldWidth()
          Returns the width in pixels of the trailing held columns, or 0 if no trailing columns are held.
 java.lang.String getUIClassID()
          Returns the suffix used to construct the name of the look and feel (L&F) class used to render this component.
 java.awt.Point getViewPosition()
          If the column header is placed in a
 void hold(int columnModelIndex)
          "Holds" the given index using the default orientation.
 void hold(int columnModelIndex, int orientation)
          "Holds" the given index using the orientation specified.
protected  void initializeLocalVars()
          Initializes the local variables and properties with default values.
 boolean isHeightSet()
          Returns true if the height of the header has been set, false otherwise.
 boolean isHeld(int columnModelIndex)
          Returns true if the given modelIndex is held for any orientation, false otherwise.
 boolean isHeld(int columnModelIndex, int orientation)
          Returns true if the given modelIndex is held for the given orientation, false otherwise.
 boolean isHoldingAllowed(int orientation)
          Returns true if holding for a given orientation is allowed or false otherwise.
 boolean isHoldingEnabled()
          Returns true is holding is enabled, should return false if holding is not allowed.
 void paintComponent(java.awt.Graphics g)
          Overrode this method as the clipBounds needs to be modified on the Graphics due to held columns, if nothing is currently being held, the clipBounds will be left untouched.
 java.awt.Component prepareRenderer(javax.swing.table.TableCellRenderer renderer, int column)
          Prepares the renderer by retrieving the column label and selection state of the column at column.
 void printComponent(java.awt.Graphics g)
          Overrode this method so that the clipbounds will not be modified to accomate the held column when printing as the clipbounds should already be set to the correct size.
 void release(int columnModelIndex)
          Releases the given modelIndex from being held, so it will return to its original place in the view.
 void releaseAll()
          Releases all held indices and returns them to their previous location.
 void setCellsToSizeCount(int newCount)
          Specifies the number of cells to measure when calculating the width of the column.
 void setColumnModel(javax.swing.table.TableColumnModel columnModel)
          Sets the column model for this table to columnModel and registers for listener notifications from the new column model.
 void setHeight(int newHeight)
          Sets the header's height to newHeight.
 void setHoldingEnabled(boolean enableHolding)
          Sets the state of whether holding of indices is enabled or not.
 void setTable(javax.swing.JTable table)
          Sets the table associated with this header.
 void sizeColumnsToFit()
          Sizes all the columns to the width needed based on their label and data.
 void sizeColumnToFit(int column)
          Sizes the given column to the width needed based on it's label and data.
 void updateUI()
          Notification from the
Field Detail

RB_KEY

public static final java.lang.String RB_KEY
See Also:
Constant Field Values

heightSet

protected boolean heightSet

height

protected int height

cellsToSizeCount

protected int cellsToSizeCount

lastColumnSized

protected int lastColumnSized

printing

public boolean printing

holdingEnabled

protected boolean holdingEnabled
Constructor Detail

ColumnHeader

public ColumnHeader()
Constructs a ColumnHeader with a default TableColumnModel.

See Also:
JTableHeader.createDefaultColumnModel()

ColumnHeader

public ColumnHeader(javax.swing.table.TableColumnModel model)
Constructs a ColumnHeader which is initialized with model as the Column model. If model is null this method will initialize the table header with a default TableColumnModel.

Parameters:
model - the Column model for the table
See Also:
JTableHeader.createDefaultColumnModel()
Method Detail

isHeightSet

public boolean isHeightSet()
Returns true if the height of the header has been set, false otherwise. Is used to determine if the column header should size itself based on its preferred size of its labels or not.

Returns:
true if the height has been set, false otherwise

setTable

public void setTable(javax.swing.JTable table)
Sets the table associated with this header.

Overrides:
setTable in class javax.swing.table.JTableHeader
Parameters:
table - the new table

setColumnModel

public void setColumnModel(javax.swing.table.TableColumnModel columnModel)
Sets the column model for this table to columnModel and registers for listener notifications from the new column model.

Overrides:
setColumnModel in class javax.swing.table.JTableHeader
Parameters:
columnModel - the new column model for this header
Throws:
java.lang.IllegalArgumentException - if columnModel is null
See Also:
JTableHeader.getColumnModel()

columnAtPoint

public int columnAtPoint(java.awt.Point point)
Returns the index of the column that point lies in, or -1 if it lies out of bounds.

Overrides:
columnAtPoint in class javax.swing.table.JTableHeader
Returns:
the index of the column that point lies in, or -1 if it lies out of bounds

columnAtPoint

public int columnAtPoint(java.awt.Point point,
                         boolean accountForHolds)
Returns the index of the column that point lies in, or -1 if it lies out of bounds.

Parameters:
accountForHolds - if false and the point is over a held column, this method will return the column index for the column beneath the held column. If true, this will return the index of the column the point is on, taking into account the held columns.
Returns:
the index of the column that point lies in, or -1 if it lies out of bounds

getHeaderRect

public java.awt.Rectangle getHeaderRect(int column)
Returns the rectangle containing the header tile at row. When the column parameter is out of bounds this method uses the same conventions as the TableView method getCellRect.

Overrides:
getHeaderRect in class javax.swing.table.JTableHeader
Returns:
the rectangle containing the header tile at column
See Also:
TableView.getCellRect(int, int, boolean)

getViewPosition

public java.awt.Point getViewPosition()
If the column header is placed in a JScrollPane the this will return the view position of the JViewport that contains the column header.

Returns:
a point the represents the region of the column header that is currently scrolled into view, the point will be the upper left corner of the column header that is currently in view

createDefaultRenderer

protected javax.swing.table.TableCellRenderer createDefaultRenderer()
Returns a default renderer to be used when no header renderer is defined by a TableColumn.

Overrides:
createDefaultRenderer in class javax.swing.table.JTableHeader
Parameters:
default - renderer to be used when there is no header renderer

prepareRenderer

public java.awt.Component prepareRenderer(javax.swing.table.TableCellRenderer renderer,
                                          int column)
Prepares the renderer by retrieving the column label and selection state of the column at column.

Note: Throughout the tableview package, the internal implementations always use this method to prepare renderers so that this default behavior can be safely overridden by a subclass.

Parameters:
renderer - the TableCellRenderer to prepare for the given column
column - the row index of the column to render, where 0 is the first column

initializeLocalVars

protected void initializeLocalVars()
Initializes the local variables and properties with default values. Used by the constructor methods.

Overrides:
initializeLocalVars in class javax.swing.table.JTableHeader

updateUI

public void updateUI()
Notification from the UIManager that the look and feel (L&F) has changed. Replaces the current UI object with the latest version from the UIManager.

Overrides:
updateUI in class javax.swing.table.JTableHeader
See Also:
JComponent.updateUI()

getUIClassID

public java.lang.String getUIClassID()
Returns the suffix used to construct the name of the look and feel (L&F) class used to render this component.

Overrides:
getUIClassID in class javax.swing.table.JTableHeader
Returns:
the string "ColumnHeaderUI"
See Also:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)

setHeight

public void setHeight(int newHeight)
Sets the header's height to newHeight. This also sets the heightSet property to true if the height is not equal to the current height.

Parameters:
newHeight - the new height the the column header

getHeight

public int getHeight()
Returns the height of the column header.

Overrides:
getHeight in class javax.swing.JComponent
Returns:
the height of the column header in pixels.
See Also:
setHeight(int)

setCellsToSizeCount

public void setCellsToSizeCount(int newCount)
Specifies the number of cells to measure when calculating the width of the column. A value of zero will cause only the column's label to be measured, while a negative value will measure all cells. Calculating the width of all the cells in a column could be time consuming so be careful when setting a negative value or a large value. The default value is 25.

Parameters:
newCount - the number of cells to measure to determine the width of the columns, a negative value equates to calculating the width of all cells.
See Also:
getCellsToSizeCount(), sizeColumnToFit(int), sizeColumnsToFit()

getCellsToSizeCount

public int getCellsToSizeCount()
Returns the number of cells in a column to measure when calculating the width of the column. A value of zero will cause only the column's label to be measured, while a negative value will measure all cells in the column. The default value is 25.

Returns:
the number of cells to measure the width of to determine the height of a column
See Also:
setCellsToSizeCount(int), sizeColumnToFit(int), sizeColumnsToFit()

sizeColumnToFit

public void sizeColumnToFit(int column)
Sizes the given column to the width needed based on it's label and data. A few conditions have to be met for this to actually resize the column:
  • the table must have the autoResizeMode turned off
  • resizing on the header must be allowed
  • resizing on the given column must be allowed
This method calls calculatePreferredWidthForColumn(int) to determine the width for the given column. The width the column actually receive may not be the same value that is returned from the calculatePreferredWidthForColumn(int) as a minimum or maximum size may already be set on the TableColumn.

Parameters:
column - the viewer index of the column to remeasure to fit
See Also:
getCellsToSizeCount(), setCellsToSizeCount(int), sizeColumnsToFit(), calculatePreferredWidthForColumn(int)

sizeColumnsToFit

public void sizeColumnsToFit()
Sizes all the columns to the width needed based on their label and data. A few conditions have to be met for this to actually resize the columns:
  • the table must have the autoResizeMode turned off
  • resizing on the header must be allowed
  • resizing on each table column must be allowed
This method calls calculatePreferredWidthForColumns(int[]) to determine the width for each column. The width the columns actually receive may not be the same value that is returned from the calculatePreferredWidthForColumns(int[]) as a minimum or maximum size may already be set on the TableColumn.

See Also:
getCellsToSizeCount(), setCellsToSizeCount(int), sizeColumnToFit(int), calculatePreferredWidthForColumn(int)

calculatePreferredWidthForColumns

public int[] calculatePreferredWidthForColumns(int[] columns)
Calculates the preferred width for the given column based on it's label and data. The method uses the value from getCellToSizeCount() to determine the number of cells to measure to determine the column width. This is compared with the preferred width of the column label and the larger size is returned for the column. This width may not be the best fit as the value returned from getCellToSizeCount() may be too small so that too few of cells were measured to determine the column width.

Parameters:
columns - an array of integers of the viewer indexes of columns requesting their size calculated
Returns:
an array on integers that indicate the size for each column, or an empty array if no columns were requested or allowed to be resized
See Also:
getCellsToSizeCount(), setCellsToSizeCount(int), sizeColumnsToFit(), sizeColumnToFit(int)

getPreferredHeaderWidthForColumn

protected int getPreferredHeaderWidthForColumn(int column)

calculatePreferredWidthForColumn

public int calculatePreferredWidthForColumn(int column)
Calculates the preferred width for the given column based on it's label and data. The method uses the value from getCellToSizeCount() to determine the number of cells to measure to determine the column width. This is compared with the preferred width of the column label and the larger size is returned for the column. This width may not be the best fit as the value returned from getCellToSizeCount() may be too small so that too few of cells were measured to determine the column width.

Parameters:
column - the viewer index of the column to measure
See Also:
getCellsToSizeCount(), setCellsToSizeCount(int), sizeColumnsToFit(), sizeColumnToFit(int)

paintComponent

public void paintComponent(java.awt.Graphics g)
Overrode this method as the clipBounds needs to be modified on the Graphics due to held columns, if nothing is currently being held, the clipBounds will be left untouched.

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - The Graphics context used for the painting

printComponent

public void printComponent(java.awt.Graphics g)
Overrode this method so that the clipbounds will not be modified to accomate the held column when printing as the clipbounds should already be set to the correct size.

Overrides:
printComponent in class javax.swing.JComponent
Parameters:
g - The Graphics context used for printing

getLeadingHeldWidth

public int getLeadingHeldWidth()
Returns the width in pixels of the leading held columns, or 0 if no leading columns are held.

Returns:
the width in pixels of the leading columns being held

getTrailingHeldWidth

public int getTrailingHeldWidth()
Returns the width in pixels of the trailing held columns, or 0 if no trailing columns are held.

Returns:
the width in pixels of the trailing columns being held

getHeldIndices

public java.util.List getHeldIndices()
Description copied from interface: HoldInterface
Returns a list of the indices that are being held. This list will include all the indices for all the orientations. Modifications to this list will not be reflected in the held list, this list is a duplicate.

Specified by:
getHeldIndices in interface HoldInterface
Returns:
a list of the held indices
See Also:
HoldInterface.getHeldIndices(int)

getHeldIndices

public java.util.List getHeldIndices(int orientation)
Description copied from interface: HoldInterface
Returns a list of the indices that are being held for the given orientation. Modifications to this list will be reflected in the held list as this is the true list.

Specified by:
getHeldIndices in interface HoldInterface
Parameters:
orientation - the orientation of the held indices that are being returned
Returns:
a list of the held indices
See Also:
HoldInterface.getHeldIndices()

getHold

public HoldInterface getHold()

hold

public void hold(int columnModelIndex)
Description copied from interface: HoldInterface
"Holds" the given index using the default orientation. For example, on a table, the default held column location would be on the left side and for a row would be at the top. A held index is one that has been made non-scrollable and is thus always, space permitting, displayed; i.e. it is never scrolled out of view.

The order in which the indices are held controls the order in which they are displayed.

Should do nothing if the index is already held.

Specified by:
hold in interface HoldInterface
Parameters:
columnModelIndex - the data model index of the object wishing to be held
See Also:
HoldInterface.hold(int, int), HoldInterface.release(int), HoldInterface.releaseAll()

hold

public void hold(int columnModelIndex,
                 int orientation)
Description copied from interface: HoldInterface
"Holds" the given index using the orientation specified. For example, on a table, a column could be held on the left or right and a row could be held on the top or bottom. A held index is one that has been made non-scrollable and is thus always, space permitting, displayed; i.e. it is never scrolled out of view.

The order in which the indices are held controls the order in which they are displayed.

Should do nothing if the index is already held.

Specified by:
hold in interface HoldInterface
Parameters:
columnModelIndex - the data model index of the object wishing to be held
orientation - the orientation or location the index is to be held
See Also:
HoldInterface.hold(int), HoldInterface.release(int), HoldInterface.releaseAll()

isHeld

public boolean isHeld(int columnModelIndex)
Description copied from interface: HoldInterface
Returns true if the given modelIndex is held for any orientation, false otherwise.

Specified by:
isHeld in interface HoldInterface
Parameters:
columnModelIndex - the data model index of the object queried about
Returns:
true if the index is held, false otherwise
See Also:
HoldInterface.isHeld(int, int)

isHeld

public boolean isHeld(int columnModelIndex,
                      int orientation)
Description copied from interface: HoldInterface
Returns true if the given modelIndex is held for the given orientation, false otherwise.

Specified by:
isHeld in interface HoldInterface
Parameters:
columnModelIndex - the data model index of the object queried about
orientation - the orientation or location that the index is being queried for
Returns:
true if the index is held at the given orientation, false otherwise
See Also:
HoldInterface.isHeld(int)

isHoldingAllowed

public boolean isHoldingAllowed(int orientation)
Description copied from interface: HoldInterface
Returns true if holding for a given orientation is allowed or false otherwise. Holding must be enabled for this to return true.

Specified by:
isHoldingAllowed in interface HoldInterface
Parameters:
orientation - the orientation being queried about
Returns:
true is holding is enabled an dallowed for a given orientation, false otherwise

release

public void release(int columnModelIndex)
Description copied from interface: HoldInterface
Releases the given modelIndex from being held, so it will return to its original place in the view. If the modelIndex is not held, nothing is done.

Specified by:
release in interface HoldInterface
Parameters:
columnModelIndex - the index currently held that is wishing to be released
See Also:
HoldInterface.hold(int), HoldInterface.hold(int, int), HoldInterface.releaseAll()

releaseAll

public void releaseAll()
Description copied from interface: HoldInterface
Releases all held indices and returns them to their previous location.

Specified by:
releaseAll in interface HoldInterface
See Also:
HoldInterface.hold(int), HoldInterface.hold(int, int), HoldInterface.release(int)

isHoldingEnabled

public boolean isHoldingEnabled()
Returns true is holding is enabled, should return false if holding is not allowed.

Specified by:
isHoldingEnabled in interface HoldInterface
Returns:
true is holding of indices is enabled, false otherwise
See Also:
setHoldingEnabled(boolean)

setHoldingEnabled

public void setHoldingEnabled(boolean enableHolding)
Sets the state of whether holding of indices is enabled or not.

Specified by:
setHoldingEnabled in interface HoldInterface
Parameters:
enableHolding - true to enable holding, false otherwise
See Also:
isHoldingEnabled()



Copyright © 2009 SAS Institute Inc. All Rights Reserved.