All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hfg.html.Table Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.html;

import java.awt.Color;
import java.util.List;

import com.hfg.html.attribute.HTMLColor;
import com.hfg.graphics.ColorUtil;
import com.hfg.util.Recursion;
import com.hfg.util.collection.CollectionUtil;
import com.hfg.xml.XMLNode;

//------------------------------------------------------------------------------
/**
 * Represents a table (<table>) tag.
 *
 * @author J. Alex Taylor, hairyfatguy.com
 */
//------------------------------------------------------------------------------
// com.hfg XML/HTML Coding Library
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
// [email protected]
//------------------------------------------------------------------------------

public class Table extends HTMLTagWithCoreEvents
{

   //##########################################################################
   // PRIVATE FIELDS
   //##########################################################################


   //##########################################################################
   // CONSTRUCTORS
   //##########################################################################

   //--------------------------------------------------------------------------
   public Table()
   {
      super(HTML.TABLE);
   }

   //--------------------------------------------------------------------------
   public Table(XMLNode inXMLNode)
   {
      this();
      initFromXMLNode(inXMLNode);
   }

   //##########################################################################
   // PUBLIC METHODS
   //##########################################################################


   //--------------------------------------------------------------------------
   public THead addTHead()
   {
      THead thead = new THead();
      addSubtag(thead);
      return thead;
   }

   //--------------------------------------------------------------------------
   public TBody addTBody()
   {
      TBody tbody = new TBody();
      addSubtag(tbody);
      return tbody;
   }

   //--------------------------------------------------------------------------
   public TFoot addTFoot()
   {
      TFoot tfoot = new TFoot();
      addSubtag(tfoot);
      return tfoot;
   }


   //--------------------------------------------------------------------------
   public Tr addRow()
   {
      Tr tr = new Tr();
      addSubtag(tr);
      return tr;
   }

   //--------------------------------------------------------------------------
   public void addRow(Tr inRow)
   {
      addSubtag(inRow);
   }

   //--------------------------------------------------------------------------
   public List getRows()
   {
      List rows = getSubtagsByClass(Tr.class, Recursion.OFF);
      if (!CollectionUtil.hasValues(rows))
      {
         // The rows might be within a TBody
         HTMLTag tbody = getOptionalSubtagByName(HTML.TBODY);
         if (tbody != null)
         {
            rows = tbody.getSubtagsByClass(Tr.class, Recursion.OFF);
         }
      }
      
      return rows;
   }


   //--------------------------------------------------------------------------
   public Colgroup addColgroup()
   {
      Colgroup colgroup = new Colgroup();
      addSubtag(colgroup);

      return colgroup;
   }


   //--------------------------------------------------------------------------
   public Col addCol()
   {
      Col col = new Col();
      addSubtag(col);

      return col;
   }

   //--------------------------------------------------------------------------
   public List getCols()
   {
      return getSubtagsByClass(Col.class);
   }

   //--------------------------------------------------------------------------
   public Table setCellPadding(int inValue)
   {
      setAttribute(HTML.CELLPADDING, inValue);

      return this;
   }

   //--------------------------------------------------------------------------
   public Table setCellSpacing(int inValue)
   {
      setAttribute(HTML.CELLSPACING, inValue);

      return this;
   }

   //--------------------------------------------------------------------------
   public Table setBorder(int inValue)
   {
      setAttribute(HTML.BORDER, inValue);

      return this;
   }

   //---------------------------------------------------------------------------
   /**
    Sets the background color for the table.
    */
   public Table setBackgroundColor(HTMLColor inValue)
   {
      setAttribute(HTML.BGCOLOR, inValue);
      return this;
   }

   //--------------------------------------------------------------------------
   /**
    Sets the background color for the table.
    */
   public Table setBackgroundColor(Color inValue)
   {
      setAttribute(HTML.BGCOLOR, "#" + ColorUtil.colorToHex(inValue));
      return this;
   }

   //--------------------------------------------------------------------------
   /**
    Sets the background color for the table.
    */
   public Table setBackgroundColor(String inValue)
   {
      setAttribute(HTML.BGCOLOR, inValue);
      return this;
   }

   //--------------------------------------------------------------------------
   public Table setBackground(String inValue)
   {
      setAttribute(HTML.BACKGROUND, inValue);
      return this;
   }

   //--------------------------------------------------------------------------
   public Table setWidth(String inValue)
   {
      setAttribute(HTML.WIDTH, inValue);
      return this;
   }

   //--------------------------------------------------------------------------
   public Table setWidth(int inValue)
   {
      setAttribute(HTML.WIDTH, inValue);
      return this;
   }

 
   // Overrides for HTMLTag setters to allow method chaining.

   //--------------------------------------------------------------------------
   @Override
   public Table addClass(String inValue)
   {
      return (Table) super.addClass(inValue);
   }

   //--------------------------------------------------------------------------
   @Override
   public Table setClass(String inValue)
   {
      return (Table) super.setClass(inValue);
   }

   //--------------------------------------------------------------------------
   @Override
   public Table setId(String inValue)
   {
      return (Table) super.setId(inValue);
   }

   //--------------------------------------------------------------------------
   @Override
   public Table setStyle(CharSequence inValue)
   {
      return (Table) super.setStyle(inValue);
   }

   //--------------------------------------------------------------------------
   @Override
   public Table addStyle(String inValue)
   {
      return (Table) super.addStyle(inValue);
   }

   // Overrides for HTMLTagWithCoreEvents setters to allow method chaining.

   //--------------------------------------------------------------------------
   @Override
   public Table setOnClick(String inValue)
   {
      return (Table) super.setOnClick(inValue);
   }

   //--------------------------------------------------------------------------
   @Override
   public Table setOnDblClick(String inValue)
   {
      return (Table) super.setOnDblClick(inValue);
   }

   //--------------------------------------------------------------------------
   @Override
   public Table setOnMouseDown(String inValue)
   {
      return (Table) super.setOnMouseDown(inValue);
   }

   //--------------------------------------------------------------------------
   @Override
   public Table setOnMouseMove(String inValue)
   {
      return (Table) super.setOnMouseMove(inValue);
   }

   //--------------------------------------------------------------------------
   @Override
   public Table appendToOnMouseOut(String inValue)
   {
      return (Table) super.appendToOnMouseOut(inValue);
   }

   //--------------------------------------------------------------------------
   @Override
   public Table setOnMouseOut(String inValue)
   {
      return (Table) super.setOnMouseOut(inValue);
   }

   //--------------------------------------------------------------------------
   @Override
   public Table appendToOnMouseOver(String inValue)
   {
      return (Table) super.appendToOnMouseOver(inValue);
   }

   //--------------------------------------------------------------------------
   @Override
   public Table setOnMouseOver(String inValue)
   {
      return (Table) super.setOnMouseOver(inValue);
   }

   //--------------------------------------------------------------------------
   @Override
   public Table setOnMouseUp(String inValue)
   {
      return (Table) super.setOnMouseUp(inValue);
   }

   //--------------------------------------------------------------------------
   @Override
   public Table setOnKeyDown(String inValue)
   {
      return (Table) super.setOnKeyDown(inValue);
   }

   //--------------------------------------------------------------------------
   @Override
   public Table setOnKeyPress(String inValue)
   {
      return (Table) super.setOnKeyPress(inValue);
   }

   //--------------------------------------------------------------------------
   @Override
   public Table setOnKeyUp(String inValue)
   {
      return (Table) super.setOnKeyUp(inValue);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy