001package com.hfg.html; 002 003import java.awt.Color; 004 005import com.hfg.html.attribute.HTMLColor; 006import com.hfg.graphics.ColorUtil; 007import com.hfg.xml.XMLAttribute; 008import com.hfg.xml.XMLNode; 009 010//------------------------------------------------------------------------------ 011/** 012 Represents a body (<body>) tag. 013 <div> 014 @author J. Alex Taylor, hairyfatguy.com 015 </div> 016 */ 017//------------------------------------------------------------------------------ 018// com.hfg XML/HTML Coding Library 019// 020// This library is free software; you can redistribute it and/or 021// modify it under the terms of the GNU Lesser General Public 022// License as published by the Free Software Foundation; either 023// version 2.1 of the License, or (at your option) any later version. 024// 025// This library is distributed in the hope that it will be useful, 026// but WITHOUT ANY WARRANTY; without even the implied warranty of 027// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 028// Lesser General Public License for more details. 029// 030// You should have received a copy of the GNU Lesser General Public 031// License along with this library; if not, write to the Free Software 032// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 033// 034// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 035// jataylor@hairyfatguy.com 036//------------------------------------------------------------------------------ 037 038public class Body extends HTMLTagWithCoreEvents 039{ 040 //########################################################################### 041 // CONSTRUCTORS 042 //########################################################################### 043 044 //--------------------------------------------------------------------------- 045 public Body() 046 { 047 super(HTML.BODY); 048 } 049 050 //-------------------------------------------------------------------------- 051 public Body(XMLNode inXMLNode) 052 { 053 this(); 054 initFromXMLNode(inXMLNode); 055 } 056 057 //########################################################################### 058 // PUBLIC METHODS 059 //########################################################################### 060 061 062 //--------------------------------------------------------------------------- 063 public Center addCenter() 064 { 065 Center center = new Center(); 066 addSubtag(center); 067 068 return center; 069 } 070 071 //--------------------------------------------------------------------------- 072 public Center addCenter(String inContent) 073 { 074 Center center = new Center(inContent); 075 addSubtag(center); 076 077 return center; 078 } 079 080 //--------------------------------------------------------------------------- 081 public Center addCenter(HTMLTag inContent) 082 { 083 Center center = new Center(inContent); 084 addSubtag(center); 085 086 return center; 087 } 088 089 090 //--------------------------------------------------------------------------- 091 public Div addDiv() 092 { 093 Div div = new Div(); 094 addSubtag(div); 095 096 return div; 097 } 098 099 //--------------------------------------------------------------------------- 100 public Div addDiv(String inContent) 101 { 102 Div div = new Div(inContent); 103 addSubtag(div); 104 105 return div; 106 } 107 108 //--------------------------------------------------------------------------- 109 public Form addForm() 110 { 111 Form form = new Form(); 112 addSubtag(form); 113 114 return form; 115 } 116 117 //--------------------------------------------------------------------------- 118 public Form addForm(String inFormName) 119 { 120 Form form = new Form(inFormName); 121 addSubtag(form); 122 123 return form; 124 } 125 126 127 //--------------------------------------------------------------------------- 128 public Img addImage(String inSrc) 129 { 130 Img image = new Img(inSrc); 131 addSubtag(image); 132 133 return image; 134 } 135 136 //--------------------------------------------------------------------------- 137 public ImageMap addImageMap() 138 { 139 ImageMap imageMap = new ImageMap(); 140 addSubtag(imageMap); 141 142 return imageMap; 143 } 144 145 //--------------------------------------------------------------------------- 146 public IFrame addIFrame() 147 { 148 IFrame iframe = new IFrame(); 149 addSubtag(iframe); 150 151 return iframe; 152 } 153 154 //--------------------------------------------------------------------------- 155 public Link addLink() 156 { 157 Link link = new Link(); 158 addSubtag(link); 159 160 return link; 161 } 162 163 //--------------------------------------------------------------------------- 164 public Link addLink(CharSequence inURL) 165 { 166 Link link = new Link(inURL); 167 addSubtag(link); 168 169 return link; 170 } 171 172 //--------------------------------------------------------------------------- 173 public Link addLink(CharSequence inURL, String inContent) 174 { 175 Link link = new Link(inURL, inContent); 176 addSubtag(link); 177 178 return link; 179 } 180 181 182 //--------------------------------------------------------------------------- 183 public Nobr addNobr() 184 { 185 Nobr nobr = new Nobr(); 186 addSubtag(nobr); 187 188 return nobr; 189 } 190 191 //--------------------------------------------------------------------------- 192 public Nobr addNobr(String inContent) 193 { 194 Nobr nobr = new Nobr(inContent); 195 addSubtag(nobr); 196 197 return nobr; 198 } 199 200 //--------------------------------------------------------------------------- 201 public Nobr addNobr(HTMLTag inContent) 202 { 203 Nobr nobr = new Nobr(inContent); 204 addSubtag(nobr); 205 206 return nobr; 207 } 208 209 210 //--------------------------------------------------------------------------- 211 public Pre addPre() 212 { 213 Pre pre = new Pre(); 214 addSubtag(pre); 215 216 return pre; 217 } 218 219 //--------------------------------------------------------------------------- 220 public Pre addPre(String inContent) 221 { 222 Pre pre = new Pre(inContent); 223 addSubtag(pre); 224 225 return pre; 226 } 227 228 //--------------------------------------------------------------------------- 229 public Pre addPre(HTMLTag inContent) 230 { 231 Pre pre = new Pre(inContent); 232 addSubtag(pre); 233 234 return pre; 235 } 236 237 //--------------------------------------------------------------------------- 238 public Span addSpan() 239 { 240 Span span = new Span(); 241 addSubtag(span); 242 243 return span; 244 } 245 246 //--------------------------------------------------------------------------- 247 public Span addSpan(String inContent) 248 { 249 Span span = new Span(inContent); 250 addSubtag(span); 251 252 return span; 253 } 254 255 //--------------------------------------------------------------------------- 256 public Span addSpan(HTMLTag inContent) 257 { 258 Span span = new Span(inContent); 259 addSubtag(span); 260 261 return span; 262 } 263 264 //--------------------------------------------------------------------------- 265 public Table addTable() 266 { 267 Table table = new Table(); 268 addSubtag(table); 269 270 return table; 271 } 272 273 274 //--------------------------------------------------------------------------- 275 public Ul addUnorderedList() 276 { 277 Ul ul = new Ul(); 278 addSubtag(ul); 279 280 return ul; 281 } 282 283 //--------------------------------------------------------------------------- 284 public void br() 285 { 286 HTMLUtil.br(this); 287 } 288 289 //--------------------------------------------------------------------------- 290 public void br(int inNumber) 291 { 292 HTMLUtil.br(this, inNumber); 293 } 294 295 //--------------------------------------------------------------------------- 296 public void nbsp(int inNumber) 297 { 298 HTMLUtil.nbsp(this, inNumber); 299 } 300 301 //--------------------------------------------------------------------------- 302 public void hr() 303 { 304 HTMLUtil.hr(this); 305 } 306 307 //--------------------------------------------------------------------------- 308 public void hr(String inWidth) 309 { 310 HTMLUtil.hr(this, inWidth); 311 } 312 313 //--------------------------------------------------------------------------- 314 /** 315 Sets the background image for the page. 316 @param inValue the URL of the background image to use for the body 317 @return this Body object to enable method chaining 318 */ 319 public Body setBackground(String inValue) 320 { 321 setAttribute(HTML.BACKGROUND, inValue); 322 return this; 323 } 324 325 //--------------------------------------------------------------------------- 326 /** 327 Sets the background color for the page. 328 @param inValue the background color to use for the body 329 @return this Body object to enable method chaining 330 */ 331 public Body setBackgroundColor(HTMLColor inValue) 332 { 333 setAttribute(HTML.BGCOLOR, inValue); 334 return this; 335 } 336 337 //-------------------------------------------------------------------------- 338 /** 339 Sets the background color for the page. 340 @param inValue the background color to use for the body 341 @return this Body object to enable method chaining 342 */ 343 public Body setBackgroundColor(Color inValue) 344 { 345 setAttribute(HTML.BGCOLOR, "#" + ColorUtil.colorToHex(inValue)); 346 return this; 347 } 348 349 //--------------------------------------------------------------------------- 350 /** 351 Sets the background color for the page. 352 @param inValue the background color to use for the body 353 @return this Body object to enable method chaining 354 */ 355 public Body setBackgroundColor(String inValue) 356 { 357 setAttribute(HTML.BGCOLOR, inValue); 358 return this; 359 } 360 361 //--------------------------------------------------------------------------- 362 /** 363 Sets the class attribute to the specified value. 364 @param inValue the CSS class(es) to apply to the body 365 @return this Body object to enable method chaining 366 */ 367 @Override 368 public Body setClass(String inValue) 369 { 370 setAttribute(HTML.CLASS, inValue); 371 return this; 372 } 373 374 //--------------------------------------------------------------------------- 375 /** 376 Sets the onload attribute to the specified value. 377 @param inValue the 'onload' javascript to apply to the body 378 @return this Body object to enable method chaining 379 */ 380 public Body setOnLoad(String inValue) 381 { 382 setAttribute(HTML.ONLOAD, inValue); 383 return this; 384 } 385 386 //--------------------------------------------------------------------------- 387 /** 388 Appends the specified javascript to the body's onload attribute. 389 @param inValue javascript to append to the 'onload' javascript for the body 390 @return this Body object to enable method chaining 391 */ 392 public Body appendToOnLoad(String inValue) 393 { 394 XMLAttribute attr = getAttribute(HTML.ONLOAD); 395 String value = (attr != null ? attr.getValue() + " " : ""); 396 setAttribute(HTML.ONLOAD, value + inValue); 397 return this; 398 } 399 400 401 // Overrides for HTMLTag setters to allow method chaining. 402 403 //-------------------------------------------------------------------------- 404 @Override 405 public Body setId(String inValue) 406 { 407 return (Body) super.setId(inValue); 408 } 409 410 //-------------------------------------------------------------------------- 411 @Override 412 public Body setStyle(CharSequence inValue) 413 { 414 return (Body) super.setStyle(inValue); 415 } 416 417 //-------------------------------------------------------------------------- 418 @Override 419 public Body addStyle(String inValue) 420 { 421 return (Body) super.addStyle(inValue); 422 } 423 424 // Overrides for HTMLTagWithCoreEvents setters to allow method chaining. 425 426 //-------------------------------------------------------------------------- 427 @Override 428 public Body setOnClick(String inValue) 429 { 430 return (Body) super.setOnClick(inValue); 431 } 432 433 //-------------------------------------------------------------------------- 434 @Override 435 public Body setOnDblClick(String inValue) 436 { 437 return (Body) super.setOnDblClick(inValue); 438 } 439 440 //-------------------------------------------------------------------------- 441 @Override 442 public Body setOnMouseDown(String inValue) 443 { 444 return (Body) super.setOnMouseDown(inValue); 445 } 446 447 //-------------------------------------------------------------------------- 448 @Override 449 public Body setOnMouseMove(String inValue) 450 { 451 return (Body) super.setOnMouseMove(inValue); 452 } 453 454 //-------------------------------------------------------------------------- 455 @Override 456 public Body setOnMouseOut(String inValue) 457 { 458 return (Body) super.setOnMouseOut(inValue); 459 } 460 461 //-------------------------------------------------------------------------- 462 @Override 463 public Body setOnMouseOver(String inValue) 464 { 465 return (Body) super.setOnMouseOver(inValue); 466 } 467 468 //-------------------------------------------------------------------------- 469 @Override 470 public Body setOnMouseUp(String inValue) 471 { 472 return (Body) super.setOnMouseUp(inValue); 473 } 474 475 //-------------------------------------------------------------------------- 476 @Override 477 public Body setOnKeyDown(String inValue) 478 { 479 return (Body) super.setOnKeyDown(inValue); 480 } 481 482 //-------------------------------------------------------------------------- 483 @Override 484 public Body setOnKeyPress(String inValue) 485 { 486 return (Body) super.setOnKeyPress(inValue); 487 } 488 489 //-------------------------------------------------------------------------- 490 @Override 491 public Body setOnKeyUp(String inValue) 492 { 493 return (Body) super.setOnKeyUp(inValue); 494 } 495 496}