KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > core > BufferChangedEvent


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 package org.eclipse.jdt.core;
12
13 import java.util.EventObject JavaDoc;
14
15 /**
16  * A buffer changed event describes how a buffer has changed. These events are
17  * used in <code>IBufferChangedListener</code> notifications.
18  * <p>
19  * For text insertions, <code>getOffset</code> is the offset
20  * of the first inserted character, <code>getText</code> is the
21  * inserted text, and <code>getLength</code> is 0.
22  * </p>
23  * <p>
24  * For text removals, <code>getOffset</code> is the offset
25  * of the first removed character, <code>getText</code> is <code>null</code>,
26  * and <code>getLength</code> is the length of the text that was removed.
27  * </p>
28  * <p>
29  * For replacements (including <code>IBuffer.setContents</code>),
30  * <code>getOffset</code> is the offset
31  * of the first replaced character, <code>getText</code> is the replacement
32  * text, and <code>getLength</code> is the length of the original text
33  * that was replaced.
34  * </p>
35  * <p>
36  * When a buffer is closed, <code>getOffset</code> is 0, <code>getLength</code>
37  * is 0, and <code>getText</code> is <code>null</code>.
38  * </p>
39  * <p>
40  * This class is not intended to be instantiated or subclassed by clients.
41  * Instances of this class are automatically created by the Java model.
42  * </p>
43  *
44  * @see IBuffer
45  */

46 public class BufferChangedEvent extends EventObject JavaDoc {
47
48     /**
49      * The length of text that has been modified in the buffer.
50      */

51     private int length;
52
53     /**
54      * The offset into the buffer where the modification took place.
55      */

56     private int offset;
57
58     /**
59      * The text that was modified.
60      */

61     private String JavaDoc text;
62     
63     private static final long serialVersionUID = 655379473891745999L; // backward compatible
64

65 /**
66  * Creates a new buffer changed event indicating that the given buffer has changed.
67  *
68  * @param buffer the given buffer
69  * @param offset the given offset
70  * @param length the given length
71  * @param text the given text
72  */

73 public BufferChangedEvent(IBuffer buffer, int offset, int length, String JavaDoc text) {
74     super(buffer);
75     this.offset = offset;
76     this.length = length;
77     this.text = text;
78 }
79 /**
80  * Returns the buffer which has changed.
81  *
82  * @return the buffer affected by the change
83  */

84 public IBuffer getBuffer() {
85     return (IBuffer) this.source;
86 }
87 /**
88  * Returns the length of text removed or replaced in the buffer, or
89  * 0 if text has been inserted into the buffer.
90  *
91  * @return the length of the original text fragment modified by the
92  * buffer change (<code> 0 </code> in case of insertion).
93  */

94 public int getLength() {
95     return this.length;
96 }
97 /**
98  * Returns the index of the first character inserted, removed, or replaced
99  * in the buffer.
100  *
101  * @return the source offset of the textual manipulation in the buffer
102  */

103 public int getOffset() {
104     return this.offset;
105 }
106 /**
107  * Returns the text that was inserted, the replacement text,
108  * or <code>null</code> if text has been removed.
109  *
110  * @return the text corresponding to the buffer change (<code> null </code>
111  * in case of deletion).
112  */

113 public String JavaDoc getText() {
114     return this.text;
115 }
116 }
117
Popular Tags