Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.crosswire.common.swing
Class FontStore

    java.lang.Object
      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.

Author:
  DM Smith [dmsmith555 at yahoo dot com]
See Also:
  `for license details.
  The copyright to this program is held by it's authors.`

Field Summary
`private static String` | `DEFAULT_FONT`
`private static String` | `DEFAULT_KEY`
`private String` | `defaultFont`
`private Properties` | `fontMap`
`private URI` | `fontStore`
`private static String` | `LANG_KEY_PREFIX`
`private boolean` | `loaded`
`private static Logger` | `log`
`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, Language lang, String fallback)` Get a font for the specified resource.
`private void` | `load()` Load the store, if it has not been loaded.
`private Font` | `obtainFont(String fontSpec)`
`void` | `setDefaultFont(String defaultFont)`
`void` | `setFont(Language lang, Font font)` Store a font specification for the language.
`void` | `setFont(String resource, Font font)` Store a font specification for the resource.
`private 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

    private static final String DEFAULT_FONT

See Also:
  Constant Field Values

### storeName

    private String storeName

### defaultFont

    private String defaultFont

### fontStore

    private URI fontStore

### loaded

    private boolean loaded

### fontMap

    private Properties fontMap

### LANG_KEY_PREFIX

    private static final String LANG_KEY_PREFIX

See Also:
  Constant Field Values

### DEFAULT_KEY

    private static final String DEFAULT_KEY

See Also:
  Constant Field Values

### log

    private static final Logger log

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(Language lang,
                        Font font)

  Store a font specification for the language.

  Parameters:
    `lang` - the language
    `font` - the font

### getFont

    public Font getFont(String resource,
                        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.

### load

    private void load()

  Load the store, if it has not been loaded.

### store

    private void store()

  Store the store, if it exists.

### obtainFont

    private Font obtainFont(String fontSpec)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Copyright ¨ 2003-2007
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD