Java Color Value getSubstanceColor(String name)

Here you can find the source of getSubstanceColor(String name)

Description

Returns a color from the currently active Substance skin.

License

BSD License

Parameter

Parameter Description
name The name of a Color, for example #LIGHT_COLOR .

Exception

Parameter Description
Exception If an error occurs.

Return

The color, or null if no color by that name is defined.

Declaration

public static Color getSubstanceColor(String name) throws Exception 

Method Source Code


//package com.java2s;
/*//  ww w  .ja v a  2s  .  c om
 * 11/11/2010
 *
 * SubstanceUtils.java - Utility methods for Java 1.4-compatible applications
 * looking to support Substance 6.1 if the current JRE is 1.6+.
 * Copyright (C) 2003 Robert Futrell
 * http://fifesoft.com/rtext
 * Licensed under a modified BSD license.
 * See the included license file for details.
 */

import java.awt.Color;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;

public class Main {
    /**
     * Package for the Substance public API.
     */
    private static final String PKG = "org.pushingpixels.substance.api.";

    /**
     * Returns a color from the currently active Substance skin.
     *
     * @param name The name of a Color, for example {@link #LIGHT_COLOR}.
     * @return The color, or <code>null</code> if no color by that name is
     *         defined.
     * @throws Exception If an error occurs.
     */
    public static Color getSubstanceColor(String name) throws Exception {

        /*
        LookAndFeel laf = UIManager.getLookAndFeel();
        if (laf instanceof SubstanceLookAndFeel) {
           SubstanceSkin skin = SubstanceLookAndFeel.getCurrentSkin();
           SubstanceColorScheme scheme = skin.getActiveColorScheme(
                            DecorationAreaType.NONE);
           scheme.getXXX();
        }
        */

        Color color = null;
        name = Character.toUpperCase(name.charAt(0)) + name.substring(1);

        LookAndFeel laf = UIManager.getLookAndFeel();
        ClassLoader cl = (ClassLoader) UIManager.get("ClassLoader");
        if (cl != null) {
            Class<?> clazz = Class.forName(PKG + "SubstanceLookAndFeel", true, cl);
            if (clazz.isInstance(laf)) {
                Class<?> skinClazz = Class.forName(PKG + "SubstanceSkin", true, cl);
                Method m = clazz.getDeclaredMethod("getCurrentSkin");
                Object skin = m.invoke(null);
                Class<?> decAreaTypeClazz = Class.forName(PKG + "DecorationAreaType", true, cl);
                Field decAreaTypeField = decAreaTypeClazz.getDeclaredField("GENERAL");
                Object decAreaType = decAreaTypeField.get(null);
                m = skinClazz.getDeclaredMethod("getActiveColorScheme", new Class[] { decAreaTypeClazz });
                Object colorScheme = m.invoke(skin, new Object[] { decAreaType });
                Class<?> colorSchemeClazz = Class.forName(PKG + "SubstanceColorScheme", true, cl);
                m = colorSchemeClazz.getMethod("get" + name);
                color = (Color) m.invoke(colorScheme);
            }
        }

        return color;

    }
}

Related

  1. getLetterIcon(Character letter, Color fgColor, Color bgColor, int size)
  2. getLightColor()
  3. getMediumDarkColor()
  4. getNimbusDisabledTextColor()
  5. getRolloverColor()
  6. getTextColor()
  7. getTextForegroundColor()
  8. getTextInactiveTextColor()
  9. getTextPaneLabel(JScrollPane jsp, Color textColor)