com.jrefinery.workbook
Class Style

java.lang.Object
  |
  +--com.jrefinery.workbook.Style

public class Style
extends java.lang.Object

Represents a style that (when incorporated within a StyleRegion object) applies to a range of cells in a worksheet.

This class should be immutable so we can use it in multiple places without risking it being changed.


Field Summary
protected  StyleColor backgroundColor
          The background color.
protected  StyleBorder border
          The border details.
static int BOTTOM
          Constant for bottom vertical alignment.
protected  int cellIndent
          The indentation for the cells.
static int CENTER_ACROSS_SELECTION
          Constant for centered-across-selection horizontal alignment.
static int FILL
          Constant for "fill" horizontal alignment.
protected  StyleFont font
          The font details.
protected  StyleColor foregroundColor
          The foreground color.
protected  java.lang.String format
          The format.
static int GENERAL
          Constant for "general" horizontal alignment.
static int HORIZONTAL_CENTER
          Constant for centered horizontal alignment.
static int HORIZONTAL_JUSTIFY
          Constant for "justify" horizontal alignment.
protected  int horizontalAlignment
          The horizontal alignment.
static int LEFT
          Constant for left horizontal alignment.
protected  int orientation
          The orientation.
protected  StyleColor patternColor
          The pattern color.
static int RIGHT
          Constant for right horizontal alignment.
protected  int shade
          The shade.
static int TOP
          Constant for top vertical alignment.
static int VERTICAL_CENTER
          Constant for centered vertical alignment.
static int VERTICAL_JUSTIFY
          Constant for "justified" vertical alignment.
protected  int verticalAlignment
          The vertical alignment.
protected  boolean wrapText
          Wrap text (true/false).
 
Constructor Summary
Style()
          Default constructor: constructs a new Style object with default values.
Style(StyleFont font, int horizontalAlignment, int verticalAlignment)
          Standard constructor: creates a style with a specific font and alignment.
Style(StyleFont font, StyleBorder border, int horizontalAlignment, int verticalAlignment, boolean wrapText, int orientation, int shade, int cellIndent, StyleColor foregroundColor, StyleColor backgroundColor, StyleColor patternColor, java.lang.String format)
          Full constructor.
 
Method Summary
static Style applyBackgroundColor(Style style, StyleColor backgroundColor)
          Creates a new style based on the provided style, but replacing the background color as specified.
static Style applyBorder(Style style, StyleBorder border)
          Creates a new style based on the provided style, but replacing the border as specified.
static Style applyFont(Style style, StyleFont font)
          Creates a new style based on the provided style, but replacing the font as specified.
static Style applyForegroundColor(Style style, StyleColor foregroundColor)
          Creates a new style based on the provided style, but replacing the foreground color as specified.
static Style applyPatternColor(Style style, StyleColor patternColor)
          Creates a new style based on the provided style, but replacing the pattern color as specified.
 StyleColor getBackgroundColor()
          Returns the background color.
 StyleBorder getBorder()
          Returns the border for this style.
 int getCellIndent()
          Returns the indentation.
 StyleFont getFont()
          Returns the font for this style.
 StyleColor getForegroundColor()
          Returns the foreground color.
 java.lang.String getFormat()
          Returns the format string for the cell.
 int getHorizontalAlignment()
          Returns the horizontal alignment for this style.
 int getOrientation()
          Returns the text orientation.
 StyleColor getPatternColor()
          Returns the pattern color.
 int getShade()
          Returns the shade.
 int getVerticalAlignment()
          Returns the vertical alignment for this style.
 boolean isWrapText()
          Returns a flag indicating whether or not the text is wrapped.
 void writeStyle(java.io.PrintStream out, java.lang.String indent)
          Writes a style element to the stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GENERAL

public static final int GENERAL
Constant for "general" horizontal alignment.

LEFT

public static final int LEFT
Constant for left horizontal alignment.

RIGHT

public static final int RIGHT
Constant for right horizontal alignment.

HORIZONTAL_CENTER

public static final int HORIZONTAL_CENTER
Constant for centered horizontal alignment.

FILL

public static final int FILL
Constant for "fill" horizontal alignment.

HORIZONTAL_JUSTIFY

public static final int HORIZONTAL_JUSTIFY
Constant for "justify" horizontal alignment.

CENTER_ACROSS_SELECTION

public static final int CENTER_ACROSS_SELECTION
Constant for centered-across-selection horizontal alignment.

TOP

public static final int TOP
Constant for top vertical alignment.

BOTTOM

public static final int BOTTOM
Constant for bottom vertical alignment.

VERTICAL_CENTER

public static final int VERTICAL_CENTER
Constant for centered vertical alignment.

VERTICAL_JUSTIFY

public static final int VERTICAL_JUSTIFY
Constant for "justified" vertical alignment.

font

protected StyleFont font
The font details.

border

protected StyleBorder border
The border details.

horizontalAlignment

protected int horizontalAlignment
The horizontal alignment.

verticalAlignment

protected int verticalAlignment
The vertical alignment.

wrapText

protected boolean wrapText
Wrap text (true/false).

orientation

protected int orientation
The orientation.

shade

protected int shade
The shade. Not all that sure about this yet. It might in fact be a boolean in the Gnumeric file format. It needs to be "1" if the cell has a background color.

cellIndent

protected int cellIndent
The indentation for the cells.

foregroundColor

protected StyleColor foregroundColor
The foreground color.

backgroundColor

protected StyleColor backgroundColor
The background color.

patternColor

protected StyleColor patternColor
The pattern color.

format

protected java.lang.String format
The format.
Constructor Detail

Style

public Style()
Default constructor: constructs a new Style object with default values.

Style

public Style(StyleFont font,
             int horizontalAlignment,
             int verticalAlignment)
Standard constructor: creates a style with a specific font and alignment.
Parameters:
font - The font.
horizontalAlignment - The horizontal alignment.
verticalAlignment - The vertical alignment.

Style

public Style(StyleFont font,
             StyleBorder border,
             int horizontalAlignment,
             int verticalAlignment,
             boolean wrapText,
             int orientation,
             int shade,
             int cellIndent,
             StyleColor foregroundColor,
             StyleColor backgroundColor,
             StyleColor patternColor,
             java.lang.String format)
Full constructor.
Parameters:
font - The font.
border - The border.
horizontalAlignment - The horizontal alignment.
verticalAlignment - The vertical alignment.
wrapText - Wrap text (true/false).
orientation - The text orientation.
shade - ??
cellIndent - Cell indentation.
foregroundColor - The foreground color.
bacgroundColor - The bacground color.
patternColor - The pattern color.
format - The format string for the cell.
Method Detail

getFont

public StyleFont getFont()
Returns the font for this style.
Returns:
The font for this style.

getBorder

public StyleBorder getBorder()
Returns the border for this style.
Returns:
The border for this style.

getHorizontalAlignment

public int getHorizontalAlignment()
Returns the horizontal alignment for this style.
Returns:
The horizontal alignment for this style.

getVerticalAlignment

public int getVerticalAlignment()
Returns the vertical alignment for this style.
Returns:
The vertical alignment for this style.

isWrapText

public boolean isWrapText()
Returns a flag indicating whether or not the text is wrapped.
Returns:
A flag indicating whether or not the text is wrapped.

getOrientation

public int getOrientation()
Returns the text orientation.
Returns:
The text orientation.

getShade

public int getShade()
Returns the shade.
Returns:
The shade.

getCellIndent

public int getCellIndent()
Returns the indentation.
Returns:
The indentation.

getForegroundColor

public StyleColor getForegroundColor()
Returns the foreground color.
Returns:
The foreground color.

getBackgroundColor

public StyleColor getBackgroundColor()
Returns the background color.
Returns:
The background color.

getPatternColor

public StyleColor getPatternColor()
Returns the pattern color.
Returns:
The pattern color.

getFormat

public java.lang.String getFormat()
Returns the format string for the cell.
Returns:
The format string for the cell.

applyFont

public static Style applyFont(Style style,
                              StyleFont font)
Creates a new style based on the provided style, but replacing the font as specified.
Parameters:
style - The base style.
font - The new font.

applyBorder

public static Style applyBorder(Style style,
                                StyleBorder border)
Creates a new style based on the provided style, but replacing the border as specified.
Parameters:
style - The base style.
border - The new border.

applyForegroundColor

public static Style applyForegroundColor(Style style,
                                         StyleColor foregroundColor)
Creates a new style based on the provided style, but replacing the foreground color as specified.
Parameters:
style - The base style.
foregroundColor - The new foreground color.

applyBackgroundColor

public static Style applyBackgroundColor(Style style,
                                         StyleColor backgroundColor)
Creates a new style based on the provided style, but replacing the background color as specified.

We set the shade value to 1, since it looks as though this is required by the Gnumeric file format...will try to find out more about this.

Parameters:
style - The base style.
backgroundColor - The new background color.

applyPatternColor

public static Style applyPatternColor(Style style,
                                      StyleColor patternColor)
Creates a new style based on the provided style, but replacing the pattern color as specified.
Parameters:
style - The base style.
patternColor - The pattern color.

writeStyle

public void writeStyle(java.io.PrintStream out,
                       java.lang.String indent)
Writes a style element to the stream.
Parameters:
out - The stream.
indent - The indentation.