001package com.hfg.html; 002 003 004//------------------------------------------------------------------------------ 005/** 006 * Represents a checkbox form element (<input type='checkbox'>) tag. 007 * 008 * @author J. Alex Taylor, hairyfatguy.com 009 */ 010//------------------------------------------------------------------------------ 011// com.hfg XML/HTML Coding Library 012// 013// This library is free software; you can redistribute it and/or 014// modify it under the terms of the GNU Lesser General Public 015// License as published by the Free Software Foundation; either 016// version 2.1 of the License, or (at your option) any later version. 017// 018// This library is distributed in the hope that it will be useful, 019// but WITHOUT ANY WARRANTY; without even the implied warranty of 020// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 021// Lesser General Public License for more details. 022// 023// You should have received a copy of the GNU Lesser General Public 024// License along with this library; if not, write to the Free Software 025// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026// 027// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 028// jataylor@hairyfatguy.com 029//------------------------------------------------------------------------------ 030 031public class InputCheckbox extends HTMLTagWithFormEvents 032{ 033 034 //########################################################################## 035 // PRIVATE FIELDS 036 //########################################################################## 037 038 private static String sTagName = HTML.INPUT; 039 040 //########################################################################## 041 // CONSTRUCTORS 042 //########################################################################## 043 044 //-------------------------------------------------------------------------- 045 public InputCheckbox() 046 { 047 super(sTagName); 048 setAttribute(HTML.TYPE, "checkbox"); 049 } 050 051 //-------------------------------------------------------------------------- 052 public InputCheckbox(String inName, String inValue) 053 { 054 this(); 055 setName(inName); 056 setValue(inValue); 057 } 058 059 //-------------------------------------------------------------------------- 060 public InputCheckbox(String inName, String inValue, boolean checked) 061 { 062 this(inName, inValue); 063 setChecked(checked); 064 } 065 066 //########################################################################## 067 // PUBLIC METHODS 068 //########################################################################## 069 070 //-------------------------------------------------------------------------- 071 public InputCheckbox setChecked(boolean checked) 072 { 073 if (checked) { 074 setAttribute(HTML.CHECKED, "true"); 075 } 076 else { 077 removeAttribute(HTML.CHECKED); 078 } 079 080 return this; 081 } 082 083 //-------------------------------------------------------------------------- 084 public InputCheckbox setDisabled(boolean disabled) 085 { 086 if (disabled) { 087 setAttribute(HTML.DISABLED, HTML.DISABLED); 088 } 089 else { 090 removeAttribute(HTML.DISABLED); 091 } 092 093 return this; 094 } 095 096 //-------------------------------------------------------------------------- 097 public boolean isDisabled() 098 { 099 return hasAttribute(HTML.DISABLED); 100 } 101 102 //-------------------------------------------------------------------------- 103 public InputCheckbox setName(String inValue) 104 { 105 setAttribute(HTML.NAME, inValue); 106 107 return this; 108 } 109 110 //-------------------------------------------------------------------------- 111 public String getName() 112 { 113 return getAttributeValue(HTML.NAME); 114 } 115 116 //-------------------------------------------------------------------------- 117 public InputCheckbox setValue(String inValue) 118 { 119 setAttribute(HTML.VALUE, inValue); 120 121 return this; 122 } 123 124 //-------------------------------------------------------------------------- 125 public String getValue() 126 { 127 return getAttributeValue(HTML.VALUE); 128 } 129 130 131 // Overrides for HTMLTag setters to allow method chaining. 132 133 //-------------------------------------------------------------------------- 134 @Override 135 public InputCheckbox setId(String inValue) 136 { 137 return (InputCheckbox) super.setId(inValue); 138 } 139 140 //-------------------------------------------------------------------------- 141 @Override 142 public InputCheckbox setStyle(CharSequence inValue) 143 { 144 return (InputCheckbox) super.setStyle(inValue); 145 } 146 147 //-------------------------------------------------------------------------- 148 @Override 149 public InputCheckbox addStyle(String inValue) 150 { 151 return (InputCheckbox) super.addStyle(inValue); 152 } 153 154 // Overrides for HTMLTagWithCoreEvents setters to allow method chaining. 155 156 //-------------------------------------------------------------------------- 157 @Override 158 public InputCheckbox setOnClick(String inValue) 159 { 160 return (InputCheckbox) super.setOnClick(inValue); 161 } 162 163 //--------------------------------------------------------------------------- 164 @Override 165 public InputCheckbox appendToOnClick(String inValue) 166 { 167 return (InputCheckbox) super.appendToOnClick(inValue); 168 } 169 170 //-------------------------------------------------------------------------- 171 @Override 172 public InputCheckbox setOnDblClick(String inValue) 173 { 174 return (InputCheckbox) super.setOnDblClick(inValue); 175 } 176 177 //--------------------------------------------------------------------------- 178 @Override 179 public InputCheckbox appendToOnDblClick(String inValue) 180 { 181 return (InputCheckbox) super.appendToOnDblClick(inValue); 182 } 183 184 //-------------------------------------------------------------------------- 185 @Override 186 public InputCheckbox setOnMouseDown(String inValue) 187 { 188 return (InputCheckbox) super.setOnMouseDown(inValue); 189 } 190 191 //-------------------------------------------------------------------------- 192 @Override 193 public InputCheckbox setOnMouseMove(String inValue) 194 { 195 return (InputCheckbox) super.setOnMouseMove(inValue); 196 } 197 198 //-------------------------------------------------------------------------- 199 @Override 200 public InputCheckbox setOnMouseOut(String inValue) 201 { 202 return (InputCheckbox) super.setOnMouseOut(inValue); 203 } 204 205 //-------------------------------------------------------------------------- 206 @Override 207 public InputCheckbox setOnMouseOver(String inValue) 208 { 209 return (InputCheckbox) super.setOnMouseOver(inValue); 210 } 211 212 //-------------------------------------------------------------------------- 213 @Override 214 public InputCheckbox setOnMouseUp(String inValue) 215 { 216 return (InputCheckbox) super.setOnMouseUp(inValue); 217 } 218 219 //-------------------------------------------------------------------------- 220 @Override 221 public InputCheckbox setOnKeyDown(String inValue) 222 { 223 return (InputCheckbox) super.setOnKeyDown(inValue); 224 } 225 226 //-------------------------------------------------------------------------- 227 @Override 228 public InputCheckbox setOnKeyPress(String inValue) 229 { 230 return (InputCheckbox) super.setOnKeyPress(inValue); 231 } 232 233 //-------------------------------------------------------------------------- 234 @Override 235 public InputCheckbox setOnKeyUp(String inValue) 236 { 237 return (InputCheckbox) super.setOnKeyUp(inValue); 238 } 239 240 // Overrides for HTMLTagWithFormEvents setters to allow method chaining. 241 242 //-------------------------------------------------------------------------- 243 @Override 244 public InputCheckbox setOnBlur(String inValue) 245 { 246 return (InputCheckbox) super.setOnBlur(inValue); 247 } 248 249 //-------------------------------------------------------------------------- 250 @Override 251 public InputCheckbox setOnChange(String inValue) 252 { 253 return (InputCheckbox) super.setOnChange(inValue); 254 } 255 256 //-------------------------------------------------------------------------- 257 @Override 258 public InputCheckbox setOnFocus(String inValue) 259 { 260 return (InputCheckbox) super.setOnFocus(inValue); 261 } 262 263}