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.DocumentEvent;
013: import org.eclipse.jface.text.IDocument;
014: import org.eclipse.jface.text.SlaveDocumentEvent;
015:
016: /**
017: * This event is sent out by an
018: * {@link org.eclipse.jface.text.projection.ProjectionDocument}when it is
019: * manipulated. The manipulation is either a content manipulation or a change of
020: * the projection between the master and the slave. Clients can determine the
021: * type of change by asking the projection document event for its change type
022: * (see {@link #getChangeType()}) and comparing it with the predefined types
023: * {@link #PROJECTION_CHANGE}and {@link #CONTENT_CHANGE}.
024: * <p>
025: * Clients are not supposed to create instances of this class. Instances are
026: * created by {@link org.eclipse.jface.text.projection.ProjectionDocument}
027: * instances. This class is not intended to be subclassed.</p>
028: *
029: * @since 3.0
030: */
031: public class ProjectionDocumentEvent extends SlaveDocumentEvent {
032:
033: /** The change type indicating a projection change */
034: public final static Object PROJECTION_CHANGE = new Object();
035: /** The change type indicating a content change */
036: public final static Object CONTENT_CHANGE = new Object();
037:
038: /** The change type */
039: private Object fChangeType;
040: /** The offset of the change in the master document */
041: private int fMasterOffset = -1;
042: /** The length of the change in the master document */
043: private int fMasterLength = -1;
044:
045: /**
046: * Creates a new content change event caused by the given master document
047: * change. Instances created using this constructor return <code>-1</code>
048: * when calling <code>getMasterOffset</code> or
049: * <code>getMasterLength</code>. This information can be obtained by
050: * accessing the master event.
051: *
052: * @param doc the changed projection document
053: * @param offset the offset in the projection document
054: * @param length the length in the projection document
055: * @param text the replacement text
056: * @param masterEvent the original master event
057: */
058: public ProjectionDocumentEvent(IDocument doc, int offset,
059: int length, String text, DocumentEvent masterEvent) {
060: super (doc, offset, length, text, masterEvent);
061: fChangeType = CONTENT_CHANGE;
062: }
063:
064: /**
065: * Creates a new projection change event for the given properties. Instances
066: * created with this constructor return the given master document offset and
067: * length but do not have an associated master document event.
068: *
069: * @param doc the projection document
070: * @param offset the offset in the projection document
071: * @param length the length in the projection document
072: * @param text the replacement text
073: * @param masterOffset the offset in the master document
074: * @param masterLength the length in the master document
075: */
076: public ProjectionDocumentEvent(IDocument doc, int offset,
077: int length, String text, int masterOffset, int masterLength) {
078: super (doc, offset, length, text, null);
079: fChangeType = PROJECTION_CHANGE;
080: fMasterOffset = masterOffset;
081: fMasterLength = masterLength;
082: }
083:
084: /**
085: * Creates a new projection document event for the given properties. The
086: * projection change is caused by a manipulation of the master document. In
087: * order to accommodate the master document change, the projection document
088: * had to change the projection. Instances created with this constructor
089: * return the given master document offset and length and also have an
090: * associated master document event.
091: *
092: * @param doc the projection document
093: * @param offset the offset in the projection document
094: * @param length the length in the projection document
095: * @param text the replacement text
096: * @param masterOffset the offset in the master document
097: * @param masterLength the length in the master document
098: * @param masterEvent the master document event
099: */
100: public ProjectionDocumentEvent(IDocument doc, int offset,
101: int length, String text, int masterOffset,
102: int masterLength, DocumentEvent masterEvent) {
103: super (doc, offset, length, text, masterEvent);
104: fChangeType = PROJECTION_CHANGE;
105: fMasterOffset = masterOffset;
106: fMasterLength = masterLength;
107: }
108:
109: /**
110: * Returns the change type of this event. This is either {@link #PROJECTION_CHANGE} or
111: * {@link #CONTENT_CHANGE}.
112: *
113: * @return the change type of this event
114: */
115: public Object getChangeType() {
116: return fChangeType;
117: }
118:
119: /**
120: * Returns the offset of the master document range that has been added or removed in case this
121: * event describes a projection change, otherwise it returns <code>-1</code>.
122: *
123: * @return the master document offset of the projection change or <code>-1</code>
124: */
125: public int getMasterOffset() {
126: return fMasterOffset;
127: }
128:
129: /**
130: * Returns the length of the master document range that has been added or removed in case this event
131: * describes a projection changed, otherwise <code>-1</code>.
132: *
133: * @return the master document length of the projection change or <code>-1</code>
134: */
135: public int getMasterLength() {
136: return fMasterLength;
137: }
138: }
|