com.jrefinery.report.targets.table.excel
Class ExcelCellStyleFactory

java.lang.Object
  |
  +--com.jrefinery.report.targets.table.excel.ExcelCellStyleFactory

public class ExcelCellStyleFactory
extends java.lang.Object

The CellStyle factory is used to convert JFreeReport style information into excel styles. This class also keeps track of the cell styles that we have used so far, as excel has a limitation on the usable amount of defined styles. If equal styles are defined, we recycle the previously generated styles.

Author:
Heiko Evermann

Constructor Summary
ExcelCellStyleFactory(org.apache.poi.hssf.usermodel.HSSFWorkbook workbook)
          Constructor for ExcelCellStyleFactory.
 
Method Summary
protected  short convertAlignment(ElementAlignment e)
          Converts the given element alignment into one of the HSSFCellStyle-constants.
 org.apache.poi.hssf.usermodel.HSSFCellStyle createCellStyle(ExcelDataCellStyle style, TableCellBackground bg)
          Creates a HSSFCellStyle based on the given ExcelDataCellStyle.
 org.apache.poi.hssf.usermodel.HSSFCellStyle getEmptyCellStyle()
          Gets the default style, which is used for empty cells.
 ExcelDataCellStyle getExcelDataCellStyle(Element element)
          Converts the given element and the assigned style into an excel style.
 ExcelDataCellStyle getExcelDataCellStyle(Element element, java.lang.String format)
          Converts the given element and the assigned style into an excel style.
static void print()
          Prints the instance and usage counters.
protected  short translateStroke(float width)
          Tries to translate the given stroke width into one of the predefined excel border styles.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExcelCellStyleFactory

public ExcelCellStyleFactory(org.apache.poi.hssf.usermodel.HSSFWorkbook workbook)
Constructor for ExcelCellStyleFactory.

Parameters:
workbook - the workbook for which the styles should be created.
Throws:
java.lang.NullPointerException - if the workbook is null.
Method Detail

print

public static void print()
Prints the instance and usage counters.


convertAlignment

protected short convertAlignment(ElementAlignment e)
Converts the given element alignment into one of the HSSFCellStyle-constants.

Parameters:
e - the JFreeReport element alignment.
Returns:
the HSSFCellStyle-Alignment.
Throws:
java.lang.IllegalArgumentException - if an Unknown JFreeReport alignment is given.

translateStroke

protected short translateStroke(float width)
Tries to translate the given stroke width into one of the predefined excel border styles.

Parameters:
width - the AWT-Stroke-Width.
Returns:
the translated excel border width.

getExcelDataCellStyle

public ExcelDataCellStyle getExcelDataCellStyle(Element element)
Converts the given element and the assigned style into an excel style.

Parameters:
element - the element that should be converted into the excel style.
Returns:
the generated excel style, never null.

getExcelDataCellStyle

public ExcelDataCellStyle getExcelDataCellStyle(Element element,
                                                java.lang.String format)
Converts the given element and the assigned style into an excel style.

Parameters:
element - the element that should be converted into the excel style.
format - the format string for the cell.
Returns:
the generated excel style, never null.

getEmptyCellStyle

public org.apache.poi.hssf.usermodel.HSSFCellStyle getEmptyCellStyle()
Gets the default style, which is used for empty cells.

Returns:
the default style for empty cells.

createCellStyle

public org.apache.poi.hssf.usermodel.HSSFCellStyle createCellStyle(ExcelDataCellStyle style,
                                                                   TableCellBackground bg)
Creates a HSSFCellStyle based on the given ExcelDataCellStyle. If a similiar cell style was previously generated, then reuse that cached result.

Parameters:
style - the excel style that was used to collect the foreground cellstyle information.
bg - the background style for the table cell.
Returns:
the generated or cached HSSFCellStyle.