KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > console > ConsoleOutputTextStore


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 org.eclipse.debug.internal.ui.views.console;
12
13
14 import org.eclipse.jface.text.ITextStore;
15
16 public class ConsoleOutputTextStore implements ITextStore {
17
18     private StringBuffer JavaDoc fBuffer;
19
20     public ConsoleOutputTextStore(int bufferSize) {
21         fBuffer= new StringBuffer JavaDoc(bufferSize);
22     }
23
24     /**
25      * @see ITextStore#get(int)
26      */

27     public char get(int pos) {
28         return fBuffer.charAt(pos);
29     }
30
31     /**
32      * @see ITextStore#get(int, int)
33      */

34     public String JavaDoc get(int pos, int length) {
35         return fBuffer.substring(pos, pos + length);
36     }
37
38     /**
39      * @see ITextStore#getLength()
40      */

41      public int getLength() {
42         return fBuffer.length();
43     }
44
45     /**
46      * @see ITextStore#replace(int, int, String)
47      */

48      public void replace(int pos, int length, String JavaDoc text) {
49         if (text == null) {
50             text= ""; //$NON-NLS-1$
51
}
52         fBuffer.replace(pos, pos + length, text);
53     }
54
55     /**
56      * @see ITextStore#set(String)
57      */

58      public void set(String JavaDoc text) {
59         fBuffer= new StringBuffer JavaDoc(text);
60     }
61
62     /**
63      * @see StringBuffer#ensureCapacity(int)
64      */

65     public void setMinimalBufferSize(int bufferSize) {
66         fBuffer.ensureCapacity(bufferSize);
67     }
68 }
69
Popular Tags