added a builder to parse files with eclipse's build mechanisms
[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
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 {
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 changed.
65  * 
66  * @param buffer the given buffer
67  * @param offset the given offset
68  * @param length the given length
69  * @param text the given text
70  */
71 public BufferChangedEvent(IBuffer buffer, int offset, int length, String text) {
72         super(buffer);
73         this.offset = offset;
74         this.length = length;
75         this.text = text;
76 }
77 /**
78  * Returns the buffer which has changed.
79  *
80  * @return the buffer affected by the change
81  */
82 public IBuffer getBuffer() {
83         return (IBuffer) source;
84 }
85 /**
86  * Returns the length of text removed or replaced in the buffer, or
87  * 0 if text has been inserted into the buffer.
88  *
89  * @return the length of the original text fragment modified by the 
90  *   buffer change (<code> 0 </code> in case of insertion).
91  */
92 public int getLength() {
93         return this.length;
94 }
95 /**
96  * Returns the index of the first character inserted, removed, or replaced
97  * in the buffer.
98  *
99  * @return the source offset of the textual manipulation in the buffer
100  */
101 public int getOffset() {
102         return this.offset;
103 }
104 /**
105  * Returns the text that was inserted, the replacement text,
106  * or <code>null</code> if text has been removed.
107  *
108  * @return the text corresponding to the buffer change (<code> null </code>
109  *   in case of deletion).
110  */
111 public String getText() {
112         return this.text;
113 }
114 }