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


001:        /*
002:         *  Author:  Chris Seguin
003:         *
004:         *  This software has been developed under the copyleft
005:         *  rules of the GNU General Public License.  Please
006:         *  consult the GNU General Public License for more
007:         *  details about use and distribution of this software.
008:         */
009:        package org.acm.seguin.tools.builder;
010:
011:        import java.io.File;
012:        import javax.swing.JFileChooser;
013:        import javax.swing.filechooser.FileFilter;
014:        import org.acm.seguin.awt.ExceptionPrinter;
015:        import org.acm.seguin.awt.GUIExceptionPrinter;
016:        import org.acm.seguin.awt.TextExceptionPrinter;
017:        import org.acm.seguin.io.AllFileFilter;
018:        import org.acm.seguin.io.DirectoryTreeTraversal;
019:        import org.acm.seguin.io.ExtensionFileFilter;
020:        import org.acm.seguin.io.FileCopy;
021:        import org.acm.seguin.pretty.PrettyPrintFile;
022:        import org.acm.seguin.tools.RefactoryInstaller;
023:        import org.acm.seguin.util.FileSettings;
024:        import org.acm.seguin.util.MissingSettingsException;
025:
026:        /**
027:         *  Traverses a directory structure and performs all refactorings on the files.
028:         *
029:         * @author     Chris Seguin
030:         * @created    May 12, 1999
031:         */
032:        public class PrettyPrinter extends DirectoryTreeTraversal {
033:            //  Instance Variables
034:            private PrettyPrintFile ppf;
035:
036:            /**
037:             *  Creates a refactory
038:             *
039:             * @param  init   the initial directory or file
040:             * @param  quiet  Description of Parameter
041:             */
042:            public PrettyPrinter(String init, boolean quiet) {
043:                super (init);
044:
045:                if (init == null) {
046:                    return;
047:                }
048:
049:                ppf = new PrettyPrintFile();
050:                ppf.setAsk(!quiet && (new File(init)).isDirectory());
051:            }
052:
053:            /**
054:             *  Determines if this file should be handled by this traversal
055:             *
056:             * @param  currentFile  the current file
057:             * @return              true if the file should be handled
058:             */
059:            protected boolean isTarget(File currentFile) {
060:                return (currentFile.getName().endsWith(".java"));
061:            }
062:
063:            /**
064:             *  Visits the current file
065:             *
066:             * @param  currentFile  the current file
067:             */
068:            protected void visit(File currentFile) {
069:                if (ppf.isApplicable(currentFile)) {
070:                    System.out.println("Applying the Pretty Printer:  "
071:                            + currentFile.getPath());
072:                    makeBackup(currentFile);
073:                    ppf.apply(currentFile);
074:                }
075:            }
076:
077:            /**
078:             *  Make a backup of the file before applying the pretty printer
079:             *
080:             * @param  currentFile  Description of Parameter
081:             */
082:            private void makeBackup(File currentFile) {
083:                String backupExt;
084:                try {
085:                    backupExt = FileSettings.getRefactoryPrettySettings()
086:                            .getString("pretty.printer.backup.ext");
087:                    backupExt = (backupExt == null) ? "" : backupExt.trim();
088:                } catch (MissingSettingsException mse) {
089:                    backupExt = "";
090:                }
091:
092:                if ((backupExt != null) && (backupExt.length() > 0)) {
093:                    File parentDir = currentFile.getParentFile();
094:                    String name = currentFile.getName();
095:                    File dest = new File(parentDir, name + backupExt);
096:                    (new FileCopy(currentFile, dest, false)).run();
097:                }
098:            }
099:
100:            /**
101:             *  The main program
102:             *
103:             * @param  args  Description of Parameter
104:             */
105:            public static void main(String[] args) {
106:                try {
107:                    int lastOption = -1;
108:                    boolean quiet = false;
109:
110:                    for (int ndx = 0; ndx < args.length; ndx++) {
111:                        if (args[ndx].equals("-quiet")
112:                                || args[ndx].equals("-u")) {
113:                            quiet = true;
114:                            lastOption = ndx;
115:                            ExceptionPrinter
116:                                    .register(new TextExceptionPrinter());
117:                        } else if (args[ndx].equals("-?")
118:                                || args[ndx].equalsIgnoreCase("-h")
119:                                || args[ndx].equalsIgnoreCase("-help")) {
120:                            printHelpMessage();
121:                            return;
122:                        } else if (args[ndx].equals("-config")) {
123:                            String dir = args[ndx + 1];
124:                            ndx++;
125:                            FileSettings.setSettingsRoot(dir);
126:                        }
127:                    }
128:
129:                    //  Make sure everything is installed properly
130:                    (new RefactoryInstaller(false)).run();
131:
132:                    if (lastOption + 1 >= args.length) {
133:                        // no more arguments left
134:                        if (quiet) {
135:                            prettyPrinter(quiet);
136:                        } else {
137:                            prettyPrinter(System.getProperty("user.dir"), quiet);
138:                        }
139:                    } else {
140:                        // process remaining arguments as file / dir names
141:                        for (int ndx = lastOption + 1; ndx < args.length; ++ndx) {
142:                            prettyPrinter(args[ndx], quiet);
143:                        }
144:                    }
145:                } catch (Throwable thrown) {
146:                    thrown.printStackTrace(System.out);
147:                    System.exit(1);
148:                }
149:
150:                //  Exit
151:                System.exit(ExceptionPrinter.getExceptionsPrinted());
152:            }
153:
154:            /**
155:             *  Refactor the current file
156:             *
157:             * @param  filename  Description of Parameter
158:             * @param  quiet     Description of Parameter
159:             */
160:            public static void prettyPrinter(String filename, boolean quiet) {
161:                (new PrettyPrinter(filename, quiet)).run();
162:            }
163:
164:            /**
165:             *  Refactor the current file
166:             *
167:             * @param  quiet  Description of Parameter
168:             */
169:            public static void prettyPrinter(boolean quiet) {
170:                JFileChooser chooser = new JFileChooser();
171:
172:                //  Create the java file filter
173:                ExtensionFileFilter filter = new ExtensionFileFilter();
174:                filter.addExtension(".java");
175:                filter.setDescription("Java Source Files (.java)");
176:                chooser.setFileFilter(filter);
177:
178:                //  Add other file filters - All
179:                FileFilter allFilter = new AllFileFilter();
180:                chooser.addChoosableFileFilter(allFilter);
181:
182:                //  Set it so that files and directories can be selected
183:                chooser
184:                        .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
185:
186:                //  Set the directory to the current directory
187:                chooser.setCurrentDirectory(new File(System
188:                        .getProperty("user.dir")));
189:
190:                //  Get the user's selection
191:                int returnVal = chooser.showOpenDialog(null);
192:                if (returnVal == JFileChooser.APPROVE_OPTION) {
193:                    (new PrettyPrinter(chooser.getSelectedFile()
194:                            .getAbsolutePath(), quiet)).run();
195:                }
196:            }
197:
198:            /**  Print a help message  */
199:            private static void printHelpMessage() {
200:                System.out
201:                        .println("Syntax:  java PrettyPrinter file   //  means refactor this file");
202:                System.out
203:                        .println("   OR    java PrettyPrinter [-quiet|-u] dir   //  means refactor this directory");
204:                System.out
205:                        .println("   OR    java PrettyPrinter [-quiet|-u]   //  means refactor the current directory");
206:                System.out
207:                        .println("  the -quiet or the -u flag tells the pretty printer not to prompt the user");
208:            }
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.