de.jaret.util.ui.table.renderer
Class CellRendererBase

java.lang.Object
  extended by de.jaret.util.ui.table.renderer.RendererBase
      extended by de.jaret.util.ui.table.renderer.CellRendererBase
All Implemented Interfaces:
ICellRenderer
Direct Known Subclasses:
BarCellRenderer, BooleanCellRenderer, ClassImageRenderer, ImageCellRenderer, ObjectImageRenderer, SmileyCellRenderer, TableHierarchyRenderer, TextCellRenderer

public abstract class CellRendererBase
extends RendererBase
implements ICellRenderer

Base implementation for cell renderers that support both screen and printer rendering. This base implementation contains some useful methods so that it is highly recommended to base all renderer implementations on this base.

Version:
$Id: CellRendererBase.java 489 2007-06-05 17:56:08Z olk $
Author:
Peter Kliem

Field Summary
protected  int _inset
          cell inset used by the convenience methods.
protected static org.eclipse.swt.graphics.RGB BLACKRGB
          default foreground color.
protected static int FOCUSINSETS
          insets used when drawing the focus.
protected static org.eclipse.swt.graphics.Color SELECTIONCOLOR
          selection color for overlay (non printing only).
protected static org.eclipse.swt.graphics.RGB WHITERGB
          default background color.
 
Fields inherited from class de.jaret.util.ui.table.renderer.RendererBase
_printer, _scaleX, _scaleY, SCREEN_DPI_X, SCREEN_DPI_Y
 
Constructor Summary
CellRendererBase(org.eclipse.swt.printing.Printer printer)
          May be constructed without printer (supplying null).
 
Method Summary
protected  org.eclipse.swt.graphics.Rectangle applyInsets(org.eclipse.swt.graphics.Rectangle rect)
          Calculate the resulting rectangle after applying the insets.
protected  void drawBackground(org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle area, ICellStyle style, boolean selected, boolean printing)
          Draw the cell background.
protected  org.eclipse.swt.graphics.Rectangle drawBorder(org.eclipse.swt.graphics.GC gc, ICellStyle cellStyle, org.eclipse.swt.graphics.Rectangle drawingArea, boolean printing)
          Draw the border for the cell according to the cell style.
protected  void drawCommentMarker(org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle area, org.eclipse.swt.graphics.Color color, int size)
          Draw a marker in upper left corner for indicating a cell comment.
protected  void drawFocus(org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle drawingArea)
          Draw focus marking.
protected  void drawSelection(org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle area, ICellStyle style, boolean selected, boolean printing)
          Draws a cell selection by overlaying alpha blended area using SELECTIONCOLOR.
protected  org.eclipse.swt.graphics.Color getBackgroundColor(ICellStyle style, boolean printing)
          Get the background color according to a cell style.
protected  org.eclipse.swt.graphics.Color getBorderColor(ICellStyle style, boolean printing)
          Get the border color according to the cell style.
protected  org.eclipse.swt.graphics.Font getFont(ICellStyle style, boolean printing, org.eclipse.swt.graphics.Font defaultFont)
          Retrieve the font accrding to the cell style.
protected  org.eclipse.swt.graphics.Color getForegroundColor(ICellStyle style, boolean printing)
          Get the foreground color according to the cell style.
protected  int getInnerWidth(int width, ICellStyle cellStyle)
          Target inner width (width - borders - insets).
 int getPreferredHeight(org.eclipse.swt.graphics.GC gc, ICellStyle cellStyle, int width, IRow row, IColumn column)
          Calculate the preferred height of a specific cell.
 int getPreferredWidth(java.util.List<IRow> rows, IColumn column)
          Calculate the preferred width for the column.
 java.lang.String getTooltip(JaretTable jaretTable, org.eclipse.swt.graphics.Rectangle drawingArea, IRow row, IColumn column, int x, int y)
          Provide a tooltip text for display.
protected  int getVerticalSpacesSum(ICellStyle cellStyle)
          Calculate the sum of all vertical spaces that could be spplied.
protected  boolean isInCommentMarkerArea(org.eclipse.swt.graphics.Rectangle area, int size, int x, int y)
          Check whether a position is in the area of the commetn marker.
 
Methods inherited from class de.jaret.util.ui.table.renderer.RendererBase
getPrinter, getScaleX, getScaleY, restoreGCAttributes, saveGCAttributes, scaleX, scaleY
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.jaret.util.ui.table.renderer.ICellRenderer
createPrintRenderer, dispose, draw
 

Field Detail

SELECTIONCOLOR

protected static final org.eclipse.swt.graphics.Color SELECTIONCOLOR
selection color for overlay (non printing only).


FOCUSINSETS

protected static final int FOCUSINSETS
insets used when drawing the focus.

See Also:
Constant Field Values

WHITERGB

protected static final org.eclipse.swt.graphics.RGB WHITERGB
default background color.


BLACKRGB

protected static final org.eclipse.swt.graphics.RGB BLACKRGB
default foreground color.


_inset

protected int _inset
cell inset used by the convenience methods.

Constructor Detail

CellRendererBase

public CellRendererBase(org.eclipse.swt.printing.Printer printer)
May be constructed without printer (supplying null).

Parameters:
printer - or null
Method Detail

getPreferredWidth

public int getPreferredWidth(java.util.List<IRow> rows,
                             IColumn column)
Calculate the preferred width for the column. Default implementation: no prferred width.

Specified by:
getPreferredWidth in interface ICellRenderer
Parameters:
rows - the rows currently displayed by the table
column - the column for which the preferred width is to be calculated
Returns:
the preferred width or -1 for no special preferred width.

getPreferredHeight

public int getPreferredHeight(org.eclipse.swt.graphics.GC gc,
                              ICellStyle cellStyle,
                              int width,
                              IRow row,
                              IColumn column)
Calculate the preferred height of a specific cell. Default implementation returning: no information.

Specified by:
getPreferredHeight in interface ICellRenderer
Parameters:
gc - GC that will used
cellStyle - cell style of the cell
width - width of the column (thus of the cell)
row - row
column - column
Returns:
the preferred height or -1 for no special preferred height

getTooltip

public java.lang.String getTooltip(JaretTable jaretTable,
                                   org.eclipse.swt.graphics.Rectangle drawingArea,
                                   IRow row,
                                   IColumn column,
                                   int x,
                                   int y)
Provide a tooltip text for display. Default: no tooltip.

Specified by:
getTooltip in interface ICellRenderer
Parameters:
jaretTable - table that is asking
drawingArea - area of the cell rendering
row - row
column - column
x - mouse x coordinate (absolute within drawing area)
y - mouse y coordinate (abs within drawing area)
Returns:
tootip text or null if no tooltip is to be shown

getInnerWidth

protected int getInnerWidth(int width,
                            ICellStyle cellStyle)
Target inner width (width - borders - insets).

Parameters:
width - width
cellStyle - cell style
Returns:
target inner width

getVerticalSpacesSum

protected int getVerticalSpacesSum(ICellStyle cellStyle)
Calculate the sum of all vertical spaces that could be spplied.

Parameters:
cellStyle - cell style
Returns:
sum of all vertical spaces

drawFocus

protected void drawFocus(org.eclipse.swt.graphics.GC gc,
                         org.eclipse.swt.graphics.Rectangle drawingArea)
Draw focus marking. Should be called with the corrected drawing area.

Parameters:
gc - GC
drawingArea - corrected drawing area

applyInsets

protected org.eclipse.swt.graphics.Rectangle applyInsets(org.eclipse.swt.graphics.Rectangle rect)
Calculate the resulting rectangle after applying the insets.

Parameters:
rect - cell drawing area
Returns:
corrected rectangle

drawBorder

protected org.eclipse.swt.graphics.Rectangle drawBorder(org.eclipse.swt.graphics.GC gc,
                                                        ICellStyle cellStyle,
                                                        org.eclipse.swt.graphics.Rectangle drawingArea,
                                                        boolean printing)
Draw the border for the cell according to the cell style.

Parameters:
gc - GC
cellStyle - th style
drawingArea - the drawing area of the cell
printing - true marks operation for a printer
Returns:
the corrected drawing area (the thickness of the border has been substracted)

drawBackground

protected void drawBackground(org.eclipse.swt.graphics.GC gc,
                              org.eclipse.swt.graphics.Rectangle area,
                              ICellStyle style,
                              boolean selected,
                              boolean printing)
Draw the cell background.

Parameters:
gc - GC
area - cell drawing area
style - cell style
selected - true for selected
printing - true if printing

drawSelection

protected void drawSelection(org.eclipse.swt.graphics.GC gc,
                             org.eclipse.swt.graphics.Rectangle area,
                             ICellStyle style,
                             boolean selected,
                             boolean printing)
Draws a cell selection by overlaying alpha blended area using SELECTIONCOLOR.

Parameters:
gc - GC
area - area of the cell
style - cellstyle
selected - true if selecetd
printing - true if printing - no selection will be drawn when printing

drawCommentMarker

protected void drawCommentMarker(org.eclipse.swt.graphics.GC gc,
                                 org.eclipse.swt.graphics.Rectangle area,
                                 org.eclipse.swt.graphics.Color color,
                                 int size)
Draw a marker in upper left corner for indicating a cell comment.

Parameters:
gc - GC
area - drawing area
color - color of the marker
size - size of the marker

isInCommentMarkerArea

protected boolean isInCommentMarkerArea(org.eclipse.swt.graphics.Rectangle area,
                                        int size,
                                        int x,
                                        int y)
Check whether a position is in the area of the commetn marker.

Parameters:
area - drawing area of the cell
size - size of the marker
x - x coordinate to check
y - y coordinate to check
Returns:
true if the position is in the area of the marker

getBackgroundColor

protected org.eclipse.swt.graphics.Color getBackgroundColor(ICellStyle style,
                                                            boolean printing)
Get the background color according to a cell style.

Parameters:
style - cell style
printing - true for printing
Returns:
the color

getForegroundColor

protected org.eclipse.swt.graphics.Color getForegroundColor(ICellStyle style,
                                                            boolean printing)
Get the foreground color according to the cell style.

Parameters:
style - cell style
printing - true for printing
Returns:
the foreground color

getBorderColor

protected org.eclipse.swt.graphics.Color getBorderColor(ICellStyle style,
                                                        boolean printing)
Get the border color according to the cell style.

Parameters:
style - cell style
printing - true for printing
Returns:
the border color

getFont

protected org.eclipse.swt.graphics.Font getFont(ICellStyle style,
                                                boolean printing,
                                                org.eclipse.swt.graphics.Font defaultFont)
Retrieve the font accrding to the cell style.

Parameters:
style - cell style
printing - true for printing
defaultFont - a default font used if no font can be retrieved
Returns:
font according to style or default font


Copyright © 2012. All Rights Reserved.