com.taco.i18n.gui
Class FontUtilities

java.lang.Object
  extended by com.taco.i18n.gui.FontUtilities

public class FontUtilities
extends java.lang.Object

Utility functions for getting fonts appropriate for locales.


Nested Class Summary
static class FontUtilities.DefaultFontMapper
          A default implementation of IFontMapper.
static interface FontUtilities.IFontMapper
           
 
Field Summary
protected static java.awt.Font _DEFAULT_SERIF_FONT
          A prototypical font for the current platform used to determine if the current platform can display characters in different locales.
protected static java.util.Map _localeToFontsMap
          A map from locale to arrays of fonts that that can display characters in the locale, made plain and one-point.
 
Constructor Summary
FontUtilities()
           
 
Method Summary
static void adjustFontsForLocale(java.awt.Component component, java.util.Locale locale)
          Call adjustFontsForLocale(Locale.getDefault(), component, locale, true, DefaultFontMapper.instance).
static javax.swing.border.Border adjustFontsForLocale(java.util.Locale oldLocale, javax.swing.border.Border border, java.util.Locale locale, FontUtilities.IFontMapper fontMapper)
          Return a border that may be adjusted so that it can display characters in the argument locale.
static void adjustFontsForLocale(java.util.Locale oldLocale, java.awt.Component component, java.util.Locale locale, boolean recurse, FontUtilities.IFontMapper fontMapper)
          Adjust the font for the component and its border so that it can display characters of locale.
static java.awt.Font[] getFontsForLocale(java.util.Locale locale)
          Return an array of fonts that can display characters for the argument locale.
static boolean isCompatible(java.awt.Font font, java.util.Locale locale)
          Return true if the argument font can display characters in the argument locale.
static boolean usesChineseCharacters(java.util.Locale locale)
          Return true if Chinese characters are used in the argument locale.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_localeToFontsMap

protected static final java.util.Map _localeToFontsMap
A map from locale to arrays of fonts that that can display characters in the locale, made plain and one-point. The mapped array of fonts may be empty if no font was found that can display characters in the locale.


_DEFAULT_SERIF_FONT

protected static final java.awt.Font _DEFAULT_SERIF_FONT
A prototypical font for the current platform used to determine if the current platform can display characters in different locales.

Constructor Detail

FontUtilities

public FontUtilities()
Method Detail

getFontsForLocale

public static final java.awt.Font[] getFontsForLocale(java.util.Locale locale)

Return an array of fonts that can display characters for the argument locale. Otherwise, consult the cached map from locale to fonts. If an entry exists, return it. Otherwise, scan all fonts on the system for fonts capable of displaying characters in the argument locale. If no font that can display characters for the locale can be found, return an empty array. The returned array is a clone of the array stored by this class, so it may be modified.

This method tests if a font can display characters of a locale by seeing if it can display the locale's display name, in the argument locale.


adjustFontsForLocale

public static void adjustFontsForLocale(java.awt.Component component,
                                        java.util.Locale locale)
                                 throws java.awt.FontFormatException
Call adjustFontsForLocale(Locale.getDefault(), component, locale, true, DefaultFontMapper.instance).

Throws:
java.awt.FontFormatException

adjustFontsForLocale

public static void adjustFontsForLocale(java.util.Locale oldLocale,
                                        java.awt.Component component,
                                        java.util.Locale locale,
                                        boolean recurse,
                                        FontUtilities.IFontMapper fontMapper)
                                 throws java.awt.FontFormatException
Adjust the font for the component and its border so that it can display characters of locale. If recursive is true, adjust fonts for any components contained by component, recursively, unless a component is an instance of IFontAdjustedOnLocaleChange. If the font of component needs to be adjusted, do so whether or not it is an instance of IFontAdjustedOnLocaleChange.

Parameters:
oldLocale - The current locale of the component. May by null if unknown.
component - The component to modify.
locale - The target locale for the component.
recurse - If true, adjust fonts for all contained components, recursively.
fontMapper - The strategy for transforming original fonts to new ones.
Throws:
java.awt.FontFormatException - if no fonts can be found to display characters in the target locale.

adjustFontsForLocale

public static javax.swing.border.Border adjustFontsForLocale(java.util.Locale oldLocale,
                                                             javax.swing.border.Border border,
                                                             java.util.Locale locale,
                                                             FontUtilities.IFontMapper fontMapper)
                                                      throws java.awt.FontFormatException
Return a border that may be adjusted so that it can display characters in the argument locale. If the border doesn't need to be adjusted, return the same border.

Parameters:
oldLocale - The current locale of the border. May by null if unknown.
border - The border to .
locale - The target locale for the border.
fontMapper - The strategy for transforming original fonts to new ones.
Throws:
java.awt.FontFormatException - Thrown if no fonts can be found to display characters in the target locale.

isCompatible

public static final boolean isCompatible(java.awt.Font font,
                                         java.util.Locale locale)
Return true if the argument font can display characters in the argument locale. This method works by checking if the font can display the locale's display name, in the argument locale.


usesChineseCharacters

public static boolean usesChineseCharacters(java.util.Locale locale)
Return true if Chinese characters are used in the argument locale. This may be used to adjust fonts so that Chinese characters are displayed with bigger fonts, since they are much more detailed than Western characters. This method returns true if the language is Chinese, Japanese, or Korean.