/*
 * 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 Community 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;

public class CDImageButton implements CDCommandButton
{
  private String name;         // name of the button field
  private String image;        // image file to output
  private String alt_text;     // alt text to output
  private int width;           // width of button image
  private int height;          // height of button image

  public CDImageButton(String name, String image, String alt_text, int width, int height)
  {
    this.name = name;
    this.image = image;
    this.alt_text = alt_text;
    this.width = width;
    this.height = height;

  } // end constructor

  public void renderHere(Writer out, RenderData rdat) throws IOException
  {
    out.write("<INPUT TYPE=IMAGE NAME=\"" + name + "\" SRC=\"" + rdat.getFullImagePath(image) + "\"");
    if (alt_text!=null)
      out.write(" ALT=\"" + alt_text + "\"");
    out.write(" WIDTH=" + String.valueOf(width) + " HEIGHT=" + String.valueOf(height) + " BORDER=0>");

  } // end renderHere

  public String getName()
  {
    return name;

  } // end getName

  public boolean isClicked(ServletRequest request)
  {
    String val = request.getParameter(name + ".x");
    return (val!=null);

  } // end isClicked

} // end class CDImageButton
