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: ShapedGradientDockingTheme.java,v 1.26 2007/01/28 21:25:10 jesper Exp $
023: package net.infonode.docking.theme;
024:
025: import net.infonode.docking.properties.RootWindowProperties;
026: import net.infonode.gui.colorprovider.ColorBlender;
027: import net.infonode.gui.colorprovider.ColorMultiplier;
028: import net.infonode.gui.colorprovider.ColorProvider;
029: import net.infonode.gui.colorprovider.UIManagerColorProvider;
030: import net.infonode.gui.componentpainter.GradientComponentPainter;
031: import net.infonode.gui.componentpainter.SolidColorComponentPainter;
032: import net.infonode.gui.shaped.border.RoundedCornerBorder;
033: import net.infonode.tabbedpanel.Tab;
034: import net.infonode.tabbedpanel.TabbedPanelProperties;
035: import net.infonode.tabbedpanel.TabbedUtils;
036: import net.infonode.tabbedpanel.theme.ShapedGradientTheme;
037: import net.infonode.tabbedpanel.titledtab.TitledTabBorderSizePolicy;
038: import net.infonode.tabbedpanel.titledtab.TitledTabProperties;
039:
040: import javax.swing.border.Border;
041: import java.awt.*;
042:
043: /**
044: * A theme with tabs with rounded edges, gradient backgrounds and support for
045: * slopes on left/right side of tab.
046: *
047: * @author $Author: jesper $
048: * @version $Revision: 1.26 $
049: * @since IDW 1.2.0
050: */
051: public class ShapedGradientDockingTheme extends DockingWindowsTheme {
052: private RootWindowProperties rootWindowProperties = new RootWindowProperties();
053: private String name;
054:
055: /**
056: * Creates a default theme with sloped border on the right side of the tab
057: * (excluding tabs on window bars) and with colors based on the active look
058: * and feel
059: */
060: public ShapedGradientDockingTheme() {
061: this (0f, 0.5f);
062: }
063:
064: /**
065: * Creates a theme with the given slopes on the left and right side of the tab
066: * (excluding tabs on window bars) and with colors based on the active look and feel
067: *
068: * @param leftSlope leaning of left slope defined as left slope width divided by left slope height
069: * @param rightSlope leaning of right slope defined as right slope width divided by right slope height
070: */
071: public ShapedGradientDockingTheme(float leftSlope, float rightSlope) {
072: this (leftSlope, rightSlope,
073: UIManagerColorProvider.TABBED_PANE_DARK_SHADOW,
074: UIManagerColorProvider.TABBED_PANE_HIGHLIGHT, true);
075: }
076:
077: /**
078: * Creates a theme with the given slopes on the left and right side of the tab
079: * (excluding tabs on window bars) and with the given colors
080: *
081: * @param leftSlope leaning of left slope defined as left slope width divided
082: * by left slope height
083: * @param rightSlope leaning of right slope defined as right slope width divided
084: * by right slope height
085: * @param lineColor color provider for the lines
086: * @param highlightColor color provider for the highlighting, null for no highlighting
087: * @param focusHighlighterEnabled if true the currently focused tab is highlighted
088: */
089: public ShapedGradientDockingTheme(float leftSlope,
090: float rightSlope, ColorProvider lineColor,
091: ColorProvider highlightColor,
092: boolean focusHighlighterEnabled) {
093: this (leftSlope, rightSlope, 25, lineColor, highlightColor,
094: focusHighlighterEnabled);
095: }
096:
097: /**
098: * Creates a theme with the given slopes on the left and right side of the tab
099: * (excluding tabs on window bars) and with the given colors
100: *
101: * @param leftSlope leaning of left slope defined as left slope width divided
102: * by left slope height
103: * @param rightSlope leaning of right slope defined as right slope width divided
104: * by right slope height
105: * @param slopeHeight slope height in pixels, used when estimating slope width
106: * @param lineColor color provider for the lines
107: * @param highlightColor color provider for the highlighting, null for no highlighting
108: * @param focusHighlighterEnabled if true the currently focused tab is highlighted
109: */
110: public ShapedGradientDockingTheme(float leftSlope,
111: float rightSlope, int slopeHeight, ColorProvider lineColor,
112: ColorProvider highlightColor,
113: boolean focusHighlighterEnabled) {
114: final ShapedGradientTheme theme = new ShapedGradientTheme(
115: leftSlope, rightSlope, slopeHeight, lineColor,
116: highlightColor);
117: name = theme.getName();
118:
119: int cornerType = 3;
120:
121: TabbedPanelProperties tabbedPanelProperties = theme
122: .getTabbedPanelProperties();
123: TitledTabProperties titledTabProperties = theme
124: .getTitledTabProperties();
125:
126: // Tab window
127: rootWindowProperties.getTabWindowProperties()
128: .getTabbedPanelProperties().addSuperObject(
129: tabbedPanelProperties);
130: rootWindowProperties.getTabWindowProperties()
131: .getTabProperties().getTitledTabProperties()
132: .addSuperObject(titledTabProperties);
133:
134: if (focusHighlighterEnabled) {
135: rootWindowProperties.getTabWindowProperties()
136: .getTabProperties().getFocusedProperties()
137: .getShapedPanelProperties().setComponentPainter(
138: rootWindowProperties
139: .getTabWindowProperties()
140: .getTabProperties()
141: .getTitledTabProperties()
142: .getHighlightedProperties()
143: .getShapedPanelProperties()
144: .getComponentPainter());
145: ColorProvider topColor = new ColorMultiplier(theme
146: .getControlColor(), 0.85f);
147: rootWindowProperties.getTabWindowProperties()
148: .getTabProperties().getTitledTabProperties()
149: .getHighlightedProperties()
150: .getShapedPanelProperties().setComponentPainter(
151: new GradientComponentPainter(topColor,
152: theme.getControlColor(), theme
153: .getControlColor(), theme
154: .getControlColor()));
155: rootWindowProperties.getTabWindowProperties()
156: .getTabbedPanelProperties()
157: .getTabAreaComponentsProperties()
158: .getShapedPanelProperties().setComponentPainter(
159: new GradientComponentPainter(
160: new ColorMultiplier(theme
161: .getControlColor(), 1.1f),
162: theme.getControlColor(), theme
163: .getControlColor(),
164: topColor));
165: }
166:
167: Border highlightBorder = theme.createTabBorder(theme
168: .getLineColor(), theme.getHighlightColor(), 0f, 0f,
169: true, true, true, true, false, true, 0);
170:
171: final int inset = 4;
172: final int extraRaised = 1;
173:
174: Border normalBorder = new RoundedCornerBorder(theme
175: .getLineColor(), null, cornerType, cornerType,
176: cornerType, cornerType, true, true, true, true) {
177: private Border calculatedInsetsBorder = theme
178: .createTabBorder(theme.getLineColor(), null, 0f,
179: 0f, false, true, true, false, true, true, 0);
180:
181: protected Polygon createPolygon(Component c, int width,
182: int height) {
183: Polygon p = super .createPolygon(c, width, height);
184: for (int i = 0; i < p.npoints; i++)
185: if (p.xpoints[i] < width / 2)
186: p.xpoints[i] = p.xpoints[i]
187: + (isFirst(c) ? 0 : inset)
188: + extraRaised;
189: else
190: p.xpoints[i] = p.xpoints[i] - inset
191: - extraRaised;
192:
193: return p;
194: }
195:
196: public Insets getBorderInsets(Component c) {
197: return calculatedInsetsBorder.getBorderInsets(c);
198: }
199:
200: private boolean isFirst(Component c) {
201: Tab tab = TabbedUtils.getParentTab(c);
202: if (tab != null && tab.getTabbedPanel() != null)
203: return tab.getTabbedPanel().getTabAt(0) == tab;
204:
205: return false;
206: }
207: };
208:
209: //Insets insets = new Insets(1, 2 + extraRaised, 1, 2 + extraRaised);
210: TitledTabProperties tabProperties = rootWindowProperties
211: .getWindowBarProperties().getTabWindowProperties()
212: .getTabProperties().getTitledTabProperties();
213: tabProperties.getNormalProperties().getComponentProperties()
214: .setBorder(normalBorder).setInsets(
215: new Insets(1, 0, 1, 2 + extraRaised));
216: tabProperties.getHighlightedProperties()
217: .getComponentProperties().setBorder(highlightBorder);
218: tabProperties.setHighlightedRaised(0).setBorderSizePolicy(
219: TitledTabBorderSizePolicy.EQUAL_SIZE);
220:
221: rootWindowProperties.getWindowBarProperties()
222: .getTabWindowProperties().getTabbedPanelProperties()
223: .setTabSpacing(-inset * 2 + 2 - 2 * extraRaised)
224: .getTabAreaComponentsProperties()
225: .getComponentProperties().setBorder(
226: new RoundedCornerBorder(theme.getLineColor(),
227: theme.getHighlightColor(), cornerType,
228: cornerType, cornerType, cornerType,
229: true, true, true, true)).setInsets(
230: new Insets(0, 3, 0, 3));
231:
232: rootWindowProperties.setDragRectangleBorderWidth(3)
233:
234: .getWindowBarProperties().getComponentProperties().setInsets(
235: new Insets(2, 0, 2, 0));
236:
237: rootWindowProperties.getWindowAreaProperties().setBorder(null)
238: .setInsets(new Insets(2, 2, 2, 2));
239:
240: rootWindowProperties.getComponentProperties()
241: .setBackgroundColor(null);
242: rootWindowProperties
243: .getShapedPanelProperties()
244: .setComponentPainter(
245: new SolidColorComponentPainter(
246: new ColorBlender(
247: UIManagerColorProvider.TABBED_PANE_BACKGROUND,
248: UIManagerColorProvider.CONTROL_COLOR,
249: 0.5f)));
250:
251: rootWindowProperties.getWindowAreaShapedPanelProperties()
252: .setComponentPainter(
253: new SolidColorComponentPainter(
254: UIManagerColorProvider.CONTROL_COLOR));
255:
256: Insets insets = rootWindowProperties.getTabWindowProperties()
257: .getTabbedPanelProperties().getContentPanelProperties()
258: .getComponentProperties().getInsets();
259: if (highlightColor == null)
260: rootWindowProperties.getTabWindowProperties()
261: .getTabbedPanelProperties()
262: .getContentPanelProperties()
263: .getComponentProperties().setInsets(
264: new Insets(insets.top, insets.top,
265: insets.top, insets.top));
266: }
267:
268: /**
269: * Gets the theme name
270: *
271: * @return name
272: */
273: public String getName() {
274: return name;
275: }
276:
277: /**
278: * Gets the theme RootWindowProperties
279: *
280: * @return the RootWindowProperties
281: */
282: public RootWindowProperties getRootWindowProperties() {
283: return rootWindowProperties;
284: }
285: }
|