org.jrabbit.base.graphics.font
Class FontCache

java.lang.Object
  extended by org.jrabbit.base.data.structures.BaseKeyedContainer<T>
      extended by org.jrabbit.base.data.cache.Cache<T>
          extended by org.jrabbit.base.data.cache.GroupedCache<Font>
              extended by org.jrabbit.base.graphics.font.FontCache
All Implemented Interfaces:
java.lang.Iterable<Font>, Destroyable, Factory<Font>, Accepter<Font>, Container<Font>, KeyedContainer<Font>, Remover<Font>

public class FontCache
extends GroupedCache<Font>

Rather obviously, a FontCache is a GroupedCache that contains Fonts. FontCache has one additional bit of functionality, however. It has a "default" font that it maintains a direct reference to. Whenever a font is requested that is not in the Cache, it automatically returns the default. Though a default font is automatically in place, any font in the Cache can be set as the default. Initially, the Cache is full and the default font is null. It's highly recommended to set the default font on startup. NOTE: It's really not recommended to use the "dynamic creation" capabilities of a Cache when dealing with Fonts. There are reasons: 1: Fonts are heavy-duty, and they take a long time to load. It's much better to the user if font loading takes place out-of-game. 2: The default FontRenderers work best if more than one String is used to instantiate them. For example, an AngelCodeRenderer requires both a path to a font file and a path to an image.

Author:
Chris Molini

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jrabbit.base.data.cache.GroupedCache
GroupedCache.EntryList
 
Field Summary
private  Font defaultFont
          The reference to the default font.
 
Fields inherited from class org.jrabbit.base.data.cache.GroupedCache
groups
 
Fields inherited from class org.jrabbit.base.data.structures.BaseKeyedContainer
contents, factory
 
Constructor Summary
FontCache()
          Creates a default, empty FontCache.
 
Method Summary
 Font defaultFont()
          Obtains the current default font.
 java.lang.String defaultFontName()
          Gets information about the default font.
 boolean setDefaultFont(java.lang.String font)
          Sets the default font.
 
Methods inherited from class org.jrabbit.base.data.cache.GroupedCache
addGroup, addGroup, addIntoGroup, addIntoGroup, addIntoGroup, addIntoGroup, clearGroups, destroyGroup, disgroup, emptyGroup, groups, objectsReferenced, objectsReferenced, removeFromGroup, wipeGroup
 
Methods inherited from class org.jrabbit.base.data.cache.Cache
destroy, get, get, removeAndDestroy, setTo
 
Methods inherited from class org.jrabbit.base.data.structures.BaseKeyedContainer
add, add, add, add, clear, contains, contains, create, createMap, factory, iterator, remove, remove, remove, remove, setFactory, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultFont

private Font defaultFont
The reference to the default font.

Constructor Detail

FontCache

public FontCache()
Creates a default, empty FontCache. The default font reference is null.

Method Detail

defaultFontName

public java.lang.String defaultFontName()
Gets information about the default font.

Returns:
The default font's name.

defaultFont

public Font defaultFont()
Obtains the current default font.

Returns:
A reference to the default font.

setDefaultFont

public boolean setDefaultFont(java.lang.String font)
Sets the default font.

Parameters:
font - The font identifier to find the desired font.
Returns:
Whether or not the assignment succeeded. This call fails if the indicated font is not in the Cache.