Source Code Cross Referenced for AbstractComponentAddon.java in  » Swing-Library » swingx » org » jdesktop » swingx » 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 » swingx » org.jdesktop.swingx.plaf 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: AbstractComponentAddon.java,v 1.6 2007/02/07 15:09:51 l2fprod Exp $
003:         *
004:         * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
005:         * Santa Clara, California 95054, U.S.A. All rights reserved.
006:         *
007:         * This library is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:         * 
012:         * This library is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         * 
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this library; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
020:         */
021:        package org.jdesktop.swingx.plaf;
022:
023:        import java.util.ArrayList;
024:        import java.util.Enumeration;
025:        import java.util.List;
026:        import java.util.ResourceBundle;
027:
028:        import javax.swing.UIManager;
029:
030:        import org.jdesktop.swingx.plaf.macosx.MacOSXLookAndFeelAddons;
031:        import org.jdesktop.swingx.plaf.metal.MetalLookAndFeelAddons;
032:        import org.jdesktop.swingx.plaf.motif.MotifLookAndFeelAddons;
033:        import org.jdesktop.swingx.plaf.windows.WindowsLookAndFeelAddons;
034:
035:        /**
036:         * Ease the work of creating an addon for a component.<br>
037:         * 
038:         * @author <a href="mailto:fred@L2FProd.com">Frederic Lavigne</a>
039:         */
040:        public abstract class AbstractComponentAddon implements  ComponentAddon {
041:
042:            private String name;
043:
044:            protected AbstractComponentAddon(String name) {
045:                this .name = name;
046:            }
047:
048:            public final String getName() {
049:                return name;
050:            }
051:
052:            public void initialize(LookAndFeelAddons addon) {
053:                addon.loadDefaults(getDefaults(addon));
054:            }
055:
056:            public void uninitialize(LookAndFeelAddons addon) {
057:                // commented after Issue 446. Maybe addon should keep track of its
058:                // added defaults to correctly remove them on uninitialize
059:                // addon.unloadDefaults(getDefaults(addon));
060:            }
061:
062:            /**
063:             * Adds default key/value pairs to the given list.
064:             * 
065:             * @param addon
066:             * @param defaults
067:             */
068:            protected void addBasicDefaults(LookAndFeelAddons addon,
069:                    List<Object> defaults) {
070:            }
071:
072:            /**
073:             * Default implementation calls {@link #addBasicDefaults(LookAndFeelAddons, List)}
074:             * 
075:             * @param addon
076:             * @param defaults
077:             */
078:            protected void addMacDefaults(LookAndFeelAddons addon,
079:                    List<Object> defaults) {
080:                addBasicDefaults(addon, defaults);
081:            }
082:
083:            /**
084:             * Default implementation calls {@link #addBasicDefaults(LookAndFeelAddons, List)}
085:             * 
086:             * @param addon
087:             * @param defaults
088:             */
089:            protected void addMetalDefaults(LookAndFeelAddons addon,
090:                    List<Object> defaults) {
091:                addBasicDefaults(addon, defaults);
092:            }
093:
094:            /**
095:             * Default implementation calls {@link #addBasicDefaults(LookAndFeelAddons, List)}
096:             * 
097:             * @param addon
098:             * @param defaults
099:             */
100:            protected void addMotifDefaults(LookAndFeelAddons addon,
101:                    List<Object> defaults) {
102:                addBasicDefaults(addon, defaults);
103:            }
104:
105:            /**
106:             * Default implementation calls {@link #addBasicDefaults(LookAndFeelAddons, List)}
107:             * 
108:             * @param addon
109:             * @param defaults
110:             */
111:            protected void addWindowsDefaults(LookAndFeelAddons addon,
112:                    List<Object> defaults) {
113:                addBasicDefaults(addon, defaults);
114:            }
115:
116:            /**
117:             * Gets the defaults for the given addon.
118:             * 
119:             * Based on the addon, it calls
120:             * {@link #addMacDefaults(LookAndFeelAddons, List)} if isMac()
121:             * or
122:             * {@link #addMetalDefaults(LookAndFeelAddons, List)} if isMetal()
123:             * or
124:             * {@link #addMotifDefaults(LookAndFeelAddons, List)} if isMotif()
125:             * or
126:             * {@link #addWindowsDefaults(LookAndFeelAddons, List)} if isWindows()
127:             * or
128:             * {@link #addBasicDefaults(LookAndFeelAddons, List)} if none of the above was called.
129:             * @param addon
130:             * @return an array of key/value pairs. For example:
131:             * <pre>
132:             * Object[] uiDefaults = {
133:             *   "Font", new Font("Dialog", Font.BOLD, 12),
134:             *   "Color", Color.red,
135:             *   "five", new Integer(5)
136:             * };
137:             * </pre>
138:             */
139:            private Object[] getDefaults(LookAndFeelAddons addon) {
140:                List<Object> defaults = new ArrayList<Object>();
141:                if (isWindows(addon)) {
142:                    addWindowsDefaults(addon, defaults);
143:                } else if (isMetal(addon)) {
144:                    addMetalDefaults(addon, defaults);
145:                } else if (isMac(addon)) {
146:                    addMacDefaults(addon, defaults);
147:                } else if (isMotif(addon)) {
148:                    addMotifDefaults(addon, defaults);
149:                } else {
150:                    // at least add basic defaults
151:                    addBasicDefaults(addon, defaults);
152:                }
153:                return defaults.toArray();
154:            }
155:
156:            //
157:            // Helper methods to make ComponentAddon developer life easier
158:            //
159:
160:            /**
161:             * Adds the all keys/values from the given named resource bundle to the
162:             * defaults
163:             */
164:            protected void addResource(List<Object> defaults, String bundleName) {
165:                ResourceBundle bundle = ResourceBundle.getBundle(bundleName);
166:                for (Enumeration<String> keys = bundle.getKeys(); keys
167:                        .hasMoreElements();) {
168:                    String key = keys.nextElement();
169:                    defaults.add(key);
170:                    defaults.add(bundle.getObject(key));
171:                }
172:            }
173:
174:            /**
175:             * @return true if the addon is the Windows addon or its subclasses
176:             */
177:            protected boolean isWindows(LookAndFeelAddons addon) {
178:                return addon instanceof  WindowsLookAndFeelAddons;
179:            }
180:
181:            /**
182:             * @return true if the addon is the Metal addon or its subclasses
183:             */
184:            protected boolean isMetal(LookAndFeelAddons addon) {
185:                return addon instanceof  MetalLookAndFeelAddons;
186:            }
187:
188:            /**
189:             * @return true if the addon is the Mac OS X addon or its subclasses
190:             */
191:            protected boolean isMac(LookAndFeelAddons addon) {
192:                return addon instanceof  MacOSXLookAndFeelAddons;
193:            }
194:
195:            /**
196:             * @return true if the addon is the Motif addon or its subclasses
197:             */
198:            protected boolean isMotif(LookAndFeelAddons addon) {
199:                return addon instanceof  MotifLookAndFeelAddons;
200:            }
201:
202:            /**
203:             * @return true if the current look and feel is one of JGoodies Plastic l&fs
204:             */
205:            protected boolean isPlastic() {
206:                return UIManager.getLookAndFeel().getClass().getName()
207:                        .contains("Plastic");
208:            }
209:
210:            /**
211:             * @return true if the current look and feel is Synth l&f
212:             */
213:            protected boolean isSynth() {
214:                return UIManager.getLookAndFeel().getClass().getName()
215:                        .contains("ynth");
216:            }
217:
218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.