Source Code Cross Referenced for OceanTheme.java in  » 6.0-JDK-Core » swing » javax » swing » plaf » metal » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » swing » javax.swing.plaf.metal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * Copyright 2003-2006 Sun Microsystems, Inc.  All Rights Reserved.
003         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004         *
005         * This code is free software; you can redistribute it and/or modify it
006         * under the terms of the GNU General Public License version 2 only, as
007         * published by the Free Software Foundation.  Sun designates this
008         * particular file as subject to the "Classpath" exception as provided
009         * by Sun in the LICENSE file that accompanied this code.
010         *
011         * This code is distributed in the hope that it will be useful, but WITHOUT
012         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014         * version 2 for more details (a copy is included in the LICENSE file that
015         * accompanied this code).
016         *
017         * You should have received a copy of the GNU General Public License version
018         * 2 along with this work; if not, write to the Free Software Foundation,
019         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020         *
021         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022         * CA 95054 USA or visit www.sun.com if you need additional information or
023         * have any questions.
024         */
025
026        package javax.swing.plaf.metal;
027
028        import java.awt.*;
029        import java.net.URL;
030        import java.util.*;
031        import javax.swing.*;
032        import javax.swing.plaf.*;
033        import sun.swing.SwingUtilities2;
034        import sun.swing.PrintColorUIResource;
035
036        /**
037         * The default theme for the {@code MetalLookAndFeel}.
038         * <p>
039         * The designers
040         * of the Metal Look and Feel strive to keep the default look up to
041         * date, possibly through the use of new themes in the future.
042         * Therefore, developers should only use this class directly when they
043         * wish to customize the "Ocean" look, or force it to be the current
044         * theme, regardless of future updates.
045
046         * <p>
047         * All colors returned by {@code OceanTheme} are completely
048         * opaque.
049         *
050         * @version 1.27 05/05/07
051         * @since 1.5
052         * @see MetalLookAndFeel#setCurrentTheme
053         */
054        public class OceanTheme extends DefaultMetalTheme {
055            private static final ColorUIResource PRIMARY1 = new ColorUIResource(
056                    0x6382BF);
057            private static final ColorUIResource PRIMARY2 = new ColorUIResource(
058                    0xA3B8CC);
059            private static final ColorUIResource PRIMARY3 = new ColorUIResource(
060                    0xB8CFE5);
061            private static final ColorUIResource SECONDARY1 = new ColorUIResource(
062                    0x7A8A99);
063            private static final ColorUIResource SECONDARY2 = new ColorUIResource(
064                    0xB8CFE5);
065            private static final ColorUIResource SECONDARY3 = new ColorUIResource(
066                    0xEEEEEE);
067
068            private static final ColorUIResource CONTROL_TEXT_COLOR = new PrintColorUIResource(
069                    0x333333, Color.BLACK);
070            private static final ColorUIResource INACTIVE_CONTROL_TEXT_COLOR = new ColorUIResource(
071                    0x999999);
072            private static final ColorUIResource MENU_DISABLED_FOREGROUND = new ColorUIResource(
073                    0x999999);
074            private static final ColorUIResource OCEAN_BLACK = new PrintColorUIResource(
075                    0x333333, Color.BLACK);
076
077            private static final ColorUIResource OCEAN_DROP = new ColorUIResource(
078                    0xD2E9FF);
079
080            // ComponentOrientation Icon
081            // Delegates to different icons based on component orientation
082            private static class COIcon extends IconUIResource {
083                private Icon rtl;
084
085                public COIcon(Icon ltr, Icon rtl) {
086                    super (ltr);
087                    this .rtl = rtl;
088                }
089
090                public void paintIcon(Component c, Graphics g, int x, int y) {
091                    if (MetalUtils.isLeftToRight(c)) {
092                        super .paintIcon(c, g, x, y);
093                    } else {
094                        rtl.paintIcon(c, g, x, y);
095                    }
096                }
097            }
098
099            // InternalFrame Icon
100            // Delegates to different icons based on button state
101            private static class IFIcon extends IconUIResource {
102                private Icon pressed;
103
104                public IFIcon(Icon normal, Icon pressed) {
105                    super (normal);
106                    this .pressed = pressed;
107                }
108
109                public void paintIcon(Component c, Graphics g, int x, int y) {
110                    ButtonModel model = ((AbstractButton) c).getModel();
111                    if (model.isPressed() && model.isArmed()) {
112                        pressed.paintIcon(c, g, x, y);
113                    } else {
114                        super .paintIcon(c, g, x, y);
115                    }
116                }
117            }
118
119            /**
120             * Creates an instance of <code>OceanTheme</code>
121             */
122            public OceanTheme() {
123            }
124
125            /**
126             * Add this theme's custom entries to the defaults table.
127             *
128             * @param table the defaults table, non-null
129             * @throws NullPointerException if {@code table} is {@code null}
130             */
131            public void addCustomEntriesToTable(UIDefaults table) {
132                Object focusBorder = new UIDefaults.ProxyLazyValue(
133                        "javax.swing.plaf.BorderUIResource$LineBorderUIResource",
134                        new Object[] { getPrimary1() });
135                // .30 0 DDE8F3 white secondary2
136                java.util.List buttonGradient = Arrays.asList(new Object[] {
137                        new Float(.3f), new Float(0f),
138                        new ColorUIResource(0xDDE8F3), getWhite(),
139                        getSecondary2() });
140
141                // Other possible properties that aren't defined:
142                //
143                // Used when generating the disabled Icons, provides the region to
144                // constrain grays to.
145                // Button.disabledGrayRange -> Object[] of Integers giving min/max
146                // InternalFrame.inactiveTitleGradient -> Gradient when the
147                //   internal frame is inactive.
148                Color cccccc = new ColorUIResource(0xCCCCCC);
149                Color dadada = new ColorUIResource(0xDADADA);
150                Color c8ddf2 = new ColorUIResource(0xC8DDF2);
151                Object directoryIcon = getIconResource("icons/ocean/directory.gif");
152                Object fileIcon = getIconResource("icons/ocean/file.gif");
153                java.util.List sliderGradient = Arrays.asList(new Object[] {
154                        new Float(.3f), new Float(.2f), c8ddf2, getWhite(),
155                        new ColorUIResource(SECONDARY2) });
156
157                Object[] defaults = new Object[] {
158                        "Button.gradient",
159                        buttonGradient,
160                        "Button.rollover",
161                        Boolean.TRUE,
162                        "Button.toolBarBorderBackground",
163                        INACTIVE_CONTROL_TEXT_COLOR,
164                        "Button.disabledToolBarBorderBackground",
165                        cccccc,
166                        "Button.rolloverIconType",
167                        "ocean",
168
169                        "CheckBox.rollover",
170                        Boolean.TRUE,
171                        "CheckBox.gradient",
172                        buttonGradient,
173
174                        "CheckBoxMenuItem.gradient",
175                        buttonGradient,
176
177                        // home2
178                        "FileChooser.homeFolderIcon",
179                        getIconResource("icons/ocean/homeFolder.gif"),
180                        // directory2
181                        "FileChooser.newFolderIcon",
182                        getIconResource("icons/ocean/newFolder.gif"),
183                        // updir2
184                        "FileChooser.upFolderIcon",
185                        getIconResource("icons/ocean/upFolder.gif"),
186
187                        // computer2
188                        "FileView.computerIcon",
189                        getIconResource("icons/ocean/computer.gif"),
190                        "FileView.directoryIcon",
191                        directoryIcon,
192                        // disk2
193                        "FileView.hardDriveIcon",
194                        getIconResource("icons/ocean/hardDrive.gif"),
195                        "FileView.fileIcon",
196                        fileIcon,
197                        // floppy2
198                        "FileView.floppyDriveIcon",
199                        getIconResource("icons/ocean/floppy.gif"),
200
201                        "Label.disabledForeground",
202                        getInactiveControlTextColor(),
203
204                        "Menu.opaque",
205                        Boolean.FALSE,
206
207                        "MenuBar.gradient",
208                        Arrays.asList(new Object[] { new Float(1f),
209                                new Float(0f), getWhite(), dadada,
210                                new ColorUIResource(dadada) }),
211                        "MenuBar.borderColor",
212                        cccccc,
213
214                        "InternalFrame.activeTitleGradient",
215                        buttonGradient,
216                        // close2
217                        "InternalFrame.closeIcon",
218                        new UIDefaults.LazyValue() {
219                            public Object createValue(UIDefaults table) {
220                                return new IFIcon(
221                                        getHastenedIcon(
222                                                "icons/ocean/close.gif", table),
223                                        getHastenedIcon(
224                                                "icons/ocean/close-pressed.gif",
225                                                table));
226                            }
227                        },
228                        // minimize
229                        "InternalFrame.iconifyIcon",
230                        new UIDefaults.LazyValue() {
231                            public Object createValue(UIDefaults table) {
232                                return new IFIcon(
233                                        getHastenedIcon(
234                                                "icons/ocean/iconify.gif",
235                                                table),
236                                        getHastenedIcon(
237                                                "icons/ocean/iconify-pressed.gif",
238                                                table));
239                            }
240                        },
241                        // restore
242                        "InternalFrame.minimizeIcon",
243                        new UIDefaults.LazyValue() {
244                            public Object createValue(UIDefaults table) {
245                                return new IFIcon(
246                                        getHastenedIcon(
247                                                "icons/ocean/minimize.gif",
248                                                table),
249                                        getHastenedIcon(
250                                                "icons/ocean/minimize-pressed.gif",
251                                                table));
252                            }
253                        },
254                        // menubutton3
255                        "InternalFrame.icon",
256                        getIconResource("icons/ocean/menu.gif"),
257                        // maximize2
258                        "InternalFrame.maximizeIcon",
259                        new UIDefaults.LazyValue() {
260                            public Object createValue(UIDefaults table) {
261                                return new IFIcon(
262                                        getHastenedIcon(
263                                                "icons/ocean/maximize.gif",
264                                                table),
265                                        getHastenedIcon(
266                                                "icons/ocean/maximize-pressed.gif",
267                                                table));
268                            }
269                        },
270                        // paletteclose
271                        "InternalFrame.paletteCloseIcon",
272                        new UIDefaults.LazyValue() {
273                            public Object createValue(UIDefaults table) {
274                                return new IFIcon(
275                                        getHastenedIcon(
276                                                "icons/ocean/paletteClose.gif",
277                                                table),
278                                        getHastenedIcon(
279                                                "icons/ocean/paletteClose-pressed.gif",
280                                                table));
281                            }
282                        },
283
284                        "List.focusCellHighlightBorder",
285                        focusBorder,
286
287                        "MenuBarUI",
288                        "javax.swing.plaf.metal.MetalMenuBarUI",
289
290                        "OptionPane.errorIcon",
291                        getIconResource("icons/ocean/error.png"),
292                        "OptionPane.informationIcon",
293                        getIconResource("icons/ocean/info.png"),
294                        "OptionPane.questionIcon",
295                        getIconResource("icons/ocean/question.png"),
296                        "OptionPane.warningIcon",
297                        getIconResource("icons/ocean/warning.png"),
298
299                        "RadioButton.gradient",
300                        buttonGradient,
301                        "RadioButton.rollover",
302                        Boolean.TRUE,
303
304                        "RadioButtonMenuItem.gradient",
305                        buttonGradient,
306
307                        "ScrollBar.gradient",
308                        buttonGradient,
309
310                        "Slider.altTrackColor",
311                        new ColorUIResource(0xD2E2EF),
312                        "Slider.gradient",
313                        sliderGradient,
314                        "Slider.focusGradient",
315                        sliderGradient,
316
317                        "SplitPane.oneTouchButtonsOpaque",
318                        Boolean.FALSE,
319                        "SplitPane.dividerFocusColor",
320                        c8ddf2,
321
322                        "TabbedPane.borderHightlightColor",
323                        getPrimary1(),
324                        "TabbedPane.contentAreaColor",
325                        c8ddf2,
326                        "TabbedPane.contentBorderInsets",
327                        new Insets(4, 2, 3, 3),
328                        "TabbedPane.selected",
329                        c8ddf2,
330                        "TabbedPane.tabAreaBackground",
331                        dadada,
332                        "TabbedPane.tabAreaInsets",
333                        new Insets(2, 2, 0, 6),
334                        "TabbedPane.unselectedBackground",
335                        SECONDARY3,
336
337                        "Table.focusCellHighlightBorder",
338                        focusBorder,
339                        "Table.gridColor",
340                        SECONDARY1,
341                        "TableHeader.focusCellBackground",
342                        c8ddf2,
343
344                        "ToggleButton.gradient",
345                        buttonGradient,
346
347                        "ToolBar.borderColor",
348                        cccccc,
349                        "ToolBar.isRollover",
350                        Boolean.TRUE,
351
352                        "Tree.closedIcon",
353                        directoryIcon,
354
355                        "Tree.collapsedIcon",
356                        new UIDefaults.LazyValue() {
357                            public Object createValue(UIDefaults table) {
358                                return new COIcon(
359                                        getHastenedIcon(
360                                                "icons/ocean/collapsed.gif",
361                                                table),
362                                        getHastenedIcon(
363                                                "icons/ocean/collapsed-rtl.gif",
364                                                table));
365                            }
366                        },
367
368                        "Tree.expandedIcon",
369                        getIconResource("icons/ocean/expanded.gif"),
370                        "Tree.leafIcon", fileIcon, "Tree.openIcon",
371                        directoryIcon, "Tree.selectionBorderColor",
372                        getPrimary1(), "Tree.dropLineColor", getPrimary1(),
373                        "Table.dropLineColor", getPrimary1(),
374                        "Table.dropLineShortColor", OCEAN_BLACK,
375
376                        "Table.dropCellBackground", OCEAN_DROP,
377                        "Tree.dropCellBackground", OCEAN_DROP,
378                        "List.dropCellBackground", OCEAN_DROP,
379                        "List.dropLineColor", getPrimary1() };
380                table.putDefaults(defaults);
381            }
382
383            /**
384             * Overriden to enable picking up the system fonts, if applicable.
385             */
386            boolean isSystemTheme() {
387                return true;
388            }
389
390            /**
391             * Return the name of this theme, "Ocean".
392             *
393             * @return "Ocean"
394             */
395            public String getName() {
396                return "Ocean";
397            }
398
399            /**
400             * Returns the primary 1 color. This returns a color with an rgb hex value
401             * of {@code 0x6382BF}.
402             *
403             * @return the primary 1 color
404             * @see java.awt.Color#decode
405             */
406            protected ColorUIResource getPrimary1() {
407                return PRIMARY1;
408            }
409
410            /**
411             * Returns the primary 2 color. This returns a color with an rgb hex value
412             * of {@code 0xA3B8CC}.
413             *
414             * @return the primary 2 color
415             * @see java.awt.Color#decode
416             */
417            protected ColorUIResource getPrimary2() {
418                return PRIMARY2;
419            }
420
421            /**
422             * Returns the primary 3 color. This returns a color with an rgb hex value
423             * of {@code 0xB8CFE5}.
424             *
425             * @return the primary 3 color
426             * @see java.awt.Color#decode
427             */
428            protected ColorUIResource getPrimary3() {
429                return PRIMARY3;
430            }
431
432            /**
433             * Returns the secondary 1 color. This returns a color with an rgb hex
434             * value of {@code 0x7A8A99}.
435             *
436             * @return the secondary 1 color
437             * @see java.awt.Color#decode
438             */
439            protected ColorUIResource getSecondary1() {
440                return SECONDARY1;
441            }
442
443            /**
444             * Returns the secondary 2 color. This returns a color with an rgb hex
445             * value of {@code 0xB8CFE5}.
446             *
447             * @return the secondary 2 color
448             * @see java.awt.Color#decode
449             */
450            protected ColorUIResource getSecondary2() {
451                return SECONDARY2;
452            }
453
454            /**
455             * Returns the secondary 3 color. This returns a color with an rgb hex
456             * value of {@code 0xEEEEEE}.
457             *
458             * @return the secondary 3 color
459             * @see java.awt.Color#decode
460             */
461            protected ColorUIResource getSecondary3() {
462                return SECONDARY3;
463            }
464
465            /**
466             * Returns the black color. This returns a color with an rgb hex
467             * value of {@code 0x333333}.
468             *
469             * @return the black color
470             * @see java.awt.Color#decode
471             */
472            protected ColorUIResource getBlack() {
473                return OCEAN_BLACK;
474            }
475
476            /**
477             * Returns the desktop color. This returns a color with an rgb hex
478             * value of {@code 0xFFFFFF}.
479             *
480             * @return the desktop color
481             * @see java.awt.Color#decode
482             */
483            public ColorUIResource getDesktopColor() {
484                return MetalTheme.white;
485            }
486
487            /**
488             * Returns the inactive control text color. This returns a color with an
489             * rgb hex value of {@code 0x999999}.
490             *
491             * @return the inactive control text color
492             */
493            public ColorUIResource getInactiveControlTextColor() {
494                return INACTIVE_CONTROL_TEXT_COLOR;
495            }
496
497            /**
498             * Returns the control text color. This returns a color with an
499             * rgb hex value of {@code 0x333333}.
500             *
501             * @return the control text color
502             */
503            public ColorUIResource getControlTextColor() {
504                return CONTROL_TEXT_COLOR;
505            }
506
507            /**
508             * Returns the menu disabled foreground color. This returns a color with an
509             * rgb hex value of {@code 0x999999}.
510             *
511             * @return the menu disabled foreground color
512             */
513            public ColorUIResource getMenuDisabledForeground() {
514                return MENU_DISABLED_FOREGROUND;
515            }
516
517            private Object getIconResource(String iconID) {
518                return SwingUtilities2.makeIcon(getClass(), OceanTheme.class,
519                        iconID);
520            }
521
522            // makes use of getIconResource() to fetch an icon and then hastens it
523            // - calls createValue() on it and returns the actual icon
524            private Icon getHastenedIcon(String iconID, UIDefaults table) {
525                Object res = getIconResource(iconID);
526                return (Icon) ((UIDefaults.LazyValue) res).createValue(table);
527            }
528        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.