Source Code Cross Referenced for FragmentUpdater.java in  » IDE-Eclipse » text » org » eclipse » jface » text » projection » 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 » IDE Eclipse » text » org.eclipse.jface.text.projection 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2005 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.jface.text.projection;
011:
012:        import org.eclipse.jface.text.BadLocationException;
013:        import org.eclipse.jface.text.BadPositionCategoryException;
014:        import org.eclipse.jface.text.DefaultPositionUpdater;
015:        import org.eclipse.jface.text.DocumentEvent;
016:        import org.eclipse.jface.text.IDocument;
017:        import org.eclipse.jface.text.Position;
018:
019:        /**
020:         * The position updater used to adapt the fragments of a master document. If an
021:         * insertion happens at a fragment's offset, the fragment is extended rather
022:         * than shifted. Also, the last fragment is extended if an insert operation
023:         * happens at the end of the fragment.
024:         *
025:         * @since 3.0
026:         */
027:        class FragmentUpdater extends DefaultPositionUpdater {
028:
029:            /** Indicates whether the position being updated represents the last fragment. */
030:            private boolean fIsLast = false;
031:
032:            /**
033:             * Creates the fragment updater for the given category.
034:             *
035:             * @param fragmentCategory the position category used for managing the fragments of a document
036:             */
037:            protected FragmentUpdater(String fragmentCategory) {
038:                super (fragmentCategory);
039:            }
040:
041:            /*
042:             * @see org.eclipse.jface.text.IPositionUpdater#update(org.eclipse.jface.text.DocumentEvent)
043:             */
044:            public void update(DocumentEvent event) {
045:
046:                try {
047:
048:                    Position[] category = event.getDocument().getPositions(
049:                            getCategory());
050:
051:                    fOffset = event.getOffset();
052:                    fLength = event.getLength();
053:                    fReplaceLength = (event.getText() == null ? 0 : event
054:                            .getText().length());
055:                    fDocument = event.getDocument();
056:
057:                    for (int i = 0; i < category.length; i++) {
058:
059:                        fPosition = category[i];
060:                        fIsLast = (i == category.length - 1);
061:
062:                        fOriginalPosition.offset = fPosition.offset;
063:                        fOriginalPosition.length = fPosition.length;
064:
065:                        if (notDeleted())
066:                            adaptToReplace();
067:                    }
068:
069:                } catch (BadPositionCategoryException x) {
070:                    // do nothing
071:                }
072:            }
073:
074:            /*
075:             * @see org.eclipse.jface.text.DefaultPositionUpdater#adaptToInsert()
076:             */
077:            protected void adaptToInsert() {
078:                int myStart = fPosition.offset;
079:                int myEnd = Math.max(myStart, fPosition.offset
080:                        + fPosition.length
081:                        - (fIsLast || isAffectingReplace() ? 0 : 1));
082:
083:                if (myEnd < fOffset)
084:                    return;
085:
086:                if (fLength <= 0) {
087:
088:                    if (myStart <= fOffset)
089:                        fPosition.length += fReplaceLength;
090:                    else
091:                        fPosition.offset += fReplaceLength;
092:
093:                } else {
094:
095:                    if (myStart <= fOffset
096:                            && fOriginalPosition.offset <= fOffset)
097:                        fPosition.length += fReplaceLength;
098:                    else
099:                        fPosition.offset += fReplaceLength;
100:                }
101:            }
102:
103:            /**
104:             * Returns whether this updater considers any position affected by the given document event. A
105:             * position is affected if <code>event</code> {@link Position#overlapsWith(int, int) overlaps}
106:             * with it but not if the position is only shifted.
107:             * 
108:             * @param event the event
109:             * @return <code>true</code> if there is any affected position, <code>false</code> otherwise
110:             */
111:            public boolean affectsPositions(DocumentEvent event) {
112:                IDocument document = event.getDocument();
113:                try {
114:
115:                    int index = document.computeIndexInCategory(getCategory(),
116:                            event.getOffset());
117:                    Position[] fragments = document.getPositions(getCategory());
118:
119:                    if (0 < index) {
120:                        Position fragment = fragments[index - 1];
121:                        if (fragment.overlapsWith(event.getOffset(), event
122:                                .getLength()))
123:                            return true;
124:                        if (index == fragments.length
125:                                && fragment.offset + fragment.length == event
126:                                        .getOffset())
127:                            return true;
128:                    }
129:
130:                    if (index < fragments.length) {
131:                        Position fragment = fragments[index];
132:                        return fragment.overlapsWith(event.getOffset(), event
133:                                .getLength());
134:                    }
135:
136:                } catch (BadLocationException x) {
137:                } catch (BadPositionCategoryException x) {
138:                }
139:
140:                return false;
141:            }
142:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.