com.sptci.echo2.style
Class Font

java.lang.Object
  extended by nextapp.echo2.app.Font
      extended by com.sptci.echo2.style.Font
All Implemented Interfaces:
Serializable

public class Font
extends Font

A custom font class to use in styles. This class by default uses TYPEFACE as the Font.Typeface and ensures consistent font typeface across the application. It is recomended that you use the getInstance() method or its overloaded derivatives to avoid replication across sessions.

The following shows the recommended way to use this class:

   import com.sptci.echo2.style.Extent;
   import com.sptci.echo2.style.Font;

     ...
     Font normalFont = Font.getInstance();
     Font largeFont = Font.getInstance( Extent.getInstance( 14 ) );
     Font boldFont = Font.getInstance( Font.BOLD );
 

© Copyright 2006 Sans Pareil Technologies, Inc.

Version:
$Id: Font.java 3334 2007-06-08 16:25:49Z rakesh $
Author:
Rakesh Vidyadharan 2006-11-06
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class nextapp.echo2.app.Font
Font.Typeface
 
Field Summary
protected static Map<String,Map<String,Font>> cache
          The cache of reusable font instances.
protected static Map<String,Font> defaultCache
          The nested map used to store the fonts for the default TYPEFACE.
static Extent SIZE
          The default font size to use.
static int STYLE
          The default font style to use.
static Font.Typeface TYPEFACE
          The application wide default typeface.
 
Fields inherited from class nextapp.echo2.app.Font
ARIAL, BOLD, COURIER, COURIER_NEW, HELVETICA, ITALIC, LINE_THROUGH, MONOSPACE, OVERLINE, PLAIN, SANS_SERIF, SERIF, TIMES, TIMES_NEW_ROMAN, TIMES_ROMAN, UNDERLINE, VERDANA
 
Constructor Summary
Font()
          Deprecated. Use getInstance() instead.
Font(Extent size)
          Deprecated. Use getInstance( Extent ) instead.
Font(Font.Typeface typeface, int style, Extent size)
          Deprecated. Use getInstance( Font.Typeface, int, Extent ) instead.
Font(int style)
          Deprecated. Use getInstance( int ) instead.
Font(int style, Extent size)
          Deprecated. Use getInstance( int, Extent ) instead.
 
Method Summary
static Font getInstance()
          Factory method to use to retrieve the cached default font instance.
static Font getInstance(Extent size)
          Factory method to use to retrieve a cached font instance.
static Font getInstance(Font.Typeface typeface, Extent size)
          Deprecated. Warning, you are creating a non-standard font.
static Font getInstance(Font.Typeface typeface, int style, Extent size)
          Deprecated. Warning, you are creating a non-standard font.
static Font getInstance(int style)
          Factory method to use to retrieve a cached font instance.
static Font getInstance(int style, Extent size)
          Factory method to use to retrieve a cached font instance.
protected static String getKey(Extent size)
          Return a key for the extent specified.
protected static String getKey(Font.Typeface typeface)
          Return a key for the Font.Typeface chain.
protected static String getKey(int style, Extent size)
          Return a key for the style and extent specified.
protected static Map<String,Font> getMap(String typeface)
          Return the embedded Map value in cache.
 
Methods inherited from class nextapp.echo2.app.Font
equals, getSize, getTypeface, isBold, isItalic, isLineThrough, isOverline, isPlain, isUnderline, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPEFACE

public static final Font.Typeface TYPEFACE
The application wide default typeface.


SIZE

public static final Extent SIZE
The default font size to use.


STYLE

public static final int STYLE
The default font style to use.

See Also:
Constant Field Values

cache

protected static final Map<String,Map<String,Font>> cache
The cache of reusable font instances. A nested map structure is used to allow for future management based upon Font.Typeface values.


defaultCache

protected static final Map<String,Font> defaultCache
The nested map used to store the fonts for the default TYPEFACE.

Constructor Detail

Font

@Deprecated
public Font()
Deprecated. Use getInstance() instead.

Create a new instance of the font using the defaults for style and size.


Font

@Deprecated
public Font(int style)
Deprecated. Use getInstance( int ) instead.

Create a new instance of the font using the specified style and default size.

Parameters:
style - The style to use for the font. Styles are usually specified using the constants in the Font class.

Font

@Deprecated
public Font(Extent size)
Deprecated. Use getInstance( Extent ) instead.

Create a new instance of the font using the specified size and default style.

Parameters:
size - The font size to use.

Font

@Deprecated
public Font(int style,
                       Extent size)
Deprecated. Use getInstance( int, Extent ) instead.

Create a new instance of the font using the specified style and size.

Parameters:
style - The style to use for the font. Styles are usually specified using the constants in the Font class.
size - The font size to use.

Font

@Deprecated
public Font(Font.Typeface typeface,
                       int style,
                       Extent size)
Deprecated. Use getInstance( Font.Typeface, int, Extent ) instead.

Create a new instance of the font using the specified typeface chain, style and size.

Parameters:
typeface - The typeface chain to use for the font.
style - The style to use for the font. Styles are usually specified using the constants in the Font class.
size - The font size to use.
Method Detail

getInstance

public static Font getInstance()
Factory method to use to retrieve the cached default font instance.

See Also:
getInstance( int, Extent )

getInstance

public static Font getInstance(Extent size)
Factory method to use to retrieve a cached font instance.

Note: This method can be refactored to delegate to getInstance( Font.Typeface, Extent ), however has been left as a separate implementation to avoid the lookup process involved in getKey(nextapp.echo2.app.Extent).

Parameters:
size - The font size to use.
See Also:
getKey( Extent ), defaultCache

getInstance

public static Font getInstance(int style)
Factory method to use to retrieve a cached font instance.

Parameters:
style - The style to use for the font. Styles are usually specified using the constants in the Font class.
See Also:
getInstance( int, Extent )

getInstance

public static Font getInstance(int style,
                               Extent size)
Factory method to use to retrieve a cached font instance.

Note: This method can be refactored to delegate to getInstance( Font.Typeface, int, Extent ), however has been left as a separate implementation to avoid the normalisation process involved in getKey(nextapp.echo2.app.Extent).

Parameters:
style - The style to use for the font. Styles are usually specified using the constants in the Font class.
size - The font size to use.
See Also:
getKey( int, Extent ), defaultCache

getInstance

public static Font getInstance(Font.Typeface typeface,
                               Extent size)
Deprecated. Warning, you are creating a non-standard font.

Factory method to use to retrieve a cached font instance.

Parameters:
typeface - The typeface chain to use for the font.
size - The font size to use.
See Also:
getKey( Font.Typeface ), getKey( Extent ), getMap(java.lang.String)

getInstance

public static Font getInstance(Font.Typeface typeface,
                               int style,
                               Extent size)
Deprecated. Warning, you are creating a non-standard font.

Factory method to use to retrieve a cached font instance.

Parameters:
typeface - The typeface chain to use for the font.
style - The style to use for the font. Styles are usually specified using the constants in the Font class.
size - The font size to use.

getKey

protected static String getKey(Extent size)
Return a key for the extent specified.

Parameters:
size - The extent whose key is to be returned.
Returns:
The normalised key for the extent.

getKey

protected static String getKey(int style,
                               Extent size)
Return a key for the style and extent specified.

Parameters:
style - The style to use for the font.
size - The extent whose key is to be returned.
Returns:
The normalised key for the extent.

getKey

protected static String getKey(Font.Typeface typeface)
Return a key for the Font.Typeface chain.

Parameters:
typeface - The typeface whose key chain is to be returned.
Returns:
The key for the typeface chain.

getMap

protected static Map<String,Font> getMap(String typeface)
Return the embedded Map value in cache.

Parameters:
typeface - The key for the Font.Typeface.
Returns:
The embedded map.