Source Code Cross Referenced for EditorDebug.java in  » Swing-Library » abeille-forms-designer » org » netbeans » editor » 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 » Swing Library » abeille forms designer » org.netbeans.editor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *                 Sun Public License Notice
003:         * 
004:         * The contents of this file are subject to the Sun Public License
005:         * Version 1.0 (the "License"). You may not use this file except in
006:         * compliance with the License. A copy of the License is available at
007:         * http://www.sun.com/
008:         * 
009:         * The Original Code is NetBeans. The Initial Developer of the Original
010:         * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
011:         * Microsystems, Inc. All Rights Reserved.
012:         */
013:
014:        package org.netbeans.editor;
015:
016:        import java.util.Iterator;
017:        import java.util.List;
018:
019:        import javax.swing.text.BadLocationException;
020:        import javax.swing.text.JTextComponent;
021:        import javax.swing.text.Segment;
022:
023:        /**
024:         * Various internal tests
025:         * 
026:         * @author Miloslav Metelka
027:         * @version 0.10
028:         */
029:
030:        public class EditorDebug {
031:
032:            private EditorDebug() {
033:                // instance creation has no sense
034:            }
035:
036:            public static void dumpPlanes(BaseDocument doc) {
037:                Class markClasses[] = new Class[] { MarkFactory.LineMark.class,
038:                        MarkFactory.CaretMark.class,
039:                        MarkFactory.DrawMark.class,
040:                        MarkFactory.SyntaxMark.class, Mark.class };
041:                char markChars[] = new char[] { 'L', 'C', 'D', 'S', 'B' };
042:                System.out
043:                        .println("--------------------------- DUMP OF MARK PLANES --------------------------------"); // NOI18N
044:                System.out.println("Mark legend:\nD - DrawMark\n" // NOI18N
045:                        + "S - SyntaxMark\nB - BaseMark\n" // NOI18N
046:                        + "L - LineMark\nC - CaretMark"); // NOI18N
047:                System.out.println(doc.op.markPlanesToString(markClasses,
048:                        markChars));
049:                System.out
050:                        .println("--------------------------------------------------------------------------------\n"); // NOI18N
051:            }
052:
053:            public static void dumpSyntaxMarks(final BaseDocument doc) {
054:                System.out
055:                        .println("--------------------------- DUMP OF SYNTAX MARKS --------------------------------"); // NOI18N
056:                final int docLen = doc.getLength();
057:                // Suspended because of docmarks rewrite due to #11692
058:                /*
059:                 * doc.op.renderMarks( new DocMarks.Renderer() { public void render() {
060:                 * int markCnt = getMarkCnt(); int index = 0; int pos = 0; int lastPos =
061:                 * pos; int lastMarkPos = 0; int maxMarkDistance = 0; int
062:                 * minMarkDistance = docLen; Mark markArray[] = getMarkArray();
063:                 * SyntaxSeg.Slot slot = SyntaxSeg.getFreeSlot(); Syntax syntax =
064:                 * doc.getFreeSyntax();
065:                 * 
066:                 * try { syntax.load(null, slot.array, 0, 0, false, 0); while (index <
067:                 * markCnt) { Mark mark = markArray[index++]; pos += getRelPos(mark); if
068:                 * (mark instanceof MarkFactory.SyntaxMark) { MarkFactory.SyntaxMark
069:                 * syntaxMark = (MarkFactory.SyntaxMark)mark; int delta = pos -
070:                 * lastMarkPos; if (delta > maxMarkDistance) { maxMarkDistance = delta; }
071:                 * if (delta < minMarkDistance) { minMarkDistance = delta; } lastMarkPos =
072:                 * pos;
073:                 * 
074:                 * int preScan = syntax.getPreScan(); int loadPos = lastPos - preScan;
075:                 * int scanLen = pos - loadPos; try { slot.load(doc, loadPos, scanLen); }
076:                 * catch (BadLocationException e) { e.printStackTrace(); }
077:                 * syntax.relocate(slot.array, slot.offset + preScan, scanLen - preScan,
078:                 * (pos == docLen), pos);
079:                 * 
080:                 * while (syntax.nextToken() != null) { }
081:                 * 
082:                 * lastPos = pos; try { System.out.println(((syntaxMark ==
083:                 * doc.op.eolMark) ? "!!EOLMark!!" : "syntaxMark:") // NOI18N + "
084:                 * getOffset()=" + Utilities.debugPosition(doc, syntaxMark.getOffset()) //
085:                 * NOI18N + ", getLine()=" + syntaxMark.getLine() // NOI18N + ", " +
086:                 * syntaxMark // NOI18N + ",\n StateInfo=" + syntaxMark.getStateInfo() //
087:                 * NOI18N + ",\n Syntax:" + syntax); // NOI18N } catch
088:                 * (InvalidMarkException e) { e.printStackTrace(); } } } } finally {
089:                 * doc.releaseSyntax(syntax); SyntaxSeg.releaseSlot(slot); }
090:                 * 
091:                 * System.out.println("Maximum mark distance is " + maxMarkDistance //
092:                 * NOI18N + "\nMinimum mark distance is " + minMarkDistance); // NOI18N } } );
093:                 */
094:                System.out
095:                        .println("--------------------------------------------------------------------------------\n"); // NOI18N
096:            }
097:
098:            public static void test(JTextComponent component) {
099:                BaseTextUI ui = ((BaseTextUI) component.getUI());
100:                BaseView view = (BaseView) ui.getRootView(component);
101:                view = (BaseView) view.getView(0);
102:                final BaseDocument doc = (BaseDocument) component.getDocument();
103:                EditorUI editorUI = ui.getEditorUI();
104:                final int docLen = doc.getLength();
105:
106:                System.out
107:                        .println("\n------------------------- Registry --------------------------------"); // NOI18N
108:                System.out.println(Registry.registryToString());
109:
110:                System.out
111:                        .println("\n------------------------- DEBUGGING INFORMATION --------------------------------"); // NOI18N
112:                String buf = "Document: " + doc // NOI18N
113:                        + "\nview.mainHeight=" + ((LeafView) view).mainHeight // NOI18N
114:                        + "\nDoubleBuffering=" + component.isDoubleBuffered(); // NOI18N
115:                buf += "\ncomponent.getLocation()=" + component.getLocation() // NOI18N
116:                        + "\ncomponent.getSize()=" + component.getSize() // NOI18N
117:                        + "\nvirtualSize=" + editorUI.virtualSize; // NOI18N
118:                buf += "\nEditorUI LAYERS:\n" + editorUI.getDrawLayerList(); // NOI18N
119:                System.out.println(buf);
120:
121:                System.out.println(doc.op.infoToString());
122:
123:                buf = "\n------------------------ CR occurence test ------------------------\n"; // NOI18N
124:                try {
125:                    char chars[] = doc.getChars(0, docLen);
126:                    int i;
127:                    for (i = 0; i < docLen; i++) {
128:                        if (chars[i] == '\r') {
129:                            buf += "CR found at pos=" + i + ", line="
130:                                    + doc.op.getLine(i) + "\n"; // NOI18N
131:                            break;
132:                        }
133:                    }
134:                    if (i == docLen) {
135:                        buf += "No CR found. CR occurence test suceeded."; // NOI18N
136:                    }
137:                } catch (BadLocationException e) {
138:                    e.printStackTrace();
139:                }
140:                System.out.println(buf);
141:            }
142:
143:            public static void checkSettings(Class kitClass) throws Exception {
144:                int readBufferSize = SettingsUtil.getInteger(kitClass,
145:                        SettingsNames.READ_BUFFER_SIZE,
146:                        SettingsDefaults.defaultReadBufferSize);
147:
148:                int writeBufferSize = SettingsUtil.getInteger(kitClass,
149:                        SettingsNames.WRITE_BUFFER_SIZE,
150:                        SettingsDefaults.defaultWriteBufferSize);
151:
152:                int readMarkDistance = SettingsUtil.getInteger(kitClass,
153:                        SettingsNames.READ_MARK_DISTANCE,
154:                        SettingsDefaults.defaultReadMarkDistance);
155:
156:                int markDistance = SettingsUtil.getInteger(kitClass,
157:                        SettingsNames.MARK_DISTANCE,
158:                        SettingsDefaults.defaultMarkDistance);
159:
160:                int maxMarkDistance = SettingsUtil.getInteger(kitClass,
161:                        SettingsNames.MAX_MARK_DISTANCE,
162:                        SettingsDefaults.defaultMaxMarkDistance);
163:
164:                int minMarkDistance = SettingsUtil.getInteger(kitClass,
165:                        SettingsNames.MIN_MARK_DISTANCE,
166:                        SettingsDefaults.defaultMinMarkDistance);
167:
168:                int syntaxUpdateBatchSize = SettingsUtil.getInteger(kitClass,
169:                        SettingsNames.SYNTAX_UPDATE_BATCH_SIZE,
170:                        SettingsDefaults.defaultSyntaxUpdateBatchSize);
171:
172:                // Now perform checks
173:                if (maxMarkDistance < markDistance) {
174:                    throw new Exception("maxMarkDistance=" + maxMarkDistance // NOI18N
175:                            + " < markDistance=" + markDistance); // NOI18N
176:                }
177:
178:                if (markDistance < minMarkDistance) {
179:                    throw new Exception("markDistance=" + markDistance // NOI18N
180:                            + " < minMarkDistance=" + minMarkDistance); // NOI18N
181:                }
182:
183:                if (readMarkDistance < minMarkDistance) {
184:                    throw new Exception("readMarkDistance=" + readMarkDistance // NOI18N
185:                            + " < minMarkDistance=" + minMarkDistance); // NOI18N
186:                }
187:
188:                if (syntaxUpdateBatchSize < maxMarkDistance) {
189:                    throw new Exception("syntaxUpdateBatchSize="
190:                            + syntaxUpdateBatchSize // NOI18N
191:                            + " < maxMarkDistance=" + maxMarkDistance); // NOI18N
192:                }
193:
194:            }
195:
196:            /** Replace '\n', '\r' and '\t' in the string so they are identifiable. */
197:            public static String debugString(String s) {
198:                return (s != null) ? debugChars(s.toCharArray(), 0, s.length())
199:                        : "NULL STRING";
200:            }
201:
202:            public static String debugChars(Segment seg) {
203:                return debugChars(seg.array, seg.offset, seg.count);
204:            }
205:
206:            public static String debugChars(char chars[]) {
207:                return debugChars(chars, 0, chars.length);
208:            }
209:
210:            /** Replace '\n', '\r' and '\t' in the char array so they are identifiable. */
211:            public static String debugChars(char chars[], int offset, int len) {
212:                if (len < 0) {
213:                    return "EditorDebug.debugChars() !ERROR! len=" + len
214:                            + " < 0"; // NOI18N
215:                }
216:                if (offset < 0) {
217:                    return "EditorDebug.debugChars() !ERROR! offset=" + offset
218:                            + " < 0"; // NOI18N
219:                }
220:                if (offset + len > chars.length) {
221:                    return "EditorDebug.debugChars() !ERROR! offset=" + offset
222:                            + " + len=" + len // NOI18N
223:                            + " > chars.length=" + chars.length; // NOI18N
224:                }
225:                StringBuffer sb = new StringBuffer(len);
226:                int endOffset = offset + len;
227:                for (; offset < endOffset; offset++) {
228:                    switch (chars[offset]) {
229:                    case '\n':
230:                        sb.append("\\n"); // NOI18N
231:                        break;
232:                    case '\t':
233:                        sb.append("\\t"); // NOI18N
234:                        break;
235:                    case '\r':
236:                        sb.append("\\r"); // NOI18N
237:                        break;
238:                    default:
239:                        sb.append(chars[offset]);
240:                    }
241:                }
242:                return sb.toString();
243:            }
244:
245:            public static String debugChar(char ch) {
246:                switch (ch) {
247:                case '\n':
248:                    return "\\n"; // NOI18N
249:                case '\t':
250:                    return "\\t"; // NOI18N
251:                case '\r':
252:                    return "\\r"; // NOI18N
253:                default:
254:                    return String.valueOf(ch);
255:                }
256:            }
257:
258:            public static String debugPairs(int[] pairs) {
259:                String ret;
260:                if (pairs == null) {
261:                    ret = "Null pairs"; // NOI18N
262:                } else if (pairs.length == 0) {
263:                    ret = "No pairs"; // NOI18N
264:                } else {
265:                    StringBuffer sb = new StringBuffer();
266:                    for (int i = 0; i < pairs.length; i += 2) {
267:                        sb.append('[');
268:                        sb.append(pairs[i]);
269:                        sb.append(", "); // NOI18N
270:                        sb.append(pairs[i + 1]);
271:                        if (i < pairs.length - 1) {
272:                            sb.append("]\n"); // NOI18N
273:                        }
274:                    }
275:                    ret = sb.toString();
276:                }
277:
278:                return ret;
279:            }
280:
281:            public static String debugArray(Object[] array) {
282:                String ret;
283:                if (array == null) {
284:                    ret = "Null array"; // NOI18N
285:                } else if (array.length == 0) {
286:                    ret = "Empty array"; // NOI18N
287:                } else {
288:                    StringBuffer sb = new StringBuffer();
289:                    for (int i = 0; i < array.length; i++) {
290:                        sb.append('[');
291:                        sb.append(i);
292:                        sb.append("]="); // NOI18N
293:                        sb.append(array[i]);
294:                        if (i != array.length - 1) {
295:                            sb.append('\n');
296:                        }
297:                    }
298:                    ret = sb.toString();
299:                }
300:                return ret;
301:            }
302:
303:            public static String debugArray(int[] array) {
304:                String ret;
305:                if (array == null) {
306:                    ret = "Null array"; // NOI18N
307:                } else if (array.length == 0) {
308:                    ret = "Empty array"; // NOI18N
309:                } else {
310:                    StringBuffer sb = new StringBuffer();
311:                    for (int i = 0; i < array.length; i++) {
312:                        sb.append('[');
313:                        sb.append(i);
314:                        sb.append("]="); // NOI18N
315:                        sb.append(array[i]);
316:                        if (i != array.length - 1) {
317:                            sb.append('\n');
318:                        }
319:                    }
320:                    ret = sb.toString();
321:                }
322:                return ret;
323:            }
324:
325:            public static String debugBlocks(BaseDocument doc, int[] blocks) {
326:                String ret;
327:                if (blocks == null) {
328:                    ret = "Null blocks"; // NOI18N
329:                } else if (blocks.length == 0) {
330:                    ret = "Empty blocks"; // NOI18N
331:                } else if (blocks.length % 2 != 0) {
332:                    ret = "Blocks.length=" + blocks.length + " is not even!"; // NOI18N
333:                } else {
334:                    StringBuffer sb = new StringBuffer();
335:                    for (int i = 0; i < blocks.length; i += 2) {
336:                        sb.append('[');
337:                        sb.append(i);
338:                        sb.append("]=("); // NOI18N
339:                        sb.append(blocks[i]);
340:                        sb.append(", "); // NOI18N
341:                        sb.append(blocks[i + 1]);
342:                        sb.append(") or ("); // NOI18N
343:                        sb.append(Utilities.debugPosition(doc, blocks[i]));
344:                        sb.append(", "); // NOI18N
345:                        sb.append(Utilities.debugPosition(doc, blocks[i + 1]));
346:                        sb.append(')');
347:
348:                        if (i != blocks.length - 1) {
349:                            sb.append('\n');
350:                        }
351:                    }
352:                    ret = sb.toString();
353:                }
354:                return ret;
355:            }
356:
357:            public static String debugList(List l) {
358:                String ret;
359:                if (l == null) {
360:                    ret = "Null list"; // NOI18N
361:                } else if (l.size() == 0) {
362:                    ret = "Empty list"; // NOI18N
363:                } else {
364:                    int cnt = l.size();
365:                    StringBuffer sb = new StringBuffer();
366:                    for (int i = 0; i < cnt; i++) {
367:                        sb.append('[');
368:                        sb.append(i);
369:                        sb.append("]="); // NOI18N
370:                        sb.append(l.get(i));
371:                        if (i != cnt - 1) {
372:                            sb.append('\n');
373:                        }
374:                    }
375:                    ret = sb.toString();
376:                }
377:                return ret;
378:            }
379:
380:            public static String debugIterator(Iterator i) {
381:                String ret;
382:                if (i == null) {
383:                    ret = "Null iterator"; // NOI18N
384:                } else if (!i.hasNext()) {
385:                    ret = "Empty iterator"; // NOI18N
386:                } else {
387:                    StringBuffer sb = new StringBuffer();
388:                    int ind = 0;
389:                    while (i.hasNext()) {
390:                        sb.append('[');
391:                        sb.append(ind++);
392:                        sb.append("]="); // NOI18N
393:                        sb.append(i.next().toString());
394:                        if (i.hasNext()) {
395:                            sb.append('\n');
396:                        }
397:                    }
398:                    ret = sb.toString();
399:                }
400:                return ret;
401:            }
402:
403:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.