Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Collections;

import java.util.List;

import javax.swing.UIDefaults;
import javax.swing.UIManager;

public class Main {
    /**
     * Convenience method for retrieving a subset of the UIDefaults pertaining
     * to a particular class.
     * 
     * @param clazz
     *            the class of interest
     * @return the UIDefaults of the class
     */
    public static UIDefaults getUIDefaultsOfClass(final Class clazz) {
        String name = clazz.getName();
        name = name.substring(name.lastIndexOf(".") + 2);
        return getUIDefaultsOfClass(name);
    }

    /**
     * Convenience method for retrieving a subset of the UIDefaults pertaining
     * to a particular class.
     * 
     * @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;
    }
}