Search in sources :

Example 16 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 17 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 18 with UIDefaults

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

use of javax.swing.UIDefaults in project jgnash by ccavanaugh.

the class NimbusUtils method reduceNimbusButtonMargin.

/**
     * Reduce the margins around the content of a button for the Nimbus look and feel
     * 
     * @param button button to alter
     */
public static void reduceNimbusButtonMargin(final JButton button) {
    UIDefaults buttonDefaults = new UIDefaults();
    buttonDefaults.put("Button.contentMargins", new Insets(6, 6, 6, 6));
    button.putClientProperty("Nimbus.Overrides", buttonDefaults);
    button.putClientProperty("Nimbus.Overrides.InheritDefaults", Boolean.FALSE);
}
Also used : UIDefaults(javax.swing.UIDefaults) Insets(java.awt.Insets)

Example 20 with UIDefaults

use of javax.swing.UIDefaults in project ceylon-compiler by ceylon.

the class Test method test.

static void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    JPanel jPanel = new javax.swing.JPanel();
    UIDefaults defaults = UIManager.getDefaults();
    Object cl = defaults.get("ClassLoader");
    ClassLoader uiClassLoader = (cl != null) ? (ClassLoader) cl : jPanel.getClass().getClassLoader();
    try {
        String className = (String) defaults.get(jPanel.getUIClassID());
        if (className != null) {
            Class cls = (Class) defaults.get(className);
            if (cls == null) {
                if (uiClassLoader == null) {
                    Method m = SwingUtilities.class.getDeclaredMethod("loadSystemClass", String.class);
                    m.setAccessible(true);
                    m.invoke(null, className);
                    // cls = SwingUtilities.loadSystemClass(className);
                    throw new RuntimeException("FAIL");
                } else {
                    cls = uiClassLoader.loadClass(className);
                }
            }
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (ClassCastException e) {
        e.printStackTrace();
    }
    jPanel.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) UIDefaults(javax.swing.UIDefaults) Method(java.lang.reflect.Method)

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