001package com.hfg.html; 002 003import com.hfg.html.attribute.Align; 004import com.hfg.html.attribute.VAlign; 005import com.hfg.xml.XMLNode; 006 007//------------------------------------------------------------------------------ 008/** 009 Represents a image (<img>) tag. 010 <div> 011 @author J. Alex Taylor, hairyfatguy.com 012 </div> 013 */ 014//------------------------------------------------------------------------------ 015// com.hfg XML/HTML Coding Library 016// 017// This library is free software; you can redistribute it and/or 018// modify it under the terms of the GNU Lesser General Public 019// License as published by the Free Software Foundation; either 020// version 2.1 of the License, or (at your option) any later version. 021// 022// This library is distributed in the hope that it will be useful, 023// but WITHOUT ANY WARRANTY; without even the implied warranty of 024// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 025// Lesser General Public License for more details. 026// 027// You should have received a copy of the GNU Lesser General Public 028// License along with this library; if not, write to the Free Software 029// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 030// 031// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 032// jataylor@hairyfatguy.com 033//------------------------------------------------------------------------------ 034 035public class Img extends HTMLTagWithCoreEvents 036{ 037 038 //########################################################################## 039 // CONSTRUCTORS 040 //########################################################################## 041 042 //-------------------------------------------------------------------------- 043 public Img() 044 { 045 super(HTML.IMG); 046 setAlt(""); 047 } 048 049 //-------------------------------------------------------------------------- 050 public Img(CharSequence inSrc) 051 { 052 this(); 053 setSrc(inSrc); 054 } 055 056 //-------------------------------------------------------------------------- 057 public Img(XMLNode inXMLNode) 058 { 059 this(); 060 initFromXMLNode(inXMLNode); 061 } 062 063 //########################################################################## 064 // PUBLIC METHODS 065 //########################################################################## 066 067 //-------------------------------------------------------------------------- 068 public Img setSrc(CharSequence inValue) 069 { 070 if (inValue != null) 071 { 072 setAttribute(HTML.SRC, inValue.toString()); 073 } 074 075 return this; 076 } 077 078 //-------------------------------------------------------------------------- 079 public String getSrc() 080 { 081 return getAttributeValue(HTML.SRC); 082 } 083 084 //-------------------------------------------------------------------------- 085 /** 086 Sets the string to be displayed before the image is loaded or in case the 087 image cannot be loaded. 088 @param inValue the value to use for the 'alt' attribute 089 @return this Img object to enable method chaining 090 */ 091 public Img setAlt(String inValue) 092 { 093 setAttribute(HTML.ALT, inValue); 094 095 return this; 096 } 097 098 //-------------------------------------------------------------------------- 099 public String getAlt() 100 { 101 return getAttributeValue(HTML.ALT); 102 } 103 104 105 106 //-------------------------------------------------------------------------- 107 public Img setAlign(Align inValue) 108 { 109 setAttribute(inValue.getHTMLAttributeName(), inValue.toString()); 110 111 return this; 112 } 113 114 //-------------------------------------------------------------------------- 115 /** 116 * Since an img align attribute allows the normally valign values of 'top' 117 * and 'bottom', this alternate setAlign method takes a VAlign object. 118 @param inValue the value to use for the 'align' attribute 119 @return this Img object to enable method chaining 120 */ 121 public Img setAlign(VAlign inValue) 122 { 123 setAttribute(HTML.ALIGN, inValue.toString()); 124 125 return this; 126 } 127 128 129 //--------------------------------------------------------------------------- 130 public Img setName(String inValue) 131 { 132 setAttribute(HTML.NAME, inValue); 133 134 return this; 135 } 136 137 //--------------------------------------------------------------------------- 138 public String getName() 139 { 140 return getAttributeValue(HTML.NAME); 141 } 142 143 144 145 //-------------------------------------------------------------------------- 146 public Img setWidth(String inValue) 147 { 148 setAttribute(HTML.WIDTH, inValue); 149 150 return this; 151 } 152 153 //-------------------------------------------------------------------------- 154 public Img setWidth(int inValue) 155 { 156 setAttribute(HTML.WIDTH, new Integer(inValue).toString()); 157 158 return this; 159 } 160 161 //-------------------------------------------------------------------------- 162 public String getWidth() 163 { 164 return getAttributeValue(HTML.WIDTH); 165 } 166 167 //-------------------------------------------------------------------------- 168 public Img setHeight(String inValue) 169 { 170 setAttribute(HTML.HEIGHT, inValue); 171 172 return this; 173 } 174 175 //-------------------------------------------------------------------------- 176 public Img setHeight(int inValue) 177 { 178 setAttribute(HTML.HEIGHT, new Integer(inValue).toString()); 179 180 return this; 181 } 182 183 //-------------------------------------------------------------------------- 184 public String getHeight() 185 { 186 return getAttributeValue(HTML.HEIGHT); 187 } 188 189 190 //-------------------------------------------------------------------------- 191 public Img setBorder(int inValue) 192 { 193 setAttribute(HTML.BORDER, new Integer(inValue).toString()); 194 195 return this; 196 } 197 198 //-------------------------------------------------------------------------- 199 public String getBorder() 200 { 201 return getAttributeValue(HTML.BORDER); 202 } 203 204 205 //-------------------------------------------------------------------------- 206 public Img setTitle(String inValue) 207 { 208 setAttribute(HTML.TITLE, inValue); 209 return this; 210 } 211 212 //-------------------------------------------------------------------------- 213 public Img setUseMap(String inValue) 214 { 215 setAttribute(HTML.USEMAP, inValue); 216 return this; 217 } 218 219 //-------------------------------------------------------------------------- 220 public Img setStyle(String inValue) 221 { 222 setAttribute(HTML.STYLE, inValue); 223 return this; 224 } 225 226 227 // Overrides for HTMLTag setters to allow method chaining. 228 229 //-------------------------------------------------------------------------- 230 @Override 231 public Img setId(String inValue) 232 { 233 return (Img) super.setId(inValue); 234 } 235 236 // Overrides for HTMLTagWithCoreEvents setters to allow method chaining. 237 238 //-------------------------------------------------------------------------- 239 @Override 240 public Img setOnClick(String inValue) 241 { 242 return (Img) super.setOnClick(inValue); 243 } 244 245 //-------------------------------------------------------------------------- 246 @Override 247 public Img setOnDblClick(String inValue) 248 { 249 return (Img) super.setOnDblClick(inValue); 250 } 251 252 //-------------------------------------------------------------------------- 253 @Override 254 public Img setOnMouseDown(String inValue) 255 { 256 return (Img) super.setOnMouseDown(inValue); 257 } 258 259 //-------------------------------------------------------------------------- 260 @Override 261 public Img setOnMouseMove(String inValue) 262 { 263 return (Img) super.setOnMouseMove(inValue); 264 } 265 266 //-------------------------------------------------------------------------- 267 @Override 268 public Img setOnMouseOut(String inValue) 269 { 270 return (Img) super.setOnMouseOut(inValue); 271 } 272 273 //-------------------------------------------------------------------------- 274 @Override 275 public Img setOnMouseOver(String inValue) 276 { 277 return (Img) super.setOnMouseOver(inValue); 278 } 279 280 //-------------------------------------------------------------------------- 281 @Override 282 public Img setOnMouseUp(String inValue) 283 { 284 return (Img) super.setOnMouseUp(inValue); 285 } 286 287 //-------------------------------------------------------------------------- 288 @Override 289 public Img setOnKeyDown(String inValue) 290 { 291 return (Img) super.setOnKeyDown(inValue); 292 } 293 294 //-------------------------------------------------------------------------- 295 @Override 296 public Img setOnKeyPress(String inValue) 297 { 298 return (Img) super.setOnKeyPress(inValue); 299 } 300 301 //-------------------------------------------------------------------------- 302 @Override 303 public Img setOnKeyUp(String inValue) 304 { 305 return (Img) super.setOnKeyUp(inValue); 306 } 307 308}