Source Code Cross Referenced for DirectoryTree.java in  » UML » jrefactory » org » acm » seguin » pmd » swingui » 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 » UML » jrefactory » org.acm.seguin.pmd.swingui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.acm.seguin.pmd.swingui;
002:
003:        import org.acm.seguin.pmd.swingui.event.ListenerList;
004:        import org.acm.seguin.pmd.swingui.event.SetupFilesEvent;
005:        import org.acm.seguin.pmd.swingui.event.SetupFilesEventListener;
006:        import org.acm.seguin.pmd.swingui.event.StatusBarEvent;
007:
008:        import javax.swing.BorderFactory;
009:        import javax.swing.Icon;
010:        import javax.swing.JTree;
011:        import javax.swing.UIManager;
012:        import javax.swing.border.EtchedBorder;
013:        import javax.swing.tree.DefaultTreeCellRenderer;
014:        import javax.swing.tree.TreePath;
015:        import java.awt.Component;
016:        import java.io.File;
017:
018:        /**
019:         *
020:         * @author Donald A. Leckie
021:         * @since August 17, 2002
022:         * @version $Revision: 1.1 $, $Date: 2003/07/29 20:51:59 $
023:         */
024:        class DirectoryTree extends JTree {
025:
026:            /**
027:             *******************************************************************************
028:             *
029:             */
030:            protected DirectoryTree(String rootName) {
031:                super (new DirectoryTreeModel(rootName));
032:
033:                setRootVisible(true);
034:                setBorder(BorderFactory
035:                        .createEtchedBorder(EtchedBorder.LOWERED));
036:                setCellRenderer(new DirectoryTreeNodeRenderer());
037:                ((DirectoryTreeModel) getModel()).setDirectoryTree(this );
038:                setBackground(UIManager.getColor("pmdTreeBackground"));
039:                ListenerList
040:                        .addListener((SetupFilesEventListener) new SetupFilesEventHandler());
041:            }
042:
043:            /**
044:             *******************************************************************************
045:             *
046:             */
047:            protected void expandRootNode() {
048:                DirectoryTreeModel treeModel = (DirectoryTreeModel) getModel();
049:                DirectoryTreeNode treeNode = (DirectoryTreeNode) treeModel
050:                        .getRoot();
051:                TreePath treePath = new TreePath(treeNode.getPath());
052:                expandPath(treePath);
053:            }
054:
055:            /**
056:             *******************************************************************************
057:             *
058:             */
059:            protected DirectoryTreeNode getSelectedNode() {
060:                TreePath path = getSelectionModel().getSelectionPath();
061:
062:                return (DirectoryTreeNode) path.getLastPathComponent();
063:            }
064:
065:            /**
066:             *********************************************************************************
067:             *********************************************************************************
068:             *********************************************************************************
069:             */
070:            private class SetupFilesEventHandler implements 
071:                    SetupFilesEventListener {
072:
073:                /**
074:                 ****************************************************************************
075:                 *
076:                 * @param event
077:                 */
078:                public void startSetup(SetupFilesEvent event) {
079:                }
080:
081:                /**
082:                 ****************************************************************************
083:                 *
084:                 * @param event
085:                 */
086:                public void stopSetup(SetupFilesEvent event) {
087:                }
088:
089:                /**
090:                 ****************************************************************************
091:                 *
092:                 * @param event
093:                 */
094:                public void setFileList(SetupFilesEvent event) {
095:                    File[] directories = event.getFileList();
096:                    String name = "Locating root directories.";
097:                    SetupFilesThread setupFilesThread = new SetupFilesThread(
098:                            name, directories);
099:                    setupFilesThread.start();
100:                }
101:            }
102:
103:            /**
104:             ********************************************************************************
105:             ********************************************************************************
106:             ********************************************************************************
107:             */
108:            private class SetupFilesThread extends Thread {
109:                private File[] m_rootDirectories;
110:
111:                /**
112:                 ****************************************************************************
113:                 *
114:                 * @param name
115:                 */
116:                private SetupFilesThread(String threadName,
117:                        File[] rootDirectories) {
118:                    super (threadName);
119:
120:                    m_rootDirectories = rootDirectories;
121:                }
122:
123:                /**
124:                 ***************************************************************************
125:                 *
126:                 */
127:                public void run() {
128:                    setup();
129:                    process();
130:                    cleanup();
131:                }
132:
133:                /**
134:                 ***************************************************************************
135:                 *
136:                 */
137:                protected void setup() {
138:                    SetupFilesEvent.notifyStartSetup(this );
139:                    StatusBarEvent.notifyStartAnimation(this );
140:                }
141:
142:                /**
143:                 ***************************************************************************
144:                 *
145:                 */
146:                protected void process() {
147:                    StatusBarEvent.notifyShowMessage(this ,
148:                            "Locating root directories.  Please wait...");
149:                    DirectoryTreeModel treeModel = (DirectoryTreeModel) getModel();
150:                    treeModel.setupFiles(m_rootDirectories);
151:                    expandRootNode();
152:                }
153:
154:                /**
155:                 ***************************************************************************
156:                 *
157:                 */
158:                protected void cleanup() {
159:                    StatusBarEvent.notifyStopAnimation(this );
160:                    SetupFilesEvent.notifyStopSetup(this );
161:                }
162:            }
163:
164:            /**
165:             ********************************************************************************
166:             ********************************************************************************
167:             ********************************************************************************
168:             */
169:            private class DirectoryTreeNodeRenderer extends
170:                    DefaultTreeCellRenderer {
171:
172:                private Icon m_defaultClosedIcon;
173:                private Icon m_defaultLeafIcon;
174:                private Icon m_defaultOpenIcon;
175:
176:                /**
177:                 ***************************************************************************
178:                 *
179:                 */
180:                protected DirectoryTreeNodeRenderer() {
181:                    super ();
182:
183:                    m_defaultClosedIcon = getDefaultClosedIcon();
184:                    m_defaultLeafIcon = getDefaultLeafIcon();
185:                    m_defaultOpenIcon = getDefaultOpenIcon();
186:                    setBackgroundNonSelectionColor(UIManager
187:                            .getColor("pmdTreeBackground"));
188:                }
189:
190:                /**
191:                 **************************************************************************
192:                 *
193:                 * @param tree
194:                 * @param object
195:                 * @param isSelected
196:                 * @param isExpanded
197:                 * @param isLeaf
198:                 * @param row
199:                 * @param hasFocus
200:                 *
201:                 * @return
202:                 */
203:                public Component getTreeCellRendererComponent(JTree tree,
204:                        Object object, boolean isSelected, boolean isExpanded,
205:                        boolean isLeaf, int row, boolean hasFocus) {
206:                    DirectoryTreeNode treeNode = (DirectoryTreeNode) object;
207:                    Object userObject = treeNode.getUserObject();
208:
209:                    if (userObject instanceof  String) {
210:                        // The root node will display either an open or closed icon.
211:                        setClosedIcon(m_defaultClosedIcon);
212:                        setLeafIcon(m_defaultClosedIcon);
213:                        setOpenIcon(m_defaultOpenIcon);
214:                    } else if (((File) userObject).isFile()) {
215:                        // A file cannot have any children; therefore, the default icon settings are used.
216:                        setClosedIcon(m_defaultClosedIcon);
217:                        setLeafIcon(m_defaultLeafIcon);
218:                        setOpenIcon(m_defaultOpenIcon);
219:                    } else {
220:                        // A directory may or may not have children.  The following conditions are used:
221:                        //
222:                        //   For a file
223:                        //      files are not viewed in the tree
224:                        //   For a directory
225:                        //      has no children --- use closed folder icon
226:                        //      has children
227:                        //         is expanded --- use open folder icon
228:                        //         is collapsed --- use closed folder icon
229:                        //
230:                        setClosedIcon(m_defaultClosedIcon);
231:                        setLeafIcon(m_defaultClosedIcon);
232:                        setOpenIcon(m_defaultOpenIcon);
233:                    }
234:
235:                    return super.getTreeCellRendererComponent(tree, object,
236:                            isSelected, isExpanded, isLeaf, row, hasFocus);
237:                }
238:            }
239:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.