Skip to content

Commit

Permalink
#219 add more attributes to b:switch
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanrauh committed Dec 28, 2015
1 parent 8ad6b2d commit b550748
Show file tree
Hide file tree
Showing 4 changed files with 594 additions and 262 deletions.
212 changes: 211 additions & 1 deletion src/main/java/net/bootsfaces/component/switchComponent/Switch.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,18 @@ public String getFamily() {
}
protected enum PropertyKeys {
onText,
offText
offText,
onColor,
offColor,
indeterminate,
inverse,
switchsize,
animate,
disabled,
readonly,
labelText,
handleWidth,
labelWidth
;

String toString;
Expand Down Expand Up @@ -105,5 +116,204 @@ public String getOffText() {
public void setOffText(String _offText) {
getStateHelper().put(PropertyKeys.offText, _offText);
}


/**
* Color of the left hand side of the switch. Legal values: 'primary', 'info', 'success', 'warning', 'danger', 'default'. Default value: 'primary'. <P>
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
*/
public String getOnColor() {
String value = (String)getStateHelper().eval(PropertyKeys.onColor);
return value;
}

/**
* Color of the left hand side of the switch. Legal values: 'primary', 'info', 'success', 'warning', 'danger', 'default'. Default value: 'primary'. <P>
* Usually this method is called internally by the JSF engine.
*/
public void setOnColor(String _onColor) {
getStateHelper().put(PropertyKeys.onColor, _onColor);
}


/**
* Color of the right hand side of the switch. Legal values: 'primary', 'info', 'success', 'warning', 'danger', 'default'. Default value: 'primary'. <P>
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
*/
public String getOffColor() {
String value = (String)getStateHelper().eval(PropertyKeys.offColor);
return value;
}

/**
* Color of the right hand side of the switch. Legal values: 'primary', 'info', 'success', 'warning', 'danger', 'default'. Default value: 'primary'. <P>
* Usually this method is called internally by the JSF engine.
*/
public void setOffColor(String _offColor) {
getStateHelper().put(PropertyKeys.offColor, _offColor);
}


/**
* Indeterminate state. Turned off by default. <P>
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
*/
public boolean isIndeterminate() {
Boolean value = (Boolean)getStateHelper().eval(PropertyKeys.indeterminate, false);
return (boolean) value;
}

/**
* Indeterminate state. Turned off by default. <P>
* Usually this method is called internally by the JSF engine.
*/
public void setIndeterminate(boolean _indeterminate) {
getStateHelper().put(PropertyKeys.indeterminate, _indeterminate);
}


/**
* Inverse switch direction. Default value: false <P>
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
*/
public boolean isInverse() {
Boolean value = (Boolean)getStateHelper().eval(PropertyKeys.inverse, false);
return (boolean) value;
}

/**
* Inverse switch direction. Default value: false <P>
* Usually this method is called internally by the JSF engine.
*/
public void setInverse(boolean _inverse) {
getStateHelper().put(PropertyKeys.inverse, _inverse);
}


/**
* The checkbox size. null, 'mini', 'small', 'normal', 'large'. Default value: 'null'. <P>
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
*/
public String getSwitchsize() {
String value = (String)getStateHelper().eval(PropertyKeys.switchsize);
return value;
}

/**
* The checkbox size. null, 'mini', 'small', 'normal', 'large'. Default value: 'null'. <P>
* Usually this method is called internally by the JSF engine.
*/
public void setSwitchsize(String _switchsize) {
getStateHelper().put(PropertyKeys.switchsize, _switchsize);
}


/**
* Animate the switch. Default value: true. <P>
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
*/
public boolean isAnimate() {
Boolean value = (Boolean)getStateHelper().eval(PropertyKeys.animate, false);
return (boolean) value;
}

/**
* Animate the switch. Default value: true. <P>
* Usually this method is called internally by the JSF engine.
*/
public void setAnimate(boolean _animate) {
getStateHelper().put(PropertyKeys.animate, _animate);
}


/**
* Is the switch disabled? Default value: false. <P>
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
*/
public boolean isDisabled() {
Boolean value = (Boolean)getStateHelper().eval(PropertyKeys.disabled, false);
return (boolean) value;
}

/**
* Is the switch disabled? Default value: false. <P>
* Usually this method is called internally by the JSF engine.
*/
public void setDisabled(boolean _disabled) {
getStateHelper().put(PropertyKeys.disabled, _disabled);
}


/**
* Is the switch readonly? Default value: false. <P>
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
*/
public boolean isReadonly() {
Boolean value = (Boolean)getStateHelper().eval(PropertyKeys.readonly, false);
return (boolean) value;
}

/**
* Is the switch readonly? Default value: false. <P>
* Usually this method is called internally by the JSF engine.
*/
public void setReadonly(boolean _readonly) {
getStateHelper().put(PropertyKeys.readonly, _readonly);
}


/**
* Text of the center handle of the switch. Default value: a space (nbsp). <P>
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
*/
public String getLabelText() {
String value = (String)getStateHelper().eval(PropertyKeys.labelText);
return value;
}

/**
* Text of the center handle of the switch. Default value: a space (nbsp). <P>
* Usually this method is called internally by the JSF engine.
*/
public void setLabelText(String _labelText) {
getStateHelper().put(PropertyKeys.labelText, _labelText);
}


/**
* Width of the left and right sides in pixels. <P>
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
*/
public int getHandleWidth() {
Integer value = (Integer)getStateHelper().eval(PropertyKeys.handleWidth, 0);
return (int) value;
}

/**
* Width of the left and right sides in pixels. <P>
* Usually this method is called internally by the JSF engine.
*/
public void setHandleWidth(int _handleWidth) {
getStateHelper().put(PropertyKeys.handleWidth, _handleWidth);
}


/**
* Width of the center handle in pixels. <P>
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
*/
public int getLabelWidth() {
Integer value = (Integer)getStateHelper().eval(PropertyKeys.labelWidth, 0);
return (int) value;
}

/**
* Width of the center handle in pixels. <P>
* Usually this method is called internally by the JSF engine.
*/
public void setLabelWidth(int _labelWidth) {
getStateHelper().put(PropertyKeys.labelWidth, _labelWidth);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,52 @@
import net.bootsfaces.component.selectBooleanCheckbox.SelectBooleanCheckbox;
import net.bootsfaces.component.selectBooleanCheckbox.SelectBooleanCheckboxRenderer;


/** This class generates the HTML code of &lt;b:switchWidget /&gt;. */
@FacesRenderer(componentFamily = "net.bootsfaces.component", rendererType = "net.bootsfaces.component.switch.Switch")
public class SwitchRenderer extends SelectBooleanCheckboxRenderer {

@Override
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
ResponseWriter rw = context.getResponseWriter();
String clientId = component.getClientId();
super.encodeBegin(context, component);
clientId=clientId.replace(":","\\\\:");
clientId = clientId.replace(":", "\\\\:");
rw.append("<script>");
rw.append("$('#input_" + clientId + "').bootstrapSwitch();");
rw.append("</script>");
}

/**
* The b:switch and the b:selectBooleanCheckbox share most of their code. This method allows to add extra attributes for the switch.
* The b:switch and the b:selectBooleanCheckbox share most of their code.
* This method allows to add extra attributes for the switch.
*
* @param rw
* @param selectBooleanCheckbox
* @throws IOException
*/
protected void addAttributesForSwitch(ResponseWriter rw, SelectBooleanCheckbox selectBooleanCheckbox) throws IOException {
Switch switchComponent = (Switch)selectBooleanCheckbox;
protected void addAttributesForSwitch(ResponseWriter rw, SelectBooleanCheckbox selectBooleanCheckbox)
throws IOException {
Switch switchComponent = (Switch) selectBooleanCheckbox;
writeAttribute(rw, "data-off-text", switchComponent.getOffText());
writeAttribute(rw, "data-on-text", switchComponent.getOnText());
writeAttribute(rw, "data-on-color", switchComponent.getOnColor());
writeAttribute(rw, "data-off-color", switchComponent.getOffColor());
if (switchComponent.isIndeterminate())
writeAttribute(rw, "data-indeterminate", switchComponent.isIndeterminate());
if (switchComponent.isInverse())
writeAttribute(rw, "data-inverse", switchComponent.isInverse());
writeAttribute(rw, "data-size", switchComponent.getSwitchsize());
if (!switchComponent.isAnimate())
writeAttribute(rw, "data-animate", switchComponent.isAnimate());
if (switchComponent.isDisabled())
writeAttribute(rw, "data-disabled", switchComponent.isDisabled());
if (switchComponent.isReadonly())
writeAttribute(rw, "data-readonly", switchComponent.isReadonly());
writeAttribute(rw, "data-label-text", switchComponent.getLabelText());
if (switchComponent.getHandleWidth() > 0)
writeAttribute(rw, "data-handle-width", switchComponent.getHandleWidth());
if (switchComponent.getLabelWidth() > 0)
writeAttribute(rw, "data-label-width", switchComponent.getLabelWidth());
}

}
Loading

0 comments on commit b550748

Please sign in to comment.