001: /*
002: * Copyright (C) 2004 NNL Technology AB
003: * Visit www.infonode.net for information about InfoNode(R)
004: * products and how to contact NNL Technology AB.
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
019: * MA 02111-1307, USA.
020: */
021:
022: // $Id: UIManagerColorProvider.java,v 1.10 2005/12/04 13:46:03 jesper Exp $
023: package net.infonode.gui.colorprovider;
024:
025: import javax.swing.*;
026: import java.awt.*;
027: import java.io.Serializable;
028:
029: /**
030: * A {@link ColorProvider} which returns a property color from the {@link UIManager}.
031: *
032: * @author $Author: jesper $
033: * @version $Revision: 1.10 $
034: */
035: public class UIManagerColorProvider extends AbstractColorProvider
036: implements Serializable {
037: private static final long serialVersionUID = 1;
038:
039: /**
040: * A provider for the 'control' color.
041: */
042: public static final UIManagerColorProvider CONTROL_COLOR = new UIManagerColorProvider(
043: "control", Color.LIGHT_GRAY);
044:
045: /**
046: * A provider for the 'controlDkShadow' color.
047: */
048: public static final UIManagerColorProvider CONTROL_DARK_SHADOW = new UIManagerColorProvider(
049: "controlDkShadow", Color.BLACK);
050:
051: /**
052: * A provider for the 'TabbedPane.highlight' color.
053: */
054: public static final UIManagerColorProvider TABBED_PANE_HIGHLIGHT = new UIManagerColorProvider(
055: "TabbedPane.highlight", Color.WHITE);
056:
057: /**
058: * A provider for the 'TabbedPane.shadow' color.
059: */
060: public static final UIManagerColorProvider TABBED_PANE_SHADOW = new UIManagerColorProvider(
061: "TabbedPane.shadow", Color.BLACK);
062:
063: /**
064: * A provider for the 'TabbedPane.darkShadow' color.
065: */
066: public static final UIManagerColorProvider TABBED_PANE_DARK_SHADOW = new UIManagerColorProvider(
067: "TabbedPane.darkShadow", Color.BLACK);
068:
069: /**
070: * A provider for the 'TabbedPane.background' color.
071: */
072: public static final UIManagerColorProvider TABBED_PANE_BACKGROUND = new UIManagerColorProvider(
073: "TabbedPane.background", Color.LIGHT_GRAY);
074:
075: /**
076: * A provider for the 'Desktop.background' color.
077: */
078: public static final UIManagerColorProvider DESKTOP_BACKGROUND = new UIManagerColorProvider(
079: "Desktop.background", Color.BLUE);
080:
081: private final String propertyName;
082: private Color defaultColor;
083:
084: /**
085: * Constructor.
086: *
087: * @param propertyName the name of the property which value will be retrieved from the {@link UIManager}.
088: */
089: public UIManagerColorProvider(String propertyName) {
090: this .propertyName = propertyName;
091: }
092:
093: /**
094: * Constructor.
095: *
096: * @param propertyName the name of the property which value will be retrieved from the {@link UIManager}.
097: * @param defaultColor the color to be used if the specified color doesn't exist in the UIManager
098: */
099: public UIManagerColorProvider(String propertyName,
100: Color defaultColor) {
101: this .propertyName = propertyName;
102: this .defaultColor = defaultColor;
103: }
104:
105: public Color getColor() {
106: Color color = UIManager.getColor(propertyName);
107:
108: return color == null ? defaultColor : color;
109: }
110: }
|