/*
* Copyright (c) Blue Fish Development Group 1996-2004. All rights reserved.
*
* This version:
* $Author: jduke $
* $Date: 2005/01/05 06:26:56 $
* $Id: ColorInput.java,v 1.2 2005/01/05 06:26:56 jduke Exp $
*/
package com.bluefishgroup.bedrock.wdk.control;
import com.documentum.web.form.Control;
/**
* The ColorInput control is used to gather and encapsulate the three color component values for
* red, green, and blue.
*
* @author Jason Duke
* @version $Revision: 1.2 $
*/
public class ColorInput extends Control {
/** Whether or not enter while on textbox should submit the form. */
private boolean _defaultOnEnter;
/** Size for the HTML text element containing the amount. */
private String _size;
/** The red component value. */
private Float _red;
/** The green component value. */
private Float _green;
/** The blue component value. */
private Float _blue;
/**
* Property name for red component, used to guarantee unique form element name for each color
* component.
*/
public static final String PROPERTY_RED = "red";
/** Property name for green component. */
public static final String PROPERTY_GREEN = "green";
/** Property name for blue component. */
public static final String PROPERTY_BLUE = "blue";
/**
* Constructs a new ColorInput object.
*/
public ColorInput() {
super();
_defaultOnEnter = false;
_size = null;
_red = null;
_green = null;
_blue = null;
}
/**
* Returns the blue.
*
* @return the blue
*/
public Float getBlue() {
return _blue;
}
/**
* Sets the blue.
*
* @param blue the blue
*/
public void setBlue(Float blue) {
_blue = blue;
}
/**
* Returns the green.
*
* @return the green
*/
public Float getGreen() {
return _green;
}
/**
* Sets the green.
*
* @param green the green
*/
public void setGreen(Float green) {
_green = green;
}
/**
*
* Returns the red.
*
* @return the red
*/
public Float getRed() {
return _red;
}
/**
* Sets the red.
*
* @param red the red
*/
public void setRed(Float red) {
_red = red;
}
/**
* Gets the size property
*
* @return the size property
*/
public String getSize() {
return _size;
}
/**
* Gets the default on enter property
*
* @return the default on enter property
*/
public boolean isDefaultOnEnter() {
return _defaultOnEnter;
}
/**
* Sets the default on enter property
*
* @param defaultOnEnter the default on enter property
*/
public void setDefaultOnEnter(boolean defaultOnEnter) {
_defaultOnEnter = defaultOnEnter;
}
/**
* Sets the size property
*
* @param strSize the size property
*/
public void setSize(String size) {
_size = size;
}
/**
* Sets the default on enter property, parsing the given String into a
* boolean using Boolean.valueOf().
*
* @param defaultOnEnterStr the String representation of the default on enter property
*/
public void setDefaultOnEnter(String defaultOnEnterStr) {
_defaultOnEnter = Boolean.valueOf(defaultOnEnterStr).booleanValue();
}
/**
* Sets the red value. If the given String does not parse to a Float, the value is set to
* null.
*
* @param redStr the String representation of the red value
*/
public void setRed(String redStr) {
try {
_red = Float.valueOf(redStr);
} catch (NumberFormatException e) {
// Handle exception by clearing out value.
_red = null;
}
}
/**
* Sets the green value. If the given String does not parse to a Float, the value is set to
* null.
*
* @param greenStr the String representation of the green value
*/
public void setGreen(String greenStr) {
try {
_green = Float.valueOf(greenStr);
} catch (NumberFormatException e) {
// Handle exception by clearing out value.
_green = null;
}
}
/**
* Sets the blue value. If the given String does not parse to a Float, the value is set to
* null.
*
* @param blueStr the String representation of the blue value
*/
public void setBlue(String blueStr) {
try {
_blue = Float.valueOf(blueStr);
} catch (NumberFormatException e) {
// Handle exception by clearing out value.
_blue = null;
}
}
/**
* Get whether the control can accept focus.
*
* @return true => the control can accept focus
*/
public boolean canAcceptFocus() {
return isEnabled() && isVisible();
}
/*
* (non-Javadoc)
*
* @see com.documentum.web.form.Control#updateStateFromRequest()
*/
protected void updateStateFromRequest() {
super.updateStateFromRequest();
String redStr = getRequestParameter(getElementName(PROPERTY_RED));
String greenStr = getRequestParameter(getElementName(PROPERTY_GREEN));
String blueStr = getRequestParameter(getElementName(PROPERTY_BLUE));
if (redStr != null) {
setRed(redStr);
}
if (greenStr != null) {
setGreen(greenStr);
}
if (blueStr != null) {
setBlue(blueStr);
}
}
}
/*
* $Log: ColorInput.java,v $
* Revision 1.2 2005/01/05 06:26:56 jduke
* Completed.
*
*/