Source Code Cross Referenced for DirectoryTableModel.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 javax.swing.event.TreeSelectionEvent;
004:        import javax.swing.event.TreeSelectionListener;
005:        import javax.swing.table.DefaultTableModel;
006:        import javax.swing.tree.TreePath;
007:        import java.io.File;
008:        import java.io.FileFilter;
009:        import java.io.FileInputStream;
010:        import java.io.FileNotFoundException;
011:        import java.io.IOException;
012:        import java.io.InputStreamReader;
013:        import java.text.DateFormat;
014:        import java.text.DecimalFormat;
015:        import java.text.DecimalFormatSymbols;
016:        import java.util.Date;
017:        import java.util.Vector;
018:
019:        /**
020:         *
021:         * @author Donald A. Leckie
022:         * @since August 17, 2002
023:         * @version $Revision: 1.1 $, $Date: 2003/07/29 20:51:59 $
024:         */
025:        class DirectoryTableModel extends DefaultTableModel {
026:            private DateFormat m_dateFormat;
027:            private DecimalFormat m_decimalFormat;
028:            private String m_fileExtension;
029:
030:            //Constants
031:            protected static final int FILE_NAME_COLUMN = 0;
032:            protected static final int FILE_SIZE_COLUMN = 1;
033:            protected static final int FILE_LAST_MODIFIED_COLUMN = 2;
034:            private final int FILE_COLUMN = 3; // not a visible column
035:
036:            /**
037:             *********************************************************************************
038:             *
039:             */
040:            protected DirectoryTableModel(DirectoryTree directoryTree,
041:                    String fileExtension) {
042:                super (createData(), createColumnNames());
043:
044:                DecimalFormatSymbols decimalFormatSymbols;
045:                StringBuffer buffer;
046:                String pattern;
047:
048:                m_fileExtension = fileExtension.toLowerCase();
049:                m_dateFormat = DateFormat.getDateTimeInstance();
050:                decimalFormatSymbols = new DecimalFormatSymbols();
051:                buffer = new StringBuffer(25);
052:
053:                buffer.append('#');
054:                buffer.append(decimalFormatSymbols.getGroupingSeparator());
055:                buffer.append('#');
056:                buffer.append('#');
057:                buffer.append(decimalFormatSymbols.getDigit());
058:                buffer.append(" lines");
059:
060:                pattern = buffer.toString();
061:                m_decimalFormat = new DecimalFormat(pattern,
062:                        decimalFormatSymbols);
063:                new DirectoryTreeSelectionListener(directoryTree);
064:            }
065:
066:            /**
067:             ********************************************************************************
068:             *
069:             * @return
070:             */
071:            private static Vector createData() {
072:                return new Vector();
073:            }
074:
075:            /**
076:             ********************************************************************************
077:             *
078:             * @return
079:             */
080:            private static Vector createColumnNames() {
081:                Vector row = new Vector(2);
082:
083:                row.add("File Name");
084:                row.add("Size");
085:                row.add("Last Modified");
086:
087:                return row;
088:            }
089:
090:            /**
091:             ********************************************************************************
092:             *
093:             * @return
094:             */
095:            protected File getFile(int row) {
096:                if ((row >= 0) && (row < getRowCount())) {
097:                    return (File) getValueAt(row, FILE_COLUMN);
098:                }
099:
100:                return null;
101:            }
102:
103:            /**
104:             *******************************************************************************
105:             *
106:             * @param row
107:             * @param column
108:             *
109:             * @return
110:             */
111:            public boolean isCellEditable(int row, int column) {
112:                return false;
113:            }
114:
115:            /**
116:             *******************************************************************************
117:             *******************************************************************************
118:             *******************************************************************************
119:             */
120:            private class DirectoryTreeSelectionListener implements 
121:                    TreeSelectionListener {
122:
123:                /**
124:                 *************************************************************************
125:                 *
126:                 */
127:                private DirectoryTreeSelectionListener(
128:                        DirectoryTree directoryTree) {
129:                    directoryTree.addTreeSelectionListener(this );
130:                }
131:
132:                /**
133:                 ***************************************************************************
134:                 *
135:                 * @param directoryTree
136:                 */
137:                public void valueChanged(TreeSelectionEvent event) {
138:                    TreePath treePath = event.getPath();
139:                    DirectoryTreeNode treeNode = (DirectoryTreeNode) treePath
140:                            .getLastPathComponent();
141:                    Object userObject = treeNode.getUserObject();
142:                    Vector rows = getDataVector();
143:
144:                    for (int n = 0; n < rows.size(); n++) {
145:                        ((Vector) rows.get(n)).clear();
146:                    }
147:
148:                    rows.clear();
149:
150:                    if (userObject instanceof  File) {
151:                        File directory;
152:                        File[] files;
153:
154:                        directory = (File) userObject;
155:                        files = directory.listFiles(new FilesFilter());
156:
157:                        if (files != null) {
158:                            for (int n1 = 0; n1 < files.length; n1++) {
159:                                Vector row = new Vector(3);
160:                                String fileName = files[n1].getName();
161:                                int lineCount = countLines(files[n1]);
162:                                String size = m_decimalFormat.format(lineCount);
163:                                Date date = new Date(files[n1].lastModified());
164:                                String lastModified = m_dateFormat.format(date);
165:
166:                                row.add(fileName);
167:                                row.add(size);
168:                                row.add(lastModified);
169:                                row.add(files[n1]);
170:
171:                                rows.add(row);
172:                            }
173:                        }
174:                    }
175:
176:                    fireTableDataChanged();
177:                }
178:
179:                /**
180:                 **************************************************************************
181:                 *
182:                 * @param file
183:                 *
184:                 * @return
185:                 */
186:                private int countLines(File file) {
187:                    int lineCount = 0;
188:                    InputStreamReader reader = null;
189:
190:                    try {
191:                        char[] buffer;
192:
193:                        buffer = new char[10000];
194:                        reader = new InputStreamReader(
195:                                new FileInputStream(file));
196:
197:                        while (reader.ready()) {
198:                            int numberOfChars = reader.read(buffer);
199:
200:                            for (int n = 0; n < numberOfChars; n++) {
201:                                if (buffer[n] == '\n') {
202:                                    lineCount++;
203:                                }
204:                            }
205:                        }
206:                    } catch (FileNotFoundException exception) {
207:                        lineCount = 0;
208:                    } catch (IOException exception) {
209:                        lineCount = 0;
210:                    } finally {
211:                        if (reader != null) {
212:                            try {
213:                                reader.close();
214:                            } catch (IOException exception) {
215:                            }
216:                        }
217:                    }
218:
219:                    return lineCount;
220:                }
221:            }
222:
223:            /**
224:             *******************************************************************************
225:             *******************************************************************************
226:             *******************************************************************************
227:             */
228:            private class FilesFilter implements  FileFilter {
229:
230:                public boolean accept(File file) {
231:                    if (file.isFile() && (file.isHidden() == false)) {
232:                        String fileName = file.getName().toLowerCase();
233:
234:                        return (fileName.endsWith(m_fileExtension));
235:                    }
236:
237:                    return false;
238:
239:                }
240:            }
241:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.