Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.

1 /*******************************************************************************2 * Copyright (c) 2000, 2006 IBM Corporation and others.3 * All rights reserved. This program and the accompanying materials4 * are made available under the terms of the Eclipse Public License v1.05 * which accompanies this distribution, and is available at6 * http://www.eclipse.org/legal/epl-v10.html7 *8 * Contributors:9 * IBM Corporation - initial API and implementation10 *******************************************************************************/11 package org.eclipse.jdt.core;12 13 importjava.util.EventObject;14 15 /**16 * A buffer changed event describes how a buffer has changed. These events are17 * used in <code>IBufferChangedListener</code> notifications.18 * <p>19 * For text insertions, <code>getOffset</code> is the offset20 * of the first inserted character, <code>getText</code> is the21 * inserted text, and <code>getLength</code> is 0.22 * </p>23 * <p>24 * For text removals, <code>getOffset</code> is the offset25 * 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 offset31 * of the first replaced character, <code>getText</code> is the replacement32 * text, and <code>getLength</code> is the length of the original text33 * 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 IBuffer45 */46 publicclass BufferChangedEvent extendsEventObject {47 48 /**49 * The length of text that has been modified in the buffer.50 */51 privateint length;52 53 /**54 * The offset into the buffer where the modification took place.55 */56 privateint offset;57 58 /**59 * The text that was modified.60 */61 privateString text;62 63 privatestaticfinallong serialVersionUID = 655379473891745999L; // backward compatible64 65 /**66 * Creates a new buffer changed event indicating that the given buffer has changed.67 * 68 * @param buffer the given buffer69 * @param offset the given offset70 * @param length the given length71 * @param text the given text72 */73 public BufferChangedEvent(IBuffer buffer, int offset, int length, String 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 change83 */84 publicIBuffer getBuffer() {85 return (IBuffer) this.source;86 }87 /**88 * Returns the length of text removed or replaced in the buffer, or89 * 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 publicint getLength() {95 returnthis.length;96 }97 /**98 * Returns the index of the first character inserted, removed, or replaced99 * in the buffer.100 *101 * @return the source offset of the textual manipulation in the buffer102 */103 publicint getOffset() {104 returnthis.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 publicString getText() {114 returnthis.text;115 }116 }117