List of usage examples for javax.swing UIManager get
public static Object get(Object key)
From source file:shuffle.fwk.ShuffleController.java
/** * Creates a ShuffleController with the given configuration paths for the primary configuration * (which tells other managers where to get their configurations). If there are none passed, then * "config/main.txt" is assumed./*from w w w. j a va 2 s . c o m*/ * * @param configPaths * The paths as Strings */ public ShuffleController(String... configPaths) { if (configPaths.length > 0 && configPaths[0] != null) { factory = new ConfigFactory(configPaths[0]); } else { factory = new ConfigFactory(); } Integer menuFontOverride = getPreferencesManager().getIntegerValue(KEY_FONT_SIZE_SCALING); if (menuFontOverride != null && menuFontOverride != 100 && menuFontOverride >= 1 && menuFontOverride <= 10000) { float scale = menuFontOverride.floatValue() / 100.0f; try { // This is the cleanest and most bug-free way to do this hack. Set<Object> allKeys = new HashSet<Object>(); allKeys.add("JMenu.font"); // Yes we're not supposed to use this, but it is the only one that works with Nimbus LAF allKeys.addAll(UIManager.getLookAndFeelDefaults().keySet()); Object value = UIManager.get("defaultFont"); if (value != null && value instanceof FontUIResource) { FontUIResource fromFont = (javax.swing.plaf.FontUIResource) value; FontUIResource toFont = new FontUIResource(fromFont.deriveFont(fromFont.getSize() * scale)); // This one is necessary UIManager.getLookAndFeel().getDefaults().put("defaultFont", toFont); // And this one allows other LAF to be used in the future UIManager.getDefaults().put("defaultFont", toFont); } // Needed for Nimbus's JTable row height adjustment Object tableFontValue = UIManager.getLookAndFeel().getDefaults().get("Table.font"); Number bestRowHeight = null; if (tableFontValue != null && tableFontValue instanceof FontUIResource) { FontUIResource fromFont = (FontUIResource) tableFontValue; bestRowHeight = fromFont.getSize(); } Object rowHeightValue = UIManager.getLookAndFeel().getDefaults().get("Table.rowHeight"); if (rowHeightValue != null && rowHeightValue instanceof Number) { Number rowHeight = (Number) rowHeightValue; rowHeight = rowHeight.doubleValue() * scale; if (bestRowHeight == null || bestRowHeight.intValue() < rowHeight.intValue()) { bestRowHeight = rowHeight; } } if (bestRowHeight != null) { bestRowHeight = bestRowHeight.doubleValue() * (4.0 / 3.0); } if (bestRowHeight != null && bestRowHeight.intValue() > 0) { UIManager.getLookAndFeel().getDefaults().put("Table.rowHeight", bestRowHeight.intValue()); } } catch (Exception e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); LOG.log(Level.SEVERE, "Cannot override menu font sizes!", e); } } try { setModel(new ShuffleModel(this)); setView(new ShuffleView(this)); getModel().checkLocaleConfig(); loadFrame(); } catch (Exception e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); LOG.log(Level.SEVERE, "Failure on start:", e); } }
From source file:storybook.toolkit.swing.SwingUtil.java
public static void setUIFont(javax.swing.plaf.FontUIResource f) { Enumeration<Object> keys = UIManager.getDefaults().keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); Object value = UIManager.get(key); if (value instanceof javax.swing.plaf.FontUIResource) UIManager.put(key, f); }// www . j a v a 2s. c om }
From source file:tvbrowser.TVBrowser.java
private static void updateLookAndFeel() { try {//from ww w. j a va2 s. c om if (OperatingSystem.isWindows()) { UIManager.installLookAndFeel("Extended Windows", "com.jgoodies.looks.windows.WindowsLookAndFeel"); } UIManager.installLookAndFeel("Plastic", "com.jgoodies.looks.plastic.PlasticLookAndFeel"); UIManager.installLookAndFeel("Plastic 3D", "com.jgoodies.looks.plastic.Plastic3DLookAndFeel"); UIManager.installLookAndFeel("Plastic XP", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); UIManager.installLookAndFeel("Skin", "com.l2fprod.gui.plaf.skin.SkinLookAndFeel"); /* Map<String, SkinInfo> substanceSkins = SubstanceLookAndFeel.getAllSkins(); if (substanceSkins != null) { for (SkinInfo skin : substanceSkins.values()) { String className = skin.getClassName(); UIManager.installLookAndFeel("Substance " + skin.getDisplayName(), StringUtils.replace(StringUtils.replace(className, "Skin", "LookAndFeel"), "skin.", "skin.Substance")); } } */ } catch (Exception e1) { // ignore any exception for optional skins e1.printStackTrace(); } if (Settings.propLookAndFeel.getString().equals("com.l2fprod.gui.plaf.skin.SkinLookAndFeel")) { String themepack = Settings.propSkinLFThemepack.getString(); try { File themepackFile = new File(themepack); if (!themepackFile.exists()) { themepackFile = new File(Settings.getUserDirectoryName(), themepack); } if (!themepackFile.exists() && OperatingSystem.isMacOs()) { themepackFile = new File("/Library/Application Support/TV-Browser/", themepack); } SkinLookAndFeel.setSkin(SkinLookAndFeel.loadThemePack(themepackFile.getAbsolutePath())); } catch (Exception exc) { ErrorHandler.handle("Could not load themepack.\nSkinLF is disabled now", exc); Settings.propLookAndFeel.setString(Settings.propLookAndFeel.getDefault()); } } else if (Settings.propLookAndFeel.getString().startsWith("com.jgoodies")) { com.jgoodies.looks.Options.setPopupDropShadowEnabled(Settings.propJGoodiesShadow.getBoolean()); UIManager.put("jgoodies.popupDropShadowEnabled", Boolean.valueOf(Settings.propJGoodiesShadow.getBoolean())); try { LookUtils.setLookAndTheme( (LookAndFeel) Class.forName(Settings.propLookAndFeel.getString()).newInstance(), Class.forName(Settings.propJGoodiesTheme.getString()).newInstance()); } catch (Throwable e) { ErrorHandler.handle("Could not load themepack.\nJGoodies is disabled now", e); Settings.propLookAndFeel.setString(Settings.propLookAndFeel.getDefault()); } } if (curLookAndFeel == null || !curLookAndFeel.equals(Settings.propLookAndFeel.getString())) { try { curLookAndFeel = Settings.propLookAndFeel.getString(); // check if LnF is still available boolean foundCurrent = lookAndFeelExists(curLookAndFeel); // reset look and feel? if (!foundCurrent) { if (JOptionPane.showConfirmDialog(null, mLocalizer.msg("lnfMissing", "The look and feel '{0}' is no longer available,\nso the default look and feel will be used.\n\nDo you want to set the look and feel option to the default look and feel?", curLookAndFeel), mLocalizer.msg("lnfMissing.title", "Look and feel missing"), JOptionPane.WARNING_MESSAGE | JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { Settings.propLookAndFeel.resetToDefault(); curLookAndFeel = Settings.propLookAndFeel.getString(); foundCurrent = true; } } if (foundCurrent) { UIThreadRunner.invokeAndWait(new Runnable() { @Override public void run() { try { UIManager.setLookAndFeel(curLookAndFeel); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } mLog.info("setting look and feel to " + curLookAndFeel); } }); } } catch (Exception exc) { String msg = mLocalizer.msg("error.1", "Unable to set look and feel.", exc); ErrorHandler.handle(msg, exc); } } // set colors for action pane at UIManager UIManager.put("TaskPane.foreGround", UIManager.get("Button.foreground")); if (UIManager.getColor("List.selectionBackground") == null) { UIManager.put("List.selectionBackground", UIManager.getColor("Tree.selectionBackground")); } if (UIManager.getColor("List.selectionForeground") == null) { UIManager.put("List.selectionForeground", UIManager.getColor("Tree.selectionForeground")); } if (UIManager.getColor("MenuItem.selectionForeground") == null) { UIManager.put("MenuItem.selectionForeground", UIManager.getColor("Tree.selectionForeground")); } if (UIManager.getColor("ComboBox.disabledForeground") == null) { UIManager.put("ComboBox.disabledForeground", Color.gray); } if (mainFrame != null) { SwingUtilities.updateComponentTreeUI(mainFrame); mainFrame.validate(); } lookAndFeelInitialized = true; }