Source Code Cross Referenced for SyntaxDocument.java in  » IDE » bluej-editor » org » syntax » jedit » 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 » IDE » bluej editor » org.syntax.jedit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * SyntaxDocument.java - Document that can be tokenized
003:         * Copyright (C) 1999 Slava Pestov
004:         *
005:         * You may use and modify this package for any purpose. Redistribution is
006:         * permitted, in both source and binary form, provided that this notice
007:         * remains intact in all source distributions of this package.
008:         */
009:
010:        package org.syntax.jedit;
011:
012:        import java.awt.Color;
013:
014:        import javax.swing.event.DocumentEvent;
015:        import javax.swing.text.*;
016:        import javax.swing.undo.UndoableEdit;
017:
018:        import org.syntax.jedit.tokenmarker.TokenMarker;
019:
020:        /**
021:         * A document implementation that can be tokenized by the syntax highlighting
022:         * system.
023:         *
024:         * @author Slava Pestov
025:         * @version $Id: SyntaxDocument.java 3074 2004-11-08 04:24:58Z bquig $
026:         */
027:        public class SyntaxDocument extends PlainDocument {
028:            // private members
029:            protected Color[] colors;
030:
031:            /**
032:             * Creates a new <code>DefaultSyntaxDocument</code> instance.
033:             */
034:            public SyntaxDocument(Color[] colors) {
035:                this .colors = colors;
036:                //addDocumentListener(new DocumentHandler());
037:            }
038:
039:            /**
040:             * Returns the token marker that is to be used to split lines
041:             * of this document up into tokens. May return null if this
042:             * document is not to be colorized.
043:             */
044:            public TokenMarker getTokenMarker() {
045:                return tokenMarker;
046:            }
047:
048:            /**
049:             * Returns the color array that maps token identifiers to
050:             * <code>java.awt.Color</code> objects.
051:             */
052:            public Color[] getColors() {
053:                return colors;
054:            }
055:
056:            /**
057:             * Sets the token marker that is to be used to split lines of
058:             * this document up into tokens. May throw an exception if
059:             * this is not supported for this type of document.
060:             * @param tm The new token marker
061:             */
062:            public void setTokenMarker(TokenMarker tm) {
063:                tokenMarker = tm;
064:                if (tm == null)
065:                    return;
066:                tokenMarker.insertLines(0, getDefaultRootElement()
067:                        .getElementCount());
068:                tokenizeLines();
069:            }
070:
071:            /**
072:             * Reparses the document, by passing all lines to the token
073:             * marker. This should be called after the document is first
074:             * loaded.
075:             */
076:            public void tokenizeLines() {
077:                tokenizeLines(0, getDefaultRootElement().getElementCount());
078:            }
079:
080:            /**
081:             * Reparses the document, by passing the specified lines to the
082:             * token marker. This should be called after a large quantity of
083:             * text is first inserted.
084:             * @param start The first line to parse
085:             * @param len The number of lines, after the first one to parse
086:             */
087:            public void tokenizeLines(int start, int len) {
088:                if (tokenMarker == null
089:                        || !tokenMarker.supportsMultilineTokens())
090:                    return;
091:
092:                Segment lineSegment = new Segment();
093:                Element map = getDefaultRootElement();
094:
095:                len += start;
096:
097:                try {
098:                    for (int i = start; i < len; i++) {
099:                        Element lineElement = map.getElement(i);
100:                        int lineStart = lineElement.getStartOffset();
101:                        getText(lineStart, lineElement.getEndOffset()
102:                                - lineStart - 1, lineSegment);
103:                        tokenMarker.markTokens(lineSegment, i);
104:                    }
105:                } catch (BadLocationException bl) {
106:                    bl.printStackTrace();
107:                }
108:            }
109:
110:            /**
111:             * Starts a compound edit that can be undone in one operation.
112:             * Subclasses that implement undo should override this method;
113:             * this class has no undo functionality so this method is
114:             * empty.
115:             */
116:            public void beginCompoundEdit() {
117:            }
118:
119:            /**
120:             * Ends a compound edit that can be undone in one operation.
121:             * Subclasses that implement undo should override this method;
122:             * this class has no undo functionality so this method is
123:             * empty.
124:             */
125:            public void endCompoundEdit() {
126:            }
127:
128:            /**
129:             * Adds an undoable edit to this document's undo list. The edit
130:             * should be ignored if something is currently being undone.
131:             * @param edit The undoable edit
132:             *
133:             * @since jEdit 2.2pre1
134:             */
135:            public void addUndoableEdit(UndoableEdit edit) {
136:            }
137:
138:            // protected members
139:            protected TokenMarker tokenMarker;
140:
141:            /**
142:             * We overwrite this method to update the token marker
143:             * state immediately so that any event listeners get a
144:             * consistent token marker.
145:             */
146:            protected void fireInsertUpdate(DocumentEvent evt) {
147:                if (tokenMarker != null) {
148:                    DocumentEvent.ElementChange ch = evt
149:                            .getChange(getDefaultRootElement());
150:                    if (ch != null) {
151:                        tokenMarker.insertLines(ch.getIndex() + 1, ch
152:                                .getChildrenAdded().length
153:                                - ch.getChildrenRemoved().length);
154:                    }
155:                }
156:
157:                super .fireInsertUpdate(evt);
158:            }
159:
160:            /**
161:             * We overwrite this method to update the token marker
162:             * state immediately so that any event listeners get a
163:             * consistent token marker.
164:             */
165:            protected void fireRemoveUpdate(DocumentEvent evt) {
166:                if (tokenMarker != null) {
167:                    DocumentEvent.ElementChange ch = evt
168:                            .getChange(getDefaultRootElement());
169:                    if (ch != null) {
170:                        tokenMarker.deleteLines(ch.getIndex() + 1, ch
171:                                .getChildrenRemoved().length
172:                                - ch.getChildrenAdded().length);
173:                    }
174:                }
175:
176:                super.fireRemoveUpdate(evt);
177:            }
178:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.