Java Swing UIManager getDefaultActiveBackgroundColour()

Here you can find the source of getDefaultActiveBackgroundColour()

Description

get Default Active Background Colour

License

Open Source License

Declaration

public static Color getDefaultActiveBackgroundColour() 

Method Source Code


//package com.java2s;
/*/* w w  w. j  a v a2 s.c om*/
 * UIUtils.java
 *
 * Copyright (C) 2002-2015 Takis Diakoumis
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */

import java.awt.Color;

import javax.swing.UIManager;

public class Main {
    /** the active colour for backgrounds */
    private static Color defaultActiveBackgroundColour;

    public static Color getDefaultActiveBackgroundColour() {
        if (defaultActiveBackgroundColour == null) {
            if (!isWindowsLookAndFeel()) {
                Color color = UIManager.getColor("activeCaptionBorder");
                if (color == null) {
                    color = UIManager.getColor("controlShadow");
                }

                defaultActiveBackgroundColour = getBrighter(color, 0.85);

            } else {

                defaultActiveBackgroundColour = UIManager.getColor("controlLtHighlight");
            }
        }
        return defaultActiveBackgroundColour;
    }

    /**
     * Returns whether the current applied look and feel is
     * the WindowsLookAndFeel
     *
     * @return true | false
     */
    public static boolean isWindowsLookAndFeel() {
        return isLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    }

    public static Color getBrighter(Color color, double factor) {
        int r = color.getRed();
        int g = color.getGreen();
        int b = color.getBlue();

        int i = (int) (1.0 / (1.0 - factor));
        if (r == 0 && g == 0 && b == 0) {
            return new Color(i, i, i);
        }
        if (r > 0 && r < i)
            r = i;
        if (g > 0 && g < i)
            g = i;
        if (b > 0 && b < i)
            b = i;

        return new Color(Math.min((int) (r / factor), 255), Math.min((int) (g / factor), 255),
                Math.min((int) (b / factor), 255));
    }

    private static boolean isLookAndFeel(String name) {
        return UIManager.getLookAndFeel().getClass().getName().equals(name);
    }
}

Related

  1. fixHtmlDisplay(JComponent component)
  2. getAnimationSpeed()
  3. getClassLoaderForResources()
  4. getClassLoaderForResources()
  5. getDark()
  6. getDefaultAttributeSet()
  7. getDefaultFieldHeigth()
  8. getDefaultForeground()
  9. getDefaultInactiveBackgroundColour()