KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > projection > ChildDocument


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jface.text.projection;
12
13 import org.eclipse.jface.text.BadLocationException;
14 import org.eclipse.jface.text.IDocument;
15 import org.eclipse.jface.text.IRegion;
16 import org.eclipse.jface.text.Position;
17
18 /**
19  * Implementation of a child document based on
20  * {@link org.eclipse.jface.text.projection.ProjectionDocument}. This class
21  * exists for compatibility reasons.
22  * <p>
23  * Internal class. This class is not intended to be used by clients.</p>
24  *
25  * @since 3.0
26  */

27 public class ChildDocument extends ProjectionDocument {
28
29     /**
30      * Position reflecting a visible region. The exclusive end offset of the position
31      * is considered being overlapping with the visible region.
32      */

33     static private class VisibleRegion extends Position {
34
35         /**
36          * Creates a new visible region.
37          *
38          * @param regionOffset the offset of the region
39          * @param regionLength the length of the region
40          */

41         public VisibleRegion(int regionOffset, int regionLength) {
42             super(regionOffset, regionLength);
43         }
44
45         /**
46          * If <code>regionOffset</code> is the end of the visible region and the <code>regionLength == 0</code>,
47          * the <code>regionOffset</code> is considered overlapping with the visible region.
48          *
49          * @see org.eclipse.jface.text.Position#overlapsWith(int, int)
50          */

51         public boolean overlapsWith(int regionOffset, int regionLength) {
52             boolean appending= (regionOffset == offset + length) && regionLength == 0;
53             return appending || super.overlapsWith(regionOffset, regionLength);
54         }
55     }
56
57     /**
58      * Creates a new child document.
59      *
60      * @param masterDocument @inheritDoc
61      */

62     public ChildDocument(IDocument masterDocument) {
63         super(masterDocument);
64     }
65
66     /**
67      * Returns the parent document of this child document.
68      *
69      * @return the parent document of this child document
70      * @see ProjectionDocument#getMasterDocument()
71      */

72     public IDocument getParentDocument() {
73         return getMasterDocument();
74     }
75
76     /**
77      * Sets the parent document range covered by this child document to the
78      * given range.
79      *
80      * @param offset the offset of the range
81      * @param length the length of the range
82      * @throws BadLocationException if the given range is not valid
83      */

84     public void setParentDocumentRange(int offset, int length) throws BadLocationException {
85         replaceMasterDocumentRanges(offset, length);
86     }
87
88     /**
89      * Returns the parent document range of this child document.
90      *
91      * @return the parent document range of this child document
92      */

93     public Position getParentDocumentRange() {
94         IRegion coverage= getProjectionMapping().getCoverage();
95         return new VisibleRegion(coverage.getOffset(), coverage.getLength());
96     }
97 }
98
Popular Tags