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

import java.io.*;
import java.util.*;
import org.w3c.dom.*;
import com.silverwrist.util.xml.*;
import com.silverwrist.dynamo.except.*;
import com.silverwrist.dynamo.iface.*;

class StdButton implements DialogButton
{
  /*--------------------------------------------------------------------------------
   * Attributes
   *--------------------------------------------------------------------------------
   */

  private DialogPLAF m_plaf;
  private String m_name;
  private Object m_rendering;

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

  StdButton(Element elt, DialogPLAF plaf) throws DialogException
  {
    m_plaf = plaf;
    XMLLoader loader = XMLLoader.get();
    try
    { // get the name
      m_name = loader.getAttribute(elt,"name");
      m_rendering = plaf.getButtonRendering(m_name);

    } // end try
    catch (XMLLoadException e)
    { // failed to load dialog - throw exception
      throw new DialogException(e);

    } // end catch

  } // end constructor

  protected StdButton(StdButton other)
  {
    m_plaf = other.m_plaf;
    m_name = other.m_name;
    m_rendering = other.m_rendering;

  } // end constructor

  /*--------------------------------------------------------------------------------
   * Implementations from interface NamedObject
   *--------------------------------------------------------------------------------
   */

  public String getName()
  {
    return m_name;

  } // end getName

  /*--------------------------------------------------------------------------------
   * Implementations from interface DialogItem
   *--------------------------------------------------------------------------------
   */

  public Object clone()
  {
    return new StdButton(this);

  } // end clone

  public void render(TextRenderControl control, Map render_params) throws IOException, RenderingException
  {
    control.renderSubObject(m_rendering);

  } // end render

  public boolean isEnabled()
  {
    return true;

  } // end isEnabled

  public void setEnabled(boolean flag)
  { // do nothing
  } // end setEnabled

  /*--------------------------------------------------------------------------------
   * Implementations from interface DialogButton
   *--------------------------------------------------------------------------------
   */

  public boolean isClicked(Request r)
  {
    return m_plaf.isButtonClicked(r,m_name);

  } // end isClicked

} // end class StdButton
