comparison dwtx/jface/text/projection/ChildDocument.d @ 129:eb30df5ca28b

Added JFace Text sources
author Frank Benoit <benoit@tionex.de>
date Sat, 23 Aug 2008 19:10:48 +0200
parents
children c4fb132a086c
comparison
equal deleted inserted replaced
128:8df1d4193877 129:eb30df5ca28b
1 /*******************************************************************************
2 * Copyright (c) 2000, 2008 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 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module dwtx.jface.text.projection.ChildDocument;
14
15 import dwt.dwthelper.utils;
16
17 import dwtx.jface.text.BadLocationException;
18 import dwtx.jface.text.IDocument;
19 import dwtx.jface.text.IRegion;
20 import dwtx.jface.text.Position;
21
22 /**
23 * Implementation of a child document based on
24 * {@link dwtx.jface.text.projection.ProjectionDocument}. This class
25 * exists for compatibility reasons.
26 * <p>
27 * Internal class. This class is not intended to be used by clients.</p>
28 *
29 * @since 3.0
30 * @noinstantiate This class is not intended to be instantiated by clients.
31 * @noextend This class is not intended to be subclassed by clients.
32 */
33 public class ChildDocument : ProjectionDocument {
34
35 /**
36 * Position reflecting a visible region. The exclusive end offset of the position
37 * is considered being overlapping with the visible region.
38 */
39 static private class VisibleRegion : Position {
40
41 /**
42 * Creates a new visible region.
43 *
44 * @param regionOffset the offset of the region
45 * @param regionLength the length of the region
46 */
47 public VisibleRegion(int regionOffset, int regionLength) {
48 super(regionOffset, regionLength);
49 }
50
51 /**
52 * If <code>regionOffset</code> is the end of the visible region and the <code>regionLength is 0</code>,
53 * the <code>regionOffset</code> is considered overlapping with the visible region.
54 *
55 * @see dwtx.jface.text.Position#overlapsWith(int, int)
56 */
57 public bool overlapsWith(int regionOffset, int regionLength) {
58 bool appending= (regionOffset is offset + length) && regionLength is 0;
59 return appending || super.overlapsWith(regionOffset, regionLength);
60 }
61 }
62
63 /**
64 * Creates a new child document.
65 *
66 * @param masterDocument @inheritDoc
67 */
68 public ChildDocument(IDocument masterDocument) {
69 super(masterDocument);
70 }
71
72 /**
73 * Returns the parent document of this child document.
74 *
75 * @return the parent document of this child document
76 * @see ProjectionDocument#getMasterDocument()
77 */
78 public IDocument getParentDocument() {
79 return getMasterDocument();
80 }
81
82 /**
83 * Sets the parent document range covered by this child document to the
84 * given range.
85 *
86 * @param offset the offset of the range
87 * @param length the length of the range
88 * @throws BadLocationException if the given range is not valid
89 */
90 public void setParentDocumentRange(int offset, int length) throws BadLocationException {
91 replaceMasterDocumentRanges(offset, length);
92 }
93
94 /**
95 * Returns the parent document range of this child document.
96 *
97 * @return the parent document range of this child document
98 */
99 public Position getParentDocumentRange() {
100 IRegion coverage= getDocumentInformationMapping().getCoverage();
101 return new VisibleRegion(coverage.getOffset(), coverage.getLength());
102 }
103 }