jimm.datavision.field
Class Format

java.lang.Object
  extended by java.util.Observable
      extended by jimm.datavision.field.Format
All Implemented Interfaces:
java.lang.Cloneable, Writeable
Direct Known Subclasses:
DefaultFormat

public class Format
extends java.util.Observable
implements Writeable, java.lang.Cloneable

A format describes how to display a field. It specifies font family name, size, attributes (bold, italic, underline, wrap), alignment, and print format.

If a field's value is null, then the getter returns the value of the report's default field's format (which will never be null.

Author:
Jim Menard, jimm@io.com

Field Summary
protected  java.lang.Integer align
           
static int ALIGN_CENTER
          Used to specify center alignment.
static int ALIGN_LEFT
          Used to specify left alignment.
static int ALIGN_RIGHT
          Used to specify right alignment.
protected  java.lang.Boolean bold
           
protected  java.awt.Color color
           
protected static java.awt.Color DEFAULT_COLOR
           
protected static java.lang.String DEFAULT_FONT_FAMILY_NAME
           
protected static int DEFAULT_SIZE
           
protected  Field field
           
protected  java.awt.Font font
           
protected  java.lang.String fontFamilyName
           
protected  java.lang.String format
           
protected  java.lang.Boolean italic
           
protected  java.lang.Double size
           
protected  java.lang.Boolean underline
           
protected  java.lang.Boolean wrap
           
 
Constructor Summary
Format()
          Constructor.
 
Method Summary
static int alignFromString(java.lang.String s)
          Returns an ALIGN_* constant, given one of "left", "center", or "right".
static java.lang.String alignToString(int align)
          Given an ALIGN_* constant, return the string used to represent that value in a report XML file.
 void clearFontCache()
          Clears the font we may be holding on to.
 java.lang.Object clone()
          Returns a clone of this format.
static Format createDefaultFormat()
           
static Format createEmptyFormat()
           
 boolean equals(java.lang.Object obj)
           
protected  void fillClonedField(Format f)
           
 int getAlign()
          Returns the alignment.
 java.awt.Color getColor()
          Returns the color for this format.
 Format getDefaultFormat()
          Returns this field's report's default field's format (*whew*).
 java.awt.Font getFont()
          Based on our font family name, alignment flags, and size, return a font.
 java.lang.String getFontFamilyName()
          Returns the font family name for this format.
 java.lang.String getFormat()
          Returns the format string for this field.
 double getSize()
          Returns the size for this format.
 int hashCode()
           
 boolean isBold()
          Returns the bold state.
 boolean isItalic()
          Returns the italic state.
 boolean isUnderline()
          Returns the underline state.
 boolean isWrap()
          Returns the wrap state.
 void setAlign(int newAlign)
          Sets the alignment.
 void setBold(boolean newBold)
          Sets the bold state.
 void setColor(java.awt.Color newColor)
          Sets the color
(package private)  void setField(Field f)
          Normally you don't need to call this, because Field.setFormat(jimm.datavision.field.Format) calls this.
 void setFontFamilyName(java.lang.String newFontFamilyName)
          Sets the font family name
 void setFormat(java.lang.String newFormat)
          Sets the format string.
 void setItalic(boolean newItalic)
          Sets the italic state.
 void setSize(double newSize)
          Sets the size
 void setUnderline(boolean newUnderline)
          Sets the underline state.
 void setWrap(boolean newWrap)
          Sets the wrap state.
 java.lang.String toString()
          Returns a string representation of this format.
 void writeXML(XMLWriter out)
          Writes this format as an XML tag.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_FONT_FAMILY_NAME

protected static final java.lang.String DEFAULT_FONT_FAMILY_NAME
See Also:
Constant Field Values

DEFAULT_SIZE

protected static final int DEFAULT_SIZE
See Also:
Constant Field Values

DEFAULT_COLOR

protected static final java.awt.Color DEFAULT_COLOR

ALIGN_LEFT

public static final int ALIGN_LEFT
Used to specify left alignment.

See Also:
Constant Field Values

ALIGN_CENTER

public static final int ALIGN_CENTER
Used to specify center alignment.

See Also:
Constant Field Values

ALIGN_RIGHT

public static final int ALIGN_RIGHT
Used to specify right alignment.

See Also:
Constant Field Values

field

protected Field field

fontFamilyName

protected java.lang.String fontFamilyName

size

protected java.lang.Double size

bold

protected java.lang.Boolean bold

italic

protected java.lang.Boolean italic

underline

protected java.lang.Boolean underline

wrap

protected java.lang.Boolean wrap

align

protected java.lang.Integer align

format

protected java.lang.String format

color

protected java.awt.Color color

font

protected java.awt.Font font
Constructor Detail

Format

Format()
Constructor. Creates an empty format.

Method Detail

alignFromString

public static int alignFromString(java.lang.String s)
Returns an ALIGN_* constant, given one of "left", "center", or "right". If the specified string is null or is not one of these values, ALIGN_LEFT is returned.

Parameters:
s - the string "left", "center", or "right" (case is not significant)
Returns:
one of ALIGN_LEFT, ALIGN_CENTER, or ALIGN_RIGHT

alignToString

public static java.lang.String alignToString(int align)
Given an ALIGN_* constant, return the string used to represent that value in a report XML file. If align is not one of those values, returns "left".

Parameters:
align - one of "left", "center", or "right"

createEmptyFormat

public static Format createEmptyFormat()

createDefaultFormat

public static Format createDefaultFormat()

setField

void setField(Field f)
Normally you don't need to call this, because Field.setFormat(jimm.datavision.field.Format) calls this.

Parameters:
f - a field

clone

public java.lang.Object clone()
Returns a clone of this format.

Overrides:
clone in class java.lang.Object

fillClonedField

protected void fillClonedField(Format f)

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getDefaultFormat

public Format getDefaultFormat()
Returns this field's report's default field's format (*whew*).


getFontFamilyName

public java.lang.String getFontFamilyName()
Returns the font family name for this format.

Returns:
the font family name

setFontFamilyName

public void setFontFamilyName(java.lang.String newFontFamilyName)
Sets the font family name

Parameters:
newFontFamilyName - the new font family name

getFont

public java.awt.Font getFont()
Based on our font family name, alignment flags, and size, return a font. Never returns null.

Returns:
a font; never null

clearFontCache

public void clearFontCache()
Clears the font we may be holding on to.


getSize

public double getSize()
Returns the size for this format.

Returns:
the size

setSize

public void setSize(double newSize)
Sets the size

Parameters:
newSize - the new size

isBold

public boolean isBold()
Returns the bold state.

Returns:
the bold state

setBold

public void setBold(boolean newBold)
Sets the bold state.

Parameters:
newBold - the new value

isItalic

public boolean isItalic()
Returns the italic state.

Returns:
the italic state

setItalic

public void setItalic(boolean newItalic)
Sets the italic state.

Parameters:
newItalic - the new value

isUnderline

public boolean isUnderline()
Returns the underline state.

Returns:
the underline state

setUnderline

public void setUnderline(boolean newUnderline)
Sets the underline state.

Parameters:
newUnderline - the new underline state

isWrap

public boolean isWrap()
Returns the wrap state.

Returns:
the wrap state

setWrap

public void setWrap(boolean newWrap)
Sets the wrap state.

Parameters:
newWrap - the new wrap state

getAlign

public int getAlign()
Returns the alignment.

Returns:
one of the ALIGN_* values

setAlign

public void setAlign(int newAlign)
Sets the alignment.

Parameters:
newAlign - one of the ALIGN_* values

getFormat

public java.lang.String getFormat()
Returns the format string for this field. May return null.

Returns:
the format string, possibly null

setFormat

public void setFormat(java.lang.String newFormat)
Sets the format string.

Parameters:
newFormat - the new format string

getColor

public java.awt.Color getColor()
Returns the color for this format.

Returns:
the color

setColor

public void setColor(java.awt.Color newColor)
Sets the color

Parameters:
newColor - the new color

toString

public java.lang.String toString()
Returns a string representation of this format. Mainly used for debugging.

Overrides:
toString in class java.lang.Object
Returns:
pretty string, inn't it?

writeXML

public void writeXML(XMLWriter out)
Writes this format as an XML tag. Only writes the differences between this format and the default one.

Specified by:
writeXML in interface Writeable
Parameters:
out - a writer that knows how to write XML