EchoPoint
1.0

echopoint.util
Class FontKit

java.lang.Object
  extended byechopoint.util.FontKit

public class FontKit
extends java.lang.Object

A utility to class to help with Font manipulation

Author:
Brad Baker

Field Summary
static java.lang.String[] EchoFontStrings
          Constant array for Echo Font strings
static java.lang.String[][] EchoFontValues
          Constant array for Echo Font Values
static java.lang.String[] FontStyleStrings
          Constant array for Echo Font Style strings
 
Method Summary
static void addBold(nextapp.echo.Component c)
          Adds bold to a Component's font.
static nextapp.echo.Font addBold(nextapp.echo.Font f)
          Adds the Font.BOLD attribute to an exisitng Font object and returns a new Font.
static void addItalic(nextapp.echo.Component c)
          Adds italic to a Component's font.
static nextapp.echo.Font addItalic(nextapp.echo.Font f)
          Adds the Font.ITALIC attribute to an exisitng Font object and returns a new Font.
static void addSize(nextapp.echo.Component c, int sizeDelta)
          Sets a component's font smaller or large by the specified delta amount.
static nextapp.echo.Font addSize(nextapp.echo.Font f, int sizeDelta)
          Makes a font smaller or larger by adding the specified amount to its current font size.
static void addStyle(nextapp.echo.Component c, int style)
          Adds the specified style to a Component's font.
static nextapp.echo.Font addStyle(nextapp.echo.Font f, int style)
          Adds the specified style to the Font and returns a new Font.
static void addUnderline(nextapp.echo.Component c)
          Adds underline to a Component's font.
static nextapp.echo.Font addUnderline(nextapp.echo.Font f)
          Adds the Font.UNDERLINE attribute to an exisitng Font object and returns a new Font.
static nextapp.echo.Font findFont(nextapp.echo.Component comp)
          Searchs the heirarchy tree of the component and finds the first non null Font object.
static nextapp.echo.Font font(java.lang.String fontString)
          Shortcut synonym for makeFont(fontString);
static boolean isFontString(java.lang.String fontString)
          Returns true if the fontString is a valid representation of a Font value.
static java.awt.Font makeAwtFont(nextapp.echo.Font echoFont, java.awt.Font awtDefaultFont)
          Creates an AWT font object from a Echo font object.
static java.lang.String makeCSSFont(nextapp.echo.Font f)
          Makes a W3C CSS font string in the special format fontstyle, fontsize, fontnames
static nextapp.echo.Font makeFont(java.lang.String fontString)
          Returns the Font value of the given Font string representation.
static java.lang.String makeFontString(nextapp.echo.Font f)
          Makes a string representation of a font in the format font(fontName, fontStyle, fontSize) where : fontName - is a font name such as 'Verdana' or 'Times New Roman'.
static void setBold(nextapp.echo.Component c)
          Sets Component's font to bold.
static void setItalic(nextapp.echo.Component c)
          Sets Component's font to italic.
static nextapp.echo.Font setName(nextapp.echo.Font font, java.lang.String fontName)
          Returns a new Font object, based on font, that has the specified fontName.
static nextapp.echo.Font setNames(nextapp.echo.Font font, java.lang.String[] fontNames)
          Returns a new Font object, based on font, that has the specified fontNames.
static void setSize(nextapp.echo.Component c, int size)
          Sets the size of a Component's font.
static nextapp.echo.Font setSize(nextapp.echo.Font font, int size)
          Returns a new Font object, based on font, that has the specified size.
static nextapp.echo.Font setStyle(nextapp.echo.Font font, int style)
          Returns a new Font object, based on font, that has the specified style.
static void setUnderline(nextapp.echo.Component c)
          Sets Component's font to underline.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FontStyleStrings

public static java.lang.String[] FontStyleStrings
Constant array for Echo Font Style strings


EchoFontStrings

public static java.lang.String[] EchoFontStrings
Constant array for Echo Font strings


EchoFontValues

public static java.lang.String[][] EchoFontValues
Constant array for Echo Font Values

Method Detail

makeAwtFont

public static java.awt.Font makeAwtFont(nextapp.echo.Font echoFont,
                                        java.awt.Font awtDefaultFont)
Creates an AWT font object from a Echo font object. This is useful for drawing on AWT images.

Parameters:
echoFont - - the nextapp.echo.Font object to convert
awtDefaultFont - - a default AWT font to use if the conversion cant be done.
Returns:
- a new java.awt.Font object base don echoFont.

makeCSSFont

public static java.lang.String makeCSSFont(nextapp.echo.Font f)
Makes a W3C CSS font string in the special format

fontstyle, fontsize, fontnames

Parameters:
f - - the font to represent as a W3C CSS string
Returns:
the W3C CSS string represenation

addBold

public static void addBold(nextapp.echo.Component c)
Adds bold to a Component's font.

If the component has no font, a findFont is performed and the result is set in as the font.

Parameters:
c - - the component in question
See Also:
addBold(Font)

addItalic

public static void addItalic(nextapp.echo.Component c)
Adds italic to a Component's font.

If the component has no font, a findFont is performed and the result is set in as the font.

Parameters:
c - - the component in question
See Also:
addItalic(Font)

addUnderline

public static void addUnderline(nextapp.echo.Component c)
Adds underline to a Component's font.

If the component has no font, a findFont is performed and the result is set in as the font.

Parameters:
c - - the component in question
See Also:
addUnderline(Font)

addStyle

public static void addStyle(nextapp.echo.Component c,
                            int style)
Adds the specified style to a Component's font.

If the component has no font, a findFont is performed and the result is set in as the font.

Parameters:
c - - the component in question
See Also:
addStyle(Font, int)

addSize

public static void addSize(nextapp.echo.Component c,
                           int sizeDelta)
Sets a component's font smaller or large by the specified delta amount.

If the component has no font, a findFont is performed and the result is set in as the font.

Parameters:
c - - the component in question
sizeDelta - - a positive or negative delta amount
See Also:
addSize(Font, int)

setBold

public static void setBold(nextapp.echo.Component c)
Sets Component's font to bold.

If the component has no font, a findFont is performed and the result is set in as the font.

Parameters:
c - - the component in question
See Also:
setStyle(Font, int)

setItalic

public static void setItalic(nextapp.echo.Component c)
Sets Component's font to italic.

If the component has no font, a findFont is performed and the result is set in as the font.

Parameters:
c - - the component in question
See Also:
setStyle(Font, int)

setUnderline

public static void setUnderline(nextapp.echo.Component c)
Sets Component's font to underline.

If the component has no font, a findFont is performed and the result is set in as the font.

Parameters:
c - - the component in question
See Also:
setStyle(Font, int)

setSize

public static void setSize(nextapp.echo.Component c,
                           int size)
Sets the size of a Component's font.

If the component has no font, a findFont is performed and the result is set in as the font.

Parameters:
c - - the component in question
size - - the new font size
See Also:
setSize(Font, int)

findFont

public static nextapp.echo.Font findFont(nextapp.echo.Component comp)
Searchs the heirarchy tree of the component and finds the first non null Font object. It will return EchoInstance.DEFAULT_FONT if no ancestor components have a Font set.


makeFont

public static nextapp.echo.Font makeFont(java.lang.String fontString)
Returns the Font value of the given Font string representation.

The allowable forms are :

- fontName,fontStyle,fontSize
- font( fontName, fontStyle, fontSize)

where

fontName - eg. Verdana or 'Times New Roman'. If multiple font names are specified or there is white space in the font name, then it must be enclosed in single quotes and commas eg. 'Verdana, Times New Roman, Tahoma'.
fontStyle - PLAIN|BOLD|ITALIC|UNDERLINE or nothing! (this is case insenstive)
fontSize - an integer size value

Examples :

 	Verdana,,9 									- is a legal font string
 	Verdana,PLAIN,9 							- is a legal font string
 	Verdana,plain,9 							- is a legal font string
 	Verdana,bold|italic,9						- is a legal font string
 	'Times New Roman',plain,9 					- is a legal font string
 	'Verdana, Times New Roman',plain,9 			- is a legal font string
 
 	font(Verdana,,9)							- is a legal font string
 	font(Verdana,PLAIN,9)						- is a legal font string
 	font(Verdana,plain,9)						- is a legal font string
 	font(Verdana,bold|italic,9)					- is a legal font string
 	font('Verdana, Times New Roman',plain,9)	- is a legal font string
 
 	Verdana, 3, 9								- is an ILLEGAL font string
 	Verdana, Times New Roman,PLAIN,9			- is an ILLEGAL font string
 	font(Verdana, 3, 9)							- is an ILLEGAL font string
 	font(Verdana, Times New Roman,PLAIN,9)		- is an ILLEGAL font string
 

The results of this operations is cached in a global static cache, so that Font objects can be re-used. This is okay since Font objects are immutable once created.

Parameters:
fontString - - the font string in question
Returns:
a new Font object
Throws:
java.lang.IllegalArgumentException - - if the fontString is in an invalid format

font

public static nextapp.echo.Font font(java.lang.String fontString)
Shortcut synonym for makeFont(fontString);

See Also:
makeFont(String)

isFontString

public static boolean isFontString(java.lang.String fontString)
Returns true if the fontString is a valid representation of a Font value.

The allowable forms are :

- fontName,fontStyle,fontSize
- font( fontName, fontStyle, fontSize)

where

fontName - eg. Verdana or 'Times New Roman'. If multiple font names are specified or there is white space in the font name, then it must be enclosed in single quotes and commas eg. 'Verdana, Times New Roman, Tahoma'.
fontStyle - PLAIN|BOLD|ITALIC|UNDERLINE or nothing! (this is case insenstive)
fontSize - an integer size value

Examples :

 	Verdana,,9 									- is a legal font string
 	Verdana,PLAIN,9 							- is a legal font string
 	Verdana,plain,9 							- is a legal font string
 	Verdana,bold|italic,9						- is a legal font string
 	'Times New Roman',plain,9 					- is a legal font string
 	'Verdana, Times New Roman',plain,9 			- is a legal font string
 
 	font(Verdana,,9)							- is a legal font string
 	font(Verdana,PLAIN,9)						- is a legal font string
 	font(Verdana,plain,9)						- is a legal font string
 	font(Verdana,bold|italic,9)					- is a legal font string
 	font('Verdana, Times New Roman',plain,9)	- is a legal font string
 
 	Verdana, 3, 9								- is an ILLEGAL font string
 	Verdana, Times New Roman,PLAIN,9			- is an ILLEGAL font string
 	font(Verdana, 3, 9)							- is an ILLEGAL font string
 	font(Verdana, Times New Roman,PLAIN,9)		- is an ILLEGAL font string
 

Parameters:
fontString - - the font string representation to check
Returns:
true if the string is in the correct format

makeFontString

public static java.lang.String makeFontString(nextapp.echo.Font f)
Makes a string representation of a font in the format

font(fontName, fontStyle, fontSize)

where :

fontName - is a font name such as 'Verdana' or 'Times New Roman'. fontStyle - PLAIN|BOLD|ITALIC|UNDERLINE fontSize - an integer size value

Parameters:
f - - the font to make into a String representation
Returns:
the string representation of the font

addBold

public static nextapp.echo.Font addBold(nextapp.echo.Font f)
Adds the Font.BOLD attribute to an exisitng Font object and returns a new Font.

Parameters:
f - - the font in question
Returns:
- a new Font object

addItalic

public static nextapp.echo.Font addItalic(nextapp.echo.Font f)
Adds the Font.ITALIC attribute to an exisitng Font object and returns a new Font.

Parameters:
f - - the font in question
Returns:
- a new Font object

addUnderline

public static nextapp.echo.Font addUnderline(nextapp.echo.Font f)
Adds the Font.UNDERLINE attribute to an exisitng Font object and returns a new Font.

Parameters:
f - - the font in question
Returns:
- a new Font object

addStyle

public static nextapp.echo.Font addStyle(nextapp.echo.Font f,
                                         int style)
Adds the specified style to the Font and returns a new Font.

Parameters:
f - - the font in question
style - - the new font style to added to the font
Returns:
- a new Font object

addSize

public static nextapp.echo.Font addSize(nextapp.echo.Font f,
                                        int sizeDelta)
Makes a font smaller or larger by adding the specified amount to its current font size. The Font is made smaller if a negative value is used.

Parameters:
f - - the font in question
sizeDelta - - the size delta to add to the current size
Returns:
- a new Font object

setSize

public static nextapp.echo.Font setSize(nextapp.echo.Font font,
                                        int size)
Returns a new Font object, based on font, that has the specified size.

Parameters:
font - - the font to use as a template
size - - the new size
Returns:
a new Font object with the new size

setStyle

public static nextapp.echo.Font setStyle(nextapp.echo.Font font,
                                         int style)
Returns a new Font object, based on font, that has the specified style.

Parameters:
font - - the font to use as a template
style - - the new style
Returns:
a new Font object with the new style

setNames

public static nextapp.echo.Font setNames(nextapp.echo.Font font,
                                         java.lang.String[] fontNames)
Returns a new Font object, based on font, that has the specified fontNames.

Parameters:
font - - the font to use as a template
fontNames - - an array of font names
Returns:
a new Font object with the new font names

setName

public static nextapp.echo.Font setName(nextapp.echo.Font font,
                                        java.lang.String fontName)
Returns a new Font object, based on font, that has the specified fontName.

If fontName has whitespace in it, then you need to surround it in single quotes.

Parameters:
font - - the font to use as a template
fontName - - the new font name to use
Returns:
a new Font object with the new font name

EchoPoint
1.0