org.jcreme.swing.table.colormodel
Class DefaultTableColorModel

java.lang.Object
  extended byorg.jcreme.swing.table.colormodel.DefaultTableColorModel
All Implemented Interfaces:
TableColorModel
Direct Known Subclasses:
BaseCyclingColorModel, ChangeHighlightingColorModel, LayeredColorModel, LineTitlesColorModel

public class DefaultTableColorModel
extends java.lang.Object
implements TableColorModel

This a basic implementation of the TableColorModel interface. The only color effect of this class is to ensure a minimum "distance" between the foreground and background colors. Other implementations may derive from this class.

Version:
$Revision: 1.3 $
Author:
$Author: dbregeon $

Field Summary
protected static int MINIMUM_COLOR_DISTANCE
          This is the minimum "distance" between the background and the foreground colors.
 
Constructor Summary
DefaultTableColorModel()
           
 
Method Summary
 void addTableColorModelListener(TableColorModelListener l)
          Enables to add listeners for the modifications of the color scheme.
protected  java.awt.Color ensureMinimumDistance(java.awt.Color fgColor, java.awt.Color bgColor)
          This method enables to generate a Color that may replace the parameter fgColor as a foreground Color.
protected  void fireTableColorModelChanged(TableColorModelEvent e)
          Fires a TableColorModelEvent telling registered listeners that the color scheme has changed.
 java.awt.Color getBackgroundColor(int row, int column, boolean selected, java.awt.Component renderer)
          Gives access to the background color of a cell.
protected  int getDistance(java.awt.Color colorOne, java.awt.Color colorTwo)
          This method returns the "distance" between two colors.
 java.awt.Color getForegroundColor(int row, int column, boolean selected, java.awt.Component renderer)
          Gives access to the foreground color of a cell.
 java.util.EventListener[] getListeners(java.lang.Class listenerType)
          Gets the list of the listeners registered for the modifications of the color scheme.
 javax.swing.table.TableModel getTableModel()
          Gives access to the TableModel colored by this TableColorModel.
protected  java.awt.Color mixColors(java.awt.Color top, java.awt.Color bottom)
          This is a convenience method that enables to mix two colors.
 void removeTableColorModelListener(TableColorModelListener l)
          Unregisters the listener for the modifications of the color model.
 void setTableModel(javax.swing.table.TableModel model)
          Sets the model that will be colored by this TableColorModel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MINIMUM_COLOR_DISTANCE

protected static final int MINIMUM_COLOR_DISTANCE
This is the minimum "distance" between the background and the foreground colors. This distance ensures that the foreground text is always visible.

See Also:
Constant Field Values
Constructor Detail

DefaultTableColorModel

public DefaultTableColorModel()
Method Detail

getListeners

public java.util.EventListener[] getListeners(java.lang.Class listenerType)
Gets the list of the listeners registered for the modifications of the color scheme.

Specified by:
getListeners in interface TableColorModel
Parameters:
listenerType - The class of listeners to retrieve.
Returns:
The list of all listeners of the given type registered in the list.

getBackgroundColor

public java.awt.Color getBackgroundColor(int row,
                                         int column,
                                         boolean selected,
                                         java.awt.Component renderer)
Gives access to the background color of a cell.

Specified by:
getBackgroundColor in interface TableColorModel
Parameters:
row - the cell's row.
column - the cell's column.
selected - whether the cell is currently selected or not.
renderer - the renderer used to display the cell.
Returns:
the background color for the cell.

fireTableColorModelChanged

protected void fireTableColorModelChanged(TableColorModelEvent e)
Fires a TableColorModelEvent telling registered listeners that the color scheme has changed.

Parameters:
e - The event describing the changes.

addTableColorModelListener

public void addTableColorModelListener(TableColorModelListener l)
Enables to add listeners for the modifications of the color scheme.

Specified by:
addTableColorModelListener in interface TableColorModel
Parameters:
l - the listener to add.

removeTableColorModelListener

public void removeTableColorModelListener(TableColorModelListener l)
Unregisters the listener for the modifications of the color model.

Specified by:
removeTableColorModelListener in interface TableColorModel
Parameters:
l - the listener to remove.

getForegroundColor

public java.awt.Color getForegroundColor(int row,
                                         int column,
                                         boolean selected,
                                         java.awt.Component renderer)
Gives access to the foreground color of a cell.

Specified by:
getForegroundColor in interface TableColorModel
Parameters:
row - the cell's row.
column - the cell's column.
selected - whether the cell is currently selected or not.
renderer - the renderer used to display the cell.
Returns:
the foreground color for the cell.

ensureMinimumDistance

protected java.awt.Color ensureMinimumDistance(java.awt.Color fgColor,
                                               java.awt.Color bgColor)
This method enables to generate a Color that may replace the parameter fgColor as a foreground Color. When the "distance" between the fgColor and the bgColor is lesser than MINIMUM_COLOR_DISTANCE, the returned color's components are: red = Math.max(0, Math.min(255, bgRed + MINIMUM_COLOR_DISTANCE * (fgRed - bgRed) / d)); green = Math.max(0, Math.min(255, bgGreen + MINIMUM_COLOR_DISTANCE * (fgGreen - bgGreen) / d)); blue = Math.max(0, Math.min(255, bgBlue + MINIMUM_COLOR_DISTANCE * (fgBlue - bgBlue) / d));

Parameters:
fgColor - the original foreground color.
bgColor - the original background color.
Returns:
the fgColor parameter or the aforementioned replacement color.

getDistance

protected int getDistance(java.awt.Color colorOne,
                          java.awt.Color colorTwo)
This method returns the "distance" between two colors. The distance is the usual euclidian distance in a three dimension space.

Parameters:
colorOne - the first color.
colorTwo - the second color.
Returns:
the euclidian distance between colorOne and colorTwo.

mixColors

protected java.awt.Color mixColors(java.awt.Color top,
                                   java.awt.Color bottom)
This is a convenience method that enables to mix two colors. It may be used when a TableColorModel implementation needs to mix two layers of color.

Parameters:
top - the color that is on the top layer.
bottom - the color that is on the bottom layer.
Returns:
a mixed color between the two parameter colors. The color has the following components: red = 255 - Math.min(255, (6 * (255 - bottom.getRed()) + 4 * (255 - top.getRed())) / 10) green = 255 - Math.min(255, (6 * (255 - bottom.getGreen()) + 4 * (255 - top.getGreen())) / 10) blue = 255 - Math.min(255, (6 * (255 - bottom.getBlue()) + 4 * (255 - top.getBlue())) / 10)

getTableModel

public javax.swing.table.TableModel getTableModel()
Description copied from interface: TableColorModel
Gives access to the TableModel colored by this TableColorModel.

Specified by:
getTableModel in interface TableColorModel
Returns:
the data colored by this model.
See Also:
TableColorModel.getTableModel()

setTableModel

public void setTableModel(javax.swing.table.TableModel model)
Description copied from interface: TableColorModel
Sets the model that will be colored by this TableColorModel.

Specified by:
setTableModel in interface TableColorModel
Parameters:
model - the data to be colored by this model.
See Also:
TableColorModel.setTableModel(javax.swing.table.TableModel)


Copyright 2006 null. All Rights Reserved.