Source Code Cross Referenced for SyntaxUtilities.java in  » Web-Services » soapui-1.7.5 » 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 » Web Services » soapui 1.7.5 » org.syntax.jedit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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