Source Code Cross Referenced for BufferContent.java in  » Scripting » Kawa » gnu » jemacs » swing » 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 » Scripting » Kawa » gnu.jemacs.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package gnu.jemacs.swing;
002:
003:        import gnu.jemacs.buffer.*;
004:        import javax.swing.text.*;
005:        import javax.swing.undo.*;
006:        import gnu.lists.*;
007:
008:        /** A Content class that supports Emacs-style Markers.
009:         * The standard GapContent is close, but unfortunately it only
010:         * supports inserting *before* marks, which is not the Emacs default.
011:         * This provides a superset of the Position functionality (except for undo).
012:         */
013:
014:        public class BufferContent extends gnu.kawa.swingviews.SwingContent {
015:            public BufferContent() {
016:                this (100);
017:            }
018:
019:            public BufferContent(int initialSize) {
020:                super (initialSize);
021:            }
022:
023:            public static int indexOf(char[] buffer, int start, int limit,
024:                    char ch) {
025:                for (int i = start; i < limit; i++) {
026:                    if (buffer[i] == ch)
027:                        return i;
028:                }
029:                return -1;
030:            }
031:
032:            /** Search for the last occurrence of a character
033:             * in buffer[limit..start]. */
034:            public static int lastIndexOf(char[] buffer, int start, int limit,
035:                    char ch) {
036:                for (int i = start; i >= limit; i--) {
037:                    if (buffer[i] == ch)
038:                        return i;
039:                }
040:                return -1;
041:            }
042:
043:            /** Search in BUF for COUNT instances of the character TARGET between START and END.
044:             * If COUNT is positive, search forwards; END must be >= START.
045:             * If COUNT is negative, search backwards for the -COUNTth instance;
046:             *   END must be <= START.
047:             * If COUNT is zero, do anything you please; run rogue, for all I care.
048:             *
049:             * If we find COUNT instances, SHORTAGE is zero, and return the
050:             * position after the COUNTth match.  Note that for reverse motion
051:             * this is not the same as the usual convention for Emacs motion commands.
052:
053:             * If we don't find COUNT instances before reaching END, set SHORTAGE
054:             * to the number of TARGETs left unfound, and return (shortage<<32|END).
055:             * @return (SHORTAGE<<32|POS)
056:             */
057:
058:            public final long scan(char target, int start, int end, int count,
059:                    boolean allowQuit) {
060:                CharBuffer b = buffer;
061:                int limit = end > b.gapStart ? end + b.gapEnd - b.gapStart
062:                        : end;
063:                if (start > b.gapStart)
064:                    start += b.gapEnd - b.gapStart;
065:                if (count > 0) {
066:                    while (start < limit && count > 0) {
067:                        int ceil;
068:                        if (start == b.gapStart)
069:                            start = b.gapEnd;
070:                        if (start < b.gapStart && limit > b.gapStart)
071:                            ceil = b.gapStart;
072:                        else {
073:                            ceil = limit;
074:                        }
075:                        if (allowQuit) {
076:                            if (ceil - start > 5000)
077:                                ceil = start + 5000;
078:                            Signal.checkQuit();
079:                        }
080:                        int i = indexOf(b.getArray(), start, ceil, target);
081:                        if (i >= 0) {
082:                            count--;
083:                            start = i + 1;
084:                        } else
085:                            start = ceil;
086:                    }
087:                    if (start > b.gapEnd)
088:                        start -= b.gapEnd - b.gapStart;
089:                    return ((long) count << 32) | start;
090:                } else {
091:                    while (start > limit && count < 0) {
092:                        if (start == b.gapEnd)
093:                            start = b.gapStart;
094:                        int floor;
095:                        if (start <= b.gapStart || limit >= b.gapEnd)
096:                            floor = limit;
097:                        else
098:                            floor = b.gapEnd;
099:                        if (allowQuit) {
100:                            if (start - floor > 5000)
101:                                floor = start - 5000;
102:                            Signal.checkQuit();
103:                        }
104:                        int i = lastIndexOf(b.getArray(), start - 1, floor,
105:                                target);
106:                        if (i >= 0) {
107:                            count++;
108:                            start = i;
109:                        } else
110:                            start = floor;
111:                    }
112:
113:                    if (start >= b.gapEnd)
114:                        start -= b.gapEnd - b.gapStart;
115:                    if (count != 0)
116:                        return ((long) (-count) << 32) | start;
117:                    else {
118:                        // We found the character we were looking for; we have to return
119:                        // the position *after* it due to the strange way that the return
120:                        // value is defined.
121:                        return start + 1;
122:                    }
123:                }
124:            }
125:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.