/*
 * 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-02 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.venice.ui.dlg;

import java.io.IOException;
import org.w3c.dom.*;
import com.silverwrist.util.*;
import com.silverwrist.venice.except.*;
import com.silverwrist.venice.ui.*;
import com.silverwrist.venice.ui.helpers.HTMLRendering;
import com.silverwrist.venice.util.XMLLoader;

public class CategoryHeader implements DialogField, ColorSelectors
{
  /*--------------------------------------------------------------------------------
   * Static data members
   *--------------------------------------------------------------------------------
   */

  public static final String TAGNAME = "header";

  /*--------------------------------------------------------------------------------
   * Attributes
   *--------------------------------------------------------------------------------
   */

  private String caption;              // caption to display
  private String rtext;                // text to display on right
  private boolean enabled;             // enabled or not?

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

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

  } // end constructor

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

  } // end constructor

  public CategoryHeader(Element elt) throws ConfigException
  {
    XMLLoader loader = XMLLoader.get();
    this.caption = loader.configGetAttribute(elt,"capt");
    DOMElementHelper h = new DOMElementHelper(elt);
    this.rtext = h.getElementText();
    this.enabled = !(h.hasAttribute("disabled"));

  } // end constructor

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

  } // end constructor

  /*--------------------------------------------------------------------------------
   * Implementations from interface RenderDirect
   *--------------------------------------------------------------------------------
   */

  public void render(RequestOutput out) throws IOException
  {
    HTMLRendering html = (HTMLRendering)(out.queryService(HTMLRendering.class));
    String open_font = html.getFontTag(enabled ? html.CONTENT_FOREGROUND : html.CONTENT_DISABLED,"content");
    out.write("<TR VALIGN=MIDDLE><TD ALIGN=RIGHT CLASS=\"content\">" + open_font + "<B>"
	      + StringUtil.encodeHTML(caption) + ":</B></FONT></TD><TD ALIGN=LEFT CLASS=\"content\">");
    if (rtext==null)
      out.write("&nbsp;");
    else
      out.write(open_font + StringUtil.encodeHTML(rtext) + "</FONT>");
    out.write("</TD></TR>\n");

  } // end render

  /*--------------------------------------------------------------------------------
   * Implementations from interface DialogField
   *--------------------------------------------------------------------------------
   */

  public String getName()
  {
    return null;

  } // end getName

  public Object getValue()
  {
    return null;

  } // end getValue

  public void setValue(Object o)
  { // do nothing
  } // end setValue

  public void setValueFrom(RequestInput ri)
  { // do nothing
  } // end setValueFrom

  public boolean isRequired()
  {
    return false;

  } // end isRequired

  public boolean isFile()
  {
    return false;

  } // end isFile

  public boolean isHidden()
  {
    return false;

  } // end isHidden

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

  public boolean isEnabled()
  {
    return enabled;

  } // end isEnabled

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

  } // end setEnabled

  public Object sendMessage(String msg, Object data)
  {
    return null;

  } // end sendMessage

  public DialogField duplicate()
  {
    return new CategoryHeader(this);

  } // end duplicate

} // end class CategoryHeader
