001 /*
002 * $Id: JXTitledPanelAddon.java,v 1.11 2006/04/12 09:27:48 kleopatra Exp $
003 *
004 * Copyright 2004 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 package org.jdesktop.swingx.plaf;
022
023 import java.awt.Color;
024 import java.util.Arrays;
025 import java.util.List;
026
027 import javax.swing.UIManager;
028 import javax.swing.plaf.ColorUIResource;
029 import javax.swing.plaf.metal.MetalLookAndFeel;
030
031 import org.jdesktop.swingx.JXTitledPanel;
032 import org.jdesktop.swingx.painter.gradient.BasicGradientPainter;
033
034 /**
035 * Addon for <code>JXTitledPanel</code>.<br>
036 *
037 */
038 public class JXTitledPanelAddon extends AbstractComponentAddon {
039
040 public JXTitledPanelAddon() {
041 super("JXTitledPanel");
042 }
043
044 @Override
045 protected void addBasicDefaults(LookAndFeelAddons addon, List<Object> defaults) {
046 super.addBasicDefaults(addon, defaults);
047 defaults.addAll(Arrays.asList(new Object[] {
048 JXTitledPanel.uiClassID,
049 "org.jdesktop.swingx.plaf.metal.MetalTitledPanelUI",
050 "JXTitledPanel.title.font",
051 UIManager.getFont("Button.font"),
052 "JXTitledPanel.title.foreground", new ColorUIResource(Color.WHITE),
053 "JXTitledPanel.title.painter", new PainterUIResource(
054 new BasicGradientPainter(0, 0, Color.LIGHT_GRAY, 0, 1, Color.GRAY))
055 }));
056 }
057
058 @Override
059 protected void addMetalDefaults(LookAndFeelAddons addon, List<Object> defaults) {
060 super.addMetalDefaults(addon, defaults);
061
062 if (isPlastic()) {
063 defaults.addAll(Arrays.asList(new Object[] {
064 "JXTitledPanel.title.foreground", new ColorUIResource(255, 255, 255),
065 "JXTitledPanel.title.painter", new PainterUIResource(
066 new BasicGradientPainter(0, 0,
067 new Color(49, 121, 242),
068 0, 1,
069 new Color(198, 211, 247)
070 ))
071 }));
072 } else {
073 defaults.addAll(Arrays.asList(new Object[] {
074 "JXTitledPanel.title.foreground", new ColorUIResource(255, 255, 255),
075 "JXTitledPanel.title.painter", new PainterUIResource(
076 new BasicGradientPainter(0, 0,
077 MetalLookAndFeel.getCurrentTheme().getPrimaryControl(), 0, 1,
078 MetalLookAndFeel.getCurrentTheme().getPrimaryControlDarkShadow()))
079 }));
080 }
081 }
082
083 @Override
084 protected void addWindowsDefaults(LookAndFeelAddons addon, List<Object> defaults) {
085 super.addWindowsDefaults(addon, defaults);
086 // JW: copied to get hold of the old colors
087 // "JXTitledPanel.title.foreground", new ColorUIResource(255, 255, 255),
088 // "JXTitledPanel.title.darkBackground", new ColorUIResource(49, 121, 242),
089 // "JXTitledPanel.title.lightBackground", new ColorUIResource(198, 211, 247),
090
091 // JW: hot fix for #291-swingx
092 // was tracked down by Neil Weber - the requested colors are not available in
093 // all LFs, so changed to fall-back to something real
094 // don't understand why this has blown when trying to toggle to Metal...
095 // definitely needs deeper digging
096 defaults.addAll(Arrays.asList(new Object[] {
097 "JXTitledPanel.title.foreground",
098 getSafeColor("InternalFrame.activeTitleForeground", new ColorUIResource(255, 255, 255)),
099 "JXTitledPanel.title.painter", new PainterUIResource(
100 new BasicGradientPainter(0, 0,
101 getSafeColor("InternalFrame.inactiveTitleGradient", new ColorUIResource(49, 121, 242)), 0, 1,
102 getSafeColor("InternalFrame.activeTitleBackground", new ColorUIResource(198, 211, 247))))
103 }));
104
105 // defaults.addAll(Arrays.asList(new Object[] {
106 // "JXTitledPanel.title.foreground", UIManager.getColor("InternalFrame.activeTitleForeground"),
107 // "JXTitledPanel.title.painter", new PainterUIResource(
108 // new BasicGradientPainter(0, 0,
109 // UIManager.getColor("InternalFrame.inactiveTitleGradient"), 0, 1,
110 // UIManager.getColor("InternalFrame.activeTitleBackground")))
111 // }));
112
113
114 }
115
116 protected Color getSafeColor(String uiKey, Color fallBack) {
117 Color color = UIManager.getColor(uiKey);
118 if (color == null) {
119 color = fallBack;
120 }
121 return color;
122 }
123 }