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: UIManagerUtil.java,v 1.6 2005/12/04 13:46:04 jesper Exp $
023: package net.infonode.gui;
024:
025: import net.infonode.gui.border.BorderUtil;
026: import net.infonode.util.ColorUtil;
027:
028: import javax.swing.*;
029: import javax.swing.border.Border;
030: import java.awt.*;
031:
032: /**
033: * @author $Author: jesper $
034: * @version $Revision: 1.6 $
035: */
036: public class UIManagerUtil {
037: private UIManagerUtil() {
038: }
039:
040: public static Insets getInsets(String key) {
041: return InsetsUtil.copy(UIManager.getInsets(key));
042: }
043:
044: public static Insets getInsets(String key, Insets insets) {
045: Insets i = getInsets(key);
046: return i == null ? insets : i;
047: }
048:
049: public static Insets getInsets(String key, String defaultKey) {
050: Insets i = getInsets(key);
051:
052: if (i != null)
053: return i;
054:
055: i = getInsets(defaultKey);
056: return i == null ? new Insets(0, 0, 0, 0) : i;
057: }
058:
059: public static Color getColor(String key) {
060: return ColorUtil.copy(UIManager.getColor(key));
061: }
062:
063: public static Color getColor(String key, String defaultKey) {
064: return getColor(key, defaultKey, Color.BLACK);
065: }
066:
067: public static Color getColor(String key, String defaultKey,
068: Color defaultColor) {
069: Color i = getColor(key);
070:
071: if (i != null)
072: return i;
073:
074: i = getColor(defaultKey);
075: return i == null ? defaultColor : i;
076: }
077:
078: public static Border getBorder(String key) {
079: return BorderUtil.copy(UIManager.getBorder(key));
080: }
081:
082: public static Border getBorder(String key, String defaultKey) {
083: Border i = getBorder(key);
084:
085: if (i != null)
086: return i;
087:
088: i = getBorder(defaultKey);
089: return i == null ? BorderFactory.createEmptyBorder() : i;
090: }
091:
092: public static Font getFont(String key) {
093: Font font = UIManager.getFont(key);
094: if (font == null)
095: font = new JLabel().getFont();
096: return FontUtil.copy(font);
097: }
098:
099: public static Font getFont(String key, String defaultKey) {
100: Font i = getFont(key);
101:
102: if (i != null)
103: return i;
104:
105: i = getFont(defaultKey);
106: return i == null ? new Font("Dialog", 0, 11) : i;
107: }
108:
109: public static Color getColor(String key, Color defaultColor) {
110: Color c = getColor(key);
111: return c == null ? defaultColor : c;
112: }
113: }
|