Source Code Cross Referenced for ContentManager.java in  » Swing-Library » jEdit » org » gjt » sp » jedit » buffer » 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 » Swing Library » jEdit » org.gjt.sp.jedit.buffer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ContentManager.java - Manages text content
003:         * :tabSize=8:indentSize=8:noTabs=false:
004:         * :folding=explicit:collapseFolds=1:
005:         *
006:         * Copyright (C) 2001, 2002 Slava Pestov
007:         *
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public License
010:         * as published by the Free Software Foundation; either version 2
011:         * of the License, or any later version.
012:         *
013:         * This program is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public License
019:         * along with this program; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
021:         */
022:
023:        package org.gjt.sp.jedit.buffer;
024:
025:        import javax.swing.text.Segment;
026:
027:        /**
028:         * A class internal to jEdit's document model. You should not use it
029:         * directly. To improve performance, none of the methods in this class
030:         * check for out of bounds access, nor are they thread-safe. The
031:         * <code>Buffer</code> class, through which these methods must be
032:         * called through, implements such protection.
033:         *
034:         * @author Slava Pestov
035:         * @version $Id: ContentManager.java 4524 2003-03-09 19:26:05Z spestov $
036:         * @since jEdit 4.0pre1
037:         */
038:        public class ContentManager {
039:            //{{{ getLength() method
040:            public final int getLength() {
041:                return length;
042:            } //}}}
043:
044:            //{{{ getText() method
045:            public String getText(int start, int len) {
046:                if (start >= gapStart)
047:                    return new String(text, start + gapEnd - gapStart, len);
048:                else if (start + len <= gapStart)
049:                    return new String(text, start, len);
050:                else {
051:                    return new String(text, start, gapStart - start)
052:                            .concat(new String(text, gapEnd, start + len
053:                                    - gapStart));
054:                }
055:            } //}}}
056:
057:            //{{{ getText() method
058:            public void getText(int start, int len, Segment seg) {
059:                if (start >= gapStart) {
060:                    seg.array = text;
061:                    seg.offset = start + gapEnd - gapStart;
062:                    seg.count = len;
063:                } else if (start + len <= gapStart) {
064:                    seg.array = text;
065:                    seg.offset = start;
066:                    seg.count = len;
067:                } else {
068:                    seg.array = new char[len];
069:
070:                    // copy text before gap
071:                    System.arraycopy(text, start, seg.array, 0, gapStart
072:                            - start);
073:
074:                    // copy text after gap
075:                    System.arraycopy(text, gapEnd, seg.array, gapStart - start,
076:                            len + start - gapStart);
077:
078:                    seg.offset = 0;
079:                    seg.count = len;
080:                }
081:            } //}}}
082:
083:            //{{{ insert() method
084:            public void insert(int start, String str) {
085:                int len = str.length();
086:                moveGapStart(start);
087:                if (gapEnd - gapStart < len) {
088:                    ensureCapacity(length + len + 1024);
089:                    moveGapEnd(start + len + 1024);
090:                }
091:
092:                str.getChars(0, len, text, start);
093:                gapStart += len;
094:                length += len;
095:            } //}}}
096:
097:            //{{{ insert() method
098:            public void insert(int start, Segment seg) {
099:                moveGapStart(start);
100:                if (gapEnd - gapStart < seg.count) {
101:                    ensureCapacity(length + seg.count + 1024);
102:                    moveGapEnd(start + seg.count + 1024);
103:                }
104:
105:                System.arraycopy(seg.array, seg.offset, text, start, seg.count);
106:                gapStart += seg.count;
107:                length += seg.count;
108:            } //}}}
109:
110:            //{{{ _setContent() method
111:            public void _setContent(char[] text, int length) {
112:                this .text = text;
113:                this .gapStart = this .gapEnd = 0;
114:                this .length = length;
115:            } //}}}
116:
117:            //{{{ remove() method
118:            public void remove(int start, int len) {
119:                moveGapStart(start);
120:                gapEnd += len;
121:                length -= len;
122:            } //}}}
123:
124:            //{{{ Private members
125:            private char[] text;
126:            private int gapStart;
127:            private int gapEnd;
128:            private int length;
129:
130:            //{{{ moveGapStart() method
131:            private void moveGapStart(int newStart) {
132:                int newEnd = gapEnd + (newStart - gapStart);
133:
134:                if (newStart == gapStart) {
135:                    // nothing to do
136:                } else if (newStart > gapStart) {
137:                    System.arraycopy(text, gapEnd, text, gapStart, newStart
138:                            - gapStart);
139:                } else if (newStart < gapStart) {
140:                    System.arraycopy(text, newStart, text, newEnd, gapStart
141:                            - newStart);
142:                }
143:
144:                gapStart = newStart;
145:                gapEnd = newEnd;
146:            } //}}}
147:
148:            //{{{ moveGapEnd() method
149:            private void moveGapEnd(int newEnd) {
150:                System.arraycopy(text, gapEnd, text, newEnd, length - gapStart);
151:                gapEnd = newEnd;
152:            } //}}}
153:
154:            //{{{ ensureCapacity() method
155:            private void ensureCapacity(int capacity) {
156:                if (capacity >= text.length) {
157:                    char[] textN = new char[capacity * 2];
158:                    System.arraycopy(text, 0, textN, 0, length
159:                            + (gapEnd - gapStart));
160:                    text = textN;
161:                }
162:            } //}}}
163:
164:            //}}}
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.