List of usage examples for java.awt Font decode
public static Font decode(String str)
From source file:org.esa.nest.dat.views.polarview.Axis.java
private static Font getFont(String propertyName, String defaultFont) { final String fontSpec = System.getProperty(propertyName, defaultFont); return Font.decode(fontSpec); }
From source file:org.esa.nest.dat.views.polarview.PolarCanvas.java
@Override public Font getFont() { final Font font = super.getFont(); if (font == null) return Font.decode("SansSerif-plain-9"); return font;//from ww w . j a v a 2 s .c om }
From source file:org.jets3t.gui.skins.html.SkinnedLookAndFeel.java
public SkinnedLookAndFeel(Properties skinProperties, String itemName) { super();// w w w .j a va2 s.c o m // Determine system defaults. JLabel defaultLabel = new JLabel(); Color backgroundColor = defaultLabel.getBackground(); Color textColor = defaultLabel.getForeground(); Font font = defaultLabel.getFont(); // Find skinning configurations. String backgroundColorValue = skinProperties.getProperty("backgroundColor", null); String textColorValue = skinProperties.getProperty("textColor", null); String fontValue = skinProperties.getProperty("font", null); // Apply skinning configurations. if (backgroundColorValue != null) { Color color = Color.decode(backgroundColorValue); if (color == null) { log.error("Unable to set background color with value: " + backgroundColorValue); } else { backgroundColor = color; } } if (textColorValue != null) { Color color = Color.decode(textColorValue); if (color == null) { log.error("Unable to set text color with value: " + textColorValue); } else { textColor = color; } } if (fontValue != null) { Font myFont = Font.decode(fontValue); if (myFont == null) { log.error("Unable to set font with value: " + fontValue); } else { font = myFont; } } // Update metal theme with configured display properties. SkinnedMetalTheme skinnedTheme = new SkinnedMetalTheme(new ColorUIResource(backgroundColor), new ColorUIResource(textColor), new FontUIResource(font)); MetalLookAndFeel.setCurrentTheme(skinnedTheme); }
From source file:org.spoutcraft.launcher.skin.ConsoleFrame.java
/** * Get a supported monospace font./*from w ww . ja v a 2s .co m*/ * * @return font */ public static Font getMonospaceFont() { for (String fontName : monospaceFontNames) { Font font = Font.decode(fontName + "-11"); if (!font.getFamily().equalsIgnoreCase("Dialog")) return font; } return new Font("Monospace", Font.PLAIN, 11); }
From source file:org.tellervo.desktop.prefs.Prefs.java
private void installUIDefault(Class<? extends Object> type, String prefskey, String uikey) { Object decoded = null;/* ww w . ja va2s .c o m*/ String pref = prefs.getProperty(prefskey); if (pref == null) { log.warn("Preference '" + prefskey + "' held null value."); return; } if (Color.class.isAssignableFrom(type)) { decoded = Color.decode(pref); } else if (Font.class.isAssignableFrom(type)) { decoded = Font.decode(pref); } else { log.warn("Unsupported UIDefault preference type: " + type); return; } if (decoded == null) { log.warn("UIDefaults color preference '" + prefskey + "' was not decodable."); return; } UIDefaults uidefaults = UIManager.getDefaults(); // if (uidefaults.contains(property)) { // NOTE: ok, UIDefaults object is strange. Not only does // it not implement the Map interface correctly, but entries // will not "stick". The entries must be first explicitly // removed, and then re-added - aaron log.debug("Removing UIDefaults key before overwriting: " + uikey); uidefaults.remove(uikey); // } if (Color.class.isAssignableFrom(type)) { uidefaults.put(uikey, new ColorUIResource((Color) decoded)); } else { uidefaults.put(uikey, new FontUIResource((Font) decoded)); } }
From source file:org.tellervo.desktop.prefs.Prefs.java
/** * Get the requested preference as a font * /*from w w w. j ava2 s . com*/ * @param key * @param deflt * @return */ public Font getFontPref(PrefKey key, Font deflt) { String value = prefs.getProperty(key.getValue()); if (value == null) return deflt; return Font.decode(value); }
From source file:org.tellervo.desktop.prefs.Prefs.java
/** * Use getPref(PrefKey, ...) instead// w w w . j a va2 s. co m * * @param pref * @param deflt * @return */ @Deprecated public Font getFontPref(String pref, Font deflt) { String value = prefs.getProperty(pref); if (value == null) return deflt; return Font.decode(value); }
From source file:org.tinymediamanager.TinyMediaManager.java
/** * The main method./*from w w w .ja va 2 s. co m*/ * * @param args * the arguments */ public static void main(String[] args) { // simple parse command line if (args != null && args.length > 0) { LOGGER.debug("TMM started with: " + Arrays.toString(args)); TinyMediaManagerCMD.parseParams(args); System.setProperty("java.awt.headless", "true"); } else { // no cmd params found, but if we are headless - display syntax String head = System.getProperty("java.awt.headless"); if (head != null && head.equals("true")) { LOGGER.info("TMM started 'headless', and without params -> displaying syntax "); TinyMediaManagerCMD.printSyntax(); System.exit(0); } } // check if we have write permissions to this folder try { RandomAccessFile f = new RandomAccessFile("access.test", "rw"); f.close(); Files.deleteIfExists(Paths.get("access.test")); } catch (Exception e2) { String msg = "Cannot write to TMM directory, have no rights - exiting."; if (!GraphicsEnvironment.isHeadless()) { JOptionPane.showMessageDialog(null, msg); } else { System.out.println(msg); } System.exit(1); } // HACK for Java 7 and JavaFX not being in boot classpath // In Java 8 and on, this is installed inside jre/lib/ext // see http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8003171 and references // so we check if it is already existent in "new" directory, and if not, load it via reflection ;o) String dir = new File(LaunchUtil.getJVMPath()).getParentFile().getParent(); // bin, one deeper File jfx = new File(dir, "lib/ext/jfxrt.jar"); if (!jfx.exists()) { // java 7 jfx = new File(dir, "lib/jfxrt.jar"); if (jfx.exists()) { try { TmmOsUtils.addPath(jfx.getAbsolutePath()); } catch (Exception e) { LOGGER.debug("failed to load JavaFX - using old styles..."); } } } if (Globals.isDebug()) { ClassLoader cl = ClassLoader.getSystemClassLoader(); URL[] urls = ((URLClassLoader) cl).getURLs(); LOGGER.info("=== DEBUG CLASS LOADING ============================="); for (URL url : urls) { LOGGER.info(url.getFile()); } } LOGGER.info("====================================================="); LOGGER.info("=== tinyMediaManager (c) 2012-2016 Manuel Laggner ==="); LOGGER.info("====================================================="); LOGGER.info("tmm.version : " + ReleaseInfo.getRealVersion()); if (Globals.isDonator()) { LOGGER.info("tmm.supporter : THANKS FOR DONATING - ALL FEATURES UNLOCKED :)"); } LOGGER.info("os.name : " + System.getProperty("os.name")); LOGGER.info("os.version : " + System.getProperty("os.version")); LOGGER.info("os.arch : " + System.getProperty("os.arch")); LOGGER.trace("network.id : " + License.getMac()); LOGGER.info("java.version : " + System.getProperty("java.version")); if (Globals.isRunningJavaWebStart()) { LOGGER.info("java.webstart : true"); } if (Globals.isRunningWebSwing()) { LOGGER.info("java.webswing : true"); } // START character encoding debug debugCharacterEncoding("default encoding : "); System.setProperty("file.encoding", "UTF-8"); System.setProperty("sun.jnu.encoding", "UTF-8"); Field charset; try { // we cannot (re)set the properties while running inside JVM // so we trick it to reread it by setting them to null ;) charset = Charset.class.getDeclaredField("defaultCharset"); charset.setAccessible(true); charset.set(null, null); } catch (Exception e) { LOGGER.warn("Error resetting to UTF-8", e); } debugCharacterEncoding("set encoding to : "); // END character encoding debug // set GUI default language Locale.setDefault(Utils.getLocaleFromLanguage(Globals.settings.getLanguage())); LOGGER.info("System language : " + System.getProperty("user.language") + "_" + System.getProperty("user.country")); LOGGER.info( "GUI language : " + Locale.getDefault().getLanguage() + "_" + Locale.getDefault().getCountry()); LOGGER.info("Scraper language : " + MovieModuleManager.MOVIE_SETTINGS.getScraperLanguage()); LOGGER.info("TV Scraper lang : " + TvShowModuleManager.SETTINGS.getScraperLanguage()); // start EDT EventQueue.invokeLater(new Runnable() { public void run() { boolean newVersion = !Globals.settings.isCurrentVersion(); // same snapshots/svn considered as "new", for upgrades try { Thread.setDefaultUncaughtExceptionHandler(new Log4jBackstop()); if (!GraphicsEnvironment.isHeadless()) { Thread.currentThread().setName("main"); } else { Thread.currentThread().setName("headless"); LOGGER.debug("starting without GUI..."); } Toolkit tk = Toolkit.getDefaultToolkit(); tk.addAWTEventListener(TmmWindowSaver.getInstance(), AWTEvent.WINDOW_EVENT_MASK); if (!GraphicsEnvironment.isHeadless()) { setLookAndFeel(); } doStartupTasks(); // suppress logging messages from betterbeansbinding org.jdesktop.beansbinding.util.logging.Logger.getLogger(ELProperty.class.getName()) .setLevel(Level.SEVERE); // init ui logger TmmUILogCollector.init(); LOGGER.info("====================================================="); // init splash SplashScreen splash = null; if (!GraphicsEnvironment.isHeadless()) { splash = SplashScreen.getSplashScreen(); } Graphics2D g2 = null; if (splash != null) { g2 = splash.createGraphics(); if (g2 != null) { Font font = new Font("Dialog", Font.PLAIN, 14); g2.setFont(font); } else { LOGGER.debug("got no graphics from splash"); } } else { LOGGER.debug("no splash found"); } if (g2 != null) { updateProgress(g2, "starting tinyMediaManager", 0); splash.update(); } LOGGER.info("starting tinyMediaManager"); // upgrade check String oldVersion = Globals.settings.getVersion(); if (newVersion) { if (g2 != null) { updateProgress(g2, "upgrading to new version", 10); splash.update(); } UpgradeTasks.performUpgradeTasksBeforeDatabaseLoading(oldVersion); // do the upgrade tasks for the old version Globals.settings.setCurrentVersion(); Globals.settings.saveSettings(); } // proxy settings if (Globals.settings.useProxy()) { LOGGER.info("setting proxy"); Globals.settings.setProxy(); } // MediaInfo ///////////////////////////////////////////////////// if (g2 != null) { updateProgress(g2, "loading MediaInfo libs", 20); splash.update(); } MediaInfoUtils.loadMediaInfo(); // load modules ////////////////////////////////////////////////// if (g2 != null) { updateProgress(g2, "loading movie module", 30); splash.update(); } TmmModuleManager.getInstance().startUp(); TmmModuleManager.getInstance().registerModule(MovieModuleManager.getInstance()); TmmModuleManager.getInstance().enableModule(MovieModuleManager.getInstance()); if (g2 != null) { updateProgress(g2, "loading TV show module", 40); splash.update(); } TmmModuleManager.getInstance().registerModule(TvShowModuleManager.getInstance()); TmmModuleManager.getInstance().enableModule(TvShowModuleManager.getInstance()); if (g2 != null) { updateProgress(g2, "loading plugins", 50); splash.update(); } // just instantiate static - will block (takes a few secs) PluginManager.getInstance(); if (ReleaseInfo.isSvnBuild()) { PluginManager.loadClasspathPlugins(); } // do upgrade tasks after database loading if (newVersion) { if (g2 != null) { updateProgress(g2, "upgrading database to new version", 70); splash.update(); } UpgradeTasks.performUpgradeTasksAfterDatabaseLoading(oldVersion); } // launch application //////////////////////////////////////////// if (g2 != null) { updateProgress(g2, "loading ui", 80); splash.update(); } if (!GraphicsEnvironment.isHeadless()) { MainWindow window = new MainWindow("tinyMediaManager / " + ReleaseInfo.getRealVersion()); // finished //////////////////////////////////////////////////// if (g2 != null) { updateProgress(g2, "finished starting :)", 100); splash.update(); } // write a random number to file, to identify this instance (for // updater, tracking, whatsoever) Utils.trackEvent("startup"); TmmWindowSaver.getInstance().loadSettings(window); window.setVisible(true); // wizard for new user if (Globals.settings.newConfig) { Globals.settings.writeDefaultSettings(); // now all plugins are resolved - write again defaults! TinyMediaManagerWizard wizard = new TinyMediaManagerWizard(); wizard.setVisible(true); } // show changelog if (newVersion && !ReleaseInfo.getVersion().equals(oldVersion)) { // special case nightly/svn: if same snapshot version, do not display changelog Utils.trackEvent("updated"); showChangelog(); } } else { TinyMediaManagerCMD.startCommandLineTasks(); // wait for other tmm threads (artwork download et all) while (TmmTaskManager.getInstance().poolRunning()) { Thread.sleep(2000); } LOGGER.info("bye bye"); // MainWindows.shutdown() try { // send shutdown signal TmmTaskManager.getInstance().shutdown(); // save unsaved settings Globals.settings.saveSettings(); // hard kill TmmTaskManager.getInstance().shutdownNow(); // close database connection TmmModuleManager.getInstance().shutDown(); } catch (Exception ex) { LOGGER.warn(ex.getMessage()); } System.exit(0); } } catch (IllegalStateException e) { LOGGER.error("IllegalStateException", e); if (!GraphicsEnvironment.isHeadless() && e.getMessage().contains("file is locked")) { // MessageDialog.showExceptionWindow(e); ResourceBundle bundle = ResourceBundle.getBundle("messages", new UTF8Control()); //$NON-NLS-1$ MessageDialog dialog = new MessageDialog(MainWindow.getActiveInstance(), bundle.getString("tmm.problemdetected")); //$NON-NLS-1$ dialog.setImage(IconManager.ERROR); dialog.setText(bundle.getString("tmm.nostart"));//$NON-NLS-1$ dialog.setDescription(bundle.getString("tmm.nostart.instancerunning"));//$NON-NLS-1$ dialog.setResizable(true); dialog.pack(); dialog.setLocationRelativeTo(MainWindow.getActiveInstance()); dialog.setVisible(true); } System.exit(1); } catch (Exception e) { LOGGER.error("Exception while start of tmm", e); if (!GraphicsEnvironment.isHeadless()) { MessageDialog.showExceptionWindow(e); } System.exit(1); } } /** * Update progress on splash screen. * * @param text * the text */ private void updateProgress(Graphics2D g2, String text, int progress) { Object oldAAValue = g2.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); g2.setComposite(AlphaComposite.Clear); g2.fillRect(20, 200, 480, 305); g2.setPaintMode(); g2.setColor(new Color(51, 153, 255)); g2.fillRect(22, 272, 452 * progress / 100, 21); g2.setColor(Color.black); g2.drawString(text + "...", 23, 310); int l = g2.getFontMetrics().stringWidth(ReleaseInfo.getRealVersion()); // bound right g2.drawString(ReleaseInfo.getRealVersion(), 480 - l, 325); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, oldAAValue); LOGGER.debug("Startup (" + progress + "%) " + text); } /** * Sets the look and feel. * * @throws Exception * the exception */ private void setLookAndFeel() throws Exception { // get font settings String fontFamily = Globals.settings.getFontFamily(); try { // sanity check fontFamily = Font.decode(fontFamily).getFamily(); } catch (Exception e) { fontFamily = "Dialog"; } int fontSize = Globals.settings.getFontSize(); if (fontSize < 12) { fontSize = 12; } String fontString = fontFamily + " " + fontSize; // Get the native look and feel class name // String laf = UIManager.getSystemLookAndFeelClassName(); Properties props = new Properties(); props.setProperty("controlTextFont", fontString); props.setProperty("systemTextFont", fontString); props.setProperty("userTextFont", fontString); props.setProperty("menuTextFont", fontString); // props.setProperty("windowTitleFont", "Dialog bold 20"); fontSize = Math.round((float) (fontSize * 0.833)); fontString = fontFamily + " " + fontSize; props.setProperty("subTextFont", fontString); props.setProperty("backgroundColor", "237 237 237"); props.setProperty("menuBackgroundColor", "237 237 237"); props.setProperty("controlBackgroundColor", "237 237 237"); props.setProperty("menuColorLight", "237 237 237"); props.setProperty("menuColorDark", "237 237 237"); props.setProperty("toolbarColorLight", "237 237 237"); props.setProperty("toolbarColorDark", "237 237 237"); props.setProperty("tooltipBackgroundColor", "255 255 255"); props.put("windowDecoration", "system"); props.put("logoString", ""); // Get the look and feel class name com.jtattoo.plaf.luna.LunaLookAndFeel.setTheme(props); String laf = "com.jtattoo.plaf.luna.LunaLookAndFeel"; // Install the look and feel UIManager.setLookAndFeel(laf); } /** * Does some tasks at startup */ private void doStartupTasks() { // rename downloaded files UpgradeTasks.renameDownloadedFiles(); // extract templates, if GD has not already done Utils.extractTemplates(); // check if a .desktop file exists if (Platform.isLinux()) { File desktop = new File(TmmOsUtils.DESKTOP_FILE); if (!desktop.exists()) { TmmOsUtils.createDesktopFileForLinux(desktop); } } } private void showChangelog() { // read the changelog try { final String changelog = Utils.readFileToString(Paths.get("changelog.txt")); if (StringUtils.isNotBlank(changelog)) { EventQueue.invokeLater(new Runnable() { @Override public void run() { WhatsNewDialog dialog = new WhatsNewDialog(changelog); dialog.pack(); dialog.setLocationRelativeTo(MainWindow.getActiveInstance()); dialog.setModalityType(ModalityType.APPLICATION_MODAL); dialog.setVisible(true); } }); } } catch (IOException e) { // no file found LOGGER.warn(e.getMessage()); } } }); }
From source file:pt.webdetails.cgg.scripts.BaseScope.java
private static Font decodeFont(String fontFamily, int fontStyle, int isize) { String fontStyleText = ""; switch (fontStyle) { case Font.BOLD: fontStyleText = "BOLD "; break;// www . j av a2 s . c om case Font.ITALIC: fontStyleText = "ITALIC "; break; case (Font.ITALIC | Font.BOLD): fontStyleText = "BOLDITALIC "; break; } String capFontFamily = fontFamily.substring(0, 1).toUpperCase() + fontFamily.substring(1, fontFamily.length()); Font ffont = Font.decode(capFontFamily + " " + fontStyleText + isize); if (ffont.getFamily().equals(Font.DIALOG) && !fontFamily.equals("dialog")) { // defaulted, try family GVTFontFamily awtFamily = FontFamilyResolver.resolve(fontFamily); if (awtFamily == null) { awtFamily = FontFamilyResolver.defaultFont; } ffont = new Font(awtFamily.getFamilyName(), fontStyle, isize); } return ffont; }
From source file:uk.co.modularaudio.componentdesigner.ComponentDesignerLauncher.java
public static void main(final String[] args) throws Exception { FontResetter.turnOnGlobalAaText();/*from w w w.j a va 2 s. c o m*/ boolean useSystemLookAndFeel = false; boolean showAlpha = false; boolean showBeta = false; String additionalBeansResource = null; String additionalConfigResource = null; String configResourcePath = CDCONFIG_PROPERTIES; if (args.length > 0) { for (int i = 0; i < args.length; ++i) { final String arg = args[i]; if (arg.equals("--useSlaf")) { useSystemLookAndFeel = true; } else if (arg.equals("--beta")) { showBeta = true; } else if (arg.equals("--alpha")) { showAlpha = true; showBeta = true; } else if (arg.equals("--pluginJar")) { additionalBeansResource = PLUGIN_BEANS_RESOURCE_PATH; additionalConfigResource = PLUGIN_CONFIG_RESOURCE_PATH; if (log.isDebugEnabled()) { log.debug("Will append plugin beans: " + additionalBeansResource); log.debug("Will append plugin config file: " + additionalConfigResource); } } else if (arg.equals("--development")) { // Let me specify certain things with hard paths configResourcePath = CDDEVELOPMENT_PROPERTIES; log.info("In development mode. Will use development properties for configuration"); } else if (arg.equals("--jprofiler")) { configResourcePath = CDJPROFILER_PROPERTIES; log.info("In jprofiler mode - using jprofiler properties for configuration"); } else { final String msg = "Unknown command line argument: " + arg; log.error(msg); throw new DatastoreException(msg); } } if (useSystemLookAndFeel) { log.info("System look and feel activated"); } if (showAlpha) { log.info("Showing alpha components"); } if (showBeta) { log.info("Showing beta components"); } } if (useSystemLookAndFeel) { final String gtkLookAndFeelClassName = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"; boolean foundGtkLaf = false; final LookAndFeelInfo lafis[] = UIManager.getInstalledLookAndFeels(); for (final LookAndFeelInfo lafi : lafis) { final String lc = lafi.getClassName(); if (lc.equals(gtkLookAndFeelClassName)) { foundGtkLaf = true; break; } } if (foundGtkLaf) { log.debug("Found available GTK laf. Will set active"); UIManager.setLookAndFeel(gtkLookAndFeelClassName); } UIManager.put("Slider.paintValue", Boolean.FALSE); } final Font f = Font.decode(""); final String fontName = f.getName(); FontResetter.setUIFontFromString(fontName, Font.PLAIN, 10); log.debug("ComponentDesigner starting."); // Set the fft library to only use current thread JTransformsConfigurator.setThreadsToOne(); final ComponentDesignerLauncher application = new ComponentDesignerLauncher(); application.init(configResourcePath, additionalBeansResource, additionalConfigResource, showAlpha, showBeta); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { application.go(); application.registerCloseAction(); } catch (final Exception e) { final String msg = "Exception caught at top level of ComponentDesigner launch: " + e.toString(); log.error(msg, e); System.exit(0); } log.debug("Leaving runnable run section."); } }); }