eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'RadioButtonGroup':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: RadioButtonGroup


Inheritance:

   Object
   |
   +--Model
      |
      +--ValueModel
         |
         +--ValueHolder
            |
            +--RadioButtonGroup

Package:
stx:libwidg
Category:
Views-Support
Version:
rev: 1.35 date: 2021/08/06 16:06:26
user: cg
file: RadioButtonGroup.st directory: libwidg
module: stx stc-classLibrary: libwidg

Description:


RadioButtonGroups control the interaction between RadioButtons
turning off other button(s) when one of the group is pressed.
To group some buttons (and have one-on behavior) use:

    |g|

    g := RadioButtonGroup new.
    ...
    b1 := RadioButton label:....
    g add:b1
    ...
    b2 := RadioButton label:....
    g add:b2
    ...

A radioButtonGroup is itself usable as a model, holding the index of
the selected button. It can be used as a selectionIndexHolder of a
SelectionInList instance.

copyright

COPYRIGHT (c) 1991 by Claus Gittinger All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

helpers
o  adaptorFor: someValueHolder value: buttonValue
create and return an adaptor for a radioButton


Instance protocol:

adding & removing
o  add: aRadioButton
add a radioButton to the group - actually, this name is misleading;
it simple creates an adaptor, which converts my value into a boolean,
depending on the buttons index-number

o  add: aRadioButton value: aValueOrNil
add a radioButton to the group - actually, this name is misleading;
it simply creates an adaptor, which converts my value into a boolean,
depending on the buttons index-number or aValueOrNil

queries
o  numberOfValues


Examples:


using Toggles for 'at most one-on behavior':
    |top panel b group|

    top := StandardSystemView label:'toggles'.
    panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
    group := RadioButtonGroup new.
    b := Toggle label:'one' in:panel.
    group add:b.
    b := Toggle label:'two' in:panel.
    group add:b.
    b := Toggle label:'three' in:panel.
    group add:b.
    top extent:(panel preferredExtent).
    top open.
using RadioButtons for 'one-on behavior':
    |top panel b group|

    top := StandardSystemView label:'radio'.
    panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
    group := RadioButtonGroup new.
    b := RadioButton label:'one' in:panel.
    group add:b.
    b := RadioButton label:'two' in:panel.
    group add:b.
    b := RadioButton label:'three' in:panel.
    group add:b.
    top extent:(panel preferredExtent).
    top open.
same, with initial selection:
    |top panel b group|

    top := StandardSystemView label:'radio'.
    panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
    group := RadioButtonGroup new.
    b := RadioButton label:'one' in:panel.
    group add:b.
    b := RadioButton label:'two' in:panel.
    group add:b.
    b := RadioButton label:'three' in:panel.
    group add:b.
    top extent:(panel preferredExtent).

    group value:1.
    top open.
using Buttons for 'none-on behavior'; buttons do not show the boolean state (they only fire); however, the groups value remembers the last pressed button:
    |top panel b group|

    top := StandardSystemView new.
    panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
    group := RadioButtonGroup new.
    b := Button label:'one' in:panel.
    group add:b.
    b := Button label:'two' in:panel.
    group add:b.
    b := Button label:'three' in:panel.
    group add:b.
    top extent:(panel preferredExtent).
    top open.

    group inspect
using checkBoxes (these have a label included). notice, that we change their behavior to radioButton behavior:
    |top panel b group|

    top := StandardSystemView new.
    panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
    panel horizontalLayout:#left.
    group := RadioButtonGroup new.
    b := CheckBox label:'one' in:panel.
    b controller beRadioButton.
    group add:b.
    b := CheckBox label:'two' in:panel.
    b controller beRadioButton.
    group add:b.
    b := CheckBox label:'three' in:panel.
    b controller beRadioButton.
    group add:b.
    top extent:(panel preferredExtent).
    top open.
a small dialog
    |dialog group b|

    dialog := Dialog new.

    group := RadioButtonGroup new.
    group add:(b := dialog addCheckBox:'one' on:nil).
    b controller beRadioButton.
    group add:(b := dialog addCheckBox:'two' on:nil).
    b controller beRadioButton.
    group add:(b := dialog addCheckBox:'three' on:nil).
    b controller beRadioButton.
    group value:2.
    dialog addAbortButton; addOkButton.
    dialog open.

    dialog accepted ifTrue:[
        Transcript showCR:'you selected: ' , group value printString
    ] ifFalse:[
        Transcript showCR:'aborted'
    ]
as a selectionIndexHolder of a selectionInList (i.e. a selectionInListView and a group displaying the same selection):
|top top2 panel b sv group selectionInList|

top := StandardSystemView extent:200@200.

panel := HorizontalPanelView
            origin:0.0@0.0 corner:1.0@1.0 in:top.

group := RadioButtonGroup new.
selectionInList := SelectionInList new.
selectionInList list:#('am' 'fm' 'off').
selectionInList selectionIndexHolder:group.

b := RadioButton label:'am' in:panel.
group add:b.

b := RadioButton label:'fm' in:panel.
group add:b.

b := RadioButton label:'off' in:panel.
group add:b.

group value:1.
top open.


top2 := StandardSystemView extent:200@200.
sv := SelectionInListView in:top2.
sv model:selectionInList.
sv origin:0.0@0.0 corner:1.0@1.0.
top2 open.


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sun, 24 Nov 2024 02:06:31 GMT