Class FontConfig

java.lang.Object
com.levigo.jadice.web.client.util.fonts.FontConfig

public class FontConfig extends Object
Used to configure the client that shall use standard 14 fonts for text annotation rendering.

The general idea is to have the standard 14 fonts Arimo, Tinos and Cousine in all 4 variants (normal, bold, italic, bold+italic) downloadable on the server.

Upon loading the application in the browser, the client downloads those fonts from the server and uses them for text + stamp annotation rendering. This class is a Singleton implementation. Access to the single instance of this class is only permitted using the #get() method.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected static class 
    A standard WebFontLoader implementation that has the main purpose to repaint the PageView when the loading operation has finished.
    static enum 
    These FontProperties help to improve the readability of the code below when there has to be defined whether a font shall be bold, italic, both, or plain.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected com.levigo.jadice.web.client.util.internal.fonts.WebFontLoader.WebFontHandler
    the WebFontLoader.WebFontHandler needed to determine when certain fonts are loaded and when all loading operations are done (successful or not)
    static final String
    The URL where the com.levigo.jadice.web.server.FontDownloadServlet is registered.
    protected final com.levigo.jadice.web.client.util.internal.fonts.WebFontLoader.WebFonts
    set of fontsToLoad that will be loaded into the client
    protected static FontConfig
    The single instance of this class.
    static final String
    The concatenation of ServerConnection.getServerAddress() and this string leads to the URL where the webfontloader.js (formerly: webfonts.js) script is hosted.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance of the FontConfig.
    FontConfig(boolean isLoadLevibats)
    Creates a new instance of the FontConfig.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    addFontFamilyToLoad(com.levigo.jadice.web.client.util.internal.fonts.DefaultFont font, String pathToFontManager)
    Loads a single DefaultFont in Plain, Italic, Bold and Bold-Italic
    protected void
    addFontToLoad(String familyName, FontConfig.FontProperty fontProperty, String pathToFontManager)
    Adds the font defined in the given parameter to the list of fonts to be loaded by adding a stylesheet to the document
    protected void
    addStandardFontsToLoad(String pathToFontManager, boolean isLoadLevibats)
    Add the fonts for the WebFontLoader to load.
    protected static String
    createFontFacePath(String pathToFontManager, String familyName, FontConfig.FontProperty fontProperty)
    Helper to improve readability in the addFontToLoad(String, FontProperty, String) method.
    static FontConfig
    get()
    Returns the only existing instance of this class.
    static FontConfig
    get(boolean isLoadLevibats)
     
    protected void
    loadFonts(String pathToJs)
    load the fontsToLoad that have been added to fontsToLoad
    protected void
    setFontHandler(com.levigo.jadice.web.client.util.internal.fonts.WebFontLoader.WebFontHandler fontHandler)
    Set the WebFontLoader.WebFontHandler to be used.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • fontHandler

      protected com.levigo.jadice.web.client.util.internal.fonts.WebFontLoader.WebFontHandler fontHandler
      the WebFontLoader.WebFontHandler needed to determine when certain fonts are loaded and when all loading operations are done (successful or not)
    • fontsToLoad

      protected final com.levigo.jadice.web.client.util.internal.fonts.WebFontLoader.WebFonts fontsToLoad
      set of fontsToLoad that will be loaded into the client
    • WEBFONTS_JS_URL

      public static final String WEBFONTS_JS_URL
      The concatenation of ServerConnection.getServerAddress() and this string leads to the URL where the webfontloader.js (formerly: webfonts.js) script is hosted.
      See Also:
    • FONTMANAGER_URL

      public static final String FONTMANAGER_URL
      The URL where the com.levigo.jadice.web.server.FontDownloadServlet is registered.
      See Also:
    • instance

      protected static FontConfig instance
      The single instance of this class.
  • Constructor Details

    • FontConfig

      public FontConfig()
      Creates a new instance of the FontConfig. Since this is a singleton implementation this constructor is only to be called from the get()-method .
    • FontConfig

      public FontConfig(boolean isLoadLevibats)
      Creates a new instance of the FontConfig. Since this is a singleton implementation this constructor is only to be called from the get()-method .
  • Method Details

    • get

      public static FontConfig get()
      Returns the only existing instance of this class. If that instance does not yet exist it is created while calling this method. If the instance already exists that instance is returned.
      Returns:
      the sole instance of this class
    • get

      public static FontConfig get(boolean isLoadLevibats)
      Parameters:
      isLoadLevibats - do we want to load the Levibats-Regular font at the client start?
    • setFontHandler

      protected void setFontHandler(com.levigo.jadice.web.client.util.internal.fonts.WebFontLoader.WebFontHandler fontHandler)
      Set the WebFontLoader.WebFontHandler to be used.
      Parameters:
      fontHandler - the WebFontLoader.WebFontHandler to be used. This parameter must not be null.
    • addFontToLoad

      protected void addFontToLoad(String familyName, FontConfig.FontProperty fontProperty, String pathToFontManager)
      Adds the font defined in the given parameter to the list of fonts to be loaded by adding a stylesheet to the document
      Parameters:
      familyName - the family name of the font to be loaded
      fontProperty - defines whether the font shall be bold, italic, both or plain.
      pathToFontManager - the path to the fontmanager to retrieve the font from
    • createFontFacePath

      protected static String createFontFacePath(String pathToFontManager, String familyName, FontConfig.FontProperty fontProperty)
      Helper to improve readability in the addFontToLoad(String, FontProperty, String) method. This method creates a path to request the given familyName with the given style and weight from a fontManager.
      Parameters:
      pathToFontManager - the path to the fontManager to retrieve the font from
      familyName - the family name of the font to be retrieved using the created path
      fontProperty - the FontConfig.FontProperty to define whether the font shall be italic, plain, both, or plain
      Returns:
      a path at which to request a font with the given family name in the given style and weight based on the given fontManager path.
    • addStandardFontsToLoad

      protected void addStandardFontsToLoad(String pathToFontManager, boolean isLoadLevibats)
      Add the fonts for the WebFontLoader to load. The standard fonts are Arimo, Cousine and Tinos in all 4 permutations(regular, bold, italic, bold + italic).
      Parameters:
      pathToFontManager - path to the com.levigo.jadice.web.server.FontDownloadServlet as defined in the web.xml
    • addFontFamilyToLoad

      protected void addFontFamilyToLoad(com.levigo.jadice.web.client.util.internal.fonts.DefaultFont font, String pathToFontManager)
      Loads a single DefaultFont in Plain, Italic, Bold and Bold-Italic
      Parameters:
      font - the Font that will be loaded in Plain, Italic, Bold and Bold-Italic
      pathToFontManager - path to the com.levigo.jadice.web.server.FontDownloadServlet as defined in the web.xml
    • loadFonts

      protected void loadFonts(String pathToJs)
      load the fontsToLoad that have been added to fontsToLoad
      Parameters:
      pathToJs - The path to the webfonts.js file