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

java.lang.Object
  extended by de.jaret.util.ui.table.renderer.RendererBase
      extended by de.jaret.util.ui.table.renderer.CellRendererBase
          extended by de.jaret.util.ui.table.renderer.ClassImageRenderer
All Implemented Interfaces:
ICellRenderer

public class ClassImageRenderer
extends CellRendererBase
implements ICellRenderer

CellRenderer rendering images corresponding to the class of the value.

Version:
$Id: ClassImageRenderer.java 391 2007-04-30 23:55:39Z olk $
Author:
Peter Kliem

Field Summary
protected  java.util.Map<java.lang.Class,java.lang.String> _keyMap
           
 
Fields inherited from class de.jaret.util.ui.table.renderer.CellRendererBase
_inset, BLACKRGB, FOCUSINSETS, SELECTIONCOLOR, WHITERGB
 
Fields inherited from class de.jaret.util.ui.table.renderer.RendererBase
_printer, _scaleX, _scaleY, SCREEN_DPI_X, SCREEN_DPI_Y
 
Constructor Summary
ClassImageRenderer()
           
ClassImageRenderer(org.eclipse.swt.printing.Printer printer)
           
 
Method Summary
 void addClassImageDescriptorMapping(java.lang.Class<?> clazz, java.lang.String key, org.eclipse.jface.resource.ImageDescriptor imageDescriptor)
          Add a mapping between a class and an image descriptor.
 void addClassRessourceNameMapping(java.lang.Class<?> clazz, java.lang.String key, java.lang.String ressourceName)
          Add a mapping between a class and an image ressource.
 ICellRenderer createPrintRenderer(org.eclipse.swt.printing.Printer printer)
          Create a renderer connfigured for printing.
 void dispose()
          If there are resources to free - this is the place.
 void draw(org.eclipse.swt.graphics.GC gc, JaretTable jaretTable, ICellStyle cellStyle, org.eclipse.swt.graphics.Rectangle drawingArea, IRow row, IColumn column, boolean drawFocus, boolean selected, boolean printing)
          Draw a single cell.
protected  java.lang.String getKeyForClass(java.lang.Class<?> clazz)
          Retrieve the key for a class, checking all super classes and interfaces.
 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.
 
Methods inherited from class de.jaret.util.ui.table.renderer.CellRendererBase
applyInsets, drawBackground, drawBorder, drawCommentMarker, drawFocus, drawSelection, getBackgroundColor, getBorderColor, getFont, getForegroundColor, getInnerWidth, getTooltip, getVerticalSpacesSum, isInCommentMarkerArea
 
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
getTooltip
 

Field Detail

_keyMap

protected java.util.Map<java.lang.Class,java.lang.String> _keyMap
Constructor Detail

ClassImageRenderer

public ClassImageRenderer(org.eclipse.swt.printing.Printer printer)

ClassImageRenderer

public ClassImageRenderer()
Method Detail

addClassImageDescriptorMapping

public void addClassImageDescriptorMapping(java.lang.Class<?> clazz,
                                           java.lang.String key,
                                           org.eclipse.jface.resource.ImageDescriptor imageDescriptor)
Add a mapping between a class and an image descriptor.

Parameters:
clazz - the class
key - string key (has to be non null an unique for this renderer) to identfy the object
imageDescriptor - image descriptor for the image

addClassRessourceNameMapping

public void addClassRessourceNameMapping(java.lang.Class<?> clazz,
                                         java.lang.String key,
                                         java.lang.String ressourceName)
Add a mapping between a class and an image ressource.

Parameters:
clazz - class
key - string key (has to be non null an unique for this renderer) to identfy the object
ressourceName - ressource path

getKeyForClass

protected java.lang.String getKeyForClass(java.lang.Class<?> clazz)
Retrieve the key for a class, checking all super classes and interfaces.

Parameters:
clazz - class to check
Returns:
key or null

draw

public void draw(org.eclipse.swt.graphics.GC gc,
                 JaretTable jaretTable,
                 ICellStyle cellStyle,
                 org.eclipse.swt.graphics.Rectangle drawingArea,
                 IRow row,
                 IColumn column,
                 boolean drawFocus,
                 boolean selected,
                 boolean printing)
Draw a single cell. The draw method should be null safe (handling null as the cell value).

Specified by:
draw in interface ICellRenderer
Parameters:
gc - GC to paint on
jaretTable - table the rendering is for
cellStyle - style of the cell
drawingArea - rectangle to draw within
row - row of the cell to paint
column - column of the cell to paint
drawFocus - true if a focus mark should be drawn
selected - true if the cell is currently selected
printing - true if the render operation is for a printer

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
Overrides:
getPreferredWidth in class CellRendererBase
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. TODO

Specified by:
getPreferredHeight in interface ICellRenderer
Overrides:
getPreferredHeight in class CellRendererBase
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

dispose

public void dispose()
If there are resources to free - this is the place. Disposes the image registry and clears the key map to help garbage collecting.

Specified by:
dispose in interface ICellRenderer

createPrintRenderer

public ICellRenderer createPrintRenderer(org.eclipse.swt.printing.Printer printer)
Create a renderer connfigured for printing.

Specified by:
createPrintRenderer in interface ICellRenderer
Parameters:
printer - printer to use
Returns:
a configured renderer for printing


Copyright © 2012. All Rights Reserved.