1 package org.catacomb.interlish.content;
2
3
4 public class StringValue extends PrimitiveValue {
5
6
7 private String text;
8
9 private int highlight;
10
11
12 public StringValue() {
13 super();
14 text = null;
15 }
16
17 public StringValue(String s) {
18 super();
19 text = s;
20 }
21
22 public StringValue(String s, boolean b) {
23 super(b);
24 text = s;
25 }
26
27
28 public String toString() {
29 return "StringValue: " + text;
30 }
31
32 public void silentSetString(String s) {
33 text = s;
34 logChange();
35 }
36
37 public String getString() {
38 reportUse(this);
39 return text;
40 }
41
42 public String getAsString() {
43 reportUse(this);
44 return (text != null ? text : "");
45 }
46
47
48 public void clear() {
49 silentSetString("");
50 }
51
52 public void set(String s) {
53 reportableSetString(s, this);
54 }
55
56 public void reportableSetString(String s, Object src) {
57 silentSetString(s);
58 reportValueChange(src);
59 reportUse(src);
60 }
61
62 public boolean hasNonTrivialValue() {
63 return (text != null && text.trim().length() > 0);
64 }
65
66 public void copyFrom(StringValue src) {
67 silentSetString(src.getString());
68 }
69
70 public void append(String string) {
71 reportableSetString(text + string, null);
72 }
73
74 public void highlightLine(int i) {
75 highlight = i;
76
77 reportValueChange("HIGHLIGHT");
78 }
79
80 public void clearHighlight() {
81 highlight = -1;
82 }
83
84 public int getHighlight() {
85 return highlight;
86 }
87
88 public void silentAppendLine(String txt) {
89 if (text == null) {
90 text = "";
91 }
92 if (text.length() == 0 || text.endsWith("\n")) {
93
94 } else {
95
96 text += "\n";
97 }
98 text += txt;
99 text += "\n";
100 }
101
102
103 public String silentGetAsString() {
104 return (text != null ? text : "");
105 }
106
107
108 }