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: GradientTheme.java,v 1.22 2005/02/16 11:28:15 jesper Exp $
023: package net.infonode.tabbedpanel.theme;
024:
025: import net.infonode.gui.Colors;
026: import net.infonode.gui.colorprovider.ColorMultiplier;
027: import net.infonode.gui.colorprovider.ColorProvider;
028: import net.infonode.gui.colorprovider.ColorProviderUtil;
029: import net.infonode.gui.colorprovider.UIManagerColorProvider;
030: import net.infonode.tabbedpanel.TabbedPanelProperties;
031: import net.infonode.tabbedpanel.border.GradientTabAreaBorder;
032: import net.infonode.tabbedpanel.border.OpenContentBorder;
033: import net.infonode.tabbedpanel.border.TabAreaLineBorder;
034: import net.infonode.tabbedpanel.titledtab.TitledTabProperties;
035:
036: import javax.swing.border.Border;
037: import javax.swing.border.CompoundBorder;
038: import java.awt.*;
039:
040: /**
041: * A theme that draws gradient tab backgrounds.
042: *
043: * @author $Author: jesper $
044: * @version $Revision: 1.22 $
045: * @since ITP 1.1.0
046: */
047: public class GradientTheme extends TabbedPanelTitledTabTheme {
048: private static final float HUE = Colors.ROYAL_BLUE_HUE;
049: private static final float SATURATION = 0.06f;
050: private static final float BRIGHTNESS = 0.72f;
051:
052: /**
053: * The tab area background color used if no color is specified in the constructor.
054: */
055: public static final Color DEFAULT_TAB_AREA_BACKGROUND_COLOR = Color
056: .getHSBColor(HUE, SATURATION, BRIGHTNESS);
057:
058: private static final Border HIGHLIGHTED_TAB_GRADIENT_BORDER = new GradientTabAreaBorder(
059: Color.WHITE);
060:
061: private static final Border TAB_AREA_COMPONENTS_GRADIENT_BORDER = new GradientTabAreaBorder(
062: new ColorMultiplier(UIManagerColorProvider.CONTROL_COLOR,
063: 0.88), UIManagerColorProvider.CONTROL_COLOR);
064:
065: private boolean opaqueTabArea;
066: private boolean shadowEnabled;
067: private Color borderColor;
068: private Color tabAreaBackgroundColor;
069: private Border normalTabGradientBorder;
070: private TitledTabProperties titledTabProperties = new TitledTabProperties();
071: private TabbedPanelProperties tabbedPanelProperties = new TabbedPanelProperties();
072:
073: /**
074: * Creates a default theme with transparent tab area and shadows.
075: */
076: public GradientTheme() {
077: this (false, true);
078: }
079:
080: /**
081: * Constructor.
082: *
083: * @param opaqueTabArea if true a gradient background is drawn for the tab area, otherwise it's transparent
084: * @param shadowEnabled if true the shadow is enabled
085: */
086: public GradientTheme(boolean opaqueTabArea, boolean shadowEnabled) {
087: this (opaqueTabArea, shadowEnabled, null);
088: }
089:
090: /**
091: * Constructor.
092: *
093: * @param opaqueTabArea if true a gradient background is drawn for the tab area, otherwise it's transparent
094: * @param shadowEnabled if true the shadow is enabled
095: * @param borderColor the border color, null means default border color
096: */
097: public GradientTheme(boolean opaqueTabArea, boolean shadowEnabled,
098: Color borderColor) {
099: this (opaqueTabArea, shadowEnabled, borderColor,
100: DEFAULT_TAB_AREA_BACKGROUND_COLOR);
101: }
102:
103: /**
104: * Constructor.
105: *
106: * @param opaqueTabArea if true a gradient background is drawn for the tab area, otherwise it's transparent
107: * @param shadowEnabled if true the shadow is enabled
108: * @param borderColor the border color, null means default border color
109: * @param tabAreaBackgroundColor the background color for the tab area and normal tabs, null means use the default tab
110: * background
111: */
112: public GradientTheme(boolean opaqueTabArea, boolean shadowEnabled,
113: Color borderColor, Color tabAreaBackgroundColor) {
114: this .opaqueTabArea = opaqueTabArea;
115: this .shadowEnabled = shadowEnabled;
116: this .borderColor = borderColor;
117: this .tabAreaBackgroundColor = tabAreaBackgroundColor;
118:
119: ColorProvider cp = ColorProviderUtil.getColorProvider(
120: tabAreaBackgroundColor,
121: UIManagerColorProvider.TABBED_PANE_BACKGROUND);
122:
123: normalTabGradientBorder = new GradientTabAreaBorder(cp,
124: new ColorMultiplier(cp, 1.1));
125: initTabbedPanelProperties();
126: initTitledTabProperties();
127: }
128:
129: /**
130: * Gets the name for this theme
131: *
132: * @return the name
133: */
134: public String getName() {
135: return "Gradient Theme"
136: + (opaqueTabArea ? " - Opaque Tab Area" : "");
137: }
138:
139: private void initTabbedPanelProperties() {
140:
141: tabbedPanelProperties.getContentPanelProperties()
142: .getComponentProperties().setInsets(
143: new Insets(3, 3, 3, 3)).setBorder(
144: new OpenContentBorder(borderColor,
145: opaqueTabArea ? 0 : 1));
146:
147: tabbedPanelProperties.setShadowEnabled(shadowEnabled)
148: .setPaintTabAreaShadow(opaqueTabArea).setTabSpacing(
149: opaqueTabArea ? 0 : -1);
150:
151: if (opaqueTabArea) {
152: if (tabAreaBackgroundColor != null)
153: tabbedPanelProperties.getTabAreaProperties()
154: .getComponentProperties().setBackgroundColor(
155: tabAreaBackgroundColor);
156:
157: tabbedPanelProperties.getTabAreaProperties()
158: .getComponentProperties().setBorder(
159: new CompoundBorder(new TabAreaLineBorder(
160: borderColor),
161: normalTabGradientBorder));
162: }
163:
164: tabbedPanelProperties.getTabAreaComponentsProperties()
165: .setStretchEnabled(opaqueTabArea)
166:
167: .getComponentProperties().setBorder(
168: new CompoundBorder(new TabAreaLineBorder(
169: opaqueTabArea ? null : borderColor,
170: !opaqueTabArea, true, !opaqueTabArea,
171: true),
172: TAB_AREA_COMPONENTS_GRADIENT_BORDER))
173: .setInsets(
174: opaqueTabArea ? new Insets(0, 3, 0, 3)
175: : new Insets(1, 3, 1, 3));
176: }
177:
178: private void initTitledTabProperties() {
179: if (opaqueTabArea)
180: titledTabProperties.setHighlightedRaised(0);
181:
182: titledTabProperties.getNormalProperties()
183: .getComponentProperties().setBorder(
184: opaqueTabArea ? (Border) new TabAreaLineBorder(
185: false, false, true, true)
186: : new CompoundBorder(
187: new TabAreaLineBorder(),
188: normalTabGradientBorder));
189:
190: if (opaqueTabArea)
191: titledTabProperties.getNormalProperties()
192: .getComponentProperties().setBackgroundColor(null);
193:
194: if (!opaqueTabArea && tabAreaBackgroundColor != null)
195: titledTabProperties.getNormalProperties()
196: .getComponentProperties().setBackgroundColor(
197: tabAreaBackgroundColor);
198:
199: titledTabProperties.getHighlightedProperties().setIconVisible(
200: true)
201:
202: .getComponentProperties().setBorder(
203: new CompoundBorder(
204: opaqueTabArea ? (Border) new TabAreaLineBorder(
205: false, false, true, true)
206: : new TabAreaLineBorder(borderColor),
207: HIGHLIGHTED_TAB_GRADIENT_BORDER));
208: }
209:
210: public TitledTabProperties getTitledTabProperties() {
211: return titledTabProperties;
212: }
213:
214: public TabbedPanelProperties getTabbedPanelProperties() {
215: return tabbedPanelProperties;
216: }
217:
218: /**
219: * Returns the gradient border for the highlighted tab.
220: *
221: * @return the gradient border for the highlighted tab
222: */
223: public Border getHighlightedTabGradientBorder() {
224: return HIGHLIGHTED_TAB_GRADIENT_BORDER;
225: }
226:
227: /**
228: * Returns the gradient border for the tab area components.
229: *
230: * @return the gradient border for the tab area components
231: */
232: public Border getTabAreaComponentsGradientBorder() {
233: return TAB_AREA_COMPONENTS_GRADIENT_BORDER;
234: }
235:
236: /**
237: * Returns the gradient border for the normal tab or the tab area if it's opaque.
238: *
239: * @return the gradient border for the normal tab or the tab area if it's opaque
240: */
241: public Border getNormalTabGradientBorder() {
242: return normalTabGradientBorder;
243: }
244: }
|