Source Code Cross Referenced for JavaDrawLayerFactory.java in  » Swing-Library » abeille-forms-designer » org » netbeans » editor » ext » java » 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.ext.java 
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.ext.java;
015:
016:        import javax.swing.event.DocumentEvent;
017:        import javax.swing.event.DocumentListener;
018:        import javax.swing.text.BadLocationException;
019:
020:        import org.netbeans.editor.Analyzer;
021:        import org.netbeans.editor.BaseDocument;
022:        import org.netbeans.editor.BaseDocumentEvent;
023:        import org.netbeans.editor.Coloring;
024:        import org.netbeans.editor.DrawContext;
025:        import org.netbeans.editor.DrawLayer;
026:        import org.netbeans.editor.FinderFactory;
027:        import org.netbeans.editor.MarkFactory;
028:        import org.netbeans.editor.TokenContextPath;
029:
030:        /**
031:         * Various java-layers
032:         * 
033:         * @author Miloslav Metelka
034:         * @version 1.00
035:         */
036:
037:        public class JavaDrawLayerFactory {
038:
039:            public static final String JAVA_LAYER_NAME = "java-layer";
040:
041:            public static final int JAVA_LAYER_VISIBILITY = 1010;
042:
043:            /**
044:             * Layer that colors extra java information like the methods or special
045:             * characters in the character and string literals.
046:             */
047:            public static class JavaLayer extends DrawLayer.AbstractLayer {
048:
049:                /**
050:                 * End of the area that is resolved right now. It saves repetitive
051:                 * searches for '(' for multiple fragments inside one identifier token.
052:                 */
053:                private int resolvedEndOffset;
054:
055:                private boolean resolvedValue;
056:
057:                private NonWhitespaceFwdFinder nwFinder = new NonWhitespaceFwdFinder();
058:
059:                public JavaLayer() {
060:                    super (JAVA_LAYER_NAME);
061:                }
062:
063:                public void init(DrawContext ctx) {
064:                    resolvedEndOffset = 0; // nothing resolved
065:                }
066:
067:                public boolean isActive(DrawContext ctx,
068:                        MarkFactory.DrawMark mark) {
069:                    int nextOffset = ctx.getTokenOffset()
070:                            + ctx.getTokenLength();
071:
072:                    setNextActivityChangeOffset(nextOffset);
073:                    return true;
074:                }
075:
076:                protected Coloring getMethodColoring(DrawContext ctx) {
077:                    TokenContextPath path = ctx.getTokenContextPath()
078:                            .replaceStart(JavaLayerTokenContext.contextPath);
079:                    return ctx
080:                            .getEditorUI()
081:                            .getColoring(
082:                                    path
083:                                            .getFullTokenName(JavaLayerTokenContext.METHOD));
084:                }
085:
086:                private boolean isMethod(DrawContext ctx) {
087:                    int idEndOffset = ctx.getTokenOffset()
088:                            + ctx.getTokenLength();
089:                    if (idEndOffset > resolvedEndOffset) { // beyond the resolved area
090:                        resolvedEndOffset = idEndOffset; // will resolve now
091:                        int endOffset = ctx.getEndOffset();
092:                        int bufferStartOffset = ctx.getBufferStartOffset();
093:                        char[] buffer = ctx.getBuffer();
094:                        int nwOffset = Analyzer.findFirstNonWhite(buffer,
095:                                idEndOffset - bufferStartOffset, endOffset
096:                                        - idEndOffset);
097:                        if (nwOffset >= 0) { // found non-white
098:                            resolvedValue = (buffer[nwOffset] == '(');
099:
100:                        } else { // must resolve after buffer end
101:                            try {
102:                                resolvedValue = (ctx.getEditorUI()
103:                                        .getDocument().find(nwFinder,
104:                                                endOffset, -1) >= 0)
105:                                        && (nwFinder.getFoundChar() == '(');
106:                            } catch (BadLocationException e) {
107:                                resolvedValue = false;
108:                            }
109:                        }
110:                    }
111:
112:                    return resolvedValue;
113:                }
114:
115:                public void updateContext(DrawContext ctx) {
116:                    if (ctx.getTokenID() == JavaTokenContext.IDENTIFIER
117:                            && isMethod(ctx)) {
118:                        Coloring mc = getMethodColoring(ctx);
119:                        if (mc != null) {
120:                            mc.apply(ctx);
121:                        }
122:                    }
123:                }
124:
125:            }
126:
127:            /** Find first non-white character forward */
128:            static class NonWhitespaceFwdFinder extends
129:                    FinderFactory.GenericFwdFinder {
130:
131:                private char foundChar;
132:
133:                public char getFoundChar() {
134:                    return foundChar;
135:                }
136:
137:                protected int scan(char ch, boolean lastChar) {
138:                    if (!Character.isWhitespace(ch)) {
139:                        found = true;
140:                        foundChar = ch;
141:                        return 0;
142:                    }
143:                    return 1;
144:                }
145:            }
146:
147:            /** Find first non-white character backward */
148:            public static class NonWhitespaceBwdFinder extends
149:                    FinderFactory.GenericBwdFinder {
150:
151:                private char foundChar;
152:
153:                public char getFoundChar() {
154:                    return foundChar;
155:                }
156:
157:                protected int scan(char ch, boolean lastChar) {
158:                    if (!Character.isWhitespace(ch)) {
159:                        found = true;
160:                        foundChar = ch;
161:                        return 0;
162:                    }
163:                    return -1;
164:                }
165:            }
166:
167:            /**
168:             * This class watches whether the '(' character was inserted/removed. It
169:             * ensures the appropriate part of the document till the previous
170:             * non-whitespace will be repainted.
171:             */
172:            public static class LParenWatcher implements  DocumentListener {
173:
174:                NonWhitespaceBwdFinder nwFinder = new NonWhitespaceBwdFinder();
175:
176:                private void check(DocumentEvent evt) {
177:                    if (evt.getDocument() instanceof  BaseDocument) {
178:                        BaseDocument doc = (BaseDocument) evt.getDocument();
179:                        BaseDocumentEvent bevt = (BaseDocumentEvent) evt;
180:                        char[] chars = bevt.getChars();
181:                        if (chars != null) {
182:                            boolean found = false;
183:                            for (int i = chars.length - 1; i >= 0; i--) {
184:                                if (chars[i] == '(') {
185:                                    found = true;
186:                                    break;
187:                                }
188:                            }
189:
190:                            if (found) {
191:                                int offset = evt.getOffset();
192:                                // Need to repaint
193:                                int redrawOffset = 0;
194:                                if (offset > 0) {
195:                                    try {
196:                                        redrawOffset = doc.find(nwFinder,
197:                                                offset - 1, 0);
198:                                    } catch (BadLocationException e) {
199:                                    }
200:
201:                                    if (redrawOffset < 0) { // not found non-whitespace
202:                                        redrawOffset = 0;
203:                                    }
204:                                }
205:                                doc.repaintBlock(redrawOffset, offset);
206:                            }
207:                        }
208:                    }
209:                }
210:
211:                public void insertUpdate(DocumentEvent evt) {
212:                    check(evt);
213:                }
214:
215:                public void removeUpdate(DocumentEvent evt) {
216:                    check(evt);
217:                }
218:
219:                public void changedUpdate(DocumentEvent evt) {
220:                }
221:
222:            }
223:
224:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.