Example usage for javax.swing UIDefaults get

List of usage examples for javax.swing UIDefaults get

Introduction

In this page you can find the example usage for javax.swing UIDefaults get.

Prototype

public Object get(Object key) 

Source Link

Document

Returns the value for key.

Usage

From source file:Main.java

public static void main(String[] argv) {
    UIDefaults uidefs = UIManager.getLookAndFeelDefaults();
    String[] keys = (String[]) uidefs.keySet().toArray(new String[0]);
    for (int i = 0; i < keys.length; i++) {
        Object v = uidefs.get(keys[i]);
        if (v instanceof Integer) {
            int intVal = uidefs.getInt(keys[i]);
        } else if (v instanceof Boolean) {
            boolean boolVal = uidefs.getBoolean(keys[i]);
        } else if (v instanceof String) {
            String strVal = uidefs.getString(keys[i]);
        } else if (v instanceof Dimension) {
            Dimension dimVal = uidefs.getDimension(keys[i]);
        } else if (v instanceof Insets) {
            Insets insetsVal = uidefs.getInsets(keys[i]);
        } else if (v instanceof Color) {
            Color colorVal = uidefs.getColor(keys[i]);
        } else if (v instanceof Font) {
            Font fontVal = uidefs.getFont(keys[i]);
        } else if (v instanceof Border) {
            Border borderVal = uidefs.getBorder(keys[i]);
        } else if (v instanceof Icon) {
            Icon iconVal = uidefs.getIcon(keys[i]);
        } else if (v instanceof javax.swing.text.JTextComponent.KeyBinding[]) {
            JTextComponent.KeyBinding[] keyBindsVal = (JTextComponent.KeyBinding[]) uidefs.get(keys[i]);
        } else if (v instanceof InputMap) {
            InputMap imapVal = (InputMap) uidefs.get(keys[i]);
        } else {/*from  w  w w. j a  v  a 2  s  . c o m*/
            System.out.println("Unknown type");
        }
    }
}

From source file:Main.java

public static void main(String[] argv) {
    UIDefaults uidefs = UIManager.getLookAndFeelDefaults();
    String[] keys = (String[]) uidefs.keySet().toArray(new String[0]);
    for (int i = 0; i < keys.length; i++) {
        Object v = uidefs.get(keys[i]);
        if (v instanceof Integer) {
            int intVal = uidefs.getInt(keys[i]);
        } else if (v instanceof Boolean) {
            boolean boolVal = uidefs.getBoolean(keys[i]);
        } else if (v instanceof String) {
            String strVal = uidefs.getString(keys[i]);
        } else if (v instanceof Dimension) {
            Dimension dimVal = uidefs.getDimension(keys[i]);
        } else if (v instanceof Insets) {
            Insets insetsVal = uidefs.getInsets(keys[i]);
        } else if (v instanceof Color) {
            Color colorVal = uidefs.getColor(keys[i]);
        } else if (v instanceof Font) {
            Font fontVal = uidefs.getFont(keys[i]);
        } else if (v instanceof Border) {
            Border borderVal = uidefs.getBorder(keys[i]);
        } else if (v instanceof Icon) {
            Icon iconVal = uidefs.getIcon(keys[i]);
        } else if (v instanceof javax.swing.text.JTextComponent.KeyBinding[]) {
            javax.swing.text.JTextComponent.KeyBinding[] keyBindsVal = (javax.swing.text.JTextComponent.KeyBinding[]) uidefs
                    .get(keys[i]);//  w ww  .java  2s. c o  m
        } else if (v instanceof InputMap) {
            InputMap imapVal = (InputMap) uidefs.get(keys[i]);
        } else {
            System.out.println("Unknown type");
        }
    }
}

From source file:Main.java

public static void printUIDefaults() {
    UIDefaults uiDefaults = UIManager.getDefaults();
    Enumeration<Object> e = uiDefaults.keys();
    while (e.hasMoreElements()) {
        Object key = e.nextElement();
        Object val = uiDefaults.get(key);
        System.out.println("[" + key.toString() + "]:[" + (null != val ? val.toString() : "(null)") + "]");
    }/*from w  w  w  .ja  v  a 2 s  . c  o m*/
}

From source file:Main.java

/**
 * magnify the all fonts in swing./*from   w  w  w .  j a  va2s  .  c  om*/
 * 
 * @param mag
 *            magnify parameter <br/> mag > 1. : large <br/> mag < 1. :
 *            small
 */
public static void magnifyAllFont(float mag) {
    List history = new LinkedList();
    UIDefaults defaults = UIManager.getDefaults();
    Enumeration it = defaults.keys();
    while (it.hasMoreElements()) {
        Object key = it.nextElement();
        Object a = defaults.get(key);
        if (a instanceof Font) {
            if (history.contains(a))
                continue;
            Font font = (Font) a;
            font = font.deriveFont(font.getSize2D() * mag);
            defaults.put(key, font);
            history.add(font);
        }
    }
}

From source file:Main.java

/**
 * Convenience method for retrieving the UIDefault for a single property of
 * a particular class./*from   w  w w .ja  v a  2  s .  c  o m*/
 *
 * @param clazz the class of interest
 * @param property the property to query
 * @return the UIDefault property, or null if not found
 */
public static Object getUIDefaultOfClass(Class clazz, String property) {
    Object retVal = null;
    UIDefaults defaults = getUIDefaultsOfClass(clazz);
    List<Object> listKeys = Collections.list(defaults.keys());
    for (Object key : listKeys) {
        if (key.equals(property)) {
            return defaults.get(key);
        }
        if (key.toString().equalsIgnoreCase(property)) {
            retVal = defaults.get(key);
        }
    }
    return retVal;
}

From source file:Main.java

/**
 * Convenience method for retrieving the UIDefault for a single property
 * of a particular class./*w  w w .j ava  2 s .  c  o m*/
 * 
 * @param clazz the class of interest
 * @param property the property to query
 * @return the UIDefault property, or null if not found
 */
public static Object getUIDefaultOfClass(Class<?> clazz, String property) {
    Object retVal = null;
    UIDefaults defaults = getUIDefaultsOfClass(clazz);
    List<Object> listKeys = Collections.list(defaults.keys());
    for (Object key : listKeys) {
        if (key.equals(property)) {
            return defaults.get(key);
        }
        if (key.toString().equalsIgnoreCase(property)) {
            retVal = defaults.get(key);
        }
    }
    return retVal;
}

From source file:net.sf.nmedit.jtheme.JTContext.java

public static boolean hasUIClass(JComponent component, UIDefaults defaults) {
    String uiClassID = component.getUIClassID();
    if (uiClassID == null)
        return false;

    Object cl = defaults.get(UIDefaultsClassLoaderKey);
    ClassLoader uiClassLoader = (cl != null) ? (ClassLoader) cl : component.getClass().getClassLoader();

    Class uiClass = defaults.getUIClass(uiClassID, uiClassLoader);
    return uiClass != null;
}

From source file:com.diversityarrays.kdxplore.KDXplore.java

static public void setUIfontSize(float multiplier) {
    UIDefaults defaults = UIManager.getDefaults();
    for (Enumeration<?> e = defaults.keys(); e.hasMoreElements();) {
        Object key = e.nextElement();
        Object value = defaults.get(key);
        if (value instanceof Font) {
            Font font = (Font) value;
            int newSize = Math.round(font.getSize() * multiplier);
            if (value instanceof FontUIResource) {
                defaults.put(key, new FontUIResource(font.getName(), font.getStyle(), newSize));
            } else {
                defaults.put(key, new Font(font.getName(), font.getStyle(), newSize));
            }//  ww  w. j  a  v a 2s.  c o m
        } else if (value instanceof Integer) {
            if ("Tree.rowHeight".equals(key)) { //$NON-NLS-1$
                // System.out.println(key+": "+value);
                Integer rh = (Integer) value;
                rh = (int) (rh * multiplier * 1.4);
                defaults.put(key, rh);
            }
        }
    }
}

From source file:Main.java

/**
 * Convenience method for retrieving a subset of the UIDefaults pertaining
 * to a particular class./*  ww w .  j  a  v a 2s . c  o  m*/
 *
 * @param className fully qualified name of the class of interest
 * @return the UIDefaults of the class named
 */
public static UIDefaults getUIDefaultsOfClass(String className) {
    UIDefaults retVal = new UIDefaults();
    UIDefaults defaults = UIManager.getLookAndFeelDefaults();
    List<?> listKeys = Collections.list(defaults.keys());
    for (Object key : listKeys) {
        if (key instanceof String && ((String) key).startsWith(className)) {
            String stringKey = (String) key;
            String property = stringKey;
            if (stringKey.contains(".")) {
                property = stringKey.substring(stringKey.indexOf(".") + 1);
            }
            retVal.put(property, defaults.get(key));
        }
    }
    return retVal;
}

From source file:Main.java

/**
 * Convenience method for retrieving a subset of the UIDefaults pertaining
 * to a particular class.//  w  w w .  ja  v a 2 s .  c  o m
 * 
 * @param className
 *            fully qualified name of the class of interest
 * @return the UIDefaults of the class named
 */
public static UIDefaults getUIDefaultsOfClass(final String className) {
    final UIDefaults retVal = new UIDefaults();
    final UIDefaults defaults = UIManager.getLookAndFeelDefaults();
    final List<?> listKeys = Collections.list(defaults.keys());
    for (final Object key : listKeys) {
        if (key instanceof String && ((String) key).startsWith(className)) {
            final String stringKey = (String) key;
            String property = stringKey;
            if (stringKey.contains(".")) {
                property = stringKey.substring(stringKey.indexOf(".") + 1);
            }
            retVal.put(property, defaults.get(key));
        }
    }
    return retVal;
}