org.writersforge.catalan.layout.style
Class StyleChain

java.lang.Object
  |
  +--org.writersforge.catalan.layout.style.StyleChain
All Implemented Interfaces:
AlignStyle, AllStyle, AreaStyle, BorderStyle, ExtentStyle, FontStyle, InsetStyle, TextStyle

public final class StyleChain
extends java.lang.Object
implements AllStyle

Style aggregator. Hooks multiple styles together in sequence, performing lookups on each style until it finds the property defined in one. Useful for complex style resolution and inheritance.

Author:
jsheets

Field Summary
 
Fields inherited from interface org.writersforge.catalan.layout.style.FontStyle
FONT_STYLE_BOLD, FONT_STYLE_ITALIC, FONT_STYLE_PLAIN, STYLE_ENUM
 
Fields inherited from interface org.writersforge.catalan.layout.style.TextStyle
WRAP_CHARACTER, WRAP_ENUM, WRAP_NEVER, WRAP_PHRASE, WRAP_SENTENCE, WRAP_WORD
 
Fields inherited from interface org.writersforge.catalan.layout.style.AlignStyle
ALIGN_BOTTOM, ALIGN_CENTER, ALIGN_ENUM, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_TOP
 
Constructor Summary
StyleChain()
          Creates a new empty instance of StyleChain.
StyleChain(StyleChain copy)
          Creates a new instance of StyleChain using the copy as a template.
 
Method Summary
 void addAllStyle(AllStyle allStyle)
          Adds an AllStyle to the front of the lookup chain.
 void addAreaStyle(AreaStyle areaStyle)
          Adds a AreaStyle to the front of the lookup chain.
 void addFontStyle(FontStyle fontStyle)
          Adds a FontStyle to the front of the lookup chain.
 void addTextStyle(TextStyle textStyle)
          Adds a TextStyle to the front of the lookup chain.
 AreaStyle[] getAreaStyles()
          Returns an array of all AreaStyle objects in this chain.
 java.awt.Color getBackgroundColor()
          Returns the background color of this area.
 java.awt.Color getBorderColor()
          Returns the color of the border enclosing this area.
 int getBorderWidth()
          Returns the width of the border enclosing this area.
 FontStyle getDefaultFont()
          Returns the default FontStyle of this text.
 java.lang.String getDescription()
          Returns an optional text description of this area.
 int getFirstLineIndent()
          Returns the first line indent property of this text.
 java.awt.Color getFontColor()
          Returns the color of this run of text.
 int getFontHeight()
          Estimates the height of the font in point size.
 java.lang.String getFontName()
          Returns the font name property of the style.
 int getFontSize()
          Returns the font size property of the style.
 int getFontStyle()
          Returns the font style property of the style.
 FontStyle[] getFontStyles()
          Returns an array of all FontStyle objects in this chain.
 int getHAlign()
          Returns the horizontal alignment property of the style.
 int getIndent()
          Returns the left indent spacing of this area.
 java.awt.Insets getInsets()
          Returns an Insets object set to the values of all four InsetStyle properties, indent, rightIndent, spaceBefore, and spaceAfter.
 java.awt.Dimension getMaximum()
          Returns the maximum geometrical extents of this area.
 java.awt.Dimension getMinimum()
          Returns the minimum geometrical extents of this area.
 java.awt.Dimension getPreferred()
          Returns the preferred geometrical extents of this area.
 int getRightIndent()
          Returns the right indent spacing of this area.
 int getSpaceAfter()
          Returns the bottom indent spacing of this area.
 int getSpaceBefore()
          Returns the top indent spacing of this area.
 TextStyle[] getTextStyles()
          Returns an array of all TextStyle objects in this chain.
 int getVAlign()
          Returns the vertical alignment property of the style.
 int getWrap()
          Returns the wrap style of this text, according to the WRAP_xxx enumeration.
 boolean isBreakable()
          Returns the atomic property of this text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StyleChain

public StyleChain()
Creates a new empty instance of StyleChain.


StyleChain

public StyleChain(StyleChain copy)
Creates a new instance of StyleChain using the copy as a template.

Parameters:
copy - the StyleChain to copy into the new one
Method Detail

addAllStyle

public void addAllStyle(AllStyle allStyle)
Adds an AllStyle to the front of the lookup chain. The most recently added style will be checked first. This essentially calls addFontStyle(), addTextStyle(), and addAreaStyle() with the allStyle object.

Parameters:
allStyle - the style to add to the front of the list

addFontStyle

public void addFontStyle(FontStyle fontStyle)
Adds a FontStyle to the front of the lookup chain. The most recently added style will be checked first.

Parameters:
fontStyle - the style to add to the front of the list

getFontStyles

public FontStyle[] getFontStyles()
Returns an array of all FontStyle objects in this chain.

Returns:
an array of FontStyle objects

addTextStyle

public void addTextStyle(TextStyle textStyle)
Adds a TextStyle to the front of the lookup chain. The most recently added style will be checked first.

Parameters:
textStyle - the style to add to the front of the list

getTextStyles

public TextStyle[] getTextStyles()
Returns an array of all TextStyle objects in this chain.

Returns:
an array of TextStyle objects

addAreaStyle

public void addAreaStyle(AreaStyle areaStyle)
Adds a AreaStyle to the front of the lookup chain. The most recently added style will be checked first.

Parameters:
areaStyle - the style to add to the front of the list

getAreaStyles

public AreaStyle[] getAreaStyles()
Returns an array of all AreaStyle objects in this chain.

Returns:
an array of AreatStyle objects

getFontName

public java.lang.String getFontName()
Returns the font name property of the style.

Specified by:
getFontName in interface FontStyle
Returns:
the font name for this style

getFontStyle

public int getFontStyle()
Returns the font style property of the style.

Specified by:
getFontStyle in interface FontStyle
Returns:
the font style for this style

getFontSize

public int getFontSize()
Returns the font size property of the style.

Specified by:
getFontSize in interface FontStyle
Returns:
the font size (in points) for this style

getFontHeight

public int getFontHeight()
Estimates the height of the font in point size. Not a true measure of the font height, but can be used for rough estimates.

Specified by:
getFontHeight in interface FontStyle
Returns:
the height of the font in point size

getFontColor

public java.awt.Color getFontColor()
Returns the color of this run of text.

Specified by:
getFontColor in interface FontStyle
Returns:
the text color

getDefaultFont

public FontStyle getDefaultFont()
Returns the default FontStyle of this text.

Specified by:
getDefaultFont in interface TextStyle
Returns:
the default FontStyle for this text

getWrap

public int getWrap()
Returns the wrap style of this text, according to the WRAP_xxx enumeration. The behavior of phrase and sentence wrapping may be dependent on the nature of the text.

Specified by:
getWrap in interface TextStyle
Returns:
the wrap style

getFirstLineIndent

public int getFirstLineIndent()
Returns the first line indent property of this text.

Specified by:
getFirstLineIndent in interface TextStyle
Returns:
the first line indent value for this text

isBreakable

public boolean isBreakable()
Returns the atomic property of this text. Atomic text cannot be broken apart, or wrapped to another page.

Specified by:
isBreakable in interface AreaStyle
Returns:
the atomic value for this text

getHAlign

public int getHAlign()
Returns the horizontal alignment property of the style. The returned value should be one of ALIGN_LEFT, ALIGN_CENTER, or ALIGN_RIGHT.

Specified by:
getHAlign in interface AlignStyle
Returns:
the horizontal alignment

getVAlign

public int getVAlign()
Returns the vertical alignment property of the style. The returned value should be one of ALIGN_TOP, ALIGN_CENTER, or ALIGN_BOTTOM.

Specified by:
getVAlign in interface AlignStyle
Returns:
the vertical alignment

getIndent

public int getIndent()
Returns the left indent spacing of this area.

Specified by:
getIndent in interface InsetStyle
Returns:
the left indent spacing

getRightIndent

public int getRightIndent()
Returns the right indent spacing of this area.

Specified by:
getRightIndent in interface InsetStyle
Returns:
the right indent spacing

getSpaceBefore

public int getSpaceBefore()
Returns the top indent spacing of this area.

Specified by:
getSpaceBefore in interface InsetStyle
Returns:
the top indent spacing

getSpaceAfter

public int getSpaceAfter()
Returns the bottom indent spacing of this area.

Specified by:
getSpaceAfter in interface InsetStyle
Returns:
the bottom indent spacing

getInsets

public java.awt.Insets getInsets()
Returns an Insets object set to the values of all four InsetStyle properties, indent, rightIndent, spaceBefore, and spaceAfter.

Specified by:
getInsets in interface InsetStyle
Returns:
an Insets object for this style

getPreferred

public java.awt.Dimension getPreferred()
Returns the preferred geometrical extents of this area. These extents should be followed if possible, but can be ignored if necessary. This implementation allows for extents from different styles, for example if the width is specified in the local style, but the height is specified in a style later in the chain.

Specified by:
getPreferred in interface ExtentStyle
Returns:
the preferred extents

getMinimum

public java.awt.Dimension getMinimum()
Returns the minimum geometrical extents of this area. These extents should be followed at all costs, even if clipping or overflow occurs because of it. This implementation allows for extents from different styles, for example if the width is specified in the local style, but the height is specified in a style later in the chain. Any unspecified extent should fall back on the preferred value.

Specified by:
getMinimum in interface ExtentStyle
Returns:
the minimum extents

getMaximum

public java.awt.Dimension getMaximum()
Returns the maximum geometrical extents of this area. These extents should be followed at all costs, even if clipping or overflow occurs because of it. This implementation allows for extents from different styles, for example if the width is specified in the local style, but the height is specified in a style later in the chain.

Specified by:
getMaximum in interface ExtentStyle
Returns:
the maximum extents

getBorderWidth

public int getBorderWidth()
Returns the width of the border enclosing this area.

Specified by:
getBorderWidth in interface BorderStyle
Returns:
the border width

getBorderColor

public java.awt.Color getBorderColor()
Returns the color of the border enclosing this area.

Specified by:
getBorderColor in interface BorderStyle
Returns:
the border color

getBackgroundColor

public java.awt.Color getBackgroundColor()
Returns the background color of this area.

Specified by:
getBackgroundColor in interface AreaStyle
Returns:
the background color

getDescription

public java.lang.String getDescription()
Returns an optional text description of this area.

Specified by:
getDescription in interface AreaStyle
Returns:
text description