blob: 2aa299fe5cc60845d22fb52442191fb727aca0dd [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package javax.swing.plaf.metal;
27
28import java.awt.*;
29import java.net.URL;
30import java.util.*;
31import javax.swing.*;
32import javax.swing.plaf.*;
33import sun.swing.SwingUtilities2;
34import sun.swing.PrintColorUIResource;
35
36/**
37 * The default theme for the {@code MetalLookAndFeel}.
38 * <p>
39 * The designers
40 * of the Metal Look and Feel strive to keep the default look up to
41 * date, possibly through the use of new themes in the future.
42 * Therefore, developers should only use this class directly when they
43 * wish to customize the "Ocean" look, or force it to be the current
44 * theme, regardless of future updates.
45
46 * <p>
47 * All colors returned by {@code OceanTheme} are completely
48 * opaque.
49 *
50 * @since 1.5
51 * @see MetalLookAndFeel#setCurrentTheme
52 */
53public class OceanTheme extends DefaultMetalTheme {
54 private static final ColorUIResource PRIMARY1 =
55 new ColorUIResource(0x6382BF);
56 private static final ColorUIResource PRIMARY2 =
57 new ColorUIResource(0xA3B8CC);
58 private static final ColorUIResource PRIMARY3 =
59 new ColorUIResource(0xB8CFE5);
60 private static final ColorUIResource SECONDARY1 =
61 new ColorUIResource(0x7A8A99);
62 private static final ColorUIResource SECONDARY2 =
63 new ColorUIResource(0xB8CFE5);
64 private static final ColorUIResource SECONDARY3 =
65 new ColorUIResource(0xEEEEEE);
66
67 private static final ColorUIResource CONTROL_TEXT_COLOR =
68 new PrintColorUIResource(0x333333, Color.BLACK);
69 private static final ColorUIResource INACTIVE_CONTROL_TEXT_COLOR =
70 new ColorUIResource(0x999999);
71 private static final ColorUIResource MENU_DISABLED_FOREGROUND =
72 new ColorUIResource(0x999999);
73 private static final ColorUIResource OCEAN_BLACK =
74 new PrintColorUIResource(0x333333, Color.BLACK);
75
76 private static final ColorUIResource OCEAN_DROP =
77 new ColorUIResource(0xD2E9FF);
78
79 // ComponentOrientation Icon
80 // Delegates to different icons based on component orientation
81 private static class COIcon extends IconUIResource {
82 private Icon rtl;
83
84 public COIcon(Icon ltr, Icon rtl) {
85 super(ltr);
86 this.rtl = rtl;
87 }
88
89 public void paintIcon(Component c, Graphics g, int x, int y) {
90 if (MetalUtils.isLeftToRight(c)) {
91 super.paintIcon(c, g, x, y);
92 } else {
93 rtl.paintIcon(c, g, x, y);
94 }
95 }
96 }
97
98 // InternalFrame Icon
99 // Delegates to different icons based on button state
100 private static class IFIcon extends IconUIResource {
101 private Icon pressed;
102
103 public IFIcon(Icon normal, Icon pressed) {
104 super(normal);
105 this.pressed = pressed;
106 }
107
108 public void paintIcon(Component c, Graphics g, int x, int y) {
109 ButtonModel model = ((AbstractButton)c).getModel();
110 if (model.isPressed() && model.isArmed()) {
111 pressed.paintIcon(c, g, x, y);
112 } else {
113 super.paintIcon(c, g, x, y);
114 }
115 }
116 }
117
118 /**
119 * Creates an instance of <code>OceanTheme</code>
120 */
121 public OceanTheme() {
122 }
123
124 /**
125 * Add this theme's custom entries to the defaults table.
126 *
127 * @param table the defaults table, non-null
128 * @throws NullPointerException if {@code table} is {@code null}
129 */
130 public void addCustomEntriesToTable(UIDefaults table) {
131 Object focusBorder = new UIDefaults.ProxyLazyValue(
132 "javax.swing.plaf.BorderUIResource$LineBorderUIResource",
133 new Object[] {getPrimary1()});
134 // .30 0 DDE8F3 white secondary2
135 java.util.List buttonGradient = Arrays.asList(
136 new Object[] {new Float(.3f), new Float(0f),
137 new ColorUIResource(0xDDE8F3), getWhite(), getSecondary2() });
138
139 // Other possible properties that aren't defined:
140 //
141 // Used when generating the disabled Icons, provides the region to
142 // constrain grays to.
143 // Button.disabledGrayRange -> Object[] of Integers giving min/max
144 // InternalFrame.inactiveTitleGradient -> Gradient when the
145 // internal frame is inactive.
146 Color cccccc = new ColorUIResource(0xCCCCCC);
147 Color dadada = new ColorUIResource(0xDADADA);
148 Color c8ddf2 = new ColorUIResource(0xC8DDF2);
149 Object directoryIcon = getIconResource("icons/ocean/directory.gif");
150 Object fileIcon = getIconResource("icons/ocean/file.gif");
151 java.util.List sliderGradient = Arrays.asList(new Object[] {
152 new Float(.3f), new Float(.2f),
153 c8ddf2, getWhite(), new ColorUIResource(SECONDARY2) });
154
155 Object[] defaults = new Object[] {
156 "Button.gradient", buttonGradient,
157 "Button.rollover", Boolean.TRUE,
158 "Button.toolBarBorderBackground", INACTIVE_CONTROL_TEXT_COLOR,
159 "Button.disabledToolBarBorderBackground", cccccc,
160 "Button.rolloverIconType", "ocean",
161
162 "CheckBox.rollover", Boolean.TRUE,
163 "CheckBox.gradient", buttonGradient,
164
165 "CheckBoxMenuItem.gradient", buttonGradient,
166
167 // home2
168 "FileChooser.homeFolderIcon",
169 getIconResource("icons/ocean/homeFolder.gif"),
170 // directory2
171 "FileChooser.newFolderIcon",
172 getIconResource("icons/ocean/newFolder.gif"),
173 // updir2
174 "FileChooser.upFolderIcon",
175 getIconResource("icons/ocean/upFolder.gif"),
176
177 // computer2
178 "FileView.computerIcon",
179 getIconResource("icons/ocean/computer.gif"),
180 "FileView.directoryIcon", directoryIcon,
181 // disk2
182 "FileView.hardDriveIcon",
183 getIconResource("icons/ocean/hardDrive.gif"),
184 "FileView.fileIcon", fileIcon,
185 // floppy2
186 "FileView.floppyDriveIcon",
187 getIconResource("icons/ocean/floppy.gif"),
188
189 "Label.disabledForeground", getInactiveControlTextColor(),
190
191 "Menu.opaque", Boolean.FALSE,
192
193 "MenuBar.gradient", Arrays.asList(new Object[] {
194 new Float(1f), new Float(0f),
195 getWhite(), dadada,
196 new ColorUIResource(dadada) }),
197 "MenuBar.borderColor", cccccc,
198
199 "InternalFrame.activeTitleGradient", buttonGradient,
200 // close2
201 "InternalFrame.closeIcon",
202 new UIDefaults.LazyValue() {
203 public Object createValue(UIDefaults table) {
204 return new IFIcon(getHastenedIcon("icons/ocean/close.gif", table),
205 getHastenedIcon("icons/ocean/close-pressed.gif", table));
206 }
207 },
208 // minimize
209 "InternalFrame.iconifyIcon",
210 new UIDefaults.LazyValue() {
211 public Object createValue(UIDefaults table) {
212 return new IFIcon(getHastenedIcon("icons/ocean/iconify.gif", table),
213 getHastenedIcon("icons/ocean/iconify-pressed.gif", table));
214 }
215 },
216 // restore
217 "InternalFrame.minimizeIcon",
218 new UIDefaults.LazyValue() {
219 public Object createValue(UIDefaults table) {
220 return new IFIcon(getHastenedIcon("icons/ocean/minimize.gif", table),
221 getHastenedIcon("icons/ocean/minimize-pressed.gif", table));
222 }
223 },
224 // menubutton3
225 "InternalFrame.icon",
226 getIconResource("icons/ocean/menu.gif"),
227 // maximize2
228 "InternalFrame.maximizeIcon",
229 new UIDefaults.LazyValue() {
230 public Object createValue(UIDefaults table) {
231 return new IFIcon(getHastenedIcon("icons/ocean/maximize.gif", table),
232 getHastenedIcon("icons/ocean/maximize-pressed.gif", table));
233 }
234 },
235 // paletteclose
236 "InternalFrame.paletteCloseIcon",
237 new UIDefaults.LazyValue() {
238 public Object createValue(UIDefaults table) {
239 return new IFIcon(getHastenedIcon("icons/ocean/paletteClose.gif", table),
240 getHastenedIcon("icons/ocean/paletteClose-pressed.gif", table));
241 }
242 },
243
244 "List.focusCellHighlightBorder", focusBorder,
245
246 "MenuBarUI", "javax.swing.plaf.metal.MetalMenuBarUI",
247
248 "OptionPane.errorIcon",
249 getIconResource("icons/ocean/error.png"),
250 "OptionPane.informationIcon",
251 getIconResource("icons/ocean/info.png"),
252 "OptionPane.questionIcon",
253 getIconResource("icons/ocean/question.png"),
254 "OptionPane.warningIcon",
255 getIconResource("icons/ocean/warning.png"),
256
257 "RadioButton.gradient", buttonGradient,
258 "RadioButton.rollover", Boolean.TRUE,
259
260 "RadioButtonMenuItem.gradient", buttonGradient,
261
262 "ScrollBar.gradient", buttonGradient,
263
264 "Slider.altTrackColor", new ColorUIResource(0xD2E2EF),
265 "Slider.gradient", sliderGradient,
266 "Slider.focusGradient", sliderGradient,
267
268 "SplitPane.oneTouchButtonsOpaque", Boolean.FALSE,
269 "SplitPane.dividerFocusColor", c8ddf2,
270
271 "TabbedPane.borderHightlightColor", getPrimary1(),
272 "TabbedPane.contentAreaColor", c8ddf2,
273 "TabbedPane.contentBorderInsets", new Insets(4, 2, 3, 3),
274 "TabbedPane.selected", c8ddf2,
275 "TabbedPane.tabAreaBackground", dadada,
276 "TabbedPane.tabAreaInsets", new Insets(2, 2, 0, 6),
277 "TabbedPane.unselectedBackground", SECONDARY3,
278
279 "Table.focusCellHighlightBorder", focusBorder,
280 "Table.gridColor", SECONDARY1,
281 "TableHeader.focusCellBackground", c8ddf2,
282
283 "ToggleButton.gradient", buttonGradient,
284
285 "ToolBar.borderColor", cccccc,
286 "ToolBar.isRollover", Boolean.TRUE,
287
288 "Tree.closedIcon", directoryIcon,
289
290 "Tree.collapsedIcon",
291 new UIDefaults.LazyValue() {
292 public Object createValue(UIDefaults table) {
293 return new COIcon(getHastenedIcon("icons/ocean/collapsed.gif", table),
294 getHastenedIcon("icons/ocean/collapsed-rtl.gif", table));
295 }
296 },
297
298 "Tree.expandedIcon",
299 getIconResource("icons/ocean/expanded.gif"),
300 "Tree.leafIcon", fileIcon,
301 "Tree.openIcon", directoryIcon,
302 "Tree.selectionBorderColor", getPrimary1(),
303 "Tree.dropLineColor", getPrimary1(),
304 "Table.dropLineColor", getPrimary1(),
305 "Table.dropLineShortColor", OCEAN_BLACK,
306
307 "Table.dropCellBackground", OCEAN_DROP,
308 "Tree.dropCellBackground", OCEAN_DROP,
309 "List.dropCellBackground", OCEAN_DROP,
310 "List.dropLineColor", getPrimary1()
311 };
312 table.putDefaults(defaults);
313 }
314
315 /**
316 * Overriden to enable picking up the system fonts, if applicable.
317 */
318 boolean isSystemTheme() {
319 return true;
320 }
321
322 /**
323 * Return the name of this theme, "Ocean".
324 *
325 * @return "Ocean"
326 */
327 public String getName() {
328 return "Ocean";
329 }
330
331 /**
332 * Returns the primary 1 color. This returns a color with an rgb hex value
333 * of {@code 0x6382BF}.
334 *
335 * @return the primary 1 color
336 * @see java.awt.Color#decode
337 */
338 protected ColorUIResource getPrimary1() {
339 return PRIMARY1;
340 }
341
342 /**
343 * Returns the primary 2 color. This returns a color with an rgb hex value
344 * of {@code 0xA3B8CC}.
345 *
346 * @return the primary 2 color
347 * @see java.awt.Color#decode
348 */
349 protected ColorUIResource getPrimary2() {
350 return PRIMARY2;
351 }
352
353 /**
354 * Returns the primary 3 color. This returns a color with an rgb hex value
355 * of {@code 0xB8CFE5}.
356 *
357 * @return the primary 3 color
358 * @see java.awt.Color#decode
359 */
360 protected ColorUIResource getPrimary3() {
361 return PRIMARY3;
362 }
363
364 /**
365 * Returns the secondary 1 color. This returns a color with an rgb hex
366 * value of {@code 0x7A8A99}.
367 *
368 * @return the secondary 1 color
369 * @see java.awt.Color#decode
370 */
371 protected ColorUIResource getSecondary1() {
372 return SECONDARY1;
373 }
374
375 /**
376 * Returns the secondary 2 color. This returns a color with an rgb hex
377 * value of {@code 0xB8CFE5}.
378 *
379 * @return the secondary 2 color
380 * @see java.awt.Color#decode
381 */
382 protected ColorUIResource getSecondary2() {
383 return SECONDARY2;
384 }
385
386 /**
387 * Returns the secondary 3 color. This returns a color with an rgb hex
388 * value of {@code 0xEEEEEE}.
389 *
390 * @return the secondary 3 color
391 * @see java.awt.Color#decode
392 */
393 protected ColorUIResource getSecondary3() {
394 return SECONDARY3;
395 }
396
397 /**
398 * Returns the black color. This returns a color with an rgb hex
399 * value of {@code 0x333333}.
400 *
401 * @return the black color
402 * @see java.awt.Color#decode
403 */
404 protected ColorUIResource getBlack() {
405 return OCEAN_BLACK;
406 }
407
408 /**
409 * Returns the desktop color. This returns a color with an rgb hex
410 * value of {@code 0xFFFFFF}.
411 *
412 * @return the desktop color
413 * @see java.awt.Color#decode
414 */
415 public ColorUIResource getDesktopColor() {
416 return MetalTheme.white;
417 }
418
419 /**
420 * Returns the inactive control text color. This returns a color with an
421 * rgb hex value of {@code 0x999999}.
422 *
423 * @return the inactive control text color
424 */
425 public ColorUIResource getInactiveControlTextColor() {
426 return INACTIVE_CONTROL_TEXT_COLOR;
427 }
428
429 /**
430 * Returns the control text color. This returns a color with an
431 * rgb hex value of {@code 0x333333}.
432 *
433 * @return the control text color
434 */
435 public ColorUIResource getControlTextColor() {
436 return CONTROL_TEXT_COLOR;
437 }
438
439 /**
440 * Returns the menu disabled foreground color. This returns a color with an
441 * rgb hex value of {@code 0x999999}.
442 *
443 * @return the menu disabled foreground color
444 */
445 public ColorUIResource getMenuDisabledForeground() {
446 return MENU_DISABLED_FOREGROUND;
447 }
448
449 private Object getIconResource(String iconID) {
450 return SwingUtilities2.makeIcon(getClass(), OceanTheme.class, iconID);
451 }
452
453 // makes use of getIconResource() to fetch an icon and then hastens it
454 // - calls createValue() on it and returns the actual icon
455 private Icon getHastenedIcon(String iconID, UIDefaults table) {
456 Object res = getIconResource(iconID);
457 return (Icon)((UIDefaults.LazyValue)res).createValue(table);
458 }
459}