A massive organize imports and formatting of the sources using default Eclipse code...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / BufferChangedEvent.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.core;
12
13 import java.util.EventObject;
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 of the first
20  * inserted character, <code>getText</code> is the inserted text, and
21  * <code>getLength</code> is 0.
22  * </p>
23  * <p>
24  * For text removals, <code>getOffset</code> is the offset of the first
25  * removed character, <code>getText</code> is <code>null</code>, and
26  * <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 of the first replaced character,
31  * <code>getText</code> is the replacement text, and <code>getLength</code>
32  * is the length of the original text that was replaced.
33  * </p>
34  * <p>
35  * When a buffer is closed, <code>getOffset</code> is 0,
36  * <code>getLength</code> is 0, and <code>getText</code> is
37  * <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 {
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 text;
62
63         /**
64          * Creates a new buffer changed event indicating that the given buffer has
65          * changed.
66          * 
67          * @param buffer
68          *            the given buffer
69          * @param offset
70          *            the given offset
71          * @param length
72          *            the given length
73          * @param text
74          *            the given text
75          */
76         public BufferChangedEvent(IBuffer buffer, int offset, int length,
77                         String text) {
78                 super(buffer);
79                 this.offset = offset;
80                 this.length = length;
81                 this.text = text;
82         }
83
84         /**
85          * Returns the buffer which has changed.
86          * 
87          * @return the buffer affected by the change
88          */
89         public IBuffer getBuffer() {
90                 return (IBuffer) source;
91         }
92
93         /**
94          * Returns the length of text removed or replaced in the buffer, or 0 if
95          * text has been inserted into the buffer.
96          * 
97          * @return the length of the original text fragment modified by the buffer
98          *         change (<code> 0 </code> in case of insertion).
99          */
100         public int getLength() {
101                 return this.length;
102         }
103
104         /**
105          * Returns the index of the first character inserted, removed, or replaced
106          * in the buffer.
107          * 
108          * @return the source offset of the textual manipulation in the buffer
109          */
110         public int getOffset() {
111                 return this.offset;
112         }
113
114         /**
115          * Returns the text that was inserted, the replacement text, or
116          * <code>null</code> if text has been removed.
117          * 
118          * @return the text corresponding to the buffer change (<code> null </code>
119          *         in case of deletion).
120          */
121         public String getText() {
122                 return this.text;
123         }
124 }