Example usage for javax.swing.plaf FontUIResource FontUIResource

List of usage examples for javax.swing.plaf FontUIResource FontUIResource

Introduction

In this page you can find the example usage for javax.swing.plaf FontUIResource FontUIResource.

Prototype

public FontUIResource(Font font) 

Source Link

Document

Constructs a FontUIResource .

Usage

From source file:au.org.ala.delta.intkey.Intkey.java

/**
 * Prompt the user to select the font to use in the application
 *//* www . j a v  a  2 s.c  om*/
@Action
public void chooseFont() {
    Font f = UIManager.getFont("Label.font");
    Font newFont = JFontChooser.showDialog(getMainFrame(),
            UIUtils.getResourceString("SelectFontPrompt.caption"), f);
    if (newFont != null) {
        FontUIResource fontResource = new FontUIResource(newFont);
        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, fontResource);
            }
        }
        SwingUtilities.updateComponentTreeUI(getMainFrame());
    }
}

From source file:com.peterbochs.PeterBochsDebugger.java

public void initGlobalFontSetting(Font fnt) {
    FontUIResource fontRes = new FontUIResource(fnt);
    for (Enumeration keys = UIManager.getDefaults().keys(); keys.hasMoreElements();) {
        Object key = keys.nextElement();
        Object value = UIManager.get(key);
        if (value instanceof FontUIResource) {
            UIManager.put(key, fontRes);
        }/*from   ww  w .java 2  s  .c  o m*/
    }
    SwingUtilities.updateComponentTreeUI(this);
}

From source file:org.gtdfree.ApplicationHelper.java

public static void changeDefaultFontSize(float size, String key) {
    Font f = UIManager.getDefaults().getFont(key + ".font"); //$NON-NLS-1$
    if (f != null) {
        UIManager.getDefaults().put(key + ".font", new FontUIResource(f.deriveFont(f.getSize() + size))); //$NON-NLS-1$
    }/*from  w ww  .  ja v a  2s.c  o m*/
}

From source file:org.gtdfree.ApplicationHelper.java

public static void changeDefaultFontStyle(int style, String key) {
    Font f = UIManager.getDefaults().getFont(key + ".font"); //$NON-NLS-1$
    if (f != null) {
        UIManager.getDefaults().put(key + ".font", new FontUIResource(f.deriveFont(style))); //$NON-NLS-1$
    }/*from w  ww. ja  v a 2  s  .  c  o  m*/
}

From source file:org.jets3t.gui.skins.html.SkinnedLookAndFeel.java

public SkinnedLookAndFeel(Properties skinProperties, String itemName) {
    super();//from   w w w.j a v  a2s  .co  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.tellervo.desktop.prefs.Prefs.java

private void installUIDefault(Class<? extends Object> type, String prefskey, String uikey) {
    Object decoded = null;//  w  w w .  j  av a 2s  .co 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: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./*  w ww  . j  a  v  a  2s . 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);
    }
}