Search in sources :

Example 21 with FontUIResource

use of javax.swing.plaf.FontUIResource in project jabref by JabRef.

the class JabRefGUI method setLookAndFeel.

private void setLookAndFeel() {
    try {
        String lookFeel;
        String systemLookFeel = UIManager.getSystemLookAndFeelClassName();
        if (Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_LOOK_AND_FEEL)) {
            // See https://github.com/JabRef/jabref/issues/393, https://github.com/JabRef/jabref/issues/638
            if (System.getProperty("java.runtime.name").contains("OpenJDK")) {
                // Metal L&F
                lookFeel = UIManager.getCrossPlatformLookAndFeelClassName();
                LOGGER.warn("There seem to be problems with OpenJDK and the default GTK Look&Feel. Using Metal L&F instead. Change to another L&F with caution.");
            } else {
                lookFeel = systemLookFeel;
            }
        } else {
            lookFeel = Globals.prefs.get(JabRefPreferences.WIN_LOOK_AND_FEEL);
        }
        // FIXME: Open JDK problem
        if (UIManager.getCrossPlatformLookAndFeelClassName().equals(lookFeel) && !System.getProperty("java.runtime.name").contains("OpenJDK")) {
            // try to avoid ending up with the ugly Metal L&F
            Plastic3DLookAndFeel lnf = new Plastic3DLookAndFeel();
            MetalLookAndFeel.setCurrentTheme(new SkyBluer());
            com.jgoodies.looks.Options.setPopupDropShadowEnabled(true);
            UIManager.setLookAndFeel(lnf);
        } else {
            try {
                UIManager.setLookAndFeel(lookFeel);
            } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
                // specified look and feel does not exist on the classpath, so use system l&f
                UIManager.setLookAndFeel(systemLookFeel);
                // also set system l&f as default
                Globals.prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, systemLookFeel);
                // notify the user
                JOptionPane.showMessageDialog(JabRefGUI.getMainFrame(), Localization.lang("Unable to find the requested look and feel and thus the default one is used."), Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE);
                LOGGER.warn("Unable to find requested look and feel", e);
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Look and feel could not be set", e);
    }
    // In JabRef v2.8, we did it only on NON-Mac. Now, we try on all platforms
    boolean overrideDefaultFonts = Globals.prefs.getBoolean(JabRefPreferences.OVERRIDE_DEFAULT_FONTS);
    if (overrideDefaultFonts) {
        int fontSize = Globals.prefs.getInt(JabRefPreferences.MENU_FONT_SIZE);
        UIDefaults defaults = UIManager.getDefaults();
        Enumeration<Object> keys = defaults.keys();
        for (Object key : Collections.list(keys)) {
            if ((key instanceof String) && ((String) key).endsWith(".font")) {
                FontUIResource font = (FontUIResource) UIManager.get(key);
                font = new FontUIResource(font.getName(), font.getStyle(), fontSize);
                defaults.put(key, font);
            }
        }
    }
}
Also used : UIDefaults(javax.swing.UIDefaults) FontUIResource(javax.swing.plaf.FontUIResource) Plastic3DLookAndFeel(com.jgoodies.looks.plastic.Plastic3DLookAndFeel) DatabaseNotSupportedException(org.jabref.shared.exception.DatabaseNotSupportedException) SQLException(java.sql.SQLException) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) NotASharedDatabaseException(org.jabref.shared.exception.NotASharedDatabaseException) InvalidDBMSConnectionPropertiesException(org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) SkyBluer(com.jgoodies.looks.plastic.theme.SkyBluer)

Example 22 with FontUIResource

use of javax.swing.plaf.FontUIResource in project jdk8u_jdk by JetBrains.

the class SynthParser method startFont.

private void startFont(Attributes attributes) throws SAXException {
    Font font = null;
    int style = Font.PLAIN;
    int size = 0;
    String id = null;
    String name = null;
    for (int i = attributes.getLength() - 1; i >= 0; i--) {
        String key = attributes.getQName(i);
        if (key.equals(ATTRIBUTE_ID)) {
            id = attributes.getValue(i);
        } else if (key.equals(ATTRIBUTE_IDREF)) {
            font = (Font) lookup(attributes.getValue(i), Font.class);
        } else if (key.equals(ATTRIBUTE_NAME)) {
            name = attributes.getValue(i);
        } else if (key.equals(ATTRIBUTE_SIZE)) {
            try {
                size = Integer.parseInt(attributes.getValue(i));
            } catch (NumberFormatException nfe) {
                throw new SAXException("Invalid font size: " + attributes.getValue(i));
            }
        } else if (key.equals(ATTRIBUTE_STYLE)) {
            StringTokenizer tok = new StringTokenizer(attributes.getValue(i));
            while (tok.hasMoreTokens()) {
                String token = tok.nextToken().intern();
                if (token == "BOLD") {
                    style = ((style | Font.PLAIN) ^ Font.PLAIN) | Font.BOLD;
                } else if (token == "ITALIC") {
                    style |= Font.ITALIC;
                }
            }
        }
    }
    if (font == null) {
        if (name == null) {
            throw new SAXException("You must define a name for the font");
        }
        if (size == 0) {
            throw new SAXException("You must define a size for the font");
        }
        font = new FontUIResource(name, style, size);
    } else if (name != null || size != 0 || style != Font.PLAIN) {
        throw new SAXException("Name, size and style are not for use " + "with idref");
    }
    register(id, font);
    if (_stateInfo != null) {
        _stateInfo.setFont(font);
    } else if (_style != null) {
        _style.setFont(font);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) FontUIResource(javax.swing.plaf.FontUIResource) Font(java.awt.Font) SAXException(org.xml.sax.SAXException)

Example 23 with FontUIResource

use of javax.swing.plaf.FontUIResource in project jdk8u_jdk by JetBrains.

the class DefaultSynthStyleFactory method getDefaultStyle.

/**
     * Returns the style to use if there are no matching styles.
     */
private SynthStyle getDefaultStyle() {
    if (_defaultStyle == null) {
        _defaultStyle = new DefaultSynthStyle();
        ((DefaultSynthStyle) _defaultStyle).setFont(new FontUIResource(Font.DIALOG, Font.PLAIN, 12));
    }
    return _defaultStyle;
}
Also used : FontUIResource(javax.swing.plaf.FontUIResource)

Example 24 with FontUIResource

use of javax.swing.plaf.FontUIResource in project jgnash by ccavanaugh.

the class NimbusUtils method changeFontSize.

@SuppressWarnings("ConstantConditions")
public static void changeFontSize(final int size) {
    // get UI defaults
    UIDefaults defaults = UIManager.getLookAndFeelDefaults();
    {
        // determine percent reduction for insets, etc.
        float baseSize = getBaseFontSize();
        growthPercentage = size / baseSize;
    }
    // reduce font sizes
    defaults.keySet().stream().filter(keyObj -> keyObj instanceof String).forEach(keyObj -> {
        String key = (String) keyObj;
        if (key.contains("font")) {
            Object object = defaults.get(key);
            if (object instanceof Font) {
                Font font = (Font) object;
                Font derived = font.deriveFont((float) size);
                defaults.put(key, derived);
            } else if (object instanceof FontUIResource) {
                FontUIResource resource = (FontUIResource) object;
                FontUIResource derived = new FontUIResource(resource.deriveFont((float) size));
                defaults.put(key, derived);
            }
        }
    });
    // reduce content Margins
    defaults.keySet().stream().filter(keyObj -> keyObj instanceof String).forEach(keyObj -> {
        String key = (String) keyObj;
        if (key.contains("contentMargins") || key.contains("padding")) {
            Insets derived = (Insets) ((Insets) defaults.get(key)).clone();
            if (derived.left > 0) {
                derived.left = (int) Math.ceil(derived.left * growthPercentage);
            }
            if (derived.right > 0) {
                derived.right = (int) Math.ceil(derived.right * growthPercentage);
            }
            if (derived.top > 0) {
                derived.top = (int) Math.ceil(derived.top * growthPercentage);
            }
            if (derived.bottom > 0) {
                derived.bottom = (int) Math.ceil(derived.bottom * growthPercentage);
            }
            defaults.put(key, derived);
        }
    });
    // reduce content Margins
    defaults.keySet().stream().filter(keyObj -> keyObj instanceof String).forEach(keyObj -> {
        String key = (String) keyObj;
        if (key.contains("textIconGap") || key.contains("size") || key.contains("thumbWidth") || key.contains("thumbHeight")) {
            Integer integer = (Integer) defaults.get(key);
            Integer derived = (int) Math.ceil((float) integer * growthPercentage);
            defaults.put(key, derived);
        }
    });
}
Also used : UIManager(javax.swing.UIManager) Insets(java.awt.Insets) JButton(javax.swing.JButton) Image(java.awt.Image) FontUIResource(javax.swing.plaf.FontUIResource) Font(java.awt.Font) UIDefaults(javax.swing.UIDefaults) ImageIcon(javax.swing.ImageIcon) Icon(javax.swing.Icon) UIDefaults(javax.swing.UIDefaults) Insets(java.awt.Insets) FontUIResource(javax.swing.plaf.FontUIResource) Font(java.awt.Font)

Example 25 with FontUIResource

use of javax.swing.plaf.FontUIResource in project java-swing-tips by aterai.

the class SizeVariantUtil method setSizeVariantAllComponents.

private static void setSizeVariantAllComponents(Container me, String key) {
    if (me instanceof JComponent) {
        JComponent jc = (JComponent) me;
        //             if (jc instanceof JTable) {
        //                 JTable table = (JTable) jc;
        //                 JCheckBox cb = (JCheckBox) table.getDefaultRenderer(Boolean.class);
        //                 cb.setFont(new FontUIResource(new Font(null)));
        //                 cb.putClientProperty("JComponent.sizeVariant", key);
        //             }
        jc.setFont(new FontUIResource(jc.getFont()));
        jc.putClientProperty("JComponent.sizeVariant", key);
    }
    for (Component c : me.getComponents()) {
        if (c instanceof Container) {
            setSizeVariantAllComponents((Container) c, key);
        }
    }
}
Also used : FontUIResource(javax.swing.plaf.FontUIResource)

Aggregations

FontUIResource (javax.swing.plaf.FontUIResource)26 Font (java.awt.Font)5 UIDefaults (javax.swing.UIDefaults)5 ColorUIResource (javax.swing.plaf.ColorUIResource)3 IOException (java.io.IOException)2 StringTokenizer (java.util.StringTokenizer)2 JFrame (javax.swing.JFrame)2 UISettings (com.intellij.ide.ui.UISettings)1 FontDescriptor (com.intellij.uiDesigner.lw.FontDescriptor)1 Plastic3DLookAndFeel (com.jgoodies.looks.plastic.Plastic3DLookAndFeel)1 SkyBluer (com.jgoodies.looks.plastic.theme.SkyBluer)1 Dimension (java.awt.Dimension)1 Image (java.awt.Image)1 Insets (java.awt.Insets)1 Point (java.awt.Point)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1