KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > text > undo > DocumentUndoEvent


1 /*******************************************************************************
2  * Copyright (c) 2006 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
12 package org.eclipse.text.undo;
13
14 import org.eclipse.core.runtime.Assert;
15
16 import org.eclipse.jface.text.IDocument;
17
18 /**
19  * Describes document changes initiated by undo or redo.
20  * <p>
21  * Clients are not supposed to subclass or create instances of this class.
22  * </p>
23  *
24  * @see IDocumentUndoManager
25  * @see IDocumentUndoListener
26  * @since 3.2
27  */

28 public class DocumentUndoEvent {
29
30     /**
31      * Indicates that the described document event is about to be
32      * undone.
33      */

34     public static final int ABOUT_TO_UNDO= 1 << 0;
35
36     /**
37      * Indicates that the described document event is about to be
38      * redone.
39      */

40     public static final int ABOUT_TO_REDO= 1 << 1;
41
42     /**
43      * Indicates that the described document event has been undone.
44      */

45     public static final int UNDONE= 1 << 2;
46
47     /**
48      * Indicates that the described document event has been redone.
49      */

50     public static final int REDONE= 1 << 3;
51
52     /**
53      * Indicates that the described document event is a compound undo
54      * or redo event.
55      */

56     public static final int COMPOUND= 1 << 4;
57
58     /** The changed document. */
59     private IDocument fDocument;
60
61     /** The document offset where the change begins. */
62     private int fOffset;
63
64     /** Text inserted into the document. */
65     private String JavaDoc fText;
66
67     /** Text replaced in the document. */
68     private String JavaDoc fPreservedText;
69
70     /** Bit mask of event types describing the event */
71     private int fEventType;
72
73     /** The source that triggered this event or <code>null</code> if unknown. */
74     private Object JavaDoc fSource;
75
76     /**
77      * Creates a new document event.
78      *
79      * @param doc the changed document
80      * @param offset the offset of the replaced text
81      * @param text the substitution text
82      * @param preservedText the replaced text
83      * @param eventType a bit mask describing the type(s) of event
84      * @param source the source that triggered this event or <code>null</code> if unknown
85      */

86     DocumentUndoEvent(IDocument doc, int offset, String JavaDoc text, String JavaDoc preservedText, int eventType, Object JavaDoc source) {
87
88         Assert.isNotNull(doc);
89         Assert.isTrue(offset >= 0);
90
91         fDocument= doc;
92         fOffset= offset;
93         fText= text;
94         fPreservedText= preservedText;
95         fEventType= eventType;
96         fSource= source;
97     }
98
99     /**
100      * Returns the changed document.
101      *
102      * @return the changed document
103      */

104     public IDocument getDocument() {
105         return fDocument;
106     }
107
108     /**
109      * Returns the offset of the change.
110      *
111      * @return the offset of the change
112      */

113     public int getOffset() {
114         return fOffset;
115     }
116
117     /**
118      * Returns the text that has been inserted.
119      *
120      * @return the text that has been inserted
121      */

122     public String JavaDoc getText() {
123         return fText;
124     }
125
126     /**
127      * Returns the text that has been replaced.
128      *
129      * @return the text that has been replaced
130      */

131     public String JavaDoc getPreservedText() {
132         return fPreservedText;
133     }
134
135     /**
136      * Returns the type of event that is occurring.
137      *
138      * @return the bit mask that indicates the type (or types) of the event
139      */

140     public int getEventType() {
141         return fEventType;
142     }
143
144     /**
145      * Returns the source that triggered this event.
146      *
147      * @return the source that triggered this event.
148      */

149     public Object JavaDoc getSource() {
150         return fSource;
151     }
152
153     /**
154      * Returns whether the change was a compound change or not.
155      *
156      * @return <code>true</code> if the undo or redo change is a
157      * compound change, <code>false</code> if it is not
158      */

159     public boolean isCompound() {
160         return (fEventType & COMPOUND) != 0;
161     }
162 }
163
Popular Tags