1 package jimm.datavision.field; 2 import jimm.datavision.Report; 3 import jimm.datavision.Section; 4 import jimm.datavision.gui.FieldWidget; 5 import jimm.datavision.gui.TextFieldWidget; 6 import jimm.datavision.gui.SectionWidget; 7 import jimm.util.XMLWriter; 8 9 15 public class TextField extends Field { 16 17 27 public TextField(Long id, Report report, Section section, Object value, 28 boolean visible) 29 { 30 super(id, report, section, value, visible); 31 } 32 33 public void setValue(Object newValue) { 34 String newString = (newValue == null) ? null : newValue.toString(); 35 if (value != newString && (value == null || !value.equals(newString))) { 36 value = newString; 37 setChanged(); 38 notifyObservers(); 39 } 40 } 41 42 public FieldWidget makeWidget(SectionWidget sw) { 43 return new TextFieldWidget(sw, this); 44 } 45 46 public String dragString() { 47 return typeString() + ":" + value; 48 } 49 50 public String typeString() { return "text"; } 51 52 public String designLabel() { return value.toString(); } 53 54 60 public String formulaString() { 61 String str = value.toString(); 62 63 int pos = str.indexOf('"'); 64 int len = str.length(); 65 if (pos == -1 || len == 0) 66 return "\"" + str + "\""; 67 68 StringBuffer buf = new StringBuffer ("\""); 69 for (int i = 0; i < len; ++i) { 70 char c = str.charAt(i); 71 if (c == '"') 72 buf.append("\\\""); 73 else 74 buf.append(c); 75 } 76 buf.append("\""); 77 return buf.toString(); 78 } 79 80 public void writeXML(XMLWriter out) { 81 out.startElement("field"); 82 out.attr("id", id); 83 out.attr("type", typeString()); 84 out.cdataElement("text", value.toString()); 85 writeFieldGuts(out); 86 out.endElement(); 87 } 88 89 } 90 | Popular Tags |