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


001:        /*
002:         * $Id: AbstractComponentAddon.java,v 1.2 2006/03/25 14:56:14 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:        package com.l2fprod.common.swing.plaf;
008:
009:        import com.l2fprod.common.swing.plaf.aqua.AquaLookAndFeelAddons;
010:        import com.l2fprod.common.swing.plaf.metal.MetalLookAndFeelAddons;
011:        import com.l2fprod.common.swing.plaf.motif.MotifLookAndFeelAddons;
012:        import com.l2fprod.common.swing.plaf.windows.WindowsLookAndFeelAddons;
013:
014:        import java.awt.Color;
015:        import java.awt.Font;
016:        import java.util.ArrayList;
017:        import java.util.Enumeration;
018:        import java.util.List;
019:        import java.util.ResourceBundle;
020:
021:        import javax.swing.UIManager;
022:
023:        /**
024:         * Ease the work of creating an addon for a component.<br>
025:         * 
026:         * @author Frederic Lavigne
027:         */
028:        public abstract class AbstractComponentAddon implements  ComponentAddon {
029:
030:            private String name;
031:
032:            protected AbstractComponentAddon(String name) {
033:                this .name = name;
034:            }
035:
036:            public final String getName() {
037:                return name;
038:            }
039:
040:            public void initialize(LookAndFeelAddons addon) {
041:                addon.loadDefaults(getDefaults(addon));
042:            }
043:
044:            public void uninitialize(LookAndFeelAddons addon) {
045:                addon.unloadDefaults(getDefaults(addon));
046:            }
047:
048:            /**
049:             * Adds default key/value pairs to the given list.
050:             * 
051:             * @param addon
052:             * @param defaults
053:             */
054:            protected void addBasicDefaults(LookAndFeelAddons addon,
055:                    List defaults) {
056:            }
057:
058:            /**
059:             * Default implementation calls {@link #addBasicDefaults(LookAndFeelAddons, List)}
060:             * 
061:             * @param addon
062:             * @param defaults
063:             */
064:            protected void addMacDefaults(LookAndFeelAddons addon, List defaults) {
065:                addBasicDefaults(addon, defaults);
066:            }
067:
068:            /**
069:             * Default implementation calls {@link #addBasicDefaults(LookAndFeelAddons, List)}
070:             * 
071:             * @param addon
072:             * @param defaults
073:             */
074:            protected void addMetalDefaults(LookAndFeelAddons addon,
075:                    List defaults) {
076:                addBasicDefaults(addon, defaults);
077:            }
078:
079:            /**
080:             * Default implementation calls {@link #addBasicDefaults(LookAndFeelAddons, List)}
081:             * 
082:             * @param addon
083:             * @param defaults
084:             */
085:            protected void addMotifDefaults(LookAndFeelAddons addon,
086:                    List defaults) {
087:                addBasicDefaults(addon, defaults);
088:            }
089:
090:            /**
091:             * Default implementation calls {@link #addBasicDefaults(LookAndFeelAddons, List)}
092:             * 
093:             * @param addon
094:             * @param defaults
095:             */
096:            protected void addWindowsDefaults(LookAndFeelAddons addon,
097:                    List defaults) {
098:                addBasicDefaults(addon, defaults);
099:            }
100:
101:            /**
102:             * Gets the defaults for the given addon.
103:             * 
104:             * Based on the addon, it calls
105:             * {@link #addMacDefaults(LookAndFeelAddons, List)} if isMac()
106:             * or
107:             * {@link #addMetalDefaults(LookAndFeelAddons, List)} if isMetal()
108:             * or
109:             * {@link #addMotifDefaults(LookAndFeelAddons, List)} if isMotif()
110:             * or
111:             * {@link #addWindowsDefaults(LookAndFeelAddons, List)} if isWindows()
112:             * or
113:             * {@link #addBasicDefaults(LookAndFeelAddons, List)} if none of the above was called.
114:             * @param addon
115:             * @return an array of key/value pairs. For example:
116:             * <pre>
117:             * Object[] uiDefaults = {
118:             *   "Font", new Font("Dialog", Font.BOLD, 12),
119:             *   "Color", Color.red,
120:             *   "five", new Integer(5)
121:             * };
122:             * </pre>
123:             */
124:            private Object[] getDefaults(LookAndFeelAddons addon) {
125:                List defaults = new ArrayList();
126:                if (isWindows(addon)) {
127:                    addWindowsDefaults(addon, defaults);
128:                } else if (isMetal(addon)) {
129:                    addMetalDefaults(addon, defaults);
130:                } else if (isMac(addon)) {
131:                    addMacDefaults(addon, defaults);
132:                } else if (isMotif(addon)) {
133:                    addMotifDefaults(addon, defaults);
134:                } else {
135:                    // at least add basic defaults
136:                    addBasicDefaults(addon, defaults);
137:                }
138:                return defaults.toArray();
139:            }
140:
141:            //
142:            // Helper methods to make ComponentAddon developer life easier
143:            //
144:
145:            /**
146:             * Adds the all keys/values from the given named resource bundle to the
147:             * defaults
148:             */
149:            protected void addResource(List defaults, String bundleName) {
150:                ResourceBundle bundle = ResourceBundle.getBundle(bundleName);
151:                for (Enumeration keys = bundle.getKeys(); keys
152:                        .hasMoreElements();) {
153:                    String key = (String) keys.nextElement();
154:                    defaults.add(key);
155:                    defaults.add(bundle.getObject(key));
156:                }
157:            }
158:
159:            /**
160:             * @return true if the addon is the Windows addon or its subclasses
161:             */
162:            protected boolean isWindows(LookAndFeelAddons addon) {
163:                return addon instanceof  WindowsLookAndFeelAddons;
164:            }
165:
166:            /**
167:             * @return true if the addon is the Metal addon or its subclasses
168:             */
169:            protected boolean isMetal(LookAndFeelAddons addon) {
170:                return addon instanceof  MetalLookAndFeelAddons;
171:            }
172:
173:            /**
174:             * @return true if the addon is the Aqua addon or its subclasses
175:             */
176:            protected boolean isMac(LookAndFeelAddons addon) {
177:                return addon instanceof  AquaLookAndFeelAddons;
178:            }
179:
180:            /**
181:             * @return true if the addon is the Motif addon or its subclasses
182:             */
183:            protected boolean isMotif(LookAndFeelAddons addon) {
184:                return addon instanceof  MotifLookAndFeelAddons;
185:            }
186:
187:            /**
188:             * @return true if the current look and feel is one of JGoodies Plastic l&fs
189:             */
190:            protected boolean isPlastic() {
191:                return UIManager.getLookAndFeel().getClass().getName().indexOf(
192:                        "Plastic") != -1;
193:            }
194:
195:            /**
196:             * @return true if the current look and feel is Synth l&f
197:             */
198:            protected boolean isSynth() {
199:                return UIManager.getLookAndFeel().getClass().getName().indexOf(
200:                        "ynth") != -1;
201:            }
202:
203:            protected Font getFont(String key, Font defaultFont) {
204:                Font result = UIManager.getFont(key);
205:                return result != null ? result : defaultFont;
206:            }
207:
208:            protected Color getColor(String key, Color defaultColor) {
209:                Color result = UIManager.getColor(key);
210:                return result != null ? result : defaultColor;
211:            }
212:
213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.