001: /*
002: * @(#)BasicOffice2003Theme.java 3/17/2006
003: *
004: * Copyright 2002 - 2006 JIDE Software Inc. All rights reserved.
005: */
006:
007: package com.jidesoft.plaf.office2003;
008:
009: import com.jidesoft.icons.IconsFactory;
010: import com.jidesoft.plaf.LookAndFeelFactory;
011: import com.jidesoft.utils.ColorUtils;
012:
013: import javax.swing.*;
014: import javax.swing.plaf.ColorUIResource;
015: import java.awt.*;
016:
017: /**
018: * <tt>BasicOffice2003Theme</tt> is a special Office2003 theme that uses a base color to calculate
019: * all other colors used by JIDE components. This is done regardless what current XP theme you are using.
020: */
021: public class BasicOffice2003Theme extends Office2003Theme {
022: private Color _baseColor;
023:
024: public BasicOffice2003Theme(String themeName) {
025: super (themeName);
026: }
027:
028: /**
029: * Sets the base color. The Office2003 theme will use this color as base color and calculate
030: * all other colors that will be used by JIDE components.
031: *
032: * @param color the base color.
033: * @param derivedSelectionColor if deriving selection colors from the base color. Selection color is used in
034: * places like JideButton's background and DockableFrame's title pane background.
035: * @param prefix the prefix is for the expand/collapse icon on collapsible pane. Available prefixes are
036: * "default", "blue", "homestead", "metallic", and "gray". You can decide which one to use depending
037: * on what base color is. In most cases, "default" works just fine. But if your base color has more blue,
038: * using "blue" will produce a better result. If green, you can use "homestead".
039: */
040: public void setBaseColor(Color color,
041: boolean derivedSelectionColor, String prefix) {
042: _baseColor = color;
043: float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(),
044: color.getBlue(), null);
045: Color selectionColor = Color.getHSBColor(hsb[0],
046: (hsb[1] > 0.01) ? 0.45f : hsb[0], 0.90f);
047:
048: Object uiDefaults[] = { "control",
049: ColorUtils.getDerivedColor(color, 0.9f), "controlLt",
050: ColorUtils.getDerivedColor(color, 0.95f), "controlDk",
051: ColorUtils.getDerivedColor(color, 0.8f),
052: "controlShadow",
053: ColorUtils.getDerivedColor(color, 0.4f),
054:
055: "TabbedPane.selectDk",
056: ColorUtils.getDerivedColor(selectionColor, 0.40f),
057: "TabbedPane.selectLt",
058: ColorUtils.getDerivedColor(selectionColor, 0.55f),
059:
060: "OptionPane.bannerLt",
061: ColorUtils.getDerivedColor(color, 0.5f),
062: "OptionPane.bannerDk",
063: ColorUtils.getDerivedColor(color, 0.3f),
064: "OptionPane.bannerForeground",
065: new ColorUIResource(255, 255, 255),
066:
067: "Separator.foreground",
068: ColorUtils.getDerivedColor(color, 0.4f),
069: "Separator.foregroundLt",
070: ColorUtils.getDerivedColor(color, 1.0f),
071:
072: "Gripper.foreground",
073: ColorUtils.getDerivedColor(color, 0.6f),
074: "Gripper.foregroundLt",
075: ColorUtils.getDerivedColor(color, 0.92f),
076:
077: "Chevron.backgroundLt",
078: ColorUtils.getDerivedColor(color, 0.85f),
079: "Chevron.backgroundDk",
080: ColorUtils.getDerivedColor(color, 0.75f),
081:
082: "Divider.backgroundLt",
083: ColorUtils.getDerivedColor(color, 0.9f),
084: "Divider.backgroundDk",
085: ColorUtils.getDerivedColor(color, 0.97f),
086:
087: "backgroundLt",
088: ColorUtils.getDerivedColor(color, 0.95f),
089: "backgroundDk",
090: ColorUtils.getDerivedColor(color, 0.9f),
091:
092: "CommandBar.titleBarBackground",
093: ColorUtils.getDerivedColor(color, 0.6f),
094: "MenuItem.background",
095: ColorUtils.getDerivedColor(color, 0.95f),
096:
097: "DockableFrameTitlePane.backgroundLt",
098: ColorUtils.getDerivedColor(color, 0.92f),
099: "DockableFrameTitlePane.backgroundDk",
100: ColorUtils.getDerivedColor(color, 0.85f),
101: "DockableFrameTitlePane.activeForeground",
102: new ColorUIResource(0, 0, 0),
103: "DockableFrameTitlePane.inactiveForeground",
104: new ColorUIResource(0, 0, 0),
105: "DockableFrame.backgroundLt",
106: ColorUtils.getDerivedColor(color, 0.92f),
107: "DockableFrame.backgroundDk",
108: ColorUtils.getDerivedColor(color, 0.89f),
109:
110: "selection.border",
111: ColorUtils.getDerivedColor(color, 0.5f) };
112:
113: putDefaults(uiDefaults);
114:
115: int products = LookAndFeelFactory.getProductsUsed();
116: if ((products & LookAndFeelFactory.PRODUCT_COMPONENTS) != 0) {
117: final int SIZE = 20;
118: final int MASK_SIZE = 11;
119: ImageIcon collapsiblePaneImage = IconsFactory.getImageIcon(
120: Office2003WindowsUtils.class,
121: "icons/collapsible_pane_" + prefix + ".png"); // 20 x 20
122: ImageIcon collapsiblePaneMask = IconsFactory.getImageIcon(
123: Office2003WindowsUtils.class,
124: "icons/collapsible_pane_mask.png"); // 11 x 11
125: ImageIcon normalIcon = IconsFactory.getIcon(null,
126: collapsiblePaneImage, 0, 0, SIZE, SIZE);
127: ImageIcon emphasizedIcon = IconsFactory.getIcon(null,
128: collapsiblePaneImage, SIZE, 0, SIZE, SIZE);
129: ImageIcon upMark = IconsFactory.getIcon(null,
130: collapsiblePaneMask, 0, 0, MASK_SIZE, MASK_SIZE);
131: ImageIcon downMark = IconsFactory.getIcon(null,
132: collapsiblePaneMask, 0, MASK_SIZE, MASK_SIZE,
133: MASK_SIZE);
134: uiDefaults = new Object[] {
135: "CollapsiblePane.contentBackground",
136: ColorUtils.getDerivedColor(color, 0.98f),
137: "CollapsiblePanes.backgroundLt",
138: ColorUtils.getDerivedColor(color, 0.82f),
139: "CollapsiblePanes.backgroundDk",
140: ColorUtils.getDerivedColor(color, 0.78f),
141: "CollapsiblePaneTitlePane.backgroundLt",
142: ColorUtils.getDerivedColor(color, 0.98f),
143: "CollapsiblePaneTitlePane.backgroundDk",
144: ColorUtils.getDerivedColor(color, 0.93f),
145: "CollapsiblePaneTitlePane.foreground",
146: new ColorUIResource(63, 61, 61),
147: "CollapsiblePaneTitlePane.foreground.focus",
148: new ColorUIResource(126, 124, 124),
149: "CollapsiblePaneTitlePane.backgroundLt.emphasized",
150: ColorUtils.getDerivedColor(color, 0.7f),
151: "CollapsiblePaneTitlePane.backgroundDk.emphasized",
152: ColorUtils.getDerivedColor(color, 0.72f),
153: "CollapsiblePaneTitlePane.foreground.emphasized",
154: new ColorUIResource(255, 255, 255),
155: "CollapsiblePaneTitlePane.foreground.focus.emphasized",
156: new ColorUIResource(230, 230, 230),
157:
158: "CollapsiblePane.downIcon",
159: IconsFactory.getOverlayIcon(null, normalIcon,
160: downMark, SwingConstants.CENTER),
161: "CollapsiblePane.upIcon",
162: IconsFactory.getOverlayIcon(null, normalIcon,
163: upMark, SwingConstants.CENTER),
164: "CollapsiblePane.downIcon.emphasized",
165: IconsFactory.getOverlayIcon(null, emphasizedIcon,
166: downMark, SwingConstants.CENTER),
167: "CollapsiblePane.upIcon.emphasized",
168: IconsFactory.getOverlayIcon(null, emphasizedIcon,
169: upMark, SwingConstants.CENTER),
170: "CollapsiblePane.upMask", upMark,
171: "CollapsiblePane.downMask", downMark,
172: "CollapsiblePane.titleButtonBackground",
173: normalIcon,
174: "CollapsiblePane.titleButtonBackground.emphasized",
175: emphasizedIcon, };
176: putDefaults(uiDefaults);
177: }
178:
179: if (derivedSelectionColor) {
180: Object[] uiDefaultsSelection = new Object[] {
181: "selection.Rollover",
182: selectionColor,
183: "selection.RolloverLt",
184: ColorUtils.getDerivedColor(selectionColor, 0.55f),
185: "selection.RolloverDk",
186: ColorUtils.getDerivedColor(selectionColor, 0.45f),
187:
188: "selection.Selected",
189: ColorUtils.getDerivedColor(selectionColor, 0.45f),
190: "selection.SelectedLt",
191: ColorUtils.getDerivedColor(selectionColor, 0.55f),
192: "selection.SelectedDk",
193: ColorUtils.getDerivedColor(selectionColor, 0.50f),
194:
195: "selection.Pressed",
196: ColorUtils.getDerivedColor(selectionColor, 0.4f), // focused and selected;
197: "selection.PressedLt",
198: ColorUtils.getDerivedColor(selectionColor, 0.45f),
199: "selection.PressedDk",
200: ColorUtils.getDerivedColor(selectionColor, 0.35f) };
201: putDefaults(uiDefaultsSelection);
202: }
203:
204: }
205:
206: /**
207: * Gets the base color for this theme. It is set using
208: * {@link #setBaseColor(java.awt.Color,boolean,String)} method.
209: *
210: * @return the base color.
211: */
212: public Color getBaseColor() {
213: return _baseColor;
214: }
215: }
|