be.ugent.caagt.swirl.lists
Class DefaultCellListCellRenderer

java.lang.Object
  extended by be.ugent.caagt.swirl.lists.DefaultCellListCellRenderer
All Implemented Interfaces:
CellListCellRenderer

public class DefaultCellListCellRenderer
extends java.lang.Object
implements CellListCellRenderer

Default implementation of CellListCellRenderer. Renders a cell to look like a horizontally centered label, with caption below the icon, except that the selection background and focus indicator are restricted to the text part of the label.

Works best with list whose elements implement the interface CellListCellValue.

Extension classes override method prepare to determine what text and what icon should be displayed.


Constructor Summary
DefaultCellListCellRenderer()
          Default constructor.
 
Method Summary
 java.awt.Color getBorderSelectionColor()
          Return the color which is used to draw the focus indicator.
 java.awt.Font getFont()
          Return the font used for the caption.
 java.awt.Color getForeground()
          The color which is used to display the caption.
 javax.swing.Icon getIcon()
          Icon to be displayed.
 java.awt.Color getIconBackground()
          Return the background color for icons.
 int getIconTextGap()
          Return the gap between text and icon
 java.awt.Insets getInsets()
          Return the insets of this cell.
 java.awt.Color getSelectionBackground()
          Return the background color for selections.
 java.awt.Color getSelectionForeground()
          Return the text color for selections.
 java.lang.String getText()
          Return the caption to be displayed.
 java.lang.String getToolTipText(CellList list, java.lang.Object value, int index)
          Return the tool tip text for the given element.
 void paintElement(java.awt.Graphics2D g2, CellList list, java.lang.Object value, int index, boolean isSelected, boolean cellHasFocus)
          Paint the given element at the 0,0-position on the given graphics context.
protected  void prepare(CellList list, java.lang.Object value, int index, boolean isSelected, boolean cellHasFocus)
          Prepare the renderer so that the given element can be displayed.
 void setBorderSelectionColor(java.awt.Color borderSelectionColor)
          Set the color which is used to draw the focus indicator.
 void setFont(java.awt.Font font)
          Set the font used for the caption.
 void setForeground(java.awt.Color foreground)
          Set the color to be used for the caption.
 void setIcon(javax.swing.Icon icon)
          Set the icon to be displayed.
 void setIconBackground(java.awt.Color iconBackground)
          Set the background color for icons.
 void setIconTextGap(int iconTextGap)
          Set the gap between text and icon
 void setInsets(java.awt.Insets insets)
          Set the insets of this cell.
 void setSelectionBackground(java.awt.Color selectionBackground)
          Set the background color for selections.
 void setSelectionForeground(java.awt.Color selectionForeground)
          Set the text color for selections.
 void setText(java.lang.String text)
          Set the caption to be displayed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultCellListCellRenderer

public DefaultCellListCellRenderer()
Default constructor.

Method Detail

getToolTipText

public java.lang.String getToolTipText(CellList list,
                                       java.lang.Object value,
                                       int index)
Return the tool tip text for the given element.

If value is of type CellListCellValue, this implementation returns the tool tip text provided by that interface. Otherwise it returns null.

Specified by:
getToolTipText in interface CellListCellRenderer
Parameters:
list - The cell list to which the element belongs
value - The corresponding value returned from the model
index - The index of the cell in the list
Returns:
the tool tip text for the cell, or null if no tool tip needs to be dipslayed

getText

public java.lang.String getText()
Return the caption to be displayed.


setText

public void setText(java.lang.String text)
Set the caption to be displayed.


getForeground

public java.awt.Color getForeground()
The color which is used to display the caption.

Returns:
Value of property foreGround.

setForeground

public final void setForeground(java.awt.Color foreground)
Set the color to be used for the caption.

Parameters:
foreground - New value of property foreGround.

getFont

public java.awt.Font getFont()
Return the font used for the caption.


setFont

public final void setFont(java.awt.Font font)
Set the font used for the caption.


getIcon

public javax.swing.Icon getIcon()
Icon to be displayed.

Returns:
Value of property icon.

setIcon

public void setIcon(javax.swing.Icon icon)
Set the icon to be displayed.

Parameters:
icon - New value of property icon.

getIconTextGap

public int getIconTextGap()
Return the gap between text and icon


setIconTextGap

public void setIconTextGap(int iconTextGap)
Set the gap between text and icon


getInsets

public java.awt.Insets getInsets()
Return the insets of this cell.


setInsets

public final void setInsets(java.awt.Insets insets)
Set the insets of this cell.


getSelectionForeground

public java.awt.Color getSelectionForeground()
Return the text color for selections.

Returns:
Value of property selectionForeground.

setSelectionForeground

public final void setSelectionForeground(java.awt.Color selectionForeground)
Set the text color for selections.

Parameters:
selectionForeground - New value of property selectionForeground.

getSelectionBackground

public java.awt.Color getSelectionBackground()
Return the background color for selections.

Returns:
Value of property selectionBackground.

setSelectionBackground

public final void setSelectionBackground(java.awt.Color selectionBackground)
Set the background color for selections.

Parameters:
selectionBackground - New value of property selectionBackground.

getIconBackground

public java.awt.Color getIconBackground()
Return the background color for icons.

Returns:
Value of property iconBackground.

setIconBackground

public final void setIconBackground(java.awt.Color iconBackground)
Set the background color for icons.

Parameters:
iconBackground - New value of property iconBackground.

getBorderSelectionColor

public java.awt.Color getBorderSelectionColor()
Return the color which is used to draw the focus indicator.


setBorderSelectionColor

public final void setBorderSelectionColor(java.awt.Color borderSelectionColor)
Set the color which is used to draw the focus indicator.


prepare

protected void prepare(CellList list,
                       java.lang.Object value,
                       int index,
                       boolean isSelected,
                       boolean cellHasFocus)
Prepare the renderer so that the given element can be displayed. Extensions of this class should override this method (rather than paintElement) to set the correct text and icon.

This implementation distinguishes three cases:

Parameters:
list - The cell list to which the element belongs
value - The corresponding value returned from the model
index - The index of the cell in the list
isSelected - True if the specified cell was selected.
cellHasFocus - True if the specified cell has the focus.

paintElement

public void paintElement(java.awt.Graphics2D g2,
                         CellList list,
                         java.lang.Object value,
                         int index,
                         boolean isSelected,
                         boolean cellHasFocus)
Paint the given element at the 0,0-position on the given graphics context. The element is painted to look like a horizontally centered label, with caption below the icon, except that the selection background and focus indicator are restricted to the text part of the label.

This implementation first calls prepare to initialize the text and icon property from the value parameter. Extensions of this class are advised to override prepare instead of this method.

Specified by:
paintElement in interface CellListCellRenderer
Parameters:
g2 - Graphics context onto which the cell must be painted
list - The cell list to which the element belongs
value - The corresponding value returned from the model
index - The index of the cell in the list
isSelected - True if the specified cell was selected.
cellHasFocus - True if the specified cell has the focus.