1 64 65 package com.jcorporate.expresso.services.html; 66 67 72 73 import java.io.PrintWriter ; 74 import java.util.Enumeration ; 75 import java.util.Vector ; 76 77 78 84 public class CheckBox 85 extends HtmlElement { 86 private String fieldName = null; 87 protected String currentValue = (""); 88 private Vector values = new Vector (3); 89 private Vector labels = new Vector (3); 90 private boolean isChecked = false; 91 private String thisClass = (this.getClass().getName() + "."); 92 private boolean isVertical = false; 93 94 99 public CheckBox() 100 throws HtmlException { 101 super(); 102 } 103 104 111 public CheckBox(String newFieldName, String newCurrentValue) 112 throws HtmlException { 113 super(newFieldName); 114 fieldName = newFieldName; 115 currentValue = newCurrentValue; 116 } 117 118 127 public CheckBox(String newFieldName, String newFieldValue, 128 boolean newChecked) 129 throws HtmlException { 130 super(newFieldName); 131 fieldName = newFieldName; 132 addOption(newFieldValue, ""); 133 setCurrentValue(newFieldValue); 134 isChecked = newChecked; 135 } 136 137 144 public synchronized void addOption(String fieldValue, String fieldLabel) 145 throws HtmlException { 146 values.addElement(fieldValue); 147 labels.addElement(fieldLabel); 148 } 149 150 151 158 protected synchronized void display(PrintWriter out, int depth) 159 throws HtmlException { 160 String myName = (thisClass + "display(PrintWriter)"); 161 162 if (values.size() == 0) { 163 throw new HtmlException(myName + ":CheckBox " + getName() + 164 " has no choices"); 165 } 166 167 String oneValue = null; 168 String oneLabel = null; 169 Enumeration e2 = labels.elements(); 170 171 for (Enumeration e = values.elements(); e.hasMoreElements();) { 172 oneValue = (String ) e.nextElement(); 173 oneLabel = (String ) e2.nextElement(); 174 175 if (isVertical) { 176 this.padWithTabs(out, depth); 177 out.print("<br />"); 178 } 179 if ((oneLabel != null) && !(oneLabel.trim().equals(""))) { 180 out.println(oneLabel); 181 } 182 if (isChecked) { 183 this.padWithTabs(out, depth); 184 out.println("<input type=checkbox name=\"" + fieldName + 185 "\" checked value=\"" + oneValue + "\"/>"); 186 } else { 187 this.padWithTabs(out, depth); 188 out.println("<input type=checkbox name=\"" + fieldName + 189 "\" value=\"" + oneValue + "\"/>"); 190 } 191 } 192 193 setDisplayed(); 194 } 195 196 197 203 public void setChecked(boolean newChecked) 204 throws HtmlException { 205 isChecked = newChecked; 206 } 207 208 209 215 public void setCurrentValue(String newCurrentValue) 216 throws HtmlException { 217 currentValue = newCurrentValue; 218 } 219 220 221 224 public void setVertical(boolean state) { 225 isVertical = state; 226 } 227 228 } 229 230 | Popular Tags |