Source Code Cross Referenced for PositionManager.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:         * PositionManager.java - Manages positions
003:         * :tabSize=8:indentSize=8:noTabs=false:
004:         * :folding=explicit:collapseFolds=1:
005:         *
006:         * Copyright (C) 2001, 2005 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:        //{{{ Imports
026:        import javax.swing.text.Position;
027:        import java.util.*;
028:        import org.gjt.sp.util.Log;
029:
030:        //}}}
031:
032:        /**
033:         * A class internal to jEdit's document model. You should not use it
034:         * directly.
035:         *
036:         * @author Slava Pestov
037:         * @version $Id: PositionManager.java 9007 2007-02-22 10:35:38Z kpouer $
038:         * @since jEdit 4.2pre3
039:         */
040:        public class PositionManager {
041:            //{{{ PositionManager constructor
042:            public PositionManager(JEditBuffer buffer) {
043:                this .buffer = buffer;
044:            } //}}}
045:
046:            //{{{ createPosition() method
047:            public synchronized Position createPosition(int offset) {
048:                PosBottomHalf bh = new PosBottomHalf(offset);
049:                PosBottomHalf existing = positions.get(bh);
050:                if (existing == null) {
051:                    positions.put(bh, bh);
052:                    existing = bh;
053:                }
054:
055:                return new PosTopHalf(existing);
056:            } //}}}
057:
058:            //{{{ contentInserted() method
059:            public synchronized void contentInserted(int offset, int length) {
060:                if (positions.isEmpty())
061:                    return;
062:
063:                /* get all positions from offset to the end, inclusive */
064:                Iterator iter = positions.tailMap(new PosBottomHalf(offset))
065:                        .keySet().iterator();
066:
067:                iteration = true;
068:                while (iter.hasNext()) {
069:                    ((PosBottomHalf) iter.next()).contentInserted(offset,
070:                            length);
071:                }
072:                iteration = false;
073:            } //}}}
074:
075:            //{{{ contentRemoved() method
076:            public synchronized void contentRemoved(int offset, int length) {
077:                if (positions.isEmpty())
078:                    return;
079:
080:                /* get all positions from offset to the end, inclusive */
081:                Iterator iter = positions.tailMap(new PosBottomHalf(offset))
082:                        .keySet().iterator();
083:
084:                iteration = true;
085:                while (iter.hasNext()) {
086:                    ((PosBottomHalf) iter.next())
087:                            .contentRemoved(offset, length);
088:                }
089:                iteration = false;
090:
091:            } //}}}
092:
093:            boolean iteration;
094:
095:            //{{{ Private members
096:            private JEditBuffer buffer;
097:            private SortedMap<PosBottomHalf, PosBottomHalf> positions = new TreeMap<PosBottomHalf, PosBottomHalf>();
098:
099:            //}}}
100:
101:            //{{{ Inner classes
102:
103:            //{{{ PosTopHalf class
104:            class PosTopHalf implements  Position {
105:                PosBottomHalf bh;
106:
107:                //{{{ PosTopHalf constructor
108:                PosTopHalf(PosBottomHalf bh) {
109:                    this .bh = bh;
110:                    bh.ref();
111:                } //}}}
112:
113:                //{{{ getOffset() method
114:                public int getOffset() {
115:                    return bh.offset;
116:                } //}}}
117:
118:                //{{{ finalize() method
119:                protected void finalize() {
120:                    synchronized (PositionManager.this ) {
121:                        bh.unref();
122:                    }
123:                } //}}}
124:            } //}}}
125:
126:            //{{{ PosBottomHalf class
127:            class PosBottomHalf implements  Comparable<PosBottomHalf> {
128:                int offset;
129:                int ref;
130:
131:                //{{{ PosBottomHalf constructor
132:                PosBottomHalf(int offset) {
133:                    this .offset = offset;
134:                } //}}}
135:
136:                //{{{ ref() method
137:                void ref() {
138:                    ref++;
139:                } //}}}
140:
141:                //{{{ unref() method
142:                void unref() {
143:                    if (--ref == 0)
144:                        positions.remove(this );
145:                } //}}}
146:
147:                //{{{ contentInserted() method
148:                void contentInserted(int offset, int length) {
149:                    if (offset > this .offset)
150:                        throw new ArrayIndexOutOfBoundsException();
151:                    this .offset += length;
152:                    checkInvariants();
153:                } //}}}
154:
155:                //{{{ contentRemoved() method
156:                void contentRemoved(int offset, int length) {
157:                    if (offset > this .offset)
158:                        throw new ArrayIndexOutOfBoundsException();
159:                    if (this .offset <= offset + length)
160:                        this .offset = offset;
161:                    else
162:                        this .offset -= length;
163:                    checkInvariants();
164:                } //}}}
165:
166:                //{{{ equals() method
167:                public boolean equals(Object o) {
168:                    if (!(o instanceof  PosBottomHalf))
169:                        return false;
170:
171:                    return ((PosBottomHalf) o).offset == offset;
172:                } //}}}
173:
174:                //{{{ compareTo() method
175:                public int compareTo(PosBottomHalf posBottomHalf) {
176:                    if (iteration)
177:                        Log.log(Log.ERROR, this , "Consistency failure");
178:                    return offset - posBottomHalf.offset;
179:                } //}}}
180:
181:                //{{{ checkInvariants() method
182:                private void checkInvariants() {
183:                    if (offset < 0 || offset > buffer.getLength())
184:                        throw new ArrayIndexOutOfBoundsException();
185:                } //}}}
186:            } //}}}
187:
188:            //}}}
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.