Source Code Cross Referenced for ComponentTree.java in  » Testing » jacareto » jacareto » cleverphl » gui » 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 » Testing » jacareto » jacareto.cleverphl.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Jacareto Copyright (c) 2002-2005
003:         * Applied Computer Science Research Group, Darmstadt University of
004:         * Technology, Institute of Mathematics & Computer Science,
005:         * Ludwigsburg University of Education, and Computer Based
006:         * Learning Research Group, Aachen University. All rights reserved.
007:         *
008:         * Jacareto is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public
010:         * License as published by the Free Software Foundation; either
011:         * version 2 of the License, or (at your option) any later version.
012:         *
013:         * Jacareto is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
016:         * General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public
019:         * License along with Jacareto; if not, write to the Free
020:         * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021:         *
022:         */
023:
024:        package jacareto.cleverphl.gui;
025:
026:        import jacareto.comp.ComponentHandler;
027:        import jacareto.comp.Components;
028:        import jacareto.system.Environment;
029:        import jacareto.system.Language;
030:
031:        import org.apache.log4j.Logger;
032:
033:        import java.awt.Component;
034:
035:        import java.util.Enumeration;
036:        import java.util.Hashtable;
037:
038:        import javax.swing.tree.DefaultMutableTreeNode;
039:        import javax.swing.tree.DefaultTreeModel;
040:        import javax.swing.tree.MutableTreeNode;
041:        import javax.swing.tree.TreeModel;
042:
043:        /**
044:         * This class creates a TreeModel for JTrees from a given components instance.
045:         *
046:         * @author Thomas Leonhard
047:         * @version 1.0
048:         */
049:        public class ComponentTree {
050:            /** The tree model of all components. */
051:            private DefaultTreeModel treeModel;
052:
053:            /** The root node of the tree model. */
054:            private DefaultMutableTreeNode treeModelRootNode;
055:
056:            /** Maps components to nodes. */
057:            private Hashtable componentToNode;
058:
059:            /** The logger. */
060:            private Logger logger;
061:
062:            /** The language instance. */
063:            private Language language;
064:
065:            /** The environment */
066:            protected Environment environment;
067:
068:            /** The components manager */
069:            protected Components componentsManager;
070:
071:            /**
072:             * Creates a new Components instance. The component handlers are loaded by the given class
073:             * loader.
074:             *
075:             * @param componentsManager the environment.
076:             */
077:            public ComponentTree(Components componentsManager) {
078:                this .environment = componentsManager.getEnvironment();
079:                this .componentsManager = componentsManager;
080:                this .logger = environment.getLogger();
081:                this .language = environment.getLanguage();
082:            }
083:
084:            /**
085:             * Creates the {@link TreeModel} for this ComponentsTree.
086:             *
087:             * @return {@link TreeModel}
088:             */
089:            public TreeModel createTreeModel() {
090:                componentToNode = new Hashtable();
091:                treeModelRootNode = new DefaultMutableTreeNode(environment
092:                        .getLanguage().getString("Components.TreeNodeName"));
093:                treeModel = new DefaultTreeModel(treeModelRootNode);
094:
095:                Enumeration componentEnumertation = componentsManager
096:                        .includedRoots();
097:
098:                while (componentEnumertation.hasMoreElements() == true) {
099:                    Component component = (Component) componentEnumertation
100:                            .nextElement();
101:
102:                    MutableTreeNode treeNode = createNode(component);
103:                    treeModelRootNode.add(treeNode);
104:                }
105:
106:                return treeModel;
107:            }
108:
109:            /**
110:             * Creates a {@link MutableTreeNode} including the given {@link Component}.
111:             *
112:             * @param component The {@link Component} which should be included in the TreeNode
113:             *
114:             * @return {@link MutableTreeNode}
115:             */
116:            public MutableTreeNode createNode(Component component) {
117:                String name = componentsManager.getName(component);
118:                logger.debug(language
119:                        .getString("CleverPHL.ComponentTree.Msg.CreatingNode")
120:                        + " ["
121:                        + name
122:                        + "] ["
123:                        + component.getClass().getName()
124:                        + "]");
125:
126:                String indicatorString = componentsManager
127:                        .getIndicatorString(component);
128:                if (indicatorString != null) {
129:                    indicatorString = " [ \"" + indicatorString + "\" ]";
130:                } else {
131:                    indicatorString = "";
132:                }
133:
134:                ComponentHandler compHandler = componentsManager
135:                        .getFirstComponentHandler(component);
136:
137:                DefaultMutableTreeNode result = null;
138:
139:                if ((component != null) && (name != null)) {
140:                    int lastDotPos = name.lastIndexOf(".");
141:
142:                    if (lastDotPos == -1) {
143:                        result = new DefaultMutableTreeNode(name
144:                                + indicatorString);
145:                    } else {
146:                        result = new DefaultMutableTreeNode(name
147:                                .substring(lastDotPos + 1)
148:                                + indicatorString);
149:                    }
150:
151:                    Component[] compChildren = compHandler
152:                            .getChildren(component);
153:                    int counter = 0;
154:
155:                    if ((compChildren != null) && (compChildren.length > 0)) {
156:                        MutableTreeNode childTreeNode;
157:
158:                        for (int i = 0; i < compChildren.length; i++) {
159:                            Component child = compChildren[i];
160:                            childTreeNode = createNode(child);
161:
162:                            if (childTreeNode != null) {
163:                                result.add(childTreeNode);
164:                            }
165:
166:                            counter++;
167:                        }
168:                    }
169:                } else {
170:                    logger.warn(language
171:                            .getString("Components.Error.NoHandler")
172:                            + ": " + component.getClass().getName());
173:                }
174:
175:                if (result != null) {
176:                    componentToNode.put(component, result);
177:                }
178:
179:                return result;
180:            }
181:
182:            /**
183:             * Returns the tree node for a given component.
184:             *
185:             * @param component the component
186:             *
187:             * @return the tree node of the component
188:             */
189:            public DefaultMutableTreeNode getNode(Component component) {
190:                if (componentToNode.containsKey(component)) {
191:                    return (DefaultMutableTreeNode) componentToNode
192:                            .get(component);
193:                }
194:
195:                return null;
196:            }
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.