aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/awt/TextArea.java
blob: 09f5cb2e348c88666608eb9f963151a3ef14b833 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* Copyright (C) 1999  Free Software Foundation

   This file is part of libjava.

This software is copyrighted work licensed under the terms of the
Libjava License.  Please consult the file "LIBJAVA_LICENSE" for
details.  */

package java.awt;

/* A very incomplete placeholder. */

public class TextArea extends TextComponent
{
  public synchronized void append (String str)
  {
    replaceRange(str, length, length);
  }

  public synchronized void insert (String str, int pos)
  {
    replaceRange(str, pos, pos);
  }

  public synchronized void replaceRange (String str, int start, int end)
  {
    if (length == 0)
      setText (str);
    else
      {
	int len = str.length();
	int delta = len - (end - start);
	int new_length = length + delta;
	if (buffer.length < new_length)
	  {
	    int new_size = 2 * buffer.length;
	    if (new_size < new_length)
	      new_size = new_length;
	    char[] new_buffer = new char[new_size];
	    System.arraycopy(buffer, 0, new_buffer, 0, length);
	    buffer = new_buffer;
	  }
	if (len != end)
	  System.arraycopy(buffer, start, buffer, start + len, len - end);
	str.getChars(0, len, buffer, start);
	length += delta;
      }
  }
}