Search in sources :

Example 16 with FontUIResource

use of javax.swing.plaf.FontUIResource in project intellij-community by JetBrains.

the class DarculaLaf method getDefaults.

@Override
public UIDefaults getDefaults() {
    try {
        final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod("getDefaults");
        superMethod.setAccessible(true);
        final UIDefaults metalDefaults = (UIDefaults) superMethod.invoke(new MetalLookAndFeel());
        final UIDefaults defaults = (UIDefaults) superMethod.invoke(base);
        if (SystemInfo.isLinux) {
            if (!Registry.is("darcula.use.native.fonts.on.linux")) {
                Font font = findFont("DejaVu Sans");
                if (font != null) {
                    for (Object key : defaults.keySet()) {
                        if (key instanceof String && ((String) key).endsWith(".font")) {
                            defaults.put(key, new FontUIResource(font.deriveFont(13f)));
                        }
                    }
                }
            } else if (Arrays.asList("CN", "JP", "KR", "TW").contains(Locale.getDefault().getCountry())) {
                for (Object key : defaults.keySet()) {
                    if (key instanceof String && ((String) key).endsWith(".font")) {
                        final Font font = defaults.getFont(key);
                        if (font != null) {
                            defaults.put(key, new FontUIResource("Dialog", font.getStyle(), font.getSize()));
                        }
                    }
                }
            }
        }
        LafManagerImpl.initInputMapDefaults(defaults);
        initIdeaDefaults(defaults);
        patchStyledEditorKit(defaults);
        patchComboBox(metalDefaults, defaults);
        defaults.remove("Spinner.arrowButtonBorder");
        defaults.put("Spinner.arrowButtonSize", JBUI.size(16, 5).asUIResource());
        MetalLookAndFeel.setCurrentTheme(createMetalTheme());
        if (SystemInfo.isWindows && Registry.is("ide.win.frame.decoration")) {
            JFrame.setDefaultLookAndFeelDecorated(true);
            JDialog.setDefaultLookAndFeelDecorated(true);
        }
        if (SystemInfo.isLinux && JBUI.isUsrHiDPI()) {
            applySystemFonts(defaults);
        }
        defaults.put("EditorPane.font", defaults.getFont("TextField.font"));
        if (SystemInfo.isMacOSYosemite) {
            installMacOSXFonts(defaults);
        }
        return defaults;
    } catch (Exception e) {
        log(e);
    }
    return super.getDefaults();
}
Also used : FontUIResource(javax.swing.plaf.FontUIResource) Method(java.lang.reflect.Method) MetalLookAndFeel(javax.swing.plaf.metal.MetalLookAndFeel) IOException(java.io.IOException)

Example 17 with FontUIResource

use of javax.swing.plaf.FontUIResource in project intellij-community by JetBrains.

the class IntroFontProperty method importSnapshotValue.

@Override
public void importSnapshotValue(final SnapshotContext context, final JComponent component, final RadComponent radComponent) {
    try {
        if (component.getParent() != null) {
            Font componentFont = (Font) myReadMethod.invoke(component, EMPTY_OBJECT_ARRAY);
            if (componentFont instanceof FontUIResource) {
                final Constructor constructor = component.getClass().getConstructor(ArrayUtil.EMPTY_CLASS_ARRAY);
                constructor.setAccessible(true);
                JComponent newComponent = (JComponent) constructor.newInstance(ArrayUtil.EMPTY_OBJECT_ARRAY);
                Font defaultFont = (Font) myReadMethod.invoke(newComponent, EMPTY_OBJECT_ARRAY);
                if (defaultFont == componentFont) {
                    return;
                }
                UIDefaults defaults = UIManager.getDefaults();
                Enumeration e = defaults.keys();
                while (e.hasMoreElements()) {
                    Object key = e.nextElement();
                    Object value = defaults.get(key);
                    if (key instanceof String && value == componentFont) {
                        setValue(radComponent, FontDescriptor.fromSwingFont((String) key));
                        return;
                    }
                }
            }
            Font parentFont = (Font) myReadMethod.invoke(component.getParent(), EMPTY_OBJECT_ARRAY);
            if (!Comparing.equal(componentFont, parentFont)) {
                String fontName = componentFont.getName().equals(parentFont.getName()) ? null : componentFont.getName();
                int fontStyle = componentFont.getStyle() == parentFont.getStyle() ? -1 : componentFont.getStyle();
                int fontSize = componentFont.getSize() == parentFont.getSize() ? -1 : componentFont.getSize();
                setValue(radComponent, new FontDescriptor(fontName, fontStyle, fontSize));
            }
        }
    } catch (Exception e) {
    // ignore
    }
}
Also used : Enumeration(java.util.Enumeration) FontUIResource(javax.swing.plaf.FontUIResource) Constructor(java.lang.reflect.Constructor) FontDescriptor(com.intellij.uiDesigner.lw.FontDescriptor)

Example 18 with FontUIResource

use of javax.swing.plaf.FontUIResource in project adempiere by adempiere.

the class ThemeUtils method parseFont.

//  parseColor
/**
	 *  Parse Font
	 *  <p>
	 *  javax.swing.plaf.FontUIResource[family=dialog.bold,name=Dialog,style=bold,size=12]
	 *
	 *  @param information string information to be parsed
	 *  @param stdFont font used if info cannot be parsed
	 *  @return font
	 */
public static FontUIResource parseFont(String information, FontUIResource stdFont) {
    if (information == null || information.length() == 0 || information.trim().length() == 0)
        return stdFont;
    //	System.out.print("ParseFont=" + info);
    try {
        String name = information.substring(information.indexOf("name=") + 5, information.indexOf(",style="));
        String s = information.substring(information.indexOf("style=") + 6, information.indexOf(",size="));
        int style = Font.PLAIN;
        if (s.equals("bold"))
            style = Font.BOLD;
        else if (s.equals("italic"))
            style = Font.ITALIC;
        else if (s.equals("bolditalic"))
            style = Font.BOLD | Font.ITALIC;
        int size = Integer.parseInt(information.substring(information.indexOf(",size=") + 6, information.lastIndexOf(']')));
        FontUIResource retValue = new FontUIResource(name, style, size);
        //	System.out.println(" - " + retValue.toString());
        return retValue;
    } catch (Exception e) {
        log.config(information + " - cannot parse: " + e.toString());
    }
    return stdFont;
}
Also used : FontUIResource(javax.swing.plaf.FontUIResource)

Example 19 with FontUIResource

use of javax.swing.plaf.FontUIResource in project JMRI by JMRI.

the class GuiLafConfigPaneXml method setUIFontSize.

public void setUIFontSize(float size) {
    Enumeration<Object> keys = UIManager.getDefaults().keys();
    Font f;
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        Object value = UIManager.get(key);
        if (value instanceof FontUIResource) {
            f = UIManager.getFont(key).deriveFont(((Font) value).getStyle(), size);
            UIManager.put(key, f);
        }
    }
}
Also used : FontUIResource(javax.swing.plaf.FontUIResource) Font(java.awt.Font)

Example 20 with FontUIResource

use of javax.swing.plaf.FontUIResource in project jmeter by apache.

the class JMeterUtils method applyScaleOnFonts.

/**
     * Apply HiDPI scale factor on fonts
     * @param scale float scale to apply
     */
public static void applyScaleOnFonts(final float scale) {
    log.info("Applying HiDPI scale: {}", scale);
    SwingUtilities.invokeLater(() -> {
        UIDefaults defaults = UIManager.getLookAndFeelDefaults();
        // the font objects are missing, so iterate over the keys, only
        for (Object key : new ArrayList<>(defaults.keySet())) {
            Object value = defaults.get(key);
            log.debug("Try key {} with value {}", key, value);
            if (value instanceof Font) {
                Font font = (Font) value;
                final float newSize = font.getSize() * scale;
                if (font instanceof FontUIResource) {
                    defaults.put(key, new FontUIResource(font.getName(), font.getStyle(), Math.round(newSize)));
                } else {
                    defaults.put(key, font.deriveFont(newSize));
                }
            }
        }
        JMeterUtils.refreshUI();
    });
}
Also used : UIDefaults(javax.swing.UIDefaults) FontUIResource(javax.swing.plaf.FontUIResource) ArrayList(java.util.ArrayList) Font(java.awt.Font)

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