001package com.hfg.html;
002
003import java.awt.Color;
004
005import com.hfg.html.attribute.Align;
006import com.hfg.html.attribute.HTMLColor;
007import com.hfg.html.attribute.VAlign;
008import com.hfg.graphics.ColorUtil;
009import com.hfg.xml.XMLNode;
010
011//------------------------------------------------------------------------------
012/**
013 * Represents a table row (<tr>) tag.
014 * @author J. Alex Taylor, hairyfatguy.com
015 */
016//------------------------------------------------------------------------------
017// com.hfg XML/HTML Coding Library
018//
019// This library is free software; you can redistribute it and/or
020// modify it under the terms of the GNU Lesser General Public
021// License as published by the Free Software Foundation; either
022// version 2.1 of the License, or (at your option) any later version.
023//
024// This library is distributed in the hope that it will be useful,
025// but WITHOUT ANY WARRANTY; without even the implied warranty of
026// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
027// Lesser General Public License for more details.
028//
029// You should have received a copy of the GNU Lesser General Public
030// License along with this library; if not, write to the Free Software
031// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
032//
033// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
034// jataylor@hairyfatguy.com
035//------------------------------------------------------------------------------
036
037public class Tr extends HTMLTagWithCoreEvents
038{
039
040   //##########################################################################
041   // PRIVATE FIELDS
042   //##########################################################################
043
044
045   //##########################################################################
046   // CONSTRUCTORS
047   //##########################################################################
048
049   //--------------------------------------------------------------------------
050   public Tr()
051   {
052      super(HTML.TR);
053   }
054
055   //--------------------------------------------------------------------------
056   public Tr(Align inAlign)
057   {
058      this();
059      setAlign(inAlign);
060   }
061
062   //--------------------------------------------------------------------------
063   public Tr(XMLNode inXMLNode)
064   {
065      this();
066      initFromXMLNode(inXMLNode);
067   }
068
069   //##########################################################################
070   // PUBLIC METHODS
071   //##########################################################################
072
073
074   //--------------------------------------------------------------------------
075   public void addCell(Td inCell)
076   {
077      // Using addSubtag() instead of addContent() because there should not
078      // be any content in 'tr' other than 'td' or 'th' tags.
079      addSubtag(inCell);
080   }
081
082
083   //--------------------------------------------------------------------------
084   public Td addCell()
085   {
086      Td td = new Td();
087      // Using addSubtag() instead of addContent() because there should not
088      // be any content in 'tr' other than 'td' or 'th' tags.
089      addSubtag(td);
090
091      return td;
092   }
093
094   //--------------------------------------------------------------------------
095   public Td addCell(String inContent)
096   {
097      Td td = new Td(inContent);
098      // Using addSubtag() instead of addContent() because there should not
099      // be any content in 'tr' other than 'td' or 'th' tags.
100      addSubtag(td);
101
102      return td;
103   }
104
105   //--------------------------------------------------------------------------
106   public Td addCell(String inContent, Align inAlign)
107   {
108      Td td = new Td(inContent, inAlign);
109      // Using addSubtag() instead of addContent() because there should not
110      // be any content in 'tr' other than 'td' or 'th' tags.
111      addSubtag(td);
112
113      return td;
114   }
115
116   //--------------------------------------------------------------------------
117   public Td addCell(HTMLNode inContent)
118   {
119      Td td = new Td(inContent);
120      // Using addSubtag() instead of addContent() because there should not
121      // be any content in 'tr' other than 'td' or 'th' tags.
122      addSubtag(td);
123
124      return td;
125   }
126
127   //--------------------------------------------------------------------------
128   public Td addCell(HTMLNode inContent, Align inAlign)
129   {
130      Td td = new Td(inContent, inAlign);
131      // Using addSubtag() instead of addContent() because there should not
132      // be any content in 'tr' other than 'td' or 'th' tags.
133      addSubtag(td);
134
135      return td;
136   }
137
138   //--------------------------------------------------------------------------
139   public void addHeaderCell(Th inCell)
140   {
141      // Using addSubtag() instead of addContent() because there should not
142      // be any content in 'tr' other than 'td' or 'th' tags.
143      addSubtag(inCell);
144   }
145
146   //--------------------------------------------------------------------------
147   public Th addHeaderCell()
148   {
149      Th th = new Th();
150      // Using addSubtag() instead of addContent() because there should not
151      // be any content in 'tr' other than 'td' or 'th' tags.
152      addSubtag(th);
153
154      return th;
155   }
156
157   //--------------------------------------------------------------------------
158   public Th addHeaderCell(String inContent)
159   {
160      Th th = new Th(inContent);
161      // Using addSubtag() instead of addContent() because there should not
162      // be any content in 'tr' other than 'td' or 'th' tags.
163      addSubtag(th);
164
165      return th;
166   }
167
168   //--------------------------------------------------------------------------
169   public Th addHeaderCell(String inContent, Align inAlign)
170   {
171      Th th = new Th(inContent, inAlign);
172      // Using addSubtag() instead of addContent() because there should not
173      // be any content in 'tr' other than 'td' or 'th' tags.
174      addSubtag(th);
175
176      return th;
177   }
178
179   //--------------------------------------------------------------------------
180   public Th addHeaderCell(HTMLTag inContent)
181   {
182      Th th = new Th(inContent);
183      // Using addSubtag() instead of addContent() because there should not
184      // be any content in 'tr' other than 'td' or 'th' tags.
185      addSubtag(th);
186
187      return th;
188   }
189
190   //--------------------------------------------------------------------------
191   public Th addHeaderCell(HTMLTag inContent, Align inAlign)
192   {
193      Th th = new Th(inContent, inAlign);
194      // Using addSubtag() instead of addContent() because there should not
195      // be any content in 'tr' other than 'td' or 'th' tags.
196      addSubtag(th);
197
198      return th;
199   }
200
201   //--------------------------------------------------------------------------
202   public Tr setAlign(Align inValue)
203   {
204      setAttribute(inValue.getHTMLAttributeName(), inValue.toString());
205
206      return this;
207   }
208
209   //--------------------------------------------------------------------------
210   public Tr setVAlign(VAlign inValue)
211   {
212      setAttribute(inValue.getHTMLAttributeName(), inValue.toString());
213
214      return this;
215   }
216
217
218   //---------------------------------------------------------------------------
219   /**
220    Sets the background color for the table row.
221    */
222   public Tr setBackgroundColor(HTMLColor inValue)
223   {
224      setAttribute(HTML.BGCOLOR, inValue);
225      return this;
226   }
227
228   //--------------------------------------------------------------------------
229   /**
230    Sets the background color for the table row.
231    */
232   public Tr setBackgroundColor(Color inValue)
233   {
234      setAttribute(HTML.BGCOLOR, "#" + ColorUtil.colorToHex(inValue));
235
236      return this;
237   }
238
239   //--------------------------------------------------------------------------
240   /**
241    Sets the background color for the table row.
242    */
243   public Tr setBackgroundColor(String inValue)
244   {
245      setAttribute(HTML.BGCOLOR, inValue);
246
247      return this;
248   }
249
250   //--------------------------------------------------------------------------
251   public String getBackgroundColor()
252   {
253      return getAttributeValue(HTML.BGCOLOR);
254   }
255
256
257   // Overrides for HTMLTag setters to allow method chaining.
258
259   //--------------------------------------------------------------------------
260   @Override
261   public Tr addClass(String inValue)
262   {
263      return (Tr) super.addClass(inValue);
264   }
265
266   //--------------------------------------------------------------------------
267   @Override
268   public Tr setClass(String inValue)
269   {
270      return (Tr) super.setClass(inValue);
271   }
272
273   //--------------------------------------------------------------------------
274   @Override
275   public Tr setId(String inValue)
276   {
277      return (Tr) super.setId(inValue);
278   }
279
280   //--------------------------------------------------------------------------
281   @Override
282   public Tr setStyle(CharSequence inValue)
283   {
284      return (Tr) super.setStyle(inValue);
285   }
286
287   //--------------------------------------------------------------------------
288   @Override
289   public Tr addStyle(String inValue)
290   {
291      return (Tr) super.addStyle(inValue);
292   }
293
294   // Overrides for HTMLTagWithCoreEvents setters to allow method chaining.
295
296   //--------------------------------------------------------------------------
297   @Override
298   public Tr setOnClick(String inValue)
299   {
300      return (Tr) super.setOnClick(inValue);
301   }
302
303   //--------------------------------------------------------------------------
304   @Override
305   public Tr setOnDblClick(String inValue)
306   {
307      return (Tr) super.setOnDblClick(inValue);
308   }
309
310   //--------------------------------------------------------------------------
311   @Override
312   public Tr setOnMouseDown(String inValue)
313   {
314      return (Tr) super.setOnMouseDown(inValue);
315   }
316
317   //--------------------------------------------------------------------------
318   @Override
319   public Tr setOnMouseMove(String inValue)
320   {
321      return (Tr) super.setOnMouseMove(inValue);
322   }
323
324   //--------------------------------------------------------------------------
325   @Override
326   public Tr appendToOnMouseOut(String inValue)
327   {
328      return (Tr) super.appendToOnMouseOut(inValue);
329   }
330
331   //--------------------------------------------------------------------------
332   @Override
333   public Tr setOnMouseOut(String inValue)
334   {
335      return (Tr) super.setOnMouseOut(inValue);
336   }
337
338   //--------------------------------------------------------------------------
339   @Override
340   public Tr appendToOnMouseOver(String inValue)
341   {
342      return (Tr) super.appendToOnMouseOver(inValue);
343   }
344
345   //--------------------------------------------------------------------------
346   @Override
347   public Tr setOnMouseOver(String inValue)
348   {
349      return (Tr) super.setOnMouseOver(inValue);
350   }
351
352   //--------------------------------------------------------------------------
353   @Override
354   public Tr setOnMouseUp(String inValue)
355   {
356      return (Tr) super.setOnMouseUp(inValue);
357   }
358
359   //--------------------------------------------------------------------------
360   @Override
361   public Tr setOnKeyDown(String inValue)
362   {
363      return (Tr) super.setOnKeyDown(inValue);
364   }
365
366   //--------------------------------------------------------------------------
367   @Override
368   public Tr setOnKeyPress(String inValue)
369   {
370      return (Tr) super.setOnKeyPress(inValue);
371   }
372
373   //--------------------------------------------------------------------------
374   @Override
375   public Tr setOnKeyUp(String inValue)
376   {
377      return (Tr) super.setOnKeyUp(inValue);
378   }
379
380}