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: SoftBlueIceTheme.java,v 1.17 2005/12/04 13:46:05 jesper Exp $
023: package net.infonode.tabbedpanel.theme;
024:
025: import net.infonode.gui.colorprovider.ColorBlender;
026: import net.infonode.gui.colorprovider.ColorProvider;
027: import net.infonode.gui.colorprovider.FixedColorProvider;
028: import net.infonode.gui.componentpainter.ComponentPainter;
029: import net.infonode.gui.componentpainter.FixedTransformComponentPainter;
030: import net.infonode.gui.componentpainter.GradientComponentPainter;
031: import net.infonode.gui.shaped.border.RoundedCornerBorder;
032: import net.infonode.properties.base.Property;
033: import net.infonode.properties.gui.util.ComponentProperties;
034: import net.infonode.tabbedpanel.TabbedPanelProperties;
035: import net.infonode.tabbedpanel.titledtab.TitledTabProperties;
036: import net.infonode.util.ColorUtil;
037:
038: import javax.swing.border.Border;
039: import java.awt.*;
040:
041: /**
042: * A light blue theme with gradients and rounded corners.
043: *
044: * @author $Author: jesper $
045: * @version $Revision: 1.17 $
046: * @since ITP 1.2.0
047: */
048: public class SoftBlueIceTheme extends TabbedPanelTitledTabTheme {
049: public static final FixedColorProvider DEFAULT_DARK_COLOR = new FixedColorProvider(
050: ColorUtil.mult(new Color(160, 170, 190), 0.90));
051: public static final FixedColorProvider DEFAULT_LIGHT_COLOR = new FixedColorProvider(
052: new Color(220, 230, 240));
053:
054: private ColorProvider darkColor;
055: private ColorProvider lightColor;
056: private TabbedPanelProperties tabbedPanelProperties = new TabbedPanelProperties();
057: private TitledTabProperties titledTabProperties = new TitledTabProperties();
058:
059: /**
060: * Creates a theme with default colors and rounded corners.
061: */
062: public SoftBlueIceTheme() {
063: this (DEFAULT_DARK_COLOR, DEFAULT_LIGHT_COLOR, 4);
064: }
065:
066: /**
067: * Constructor.
068: *
069: * @param darkColor the dark color used in gradients
070: * @param lightColor the light color used in gradients
071: * @param cornerType the amount of rounding to use for corners, 0-4
072: */
073: public SoftBlueIceTheme(ColorProvider darkColor,
074: ColorProvider lightColor, int cornerType) {
075: this .darkColor = darkColor;
076: this .lightColor = lightColor;
077:
078: ColorProvider light = lightColor;
079: ColorProvider dark = new ColorBlender(darkColor, lightColor,
080: 0.3f);
081: ColorProvider dark2 = new ColorBlender(darkColor,
082: FixedColorProvider.WHITE, 0.1f);
083: ColorProvider dark3 = darkColor;
084:
085: Border roundedBorder = new RoundedCornerBorder(dark3, light,
086: cornerType, cornerType, cornerType, cornerType, true,
087: true, true, true);
088:
089: Border tabNormalBorder = roundedBorder;
090:
091: Border contentBorder = new RoundedCornerBorder(dark3, light,
092: cornerType, cornerType, cornerType, cornerType, false,
093: true, true, true);
094:
095: ComponentPainter areaPainter = new FixedTransformComponentPainter(
096: new GradientComponentPainter(dark2, light, light, dark2));
097: ComponentPainter contentPainter = new FixedTransformComponentPainter(
098: new GradientComponentPainter(light, dark2, dark2, light));
099: ComponentPainter highlightPainter = new FixedTransformComponentPainter(
100: new GradientComponentPainter(FixedColorProvider.WHITE,
101: light, light, light));
102: ComponentPainter normalPainter = new FixedTransformComponentPainter(
103: new GradientComponentPainter(light, dark, dark, dark));
104:
105: tabbedPanelProperties.setPaintTabAreaShadow(true)
106: .setTabSpacing(2).setShadowEnabled(false);
107:
108: tabbedPanelProperties.getTabAreaProperties()
109: .getComponentProperties().setBorder(roundedBorder)
110: .setInsets(new Insets(2, 2, 3, 3));
111:
112: tabbedPanelProperties.getTabAreaProperties()
113: .getShapedPanelProperties().setClipChildren(true)
114: .setComponentPainter(areaPainter).setOpaque(false);
115:
116: tabbedPanelProperties.getTabAreaComponentsProperties()
117: .setStretchEnabled(true).getComponentProperties()
118: .setBorder(null).setInsets(new Insets(0, 0, 0, 0));
119:
120: tabbedPanelProperties.getTabAreaComponentsProperties()
121: .getShapedPanelProperties().setOpaque(false);
122:
123: tabbedPanelProperties.getContentPanelProperties()
124: .getComponentProperties().setBorder(contentBorder)
125: .setInsets(new Insets(3, 3, 4, 4));
126:
127: tabbedPanelProperties.getContentPanelProperties()
128: .getShapedPanelProperties().setComponentPainter(
129: contentPainter).setClipChildren(true)
130: .setOpaque(false);
131:
132: titledTabProperties.setHighlightedRaised(0);
133:
134: Font font = titledTabProperties.getNormalProperties()
135: .getComponentProperties().getFont();
136:
137: if (font != null)
138: font = font.deriveFont(Font.PLAIN).deriveFont(11f);
139:
140: titledTabProperties.getNormalProperties()
141: .getComponentProperties().setBorder(tabNormalBorder)
142: .setInsets(new Insets(1, 4, 2, 5)).setBackgroundColor(
143: titledTabProperties.getHighlightedProperties()
144: .getComponentProperties()
145: .getBackgroundColor()).setFont(font);
146:
147: titledTabProperties.getNormalProperties()
148: .getShapedPanelProperties().setComponentPainter(
149: normalPainter).setOpaque(false);
150:
151: Property[] linkedProperties = { ComponentProperties.BORDER,
152: ComponentProperties.INSETS, ComponentProperties.FONT };
153:
154: for (int i = 0; i < linkedProperties.length; i++) {
155: titledTabProperties.getHighlightedProperties()
156: .getComponentProperties().getMap()
157: .createRelativeRef(
158: linkedProperties[i],
159: titledTabProperties.getNormalProperties()
160: .getComponentProperties().getMap(),
161: linkedProperties[i]);
162: }
163:
164: titledTabProperties.getHighlightedProperties()
165: .getShapedPanelProperties().setComponentPainter(
166: highlightPainter);
167: }
168:
169: public String getName() {
170: return "Soft Blue Ice Theme";
171: }
172:
173: public TabbedPanelProperties getTabbedPanelProperties() {
174: return tabbedPanelProperties;
175: }
176:
177: public TitledTabProperties getTitledTabProperties() {
178: return titledTabProperties;
179: }
180:
181: /**
182: * Returns the dark gradient color.
183: *
184: * @return the dark gradient color
185: */
186: public ColorProvider getDarkColor() {
187: return darkColor;
188: }
189:
190: /**
191: * Returns the light gradient color.
192: *
193: * @return the light gradient color
194: */
195: public ColorProvider getLightColor() {
196: return lightColor;
197: }
198: }
|