/*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (the "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
 * 
 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
 * language governing rights and limitations under the License.
 * 
 * The Original Code is the Venice Web Communities System.
 * 
 * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
 * for Silverwrist Design Studios.  Portions created by Eric J. Bowersox are
 * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.venice.servlets.format;

import java.io.Writer;
import java.io.IOException;
import javax.servlet.ServletRequest;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.except.ValidationException;

public class CDFormCategoryHeader implements CDFormField, ColorSelectors
{
  /*--------------------------------------------------------------------------------
   * Attributes
   *--------------------------------------------------------------------------------
   */

  private String caption;
  private String rtext;
  private boolean enabled;

  /*--------------------------------------------------------------------------------
   * Constructors
   *--------------------------------------------------------------------------------
   */

  public CDFormCategoryHeader(String caption)
  {
    this.caption = caption;
    this.rtext = null;
    this.enabled = true;

  } // end constructor

  public CDFormCategoryHeader(String caption, String rtext)
  {
    this.caption = caption;
    this.rtext = rtext;
    this.enabled = true;

  } // end constructor

  protected CDFormCategoryHeader(CDFormCategoryHeader other)
  {
    this.caption = other.caption;
    this.rtext = other.rtext;
    this.enabled = true;

  } // end constructor

  /*--------------------------------------------------------------------------------
   * Implementations from interface ComponentRender
   *--------------------------------------------------------------------------------
   */

  public void renderHere(Writer out, RenderData rdat) throws IOException
  {
    out.write("<TR VALIGN=MIDDLE><TD ALIGN=RIGHT CLASS=\"content\"><FONT COLOR=\""
	      + rdat.getStdColor(enabled ? CONTENT_FOREGROUND : CONTENT_DISABLED) + "\"><B>"
	      + StringUtil.encodeHTML(caption) + ":</B></FONT></TD><TD ALIGN=LEFT CLASS=\"content\">");
    if (rtext==null)
      out.write("&nbsp;");
    else // display in the correct state
      out.write("<FONT COLOR=\"" + rdat.getStdColor(enabled ? CONTENT_FOREGROUND : CONTENT_DISABLED) + "\">"
		+ StringUtil.encodeHTML(rtext) + "</FONT>");
    out.write("</TD></TR>\n");

  } // end renderHere

  /*--------------------------------------------------------------------------------
   * Implementations from interface CDFormField
   *--------------------------------------------------------------------------------
   */

  public String getName()
  {
    return null;

  } // end getName

  public String getValue()
  {
    return null;

  } // end getValue

  public void setValue(String value)
  { // do nothing
  } // end setValue

  public Object getObjValue()
  {
    return null;

  } // end getObjValue

  public void setObjValue(Object obj)
  { // do nothing
  } // end setObjValue

  public boolean isRequired()
  {
    return false;

  } // end isRequired

  public void validate()
  { // do nothing
  } // end validate

  public CDCommandButton findButton(String name)
  {
    return null;

  } // end findButton

  public boolean isEnabled()
  {
    return enabled;

  } // end isEnabled

  public void setEnabled(boolean flag)
  {
    enabled = flag;

  } // end setEnabled

  public CDFormField duplicate()
  {
    return new CDFormCategoryHeader(this);

  } // end clone

} // end class CDFormCategoryHeader

