KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > DocumentEvent


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.jface.text;
13
14 import org.eclipse.core.runtime.Assert;
15
16
17 /**
18  * Specification of changes applied to documents. All changes are represented as
19  * replace commands, i.e. specifying a document range whose text gets replaced
20  * with different text. In addition to this information, the event also contains
21  * the changed document.
22  *
23  * @see org.eclipse.jface.text.IDocument
24  */

25 public class DocumentEvent {
26     
27     /**
28      * Debug option for asserting that text is not null.
29      * If the <code>org.eclipse.text/debug/DocumentEvent/assertTextNotNull</code>
30      * system property is <code>true</code>
31      *
32      * @since 3.3
33      */

34     private static final boolean ASSERT_TEXT_NOT_NULL= Boolean.getBoolean("org.eclipse.text/debug/DocumentEvent/assertTextNotNull"); //$NON-NLS-1$
35

36     /** The changed document */
37     public IDocument fDocument;
38     /** The document offset */
39     public int fOffset;
40     /** Length of the replaced document text */
41     public int fLength;
42     /** Text inserted into the document */
43     public String JavaDoc fText= ""; //$NON-NLS-1$
44
/**
45      * The modification stamp of the document when firing this event.
46      * @since 3.1 and public since 3.3
47      */

48     public long fModificationStamp;
49
50     /**
51      * Creates a new document event.
52      *
53      * @param doc the changed document
54      * @param offset the offset of the replaced text
55      * @param length the length of the replaced text
56      * @param text the substitution text
57      */

58     public DocumentEvent(IDocument doc, int offset, int length, String JavaDoc text) {
59
60         Assert.isNotNull(doc);
61         Assert.isTrue(offset >= 0);
62         Assert.isTrue(length >= 0);
63
64         if (ASSERT_TEXT_NOT_NULL)
65             Assert.isNotNull(text);
66
67         fDocument= doc;
68         fOffset= offset;
69         fLength= length;
70         fText= text;
71
72         if (fDocument instanceof IDocumentExtension4)
73             fModificationStamp= ((IDocumentExtension4)fDocument).getModificationStamp();
74         else
75             fModificationStamp= IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP;
76     }
77
78     /**
79      * Creates a new, not initialized document event.
80      */

81     public DocumentEvent() {
82     }
83
84     /**
85      * Returns the changed document.
86      *
87      * @return the changed document
88      */

89     public IDocument getDocument() {
90         return fDocument;
91     }
92
93     /**
94      * Returns the offset of the change.
95      *
96      * @return the offset of the change
97      */

98     public int getOffset() {
99         return fOffset;
100     }
101
102     /**
103      * Returns the length of the replaced text.
104      *
105      * @return the length of the replaced text
106      */

107     public int getLength() {
108         return fLength;
109     }
110
111     /**
112      * Returns the text that has been inserted.
113      *
114      * @return the text that has been inserted
115      */

116     public String JavaDoc getText() {
117         return fText;
118     }
119
120     /**
121      * Returns the document's modification stamp at the
122      * time when this event was sent.
123      *
124      * @return the modification stamp or {@link IDocumentExtension4#UNKNOWN_MODIFICATION_STAMP}.
125      * @see IDocumentExtension4#getModificationStamp()
126      * @since 3.1
127      */

128     public long getModificationStamp() {
129         return fModificationStamp;
130     }
131 }
132
Popular Tags