001package com.hfg.html;
002
003import com.hfg.html.attribute.Align;
004import com.hfg.html.attribute.HTMLColor;
005import com.hfg.html.attribute.VAlign;
006import com.hfg.graphics.ColorUtil;
007import com.hfg.xml.XMLNode;
008import com.hfg.xml.XMLTag;
009
010import java.awt.*;
011
012
013//------------------------------------------------------------------------------
014/**
015 * Represents a table cell (<td>) tag.
016 *
017 * @author J. Alex Taylor, hairyfatguy.com
018 */
019//------------------------------------------------------------------------------
020// com.hfg XML/HTML Coding Library
021//
022// This library is free software; you can redistribute it and/or
023// modify it under the terms of the GNU Lesser General Public
024// License as published by the Free Software Foundation; either
025// version 2.1 of the License, or (at your option) any later version.
026//
027// This library is distributed in the hope that it will be useful,
028// but WITHOUT ANY WARRANTY; without even the implied warranty of
029// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
030// Lesser General Public License for more details.
031//
032// You should have received a copy of the GNU Lesser General Public
033// License along with this library; if not, write to the Free Software
034// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
035//
036// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
037// jataylor@hairyfatguy.com
038//------------------------------------------------------------------------------
039
040public class Td extends HTMLTagWithCoreEvents
041{
042
043   //##########################################################################
044   // PRIVATE FIELDS
045   //##########################################################################
046
047
048   //##########################################################################
049   // CONSTRUCTORS
050   //##########################################################################
051
052   //--------------------------------------------------------------------------
053   public Td()
054   {
055      super(HTML.TD);
056   }
057
058   //--------------------------------------------------------------------------
059   public Td(String inContent)
060   {
061      this();
062      addContent(inContent);
063   }
064
065   //--------------------------------------------------------------------------
066   public Td(HTMLNode inContent)
067   {
068      this();
069      addSubtag(inContent);
070   }
071
072   //--------------------------------------------------------------------------
073   public Td(String inContent, Align inAlign)
074   {
075      this(inContent);
076      setAlign(inAlign);
077   }
078
079   //--------------------------------------------------------------------------
080   public Td(HTMLNode inContent, Align inAlign)
081   {
082      this(inContent);
083      setAlign(inAlign);
084   }
085
086   //--------------------------------------------------------------------------
087   public Td(XMLNode inXMLNode)
088   {
089      this();
090      initFromXMLNode(inXMLNode);
091   }
092
093   //##########################################################################
094   // PUBLIC METHODS
095   //##########################################################################
096
097
098   //--------------------------------------------------------------------------
099   public Center addCenter()
100   {
101      Center center = new Center();
102      addSubtag(center);
103
104      return center;
105   }
106
107   //--------------------------------------------------------------------------
108   public Center addCenter(String inContent)
109   {
110      Center center = new Center(inContent);
111      addSubtag(center);
112
113      return center;
114   }
115
116   //--------------------------------------------------------------------------
117   public Center addCenter(HTMLTag inContent)
118   {
119      Center center = new Center(inContent);
120      addSubtag(center);
121
122      return center;
123   }
124
125   //--------------------------------------------------------------------------
126   public Div addDiv()
127   {
128      Div div = new Div();
129      addSubtag(div);
130
131      return div;
132   }
133
134   //--------------------------------------------------------------------------
135   public Div addDiv(String inContent)
136   {
137      Div div = new Div(inContent);
138      addSubtag(div);
139
140      return div;
141   }
142
143   //--------------------------------------------------------------------------
144   public Div addDiv(HTMLTag inContent)
145   {
146      Div div = new Div(inContent);
147      addSubtag(div);
148
149      return div;
150   }
151
152   //--------------------------------------------------------------------------
153   public Form addForm()
154   {
155      Form form = new Form();
156      addSubtag(form);
157
158      return form;
159   }
160
161   //--------------------------------------------------------------------------
162   public Form addForm(String inFormName)
163   {
164      Form form = new Form(inFormName);
165      addSubtag(form);
166
167      return form;
168   }
169
170
171   //--------------------------------------------------------------------------
172   public Img addImage(String inSrc)
173   {
174      Img image = new Img(inSrc);
175      addSubtag(image);
176
177      return image;
178   }
179
180
181   //---------------------------------------------------------------------------
182   public ImageMap addImageMap()
183   {
184      ImageMap imageMap = new ImageMap();
185      addSubtag(imageMap);
186
187      return imageMap;
188   }
189
190   //---------------------------------------------------------------------------
191   public void addImageMap(ImageMap inValue)
192   {
193      addSubtag(inValue);
194   }
195
196   //--------------------------------------------------------------------------
197   public Link addLink()
198   {
199      Link link = new Link();
200      addSubtag(link);
201
202      return link;
203   }
204
205   //--------------------------------------------------------------------------
206   public Link addLink(Link inLink)
207   {
208      addSubtag(inLink);
209
210      return inLink;
211   }
212
213   //--------------------------------------------------------------------------
214   public Link addLink(CharSequence inURL)
215   {
216      Link link = new Link(inURL);
217      addSubtag(link);
218
219      return link;
220   }
221
222   //--------------------------------------------------------------------------
223   public Link addLink(CharSequence inURL, String inContent)
224   {
225      Link link = new Link(inURL, inContent);
226      addSubtag(link);
227
228      return link;
229   }
230
231   //--------------------------------------------------------------------------
232   public Link addLink(CharSequence inURL, HTMLTag inContent)
233   {
234      Link link = new Link(inURL, inContent);
235      addSubtag(link);
236
237      return link;
238   }
239
240   //--------------------------------------------------------------------------
241   public Nobr addNobr()
242   {
243      Nobr nobr = new Nobr();
244      addSubtag(nobr);
245
246      return nobr;
247   }
248
249   //--------------------------------------------------------------------------
250   public Nobr addNobr(String inContent)
251   {
252      Nobr nobr = new Nobr(inContent);
253      addSubtag(nobr);
254
255      return nobr;
256   }
257
258   //--------------------------------------------------------------------------
259   public Nobr addNobr(HTMLTag inContent)
260   {
261      Nobr nobr = new Nobr(inContent);
262      addSubtag(nobr);
263
264      return nobr;
265   }
266
267   //--------------------------------------------------------------------------
268   public Pre addPre()
269   {
270      Pre pre = new Pre();
271      addSubtag(pre);
272
273      return pre;
274   }
275
276   //--------------------------------------------------------------------------
277   public Pre addPre(String inContent)
278   {
279      Pre pre = new Pre(inContent);
280      addSubtag(pre);
281
282      return pre;
283   }
284
285   //--------------------------------------------------------------------------
286   public Pre addPre(HTMLTag inContent)
287   {
288      Pre pre = new Pre(inContent);
289      addSubtag(pre);
290
291      return pre;
292   }
293
294   //--------------------------------------------------------------------------
295   public Script addScript()
296   {
297      Script script = new Script();
298      addSubtag(script);
299
300      return script;
301   }
302
303   //--------------------------------------------------------------------------
304   public Span addSpan()
305   {
306      Span span = new Span();
307      addSubtag(span);
308
309      return span;
310   }
311
312   //--------------------------------------------------------------------------
313   public Span addSpan(String inContent)
314   {
315      Span span = new Span(inContent);
316      addSubtag(span);
317
318      return span;
319   }
320
321   //--------------------------------------------------------------------------
322   public Span addSpan(HTMLTag inContent)
323   {
324      Span span = new Span(inContent);
325      addSubtag(span);
326
327      return span;
328   }
329
330   //--------------------------------------------------------------------------
331   public Table addTable()
332   {
333      Table table = new Table();
334      addSubtag(table);
335
336      return table;
337   }
338
339   //--------------------------------------------------------------------------
340   public Ul addUnorderedList()
341   {
342      Ul ul = new Ul();
343      addSubtag(ul);
344
345      return ul;
346   }
347
348
349
350   //--------------------------------------------------------------------------
351   public InputButton addButton()
352   {
353      InputButton button = new InputButton();
354      addSubtag(button);
355
356      return button;
357   }
358
359   //--------------------------------------------------------------------------
360   public InputButton addButton(String inName, String inValue)
361   {
362      InputButton button = new InputButton(inName, inValue);
363      addSubtag(button);
364
365      return button;
366   }
367
368   //--------------------------------------------------------------------------
369   public InputSubmit addSubmit()
370   {
371      InputSubmit submit = new InputSubmit();
372      addSubtag(submit);
373
374      return submit;
375   }
376
377   //--------------------------------------------------------------------------
378   public InputSubmit addSubmit(String inName, String inValue)
379   {
380      InputSubmit submit = new InputSubmit(inName, inValue);
381      addSubtag(submit);
382
383      return submit;
384   }
385
386   //--------------------------------------------------------------------------
387   public Textarea addTextarea()
388   {
389      Textarea textarea = new Textarea();
390      addSubtag(textarea);
391
392      return textarea;
393   }
394
395   //--------------------------------------------------------------------------
396   public Textarea addTextarea(String inName, String inValue)
397   {
398      Textarea textarea = new Textarea(inName, inValue);
399      addSubtag(textarea);
400
401      return textarea;
402   }
403
404   //--------------------------------------------------------------------------
405   public InputText addTextInput()
406   {
407      InputText text = new InputText();
408      addSubtag(text);
409
410      return text;
411   }
412
413   //--------------------------------------------------------------------------
414   public InputText addTextInput(String inName, String inValue)
415   {
416      InputText text = new InputText(inName, inValue);
417      addSubtag(text);
418
419      return text;
420   }
421
422   //--------------------------------------------------------------------------
423   public InputPassword addPasswordInput()
424   {
425      InputPassword input = new InputPassword();
426      addSubtag(input);
427
428      return input;
429   }
430
431   //--------------------------------------------------------------------------
432   public InputPassword addPasswordInput(String inName, String inValue)
433   {
434      InputPassword input = new InputPassword(inName, inValue);
435      addSubtag(input);
436
437      return input;
438   }
439
440   //--------------------------------------------------------------------------
441   public InputCheckbox addCheckbox(String inName, String inValue)
442   {
443      InputCheckbox checkbox = new InputCheckbox(inName, inValue);
444      addSubtag(checkbox);
445
446      return checkbox;
447   }
448
449   //--------------------------------------------------------------------------
450   public InputCheckbox addCheckbox(String inName, String inValue, boolean checked)
451   {
452      InputCheckbox checkbox = new InputCheckbox(inName, inValue, checked);
453      addSubtag(checkbox);
454
455      return checkbox;
456   }
457
458   //--------------------------------------------------------------------------
459   public InputRadio addRadio(String inName, String inValue)
460   {
461      InputRadio radio = new InputRadio(inName, inValue);
462      addSubtag(radio);
463
464      return radio;
465   }
466
467   //--------------------------------------------------------------------------
468   public InputRadio addRadio(String inName, String inValue, boolean checked)
469   {
470      InputRadio radio = new InputRadio(inName, inValue, checked);
471      addSubtag(radio);
472
473      return radio;
474   }
475
476
477   //--------------------------------------------------------------------------
478   public Select addSelect(String inName)
479   {
480      Select select = new Select(inName);
481      addSubtag(select);
482
483      return select;
484   }
485
486
487   //--------------------------------------------------------------------------
488   public InputReset addReset()
489   {
490      InputReset reset = new InputReset();
491      addSubtag(reset);
492
493      return reset;
494   }
495
496
497   //--------------------------------------------------------------------------
498   public InputFile addFileInput()
499   {
500      InputFile subtag = new InputFile();
501      addSubtag(subtag);
502
503      return subtag;
504   }
505
506   //--------------------------------------------------------------------------
507   public InputFile addFileInput(String inName)
508   {
509      InputFile subtag = new InputFile(inName);
510      addSubtag(subtag);
511
512      return subtag;
513   }
514
515   //--------------------------------------------------------------------------
516   public InputFile addFileInput(String inName, String inValue)
517   {
518      InputFile subtag = new InputFile(inName, inValue);
519      addSubtag(subtag);
520
521      return subtag;
522   }
523
524
525   //--------------------------------------------------------------------------
526   public Td setAlign(Align inValue)
527   {
528      setAttribute(inValue.getHTMLAttributeName(), inValue.toString());
529
530      return this;
531   }
532
533   //--------------------------------------------------------------------------
534   public Td setVAlign(VAlign inValue)
535   {
536      setAttribute(inValue.getHTMLAttributeName(), inValue.toString());
537
538      return this;
539   }
540
541   //--------------------------------------------------------------------------
542   public Td setColSpan(int inValue)
543   {
544      setAttribute(HTML.COLSPAN, Integer.toString(inValue));
545
546      return this;
547   }
548
549   //--------------------------------------------------------------------------
550   public String getColSpan()
551   {
552      return getAttributeValue(HTML.COLSPAN);
553   }
554
555   //--------------------------------------------------------------------------
556   public Td setRowSpan(int inValue)
557   {
558      setAttribute(HTML.ROWSPAN, Integer.toString(inValue));
559
560      return this;
561   }
562
563   //--------------------------------------------------------------------------
564   public String getRowSpan()
565   {
566      return getAttributeValue(HTML.ROWSPAN);
567   }
568
569   //---------------------------------------------------------------------------
570   /**
571    Sets the background color for the table cell.
572    */
573   public Td setBackgroundColor(HTMLColor inValue)
574   {
575      setAttribute(HTML.BGCOLOR, inValue);
576      return this;
577   }
578
579   //--------------------------------------------------------------------------
580   /**
581    Sets the background color for the table cell.
582    */
583   public Td setBackgroundColor(Color inValue)
584   {
585      setAttribute(HTML.BGCOLOR, "#" + ColorUtil.colorToHex(inValue));
586
587      return this;
588   }
589
590   //--------------------------------------------------------------------------
591   /**
592    Sets the background color for the table cell.
593    */
594   public Td setBackgroundColor(String inValue)
595   {
596      setAttribute(HTML.BGCOLOR, inValue);
597
598      return this;
599   }
600
601   //--------------------------------------------------------------------------
602   public String getBackgroundColor()
603   {
604      return getAttributeValue(HTML.BGCOLOR);
605   }
606
607
608   //--------------------------------------------------------------------------
609   public Td setWidth(String inValue)
610   {
611      setAttribute(HTML.WIDTH, inValue);
612
613      return this;
614   }
615
616   //--------------------------------------------------------------------------
617   public Td setWidth(int inValue)
618   {
619      setAttribute(HTML.WIDTH, Integer.toString(inValue));
620
621      return this;
622   }
623
624
625   //--------------------------------------------------------------------------
626   public Td setTitle(String inValue)
627   {
628      setAttribute(HTML.TITLE, inValue);
629      return this;
630   }
631
632   //--------------------------------------------------------------------------
633   public String getTitle()
634   {
635      return getAttributeValue(HTML.TITLE);
636   }
637
638   //--------------------------------------------------------------------------
639   public Td br()
640   {
641      HTMLUtil.br(this);
642      return this;
643   }
644
645   //--------------------------------------------------------------------------
646   public Td br(int inNumber)
647   {
648      HTMLUtil.br(this, inNumber);
649      return this;
650   }
651
652   //--------------------------------------------------------------------------
653   public Td nbsp(int inNumber)
654   {
655      HTMLUtil.nbsp(this, inNumber);
656      return this;
657   }
658
659   //--------------------------------------------------------------------------
660   public void hr()
661   {
662      HTMLUtil.hr(this);
663   }
664
665   //--------------------------------------------------------------------------
666   public void hr(String inWidth)
667   {
668      HTMLUtil.hr(this, inWidth);
669   }
670
671
672   // Overrides for HTMLTag setters to allow method chaining.
673
674   //--------------------------------------------------------------------------
675   @Override
676   public Td addClass(String inValue)
677   {
678      return (Td) super.addClass(inValue);
679   }
680
681   //--------------------------------------------------------------------------
682   @Override
683   public Td setClass(String inValue)
684   {
685      return (Td) super.setClass(inValue);
686   }
687
688   //--------------------------------------------------------------------------
689   @Override
690   public Td setId(String inValue)
691   {
692      return (Td) super.setId(inValue);
693   }
694
695   //--------------------------------------------------------------------------
696   @Override
697   public Td setStyle(CharSequence inValue)
698   {
699      return (Td) super.setStyle(inValue);
700   }
701
702   //--------------------------------------------------------------------------
703   @Override
704   public Td addStyle(String inValue)
705   {
706      return (Td) super.addStyle(inValue);
707   }
708
709   // Overrides for HTMLTagWithCoreEvents setters to allow method chaining.
710
711   //--------------------------------------------------------------------------
712   @Override
713   public Td setOnClick(String inValue)
714   {
715      return (Td) super.setOnClick(inValue);
716   }
717
718   //--------------------------------------------------------------------------
719   @Override
720   public Td setOnDblClick(String inValue)
721   {
722      return (Td) super.setOnDblClick(inValue);
723   }
724
725   //--------------------------------------------------------------------------
726   @Override
727   public Td setOnMouseDown(String inValue)
728   {
729      return (Td) super.setOnMouseDown(inValue);
730   }
731
732   //--------------------------------------------------------------------------
733   @Override
734   public Td setOnMouseMove(String inValue)
735   {
736      return (Td) super.setOnMouseMove(inValue);
737   }
738
739   //--------------------------------------------------------------------------
740   @Override
741   public Td appendToOnMouseOut(String inValue)
742   {
743      return (Td) super.appendToOnMouseOut(inValue);
744   }
745
746   //--------------------------------------------------------------------------
747   @Override
748   public Td setOnMouseOut(String inValue)
749   {
750      return (Td) super.setOnMouseOut(inValue);
751   }
752
753   //--------------------------------------------------------------------------
754   @Override
755   public Td appendToOnMouseOver(String inValue)
756   {
757      return (Td) super.appendToOnMouseOver(inValue);
758   }
759
760   //--------------------------------------------------------------------------
761   @Override
762   public Td setOnMouseOver(String inValue)
763   {
764      return (Td) super.setOnMouseOver(inValue);
765   }
766
767   //--------------------------------------------------------------------------
768   @Override
769   public Td setOnMouseUp(String inValue)
770   {
771      return (Td) super.setOnMouseUp(inValue);
772   }
773
774   //--------------------------------------------------------------------------
775   @Override
776   public Td setOnKeyDown(String inValue)
777   {
778      return (Td) super.setOnKeyDown(inValue);
779   }
780
781   //--------------------------------------------------------------------------
782   @Override
783   public Td setOnKeyPress(String inValue)
784   {
785      return (Td) super.setOnKeyPress(inValue);
786   }
787
788   //--------------------------------------------------------------------------
789   @Override
790   public Td setOnKeyUp(String inValue)
791   {
792      return (Td) super.setOnKeyUp(inValue);
793   }
794}