001package com.hfg.html; 002 003import java.awt.Color; 004 005import com.hfg.html.attribute.Align; 006import com.hfg.html.attribute.VAlign; 007import com.hfg.html.attribute.HTMLColor; 008import com.hfg.graphics.ColorUtil; 009import com.hfg.xml.XMLNode; 010 011//------------------------------------------------------------------------------ 012/** 013 * Represents a table header cell (<th>) tag. 014 * 015 * @author J. Alex Taylor, hairyfatguy.com 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 Th extends HTMLTagWithCoreEvents 039{ 040 041 //########################################################################## 042 // CONSTRUCTORS 043 //########################################################################## 044 045 //-------------------------------------------------------------------------- 046 public Th() 047 { 048 super(HTML.TH); 049 } 050 051 //-------------------------------------------------------------------------- 052 public Th(String inContent) 053 { 054 this(); 055 addContent(inContent); 056 } 057 058 //-------------------------------------------------------------------------- 059 public Th(HTMLTag inContent) 060 { 061 this(); 062 addSubtag(inContent); 063 } 064 065 //-------------------------------------------------------------------------- 066 public Th(String inContent, Align inAlign) 067 { 068 this(inContent); 069 setAlign(inAlign); 070 } 071 072 //-------------------------------------------------------------------------- 073 public Th(HTMLTag inContent, Align inAlign) 074 { 075 this(inContent); 076 setAlign(inAlign); 077 } 078 079 080 //-------------------------------------------------------------------------- 081 public Th(XMLNode inXMLNode) 082 { 083 this(); 084 initFromXMLNode(inXMLNode); 085 } 086 087 //########################################################################## 088 // PUBLIC METHODS 089 //########################################################################## 090 091 //-------------------------------------------------------------------------- 092 public Center addCenter() 093 { 094 Center center = new Center(); 095 addSubtag(center); 096 097 return center; 098 } 099 100 //-------------------------------------------------------------------------- 101 public Center addCenter(String inContent) 102 { 103 Center center = new Center(inContent); 104 addSubtag(center); 105 106 return center; 107 } 108 109 //-------------------------------------------------------------------------- 110 public Center addCenter(HTMLTag inContent) 111 { 112 Center center = new Center(inContent); 113 addSubtag(center); 114 115 return center; 116 } 117 118 //-------------------------------------------------------------------------- 119 public Form addForm() 120 { 121 Form form = new Form(); 122 addSubtag(form); 123 124 return form; 125 } 126 127 //-------------------------------------------------------------------------- 128 public Form addForm(String inFormName) 129 { 130 Form form = new Form(inFormName); 131 addSubtag(form); 132 133 return form; 134 } 135 136 137 //-------------------------------------------------------------------------- 138 public Img addImage(String inSrc) 139 { 140 Img image = new Img(inSrc); 141 addSubtag(image); 142 143 return image; 144 } 145 146 //-------------------------------------------------------------------------- 147 public Link addLink() 148 { 149 Link link = new Link(); 150 addSubtag(link); 151 152 return link; 153 } 154 155 //-------------------------------------------------------------------------- 156 public Link addLink(CharSequence inURL) 157 { 158 Link link = new Link(inURL); 159 addSubtag(link); 160 161 return link; 162 } 163 164 //-------------------------------------------------------------------------- 165 public Link addLink(CharSequence inURL, String inContent) 166 { 167 Link link = new Link(inURL, inContent); 168 addSubtag(link); 169 170 return link; 171 } 172 173 //-------------------------------------------------------------------------- 174 public Nobr addNobr() 175 { 176 Nobr nobr = new Nobr(); 177 addSubtag(nobr); 178 179 return nobr; 180 } 181 182 //-------------------------------------------------------------------------- 183 public Nobr addNobr(String inContent) 184 { 185 Nobr nobr = new Nobr(inContent); 186 addSubtag(nobr); 187 188 return nobr; 189 } 190 191 //-------------------------------------------------------------------------- 192 public Nobr addNobr(HTMLTag inContent) 193 { 194 Nobr nobr = new Nobr(inContent); 195 addSubtag(nobr); 196 197 return nobr; 198 } 199 200 //-------------------------------------------------------------------------- 201 public Pre addPre() 202 { 203 Pre pre = new Pre(); 204 addSubtag(pre); 205 206 return pre; 207 } 208 209 //-------------------------------------------------------------------------- 210 public Pre addPre(String inContent) 211 { 212 Pre pre = new Pre(inContent); 213 addSubtag(pre); 214 215 return pre; 216 } 217 218 //-------------------------------------------------------------------------- 219 public Pre addPre(HTMLTag inContent) 220 { 221 Pre pre = new Pre(inContent); 222 addSubtag(pre); 223 224 return pre; 225 } 226 227 //-------------------------------------------------------------------------- 228 public Span addSpan() 229 { 230 Span span = new Span(); 231 addSubtag(span); 232 233 return span; 234 } 235 236 //-------------------------------------------------------------------------- 237 public Span addSpan(String inContent) 238 { 239 Span span = new Span(inContent); 240 addSubtag(span); 241 242 return span; 243 } 244 245 //-------------------------------------------------------------------------- 246 public Span addSpan(HTMLTag inContent) 247 { 248 Span span = new Span(inContent); 249 addSubtag(span); 250 251 return span; 252 } 253 254 //-------------------------------------------------------------------------- 255 public Table addTable() 256 { 257 Table table = new Table(); 258 addSubtag(table); 259 260 return table; 261 } 262 263 264 265 //-------------------------------------------------------------------------- 266 public Th setTitle(String inValue) 267 { 268 setAttribute(HTML.TITLE, inValue); 269 return this; 270 } 271 272 //-------------------------------------------------------------------------- 273 public String getTitle() 274 { 275 return getAttributeValue(HTML.TITLE); 276 } 277 278 279 //-------------------------------------------------------------------------- 280 public Ul addUnorderedList() 281 { 282 Ul ul = new Ul(); 283 addSubtag(ul); 284 285 return ul; 286 } 287 288 //-------------------------------------------------------------------------- 289 public Th setAlign(Align inValue) 290 { 291 setAttribute(inValue.getHTMLAttributeName(), inValue.toString()); 292 293 return this; 294 } 295 296 //-------------------------------------------------------------------------- 297 public Th setVAlign(VAlign inValue) 298 { 299 setAttribute(inValue.getHTMLAttributeName(), inValue.toString()); 300 301 return this; 302 } 303 304 //-------------------------------------------------------------------------- 305 public Th setColSpan(int inValue) 306 { 307 setAttribute(HTML.COLSPAN, Integer.toString(inValue)); 308 309 return this; 310 } 311 312 //-------------------------------------------------------------------------- 313 public String getColSpan() 314 { 315 return getAttributeValue(HTML.COLSPAN); 316 } 317 318 //-------------------------------------------------------------------------- 319 public Th setRowSpan(int inValue) 320 { 321 setAttribute(HTML.ROWSPAN, Integer.toString(inValue)); 322 323 return this; 324 } 325 326 //-------------------------------------------------------------------------- 327 public String getRowSpan() 328 { 329 return getAttributeValue(HTML.ROWSPAN); 330 } 331 332 //--------------------------------------------------------------------------- 333 /** 334 Sets the background color for the header cell. 335 */ 336 public Th setBackgroundColor(HTMLColor inValue) 337 { 338 setAttribute(HTML.BGCOLOR, inValue); 339 return this; 340 } 341 342 //-------------------------------------------------------------------------- 343 /** 344 Sets the background color for the header cell. 345 */ 346 public Th setBackgroundColor(String inValue) 347 { 348 setAttribute(HTML.BGCOLOR, inValue); 349 350 return this; 351 } 352 353 //-------------------------------------------------------------------------- 354 /** 355 Sets the background color for the header cell. 356 */ 357 public Th setBackgroundColor(Color inValue) 358 { 359 setAttribute(HTML.BGCOLOR, "#" + ColorUtil.colorToHex(inValue)); 360 361 return this; 362 } 363 364 //-------------------------------------------------------------------------- 365 public String getBackgroundColor() 366 { 367 return getAttributeValue(HTML.BGCOLOR); 368 } 369 370 371 //-------------------------------------------------------------------------- 372 public Th setWidth(String inValue) 373 { 374 setAttribute(HTML.WIDTH, inValue); 375 376 return this; 377 } 378 379 //-------------------------------------------------------------------------- 380 public Th setWidth(int inValue) 381 { 382 setAttribute(HTML.WIDTH, Integer.toString(inValue)); 383 384 return this; 385 } 386 387 388 //-------------------------------------------------------------------------- 389 public Th br() 390 { 391 HTMLUtil.br(this); 392 return this; 393 } 394 395 //-------------------------------------------------------------------------- 396 public Th br(int inNumber) 397 { 398 HTMLUtil.br(this, inNumber); 399 return this; 400 } 401 402 //-------------------------------------------------------------------------- 403 public Th nbsp(int inNumber) 404 { 405 HTMLUtil.nbsp(this, inNumber); 406 return this; 407 } 408 409 //-------------------------------------------------------------------------- 410 public void hr() 411 { 412 HTMLUtil.hr(this); 413 } 414 415 //-------------------------------------------------------------------------- 416 public void hr(String inWidth) 417 { 418 HTMLUtil.hr(this, inWidth); 419 } 420 421 422 // Overrides for HTMLTag setters to allow method chaining. 423 424 //-------------------------------------------------------------------------- 425 @Override 426 public Th addClass(String inValue) 427 { 428 return (Th) super.addClass(inValue); 429 } 430 431 //-------------------------------------------------------------------------- 432 @Override 433 public Th setClass(String inValue) 434 { 435 return (Th) super.setClass(inValue); 436 } 437 438 //-------------------------------------------------------------------------- 439 @Override 440 public Th setId(String inValue) 441 { 442 return (Th) super.setId(inValue); 443 } 444 445 //-------------------------------------------------------------------------- 446 @Override 447 public Th setStyle(CharSequence inValue) 448 { 449 return (Th) super.setStyle(inValue); 450 } 451 452 //-------------------------------------------------------------------------- 453 @Override 454 public Th addStyle(String inValue) 455 { 456 return (Th) super.addStyle(inValue); 457 } 458 459 // Overrides for HTMLTagWithCoreEvents setters to allow method chaining. 460 461 //-------------------------------------------------------------------------- 462 @Override 463 public Th setOnClick(String inValue) 464 { 465 return (Th) super.setOnClick(inValue); 466 } 467 468 //-------------------------------------------------------------------------- 469 @Override 470 public Th appendToOnClick(String inValue) 471 { 472 return (Th) super.appendToOnClick(inValue); 473 } 474 475 //-------------------------------------------------------------------------- 476 @Override 477 public Th setOnDblClick(String inValue) 478 { 479 return (Th) super.setOnDblClick(inValue); 480 } 481 482 //-------------------------------------------------------------------------- 483 @Override 484 public Th appendToOnDblClick(String inValue) 485 { 486 return (Th) super.appendToOnDblClick(inValue); 487 } 488 489 //-------------------------------------------------------------------------- 490 @Override 491 public Th setOnMouseDown(String inValue) 492 { 493 return (Th) super.setOnMouseDown(inValue); 494 } 495 496 //-------------------------------------------------------------------------- 497 @Override 498 public Th setOnMouseMove(String inValue) 499 { 500 return (Th) super.setOnMouseMove(inValue); 501 } 502 503 //-------------------------------------------------------------------------- 504 @Override 505 public Th appendToOnMouseOut(String inValue) 506 { 507 return (Th) super.appendToOnMouseOut(inValue); 508 } 509 510 //-------------------------------------------------------------------------- 511 @Override 512 public Th setOnMouseOut(String inValue) 513 { 514 return (Th) super.setOnMouseOut(inValue); 515 } 516 517 //-------------------------------------------------------------------------- 518 @Override 519 public Th appendToOnMouseOver(String inValue) 520 { 521 return (Th) super.appendToOnMouseOver(inValue); 522 } 523 524 //-------------------------------------------------------------------------- 525 @Override 526 public Th setOnMouseOver(String inValue) 527 { 528 return (Th) super.setOnMouseOver(inValue); 529 } 530 531 //-------------------------------------------------------------------------- 532 @Override 533 public Th setOnMouseUp(String inValue) 534 { 535 return (Th) super.setOnMouseUp(inValue); 536 } 537 538 //-------------------------------------------------------------------------- 539 @Override 540 public Th setOnKeyDown(String inValue) 541 { 542 return (Th) super.setOnKeyDown(inValue); 543 } 544 545 //-------------------------------------------------------------------------- 546 @Override 547 public Th setOnKeyPress(String inValue) 548 { 549 return (Th) super.setOnKeyPress(inValue); 550 } 551 552 //-------------------------------------------------------------------------- 553 @Override 554 public Th setOnKeyUp(String inValue) 555 { 556 return (Th) super.setOnKeyUp(inValue); 557 } 558}