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


001:        package org.acm.seguin.pretty;
002:
003:        import java.io.PrintWriter;
004:        import java.util.Vector;
005:        import org.acm.seguin.util.FileSettings;
006:        import org.acm.seguin.util.MissingSettingsException;
007:
008:        /**
009:         *  Stores a queue of lines to be printed
010:         *
011:         *@author    Chris Seguin
012:         */
013:        public class LineQueue {
014:            /**
015:             *  The current line number
016:             */
017:            protected int lineNumber;
018:            private Vector list;
019:            private PrintWriter output;
020:            private int absoluteSpace;
021:            private int incrementalSpace;
022:            private boolean ownline;
023:            private boolean sharedIncremental;
024:            private boolean ownlineCode;
025:            private StringBuffer buffer;
026:            private String endOfLine;
027:
028:            /**
029:             *  Constructor for the LineQueue object
030:             *
031:             *@param  init  Description of Parameter
032:             */
033:            public LineQueue(PrintWriter init) {
034:                output = init;
035:                list = new Vector();
036:                buffer = new StringBuffer();
037:
038:                FileSettings bundle = FileSettings.getRefactoryPrettySettings();
039:                try {
040:                    absoluteSpace = bundle
041:                            .getInteger("singleline.comment.absoluteindent");
042:                } catch (MissingSettingsException mse) {
043:                    absoluteSpace = 0;
044:                }
045:
046:                try {
047:                    incrementalSpace = bundle
048:                            .getInteger("singleline.comment.incrementalindent");
049:                } catch (MissingSettingsException mse) {
050:                    incrementalSpace = 0;
051:                }
052:
053:                try {
054:                    ownline = bundle.getBoolean("singleline.comment.ownline");
055:                } catch (MissingSettingsException mse) {
056:                    ownline = true;
057:                }
058:
059:                try {
060:                    String temp = bundle
061:                            .getString("singleline.comment.indentstyle.shared");
062:                    sharedIncremental = temp.equalsIgnoreCase("incremental");
063:                } catch (MissingSettingsException mse) {
064:                    sharedIncremental = true;
065:                }
066:
067:                try {
068:                    String temp = bundle
069:                            .getString("singleline.comment.indentstyle.ownline");
070:                    ownlineCode = temp.equalsIgnoreCase("code");
071:                } catch (MissingSettingsException mse) {
072:                    ownlineCode = true;
073:                }
074:
075:                try {
076:                    String temp = bundle.getString("end.line");
077:                    if (temp.equalsIgnoreCase("CRNL")
078:                            || temp.equalsIgnoreCase("CRLF")
079:                            || temp.equalsIgnoreCase("DOS")) {
080:                        endOfLine = "\r\n";
081:                    } else if (temp.equalsIgnoreCase("CR")
082:                            || temp.equalsIgnoreCase("MAC")) {
083:                        endOfLine = "\r";
084:                    } else if (temp.equalsIgnoreCase("NL")
085:                            || temp.equalsIgnoreCase("LF")
086:                            || temp.equalsIgnoreCase("UNIX")) {
087:                        endOfLine = "\n";
088:                    } else {
089:                        endOfLine = "\n";
090:                    }
091:                } catch (MissingSettingsException mse) {
092:                    endOfLine = "\n";
093:                }
094:
095:                lineNumber = 1;
096:            }
097:
098:            /**
099:             *  Sets the AbsoluteCommentSpacing attribute of the LineQueue object
100:             *
101:             *@param  value  The new AbsoluteCommentSpacing value
102:             */
103:            public void setAbsoluteCommentSpacing(int value) {
104:                absoluteSpace = value;
105:            }
106:
107:            /**
108:             *  Sets the IncrementalCommentSpacing attribute of the LineQueue object
109:             *
110:             *@param  value  The new IncrementalCommentSpacing value
111:             */
112:            public void setIncrementalCommentSpacing(int value) {
113:                incrementalSpace = value;
114:            }
115:
116:            /**
117:             *  Sets the Ownline attribute of the LineQueue object
118:             *
119:             *@param  value  The new Ownline value
120:             */
121:            public void setOwnline(boolean value) {
122:                ownline = value;
123:            }
124:
125:            /**
126:             *  Sets the SharedIncremental attribute of the LineQueue object
127:             *
128:             *@param  value  The new SharedIncremental value
129:             */
130:            public void setSharedIncremental(boolean value) {
131:                sharedIncremental = value;
132:            }
133:
134:            /**
135:             *  Sets the OwnlineCode attribute of the LineQueue object
136:             *
137:             *@param  value  The new OwnlineCode value
138:             */
139:            public void setOwnlineCode(boolean value) {
140:                ownlineCode = value;
141:            }
142:
143:            /**
144:             *  Returns the current line
145:             *
146:             *@return    the line number
147:             */
148:            public int getCurrentLine() {
149:                return lineNumber;
150:            }
151:
152:            /**
153:             *  Description of the Method
154:             *
155:             *@param  value  Description of Parameter
156:             */
157:            public void println(String value) {
158:                if (value.length() > 0) {
159:                    flush();
160:                }
161:                list.addElement(value);
162:            }
163:
164:            /**
165:             *  Appends a comment to the file
166:             *
167:             *@param  comment  the comment to append
168:             *@param  prefix   the prefix to the line
169:             */
170:            public void appendSingleLineComment(String comment, String prefix) {
171:                if (list.size() > 0) {
172:                    if (ownline) {
173:                        list.insertElementAt(makeLine(prefix, comment), 1);
174:                        flushFirstLine();
175:                    } else {
176:                        updateLine(comment, prefix);
177:                    }
178:                } else {
179:                    println(makeLine(prefix, comment));
180:                }
181:                flushFirstLine();
182:            }
183:
184:            /**
185:             *  Appends a comment to the file
186:             *
187:             *@param  comment  the comment to append
188:             *@param  prefix   the prefix to the line
189:             */
190:            public void appendCategoryComment(String comment, String prefix) {
191:                if (list.size() > 0) {
192:                    String first = (String) list.elementAt(0);
193:                    if (first.length() > 0) {
194:                        list.insertElementAt(prefix + comment, 1);
195:                        flushFirstLine();
196:                    } else {
197:                        list.insertElementAt(prefix + comment, 0);
198:                    }
199:                } else {
200:                    println(prefix + comment);
201:                }
202:                flushFirstLine();
203:            }
204:
205:            /**
206:             *  Flushes the first line in the cache
207:             */
208:            public void flushFirstLine() {
209:                if (list.size() > 0) {
210:                    writeln((String) list.elementAt(0));
211:                    list.removeElementAt(0);
212:                }
213:            }
214:
215:            /**
216:             *  Flushes all the lines in the buffer
217:             */
218:            public void flush() {
219:                int last = list.size();
220:                for (int ndx = 0; ndx < last; ndx++) {
221:                    writeln((String) list.elementAt(ndx));
222:                }
223:                list.removeAllElements();
224:                output.flush();
225:            }
226:
227:            /**
228:             *  Gets the Output attribute of the LineQueue object
229:             *
230:             *@return    The Output value
231:             */
232:            protected PrintWriter getOutput() {
233:                return output;
234:            }
235:
236:            /**
237:             *  Writes a single line to the output stream
238:             *
239:             *@param  value  Description of Parameter
240:             */
241:            protected void writeln(String value) {
242:                buffer.setLength(0);
243:                buffer.append(value);
244:                int length = value.length();
245:                while ((length > 0)
246:                        && Character.isWhitespace(buffer.charAt(length - 1))) {
247:                    length--;
248:                    buffer.setLength(length);
249:                }
250:                output.print(buffer.toString());
251:                output.print(endOfLine);
252:
253:                //  Next line
254:                lineNumber++;
255:            }
256:
257:            /**
258:             *  Updates the line
259:             *
260:             *@param  comment  the comment to update
261:             *@param  prefix   Description of Parameter
262:             */
263:            private void updateLine(String comment, String prefix) {
264:                String first = (String) list.elementAt(0);
265:
266:                if (first.length() == 0) {
267:                    list.setElementAt(makeLine(prefix, comment), 0);
268:                    return;
269:                }
270:
271:                if (!sharedIncremental) {
272:                    list.setElementAt(makeLine(first, comment), 0);
273:                    return;
274:                }
275:
276:                StringBuffer buffer = new StringBuffer(first);
277:                for (int ndx = 0; ndx < incrementalSpace; ndx++) {
278:                    buffer.append(" ");
279:                }
280:                buffer.append(comment);
281:
282:                list.setElementAt(buffer.toString(), 0);
283:            }
284:
285:            /**
286:             *  Creates a line
287:             *
288:             *@param  prefix   the prefix of the comment
289:             *@param  comment  the comment
290:             *@return          a string with the correct length
291:             */
292:            private String makeLine(String prefix, String comment) {
293:                //if (prefix.length() == 0) {
294:                //	return comment;
295:                //}
296:
297:                String trim = prefix.trim();
298:                boolean hasNoCode = ((trim == null) || (trim.length() == 0));
299:                boolean indent = (hasNoCode && !ownlineCode)
300:                        || (!hasNoCode && !sharedIncremental);
301:
302:                if (indent) {
303:                    StringBuffer buffer;
304:                    if (!hasNoCode) {
305:                        buffer = new StringBuffer(prefix);
306:                    } else {
307:                        buffer = new StringBuffer();
308:                    }
309:
310:                    while (buffer.length() < absoluteSpace) {
311:                        buffer.append(" ");
312:                    }
313:                    buffer.append(comment);
314:
315:                    return buffer.toString();
316:                } else {
317:                    return prefix + comment;
318:                }
319:            }
320:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.