/** * Tries to instantiate the class given by name. If it exists, is accessible/instantiatable and * implements {@link ThreeLetterCodeGenerator}, the instance is returned. Otherwise the default * implementation is returned. * * @param className the class name for the {@link ThreeLetterCodeGenerator} * @return the initialized instance. */ public static final ThreeLetterCodeGenerator initThreeLetterCodeGenerator(String className) { if (className == null) return (getDefaultTLC()); Class<?> clazz = null; try { clazz = Class.forName(className); } catch (ClassNotFoundException e) { RFDHLog.exception( "WARNING: ", "Class ", className, " not found through standard ClassLoader. Using default ThreeLetterCodeGenerator."); return (getDefaultTLC()); } if (!ThreeLetterCodeGenerator.class.isAssignableFrom(clazz)) { RFDHLog.exception( "WARNING: ", "Class ", className, " doesn't implement net.ctdp.rfdynhud.util.ThreeLetterCodeGenerator. Using default implementation."); return (getDefaultTLC()); } try { return ((ThreeLetterCodeGenerator) clazz.newInstance()); } catch (InstantiationException e) { RFDHLog.exception( "WARNING: ", "Cannot instantiate class ", className, ". Using default ThreeLetterCodeGenerator."); return (getDefaultTLC()); } catch (IllegalAccessException e) { RFDHLog.exception( "WARNING: ", "Cannot instantiate class ", className, ". Using default ThreeLetterCodeGenerator."); return (getDefaultTLC()); } }
private static Object getFallback( IllegalArgumentException exception, boolean extractVirtualFlag, boolean extractAntialiasFlag, boolean throwException, boolean logException) { if (throwException) throw exception; if (logException) RFDHLog.exception(exception); if (extractVirtualFlag || extractAntialiasFlag) return (Boolean.FALSE); return (FALLBACK_FONT); }
public static void loadCustomFonts(GameFileSystem fileSystem) { File folder = new File( ResourceManager.isCompleteIDEMode() ? fileSystem.getConfigFolder().getParentFile() : fileSystem.getPluginFolder(), "fonts"); if (!folder.exists()) return; RFDHLog.printlnEx("Loading custom fonts..."); for (File file : folder.listFiles()) { if (file.isFile() && file.getName().toLowerCase().endsWith("ttf")) { Font font = null; try { font = Font.createFont(Font.TRUETYPE_FONT, file); } catch (Throwable t) { RFDHLog.exception( "Couldn't load font file \"" + file.getAbsolutePath() + "\". Message was: " + t.getMessage()); } if (font != null) { Font testFont = new Font(font.getName(), font.getStyle(), font.getSize()); if (testFont.getName().equals(font.getName()) && testFont.getFamily().equals(font.getFamily())) RFDHLog.exception( "Couldn't register font \"" + font.getName() + "\". It is already registered."); else if (GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(font)) RFDHLog.printlnEx(" Loaded and registered custom font \"" + font.getName() + "\"."); else RFDHLog.exception("Couldn't register font \"" + font.getName() + "\"."); } } } }