Created
October 23, 2018 09:38
-
-
Save samuelstein/82e61f8e51c83bc2cfafc19808103da0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This is a wrapper class that registers the font awesome .ttf included in the package. | |
* ControlsFX loads this font dynamically at run time from a CDN. Thus, it works only if Internet | |
* connection is available | |
* . | |
* This class registers an included version of the font. The {@link #init()} method should be called | |
* during the initialization procedure of the application such that the font is available early. | |
* | |
* @author albrecht | |
*/ | |
private static class FontAwesomeOffline { | |
private static final String fontLocation = "assets/fonts/fontawesome-webfont.ttf"; | |
private static GlyphFont font; | |
private FontAwesomeOffline() { | |
// prevent instances | |
} | |
public static void init() { | |
InputStream input = FontAwesomeOffline.class.getClassLoader().getResourceAsStream(fontLocation); | |
if (input != null) { | |
font = new FontAwesome(input); | |
GlyphFontRegistry.register(font); | |
LOG.info("Using {} from local assets.", font.getName()); | |
// Note: if we would close the input stream, icons would not be displayed anymore! | |
} else { | |
LOG.error("Could not initialize font awesome: " + fontLocation); | |
} | |
} | |
public static GlyphFont getGlyphFont() { | |
return font; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment