Source Code Cross Referenced for LookAndFeelFactory.java in  » Swing-Library » jide-common » com » jidesoft » plaf » 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 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * @(#)LookAndFeelFactory.java 5/28/2005
0003:         *
0004:         * Copyright 2002 - 2005 JIDE Software Inc. All rights reserved.
0005:         */
0006:
0007:        package com.jidesoft.plaf;
0008:
0009:        import com.jidesoft.icons.IconsFactory;
0010:        import com.jidesoft.plaf.basic.Painter;
0011:        import com.jidesoft.plaf.eclipse.Eclipse3xMetalUtils;
0012:        import com.jidesoft.plaf.eclipse.Eclipse3xWindowsUtils;
0013:        import com.jidesoft.plaf.eclipse.EclipseMetalUtils;
0014:        import com.jidesoft.plaf.eclipse.EclipseWindowsUtils;
0015:        import com.jidesoft.plaf.office2003.Office2003Painter;
0016:        import com.jidesoft.plaf.office2003.Office2003WindowsUtils;
0017:        import com.jidesoft.plaf.vsnet.VsnetMetalUtils;
0018:        import com.jidesoft.plaf.vsnet.VsnetWindowsUtils;
0019:        import com.jidesoft.plaf.xerto.XertoMetalUtils;
0020:        import com.jidesoft.plaf.xerto.XertoWindowsUtils;
0021:        import com.jidesoft.swing.JideSwingUtilities;
0022:        import com.jidesoft.swing.JideTabbedPane;
0023:        import com.jidesoft.utils.ProductNames;
0024:        import com.jidesoft.utils.SecurityUtils;
0025:        import com.jidesoft.utils.SystemInfo;
0026:        import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
0027:
0028:        import javax.swing.*;
0029:        import javax.swing.plaf.BorderUIResource;
0030:        import javax.swing.plaf.ColorUIResource;
0031:        import javax.swing.plaf.metal.MetalLookAndFeel;
0032:        import java.awt.*;
0033:        import java.lang.reflect.InvocationTargetException;
0034:        import java.util.List;
0035:        import java.util.Vector;
0036:
0037:        /**
0038:         * JIDE Software created many new components that need their own ComponentUI classes and additional UIDefaults in UIDefaults table.
0039:         * LookAndFeelFactory can take the UIDefaults from any existing look and feel
0040:         * and add the extra UIDefaults JIDE components need.
0041:         * <p/>
0042:         * Before using any JIDE components, please make you call one of the two LookAndFeelFactory.installJideExtension(...) methods.
0043:         * Bascially, you set L&F using UIManager first just like before, then call installJideExtension. See code below for an example.
0044:         * <code><pre>
0045:         * UIManager.setLookAndFeel(WindowsLookAndFeel.class.getName()); // you need to catch the exceptions on this call.
0046:         * LookAndFeelFactory.installJideExtension();
0047:         * </pre></code>
0048:         * LookAndFeelFactory.installJideExtension() method will check what kind of L&F you set and what operating system you are on and
0049:         * decide which style of JIDE extension it will install. Here is the rule.
0050:         * <ul>
0051:         * <li> OS: Windows XP with XP theme on, L&F: Windows L&F => OFFICE2003_STYLE
0052:         * <li> OS: any Windows, L&F: Windows L&F => VSNET_STYLE
0053:         * <li> OS: Linux, L&F: any L&F based on Metal L&F => VSNET_STYLE
0054:         * <li> OS: Mac OSX, L&F: Aqua L&F => AQUA_STYLE
0055:         * <li> OS: any OS, L&F: Quaqua L&F => AQUA_STYLE
0056:         * <li> Otherwise => VSNET_STYLE
0057:         * </ul>
0058:         * There is also another installJideExtension which takes an int style parameter. You can pass in {@link #VSNET_STYLE},
0059:         * {@link #ECLIPSE_STYLE}, {@link #ECLIPSE3X_STYLE}, {@link #OFFICE2003_STYLE}, or {@link #XERTO_STYLE}. In the other word,
0060:         * you will make the choice of style instead of letting LookAndFeelFactory to decide one for you. Please note, there is no constant defined for
0061:         * AQUA_STYLE. The only way to use it is when you are using Aqua L&F or Quaqua L&F and you call installJideExtension() method,
0062:         * the one without parameter.
0063:         * <p/>
0064:         * LookAndFeelFactory supports a number of known L&Fs. You can see those L&Fs as constants whose names are
0065:         * something like "_LNF" such as WINDOWS_LNF.
0066:         * <p/>
0067:         * If you are using a 3rd party L&F we are not officially supporting, we might need to customize it. Here are two classes you can use.
0068:         * The first one is {@link UIDefaultsCustomizer}. You can add a number of customizers to LookAndFeelFactory. After LookAndFeelFactory
0069:         * installJideExtension method is called, we will call customize() method on each UIDefaultsCustomizer to add additional UIDefaults
0070:         * you specified. You can use UIDefaultsCustomizer to do things like small tweaks to UIDefaults without the hassle of creating a new style.
0071:         * <p/>
0072:         * Most likely, we will not need to use {@link UIDefaultsInitializer} if you are use L&Fs such as WindowsLookAndFeel,
0073:         * any L&Fs based on MetalLookAndFeel, or AquaLookAndFeel etc. The only exception is Synth L&F and any L&Fs based on it. The reason is we
0074:         * calcualte all colors we will use in JIDE components from existing wel-known UIDefaults. For example, we will use UIManagerLookup.getColor("activeCaption")
0075:         * to calculate a color that we can use in dockable frame's title pane. We will use UIManagerLookup.getColor("control") to calculate a color that
0076:         * we can use as background of JIDE component. Most L&Fs will fill those UIDefaults. However in Synth L&F, those UIDefaults may or may not
0077:         * have a valid value. You will end up with NPE later in the code when you call installJideExtension. In this case, you can add those extra UIDefaults
0078:         * in UIDefaultsInitializer. We will call it before installJideExtension is called so that those UIDefaults are there ready for us to use.
0079:         * This is how added support to GTK L&F and Synthethica L&F.
0080:         * <p/>
0081:         * {@link #installJideExtension()} method will only add the additional UIDefaults to current ClassLoader. If you have several class loaders in your system,
0082:         * you probably should tell the UIManager to use the class loader that called <code>installJideExtension</code>. Otherwise, you might some unexpected errors.
0083:         * Here is how to specify the class loaders.
0084:         * <code><pre>
0085:         * UIManager.put("ClassLoader", currentClass.getClassLoader()); // currentClass is the class where the code is.
0086:         * LookAndFeelFactory.installDefaultLookAndFeelAndExtension(); // or installJideExtension()
0087:         * </pre></code>
0088:         */
0089:        public class LookAndFeelFactory implements  ProductNames {
0090:
0091:            /**
0092:             * Class name of Windows L&F provided in Sun JDK.
0093:             */
0094:            public static final String WINDOWS_LNF = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
0095:
0096:            /**
0097:             * Class name of Metal L&F provided in Sun JDK.
0098:             */
0099:            public static final String METAL_LNF = "javax.swing.plaf.metal.MetalLookAndFeel";
0100:
0101:            /**
0102:             * Class name of Aqua L&F provided in Apple Mac OSX JDK.
0103:             */
0104:            public static final String AQUA_LNF = "apple.laf.AquaLookAndFeel";
0105:
0106:            /**
0107:             * Class name of Quaqua L&F.
0108:             */
0109:            public static final String QUAQUA_LNF = "ch.randelshofer.quaqua.QuaquaLookAndFeel";
0110:
0111:            /**
0112:             * Class name of Quaqua Alloy L&F.
0113:             */
0114:            public static final String ALLOY_LNF = "com.incors.plaf.alloy.AlloyLookAndFeel";
0115:
0116:            /**
0117:             * Class name of Synthetica L&F.
0118:             */
0119:            public static final String SYNTHETICA_LNF = "de.javasoft.plaf.synthetica.SyntheticaStandardLookAndFeel";
0120:
0121:            private static final String SYNTHETICA_LNF_PREFIX = "de.javasoft.plaf.synthetica.Synthetica";
0122:
0123:            /**
0124:             * Class name of Plastic3D L&F before JGoodies Look 1.3 release.
0125:             */
0126:            public static final String PLASTIC3D_LNF = "com.jgoodies.plaf.plastic.Plastic3DLookAndFeel";
0127:
0128:            /**
0129:             * Class name of Plastic3D L&F after JGoodies Look 1.3 release.
0130:             */
0131:            public static final String PLASTIC3D_LNF_1_3 = "com.jgoodies.looks.plastic.Plastic3DLookAndFeel";
0132:
0133:            /**
0134:             * Class name of PlasticXP L&F.
0135:             */
0136:            public static final String PLASTICXP_LNF = "com.jgoodies.looks.plastic.PlasticXPLookAndFeel";
0137:
0138:            /**
0139:             * Class name of Tonic L&F.
0140:             */
0141:            public static final String TONIC_LNF = "com.digitprop.tonic.TonicLookAndFeel";
0142:
0143:            /**
0144:             * Class name of A03 L&F.
0145:             */
0146:            public static final String A03_LNF = "apprising.api.swing.plaf.a03.A03LookAndFeel";
0147:
0148:            /**
0149:             * Class name of Pgs L&F.
0150:             */
0151:            public static final String PGS_LNF = "com.pagosoft.plaf.PgsLookAndFeel";
0152:
0153:            /**
0154:             * Class name of GTK L&F provided by Sun JDK.
0155:             */
0156:            public static final String GTK_LNF = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
0157:
0158:            /**
0159:             * A style that you can use with {@link #installJideExtension(int)} method. This style is the same as VSNET_STYLE
0160:             * except it doesn't have menu related UIDefaults. You can only use this style if you didn't use any component from JIDE Action Framework.
0161:             * <p/>
0162:             *
0163:             * @see #VSNET_STYLE
0164:             */
0165:            public final static int VSNET_STYLE_WITHOUT_MENU = 0;
0166:
0167:            /**
0168:             * A style that you can use with {@link #installJideExtension(int)} method.
0169:             * This style mimics the visual style of Microsoft Visuasl Studio .NET for the toolbars, menus and dockable windows.
0170:             * <p/>
0171:             * Vsnet style is a very simple style with no gradient. Although it works on almost all L&Fs in any operating systems, it looks the best
0172:             * on Windows 2000 or 98, or on Windows XP when XP theme is not on. If XP theme is on, we suggest you use Office2003 style or Xerto style.
0173:             * Since the style is so simple, it works with a lot of the 3rd party L&F such as Tonic, Pgs, Alloy etc without causing too much noice.
0174:             * That's why this is also the default style for any L&Fs we don't recognize when you call {@link #installJideExtension()},
0175:             * the one with out style parameter. If you would like another style to be used as the default style, you can call {@link #setDefaultStyle(int)} method.
0176:             * <p/>
0177:             * Here is the code to set to Windows L&F with Vsnet style extension.
0178:             * <code><pre>
0179:             * UIManager.setLookAndFeel(WindowsLookAndFeel.class.getName()); // you need to catch the exceptions on this call.
0180:             * LookAndFeelFactory.installJideExtension(LookAndFeelFactory.VSNET_STYLE);
0181:             * </pre></code>
0182:             * There is a special system property "shading theme" you can use. If you turn it on using the code below, you will see
0183:             * a graident on dockable frame's title pane and rounded corner and graident on the tabs of JideTabbedPane.
0184:             * So if the L&F you are using uses graident, you can set this property to true to match with your L&F. For example, if you use
0185:             * Plastic3D L&F, turning this property on will look better.
0186:             * <code><pre>
0187:             * System.setProperty("shadingtheme", "true");
0188:             * </pre></code>
0189:             */
0190:            public final static int VSNET_STYLE = 1;
0191:
0192:            /**
0193:             * A style that you can use with {@link #installJideExtension(int)} method.
0194:             * This style mimics the visual style of Eclipse 2.x for the toolbars, menus and dockable windows.
0195:             * <p/>
0196:             * Eclipse style works for almost all L&Fs and on any operating systems, although it looks the best on Windows.
0197:             * For any other operating systems we suggest you to use XERTO_STYLE or VSNET_STYLE.
0198:             * <p/>
0199:             * Here is the code to set to any L&F with Eclipse style extension.
0200:             * <code><pre>
0201:             * UIManager.setLookAndFeel(AnyLookAndFeel.class.getName()); // you need to catch the exceptions on this call.
0202:             * LookAndFeelFactory.installJideExtension(LookAndFeelFactory.ECLIPSE_STYLE);
0203:             * </pre></code>
0204:             */
0205:            public final static int ECLIPSE_STYLE = 2;
0206:
0207:            /**
0208:             * A style that you can use with {@link #installJideExtension(int)} method.
0209:             * This style mimics the visual style of Microsoft Office2003 for the toolbars, menus and dockable windows.
0210:             * <p/>
0211:             * Office2003 style looks great on Windows XP when Windows or Windows XP L&F from Sun JDK is used. It replicated
0212:             * the exact same style as Microsoft Office 2003, to give your end user a familar visual style.
0213:             * <p/>
0214:             * Here is the code to set to Windows L&F with Office2003 style extension.
0215:             * <code><pre>
0216:             * UIManager.setLookAndFeel(WindowsLookAndFeel.class.getName()); // you need to catch the exceptions on this call.
0217:             * LookAndFeelFactory.installJideExtension(LookAndFeelFactory.OFFICE2003_STYLE);
0218:             * </pre></code>
0219:             * It works either on any other Windows such as Winodows 2000, Windows 98 etc.
0220:             * If you are on Windows XP, Office2003 style will change theme based on the theme setting in Windows Display Property.
0221:             * But if you are not on XP, Office2003 style will use the default gray theme only. You can force to change it using
0222:             * {@link Office2003Painter#setColorName(String)} method, but it won't look good as other non-JIDE components won't have
0223:             * the matching theme.
0224:             * <p/>
0225:             * Office2003 style doesn't work on any operating systems other than Windows mainly because the design of Office2003 style is so
0226:             * centric to Windows that it doesn't look good on other operating systems.
0227:             */
0228:            public final static int OFFICE2003_STYLE = 3;
0229:
0230:            /**
0231:             * A style that you can use with {@link #installJideExtension(int)} method.
0232:             * This style is created by Xerto (http://www.xerto.com) which is used in their Imagery product.
0233:             * <p/>
0234:             * Xerto style looks great on Windows XP when Windows XP L&F from Sun JDK is used.
0235:             * <p/>
0236:             * Here is the code to set to Windows L&F with Xerto style extension.
0237:             * <code><pre>
0238:             * UIManager.setLookAndFeel(WindowsLookAndFeel.class.getName()); // you need to catch the exceptions on this call.
0239:             * LookAndFeelFactory.installJideExtension(LookAndFeelFactory.XERTO_STYLE);
0240:             * </pre></code>
0241:             * Although it looks the best on Windows, Xerto style also supports Linux or Solaris if you use any L&Fs based
0242:             * on Metal L&F or Synth L&F. For example, we recommend you to use Xerto style as default if you use SyntheticaL&F, a L&F based on Synth.
0243:             * To use it, you bascially replace WindowsLookAndFeel to the L&F you want to use in setLookAndFeel line above.
0244:             */
0245:            public final static int XERTO_STYLE = 4;
0246:
0247:            /**
0248:             * A style that you can use with {@link #installJideExtension(int)} method. This style is the same as XERTO_STYLE
0249:             * except it doesn't have menu related UIDefaults. You can only use this style if you didn't use any component from JIDE Action Framework.
0250:             * Please note, we only use menu extension for Xerto style when the underlying L&F is Windows L&F. If you are using L&F such as Metal or other 3rd party L&F based on Metal,
0251:             * XERTO_STYLE_WITHOUT_MENU will be used even you use XERTO_STYLE when calling to installJideExtension().
0252:             * <p/>
0253:             *
0254:             * @see #XERTO_STYLE
0255:             */
0256:            public final static int XERTO_STYLE_WITHOUT_MENU = 6;
0257:
0258:            /**
0259:             * A style that you can use with {@link #installJideExtension(int)} method.
0260:             * This style mimics the visual style of Eclipse 3.x for the toolbars, menus and dockable windows.
0261:             * <p/>
0262:             * Eclipse 3x style works for almost all L&Fs and on any operating systems, although it looks the best on Windows.
0263:             * For any other OS's we suggest you to use XERTO_STYLE or VSNET_STYLE.
0264:             * <code><pre>
0265:             * UIManager.setLookAndFeel(AnyLookAndFeel.class.getName()); // you need to catch the exceptions on this call.
0266:             * LookAndFeelFactory.installJideExtension(LookAndFeelFactory.ECLIPSE3X_STYLE);
0267:             * </pre></code>
0268:             */
0269:            public final static int ECLIPSE3X_STYLE = 5;
0270:
0271:            private static int _style = -1;
0272:            private static int _defaultStyle = -1;
0273:            private static LookAndFeel _lookAndFeel;
0274:
0275:            /**
0276:             * If installJideExtension is called, it will put an entry on UIDefaults table. UIManagerLookup.getBoolean(JIDE_EXTENSION_INSTALLLED) will
0277:             * return true. You can also use {@link #isJideExtensionInstalled()} to check the value instead of using UIManagerLookup.getBoolean(JIDE_EXTENSION_INSTALLLED).
0278:             */
0279:            public final static String JIDE_EXTENSION_INSTALLLED = "jidesoft.extendsionInstalled";
0280:
0281:            /**
0282:             * If installJideExtension is called, a JIDE style will be installed on UIDefaults table. If so, UIManagerLookup.getInt(JIDE_STYLE_INSTALLED)
0283:             * will return you the style that is installed. For example, if the value is 1, it means VSNET_STYLE is installed because 1 is the value of VSNET_STYLE.
0284:             */
0285:            public final static String JIDE_STYLE_INSTALLED = "jidesoft.extendsionStyle";
0286:
0287:            /**
0288:             * @deprecated JIDE_STYLE name is confusing because people think this is a special style such as VSNET_STYLE or OFFICE2003_STYLE. So we decided
0289:             *             to rename it to  {@link #JIDE_STYLE_INSTALLED}. If you used this before, please change it to use JIDE_STYLE_INSTALLED instead.
0290:             */
0291:            public final static String JIDE_STYLE = JIDE_STYLE_INSTALLED;
0292:
0293:            /**
0294:             * An interface to make the customization of UIDefaults easier. This customizer will be called after installJideExtension()
0295:             * is called. So if you want to further customize UIDefault, you can use this customzier to do it.
0296:             */
0297:            public static interface UIDefaultsCustomizer {
0298:                void customize(UIDefaults defaults);
0299:            }
0300:
0301:            /**
0302:             * An interface to make the initialization of UIDefaults easier. This initializer will be called before installJideExtension()
0303:             * is called. So if you want to initialize UIDefault before installJideExtension is called, you can use this initializer to do it.
0304:             */
0305:            public static interface UIDefaultsInitializer {
0306:                void initialize(UIDefaults defaults);
0307:            }
0308:
0309:            private static List<UIDefaultsCustomizer> _uiDefaultsCustomizers = new Vector();
0310:            private static List<UIDefaultsInitializer> _uiDefaultsInitializers = new Vector();
0311:
0312:            protected LookAndFeelFactory() {
0313:            }
0314:
0315:            /**
0316:             * Gets the default style. If you never set default style before, it will return OFFICE2003_STYLE
0317:             * if you are on Windows XP, L&F is instance of Windows L&F and XP theme is on. Otherwise, it will return VSNET_STYLE.
0318:             * If you set default style before, it will return whatever style you set.
0319:             *
0320:             * @return the default style.
0321:             */
0322:            public static int getDefaultStyle() {
0323:                if (_defaultStyle == -1) {
0324:                    int suggestedStyle;
0325:                    try {
0326:                        if (XPUtils.isXPStyleOn()
0327:                                && UIManager.getLookAndFeel() instanceof  WindowsLookAndFeel) {
0328:                            suggestedStyle = OFFICE2003_STYLE;
0329:                        } else {
0330:                            suggestedStyle = VSNET_STYLE;
0331:                        }
0332:                    } catch (UnsupportedOperationException e) {
0333:                        suggestedStyle = VSNET_STYLE;
0334:                    }
0335:                    return suggestedStyle;
0336:                }
0337:                return _defaultStyle;
0338:            }
0339:
0340:            /**
0341:             * Sets the default style. If you call this method to set a default style, {@link #installJideExtension()} will
0342:             * use it as the default style.
0343:             *
0344:             * @param defaultStyle the default style.
0345:             */
0346:            public static void setDefaultStyle(int defaultStyle) {
0347:                _defaultStyle = defaultStyle;
0348:            }
0349:
0350:            /**
0351:             * Adds additional UIDefaults JIDE needed to UIDefault table. You must call this method
0352:             * everytime switching look and feel. And callupdateComponentTreeUI() in corresponding DockingManager
0353:             * or DockableBarManager after this call.
0354:             * <pre><code>
0355:             *  try {
0356:             *      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
0357:             *  }
0358:             *  catch (ClassNotFoundException e) {
0359:             *     e.printStackTrace();
0360:             *  }
0361:             *  catch (InstantiationException e) {
0362:             *     e.printStackTrace();
0363:             *  }
0364:             *  catch (IllegalAccessException e) {
0365:             *      e.printStackTrace();
0366:             *  }
0367:             *  catch (UnsupportedLookAndFeelException e) {
0368:             *      e.printStackTrace();
0369:             *  }
0370:             * <p/>
0371:             *  // to add attitional UIDefault for JIDE components
0372:             *  LookAndFeelFactory.installJideExtension(); // use default style VSNET_STYLE. You can change to a different style
0373:             * using setDefaultStyle(int style) and then call this method. Or simply call installJideExtension(style).
0374:             * <p/>
0375:             *  // call updateComponentTreeUI
0376:             *  frame.getDockableBarManager().updateComponentTreeUI();
0377:             *  frame.getDockingManager().updateComponentTreeUI();
0378:             * </code></pre>
0379:             */
0380:            public static void installJideExtension() {
0381:                installJideExtension(getDefaultStyle());
0382:            }
0383:
0384:            /**
0385:             * Add additional UIDefaults JIDE needed to UIDefaults table. You must call this method
0386:             * everytime switching look and feel. And call updateComponentTreeUI() in corresponding DockingManager
0387:             * or DockableBarManager after this call.
0388:             * <pre><code>
0389:             *  try {
0390:             *      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
0391:             *  }
0392:             *  catch (ClassNotFoundException e) {
0393:             *     e.printStackTrace();
0394:             *  }
0395:             *  catch (InstantiationException e) {
0396:             *     e.printStackTrace();
0397:             *  }
0398:             *  catch (IllegalAccessException e) {
0399:             *      e.printStackTrace();
0400:             *  }
0401:             *  catch (UnsupportedLookAndFeelException e) {
0402:             *      e.printStackTrace();
0403:             *  }
0404:             * <p/>
0405:             *  // to add attitional UIDefault for JIDE components
0406:             *  LookAndFeelFactory.installJideExtension(LookAndFeelFactory.OFFICE2003_STYLE);
0407:             * <p/>
0408:             *  // call updateComponentTreeUI
0409:             *  frame.getDockableBarManager().updateComponentTreeUI();
0410:             *  frame.getDockingManager().updateComponentTreeUI();
0411:             * </code></pre>
0412:             *
0413:             * @param style the style of the extension.
0414:             */
0415:            public static void installJideExtension(int style) {
0416:                installJideExtension(UIManager.getLookAndFeelDefaults(),
0417:                        UIManager.getLookAndFeel(), style);
0418:            }
0419:
0420:            /**
0421:             * Checks if JIDE extension is installed. Please note, UIManager.setLookAndFeel() method will
0422:             * overwrite the whole UIDefaults table. So even you called {@link #installJideExtension()} method before,
0423:             * UIManager.setLookAndFeel() method make isJideExtensionInstalled returning false.
0424:             *
0425:             * @return true if installed.
0426:             */
0427:            public static boolean isJideExtensionInstalled() {
0428:                return UIDefaultsLookup.getBoolean(JIDE_EXTENSION_INSTALLLED);
0429:            }
0430:
0431:            /**
0432:             * Installs the UIDefault needed by JIDE component to the uiDefaults table passed in.
0433:             *
0434:             * @param uiDefaults the UIDefault tables where JIDE UIDefaults will be installed.
0435:             * @param lnf        the LookAndFeel. This may have an effect on which set of JIDE UIDefaults we will install.
0436:             * @param style      the style of the JIDE UIDefaults.
0437:             */
0438:            public static void installJideExtension(UIDefaults uiDefaults,
0439:                    LookAndFeel lnf, int style) {
0440:                if (isJideExtensionInstalled() && _style == style
0441:                        && _lookAndFeel == lnf) {
0442:                    return;
0443:                }
0444:
0445:                _style = style;
0446:                uiDefaults.put(JIDE_STYLE_INSTALLED, _style);
0447:
0448:                _lookAndFeel = lnf;
0449:
0450:                UIDefaultsInitializer[] initializers = getUIDefaultsInitializers();
0451:                for (UIDefaultsInitializer initializer : initializers) {
0452:                    if (initializer != null) {
0453:                        initializer.initialize(uiDefaults);
0454:                    }
0455:                }
0456:
0457:                // For Alloy
0458:                /*        if (lnf.getClass().getName().equals(ALLOY_LNF) && isAlloyLnfInstalled()) {
0459:                 Object progressBarUI = uiDefaults.get("ProgressBarUI");
0460:                 VsnetMetalUtils.initClassDefaults(uiDefaults);
0461:                 VsnetMetalUtils.initComponentDefaults(uiDefaults);
0462:                 uiDefaults.put("ProgressBarUI", progressBarUI);
0463:                 uiDefaults.put("DockableFrameUI", "com.jidesoft.plaf.vsnet.VsnetDockableFrameUI");
0464:                 uiDefaults.put("DockableFrameTitlePane.hideIcon", IconsFactory.getIcon(null, titleButtonImage, 0, 0, titleButtonSize, titleButtonSize));
0465:                 uiDefaults.put("DockableFrameTitlePane.unfloatIcon", IconsFactory.getIcon(null, titleButtonImage, 0, titleButtonSize, titleButtonSize, titleButtonSize));
0466:                 uiDefaults.put("DockableFrameTitlePane.floatIcon", IconsFactory.getIcon(null, titleButtonImage, 0, 2 * titleButtonSize, titleButtonSize, titleButtonSize));
0467:                 uiDefaults.put("DockableFrameTitlePane.autohideIcon", IconsFactory.getIcon(null, titleButtonImage, 0, 3 * titleButtonSize, titleButtonSize, titleButtonSize));
0468:                 uiDefaults.put("DockableFrameTitlePane.stopAutohideIcon", IconsFactory.getIcon(null, titleButtonImage, 0, 4 * titleButtonSize, titleButtonSize, titleButtonSize));
0469:                 uiDefaults.put("DockableFrameTitlePane.hideAutohideIcon", IconsFactory.getIcon(null, titleButtonImage, 0, 5 * titleButtonSize, titleButtonSize, titleButtonSize));
0470:                 uiDefaults.put("DockableFrameTitlePane.maximizeIcon", IconsFactory.getIcon(null, titleButtonImage, 0, 6 * titleButtonSize, titleButtonSize, titleButtonSize));
0471:                 uiDefaults.put("DockableFrameTitlePane.restoreIcon", IconsFactory.getIcon(null, titleButtonImage, 0, 7 * titleButtonSize, titleButtonSize, titleButtonSize));
0472:                 uiDefaults.put("DockableFrameTitlePane.buttonGap", new Integer(4)); // gap between buttons
0473:                 }
0474:                 else */
0475:                if ((lnf.getClass().getName().equals(ALLOY_LNF) && isAlloyLnfInstalled())
0476:                        || (lnf.getClass().getName().equals(PLASTIC3D_LNF) && isPlastic3DLnfInstalled())
0477:                        || (lnf.getClass().getName().equals(PLASTIC3D_LNF_1_3) && isPlastic3D13LnfInstalled())
0478:                        || (lnf.getClass().getName().equals(PLASTICXP_LNF) && isPlasticXPLnfInstalled())
0479:                        || (lnf.getClass().getName().equals(PGS_LNF) && isPgsLnfInstalled())
0480:                        || (lnf.getClass().getName().equals(TONIC_LNF) && isTonicLnfInstalled())) {
0481:                    switch (style) {
0482:                    case OFFICE2003_STYLE:
0483:                        VsnetWindowsUtils.initComponentDefaults(uiDefaults);
0484:                        Office2003WindowsUtils
0485:                                .initComponentDefaults(uiDefaults);
0486:                        Office2003WindowsUtils.initClassDefaults(uiDefaults,
0487:                                false);
0488:                        break;
0489:                    case VSNET_STYLE:
0490:                    case VSNET_STYLE_WITHOUT_MENU:
0491:                        VsnetMetalUtils.initComponentDefaults(uiDefaults);
0492:                        VsnetMetalUtils.initClassDefaults(uiDefaults);
0493:
0494:                        Painter gripperPainter = new Painter() {
0495:                            public void paint(JComponent c, Graphics g,
0496:                                    Rectangle rect, int orientation, int state) {
0497:                                Office2003Painter.getInstance().paintGripper(c,
0498:                                        g, rect, orientation, state);
0499:                            }
0500:                        };
0501:
0502:                        // set all grippers to Office2003 style gripper
0503:                        uiDefaults.put("Gripper.painter", gripperPainter);
0504:                        uiDefaults.put("JideTabbedPane.gripperPainter",
0505:                                gripperPainter);
0506:                        uiDefaults.put("JideTabbedPane.defaultTabShape",
0507:                                JideTabbedPane.SHAPE_OFFICE2003);
0508:                        uiDefaults.put("JideTabbedPane.defaultTabColorTheme",
0509:                                JideTabbedPane.COLOR_THEME_WINXP);
0510:                        uiDefaults.put(
0511:                                "JideTabbedPane.selectedTabTextForeground",
0512:                                UIDefaultsLookup.getColor("controlText"));
0513:                        uiDefaults.put(
0514:                                "JideTabbedPane.unselectedTabTextForeground",
0515:                                UIDefaultsLookup.getColor("controlText"));
0516:                        uiDefaults.put("JideTabbedPane.foreground",
0517:                                UIDefaultsLookup.getColor("controlText"));
0518:                        uiDefaults.put("JideTabbedPane.light", UIDefaultsLookup
0519:                                .getColor("control"));
0520:                        uiDefaults.put("JideSplitPaneDivider.gripperPainter",
0521:                                gripperPainter);
0522:
0523:                        int products = LookAndFeelFactory.getProductsUsed();
0524:                        if ((products & PRODUCT_DOCK) != 0) {
0525:                            ImageIcon titleButtonImage = IconsFactory
0526:                                    .getImageIcon(VsnetWindowsUtils.class,
0527:                                            "icons/title_buttons_windows.gif"); // 10 x 10 x 8
0528:                            final int titleButtonSize = 10;
0529:
0530:                            uiDefaults
0531:                                    .put("DockableFrameUI",
0532:                                            "com.jidesoft.plaf.vsnet.VsnetDockableFrameUI");
0533:                            uiDefaults.put("DockableFrameTitlePane.hideIcon",
0534:                                    IconsFactory.getIcon(null,
0535:                                            titleButtonImage, 0, 0,
0536:                                            titleButtonSize, titleButtonSize));
0537:                            uiDefaults.put(
0538:                                    "DockableFrameTitlePane.unfloatIcon",
0539:                                    IconsFactory.getIcon(null,
0540:                                            titleButtonImage, 0,
0541:                                            titleButtonSize, titleButtonSize,
0542:                                            titleButtonSize));
0543:                            uiDefaults.put("DockableFrameTitlePane.floatIcon",
0544:                                    IconsFactory.getIcon(null,
0545:                                            titleButtonImage, 0,
0546:                                            2 * titleButtonSize,
0547:                                            titleButtonSize, titleButtonSize));
0548:                            uiDefaults.put(
0549:                                    "DockableFrameTitlePane.autohideIcon",
0550:                                    IconsFactory.getIcon(null,
0551:                                            titleButtonImage, 0,
0552:                                            3 * titleButtonSize,
0553:                                            titleButtonSize, titleButtonSize));
0554:                            uiDefaults.put(
0555:                                    "DockableFrameTitlePane.stopAutohideIcon",
0556:                                    IconsFactory.getIcon(null,
0557:                                            titleButtonImage, 0,
0558:                                            4 * titleButtonSize,
0559:                                            titleButtonSize, titleButtonSize));
0560:                            uiDefaults.put(
0561:                                    "DockableFrameTitlePane.hideAutohideIcon",
0562:                                    IconsFactory.getIcon(null,
0563:                                            titleButtonImage, 0,
0564:                                            5 * titleButtonSize,
0565:                                            titleButtonSize, titleButtonSize));
0566:                            uiDefaults.put(
0567:                                    "DockableFrameTitlePane.maximizeIcon",
0568:                                    IconsFactory.getIcon(null,
0569:                                            titleButtonImage, 0,
0570:                                            6 * titleButtonSize,
0571:                                            titleButtonSize, titleButtonSize));
0572:                            uiDefaults.put(
0573:                                    "DockableFrameTitlePane.restoreIcon",
0574:                                    IconsFactory.getIcon(null,
0575:                                            titleButtonImage, 0,
0576:                                            7 * titleButtonSize,
0577:                                            titleButtonSize, titleButtonSize));
0578:                            uiDefaults.put("DockableFrameTitlePane.buttonGap",
0579:                                    4); // gap between buttons
0580:                            uiDefaults.put("DockableFrame.titleBorder",
0581:                                    new BorderUIResource(BorderFactory
0582:                                            .createEmptyBorder(1, 0, 3, 0)));
0583:                            uiDefaults.put("DockableFrame.border",
0584:                                    new BorderUIResource(BorderFactory
0585:                                            .createEmptyBorder(2, 0, 0, 0)));
0586:                            uiDefaults.put(
0587:                                    "DockableFrameTitlePane.gripperPainter",
0588:                                    gripperPainter);
0589:                        }
0590:                        break;
0591:                    case ECLIPSE_STYLE:
0592:                        EclipseMetalUtils.initComponentDefaults(uiDefaults);
0593:                        EclipseMetalUtils.initClassDefaults(uiDefaults);
0594:                        break;
0595:                    case ECLIPSE3X_STYLE:
0596:                        Eclipse3xMetalUtils.initComponentDefaults(uiDefaults);
0597:                        Eclipse3xMetalUtils.initClassDefaults(uiDefaults);
0598:                        break;
0599:                    case XERTO_STYLE:
0600:                    case XERTO_STYLE_WITHOUT_MENU:
0601:                        XertoMetalUtils.initComponentDefaults(uiDefaults);
0602:                        XertoMetalUtils.initClassDefaults(uiDefaults);
0603:                        break;
0604:                    }
0605:                } else if (lnf.getClass().equals(
0606:                        MetalLookAndFeel.class.getName())) {
0607:                    switch (style) {
0608:                    case OFFICE2003_STYLE:
0609:                    case VSNET_STYLE:
0610:                        VsnetMetalUtils.initComponentDefaults(uiDefaults);
0611:                        VsnetMetalUtils.initClassDefaultsWithMenu(uiDefaults);
0612:                        break;
0613:                    case ECLIPSE_STYLE:
0614:                        EclipseMetalUtils.initComponentDefaults(uiDefaults);
0615:                        EclipseMetalUtils.initClassDefaults(uiDefaults);
0616:                        break;
0617:                    case ECLIPSE3X_STYLE:
0618:                        Eclipse3xMetalUtils.initComponentDefaults(uiDefaults);
0619:                        Eclipse3xMetalUtils.initClassDefaults(uiDefaults);
0620:                        break;
0621:                    case VSNET_STYLE_WITHOUT_MENU:
0622:                        VsnetMetalUtils.initComponentDefaults(uiDefaults);
0623:                        VsnetMetalUtils.initClassDefaults(uiDefaults);
0624:                        break;
0625:                    case XERTO_STYLE:
0626:                    case XERTO_STYLE_WITHOUT_MENU:
0627:                        XertoMetalUtils.initComponentDefaults(uiDefaults);
0628:                        XertoMetalUtils.initClassDefaults(uiDefaults);
0629:                        break;
0630:                    default:
0631:                    }
0632:                } else if (lnf instanceof  MetalLookAndFeel) {
0633:                    switch (style) {
0634:                    case OFFICE2003_STYLE:
0635:                        VsnetMetalUtils.initComponentDefaults(uiDefaults);
0636:                        VsnetMetalUtils.initClassDefaults(uiDefaults);
0637:                        break;
0638:                    case ECLIPSE_STYLE:
0639:                        EclipseMetalUtils.initClassDefaults(uiDefaults);
0640:                        EclipseMetalUtils.initComponentDefaults(uiDefaults);
0641:                        break;
0642:                    case ECLIPSE3X_STYLE:
0643:                        Eclipse3xMetalUtils.initClassDefaults(uiDefaults);
0644:                        Eclipse3xMetalUtils.initComponentDefaults(uiDefaults);
0645:                        break;
0646:                    case VSNET_STYLE:
0647:                    case VSNET_STYLE_WITHOUT_MENU:
0648:                        VsnetMetalUtils.initComponentDefaults(uiDefaults);
0649:                        VsnetMetalUtils.initClassDefaults(uiDefaults);
0650:                        break;
0651:                    case XERTO_STYLE:
0652:                        XertoMetalUtils.initComponentDefaults(uiDefaults);
0653:                        XertoMetalUtils.initClassDefaults(uiDefaults);
0654:                        break;
0655:                    default:
0656:                    }
0657:                } else if (lnf instanceof  WindowsLookAndFeel) {
0658:                    switch (style) {
0659:                    case OFFICE2003_STYLE:
0660:                        VsnetWindowsUtils
0661:                                .initComponentDefaultsWithMenu(uiDefaults);
0662:                        VsnetWindowsUtils.initClassDefaultsWithMenu(uiDefaults);
0663:                        Office2003WindowsUtils.initClassDefaults(uiDefaults);
0664:                        Office2003WindowsUtils
0665:                                .initComponentDefaults(uiDefaults);
0666:                        break;
0667:                    case ECLIPSE_STYLE:
0668:                        EclipseWindowsUtils
0669:                                .initClassDefaultsWithMenu(uiDefaults);
0670:                        EclipseWindowsUtils
0671:                                .initComponentDefaultsWithMenu(uiDefaults);
0672:                        break;
0673:                    case ECLIPSE3X_STYLE:
0674:                        Eclipse3xWindowsUtils
0675:                                .initClassDefaultsWithMenu(uiDefaults);
0676:                        Eclipse3xWindowsUtils
0677:                                .initComponentDefaultsWithMenu(uiDefaults);
0678:                        break;
0679:                    case VSNET_STYLE:
0680:                        VsnetWindowsUtils
0681:                                .initComponentDefaultsWithMenu(uiDefaults);
0682:                        VsnetWindowsUtils.initClassDefaultsWithMenu(uiDefaults);
0683:                        break;
0684:                    case VSNET_STYLE_WITHOUT_MENU:
0685:                        VsnetWindowsUtils.initComponentDefaults(uiDefaults);
0686:                        VsnetWindowsUtils.initClassDefaults(uiDefaults);
0687:                        break;
0688:                    case XERTO_STYLE:
0689:                        XertoWindowsUtils
0690:                                .initComponentDefaultsWithMenu(uiDefaults);
0691:                        XertoWindowsUtils.initClassDefaultsWithMenu(uiDefaults);
0692:                        break;
0693:                    case XERTO_STYLE_WITHOUT_MENU:
0694:                        XertoWindowsUtils.initComponentDefaults(uiDefaults);
0695:                        XertoWindowsUtils.initClassDefaults(uiDefaults);
0696:                        break;
0697:                    default:
0698:                    }
0699:                }
0700:                // For Mac only
0701:                else if ((lnf.getClass().getName().equals(AQUA_LNF) && isAquaLnfInstalled())
0702:                        || (lnf.getClass().getName().equals(QUAQUA_LNF) && isQuaquaLnfInstalled())) {
0703:                    // use reflection since we don't deliver source code of AquaJideUtils as most users don't compile it on Mac OS X
0704:                    try {
0705:                        Class<?> aquaJideUtils = getValidClassLoader()
0706:                                .loadClass(
0707:                                        "com.jidesoft.plaf.aqua.AquaJideUtils");
0708:                        aquaJideUtils.getMethod("initComponentDefaults",
0709:                                new Class[] { UIDefaults.class }).invoke(null,
0710:                                uiDefaults);
0711:                        aquaJideUtils.getMethod("initClassDefaults",
0712:                                new Class[] { UIDefaults.class }).invoke(null,
0713:                                uiDefaults);
0714:                    } catch (ClassNotFoundException e) {
0715:                        throw new RuntimeException(e);
0716:                    } catch (IllegalAccessException e) {
0717:                        throw new RuntimeException(e);
0718:                    } catch (IllegalArgumentException e) {
0719:                        throw new RuntimeException(e);
0720:                    } catch (InvocationTargetException e) {
0721:                        JideSwingUtilities.throwInvocationTargetException(e);
0722:                    } catch (NoSuchMethodException e) {
0723:                        throw new RuntimeException(e);
0724:                    } catch (SecurityException e) {
0725:                        throw new RuntimeException(e);
0726:                    }
0727:                } else {
0728:                    // built in initializer
0729:                    if (lnf.getClass().getName().equals(GTK_LNF)
0730:                            && isGTKLnfInstalled()) {
0731:                        new GTKInitializer().initialize(uiDefaults);
0732:                    } else if (lnf.getClass().getName().startsWith(
0733:                            SYNTHETICA_LNF_PREFIX)
0734:                            && isSyntheticaLnfInstalled()) {
0735:                        new SyntheticaInitializer().initialize(uiDefaults);
0736:                    }
0737:
0738:                    switch (style) {
0739:                    case OFFICE2003_STYLE:
0740:                        if (SystemInfo.isWindows()) {
0741:                            VsnetWindowsUtils
0742:                                    .initComponentDefaultsWithMenu(uiDefaults);
0743:                            Office2003WindowsUtils
0744:                                    .initComponentDefaults(uiDefaults);
0745:                            Office2003WindowsUtils
0746:                                    .initClassDefaults(uiDefaults);
0747:                        } else {
0748:                            VsnetMetalUtils.initComponentDefaults(uiDefaults);
0749:                            VsnetMetalUtils.initClassDefaults(uiDefaults);
0750:                        }
0751:                        break;
0752:                    case ECLIPSE_STYLE:
0753:                        if (SystemInfo.isWindows()) {
0754:                            EclipseWindowsUtils
0755:                                    .initClassDefaultsWithMenu(uiDefaults);
0756:                            EclipseWindowsUtils
0757:                                    .initComponentDefaultsWithMenu(uiDefaults);
0758:                        } else {
0759:                            EclipseMetalUtils.initClassDefaults(uiDefaults);
0760:                            EclipseMetalUtils.initComponentDefaults(uiDefaults);
0761:                        }
0762:                        break;
0763:                    case ECLIPSE3X_STYLE:
0764:                        if (SystemInfo.isWindows()) {
0765:                            Eclipse3xWindowsUtils
0766:                                    .initClassDefaultsWithMenu(uiDefaults);
0767:                            Eclipse3xWindowsUtils
0768:                                    .initComponentDefaultsWithMenu(uiDefaults);
0769:                        } else {
0770:                            Eclipse3xMetalUtils.initClassDefaults(uiDefaults);
0771:                            Eclipse3xMetalUtils
0772:                                    .initComponentDefaults(uiDefaults);
0773:                        }
0774:                        break;
0775:                    case VSNET_STYLE:
0776:                        if (SystemInfo.isWindows()) {
0777:                            VsnetWindowsUtils
0778:                                    .initClassDefaultsWithMenu(uiDefaults);
0779:                            VsnetWindowsUtils
0780:                                    .initComponentDefaultsWithMenu(uiDefaults);
0781:                        } else {
0782:                            VsnetMetalUtils.initComponentDefaults(uiDefaults);
0783:                            VsnetMetalUtils.initClassDefaults(uiDefaults);
0784:                        }
0785:                        break;
0786:                    case VSNET_STYLE_WITHOUT_MENU:
0787:                        if (SystemInfo.isWindows()) {
0788:                            VsnetWindowsUtils.initClassDefaults(uiDefaults);
0789:                            VsnetWindowsUtils.initComponentDefaults(uiDefaults);
0790:                        } else {
0791:                            VsnetMetalUtils.initComponentDefaults(uiDefaults);
0792:                            VsnetMetalUtils.initClassDefaults(uiDefaults);
0793:                        }
0794:                        break;
0795:                    case XERTO_STYLE:
0796:                        if (SystemInfo.isWindows()) {
0797:                            XertoWindowsUtils
0798:                                    .initClassDefaultsWithMenu(uiDefaults);
0799:                            XertoWindowsUtils
0800:                                    .initComponentDefaultsWithMenu(uiDefaults);
0801:                        } else {
0802:                            XertoMetalUtils.initComponentDefaults(uiDefaults);
0803:                            XertoMetalUtils.initClassDefaults(uiDefaults);
0804:                        }
0805:                        break;
0806:                    case XERTO_STYLE_WITHOUT_MENU:
0807:                        if (SystemInfo.isWindows()) {
0808:                            XertoWindowsUtils.initClassDefaults(uiDefaults);
0809:                            XertoWindowsUtils.initComponentDefaults(uiDefaults);
0810:                        } else {
0811:                            XertoMetalUtils.initComponentDefaults(uiDefaults);
0812:                            XertoMetalUtils.initClassDefaults(uiDefaults);
0813:                        }
0814:                        break;
0815:                    default:
0816:                    }
0817:
0818:                    // built in customizer
0819:                    if (lnf.getClass().getName().startsWith(
0820:                            SYNTHETICA_LNF_PREFIX)
0821:                            && isSyntheticaLnfInstalled()) {
0822:                        new SyntheticaCustomizer().customize(uiDefaults);
0823:                    }
0824:                }
0825:
0826:                UIManager.put(JIDE_EXTENSION_INSTALLLED, Boolean.TRUE);
0827:
0828:                UIDefaultsCustomizer[] customizers = getUIDefaultsCustomizers();
0829:                for (UIDefaultsCustomizer customizer : customizers) {
0830:                    if (customizer != null) {
0831:                        customizer.customize(uiDefaults);
0832:                    }
0833:                }
0834:            }
0835:
0836:            /**
0837:             * Returns whether or not the Aqua L&F is in classpath.
0838:             *
0839:             * @return <tt>true</tt> if aqua L&F is in classpath, <tt>false</tt> otherwise
0840:             */
0841:            public static boolean isAquaLnfInstalled() {
0842:                try {
0843:                    getValidClassLoader().loadClass(AQUA_LNF);
0844:                    return true;
0845:                } catch (ClassNotFoundException e) {
0846:                    return false;
0847:                }
0848:            }
0849:
0850:            private static ClassLoader getValidClassLoader() {
0851:                ClassLoader classLoader = LookAndFeelFactory.class
0852:                        .getClassLoader();
0853:                if (classLoader == null) {
0854:                    classLoader = ClassLoader.getSystemClassLoader();
0855:                }
0856:                return classLoader;
0857:            }
0858:
0859:            /**
0860:             * Returns whether or not the Quaqua L&F is in classpath.
0861:             *
0862:             * @return <tt>true</tt> if Quaqua L&F is in classpath, <tt>false</tt> otherwise
0863:             */
0864:            public static boolean isQuaquaLnfInstalled() {
0865:                try {
0866:                    getValidClassLoader().loadClass(QUAQUA_LNF);
0867:                    return true;
0868:                } catch (ClassNotFoundException e) {
0869:                    return false;
0870:                }
0871:            }
0872:
0873:            /**
0874:             * Returns whether alloy L&F is in classpath
0875:             *
0876:             * @return <tt>true</tt> alloy L&F is in classpath, <tt>false</tt> otherwise
0877:             */
0878:            public static boolean isAlloyLnfInstalled() {
0879:                try {
0880:                    getValidClassLoader().loadClass(ALLOY_LNF);
0881:                    return true;
0882:                } catch (ClassNotFoundException e) {
0883:                    return false;
0884:                }
0885:            }
0886:
0887:            /**
0888:             * Returns whether GTK L&F is in classpath
0889:             *
0890:             * @return <tt>true</tt> GTK L&F is in classpath, <tt>false</tt> otherwise
0891:             */
0892:            public static boolean isGTKLnfInstalled() {
0893:                try {
0894:                    getValidClassLoader().loadClass(GTK_LNF);
0895:                    return true;
0896:                } catch (ClassNotFoundException e) {
0897:                    return false;
0898:                }
0899:            }
0900:
0901:            /**
0902:             * Returns whether Plastic3D L&F is in classpath
0903:             *
0904:             * @return <tt>true</tt> Plastic3D L&F is in classpath, <tt>false</tt> otherwise
0905:             */
0906:            public static boolean isPlastic3DLnfInstalled() {
0907:                try {
0908:                    getValidClassLoader().loadClass(PLASTIC3D_LNF);
0909:                    return true;
0910:                } catch (ClassNotFoundException e) {
0911:                    return false;
0912:                }
0913:            }
0914:
0915:            /**
0916:             * Returns whether Plastic3D L&F is in classpath
0917:             *
0918:             * @return <tt>true</tt> Plastic3D L&F is in classpath, <tt>false</tt> otherwise
0919:             */
0920:            public static boolean isPlastic3D13LnfInstalled() {
0921:                try {
0922:                    getValidClassLoader().loadClass(PLASTIC3D_LNF_1_3);
0923:                    return true;
0924:                } catch (ClassNotFoundException e) {
0925:                    return false;
0926:                }
0927:            }
0928:
0929:            /**
0930:             * Returns whether PlasticXP L&F is in classpath
0931:             *
0932:             * @return <tt>true</tt> Plastic3D L&F is in classpath, <tt>false</tt> otherwise
0933:             */
0934:            public static boolean isPlasticXPLnfInstalled() {
0935:                try {
0936:                    getValidClassLoader().loadClass(PLASTICXP_LNF);
0937:                    return true;
0938:                } catch (ClassNotFoundException e) {
0939:                    return false;
0940:                }
0941:            }
0942:
0943:            /**
0944:             * Returns whether Tonic L&F is in classpath
0945:             *
0946:             * @return <tt>true</tt> Tonic L&F is in classpath, <tt>false</tt> otherwise
0947:             */
0948:            public static boolean isTonicLnfInstalled() {
0949:                try {
0950:                    getValidClassLoader().loadClass(TONIC_LNF);
0951:                    return true;
0952:                } catch (ClassNotFoundException e) {
0953:                    return false;
0954:                }
0955:            }
0956:
0957:            /**
0958:             * Returns whether A03 L&F is in classpath
0959:             *
0960:             * @return <tt>true</tt> A03 L&F is in classpath, <tt>false</tt> otherwise
0961:             */
0962:            public static boolean isA03LnfInstalled() {
0963:                try {
0964:                    getValidClassLoader().loadClass(A03_LNF);
0965:                    return true;
0966:                } catch (ClassNotFoundException e) {
0967:                    return false;
0968:                }
0969:            }
0970:
0971:            /**
0972:             * Returns whether or not the Pgs L&F is in classpath.
0973:             *
0974:             * @return <tt>true</tt> if pgs L&F is in classpath, <tt>false</tt> otherwise
0975:             */
0976:            public static boolean isPgsLnfInstalled() {
0977:                try {
0978:                    getValidClassLoader().loadClass(PGS_LNF);
0979:                    return true;
0980:                } catch (ClassNotFoundException e) {
0981:                    return false;
0982:                }
0983:            }
0984:
0985:            /**
0986:             * Returns whether or not the Synthetica L&F is in classpath.
0987:             *
0988:             * @return <tt>true</tt> if Synthetica L&F is in classpath, <tt>false</tt> otherwise
0989:             */
0990:            public static boolean isSyntheticaLnfInstalled() {
0991:                try {
0992:                    getValidClassLoader().loadClass(SYNTHETICA_LNF);
0993:                    return true;
0994:                } catch (ClassNotFoundException e) {
0995:                    return false;
0996:                }
0997:            }
0998:
0999:            /**
1000:             * Install the default L&F. In this method, we will look at system property "swing.defaultlaf" first.
1001:             * If the value is set and it's not an instance of Synth L&F, we will use it. Otherwise, we will
1002:             * use Metal L&F is OS is Linux or UNIX and use UIManager.getSystemLookAndFeelClassName() for other OS.
1003:             * In addition, we will add JIDE extension to it.
1004:             */
1005:            public static void installDefaultLookAndFeelAndExtension() {
1006:                installDefaultLookAndFeel();
1007:                // to add attitional UIDefault for JIDE components
1008:                LookAndFeelFactory.installJideExtension();
1009:            }
1010:
1011:            /**
1012:             * Install the default L&F. In this method, we will look at system property "swing.defaultlaf" first.
1013:             * If the value is set and it's not an instance of Synth L&F, we will use it. Otherwise, we will
1014:             * use Metal L&F is OS is Linux or UNIX and use UIManager.getSystemLookAndFeelClassName() for other OS.
1015:             */
1016:            public static void installDefaultLookAndFeel() {
1017:                try {
1018:                    String lnfName = SecurityUtils.getProperty(
1019:                            "swing.defaultlaf", null);
1020:                    Class<?> lnfClass = null;
1021:                    if (lnfName != null) {
1022:                        try {
1023:                            lnfClass = getValidClassLoader().loadClass(lnfName);
1024:                        } catch (ClassNotFoundException e) {
1025:                            // ignore
1026:                        }
1027:                    }
1028:
1029:                    //            if (lnfClass != null) {
1030:                    //                try {
1031:                    //                    Class synthClass = getValidClassLoader().loadClass("javax.swing.plaf.synth.SynthLookAndFeel");
1032:                    //                    if (lnfClass.isAssignableFrom(synthClass)) {
1033:                    //                        lnfClass = null;
1034:                    //                    }
1035:                    //                }
1036:                    //                catch (ClassNotFoundException e) {
1037:                    //                }
1038:                    //            }
1039:
1040:                    if (lnfClass == null) {
1041:                        UIManager.setLookAndFeel(UIManager
1042:                                .getSystemLookAndFeelClassName());
1043:                        //                // force to Metal L&F as in JDK1.5, GTK L&F is used as default L&F. We currently don't support GTK L&F.
1044:                        //                if (SystemInfo.isLinux() || SystemInfo.isUnix()) {
1045:                        //                    UIManager.setLookAndFeel(METAL_LNF);
1046:                        //                }
1047:                        //                else {
1048:                        //                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
1049:                        //                }
1050:                    } else {
1051:                        UIManager.setLookAndFeel(lnfName);
1052:                    }
1053:                } catch (Exception e) {
1054:                    e.printStackTrace();
1055:                }
1056:            }
1057:
1058:            /**
1059:             * Gets current L&F.
1060:             *
1061:             * @return the current L&F.
1062:             */
1063:            public static LookAndFeel getLookAndFeel() {
1064:                return _lookAndFeel;
1065:            }
1066:
1067:            /**
1068:             * Gets current style.
1069:             *
1070:             * @return the current style.
1071:             */
1072:            public static int getStyle() {
1073:                return _style;
1074:            }
1075:
1076:            /**
1077:             * Gets all UIDefaults customizers.
1078:             *
1079:             * @return an array of UIDefaults customizers.
1080:             */
1081:            public static UIDefaultsCustomizer[] getUIDefaultsCustomizers() {
1082:                return _uiDefaultsCustomizers
1083:                        .toArray(new UIDefaultsCustomizer[_uiDefaultsCustomizers
1084:                                .size()]);
1085:            }
1086:
1087:            /**
1088:             * Adds your own UIDefaults customizer. This customizer will be called
1089:             * after installJideExtension() is called.
1090:             * <code><pre>
1091:             * For example, we use "JideButton.font" as the UIDefault for the JideButton font. If you want to use another font, you can do
1092:             * LookAndFeelFactory.addUIDefaultsCustomizer(new LookAndFeelFactory.UIDefaultsCustomizer() {
1093:             *     public void customize(UIDefaults defaults) {
1094:             *         defaults.put("JideButton.font", whateverFont);
1095:             *     }
1096:             * });
1097:             * </pre></code>
1098:             *
1099:             * @param uiDefaultsCustomizer the UIDefaultsCustomizer
1100:             */
1101:            public static void addUIDefaultsCustomizer(
1102:                    UIDefaultsCustomizer uiDefaultsCustomizer) {
1103:                if (!_uiDefaultsCustomizers.contains(uiDefaultsCustomizer)) {
1104:                    _uiDefaultsCustomizers.add(uiDefaultsCustomizer);
1105:                }
1106:            }
1107:
1108:            /**
1109:             * Removes an existing UIDefaults customizer you added before.
1110:             *
1111:             * @param uiDefaultsCustomizer the UIDefaultsCustomizer
1112:             */
1113:            public static void removeUIDefaultsCustomizer(
1114:                    UIDefaultsCustomizer uiDefaultsCustomizer) {
1115:                _uiDefaultsCustomizers.remove(uiDefaultsCustomizer);
1116:            }
1117:
1118:            /**
1119:             * Gets all UIDefaults initializers.
1120:             *
1121:             * @return an array of UIDefaults initializers.
1122:             */
1123:            public static UIDefaultsInitializer[] getUIDefaultsInitializers() {
1124:                return _uiDefaultsInitializers
1125:                        .toArray(new UIDefaultsInitializer[_uiDefaultsInitializers
1126:                                .size()]);
1127:            }
1128:
1129:            /**
1130:             * Adds your own UIDefaults initializer. This initializer will be called
1131:             * before installJideExtension() is called.
1132:             * <p/>
1133:             * Here is how you use it. For example, we use the color of UIDefault "activeCaption" to get the active title color
1134:             * which we will use for active title bar color in JIDE components. If the L&F you are using
1135:             * doesn't set this UIDefault, we might throw NPE later in the code.
1136:             * To avoid this, you call
1137:             * <code><pre>
1138:             * LookAndFeelFactory.addUIDefaultsInitializer(new LookAndFeelFactory.UIDefaultsInitializer() {
1139:             *     public void initialize(UIDefaults defaults) {
1140:             *         defaults.put("activeCaption", whateverColor);
1141:             *     }
1142:             * });
1143:             * UIManager.setLookAndFeel(...); // set whatever L&F
1144:             * LookAndFeelFactory.installJideExtension(); // install the UIDefaults needed by the JIDE components
1145:             * </pre></code>
1146:             *
1147:             * @param uiDefaultsInitializer the UIDefaultsInitializer.
1148:             */
1149:            public static void addUIDefaultsInitializer(
1150:                    UIDefaultsInitializer uiDefaultsInitializer) {
1151:                if (!_uiDefaultsInitializers.contains(uiDefaultsInitializer)) {
1152:                    _uiDefaultsInitializers.add(uiDefaultsInitializer);
1153:                }
1154:            }
1155:
1156:            /**
1157:             * Removes an existing UIDefaults initializer you added before.
1158:             *
1159:             * @param uiDefaultsInitializer the UIDefaultsInitializer
1160:             */
1161:            public static void removeUIDefaultsInitializer(
1162:                    UIDefaultsInitializer uiDefaultsInitializer) {
1163:                _uiDefaultsInitializers.remove(uiDefaultsInitializer);
1164:            }
1165:
1166:            public static class GTKInitializer implements  UIDefaultsInitializer {
1167:                public void initialize(UIDefaults defaults) {
1168:                    Object[] uiDefaults = { "activeCaption",
1169:                            defaults.getColor("textHighlight"),
1170:                            "activeCaptionText",
1171:                            defaults.getColor("textHighlightText"),
1172:                            "inactiveCaptionBorder",
1173:                            defaults.getColor("controlShadowtextHighlightText") };
1174:                    putDefaults(defaults, uiDefaults);
1175:                }
1176:            }
1177:
1178:            public static class SyntheticaInitializer implements 
1179:                    UIDefaultsInitializer {
1180:                public void initialize(UIDefaults defaults) {
1181:                    Object[] uiDefaults = {
1182:                            "textHighlight",
1183:                            UIDefaultsLookup
1184:                                    .getColor("InternalFrame.activeTitleBackground"),
1185:                            "controlText",
1186:                            UIDefaultsLookup.getColor("Label.foreground"),
1187:                            "activeCaptionText",
1188:                            UIDefaultsLookup
1189:                                    .getColor("InternalFrame.activeTitleForeground"),
1190:                            "MenuItem.acceleratorFont",
1191:                            UIDefaultsLookup.getFont("Label.font"),
1192:                            "ComboBox.background",
1193:                            new ColorUIResource(Color.WHITE),
1194:                            "ComboBox.disabledForeground",
1195:                            defaults
1196:                                    .get("Synthetica.comboBox.disabled.textColor"),
1197:                            "ComboBox.disabledBackground",
1198:                            defaults
1199:                                    .get("Synthetica.comboBox.disabled.backgroundColor"),
1200:
1201:                            "activeCaption",
1202:                            UIDefaultsLookup
1203:                                    .getColor("InternalFrame.activeTitleBackground"),
1204:                            "inactiveCaption",
1205:                            UIDefaultsLookup
1206:                                    .getColor("InternalFrame.inactiveTitleBackground"),
1207:                            "control",
1208:                            new ColorUIResource(Color.WHITE),
1209:                            "controlLtHighlight",
1210:                            new ColorUIResource(Color.WHITE),
1211:                            "controlHighlight",
1212:                            new ColorUIResource(Color.LIGHT_GRAY),
1213:                            "controlShadow",
1214:                            new ColorUIResource(Color.DARK_GRAY),
1215:                            "controlDkShadow",
1216:                            new ColorUIResource(Color.BLACK),
1217:                            "MenuItem.background",
1218:                            new ColorUIResource(Color.GRAY),
1219:                            "SplitPane.background",
1220:                            UIDefaultsLookup.getColor("Label.background"),
1221:                            "Tree.hash",
1222:                            new ColorUIResource(Color.GRAY),
1223:
1224:                            "TextField.foreground",
1225:                            UIDefaultsLookup.getColor("Label.foreground"),
1226:                            "TextField.inactiveForeground",
1227:                            UIDefaultsLookup.getColor("Label.foreground"),
1228:                            "TextField.selectionForeground",
1229:                            UIDefaultsLookup
1230:                                    .getColor("List.selectionForeground"),
1231:                            "TextField.selectionBackground",
1232:                            UIDefaultsLookup
1233:                                    .getColor("List.selectionBackground"),
1234:                            "Table.gridColor",
1235:                            UIDefaultsLookup.getColor("Label.foreground"),
1236:                            "TextField.background",
1237:                            new ColorUIResource(Color.WHITE), };
1238:                    putDefaults(defaults, uiDefaults);
1239:                }
1240:            }
1241:
1242:            public static class SyntheticaCustomizer implements 
1243:                    UIDefaultsCustomizer {
1244:                public void customize(UIDefaults defaults) {
1245:                    Object[] uiDefaults = {
1246:                            "DockableFrame.activeTitleForeground",
1247:                            UIDefaultsLookup
1248:                                    .getColor("InternalFrame.activeTitleForeground"), };
1249:                    overwriteDefaults(defaults, uiDefaults);
1250:                }
1251:            }
1252:
1253:            public static void verifyDefaults(UIDefaults table,
1254:                    Object[] keyValueList) {
1255:                for (int i = 0, max = keyValueList.length; i < max; i += 2) {
1256:                    Object value = keyValueList[i + 1];
1257:                    if (value == null) {
1258:                        System.out.println("The value for " + keyValueList[i]
1259:                                + " is null");
1260:                    } else {
1261:                        Object oldValue = table.get(keyValueList[i]);
1262:                        if (oldValue != null) {
1263:                            System.out.println("The value for "
1264:                                    + keyValueList[i] + " exists which is "
1265:                                    + oldValue);
1266:                        }
1267:                    }
1268:                }
1269:            }
1270:
1271:            /**
1272:             * Puts a list of UIDefault to the UIDefaults table.
1273:             * The keyValueList is an array with a key and value in pair. If the value is
1274:             * null, this method will remove the key from the table. If the table already has a value for
1275:             * the key, the new value will be ignored. This is the difference from {@link #putDefaults(javax.swing.UIDefaults,Object[])} method.
1276:             * You should use this method in {@link UIDefaultsInitializer} so that it fills in the UIDefault value only when it is missing.
1277:             *
1278:             * @param table         the ui defaults table
1279:             * @param keyValueArray the key value array. It is in the format of a key followed by a value.
1280:             */
1281:            public static void putDefaults(UIDefaults table,
1282:                    Object[] keyValueArray) {
1283:                for (int i = 0, max = keyValueArray.length; i < max; i += 2) {
1284:                    Object value = keyValueArray[i + 1];
1285:                    if (value == null) {
1286:                        table.remove(keyValueArray[i]);
1287:                    } else {
1288:                        if (table.get(keyValueArray[i]) == null) {
1289:                            table.put(keyValueArray[i], value);
1290:                        }
1291:                    }
1292:                }
1293:            }
1294:
1295:            /**
1296:             * Puts a list of UIDefault to the UIDefaults table.
1297:             * The keyValueList is an array with a key and value in pair. If the value is
1298:             * null, this method will remove the key from the table. Otherwise, it will put the new value
1299:             * in even if the table already has a value for the key. This is the difference from {@link #putDefaults(javax.swing.UIDefaults,Object[])} method.
1300:             * You should use this method in {@link UIDefaultsCustomizer} because you always want to override the existing value using the new value.
1301:             *
1302:             * @param table         the ui defaults table
1303:             * @param keyValueArray the key value array. It is in the format of a key followed by a value.
1304:             */
1305:            public static void overwriteDefaults(UIDefaults table,
1306:                    Object[] keyValueArray) {
1307:                for (int i = 0, max = keyValueArray.length; i < max; i += 2) {
1308:                    Object value = keyValueArray[i + 1];
1309:                    if (value == null) {
1310:                        table.remove(keyValueArray[i]);
1311:                    } else {
1312:                        table.put(keyValueArray[i], value);
1313:                    }
1314:                }
1315:            }
1316:
1317:            private static int _productsUsed = -1;
1318:
1319:            public static int getProductsUsed() {
1320:                if (_productsUsed == -1) {
1321:                    _productsUsed = 0;
1322:                    try {
1323:                        Class.forName("com.jidesoft.docking.Product");
1324:                        _productsUsed |= PRODUCT_DOCK;
1325:                    } catch (ClassNotFoundException e) {
1326:                        //
1327:                    }
1328:                    try {
1329:                        Class.forName("com.jidesoft.action.Product");
1330:                        _productsUsed |= PRODUCT_ACTION;
1331:                    } catch (ClassNotFoundException e) {
1332:                        //
1333:                    }
1334:                    try {
1335:                        Class.forName("com.jidesoft.document.Product");
1336:                        _productsUsed |= PRODUCT_COMPONENTS;
1337:                    } catch (ClassNotFoundException e) {
1338:                        //
1339:                    }
1340:                    try {
1341:                        Class.forName("com.jidesoft.grid.Product");
1342:                        _productsUsed |= PRODUCT_GRIDS;
1343:                    } catch (ClassNotFoundException e) {
1344:                        //
1345:                    }
1346:                    try {
1347:                        Class.forName("com.jidesoft.wizard.Product");
1348:                        _productsUsed |= PRODUCT_DIALOGS;
1349:                    } catch (ClassNotFoundException e) {
1350:                        //
1351:                    }
1352:                    try {
1353:                        Class.forName("com.jidesoft.pivot.Product");
1354:                        _productsUsed |= PRODUCT_PIVOT;
1355:                    } catch (ClassNotFoundException e) {
1356:                        //
1357:                    }
1358:                    try {
1359:                        Class.forName("com.jidesoft.shortcut.Product");
1360:                        _productsUsed |= PRODUCT_SHORTCUT;
1361:                    } catch (ClassNotFoundException e) {
1362:                        //
1363:                    }
1364:                    try {
1365:                        Class.forName("com.jidesoft.editor.Product");
1366:                        _productsUsed |= PRODUCT_CODE_EDITOR;
1367:                    } catch (ClassNotFoundException e) {
1368:                        //
1369:                    }
1370:                    try {
1371:                        Class.forName("com.jidesoft.rss.Product");
1372:                        _productsUsed |= PRODUCT_FEEDREADER;
1373:                    } catch (ClassNotFoundException e) {
1374:                        //
1375:                    }
1376:                }
1377:                return _productsUsed;
1378:            }
1379:
1380:            /**
1381:             * Sets the products you will use. This is needed so that LookAndFeelFactory knows what UIDefault to initialize.
1382:             * For example, if you use only JIDE Docking Framework and JIDE Grids, you should call
1383:             * <code>setProductUsed(ProductNames.PRODUCT_DOCK | ProductNames.PRODUCT_GRIDS)</code> so that we don't initialize
1384:             * UIDefaults needed by any other products. If you use this class as part of JIDE Common Layer open source
1385:             * project, you should call <code>setProductUsed(ProductNames.PRODUCT_COMMON)</code>. If you want to use all JIDE products,
1386:             * you should call <code>setProductUsed(ProductNames.PRODUCT_ALL)</code>
1387:             *
1388:             * @param productsUsed a bit-wise OR of product values defined in {@link com.jidesoft.utils.ProductNames}.
1389:             */
1390:            public static void setProductsUsed(int productsUsed) {
1391:                _productsUsed = productsUsed;
1392:            }
1393:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.