01: package gnu.kawa.models;
02:
03: import gnu.lists.*;
04:
05: /** An editable sequences of characters and embedded objects.
06: * For now, only supports plain text.
07: * Conceptually similar to javax.swing.text.Document.
08: * May display as a one line "text field" or a multi-line "text area"
09: * depending on styling preferences; for now only the former is implemented.
10: */
11:
12: public class Text extends Model implements Viewable,
13: java.io.Serializable {
14: public final CharBuffer buffer = new CharBuffer(100);
15:
16: public Text() {
17: this ("");
18: }
19:
20: public Text(String text) {
21: buffer.gapEnd = 100 - 1;
22: buffer.getArray()[buffer.gapEnd] = '\n';
23: setText(text);
24: }
25:
26: public void makeView(Display display, Object where) {
27: display.addText(this , where);
28: }
29:
30: public String getText() {
31: int len = buffer.size() - 1;
32: int start = buffer.getSegment(0, len);
33: return new String(buffer.getArray(), start, len);
34: }
35:
36: public void setText(String text) {
37: int size = buffer.size() - 1;
38: if (size > 0)
39: buffer.delete(0, size);
40: buffer.insert(0, text, false);
41: notifyListeners("text");
42: }
43:
44: public CharBuffer getBuffer() {
45: return buffer;
46: }
47: }
|