Search in sources :

Example 11 with UIDefaults

use of javax.swing.UIDefaults in project adempiere by adempiere.

the class CompiereLookAndFeel method getDefaults.

//  getDescription
/**************************************************************************
	 *  Get/Create Defaults
	 *  @return UI Defaults
	 */
public UIDefaults getDefaults() {
    //  Theme already created/set
    MetalLookAndFeel.setCurrentTheme(s_theme);
    // calls init..Defaults
    UIDefaults defaults = super.getDefaults();
    return defaults;
}
Also used : UIDefaults(javax.swing.UIDefaults)

Example 12 with UIDefaults

use of javax.swing.UIDefaults in project jdk8u_jdk by JetBrains.

the class ColorCustomizationTest method testOverrides.

void testOverrides() {
    Color defaultColor = label.getBackground();
    // override default background
    UIDefaults defs = new UIDefaults();
    defs.put("Label.background", new ColorUIResource(Color.RED));
    label.putClientProperty("Nimbus.Overrides", defs);
    check(Color.RED);
    // change overriding color
    defs = new UIDefaults();
    defs.put("Label.background", new ColorUIResource(Color.GREEN));
    label.putClientProperty("Nimbus.Overrides", defs);
    check(Color.GREEN);
    // remove override
    label.putClientProperty("Nimbus.Overrides", null);
    check(defaultColor);
}
Also used : UIDefaults(javax.swing.UIDefaults) Color(java.awt.Color) ColorUIResource(javax.swing.plaf.ColorUIResource)

Example 13 with UIDefaults

use of javax.swing.UIDefaults in project jdk8u_jdk by JetBrains.

the class ColorCustomizationTest method testInheritance.

void testInheritance() {
    Color defaultColor = label.getBackground();
    // more specific setting is in global defaults
    UIManager.put("Label[Enabled].background", new ColorUIResource(Color.RED));
    // less specific one is in overrides
    UIDefaults defs = new UIDefaults();
    defs.put("Label.background", new ColorUIResource(Color.GREEN));
    // global wins
    label.putClientProperty("Nimbus.Overrides", defs);
    check(Color.RED);
    // now override wins
    label.putClientProperty("Nimbus.Overrides.InheritDefaults", false);
    check(Color.GREEN);
    // global is back
    label.putClientProperty("Nimbus.Overrides.InheritDefaults", true);
    check(Color.RED);
    // back to default color
    UIManager.put("Label[Enabled].background", null);
    label.putClientProperty("Nimbus.Overrides.InheritDefaults", false);
    label.putClientProperty("Nimbus.Overrides", null);
    check(defaultColor);
}
Also used : UIDefaults(javax.swing.UIDefaults) Color(java.awt.Color) ColorUIResource(javax.swing.plaf.ColorUIResource)

Example 14 with UIDefaults

use of javax.swing.UIDefaults 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)

Example 15 with UIDefaults

use of javax.swing.UIDefaults 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)

Aggregations

UIDefaults (javax.swing.UIDefaults)20 FontUIResource (javax.swing.plaf.FontUIResource)5 Color (java.awt.Color)4 Font (java.awt.Font)3 ColorUIResource (javax.swing.plaf.ColorUIResource)3 Dimension (java.awt.Dimension)2 Insets (java.awt.Insets)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 JFrame (javax.swing.JFrame)2 Plastic3DLookAndFeel (com.jgoodies.looks.plastic.Plastic3DLookAndFeel)1 SkyBluer (com.jgoodies.looks.plastic.theme.SkyBluer)1 Image (java.awt.Image)1 Point (java.awt.Point)1 SystemColor (java.awt.SystemColor)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 File (java.io.File)1