001: /*
002: * SmoothGradientLookAndFeel.java
003: *
004: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
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 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, MA 02111-1307, USA.
019: *
020: */
021:
022: package org.underworldlabs.swing.plaf.smoothgradient;
023:
024: import java.awt.Color;
025:
026: import javax.swing.Icon;
027: import javax.swing.UIDefaults;
028: import javax.swing.plaf.ColorUIResource;
029: import javax.swing.plaf.metal.MetalLookAndFeel;
030: import javax.swing.plaf.metal.MetalTheme;
031: import org.underworldlabs.swing.plaf.UIUtils;
032:
033: /* ----------------------------------------------------------
034: * CVS NOTE: Changes to the CVS repository prior to the
035: * release of version 3.0.0beta1 has meant a
036: * resetting of CVS revision numbers.
037: * ----------------------------------------------------------
038: */
039:
040: /**
041: *
042: * @author Takis Diakoumis
043: * @version $Revision: 1.4 $
044: * @date $Date: 2006/05/14 06:56:07 $
045: */
046: public class SmoothGradientLookAndFeel extends MetalLookAndFeel {
047:
048: public static final Color FRAME_BUTTON_START_ACTIVE = new Color(
049: 157, 157, 225);
050: public static final Color FRAME_BUTTON_STOP_ACTIVE = new Color(185,
051: 185, 244);
052: public static final Color FRAME_BUTTON_START_INACTIVE = new Color(
053: 223, 223, 223, 223);
054: public static final Color FRAME_BUTTON_STOP_INACTIVE = new Color(
055: 243, 243, 243, 243);
056:
057: public static final Color DARKEN_START = new Color(0, 0, 0, 0);
058: public static final Color DARKEN_STOP = new Color(0, 0, 0, 64);
059: public static final Color LT_DARKEN_STOP = new Color(0, 0, 0, 32);
060: public static final Color BRIGHTEN_START = new Color(255, 255, 255,
061: 0);
062: public static final Color BRIGHTEN_STOP = new Color(255, 255, 255,
063: 128);
064: public static final Color LT_BRIGHTEN_STOP = new Color(255, 255,
065: 255, 64);
066:
067: /** Client property key to disable the pseudo 3D effect. */
068: public static final String IS_3D_KEY = "Plastic.is3D";
069:
070: /** The current color theme. */
071: private static MetalTheme metalTheme;
072:
073: /** The look-global state for the 3D enabledment. */
074: private static boolean is3DEnabled = true;
075:
076: /** The look dependent <code>FontSizeHints</code> */
077: private static FontSizeHints fontSizeHints;
078:
079: /** The modified darker highlight for internal frame bumps */
080: private static Color internalFrameBumpsHighlight;
081:
082: /** Constructs the <code>PlasticLookAndFeel</code>. */
083: public SmoothGradientLookAndFeel() {
084: if (internalFrameBumpsHighlight == null)
085: internalFrameBumpsHighlight = new Color(198, 198, 246);
086: }
087:
088: public String getID() {
089: return "SmoothGradient";
090: }
091:
092: public String getName() {
093: return "Smooth Gradient Look and Feel";
094: }
095:
096: public String getDescription() {
097: return "The Execute Query Smooth Gradient Look and Feel - modified from "
098: + "The JGoodies Plastic Look and Feel";
099: }
100:
101: // Special Properties ***************************************************
102:
103: /**
104: * Answers the current <code>FontSizeHints</code>,
105: * where look specific settings shadow the global users defaults
106: * as stored under key <code>FontSizeHints.KEY</code>.
107: *
108: * @see Options#setGlobalFontSizeHints
109: * @see FontSizeHints
110: */
111: public static FontSizeHints getFontSizeHints() {
112: return fontSizeHints != null ? fontSizeHints : Options
113: .getGlobalFontSizeHints();
114: }
115:
116: /**
117: * Sets <code>FontSizeHints</code> that shadow the global font size hints.
118: *
119: * @see Options#setGlobalFontSizeHints
120: * @see FontSizeHints
121: */
122: public static void setFontSizeHints(FontSizeHints newHints) {
123: fontSizeHints = newHints;
124: }
125:
126: protected boolean is3DEnabled() {
127: return is3DEnabled;
128: }
129:
130: public static void set3DEnabled(boolean b) {
131: is3DEnabled = b;
132: }
133:
134: // Overriding Superclass Behavior ***************************************
135:
136: /**
137: * Initializes the class defaults, that is, overrides some UI delegates
138: * with JGoodies Plastic implementations.
139: *
140: * @see javax.swing.plaf.basic.BasicLookAndFeel#getDefaults
141: */
142: protected void initClassDefaults(UIDefaults table) {
143: super .initClassDefaults(table);
144:
145: String NAME_PREFIX = "org.underworldlabs.swing.plaf.smoothgradient.SmoothGradient";
146:
147: // Overwrite some of the uiDefaults.
148: Object[] uiDefaults = { "ButtonUI", NAME_PREFIX + "ButtonUI",
149: //"ToggleButtonUI", NAME_PREFIX + "ToggleButtonUI",
150: "ComboBoxUI", NAME_PREFIX + "ComboBoxUI",
151: "ScrollBarUI", NAME_PREFIX + "ScrollBarUI",
152: // "SpinnerUI", NAME_PREFIX + "SpinnerUI",
153: // "TreeUI", NAME_PREFIX + "TreeUI",
154: // "RootPaneUI", NAME_PREFIX + "RootPaneUI",
155: "InternalFrameUI", NAME_PREFIX + "InternalFrameUI",
156:
157: };
158:
159: table.putDefaults(uiDefaults);
160:
161: }
162:
163: protected void initComponentDefaults(UIDefaults table) {
164: super .initComponentDefaults(table);
165:
166: Icon checkBoxMenuItemIcon = SmoothGradientIconFactory
167: .getCheckBoxMenuItemIcon();
168:
169: // Should be active.
170: int treeFontSize = table.getFont("Tree.font").getSize();
171: Integer rowHeight = new Integer(treeFontSize + 5);
172: Object treeExpandedIcon = SmoothGradientIconFactory
173: .getExpandedTreeIcon();
174: Object treeCollapsedIcon = SmoothGradientIconFactory
175: .getCollapsedTreeIcon();
176: ColorUIResource gray = new ColorUIResource(UIUtils.getBrighter(
177: Color.GRAY, 0.8));
178:
179: final Object[] internalFrameIconArgs = new Object[1];
180: internalFrameIconArgs[0] = new Integer(16);
181:
182: Boolean is3D = new Boolean(true);
183:
184: Object[] defaults = {
185: "CheckBoxMenuItem.checkIcon",
186: checkBoxMenuItemIcon,
187: "ComboBox.selectionForeground",
188: getMenuSelectedForeground(),
189: "ComboBox.selectionBackground",
190: getMenuSelectedBackground(),
191: "ComboBox.arrowButtonBorder",
192: SmoothGradientBorders.getComboBoxArrowButtonBorder(),
193: "ComboBox.editorBorder",
194: SmoothGradientBorders.getComboBoxEditorBorder(),
195: "Menu.arrowIcon",
196: SmoothGradientIconFactory.getMenuArrowIcon(),
197: /*
198: "FileView.computerIcon", makeIcon(getClass(), "icons/Computer.gif"),
199: "FileView.directoryIcon", makeIcon(getClass(), "icons/TreeClosed.gif"),
200: "FileView.fileIcon", makeIcon(getClass(), "icons/File.gif"),
201: "FileView.floppyDriveIcon", makeIcon(getClass(), "icons/FloppyDrive.gif"),
202: "FileView.hardDriveIcon", makeIcon(getClass(), "icons/HardDrive.gif"),
203: "FileChooser.homeFolderIcon", makeIcon(getClass(), "icons/HomeFolder.gif"),
204: "FileChooser.newFolderIcon", makeIcon(getClass(), "icons/NewFolder.gif"),
205: "FileChooser.upFolderIcon", makeIcon(getClass(), "icons/UpFolder.gif"),
206: */
207: // "Tree.closedIcon", makeIcon(getClass(), "icons/TreeClosed.gif"),
208: // "Tree.openIcon", makeIcon(getClass(), "icons/TreeOpen.gif"),
209: // "Tree.leafIcon", makeIcon(getClass(), "icons/TreeLeaf.gif"),
210: "Tree.expandedIcon",
211: treeExpandedIcon,
212: "Tree.collapsedIcon",
213: treeCollapsedIcon,
214: "Tree.line",
215: gray,
216: "Tree.hash",
217: gray,
218: "Tree.rowHeight",
219: rowHeight,
220: "InternalFrame.iconifyIcon",
221: SmoothGradientIconFactory
222: .getInternalFrameMinimizeIcon(16),
223: "InternalFrame.maximizeIcon",
224: SmoothGradientIconFactory
225: .getInternalFrameMaximizeIcon(16),
226: "InternalFrame.minimizeIcon",
227: SmoothGradientIconFactory
228: .getInternalFrameAltMaximizeIcon(16),
229: "InternalFrame.closeIcon",
230: SmoothGradientIconFactory.getInternalFrameCloseIcon(16),
231:
232: "Button.is3DEnabled", is3D, "ComboBox.is3DEnabled",
233: is3D, "ScrollBar.is3DEnabled",
234: is3D,
235: "ToggleButton.is3DEnabled",
236: is3D,
237: // PolishedScrollBarUI.MAX_BUMPS_WIDTH_KEY, new Integer(22),
238:
239: "InternalFrame.optionDialogBorder",
240: SmoothGradientBorders.getOptionDialogBorder(),
241: "InternalFrame.border",
242: SmoothGradientBorders.getInternalFrameBorder()
243: /*
244: "RootPane.plainDialogBorder", SmoothGradientBorders.getDialogBorder(),
245: "RootPane.informationDialogBorder", SmoothGradientBorders.getDialogBorder(),
246: "RootPane.errorDialogBorder", SmoothGradientBorders.getErrorDialogBorder(),
247: "RootPane.colorChooserDialogBorder", SmoothGradientBorders.getQuestionDialogBorder(),
248: "RootPane.fileChooserDialogBorder", SmoothGradientBorders.getQuestionDialogBorder(),
249: "RootPane.questionDialogBorder", SmoothGradientBorders.getQuestionDialogBorder(),
250: "RootPane.warningDialogBorder", SmoothGradientBorders.getWarningDialogBorder()
251: */
252:
253: };
254:
255: table.putDefaults(defaults);
256:
257: }
258:
259: /**
260: * Gets the current <code>PlasticTheme</code>.
261: */
262: public static MetalTheme getCurrentTheme() {
263: return metalTheme;
264: }
265:
266: // Accessed by ProxyLazyValues ******************************************
267: /*
268: public static BorderUIResource getInternalFrameBorder() {
269: return new BorderUIResource(PlasticBorders.getInternalFrameBorder());
270: }
271:
272: public static BorderUIResource getPaletteBorder() {
273: return new BorderUIResource(PlasticBorders.getPaletteBorder());
274: }
275: */
276:
277: public static Color getInternalFrameBumpsHighlight() {
278: if (internalFrameBumpsHighlight == null)
279: internalFrameBumpsHighlight = new Color(198, 198, 246);
280:
281: return internalFrameBumpsHighlight;
282: }
283:
284: // Accessing Theme Colors and Fonts *************************************
285: /*
286:
287: public static ColorUIResource getPrimaryControlDarkShadow() {
288: return getMyCurrentTheme().getPrimaryControlDarkShadow();
289: }
290:
291: public static ColorUIResource getPrimaryControlHighlight() {
292: return getMyCurrentTheme().getPrimaryControlHighlight();
293: }
294:
295: public static ColorUIResource getPrimaryControlInfo() {
296: return getMyCurrentTheme().getPrimaryControlInfo();
297: }
298:
299: public static ColorUIResource getPrimaryControlShadow() {
300: return getMyCurrentTheme().getPrimaryControlShadow();
301: }
302:
303: public static ColorUIResource getPrimaryControl() {
304: return getMyCurrentTheme().getPrimaryControl();
305: }
306:
307: public static ColorUIResource getControlHighlight() {
308: return getMyCurrentTheme().getControlHighlight();
309: }
310:
311: public static ColorUIResource getControlDarkShadow() {
312: return getMyCurrentTheme().getControlDarkShadow();
313: }
314:
315: public static ColorUIResource getControl() {
316: return getMyCurrentTheme().getControl();
317: }
318:
319: public static ColorUIResource getFocusColor() {
320: return getMyCurrentTheme().getFocusColor();
321: }
322:
323: public static ColorUIResource getMenuItemBackground() {
324: return getMyCurrentTheme().getMenuItemBackground();
325: }
326:
327: public static ColorUIResource getMenuItemSelectedBackground() {
328: return getMyCurrentTheme().getMenuItemSelectedBackground();
329: }
330:
331: public static ColorUIResource getMenuItemSelectedForeground() {
332: return getMyCurrentTheme().getMenuItemSelectedForeground();
333: }
334:
335: public static ColorUIResource getWindowTitleBackground() {
336: return getMyCurrentTheme().getWindowTitleBackground();
337: }
338:
339: public static ColorUIResource getWindowTitleForeground() {
340: return getMyCurrentTheme().getWindowTitleForeground();
341: }
342:
343: public static ColorUIResource getWindowTitleInactiveBackground() {
344: return getMyCurrentTheme().getWindowTitleInactiveBackground();
345: }
346:
347: public static ColorUIResource getWindowTitleInactiveForeground() {
348: return getMyCurrentTheme().getWindowTitleInactiveForeground();
349: }
350:
351: public static ColorUIResource getSimpleInternalFrameForeground() {
352: return getMyCurrentTheme().getSimpleInternalFrameForeground();
353: }
354:
355: public static ColorUIResource getSimpleInternalFrameBackground() {
356: return getMyCurrentTheme().getSimpleInternalFrameBackground();
357: }
358:
359: public static ColorUIResource getTitleTextColor() {
360: return getMyCurrentTheme().getTitleTextColor();
361: }
362:
363: public static FontUIResource getTitleTextFont() {
364: return getMyCurrentTheme().getTitleTextFont();
365: }*/
366:
367: }
|