Source Code Cross Referenced for SyntaxUtilities.java in  » XML-UI » XUI » net » xoetrope » builder » editor » syntaxhighlight » 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 » XML UI » XUI » net.xoetrope.builder.editor.syntaxhighlight 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.xoetrope.builder.editor.syntaxhighlight;
002:
003:        /*
004:         * SyntaxUtilities.java - Utility functions used by syntax colorizing
005:         * Copyright (C) 1999 Slava Pestov
006:         *
007:         * You may use and modify this package for any purpose. Redistribution is
008:         * permitted, in both source and binary form, provided that this notice
009:         * remains intact in all source distributions of this package.
010:         */
011:
012:        import java.awt.Color;
013:        import java.awt.Font;
014:        import java.awt.Graphics;
015:        import javax.swing.text.Segment;
016:        import javax.swing.text.TabExpander;
017:        import javax.swing.text.Utilities;
018:
019:        /**
020:         * Class with several utility functions used by jEdit's syntax colorizing
021:         * subsystem.
022:         *
023:         * @author Slava Pestov
024:         * @version $Id: SyntaxUtilities.java,v 1.22 2005/01/05 17:20:49 luano Exp $
025:         */
026:        public class SyntaxUtilities {
027:            /**
028:             * Checks if a subregion of a <code>Segment</code> is equal to a
029:             * string.
030:             * @param ignoreCase True if case should be ignored, false otherwise
031:             * @param text The segment
032:             * @param offset The offset into the segment
033:             * @param match The string to match
034:             */
035:            public static boolean regionMatches(boolean ignoreCase,
036:                    Segment text, int offset, String match) {
037:                int length = offset + match.length();
038:                char[] textArray = text.array;
039:                if (length > text.offset + text.count)
040:                    return false;
041:                for (int i = offset, j = 0; i < length; i++, j++) {
042:                    char c1 = textArray[i];
043:                    char c2 = match.charAt(j);
044:                    if (ignoreCase) {
045:                        c1 = Character.toUpperCase(c1);
046:                        c2 = Character.toUpperCase(c2);
047:                    }
048:                    if (c1 != c2)
049:                        return false;
050:                }
051:                return true;
052:            }
053:
054:            /**
055:             * Checks if a subregion of a <code>Segment</code> is equal to a
056:             * character array.
057:             * @param ignoreCase True if case should be ignored, false otherwise
058:             * @param text The segment
059:             * @param offset The offset into the segment
060:             * @param match The character array to match
061:             */
062:            public static boolean regionMatches(boolean ignoreCase,
063:                    Segment text, int offset, char[] match) {
064:                int length = offset + match.length;
065:                char[] textArray = text.array;
066:                if (length > text.offset + text.count)
067:                    return false;
068:                for (int i = offset, j = 0; i < length; i++, j++) {
069:                    char c1 = textArray[i];
070:                    char c2 = match[j];
071:                    if (ignoreCase) {
072:                        c1 = Character.toUpperCase(c1);
073:                        c2 = Character.toUpperCase(c2);
074:                    }
075:                    if (c1 != c2)
076:                        return false;
077:                }
078:                return true;
079:            }
080:
081:            /**
082:             * Returns the default style table. This can be passed to the
083:             * <code>setStyles()</code> method of <code>SyntaxDocument</code>
084:             * to use the default syntax styles.
085:             */
086:            public static SyntaxStyle[] getDefaultSyntaxStyles() {
087:                SyntaxStyle[] styles = new SyntaxStyle[Token.ID_COUNT];
088:
089:                styles[Token.COMMENT1] = new SyntaxStyle(Color.black, true,
090:                        false);
091:                styles[Token.COMMENT2] = new SyntaxStyle(new Color(0x990033),
092:                        true, false);
093:                styles[Token.KEYWORD1] = new SyntaxStyle(Color.black, false,
094:                        true);
095:                styles[Token.KEYWORD2] = new SyntaxStyle(Color.magenta, false,
096:                        false);
097:                styles[Token.KEYWORD3] = new SyntaxStyle(new Color(0x009600),
098:                        false, false);
099:                styles[Token.LITERAL1] = new SyntaxStyle(new Color(0x650099),
100:                        false, false);
101:                styles[Token.LITERAL2] = new SyntaxStyle(new Color(0x650099),
102:                        false, true);
103:                styles[Token.LABEL] = new SyntaxStyle(new Color(0x990033),
104:                        false, true);
105:                styles[Token.OPERATOR] = new SyntaxStyle(Color.black, false,
106:                        true);
107:                styles[Token.INVALID] = new SyntaxStyle(Color.red, false, true);
108:
109:                return styles;
110:            }
111:
112:            /**
113:             * Paints the specified line onto the graphics context. Note that this
114:             * method munges the offset and count values of the segment.
115:             * @param line The line segment
116:             * @param tokens The token list for the line
117:             * @param styles The syntax style list
118:             * @param expander The tab expander used to determine tab stops. May
119:             * be null
120:             * @param gfx The graphics context
121:             * @param x The x co-ordinate
122:             * @param y The y co-ordinate
123:             * @return The x co-ordinate, plus the width of the painted string
124:             */
125:            public static int paintSyntaxLine(Segment line, Token tokens,
126:                    SyntaxStyle[] styles, TabExpander expander, Graphics gfx,
127:                    int x, int y) {
128:                Font defaultFont = gfx.getFont();
129:                Color defaultColor = gfx.getColor();
130:
131:                int offset = 0;
132:                for (;;) {
133:                    byte id = tokens.id;
134:                    if (id == Token.END)
135:                        break;
136:
137:                    int length = tokens.length;
138:                    if (id == Token.NULL) {
139:                        if (!defaultColor.equals(gfx.getColor()))
140:                            gfx.setColor(defaultColor);
141:                        if (!defaultFont.equals(gfx.getFont()))
142:                            gfx.setFont(defaultFont);
143:                    } else
144:                        styles[id].setGraphicsFlags(gfx, defaultFont);
145:
146:                    line.count = length;
147:                    x = Utilities.drawTabbedText(line, x, y, gfx, expander, 0);
148:                    line.offset += length;
149:                    offset += length;
150:
151:                    tokens = tokens.next;
152:                }
153:
154:                return x;
155:            }
156:
157:            // private members
158:            private SyntaxUtilities() {
159:            }
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.