1 3 package org.faceless.pdf; 4 5 import java.util.*; 6 import java.io.*; 7 import java.awt.Color ; 8 9 39 public final class Form extends PeeredObject 40 { 41 private final org.faceless.pdf2.Form form; 42 private PDFStyle backstyle; 43 private int radio=FormElement.STYLE_CIRCLE, check=FormElement.STYLE_CHECK; 44 45 Form(org.faceless.pdf2.Form form) 46 { 47 this.form=form; 48 } 49 50 Object getPeer() 51 { 52 return form; 53 } 54 55 65 public void addElement(String name, FormElement element) 66 { 67 form.addElement(name, element.element); 68 } 69 70 75 public FormElement getElement(String name) 76 { 77 return (FormElement)PeeredObject.getPeer(form.getElement(name)); 78 } 79 80 84 public void removeElement(String name) 85 { 86 form.removeElement(name); 87 } 88 89 97 public void renameElement(String fromname, String toname) 98 { 99 form.renameElement(fromname,toname); 100 } 101 102 106 public void clear() 107 { 108 form.clear(); 109 } 110 111 118 public Map getElements() 119 { 120 Map out = new org.faceless.util.OrderedMap(); 121 Map in = form.getElements(); 122 for (Iterator i = in.entrySet().iterator();i.hasNext();) { 123 Map.Entry e = (Map.Entry)i.next(); 124 out.put(e.getKey(), PeeredObject.getPeer(e.getValue())); 125 } 126 return Collections.unmodifiableMap(out); 127 } 128 129 135 public String getName(FormElement element) 136 { 137 return form.getName(element.element); 138 } 139 140 149 public void setBackgroundStyle(PDFStyle style) 150 { 151 org.faceless.pdf2.PDFStyle newstyle = style.style; 152 153 char newcheck, newradio; 154 if (check==FormElement.STYLE_CIRCLE) newcheck=newstyle.FORMRADIOBUTTONSTYLE_CIRCLE; 155 else if (check==FormElement.STYLE_CROSS) newcheck=newstyle.FORMRADIOBUTTONSTYLE_CROSS; 156 else if (check==FormElement.STYLE_DIAMOND) newcheck=newstyle.FORMRADIOBUTTONSTYLE_DIAMOND; 157 else if (check==FormElement.STYLE_SQUARE) newcheck=newstyle.FORMRADIOBUTTONSTYLE_SQUARE; 158 else if (check==FormElement.STYLE_STAR) newcheck=newstyle.FORMRADIOBUTTONSTYLE_STAR; 159 else newcheck=newstyle.FORMRADIOBUTTONSTYLE_CHECK; 160 161 if (radio==FormElement.STYLE_CIRCLE) newradio=newstyle.FORMRADIOBUTTONSTYLE_CIRCLE; 162 else if (radio==FormElement.STYLE_CROSS) newradio=newstyle.FORMRADIOBUTTONSTYLE_CROSS; 163 else if (radio==FormElement.STYLE_DIAMOND) newradio=newstyle.FORMRADIOBUTTONSTYLE_DIAMOND; 164 else if (radio==FormElement.STYLE_SQUARE) newradio=newstyle.FORMRADIOBUTTONSTYLE_SQUARE; 165 else if (radio==FormElement.STYLE_STAR) newradio=newstyle.FORMRADIOBUTTONSTYLE_STAR; 166 else newradio=newstyle.FORMRADIOBUTTONSTYLE_CHECK; 167 168 newstyle.setFormRadioButtonStyle(newradio); 169 newstyle.setFormCheckboxStyle(newcheck); 170 171 form.setBackgroundStyle(newstyle); 172 173 this.backstyle=style; 174 } 175 176 187 public void setTextStyle(PDFStyle style) 188 { 189 form.setTextStyle(style.style); 190 } 191 192 204 public void setButtonStyle(int checkbox, int radiobutton) 205 { 206 this.check=checkbox; 207 this.radio=radiobutton; 208 setBackgroundStyle(backstyle); 209 } 210 211 public String toString() 212 { 213 Map m = getElements(); 214 String s = "<form>\n"; 215 for (Iterator i = m.keySet().iterator();i.hasNext();) { 216 String name = (String )i.next(); 217 FormElement val = (FormElement)m.get(name); 218 String z = val.toString(); 219 int j = Math.min(z.indexOf(' '), z.indexOf('>')); 220 z = z.substring(0,j)+" name=\""+name+"\""+z.substring(j); 221 s+=" "+z+"\n"; 222 } 223 return s+"</form>"; 224 } 225 } 226 | Popular Tags |