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

java.lang.Object
  extended by de.jaret.util.ui.table.renderer.DefaultCellStyleProvider
All Implemented Interfaces:
ICellStyleProvider, java.beans.PropertyChangeListener, java.util.EventListener

public class DefaultCellStyleProvider
extends java.lang.Object
implements ICellStyleProvider, java.beans.PropertyChangeListener

A Default implementation of a CellStyleProvider. It will register itself with every cell style as a property change listener.

Version:
$Id: DefaultCellStyleProvider.java 347 2007-04-07 15:01:10Z olk $
Author:
Peter Kliem

Field Summary
protected  java.util.Map<IRow,java.util.Map<IColumn,ICellStyle>> _cellMap
          map combintaion storing the style of a cell .
protected  java.util.Map<IColumn,ICellStyle> _columnMap
          map storing the column cell styles.
protected  ICellStyle _defaultCellStyle
          the default cell style.
protected  ICellStyle _defaultCellStyleAlignRight
          the default cell style aligned right.
protected  java.util.List<ICellStyleListener> _listeners
          the listener list.
protected  java.util.Map<IRow,ICellStyle> _rowMap
          map storing the row cell styles.
protected  IStyleStrategy _styleStrategy
          style stategy.
 
Constructor Summary
DefaultCellStyleProvider()
          Constructor.
 
Method Summary
 void addCellStyleListener(ICellStyleListener csl)
          Add a listener to listen on cell style changes.
protected  void fireCellStyleChanged(IRow row, IColumn column, ICellStyle cellStyle)
          Inform listeners about a cell style change.
 ICellStyle getCellSpecificStyle(IRow row, IColumn column, boolean create)
          Get the cell style defined for a single cell.
 ICellStyle getCellStyle(IRow row, IColumn column)
          Retrieve the cell style for a cell.
 ICellStyle getColumnCellStyle(IColumn column, boolean create)
          Retrieve the cell style for a column.
 ICellStyle getDefaultCellStyle()
          Retrieve the default cell style used for cells where no style has been set.
 ICellStyle getRowCellStyle(IRow row, boolean create)
          Retrieve the cell style for a row.
protected  java.util.List<IJaretTableCell> getStyleLocations(ICellStyle style)
          Retrieve all cells that have a certain style.
 IStyleStrategy getStyleStrategy()
          Retrieve a style strategy if set.
 void propertyChange(java.beans.PropertyChangeEvent event)
           Listens to all styles and fires style changed for every location a style is used in.
 void remCellStyleListener(ICellStyleListener csl)
          Remove a cell sytle listener.
 void setBackground(IColumn column, org.eclipse.swt.graphics.RGB background)
          Convenience method for setting the background of a column.
 void setBackground(IRow row, IColumn column, org.eclipse.swt.graphics.RGB background)
          Convenience method for setting the background of a cell.
 void setBackground(IRow row, org.eclipse.swt.graphics.RGB background)
          Convenience method for setting the background of a row.
 void setCellStyle(IRow row, IColumn column, ICellStyle style)
          Set the cell style to use for a specific cell.
 void setColumnCellStyle(IColumn column, ICellStyle style)
          Set the cell style for a column.
 void setDefaultCellStyle(ICellStyle cellStyle)
          Set the default cell style that is used whenever no specific style has been set for a cell, column or row.
 void setFont(IColumn column, org.eclipse.swt.graphics.FontData fontdata)
          Convenience method for setting the font.
 void setFont(IRow row, org.eclipse.swt.graphics.FontData fontdata)
          Convenience method for setting the font.
 void setFont(IRow row, IColumn column, org.eclipse.swt.graphics.FontData fontdata)
          Convenience method for setting the font.
 void setForeground(IColumn column, org.eclipse.swt.graphics.RGB foreground)
          Convenience method for setting the foreground of a column.
 void setForeground(IRow row, IColumn column, org.eclipse.swt.graphics.RGB foreground)
          Convenience method for setting the foreground of a cell.
 void setForeground(IRow row, org.eclipse.swt.graphics.RGB foreground)
          Convenience method for setting the foreground of a row.
 void setHorizontalAlignment(IColumn column, ITableViewState.HAlignment alignment)
          Convenience method for setting the horizontal alignment.
 void setHorizontalAlignment(IRow row, IColumn column, ITableViewState.HAlignment alignment)
          Convenience method for setting the horizontal alignment.
 void setHorizontalAlignment(IRow row, ITableViewState.HAlignment alignment)
          Convenience method for setting the horizontal alignment.
 void setRowCellStyle(IRow row, ICellStyle style)
          Set the cell style for a row.
 void setStyleStrategy(IStyleStrategy startegy)
          Set a style strategy to be involved when delivering styles.
 void setVerticalAlignment(IColumn column, ITableViewState.VAlignment alignment)
          Convenience method for setting the vertical alignment.
 void setVerticalAlignment(IRow row, IColumn column, ITableViewState.VAlignment alignment)
          Convenience method for setting the vertical alignment.
 void setVerticalAlignment(IRow row, ITableViewState.VAlignment alignment)
          Convenience method for setting the vertical alignment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_rowMap

protected java.util.Map<IRow,ICellStyle> _rowMap
map storing the row cell styles.


_columnMap

protected java.util.Map<IColumn,ICellStyle> _columnMap
map storing the column cell styles.


_cellMap

protected java.util.Map<IRow,java.util.Map<IColumn,ICellStyle>> _cellMap
map combintaion storing the style of a cell .


_listeners

protected java.util.List<ICellStyleListener> _listeners
the listener list.


_defaultCellStyle

protected ICellStyle _defaultCellStyle
the default cell style.


_defaultCellStyleAlignRight

protected ICellStyle _defaultCellStyleAlignRight
the default cell style aligned right.


_styleStrategy

protected IStyleStrategy _styleStrategy
style stategy.

Constructor Detail

DefaultCellStyleProvider

public DefaultCellStyleProvider()
Constructor.

Method Detail

getCellStyle

public ICellStyle getCellStyle(IRow row,
                               IColumn column)
Retrieve the cell style for a cell. This method should not create CellStyle objects. TODO include a strategy for priority row/column.

Specified by:
getCellStyle in interface ICellStyleProvider
Parameters:
row - row of the cell
column - col of the cell
Returns:
cell style for the specified cell

setRowCellStyle

public void setRowCellStyle(IRow row,
                            ICellStyle style)
Set the cell style for a row.

Specified by:
setRowCellStyle in interface ICellStyleProvider
Parameters:
row - row
style - cell style

getRowCellStyle

public ICellStyle getRowCellStyle(IRow row,
                                  boolean create)
Retrieve the cell style for a row.

Specified by:
getRowCellStyle in interface ICellStyleProvider
Parameters:
row - row
create - if true and no style has been set for the row, create a copy of the default cell style
Returns:
the cellstyle for the row which might be the default cell style if create is set to false

setColumnCellStyle

public void setColumnCellStyle(IColumn column,
                               ICellStyle style)
Set the cell style for a column.

Specified by:
setColumnCellStyle in interface ICellStyleProvider
Parameters:
column - column
style - style

getColumnCellStyle

public ICellStyle getColumnCellStyle(IColumn column,
                                     boolean create)
Retrieve the cell style for a column.

Specified by:
getColumnCellStyle in interface ICellStyleProvider
Parameters:
column - column
create - if true and no style has been set for the column, create a copy of the default cell style
Returns:
the cellstyle for the colun which might be the default cell style if create is set to false

getCellSpecificStyle

public ICellStyle getCellSpecificStyle(IRow row,
                                       IColumn column,
                                       boolean create)
Get the cell style defined for a single cell. Should create a new CellStyle object if create is true.

Specified by:
getCellSpecificStyle in interface ICellStyleProvider
Parameters:
row - row of the cell
column - column of the cell
create - true will signal to create a new style object if necessary
Returns:
cell style for the cell

setCellStyle

public void setCellStyle(IRow row,
                         IColumn column,
                         ICellStyle style)
Set the cell style to use for a specific cell.

Specified by:
setCellStyle in interface ICellStyleProvider
Parameters:
row - row of the cell
column - column of the cell
style - style to use

getDefaultCellStyle

public ICellStyle getDefaultCellStyle()
Retrieve the default cell style used for cells where no style has been set. If the returned cell style is modified, this applies for all default styled cells.

Specified by:
getDefaultCellStyle in interface ICellStyleProvider
Returns:
the default cell style.

setDefaultCellStyle

public void setDefaultCellStyle(ICellStyle cellStyle)
Set the default cell style that is used whenever no specific style has been set for a cell, column or row.

Specified by:
setDefaultCellStyle in interface ICellStyleProvider
Parameters:
cellStyle - cell style to use as the default cell style

addCellStyleListener

public void addCellStyleListener(ICellStyleListener csl)
Add a listener to listen on cell style changes.

Specified by:
addCellStyleListener in interface ICellStyleProvider
Parameters:
csl - listener

remCellStyleListener

public void remCellStyleListener(ICellStyleListener csl)
Remove a cell sytle listener.

Specified by:
remCellStyleListener in interface ICellStyleProvider
Parameters:
csl - listener to remove

fireCellStyleChanged

protected void fireCellStyleChanged(IRow row,
                                    IColumn column,
                                    ICellStyle cellStyle)
Inform listeners about a cell style change.

Parameters:
row - row affected
column - olumn affected
cellStyle - new style

getStyleLocations

protected java.util.List<IJaretTableCell> getStyleLocations(ICellStyle style)
Retrieve all cells that have a certain style. TODO check performance

Parameters:
style - the style to search
Returns:
list of cels the style applies to

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent event)
Listens to all styles and fires style changed for every location a style is used in.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener

getStyleStrategy

public IStyleStrategy getStyleStrategy()
Retrieve a style strategy if set.

Specified by:
getStyleStrategy in interface ICellStyleProvider
Returns:
the strategy or null

setStyleStrategy

public void setStyleStrategy(IStyleStrategy startegy)
Set a style strategy to be involved when delivering styles.

Specified by:
setStyleStrategy in interface ICellStyleProvider
Parameters:
startegy - strategy to use

setBackground

public void setBackground(IRow row,
                          org.eclipse.swt.graphics.RGB background)
Convenience method for setting the background of a row. This method will manipulate or create a style.

Specified by:
setBackground in interface ICellStyleProvider
Parameters:
row - row
background - background color

setBackground

public void setBackground(IColumn column,
                          org.eclipse.swt.graphics.RGB background)
Convenience method for setting the background of a column. This method will manipulate or create a style.

Specified by:
setBackground in interface ICellStyleProvider
Parameters:
column - column
background - background color

setBackground

public void setBackground(IRow row,
                          IColumn column,
                          org.eclipse.swt.graphics.RGB background)
Convenience method for setting the background of a cell. This method will manipulate or create a style.

Specified by:
setBackground in interface ICellStyleProvider
Parameters:
row - row of th cell
column - column of the cell
background - background color

setForeground

public void setForeground(IRow row,
                          org.eclipse.swt.graphics.RGB foreground)
Convenience method for setting the foreground of a row. This method will manipulate or create a style.

Specified by:
setForeground in interface ICellStyleProvider
Parameters:
row - row
foreground - background color

setForeground

public void setForeground(IColumn column,
                          org.eclipse.swt.graphics.RGB foreground)
Convenience method for setting the foreground of a column. This method will manipulate or create a style.

Specified by:
setForeground in interface ICellStyleProvider
Parameters:
column - column
foreground - foreground color

setForeground

public void setForeground(IRow row,
                          IColumn column,
                          org.eclipse.swt.graphics.RGB foreground)
Convenience method for setting the foreground of a cell. This method will manipulate or create a style.

Specified by:
setForeground in interface ICellStyleProvider
Parameters:
row - row of th cell
column - column of the cell
foreground - foreground color

setHorizontalAlignment

public void setHorizontalAlignment(IRow row,
                                   ITableViewState.HAlignment alignment)
Convenience method for setting the horizontal alignment. The method will create a cell style for the element or manipulate the already set style.

Specified by:
setHorizontalAlignment in interface ICellStyleProvider
Parameters:
row - row
alignment - horizontal alignment

setHorizontalAlignment

public void setHorizontalAlignment(IColumn column,
                                   ITableViewState.HAlignment alignment)
Convenience method for setting the horizontal alignment. The method will create a cell style for the element or manipulate the already set style.

Specified by:
setHorizontalAlignment in interface ICellStyleProvider
Parameters:
column - column
alignment - horizontal alignment

setHorizontalAlignment

public void setHorizontalAlignment(IRow row,
                                   IColumn column,
                                   ITableViewState.HAlignment alignment)
Convenience method for setting the horizontal alignment. The method will create a cell style for the element or manipulate the already set style.

Specified by:
setHorizontalAlignment in interface ICellStyleProvider
Parameters:
row - row of th cell
column - column of the cell
alignment - horizontal alignment

setVerticalAlignment

public void setVerticalAlignment(IRow row,
                                 ITableViewState.VAlignment alignment)
Convenience method for setting the vertical alignment. The method will create a cell style for the element or manipulate the already set style.

Specified by:
setVerticalAlignment in interface ICellStyleProvider
Parameters:
row - row
alignment - vertical alignment

setVerticalAlignment

public void setVerticalAlignment(IColumn column,
                                 ITableViewState.VAlignment alignment)
Convenience method for setting the vertical alignment. The method will create a cell style for the element or manipulate the already set style.

Specified by:
setVerticalAlignment in interface ICellStyleProvider
Parameters:
column - column
alignment - vertical alignment

setVerticalAlignment

public void setVerticalAlignment(IRow row,
                                 IColumn column,
                                 ITableViewState.VAlignment alignment)
Convenience method for setting the vertical alignment. The method will create a cell style for the element or manipulate the already set style.

Specified by:
setVerticalAlignment in interface ICellStyleProvider
Parameters:
row - row of th cell
column - column of the cell
alignment - vertical alignment

setFont

public void setFont(IRow row,
                    org.eclipse.swt.graphics.FontData fontdata)
Convenience method for setting the font. The method will create a cell style for the element or manipulate the already set style.

Specified by:
setFont in interface ICellStyleProvider
Parameters:
row - row
fontdata - font data for the font to use

setFont

public void setFont(IColumn column,
                    org.eclipse.swt.graphics.FontData fontdata)
Convenience method for setting the font. The method will create a cell style for the element or manipulate the already set style.

Specified by:
setFont in interface ICellStyleProvider
Parameters:
column - column
fontdata - font data for the font to use

setFont

public void setFont(IRow row,
                    IColumn column,
                    org.eclipse.swt.graphics.FontData fontdata)
Convenience method for setting the font. The method will create a cell style for the element or manipulate the already set style.

Specified by:
setFont in interface ICellStyleProvider
Parameters:
row - row of th cell
column - column of the cell
fontdata - font data for the font to use


Copyright © 2012. All Rights Reserved.