Java Swing Font getAsNotUIResource(Font font)

Here you can find the source of getAsNotUIResource(Font font)

Description

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

License

Open Source License

Parameter

Parameter Description
font the base font

Return

a font not of type UIResource, may be null.

Declaration

public static Font getAsNotUIResource(Font font) 

Method Source Code


//package com.java2s;
/*/*from  www .  j  a va  2  s . c  om*/
 * $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. createTextLayout(JComponent c, String s, Font f, FontRenderContext frc)
  2. defaultFont()
  3. drawCentredText(Graphics2D g, Font font, String text, int x, int y)
  4. drawString(Graphics g, Font font, String text, Rectangle rect, int align)
  5. drawString(Graphics g, String text, int x, int y, Font font, Color color)
  6. getDefaultFont()
  7. getDefaultLabelBoldFont()
  8. getDefaultLabelFont()
  9. getFont(String name)