Source Code Cross Referenced for DefaultOffice2003Theme.java in  » Swing-Library » jide-common » com » jidesoft » plaf » office2003 » Java Source Code / Java DocumentationJava Source Code and Java Documentation

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 geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » jide common » com.jidesoft.plaf.office2003 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)${NAME}
003:         *
004:         * Copyright 2002 - 2004 JIDE Software Inc. All rights reserved.
005:         */
006:        package com.jidesoft.plaf.office2003;
007:
008:        import com.jidesoft.icons.IconsFactory;
009:        import com.jidesoft.plaf.*;
010:        import com.jidesoft.plaf.vsnet.ConvertListener;
011:        import com.jidesoft.utils.ColorUtils;
012:
013:        import javax.swing.*;
014:        import javax.swing.plaf.ColorUIResource;
015:        import java.awt.*;
016:
017:        /**
018:         * The default 2003 theme. This theme doesn't define any color of its own but derive all colors from
019:         * the underlying L&F. If your application used a customized L&F other than Windows L&F, this is
020:         * the preferred theme as it will consider the colors defined underlying L&F to make it looks consistent
021:         * than hard-coded themes such as BLUE, HOMESTEAD of METALLIC.
022:         */
023:        public class DefaultOffice2003Theme extends Office2003Theme {
024:            private static final double DAKRER_FACTOR = 0.76;
025:            private static final double FACTOR = 0.85;
026:            private static final double LIGHTER_FACTOR = 0.95;
027:            private static final double EVEN_LIGHTER_FACTOR = 0.97;
028:
029:            private static boolean _useStandardSelectionColor;
030:
031:            static {
032:                try {
033:                    _useStandardSelectionColor = XPUtils.isXPStyleOn();
034:                } catch (UnsupportedOperationException e) {
035:                    _useStandardSelectionColor = false;
036:                }
037:            }
038:
039:            static Color getLighterColor(Color color) {
040:                if (Color.BLACK.equals(color)) {
041:                    return color;
042:                } else if (Color.WHITE.equals(color)) {
043:                    return color;
044:                }
045:                return ColorUtils.getDerivedColor(color, 0.93f);
046:            }
047:
048:            public DefaultOffice2003Theme() {
049:                super (XPUtils.DEFAULT);
050:
051:                if (!isUseStandardSelectionColor()) {
052:                    putDerivedSelectionColor();
053:                }
054:
055:                Toolkit toolkit = Toolkit.getDefaultToolkit();
056:                WindowsDesktopProperty control = new WindowsDesktopProperty(
057:                        "win.3d.backgroundColor", UIDefaultsLookup
058:                                .get("control"), toolkit);
059:                Object controlDk2 = new ExtWindowsDesktopProperty(
060:                        new String[] { "win.3d.backgroundColor" },
061:                        new Object[] { UIDefaultsLookup.get("control") },
062:                        toolkit, new ConvertListener() {
063:                            public Object convert(Object[] obj) {
064:                                return darker((Color) obj[0], LIGHTER_FACTOR);
065:                            }
066:                        });
067:                Object controlDk = new ExtWindowsDesktopProperty(
068:                        new String[] { "win.3d.backgroundColor" },
069:                        new Object[] { UIDefaultsLookup.get("control") },
070:                        toolkit, new ConvertListener() {
071:                            public Object convert(Object[] obj) {
072:                                return darker((Color) obj[0], DAKRER_FACTOR);
073:                            }
074:                        });
075:                Object controlLt = new ExtWindowsDesktopProperty(
076:                        new String[] { "win.3d.highlightColor" },
077:                        new Object[] { UIDefaultsLookup
078:                                .get("controlLtHighlight") }, toolkit,
079:                        new ConvertListener() {
080:                            public Object convert(Object[] obj) {
081:                                return brighter((Color) obj[0], FACTOR);
082:                            }
083:                        });
084:                WindowsDesktopProperty controlShadow = new WindowsDesktopProperty(
085:                        "win.3d.shadowColor", UIDefaultsLookup
086:                                .get("controlShadow"), toolkit);
087:                Object controlDkShadow = new ExtWindowsDesktopProperty(
088:                        new String[] { "win.3d.shadowColor" },
089:                        new Object[] { UIDefaultsLookup.get("controlShadow") },
090:                        toolkit, new ConvertListener() {
091:                            public Object convert(Object[] obj) {
092:                                return darker((Color) obj[0], FACTOR);
093:                            }
094:                        });
095:                WindowsDesktopProperty controlText = new WindowsDesktopProperty(
096:                        "win.button.textColor", UIDefaultsLookup
097:                                .get("controlText"), toolkit);
098:                WindowsDesktopProperty controlLtHighlight = new WindowsDesktopProperty(
099:                        "win.3d.highlightColor", UIDefaultsLookup
100:                                .get("controlLtHighlight"), toolkit);
101:                WindowsDesktopProperty commandBarCaption = new WindowsDesktopProperty(
102:                        "", UIDefaultsLookup.get("inactiveCaption"), toolkit);
103:                Object menuItemBackground = new ExtWindowsDesktopProperty(
104:                        //Actual color 249, 248, 247
105:                        new String[] { "win.3d.backgroundColor" },
106:                        new Object[] { UIDefaultsLookup.get("control") },
107:                        toolkit, new ConvertListener() {
108:                            public Object convert(Object[] obj) {
109:                                return new ColorUIResource(
110:                                        getLighterColor((Color) obj[0]));
111:                            }
112:                        });
113:
114:                Object uiDefaults[] = { "control", control, "controlLt",
115:                        controlLt, "controlDk", control, "controlShadow",
116:                        controlShadow,
117:
118:                        "OptionPane.bannerLt", new ColorUIResource(0, 52, 206),
119:                        "OptionPane.bannerDk",
120:                        new ColorUIResource(45, 96, 249),
121:                        "OptionPane.bannerForeground",
122:                        new ColorUIResource(255, 255, 255),
123:
124:                        "Separator.foreground", controlShadow,
125:                        "Separator.foregroundLt", controlLt,
126:
127:                        "Gripper.foreground", controlShadow,
128:                        "Gripper.foregroundLt", controlLt,
129:
130:                        "Chevron.backgroundLt", controlDk,
131:                        "Chevron.backgroundDk", controlShadow,
132:
133:                        "Divider.backgroundLt", controlShadow,
134:                        "Divider.backgroundDk", controlDkShadow,
135:
136:                        "backgroundLt", controlLt, "backgroundDk", control,
137:
138:                        "selection.border", controlShadow,
139:
140:                        "MenuItem.background", menuItemBackground,
141:
142:                        "DockableFrameTitlePane.backgroundLt", controlLt,
143:                        "DockableFrameTitlePane.backgroundDk", controlDk2,
144:                        "DockableFrameTitlePane.activeForeground", controlText,
145:                        "DockableFrameTitlePane.inactiveForeground",
146:                        controlText, "DockableFrame.backgroundLt", controlLt,
147:                        "DockableFrame.backgroundDk", controlLt,
148:
149:                        "CommandBar.titleBarBackground", commandBarCaption, };
150:                putDefaults(uiDefaults);
151:
152:                int products = LookAndFeelFactory.getProductsUsed();
153:
154:                if ((products & LookAndFeelFactory.PRODUCT_COMPONENTS) != 0) {
155:                    final int SIZE = 20;
156:                    final int MASK_SIZE = 11;
157:                    ImageIcon collapsiblePaneImage = IconsFactory.getImageIcon(
158:                            Office2003WindowsUtils.class,
159:                            "icons/collapsible_pane_default.png"); // 20 x 20
160:                    ImageIcon collapsiblePaneMask = IconsFactory.getImageIcon(
161:                            Office2003WindowsUtils.class,
162:                            "icons/collapsible_pane_mask.png"); // 11 x 11
163:                    ImageIcon normalIcon = IconsFactory.getIcon(null,
164:                            collapsiblePaneImage, 0, 0, SIZE, SIZE);
165:                    ImageIcon emphasizedIcon = IconsFactory.getIcon(null,
166:                            collapsiblePaneImage, SIZE, 0, SIZE, SIZE);
167:                    ImageIcon upMark = IconsFactory.getIcon(null,
168:                            collapsiblePaneMask, 0, 0, MASK_SIZE, MASK_SIZE);
169:                    ImageIcon downMark = IconsFactory.getIcon(null,
170:                            collapsiblePaneMask, 0, MASK_SIZE, MASK_SIZE,
171:                            MASK_SIZE);
172:                    uiDefaults = new Object[] {
173:                            "CollapsiblePane.contentBackground",
174:                            controlLtHighlight,
175:                            "CollapsiblePanes.backgroundLt",
176:                            control,
177:                            "CollapsiblePanes.backgroundDk",
178:                            controlShadow,
179:                            "CollapsiblePaneTitlePane.backgroundLt",
180:                            controlLt,
181:                            "CollapsiblePaneTitlePane.backgroundDk",
182:                            control,
183:                            "CollapsiblePaneTitlePane.foreground",
184:                            controlText,
185:                            "CollapsiblePaneTitlePane.foreground.focus",
186:                            controlText,
187:                            "CollapsiblePaneTitlePane.backgroundLt.emphasized",
188:                            controlShadow,
189:                            "CollapsiblePaneTitlePane.backgroundDk.emphasized",
190:                            controlDkShadow,
191:                            "CollapsiblePaneTitlePane.foreground.emphasized",
192:                            controlLtHighlight,
193:                            "CollapsiblePaneTitlePane.foreground.focus.emphasized",
194:                            controlLtHighlight,
195:                            "CollapsiblePane.downIcon",
196:                            IconsFactory.getOverlayIcon(null, normalIcon,
197:                                    downMark, SwingConstants.CENTER),
198:                            "CollapsiblePane.upIcon",
199:                            IconsFactory.getOverlayIcon(null, normalIcon,
200:                                    upMark, SwingConstants.CENTER),
201:                            "CollapsiblePane.downIcon.emphasized",
202:                            IconsFactory.getOverlayIcon(null, emphasizedIcon,
203:                                    downMark, SwingConstants.CENTER),
204:                            "CollapsiblePane.upIcon.emphasized",
205:                            IconsFactory.getOverlayIcon(null, emphasizedIcon,
206:                                    upMark, SwingConstants.CENTER),
207:                            "CollapsiblePane.upMask", upMark,
208:                            "CollapsiblePane.downMask", downMark,
209:                            "CollapsiblePane.titleButtonBackground",
210:                            normalIcon,
211:                            "CollapsiblePane.titleButtonBackground.emphasized",
212:                            emphasizedIcon, };
213:                    putDefaults(uiDefaults);
214:                }
215:            }
216:
217:            private void putDerivedSelectionColor() {
218:                Object selectionRollover = new ActiveValue() {
219:                    public Object createValue(UIDefaults table) {
220:                        return UIDefaultsLookup
221:                                .getColor("JideButton.focusedBackground");
222:                    }
223:                };
224:                Object selectionRolloverLt = new ActiveValue() {
225:                    public Object createValue(UIDefaults table) {
226:                        return brighter(UIDefaultsLookup
227:                                .getColor("JideButton.focusedBackground"),
228:                                LIGHTER_FACTOR);
229:                    }
230:                };
231:                Object selectionRolloverDk = new ActiveValue() {
232:                    public Object createValue(UIDefaults table) {
233:                        return darker(UIDefaultsLookup
234:                                .getColor("JideButton.focusedBackground"),
235:                                LIGHTER_FACTOR);
236:                    }
237:                };
238:
239:                Object selectionSelected = new ActiveValue() {
240:                    public Object createValue(UIDefaults table) {
241:                        return UIDefaultsLookup
242:                                .getColor("JideButton.selectedBackground");
243:                    }
244:                };
245:                Object selectionSelectedLt = new ActiveValue() {
246:                    public Object createValue(UIDefaults table) {
247:                        return brighter(UIDefaultsLookup
248:                                .getColor("JideButton.selectedBackground"),
249:                                LIGHTER_FACTOR);
250:                    }
251:                };
252:                Object selectionSelectedDk = new ActiveValue() {
253:                    public Object createValue(UIDefaults table) {
254:                        return darker(UIDefaultsLookup
255:                                .getColor("JideButton.selectedBackground"),
256:                                LIGHTER_FACTOR);
257:                    }
258:                };
259:                Object selectionSelectedAndFocused = new ActiveValue() {
260:                    public Object createValue(UIDefaults table) {
261:                        return UIDefaultsLookup
262:                                .getColor("JideButton.selectedAndFocusedBackground");
263:                    }
264:                };
265:                Object selectionSelectedAndFocusedLt = new ActiveValue() {
266:                    public Object createValue(UIDefaults table) {
267:                        return brighter(
268:                                UIDefaultsLookup
269:                                        .getColor("JideButton.selectedAndFocusedBackground"),
270:                                LIGHTER_FACTOR);
271:                    }
272:                };
273:                Object selectionSelectedAndFocusedDk = new ActiveValue() {
274:                    public Object createValue(UIDefaults table) {
275:                        return darker(
276:                                UIDefaultsLookup
277:                                        .getColor("JideButton.selectedAndFocusedBackground"),
278:                                LIGHTER_FACTOR);
279:                    }
280:                };
281:
282:                Object[] uiDefaultsSelection = new Object[] {
283:                        "selection.Rollover", selectionRollover,
284:                        "selection.RolloverLt", selectionRolloverLt,
285:                        "selection.RolloverDk", selectionRolloverDk,
286:
287:                        "selection.Selected", selectionSelected,
288:                        "selection.SelectedLt", selectionSelectedLt,
289:                        "selection.SelectedDk", selectionSelectedDk,
290:
291:                        "selection.Pressed",
292:                        selectionSelectedAndFocused, // focused and selected;
293:                        "selection.PressedLt", selectionSelectedAndFocusedLt,
294:                        "selection.PressedDk", selectionSelectedAndFocusedDk };
295:                putDefaults(uiDefaultsSelection);
296:            }
297:
298:            private void removeDerivedSelectionColor() {
299:                Object[] uiDefaultsSelection = new Object[] {
300:                        "selection.Rollover", "selection.RolloverLt",
301:                        "selection.RolloverDk",
302:
303:                        "selection.Selected", "selection.SelectedLt",
304:                        "selection.SelectedDk",
305:
306:                        "selection.Pressed", "selection.PressedLt",
307:                        "selection.PressedDk" };
308:                for (int i = 0; i < uiDefaultsSelection.length; i++) {
309:                    Object o = uiDefaultsSelection[i];
310:                    remove(o);
311:                }
312:            }
313:
314:            /**
315:             * Creates a new <code>Color</code> that is a brighter version of this
316:             * <code>Color</code>.
317:             * <p/>
318:             * This method applies an arbitrary scale factor to each of the three RGB
319:             * components of this <code>Color</code> to create a brighter version
320:             * of this <code>Color</code>. Although <code>brighter</code> and
321:             * <code>darker</code> are inverse operations, the results of a
322:             * series of invocations of these two methods might be inconsistent
323:             * because of rounding errors.
324:             *
325:             * @return a new <code>Color</code> object that is
326:             *         a brighter version of this <code>Color</code>.
327:             * @see java.awt.Color#darker
328:             * @since JDK1.0
329:             */
330:            private Color brighter(Color c, double factor) {
331:                int r = c.getRed();
332:                int g = c.getGreen();
333:                int b = c.getBlue();
334:
335:                /* From 2D group:
336:                 * 1. black.brighter() should return grey
337:                 * 2. applying brighter to blue will always return blue, brighter
338:                 * 3. non pure color (non zero rgb) will eventually return white
339:                 */
340:                int i = (int) (1.0 / (1.0 - factor));
341:                if (r == 0 && g == 0 && b == 0) {
342:                    return new Color(i, i, i);
343:                }
344:                if (r > 0 && r < i)
345:                    r = i;
346:                if (g > 0 && g < i)
347:                    g = i;
348:                if (b > 0 && b < i)
349:                    b = i;
350:
351:                return new Color(Math.min((int) (r / factor), 255), Math.min(
352:                        (int) (g / factor), 255), Math.min((int) (b / factor),
353:                        255));
354:            }
355:
356:            /**
357:             * Creates a new <code>Color</code> that is a darker version of this
358:             * <code>Color</code>.
359:             * <p/>
360:             * This method applies an arbitrary scale factor to each of the three RGB
361:             * components of this <code>Color</code> to create a darker version of
362:             * this <code>Color</code>.  Although <code>brighter</code> and
363:             * <code>darker</code> are inverse operations, the results of a series
364:             * of invocations of these two methods might be inconsistent because
365:             * of rounding errors.
366:             *
367:             * @return a new <code>Color</code> object that is
368:             *         a darker version of this <code>Color</code>.
369:             * @see java.awt.Color#brighter
370:             * @since JDK1.0
371:             */
372:            private Color darker(Color c, double factor) {
373:                return new Color(Math.max((int) (c.getRed() * factor), 0), Math
374:                        .max((int) (c.getGreen() * factor), 0), Math.max(
375:                        (int) (c.getBlue() * factor), 0));
376:            }
377:
378:            /**
379:             * Checks if the standard selection color will be used.
380:             *
381:             * @return true if the standard selection color will be used.
382:             */
383:            public static boolean isUseStandardSelectionColor() {
384:                return _useStandardSelectionColor;
385:            }
386:
387:            /**
388:             * Sets if the standard selection color will be used. The standard selection color (orange) is the color that used in Office 2003
389:             * to indicate a button is selected or focused. By default it will be used for all Office 2003 theme including DefayltOffice2003Theme.
390:             * If user chooses not to use it, the theme will derive the color from the default selection color of the LookAndFeel.
391:             * <p/>
392:             * If you want to call this method, make sure you call it before LookAndFeelFactory.installJideExtension(...) is called.
393:             *
394:             * @param useStandardSelectionColor
395:             */
396:            public static void setUseStandardSelectionColor(
397:                    boolean useStandardSelectionColor) {
398:                _useStandardSelectionColor = useStandardSelectionColor;
399:            }
400:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.