KickJava   Java API By Example, From Geeks To Geeks.

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


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
14 import org.eclipse.jface.text.DocumentEvent;
15 import org.eclipse.jface.text.IDocument;
16 import org.eclipse.jface.text.SlaveDocumentEvent;
17
18
19 /**
20  * This event is sent out by an
21  * {@link org.eclipse.jface.text.projection.ProjectionDocument}when it is
22  * manipulated. The manipulation is either a content manipulation or a change of
23  * the projection between the master and the slave. Clients can determine the
24  * type of change by asking the projection document event for its change type
25  * (see {@link #getChangeType()}) and comparing it with the predefined types
26  * {@link #PROJECTION_CHANGE}and {@link #CONTENT_CHANGE}.
27  * <p>
28  * Clients are not supposed to create instances of this class. Instances are
29  * created by {@link org.eclipse.jface.text.projection.ProjectionDocument}
30  * instances. This class is not intended to be subclassed.</p>
31  *
32  * @since 3.0
33  */

34 public class ProjectionDocumentEvent extends SlaveDocumentEvent {
35
36     /** The change type indicating a projection change */
37     public final static Object JavaDoc PROJECTION_CHANGE= new Object JavaDoc();
38     /** The change type indicating a content change */
39     public final static Object JavaDoc CONTENT_CHANGE= new Object JavaDoc();
40
41     /** The change type */
42     private Object JavaDoc fChangeType;
43     /** The offset of the change in the master document */
44     private int fMasterOffset= -1;
45     /** The length of the change in the master document */
46     private int fMasterLength= -1;
47
48     /**
49      * Creates a new content change event caused by the given master document
50      * change. Instances created using this constructor return <code>-1</code>
51      * when calling <code>getMasterOffset</code> or
52      * <code>getMasterLength</code>. This information can be obtained by
53      * accessing the master event.
54      *
55      * @param doc the changed projection document
56      * @param offset the offset in the projection document
57      * @param length the length in the projection document
58      * @param text the replacement text
59      * @param masterEvent the original master event
60      */

61     public ProjectionDocumentEvent(IDocument doc, int offset, int length, String JavaDoc text, DocumentEvent masterEvent) {
62         super(doc, offset, length, text, masterEvent);
63         fChangeType= CONTENT_CHANGE;
64     }
65
66     /**
67      * Creates a new projection change event for the given properties. Instances
68      * created with this constructor return the given master document offset and
69      * length but do not have an associated master document event.
70      *
71      * @param doc the projection document
72      * @param offset the offset in the projection document
73      * @param length the length in the projection document
74      * @param text the replacement text
75      * @param masterOffset the offset in the master document
76      * @param masterLength the length in the master document
77      */

78     public ProjectionDocumentEvent(IDocument doc, int offset, int length, String JavaDoc text, int masterOffset, int masterLength) {
79         super(doc, offset, length, text, null);
80         fChangeType= PROJECTION_CHANGE;
81         fMasterOffset= masterOffset;
82         fMasterLength= masterLength;
83     }
84
85     /**
86      * Creates a new projection document event for the given properties. The
87      * projection change is caused by a manipulation of the master document. In
88      * order to accommodate the master document change, the projection document
89      * had to change the projection. Instances created with this constructor
90      * return the given master document offset and length and also have an
91      * associated master document event.
92      *
93      * @param doc the projection document
94      * @param offset the offset in the projection document
95      * @param length the length in the projection document
96      * @param text the replacement text
97      * @param masterOffset the offset in the master document
98      * @param masterLength the length in the master document
99      * @param masterEvent the master document event
100      */

101     public ProjectionDocumentEvent(IDocument doc, int offset, int length, String JavaDoc text, int masterOffset, int masterLength, DocumentEvent masterEvent) {
102         super(doc, offset, length, text, masterEvent);
103         fChangeType= PROJECTION_CHANGE;
104         fMasterOffset= masterOffset;
105         fMasterLength= masterLength;
106     }
107
108     /**
109      * Returns the change type of this event. This is either {@link #PROJECTION_CHANGE} or
110      * {@link #CONTENT_CHANGE}.
111      *
112      * @return the change type of this event
113      */

114     public Object JavaDoc getChangeType() {
115         return fChangeType;
116     }
117
118     /**
119      * Returns the offset of the master document range that has been added or removed in case this
120      * event describes a projection change, otherwise it returns <code>-1</code>.
121      *
122      * @return the master document offset of the projection change or <code>-1</code>
123      */

124     public int getMasterOffset() {
125         return fMasterOffset;
126     }
127
128     /**
129      * Returns the length of the master document range that has been added or removed in case this event
130      * describes a projection changed, otherwise <code>-1</code>.
131      *
132      * @return the master document length of the projection change or <code>-1</code>
133      */

134     public int getMasterLength() {
135         return fMasterLength;
136     }
137 }
138
Popular Tags