Source Code Cross Referenced for ComponentHandlerFactory.java in  » Swing-Library » Hitch » com » silvermindsoftware » hitch » handlers » 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 » Hitch » com.silvermindsoftware.hitch.handlers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.silvermindsoftware.hitch.handlers;
002:
003:        /**
004:         * Copyright 2007 Brandon Goodin
005:         *
006:         * Licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         *
010:         *   http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */
018:
019:        import com.silvermindsoftware.hitch.handlers.component.*;
020:        import org.apache.commons.logging.Log;
021:        import org.apache.commons.logging.LogFactory;
022:
023:        import javax.swing.*;
024:        import java.util.HashMap;
025:        import java.util.Map;
026:
027:        public class ComponentHandlerFactory {
028:
029:            private static final Log log = LogFactory
030:                    .getLog(ComponentHandlerFactory.class);
031:
032:            private Map<Object, ComponentHandler> componentHandler;
033:
034:            public ComponentHandlerFactory() {
035:
036:                this .componentHandler = new HashMap<Object, ComponentHandler>();
037:
038:                ComponentHandler componentHandler = new TextComponentHandler();
039:                register(JButton.class, componentHandler);
040:                register(JTextField.class, componentHandler);
041:                register(JTextArea.class, componentHandler);
042:
043:                componentHandler = new JLabelComponentHandler();
044:                register(JLabel.class, componentHandler);
045:
046:                componentHandler = new ValueComponentHandler();
047:                register(JFormattedTextField.class, componentHandler);
048:
049:                componentHandler = new JComboBoxComponentHandler();
050:                register(JComboBox.class, componentHandler);
051:
052:                componentHandler = new JListComponentHandler();
053:                register(JList.class, componentHandler);
054:
055:                componentHandler = new ToggleComponentHandler();
056:                register(JRadioButton.class, componentHandler);
057:                register(JCheckBox.class, componentHandler);
058:                register(JToggleButton.class, componentHandler);
059:
060:                componentHandler = new JSpinnerComponentHandler();
061:                register(JSpinner.class, componentHandler);
062:
063:                componentHandler = new JSliderComponentHandler();
064:                register(JSlider.class, componentHandler);
065:
066:                //--- NEED TO BE ASSIGNED---
067:                //		register(JMenuItem.class, componentHandler);
068:                //		register(JRadioButtonMenuItem.class, componentHandler);
069:                //		register(JCheckBoxMenuItem.class, componentHandler);
070:                //		register(JMenu.class, componentHandler);
071:                //		register(JMenuItem.class, componentHandler);
072:
073:            }
074:
075:            /**
076:             * Register a component handler instance for a key (generally a class)
077:             *
078:             * @param key              the key
079:             * @param componentHandler the component instance that will handle data mapping for the key
080:             */
081:            public void register(Object key, ComponentHandler componentHandler) {
082:                if (log.isDebugEnabled()) {
083:                    log.debug("Adding '" + componentHandler.getClass()
084:                            + "' to registry under key '" + key + "'.");
085:                }
086:                this .componentHandler.put(key, componentHandler);
087:            }
088:
089:            /**
090:             * Looks in the registry for a suitable handler instance based on the 'key'. If no exact match
091:             * is found and key is of type Class, then we look for a superclass of 'key'. If we find a
092:             * match, we return it, and register it's handler under the subclass so future lookups are fast.
093:             *
094:             * @param key - generally a class (will it ever not be a class?)
095:             * @return the ComponentHandler for the key
096:             */
097:            public ComponentHandler getHandler(Object key) {
098:
099:                // look for an exact match
100:                ComponentHandler returnValue = componentHandler.get(key);
101:
102:                if (null == returnValue) {
103:                    // Darn, we didn't find one.
104:                    if (log.isDebugEnabled()) {
105:                        log.debug("Could not find match for key '" + key
106:                                + "' in registry, searching for subclasses.");
107:                    }
108:                    if (key instanceof  Class) {
109:                        // The search was for a class, so let's look to see if any of it's superclasses are
110:                        // registered...
111:                        Class keyClass = (Class) key;
112:
113:                        if (log.isDebugEnabled()) {
114:                            log.debug("Searching for superclasses of '" + key
115:                                    + "' in registry.");
116:                        }
117:
118:                        keyClass = keyClass.getSuperclass();
119:                        while (keyClass != null) {
120:                            if (log.isDebugEnabled()) {
121:                                log
122:                                        .debug("Looking for a match for "
123:                                                + keyClass);
124:                            }
125:                            returnValue = componentHandler.get(keyClass);
126:                            if (null != returnValue) {
127:                                if (log.isDebugEnabled()) {
128:                                    log.debug("Found a match for " + keyClass);
129:                                }
130:                                register(key, returnValue);
131:                                break;
132:                            }
133:                            keyClass = keyClass.getSuperclass();
134:                        }
135:                    }
136:                }
137:
138:                if (log.isDebugEnabled()) {
139:                    log.debug("Returning '" + returnValue + "' for key '" + key
140:                            + "'");
141:                }
142:
143:                return returnValue;
144:            }
145:
146:            /**
147:             * Get the class that will be responsible for handling a particular component.
148:             *
149:             * @param componentType the component to look up
150:             * @return the class that will handle this component
151:             */
152:            public Class getHandlerType(Class componentType) {
153:
154:                Class retVal = null;
155:                Object object = getHandler(componentType);
156:                if (object != null) {
157:                    retVal = object.getClass();
158:                }
159:                return retVal;
160:            }
161:
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.