001/* 002 * $Id$ 003 * 004 * Copyright 2009 Sun Microsystems, Inc., 4150 Network Circle, 005 * Santa Clara, California 95054, U.S.A. All rights reserved. 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this library; if not, write to the Free Software 019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 020 * 021 */ 022package org.jdesktop.swingx.plaf; 023 024import java.awt.Color; 025import java.awt.Font; 026 027import javax.swing.plaf.ComponentUI; 028import javax.swing.plaf.UIResource; 029 030/** 031 * Collection of helpers. Could move to LookAndFeelAddon? 032 * 033 * @author Jeanette Winzenburg 034 */ 035public class LookAndFeelUtils { 036 037 /** 038 * Returns the ui that is of type <code>klass</code>, or null if 039 * one can not be found. 040 */ 041 public static Object getUIOfType(ComponentUI ui, Class<?> klass) { 042 if (klass.isInstance(ui)) { 043 return ui; 044 } 045 return null; 046 } 047 048 /** 049 * Returns a Font based on the param which is not of type UIResource. 050 * 051 * @param font the base font 052 * @return a font not of type UIResource, may be null. 053 */ 054 public static Font getAsNotUIResource(Font font) { 055 if (!(font instanceof UIResource)) return font; 056 // PENDING JW: correct way to create another font instance? 057 return font.deriveFont(font.getAttributes()); 058 } 059 060 /** 061 * Returns a Color based on the param which is not of type UIResource. 062 * 063 * @param color the base color 064 * @return a color not of type UIResource, may be null. 065 */ 066 public static Color getAsNotUIResource(Color color) { 067 if (!(color instanceof UIResource)) return color; 068 // PENDING JW: correct way to create another color instance? 069 float[] rgb = color.getRGBComponents(null); 070 return new Color(rgb[0], rgb[1], rgb[2], rgb[3]); 071 } 072 073 074}