de.kupzog.ktable.renderers
Class DefaultCellRenderer

java.lang.Object
  extended by de.kupzog.ktable.renderers.DefaultCellRenderer
All Implemented Interfaces:
KTableCellRenderer
Direct Known Subclasses:
BarDiagramCellRenderer, CheckableCellRenderer, FixedCellRenderer, TextCellRenderer

public class DefaultCellRenderer
extends java.lang.Object
implements KTableCellRenderer

Class that provides additional facilities commonly used when writing custom renderers.

Author:
Lorenz Maierhofer

Field Summary
 org.eclipse.swt.graphics.Color COLOR_BACKGROUND
           
static org.eclipse.swt.graphics.Color COLOR_BGFOCUS
           
static org.eclipse.swt.graphics.Color COLOR_BGROWFOCUS
           
static org.eclipse.swt.graphics.Color COLOR_COMMENTSIGN
           
static org.eclipse.swt.graphics.Color COLOR_FGROWFOCUS
           
static org.eclipse.swt.graphics.Color COLOR_FIXEDHIGHLIGHT
           
static org.eclipse.swt.graphics.Color COLOR_LINE_DARKGRAY
           
static org.eclipse.swt.graphics.Color COLOR_LINE_LIGHTGRAY
           
 org.eclipse.swt.graphics.Color COLOR_TEXT
           
static int INDICATION_CLICKED
          Make the header column show a button-pressed behavior when clicked.
static int INDICATION_COMMENT
          Draws a little triangle in the upper right corner of the cell as an indication that additional information is available.
static int INDICATION_FOCUS
          Color fixed cells with focus in a different color.
static int INDICATION_FOCUS_ROW
          Color fixed cells with focus in a different color.
static int INDICATION_GRADIENT
          Draws a gradient in the figure representing the cell content.
static int INDICATION_SORT
          Shows a sort indicator in the fixed cell if sorting is active for the column.
static int STYLE_FLAT
          Makes a flat looking cell.
static int STYLE_PUSH
          Makes a button-like cell.
 
Fields inherited from interface de.kupzog.ktable.KTableCellRenderer
defaultRenderer
 
Constructor Summary
DefaultCellRenderer(int style)
          The constructor that sets the style bits given.
 
Method Summary
 void drawCell(org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle rect, int col, int row, java.lang.Object content, boolean focus, boolean fixed, boolean clicked, KTableModel model)
          A default implementation that paints cells in a way that is more or less Excel-like.
 int getAlignment()
           
 org.eclipse.swt.graphics.Color getBackground()
           
 org.eclipse.swt.graphics.Font getFont()
           
 org.eclipse.swt.graphics.Color getForeground()
           
 int getOptimalWidth(org.eclipse.swt.graphics.GC gc, int col, int row, java.lang.Object content, boolean fixed, KTableModel model)
          Returns the optimal width of the given cell (used by column resizing)
 int getStyle()
           
 void setAlignment(int style)
          Sets the alignment of the cell content.
 void setBackground(org.eclipse.swt.graphics.Color bgcolor)
          Set the background color that should be used when painting the cell background.
 void setDefaultBackground(org.eclipse.swt.graphics.Color bgcolor)
          Changes the default background color that will be used when no background color is set via setBackground().
 void setDefaultForeground(org.eclipse.swt.graphics.Color fgcolor)
          Changes the default foreground color that will be used when no other foreground color is set.
 void setFont(org.eclipse.swt.graphics.Font font)
          Sets the font the renderer will use for drawing its content.
 void setForeground(org.eclipse.swt.graphics.Color fgcolor)
          Set the foreground color used to paint text et al.
 void setStyle(int style)
          Overwrites the style bits with the given one.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COLOR_TEXT

public org.eclipse.swt.graphics.Color COLOR_TEXT

COLOR_BACKGROUND

public org.eclipse.swt.graphics.Color COLOR_BACKGROUND

COLOR_LINE_LIGHTGRAY

public static final org.eclipse.swt.graphics.Color COLOR_LINE_LIGHTGRAY

COLOR_LINE_DARKGRAY

public static final org.eclipse.swt.graphics.Color COLOR_LINE_DARKGRAY

COLOR_BGFOCUS

public static final org.eclipse.swt.graphics.Color COLOR_BGFOCUS

COLOR_COMMENTSIGN

public static final org.eclipse.swt.graphics.Color COLOR_COMMENTSIGN

COLOR_FIXEDHIGHLIGHT

public static final org.eclipse.swt.graphics.Color COLOR_FIXEDHIGHLIGHT

COLOR_BGROWFOCUS

public static final org.eclipse.swt.graphics.Color COLOR_BGROWFOCUS

COLOR_FGROWFOCUS

public static final org.eclipse.swt.graphics.Color COLOR_FGROWFOCUS

STYLE_PUSH

public static final int STYLE_PUSH
Makes a button-like cell.

Used in:
- FixedCellRenderer

See Also:
Constant Field Values

STYLE_FLAT

public static final int STYLE_FLAT
Makes a flat looking cell.

Used in:
- FixedCellRenderer

See Also:
Constant Field Values

INDICATION_SORT

public static final int INDICATION_SORT
Shows a sort indicator in the fixed cell if sorting is active for the column.

Has only an effect if the tablemodel is an instanceof KTableSortModel.

Used in:
- FixedCellRenderer

See Also:
Constant Field Values

INDICATION_FOCUS

public static final int INDICATION_FOCUS
Color fixed cells with focus in a different color.

Has only an effect on fixed cells when KTable.setHighlightSelectionInHeader(true) was set.

Used in:
- CheckableCellRenderer
- FixedCellRenderer
- TextCellRenderer

See Also:
Constant Field Values

INDICATION_FOCUS_ROW

public static final int INDICATION_FOCUS_ROW
Color fixed cells with focus in a different color.

Has only an effect when KTable.setHighlightSelectionInHeader(true) was set.

Used in:
- CheckableCellRenderer
- FixedCellRenderer
- TextCellRenderer

See Also:
Constant Field Values

INDICATION_CLICKED

public static final int INDICATION_CLICKED
Make the header column show a button-pressed behavior when clicked.

Used in:
- FixedCellRenderer (Has only an effect when STYLE_PUSH is set.)
- CheckableCellRenderer

See Also:
Constant Field Values

INDICATION_COMMENT

public static final int INDICATION_COMMENT
Draws a little triangle in the upper right corner of the cell as an indication that additional information is available.

Used in:
- CheckableCellRenderer
- TextCellRenderer

See Also:
Constant Field Values

INDICATION_GRADIENT

public static final int INDICATION_GRADIENT
Draws a gradient in the figure representing the cell content. Used by:
- BarDiagramCellRenderer

See Also:
Constant Field Values
Constructor Detail

DefaultCellRenderer

public DefaultCellRenderer(int style)
The constructor that sets the style bits given. The default cellrenderer ignores all style bits. See subclasses for their honored style bits.

Method Detail

setStyle

public void setStyle(int style)
Overwrites the style bits with the given one.

Parameters:
style - The styles to AND with the current style bits.
See Also:
for accessing the style bits.

getStyle

public int getStyle()
Returns:
Returns the currently set style.

getOptimalWidth

public int getOptimalWidth(org.eclipse.swt.graphics.GC gc,
                           int col,
                           int row,
                           java.lang.Object content,
                           boolean fixed,
                           KTableModel model)
Description copied from interface: KTableCellRenderer
Returns the optimal width of the given cell (used by column resizing)

Specified by:
getOptimalWidth in interface KTableCellRenderer
Returns:
int

drawCell

public void drawCell(org.eclipse.swt.graphics.GC gc,
                     org.eclipse.swt.graphics.Rectangle rect,
                     int col,
                     int row,
                     java.lang.Object content,
                     boolean focus,
                     boolean fixed,
                     boolean clicked,
                     KTableModel model)
A default implementation that paints cells in a way that is more or less Excel-like. Only the cell with focus looks very different.

Specified by:
drawCell in interface KTableCellRenderer
Parameters:
gc - The gc to draw on
rect - The coordinates and size of the cell (add 1 to width and hight to include the borders)
col - The column
row - The row
content - The content of the cell (as given by the table model)
focus - True if the cell is selected
fixed - True if the cell is an unscrollable header cell (not an unscrollable body cell!)
clicked - True if the cell is currently clicked (useful e.g. to paint a pressed button) the case when fixed row and column elements should be highlighted because a cell in that row and column has focus.
model - The KTableModel that holds the data for the cell. Note that this is only included into the parameter list to allow more flexible cell renderers. Models might provide additional information that can be requested when rendering.
See Also:
KTableCellRenderer.drawCell(GC, Rectangle, int, int, Object, boolean, boolean, boolean, KTableModel)

setAlignment

public void setAlignment(int style)
Sets the alignment of the cell content.

Parameters:
style - The OR-ed alignment constants for vertical and horizontal alignment as defined in SWTX.
See Also:
SWTX.ALIGN_HORIZONTAL_CENTER, SWTX.ALIGN_HORIZONTAL_LEFT, SWTX.ALIGN_HORIZONTAL_RIGHT, SWTX.ALIGN_VERTICAL_CENTER, SWTX.ALIGN_VERTICAL_TOP, SWTX.ALIGN_VERTICAL_BOTTOM

getAlignment

public int getAlignment()
Returns:
Returns the alignment for the cell content. 2 or-ed constants, one for horizontal, one for vertical alignment.
See Also:
SWTX.ALIGN_HORIZONTAL_CENTER, SWTX.ALIGN_HORIZONTAL_LEFT, SWTX.ALIGN_HORIZONTAL_RIGHT, SWTX.ALIGN_VERTICAL_CENTER, SWTX.ALIGN_VERTICAL_TOP, SWTX.ALIGN_VERTICAL_BOTTOM

setForeground

public void setForeground(org.eclipse.swt.graphics.Color fgcolor)
Set the foreground color used to paint text et al.

Parameters:
fgcolor - The color or null to reset to default (black). Note that also the default color can be set using setDefaultForeground(Color)
See Also:
setDefaultForeground(Color)

setDefaultForeground

public void setDefaultForeground(org.eclipse.swt.graphics.Color fgcolor)
Changes the default foreground color that will be used when no other foreground color is set. (for example when setForeground(null) is called)

Parameters:
fgcolor - The foreground color to use.
See Also:
setForeground(Color)

setBackground

public void setBackground(org.eclipse.swt.graphics.Color bgcolor)
Set the background color that should be used when painting the cell background.

If the null value is given, the default color will be used. The default color is settable using setDefaultBacktround(Color)

Parameters:
bgcolor - The color or null to reset to default.
See Also:
setDefaultBackground(Color)

setDefaultBackground

public void setDefaultBackground(org.eclipse.swt.graphics.Color bgcolor)
Changes the default background color that will be used when no background color is set via setBackground().

Parameters:
bgcolor - The color for the background.
See Also:
setBackground(Color)

getForeground

public org.eclipse.swt.graphics.Color getForeground()
Returns:
returns the currently set foreground color. If none was set, the default value is returned.

getBackground

public org.eclipse.swt.graphics.Color getBackground()
Returns:
returns the currently set background color. If none was set, the default value is returned.

setFont

public void setFont(org.eclipse.swt.graphics.Font font)
Sets the font the renderer will use for drawing its content.

Parameters:
font - The font to use. Be aware that you must dispose fonts you have created.

getFont

public org.eclipse.swt.graphics.Font getFont()
Returns:
Returns the font the renderer will use to draw the content.