1 28 29 package com.caucho.widget; 30 31 import java.io.IOException; 32 33 public class TextboxWidget 34 extends XulWidget 35 { 36 private static final int NULL_INTEGER = Integer.MIN_VALUE; 37 private static final String NULL_VALUE = ""; 38 39 private VarDefinition valueDef = new XulVarDefinition(this, "value", String.class); 40 41 private EditProperty _editProperty = new EditProperty(this); 42 private DisabledProperty _disabledProperty = new DisabledProperty(this); 43 private ReadonlyProperty _readonlyProperty = new ReadonlyProperty(this); 44 45 private boolean _isMultiline; 46 47 private int _tabindex = NULL_INTEGER; 48 49 private int _cols = NULL_INTEGER; 50 private int _rows = NULL_INTEGER; 51 52 private int _size = NULL_INTEGER; 53 54 private int _maxlength = NULL_INTEGER; 55 56 public TextboxWidget() 57 { 58 } 59 60 public TextboxWidget(String id) 61 { 62 setId(id); 63 } 64 65 public TextboxWidget(String id, String initialValue) 66 { 67 setId(id); 68 setValue(initialValue); 69 } 70 71 public void setValue(String value) 72 { 73 valueDef.setValue(value); 74 } 75 76 public String getValue() 77 { 78 return valueDef.getValue(); 79 } 80 81 84 public void setMultiline(boolean isMultiline) 85 { 86 _isMultiline = isMultiline; 87 } 88 89 public boolean isMultiline() 90 { 91 return _isMultiline; 92 } 93 94 104 public void setSize(int size) 105 { 106 _size = size; 107 } 108 109 public int getSize() 110 { 111 return _size; 112 } 113 114 124 public void setCols(int cols) 125 { 126 _cols = cols; 127 } 128 129 public int getCols() 130 { 131 return _cols; 132 } 133 134 141 public void setRows(int rows) 142 { 143 _rows = rows; 144 } 145 146 public int getRows() 147 { 148 return _rows; 149 } 150 151 155 public void setMaxlength(int maxlength) 156 { 157 _maxlength = maxlength; 158 } 159 160 public int getMaxlength() 161 { 162 return _maxlength; 163 } 164 165 public void setTabindex(int tabindex) 166 { 167 _tabindex = tabindex; 168 } 169 170 public int getTabindex() 171 { 172 return _tabindex; 173 } 174 175 public void setEdit(boolean isEdit) 176 { 177 _editProperty.setValue(isEdit); 178 } 179 180 public boolean isEdit() 181 { 182 return _editProperty.getValue(); 183 } 184 185 public void setDisabled(boolean isDisabled) 186 { 187 _disabledProperty.setValue(isDisabled); 188 } 189 190 public boolean isDisabled() 191 { 192 return _disabledProperty.getValue(); 193 } 194 195 public void setReadonly(boolean isReadonly) 196 { 197 _readonlyProperty.setValue(isReadonly); 198 } 199 200 public boolean isReadonly() 201 { 202 return _readonlyProperty.getValue(); 203 } 204 205 public void init(WidgetInit init) 206 throws WidgetException 207 { 208 super.init(init); 209 210 _editProperty.init(init); 211 _disabledProperty.init(init); 212 _readonlyProperty.init(init); 213 214 if (valueDef.getValue() == null) 215 valueDef.setValue(NULL_VALUE); 216 217 init.addVarDefinition(valueDef); 218 } 219 220 223 public void setValue(VarContext context, String value) 224 { 225 if (value == null) 226 value = NULL_VALUE; 227 228 context.setVar(this, valueDef, value); 229 } 230 231 235 public String getValue(VarContext context) 236 { 237 return context.getVar(this, valueDef); 238 } 239 240 public void setEdit(VarContext context, boolean isEdit) 241 { 242 _editProperty.setValue(context, isEdit); 243 } 244 245 public boolean isEdit(VarContext context) 246 { 247 return _editProperty.getValue(context); 248 } 249 250 public void setDisabled(VarContext context, boolean isDisabled) 251 { 252 _disabledProperty.setValue(context, isDisabled); 253 } 254 255 public boolean isDisabled(VarContext context) 256 { 257 return _disabledProperty.getValue(context); 258 } 259 260 public void setReadonly(VarContext context, boolean isReadonly) 261 { 262 _readonlyProperty.setValue(context, isReadonly); 263 } 264 265 public boolean isReadonly(VarContext context) 266 { 267 return _readonlyProperty.getValue(context); 268 } 269 270 public void response(WidgetResponse response) 271 throws WidgetException, IOException 272 { 273 WidgetWriter out = response.getWriter(); 274 275 String id = getId(); 276 String cssClass = getCssClass(response); 277 278 String value = getValue(response); 279 280 boolean isEdit = isEdit(response); 281 boolean isReadonly = isReadonly(response); 282 boolean isDisabled = isDisabled(response); 283 284 out.startElement("span"); 285 out.writeAttribute("id", id); 286 287 String readonlyAttribute = isReadonly ? "readonly" : null; 288 String disabledAttribute = isDisabled ? "disabled" : null; 289 290 out.writeAttribute("class", cssClass, readonlyAttribute, disabledAttribute); 291 292 if (isEdit) { 293 int tabindex = getTabindex(); 294 int cols = getCols(); 295 int rows = getRows(); 296 int maxlength = getMaxlength(); 297 int size = getSize(); 298 299 if (isMultiline()) { 300 out.startElement("textarea"); 301 302 out.writeAttribute("name", id); 303 304 if (tabindex != NULL_INTEGER) 305 out.writeAttribute("tabindex", getCols()); 306 307 if (isReadonly) 308 out.writeAttribute("readonly", true); 309 310 if (isDisabled) 311 out.writeAttribute("disabled", true); 312 313 if (cols != NULL_INTEGER) 314 out.writeAttribute("cols", getCols()); 315 else if (size != NULL_INTEGER) 316 out.writeAttribute("cols", size); 317 318 if (rows != NULL_INTEGER) 319 out.writeAttribute("rows", rows); 320 321 if (value != null) 322 out.writeText(value); 323 324 out.endElement("textarea"); 325 } 326 else { 327 out.startElement("input"); 328 out.writeAttribute("name", id); 329 330 if (tabindex != NULL_INTEGER) 331 out.writeAttribute("tabindex", getCols()); 332 333 if (isReadonly) 334 out.writeAttribute("readonly", true); 335 336 if (isDisabled) 337 out.writeAttribute("disabled", true); 338 339 if (maxlength != NULL_INTEGER) 340 out.writeAttribute("maxlength", maxlength); 341 342 if (size != NULL_INTEGER) 343 out.writeAttribute("size", size); 344 else if (cols != NULL_INTEGER) 345 out.writeAttribute("size", cols); 346 347 if (value != null) 348 out.writeAttribute("value", value); 349 350 out.endElement("input"); 351 } 352 } 353 else { 354 out.writeText(value); 355 } 356 357 out.endElement("span"); 358 } 359 } | Popular Tags |