be.ugent.caagt.swirl.lists

Class DefaultCellListCellRenderer

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

Color
getBorderSelectionColor()
Return the color which is used to draw the focus indicator.
Font
getFont()
Return the font used for the caption.
Color
getForeground()
The color which is used to display the caption.
Icon
getIcon()
Icon to be displayed.
Color
getIconBackground()
Return the background color for icons.
int
getIconTextGap()
Return the gap between text and icon
Insets
getInsets()
Return the insets of this cell.
Color
getSelectionBackground()
Return the background color for selections.
Color
getSelectionForeground()
Return the text color for selections.
String
getText()
Return the caption to be displayed.
String
getToolTipText(CellList list, Object value, int index)
If value is of type CellListCellValue, this implementation returns the tool tip text provided by that interface.
void
paintElement(Graphics2D g2, CellList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
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.
protected void
prepare(CellList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
Prepare the renderer so that the given element can be displayed.
void
setBorderSelectionColor(Color borderSelectionColor)
Set the color which is used to draw the focus indicator.
void
setFont(Font font)
Set the font used for the caption.
void
setForeground(Color foreground)
Set the color to be used for the caption.
void
setIcon(Icon icon)
Set the icon to be displayed.
void
setIconBackground(Color iconBackground)
Set the background color for icons.
void
setIconTextGap(int iconTextGap)
Set the gap between text and icon
void
setInsets(Insets insets)
Set the insets of this cell.
void
setSelectionBackground(Color selectionBackground)
Set the background color for selections.
void
setSelectionForeground(Color selectionForeground)
Set the text color for selections.
void
setText(String text)
Set the caption to be displayed.

Constructor Details

DefaultCellListCellRenderer

public DefaultCellListCellRenderer()
Default constructor.

Method Details

getBorderSelectionColor

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

getFont

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

getForeground

public Color getForeground()
The color which is used to display the caption.
Returns:
Value of property foreGround.

getIcon

public Icon getIcon()
Icon to be displayed.
Returns:
Value of property icon.

getIconBackground

public Color getIconBackground()
Return the background color for icons.
Returns:
Value of property iconBackground.

getIconTextGap

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

getInsets

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

getSelectionBackground

public Color getSelectionBackground()
Return the background color for selections.
Returns:
Value of property selectionBackground.

getSelectionForeground

public Color getSelectionForeground()
Return the text color for selections.
Returns:
Value of property selectionForeground.

getText

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

getToolTipText

public String getToolTipText(CellList list,
                             Object value,
                             int index)
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

paintElement

public void paintElement(Graphics2D g2,
                         CellList list,
                         Object value,
                         int index,
                         boolean isSelected,
                         boolean cellHasFocus)
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

prepare

protected void prepare(CellList list,
                       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:

  • If value is of type CellListCellValue, icon and text are set according to the information provided by that interface.
  • Otherwise, if value is of type Icon, that icon is used, without text caption.
  • Otherwise, no icon is displayed and the text is set to value.toString().
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.

setBorderSelectionColor

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

setFont

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

setForeground

public final void setForeground(Color foreground)
Set the color to be used for the caption.
Parameters:
foreground - New value of property foreGround.

setIcon

public void setIcon(Icon icon)
Set the icon to be displayed.
Parameters:
icon - New value of property icon.

setIconBackground

public final void setIconBackground(Color iconBackground)
Set the background color for icons.
Parameters:
iconBackground - New value of property iconBackground.

setIconTextGap

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

setInsets

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

setSelectionBackground

public final void setSelectionBackground(Color selectionBackground)
Set the background color for selections.
Parameters:
selectionBackground - New value of property selectionBackground.

setSelectionForeground

public final void setSelectionForeground(Color selectionForeground)
Set the text color for selections.
Parameters:
selectionForeground - New value of property selectionForeground.

setText

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