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.IDocument;
014: import org.eclipse.jface.text.IRegion;
015: import org.eclipse.jface.text.Position;
016:
017: /**
018: * Implementation of a child document based on
019: * {@link org.eclipse.jface.text.projection.ProjectionDocument}. This class
020: * exists for compatibility reasons.
021: * <p>
022: * Internal class. This class is not intended to be used by clients.</p>
023: *
024: * @since 3.0
025: */
026: public class ChildDocument extends ProjectionDocument {
027:
028: /**
029: * Position reflecting a visible region. The exclusive end offset of the position
030: * is considered being overlapping with the visible region.
031: */
032: static private class VisibleRegion extends Position {
033:
034: /**
035: * Creates a new visible region.
036: *
037: * @param regionOffset the offset of the region
038: * @param regionLength the length of the region
039: */
040: public VisibleRegion(int regionOffset, int regionLength) {
041: super (regionOffset, regionLength);
042: }
043:
044: /**
045: * If <code>regionOffset</code> is the end of the visible region and the <code>regionLength == 0</code>,
046: * the <code>regionOffset</code> is considered overlapping with the visible region.
047: *
048: * @see org.eclipse.jface.text.Position#overlapsWith(int, int)
049: */
050: public boolean overlapsWith(int regionOffset, int regionLength) {
051: boolean appending = (regionOffset == offset + length)
052: && regionLength == 0;
053: return appending
054: || super .overlapsWith(regionOffset, regionLength);
055: }
056: }
057:
058: /**
059: * Creates a new child document.
060: *
061: * @param masterDocument @inheritDoc
062: */
063: public ChildDocument(IDocument masterDocument) {
064: super (masterDocument);
065: }
066:
067: /**
068: * Returns the parent document of this child document.
069: *
070: * @return the parent document of this child document
071: * @see ProjectionDocument#getMasterDocument()
072: */
073: public IDocument getParentDocument() {
074: return getMasterDocument();
075: }
076:
077: /**
078: * Sets the parent document range covered by this child document to the
079: * given range.
080: *
081: * @param offset the offset of the range
082: * @param length the length of the range
083: * @throws BadLocationException if the given range is not valid
084: */
085: public void setParentDocumentRange(int offset, int length)
086: throws BadLocationException {
087: replaceMasterDocumentRanges(offset, length);
088: }
089:
090: /**
091: * Returns the parent document range of this child document.
092: *
093: * @return the parent document range of this child document
094: */
095: public Position getParentDocumentRange() {
096: IRegion coverage = getProjectionMapping().getCoverage();
097: return new VisibleRegion(coverage.getOffset(), coverage
098: .getLength());
099: }
100: }
|