org.crosswire.common.swing
Class FontStore

java.lang.Object
  extended by org.crosswire.common.swing.FontStore
Direct Known Subclasses:
BookFont

public class FontStore
extends Object

Font Store maintains a persistent, hierarchical store of user font preferences. A font preference consists of the name of a resource and a font specification for that resource. The name of the resource may be any unique value that follows the rules for a property key. The font specification is the font itself or a string representation of the font that can be turned into a font with Font.decode(String).

Many languages share the same script. Rather than setting a font spec for many resources with the same language, this class makes it possible to set a font spec for each language.

Thus, the look up hierarchy begins with an exact match for the requested resource. If it does not work the lookup continues in the following order: the specified language's font, the fallback font, and the default font. Of course, if that does not work, use any font that Java thinks is appropriate, but use the size and style of the default font. Since scripts are shared by many languages, this FontStore supports the setting of Language defaults. If the requested language font does not exist a more general one will be provided.

Note: Some languages are represented as transliterations and others have more than one script, which may or may not be supported by a single font.

Author:
DM Smith
See Also:
The GNU General Public License for details.

Field Summary
protected static String DEFAULT_FONT
           
protected static String DEFAULT_KEY
           
private  String defaultFont
           
private  org.crosswire.common.util.PropertyMap fontMap
           
private  URI fontStore
           
protected static String LANG_KEY_PREFIX
           
private  boolean loaded
           
private static org.slf4j.Logger log
          The log stream
private  String storeName
           
 
Constructor Summary
FontStore(String storeName, URI fontDir)
          Create an new FontStore with the given persistent store.
 
Method Summary
 String getDefaultFont()
           
 Font getFont(String resource, org.crosswire.common.util.Language lang, String fallback)
          Get a font for the specified resource.
protected  org.crosswire.common.util.PropertyMap getFontMap()
           
protected  URI getFontStore()
           
protected  String getStoreName()
           
protected  boolean isLoaded()
           
protected  void load()
          Load the store, if it has not been loaded.
protected  Font obtainFont(String fontSpec)
           
 void resetFont(String key)
          Remove the font settings for a given key
 void setDefaultFont(String defaultFont)
           
 void setFont(org.crosswire.common.util.Language lang, Font font)
          Store a font specification for the language.
 void setFont(String resource, Font font)
          Store a font specification for the resource.
protected  void setFontMap(org.crosswire.common.util.PropertyMap fontMap)
           
protected  void setFontStore(URI fontStore)
           
protected  void setLoaded(boolean loaded)
           
protected  void setStoreName(String storeName)
           
protected  void store()
          Store the store, if it exists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_FONT

protected static final String DEFAULT_FONT
See Also:
Constant Field Values

LANG_KEY_PREFIX

protected static final String LANG_KEY_PREFIX
See Also:
Constant Field Values

DEFAULT_KEY

protected static final String DEFAULT_KEY
See Also:
Constant Field Values

storeName

private String storeName

defaultFont

private String defaultFont

fontStore

private URI fontStore

loaded

private boolean loaded

fontMap

private org.crosswire.common.util.PropertyMap fontMap

log

private static final org.slf4j.Logger log
The log stream

Constructor Detail

FontStore

public FontStore(String storeName,
                 URI fontDir)
Create an new FontStore with the given persistent store.

Parameters:
storeName - The name of the store, used as a file name and as a label inside the fontStore.
fontDir - The location where the fontStore can be stored.
Method Detail

getDefaultFont

public String getDefaultFont()
Returns:
the defaultFont

setDefaultFont

public void setDefaultFont(String defaultFont)
Parameters:
defaultFont - the defaultFont to set

setFont

public void setFont(String resource,
                    Font font)
Store a font specification for the resource.

Parameters:
resource - the resource
font - the font

setFont

public void setFont(org.crosswire.common.util.Language lang,
                    Font font)
Store a font specification for the language.

Parameters:
lang - the language
font - the font

resetFont

public void resetFont(String key)
Remove the font settings for a given key

Parameters:
key - the book initials or language code

getFont

public Font getFont(String resource,
                    org.crosswire.common.util.Language lang,
                    String fallback)
Get a font for the specified resource. If it does not work try the following in order: the specified language's font, the fallback font, and the default font. Of course, if that does not work, use any font that Java thinks is appropriate, but use the size and style of the default font.

Parameters:
resource - the name of the resource for whom the font is stored.
lang - the language of the resource
fallback - the fontspec for the fallback font
Returns:
the requested font if possible. A fallback font otherwise.

getStoreName

protected String getStoreName()
Returns:
the storeName

setStoreName

protected void setStoreName(String storeName)
Parameters:
storeName - the storeName to set

getFontStore

protected URI getFontStore()
Returns:
the fontStore

setFontStore

protected void setFontStore(URI fontStore)
Parameters:
fontStore - the fontStore to set

isLoaded

protected boolean isLoaded()
Returns:
the loaded

setLoaded

protected void setLoaded(boolean loaded)
Parameters:
loaded - the loaded to set

getFontMap

protected org.crosswire.common.util.PropertyMap getFontMap()
Returns:
the fontMap

setFontMap

protected void setFontMap(org.crosswire.common.util.PropertyMap fontMap)
Parameters:
fontMap - the fontMap to set

load

protected void load()
Load the store, if it has not been loaded.


store

protected void store()
Store the store, if it exists.


obtainFont

protected Font obtainFont(String fontSpec)

Copyright ยจ 2003-2015