com.hfg.html.custom.CheckboxSpan Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com_hfg Show documentation
Show all versions of com_hfg Show documentation
com.hfg xml, html, svg, and bioinformatics utility library
package com.hfg.html.custom;
import com.hfg.css.CSS;
import com.hfg.css.CSSDeclaration;
import com.hfg.html.HTMLTag;
import com.hfg.html.InputCheckbox;
import com.hfg.html.InputRadio;
import com.hfg.html.Span;
import com.hfg.html.attribute.HTMLColor;
//------------------------------------------------------------------------------
/**
Container for a checkbox or radio button plus its label. Clicking on the label
checks / unchecks the checkbox.
@author J. Alex Taylor, hairyfatguy.com
*/
//------------------------------------------------------------------------------
// com.hfg XML/HTML Coding Library
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
// [email protected]
//------------------------------------------------------------------------------
public class CheckboxSpan extends Span
{
private InputCheckbox mCheckbox;
private InputRadio mRadioBtn;
private String mDisabledClass;
//##########################################################################
// CONSTRUCTORS
//##########################################################################
//--------------------------------------------------------------------------
public CheckboxSpan(InputCheckbox inCheckbox, String inLabel)
{
super();
mCheckbox = inCheckbox;
addSubtag(inCheckbox.appendToOnClick("event.cancelBubble=true;"));
addSpan(inLabel).setStyle("margin-left: 5px;");
appendToOnClick("this.children[0].click();");
}
//--------------------------------------------------------------------------
public CheckboxSpan(InputCheckbox inCheckbox, HTMLTag inLabel)
{
super();
mCheckbox = inCheckbox;
addSubtag(inCheckbox.appendToOnClick("event.cancelBubble=true;"));
addSubtag(inLabel.addStyle("margin-left: 5px;"));
appendToOnClick("this.children[0].click();");
}
//--------------------------------------------------------------------------
public CheckboxSpan(InputRadio inRadioButton, String inLabel)
{
super();
mRadioBtn = inRadioButton;
addSubtag(inRadioButton.appendToOnClick("event.cancelBubble=true;"));
addSpan(inLabel).setStyle("margin-left: 5px;");
appendToOnClick("this.children[0].click();");
}
//--------------------------------------------------------------------------
public CheckboxSpan(InputRadio inRadioButton, HTMLTag inLabel)
{
super();
mRadioBtn = inRadioButton;
addSubtag(inRadioButton.appendToOnClick("event.cancelBubble=true;"));
addSubtag(inLabel.addStyle("margin-left: 5px;"));
appendToOnClick("this.children[0].click();");
}
//##########################################################################
// PUBLIC METHODS
//##########################################################################
//--------------------------------------------------------------------------
@Override
public CheckboxSpan addClass(String inValue)
{
return (CheckboxSpan) super.addClass(inValue);
}
//--------------------------------------------------------------------------
@Override
public CheckboxSpan addStyle(String inValue)
{
return (CheckboxSpan) super.addStyle(inValue);
}
//--------------------------------------------------------------------------
public CheckboxSpan setDisabledClass(String inValue)
{
mDisabledClass = inValue;
return this;
}
//--------------------------------------------------------------------------
public String getDisabledClass()
{
return mDisabledClass;
}
//--------------------------------------------------------------------------
public CheckboxSpan setDisabled(boolean inValue)
{
if (mCheckbox != null)
{
mCheckbox.setDisabled(inValue);
}
if (mRadioBtn != null)
{
mRadioBtn.setDisabled(inValue);
}
if (mDisabledClass != null)
{
if (inValue)
{
addClass(mDisabledClass);
}
else
{
removeClass(mDisabledClass);
}
}
else
{
setStyleColor(inValue ? HTMLColor.DARK_GRAY : null);
}
return this;
}
}