Class WAbstractToggleButton

Direct Known Subclasses:
WCheckBox, WRadioButton

public abstract class WAbstractToggleButton
extends WFormWidget
An abstract base class for radio buttons and check boxes.

A toggle button provides a button with a boolean state (checked or unchecked), and a text label.

To act on a change of the state, either connect a slot to the WFormWidget.changed() signal, or connect a slot to the checked() or unChecked() signals.

The current state (checked or unchecked) may be inspected using the isChecked() method.

  • Constructor Details

    • WAbstractToggleButton

      protected WAbstractToggleButton​(WContainerWidget parent)
      Creates an unchecked toggle button without label.
    • WAbstractToggleButton

      protected WAbstractToggleButton()
      Creates an unchecked toggle button without label.

      Calls this((WContainerWidget)null)

    • WAbstractToggleButton

      protected WAbstractToggleButton​(java.lang.CharSequence text, WContainerWidget parent)
      Creates an unchecked toggle button with given text label.

      The text label is rendered to the right side of the button.

    • WAbstractToggleButton

      protected WAbstractToggleButton​(java.lang.CharSequence text)
      Creates an unchecked toggle button with given text label.

      Calls this(text, (WContainerWidget)null)

  • Method Details

    • remove

      public void remove()
      Destructor.
      Overrides:
      remove in class WFormWidget
      See Also:
      WContainerWidget.removeWidget(WWidget widget)
    • setText

      public void setText​(java.lang.CharSequence text)
      Sets the label text.

      The label is rendered to the right of the button.

    • getText

      public WString getText()
      Returns the label text.

      See Also:
      setText(CharSequence text)
    • setTextFormat

      public boolean setTextFormat​(TextFormat format)
      Sets the text format.

      The textFormat controls how the string should be interpreted: either as plain text, which is displayed literally, or as XHTML-markup.

      When changing the textFormat to TextFormat.XHTMLText, and the current text is literal (not created using WString#tr()), the current text is parsed using an XML parser which discards malicious tags and attributes silently. When the parser encounters an XML parse error, the textFormat is left unchanged, and this method returns false.

      Returns whether the textFormat could be set for the current text.

      The default format is TextFormat.PlainText.

    • getTextFormat

      public TextFormat getTextFormat()
      Returns the text format.

      See Also:
      setTextFormat(TextFormat format)
    • isChecked

      public boolean isChecked()
      Returns the button state.

      See Also:
      setChecked()
    • setChecked

      public void setChecked​(boolean how)
      Sets the button state.

      This method does not emit one of the checked() or unChecked() signals.

      See Also:
      setChecked(), setUnChecked()
    • setChecked

      public void setChecked()
      Checks the button.

      Does not emit the checked() signal.

      See Also:
      setChecked(boolean how)
    • setUnChecked

      public void setUnChecked()
      Unchecks the button.

      Does not emit the unChecked() signal.

      See Also:
      setChecked(boolean how)
    • getValueText

      public java.lang.String getValueText()
      Returns the current value.

      Returns "yes" when checked, "maybe" when partially checked, and "no" when unchecked.

      Specified by:
      getValueText in class WFormWidget
    • setValueText

      public void setValueText​(java.lang.String text)
      Sets the current value.

      This interprets text values of "yes", "maybe" or "no".

      Specified by:
      setValueText in class WFormWidget
    • checked

      public EventSignal checked()
      Signal emitted when the button gets checked.

      This signal is emitted when the user checks the button.

      You can use the WFormWidget.changed() signal to react to any change of the button state.

    • unChecked

      public EventSignal unChecked()
      Signal emitted when the button gets un-checked.

      This signal is emitted when the user unchecks the button.

      You can use the WFormWidget.changed() signal to react to any change of the button state.

    • refresh

      public void refresh()
      Description copied from class: WWidget
      Refresh the widget.

      The refresh method is invoked when the locale is changed using WApplication#setLocale() or when the user hit the refresh button.

      The widget must actualize its contents in response.

      Note: This does *not* rerender the widget! Calling refresh() usually does not have any effect (unless you've reimplemented refresh() to attach to it an effect).

      Overrides:
      refresh in class WFormWidget
    • setWordWrap

      public void setWordWrap​(boolean wordWrap)
      Configures word wrapping.

      When wordWrap is true, the widget may break lines, creating a multi-line text. When wordWrap is false, the text will displayed on a single line, unless the text contains end-of-lines (for TextFormat.PlainText) or <br /> tags or other block-level tags (for TextFormat.XHTMLText).

      The default value is false.

      See Also:
      isWordWrap()
    • isWordWrap

      public boolean isWordWrap()
      Returns whether word wrapping is on.

      See Also:
      setWordWrap(boolean wordWrap)
    • setFormData

      protected void setFormData​(WObject.FormData formData)
      Overrides:
      setFormData in class WObject