Java Color Value getAsNotUIResource(Color color)

Here you can find the source of getAsNotUIResource(Color color)

Description

Returns a Color based on the param which is not of type UIResource.

License

Open Source License

Parameter

Parameter Description
color the base color

Return

a color not of type UIResource, may be null.

Declaration

public static Color getAsNotUIResource(Color color) 

Method Source Code


//package com.java2s;
/*/*from   w  w w.  ja v a  2  s. c  o  m*/
 * $Id$
 *
 * Copyright 2009 Sun Microsystems, Inc., 4150 Network Circle,
 * Santa Clara, California 95054, U.S.A. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library 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
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

import java.awt.Color;
import java.awt.Font;

import javax.swing.plaf.UIResource;

public class Main {
    /**
     * Returns a Font based on the param which is not of type UIResource. 
     * 
     * @param font the base font
     * @return a font not of type UIResource, may be null.
     */
    public static Font getAsNotUIResource(Font font) {
        if (!(font instanceof UIResource))
            return font;
        // PENDING JW: correct way to create another font instance?
        return font.deriveFont(font.getAttributes());
    }

    /**
     * Returns a Color based on the param which is not of type UIResource. 
     * 
     * @param color the base color
     * @return a color not of type UIResource, may be null.
     */
    public static Color getAsNotUIResource(Color color) {
        if (!(color instanceof UIResource))
            return color;
        // PENDING JW: correct way to create another color instance?
        float[] rgb = color.getRGBComponents(null);
        return new Color(rgb[0], rgb[1], rgb[2], rgb[3]);
    }
}

Related

  1. getBackgroundColor()
  2. getBlueGreyColor(Color base)
  3. getBorder(Color clr, int thickness)
  4. getColorBackground()