Source Code Cross Referenced for TextUtilities.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:         * TextUtilities.java - Utility functions used by the text area classes
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 javax.swing.text.BadLocationException;
013:        import javax.swing.text.Document;
014:
015:        /**
016:         * Class with several utility functions used by the text area component.
017:         * @author Slava Pestov
018:         * @version $Id$
019:         */
020:        public class TextUtilities {
021:            /**
022:             * Returns the offset of the bracket matching the one at the
023:             * specified offset of the document, or -1 if the bracket is
024:             * unmatched (or if the character is not a bracket).
025:             * @param doc The document
026:             * @param offset The offset
027:             * @exception BadLocationException If an out-of-bounds access
028:             * was attempted on the document text
029:             */
030:            public static int findMatchingBracket(Document doc, int offset)
031:                    throws BadLocationException {
032:                if (doc.getLength() == 0)
033:                    return -1;
034:                char c = doc.getText(offset, 1).charAt(0);
035:                char cprime; // c` - corresponding character
036:                boolean direction; // true = back, false = forward
037:
038:                switch (c) {
039:                case '(':
040:                    cprime = ')';
041:                    direction = false;
042:                    break;
043:                case ')':
044:                    cprime = '(';
045:                    direction = true;
046:                    break;
047:                case '[':
048:                    cprime = ']';
049:                    direction = false;
050:                    break;
051:                case ']':
052:                    cprime = '[';
053:                    direction = true;
054:                    break;
055:                case '{':
056:                    cprime = '}';
057:                    direction = false;
058:                    break;
059:                case '}':
060:                    cprime = '{';
061:                    direction = true;
062:                    break;
063:                default:
064:                    return -1;
065:                }
066:
067:                int count;
068:
069:                // How to merge these two cases is left as an exercise
070:                // for the reader.
071:
072:                // Go back or forward
073:                if (direction) {
074:                    // Count is 1 initially because we have already
075:                    // `found' one closing bracket
076:                    count = 1;
077:
078:                    // Get text[0,offset-1];
079:                    String text = doc.getText(0, offset);
080:
081:                    // Scan backwards
082:                    for (int i = offset - 1; i >= 0; i--) {
083:                        // If text[i] == c, we have found another
084:                        // closing bracket, therefore we will need
085:                        // two opening brackets to complete the
086:                        // match.
087:                        char x = text.charAt(i);
088:                        if (x == c)
089:                            count++;
090:
091:                        // If text[i] == cprime, we have found a
092:                        // opening bracket, so we return i if
093:                        // --count == 0
094:                        else if (x == cprime) {
095:                            if (--count == 0)
096:                                return i;
097:                        }
098:                    }
099:                } else {
100:                    // Count is 1 initially because we have already
101:                    // `found' one opening bracket
102:                    count = 1;
103:
104:                    // So we don't have to + 1 in every loop
105:                    offset++;
106:
107:                    // Number of characters to check
108:                    int len = doc.getLength() - offset;
109:
110:                    // Get text[offset+1,len];
111:                    String text = doc.getText(offset, len);
112:
113:                    // Scan forwards
114:                    for (int i = 0; i < len; i++) {
115:                        // If text[i] == c, we have found another
116:                        // opening bracket, therefore we will need
117:                        // two closing brackets to complete the
118:                        // match.
119:                        char x = text.charAt(i);
120:
121:                        if (x == c)
122:                            count++;
123:
124:                        // If text[i] == cprime, we have found an
125:                        // closing bracket, so we return i if
126:                        // --count == 0
127:                        else if (x == cprime) {
128:                            if (--count == 0)
129:                                return i + offset;
130:                        }
131:                    }
132:                }
133:
134:                // Nothing found
135:                return -1;
136:            }
137:
138:            /**
139:             * Locates the start of the word at the specified position.
140:             * @param line The text
141:             * @param pos The position
142:             */
143:            public static int findWordStart(String line, int pos,
144:                    String noWordSep) {
145:                char ch = line.charAt(pos - 1);
146:
147:                if (noWordSep == null)
148:                    noWordSep = "";
149:                boolean selectNoLetter = (!Character.isLetterOrDigit(ch) && noWordSep
150:                        .indexOf(ch) == -1);
151:
152:                int wordStart = 0;
153:                for (int i = pos - 1; i >= 0; i--) {
154:                    ch = line.charAt(i);
155:                    if (selectNoLetter
156:                            ^ (!Character.isLetterOrDigit(ch) && noWordSep
157:                                    .indexOf(ch) == -1)) {
158:                        wordStart = i + 1;
159:                        break;
160:                    }
161:                }
162:
163:                return wordStart;
164:            }
165:
166:            /**
167:             * Locates the end of the word at the specified position.
168:             * @param line The text
169:             * @param pos The position
170:             */
171:            public static int findWordEnd(String line, int pos, String noWordSep) {
172:                char ch = line.charAt(pos);
173:
174:                if (noWordSep == null)
175:                    noWordSep = "";
176:                boolean selectNoLetter = (!Character.isLetterOrDigit(ch) && noWordSep
177:                        .indexOf(ch) == -1);
178:
179:                int wordEnd = line.length();
180:                for (int i = pos; i < line.length(); i++) {
181:                    ch = line.charAt(i);
182:                    if (selectNoLetter
183:                            ^ (!Character.isLetterOrDigit(ch) && noWordSep
184:                                    .indexOf(ch) == -1)) {
185:                        wordEnd = i;
186:                        break;
187:                    }
188:                }
189:                return wordEnd;
190:            }
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.