completely rewritten;
is now a ValueHolder.
--- a/RButtGrp.st Sat Mar 01 13:53:37 1997 +0100
+++ b/RButtGrp.st Sat Mar 01 14:14:02 1997 +0100
@@ -10,14 +10,14 @@
hereby transferred.
"
-OrderedCollection subclass:#RadioButtonGroup
- instanceVariableNames:'valueChannel groupID'
+ValueHolder subclass:#RadioButtonGroup
+ instanceVariableNames:'numberOfValues'
classVariableNames:''
poolDictionaries:''
category:'Views-Support'
!
-!RadioButtonGroup class methodsFor:'documentation '!
+!RadioButtonGroup class methodsFor:'documentation '!
copyright
"
@@ -50,32 +50,28 @@
g add:b2
...
- A radioButtonGroup installs itself as the model of its toggles or
- radioButtons. Therefore, you can no longer operate the individual
- elements on models.
- Instead, the group now provides a valueHolder which takes as value
- the index of the selected toggle. You can set/get this valueHolder
- via the valueChannel:/valueChannel messages.
- See the last example for how this is done.
-
- The groupID instance variable is not required for normal operation;
- the interface builder uses it to give a button-group some descriptive
- (unique) name.
+ 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.
[author:]
Claus Gittinger
+
+ [see also:]
+ RadioButton Toggle CheckBox CheckToggle Button
+ Model ValueHolder SelectionInList
"
- "Modified: 25.4.1996 / 17:40:00 / cg"
+ "Modified: 1.3.1997 / 14:11:57 / cg"
!
examples
"
- example (using Toggles for 'at most one-on behavior'):
+ using Toggles for 'at most one-on behavior':
[exBegin]
- |top panel toggle b group|
+ |top panel b group|
- top := StandardSystemView new.
+ 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.
@@ -89,11 +85,11 @@
[exEnd]
- example (using RadioButtons for 'one-on behavior'):
+ using RadioButtons for 'one-on behavior':
[exBegin]
- |top panel toggle b group|
+ |top panel b group|
- top := StandardSystemView new.
+ 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.
@@ -107,9 +103,31 @@
[exEnd]
- example (using Buttons for 'none-on behavior'; but the groups value remembers the last button):
+ same, with initial selection:
[exBegin]
- |top panel toggle b group|
+ |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.
+ [exEnd]
+
+
+ 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:
+ [exBegin]
+ |top panel b group|
top := StandardSystemView new.
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
@@ -122,196 +140,141 @@
group add:b.
top extent:(panel preferredExtent).
top open.
- group valueChannel inspect
+
+ group inspect
[exEnd]
- example (same, with button 'two' initially on):
+ using checkBoxes (these have a label included).
+ notice, that we change their behavior to radioButton behavior:
[exBegin]
- |top panel toggle b group|
-
- top := StandardSystemView new.
- 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.
- group value:2.
- b := RadioButton label:'three' in:panel.
- group add:b.
- top extent:(panel preferredExtent).
- top open.
- [exEnd]
-
-
- using checkBoxes (these have a label included):
- [exBegin]
- |top panel toggle b group|
+ |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.
[exEnd]
- example (operating on a model)
+ a small dialog
[exBegin]
- |selected dialog group|
+ |dialog group b|
- selected := 2 asValue.
dialog := Dialog new.
+
group := RadioButtonGroup new.
- group add:(dialog addCheckBox:'one' on:nil) toggleView.
- group add:(dialog addCheckBox:'two' on:nil) toggleView.
- group add:(dialog addCheckBox:'three' on:nil) toggleView.
- group valueChannel:selected.
+ 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: ' , selected value printString
+ Transcript showCR:'you selected: ' , group value printString
] ifFalse:[
Transcript showCR:'aborted'
]
[exEnd]
+
+ as a selectionIndexHolder of a selectionInList
+ (i.e. a selectionInListView and a group displaying the same selection):
+ [exBegin]
+ |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.
"
"Created: 15.11.1995 / 17:14:53 / cg"
- "Modified: 27.4.1996 / 19:27:37 / cg"
+ "Modified: 1.3.1997 / 14:13:36 / cg"
!
version
- ^ '$Header: /cvs/stx/stx/libwidg/Attic/RButtGrp.st,v 1.24 1996-07-15 14:42:09 cg Exp $'
-! !
-
-!RadioButtonGroup methodsFor:'accessing'!
-
-groupID
- ^ groupID
-
- "Modified: 5.9.1995 / 16:04:33 / claus"
-!
-
-groupID:aSymbol
- groupID := aSymbol
-
- "Modified: 5.9.1995 / 16:04:28 / claus"
-! !
-
-!RadioButtonGroup methodsFor:'accessing-mvc'!
-
-value
- ^ valueChannel value
-!
-
-value:anIndex
- valueChannel value:anIndex
-!
-
-valueChannel
- ^ valueChannel
-!
-
-valueChannel:aValueHolder
- |oldValue newValue|
-
- valueChannel notNil ifTrue:[oldValue := valueChannel value].
- valueChannel := aValueHolder.
- (newValue := valueChannel value) ~~ oldValue ifTrue:[
- (self at:newValue) turnOnWithAction
- ]
+ ^ '$Header: /cvs/stx/stx/libwidg/Attic/RButtGrp.st,v 1.25 1997-03-01 13:14:02 cg Exp $'
! !
!RadioButtonGroup methodsFor:'adding / removing'!
add:aRadioButton
- |c|
+ "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"
- super add:aRadioButton.
+ |c idx adaptor|
- "
- this would work, if dependencies were not weak ...
- "
-"/ aRadioButton addDependent:self.
+ numberOfValues isNil ifTrue:[
+ numberOfValues := 0.
+ ].
+ numberOfValues := numberOfValues + 1.
+ idx := numberOfValues.
- "
- therefore, we have to install ourself as model of the buttons/toggles
- creating a valueChannel, if there is none yet.
- "
- valueChannel isNil ifTrue:[
- valueChannel := 0 asValue
+ adaptor := PluggableAdaptor on:self.
+ adaptor getBlock:[:m | m value == idx]
+ putBlock:[:m :onOff |
+ onOff ifTrue:[
+ m value:idx
+ ] ifFalse:[
+ idx == value ifTrue:[
+ m value:nil
+ ]
+ ]
+ ]
+ updateBlock:[:m :a :v | true].
+
+ aRadioButton isOn ifTrue:[
+ self value:idx.
].
- aRadioButton isOn ifTrue:[valueChannel value:self size].
- aRadioButton model:self; aspectMessage:#queryFrom:; changeMessage:#elementChanged:from:.
+ aRadioButton model:adaptor.
- (c := aRadioButton controller) notNil ifTrue:[
- c beRadioButton
- ] ifFalse:[
- aRadioButton controller:(RadioButtonController new).
- ]
+"/ (c := aRadioButton controller) notNil ifTrue:[
+"/ c beRadioButton
+"/ ] ifFalse:[
+"/ aRadioButton controller:(RadioButtonController new).
+"/ ]
- "Modified: 15.7.1996 / 14:07:19 / cg"
+ "Modified: 1.3.1997 / 13:58:32 / cg"
! !
-!RadioButtonGroup methodsFor:'update'!
-
-elementChanged:aToggle
- "historic compatibility leftover - will vanish"
-
- ^ self elementChanged:true from:aToggle
-!
-
-elementChanged:value from:aToggle
- "some element changed its value - find it, turn the others off
- and update my value"
-
- |newValue|
-
- self keysAndValuesDo:[:index :aComponent |
- ((aToggle == aComponent) or:[aToggle isComponentOf:aComponent]) ifTrue:[
- value ifTrue:[newValue := index]
- ] ifFalse:[
-"/ aComponent isOn ifTrue:[
-"/ aComponent turnOff
-"/ ]
- ]
- ].
-"/ aToggle turnOn.
- valueChannel value:newValue.
- self changed:#queryFrom:
-
- "Modified: 21.9.1995 / 13:42:06 / claus"
- "Modified: 5.6.1996 / 14:25:51 / cg"
-!
-
-queryFrom:aToggle
- "a query from a toggle, if its the selected one"
-
- self keysAndValuesDo:[:index :aComponent |
- ((aToggle == aComponent) or:[aToggle isComponentOf:aComponent]) ifTrue:[
- ^ valueChannel value == index
- ]
- ].
- ^ false
-
- "Modified: 5.6.1996 / 14:25:53 / cg"
-!
-
-update:something with:someArgument from:changedButton
- "
- a RadioButton in this group has changed - notify the others
- "
-
- self elementChanged:(changedButton isOn) from:changedButton
-! !
-
--- a/RadioButtonGroup.st Sat Mar 01 13:53:37 1997 +0100
+++ b/RadioButtonGroup.st Sat Mar 01 14:14:02 1997 +0100
@@ -10,14 +10,14 @@
hereby transferred.
"
-OrderedCollection subclass:#RadioButtonGroup
- instanceVariableNames:'valueChannel groupID'
+ValueHolder subclass:#RadioButtonGroup
+ instanceVariableNames:'numberOfValues'
classVariableNames:''
poolDictionaries:''
category:'Views-Support'
!
-!RadioButtonGroup class methodsFor:'documentation '!
+!RadioButtonGroup class methodsFor:'documentation '!
copyright
"
@@ -50,32 +50,28 @@
g add:b2
...
- A radioButtonGroup installs itself as the model of its toggles or
- radioButtons. Therefore, you can no longer operate the individual
- elements on models.
- Instead, the group now provides a valueHolder which takes as value
- the index of the selected toggle. You can set/get this valueHolder
- via the valueChannel:/valueChannel messages.
- See the last example for how this is done.
-
- The groupID instance variable is not required for normal operation;
- the interface builder uses it to give a button-group some descriptive
- (unique) name.
+ 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.
[author:]
Claus Gittinger
+
+ [see also:]
+ RadioButton Toggle CheckBox CheckToggle Button
+ Model ValueHolder SelectionInList
"
- "Modified: 25.4.1996 / 17:40:00 / cg"
+ "Modified: 1.3.1997 / 14:11:57 / cg"
!
examples
"
- example (using Toggles for 'at most one-on behavior'):
+ using Toggles for 'at most one-on behavior':
[exBegin]
- |top panel toggle b group|
+ |top panel b group|
- top := StandardSystemView new.
+ 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.
@@ -89,11 +85,11 @@
[exEnd]
- example (using RadioButtons for 'one-on behavior'):
+ using RadioButtons for 'one-on behavior':
[exBegin]
- |top panel toggle b group|
+ |top panel b group|
- top := StandardSystemView new.
+ 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.
@@ -107,9 +103,31 @@
[exEnd]
- example (using Buttons for 'none-on behavior'; but the groups value remembers the last button):
+ same, with initial selection:
[exBegin]
- |top panel toggle b group|
+ |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.
+ [exEnd]
+
+
+ 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:
+ [exBegin]
+ |top panel b group|
top := StandardSystemView new.
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
@@ -122,196 +140,141 @@
group add:b.
top extent:(panel preferredExtent).
top open.
- group valueChannel inspect
+
+ group inspect
[exEnd]
- example (same, with button 'two' initially on):
+ using checkBoxes (these have a label included).
+ notice, that we change their behavior to radioButton behavior:
[exBegin]
- |top panel toggle b group|
-
- top := StandardSystemView new.
- 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.
- group value:2.
- b := RadioButton label:'three' in:panel.
- group add:b.
- top extent:(panel preferredExtent).
- top open.
- [exEnd]
-
-
- using checkBoxes (these have a label included):
- [exBegin]
- |top panel toggle b group|
+ |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.
[exEnd]
- example (operating on a model)
+ a small dialog
[exBegin]
- |selected dialog group|
+ |dialog group b|
- selected := 2 asValue.
dialog := Dialog new.
+
group := RadioButtonGroup new.
- group add:(dialog addCheckBox:'one' on:nil) toggleView.
- group add:(dialog addCheckBox:'two' on:nil) toggleView.
- group add:(dialog addCheckBox:'three' on:nil) toggleView.
- group valueChannel:selected.
+ 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: ' , selected value printString
+ Transcript showCR:'you selected: ' , group value printString
] ifFalse:[
Transcript showCR:'aborted'
]
[exEnd]
+
+ as a selectionIndexHolder of a selectionInList
+ (i.e. a selectionInListView and a group displaying the same selection):
+ [exBegin]
+ |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.
"
"Created: 15.11.1995 / 17:14:53 / cg"
- "Modified: 27.4.1996 / 19:27:37 / cg"
+ "Modified: 1.3.1997 / 14:13:36 / cg"
!
version
- ^ '$Header: /cvs/stx/stx/libwidg/RadioButtonGroup.st,v 1.24 1996-07-15 14:42:09 cg Exp $'
-! !
-
-!RadioButtonGroup methodsFor:'accessing'!
-
-groupID
- ^ groupID
-
- "Modified: 5.9.1995 / 16:04:33 / claus"
-!
-
-groupID:aSymbol
- groupID := aSymbol
-
- "Modified: 5.9.1995 / 16:04:28 / claus"
-! !
-
-!RadioButtonGroup methodsFor:'accessing-mvc'!
-
-value
- ^ valueChannel value
-!
-
-value:anIndex
- valueChannel value:anIndex
-!
-
-valueChannel
- ^ valueChannel
-!
-
-valueChannel:aValueHolder
- |oldValue newValue|
-
- valueChannel notNil ifTrue:[oldValue := valueChannel value].
- valueChannel := aValueHolder.
- (newValue := valueChannel value) ~~ oldValue ifTrue:[
- (self at:newValue) turnOnWithAction
- ]
+ ^ '$Header: /cvs/stx/stx/libwidg/RadioButtonGroup.st,v 1.25 1997-03-01 13:14:02 cg Exp $'
! !
!RadioButtonGroup methodsFor:'adding / removing'!
add:aRadioButton
- |c|
+ "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"
- super add:aRadioButton.
+ |c idx adaptor|
- "
- this would work, if dependencies were not weak ...
- "
-"/ aRadioButton addDependent:self.
+ numberOfValues isNil ifTrue:[
+ numberOfValues := 0.
+ ].
+ numberOfValues := numberOfValues + 1.
+ idx := numberOfValues.
- "
- therefore, we have to install ourself as model of the buttons/toggles
- creating a valueChannel, if there is none yet.
- "
- valueChannel isNil ifTrue:[
- valueChannel := 0 asValue
+ adaptor := PluggableAdaptor on:self.
+ adaptor getBlock:[:m | m value == idx]
+ putBlock:[:m :onOff |
+ onOff ifTrue:[
+ m value:idx
+ ] ifFalse:[
+ idx == value ifTrue:[
+ m value:nil
+ ]
+ ]
+ ]
+ updateBlock:[:m :a :v | true].
+
+ aRadioButton isOn ifTrue:[
+ self value:idx.
].
- aRadioButton isOn ifTrue:[valueChannel value:self size].
- aRadioButton model:self; aspectMessage:#queryFrom:; changeMessage:#elementChanged:from:.
+ aRadioButton model:adaptor.
- (c := aRadioButton controller) notNil ifTrue:[
- c beRadioButton
- ] ifFalse:[
- aRadioButton controller:(RadioButtonController new).
- ]
+"/ (c := aRadioButton controller) notNil ifTrue:[
+"/ c beRadioButton
+"/ ] ifFalse:[
+"/ aRadioButton controller:(RadioButtonController new).
+"/ ]
- "Modified: 15.7.1996 / 14:07:19 / cg"
+ "Modified: 1.3.1997 / 13:58:32 / cg"
! !
-!RadioButtonGroup methodsFor:'update'!
-
-elementChanged:aToggle
- "historic compatibility leftover - will vanish"
-
- ^ self elementChanged:true from:aToggle
-!
-
-elementChanged:value from:aToggle
- "some element changed its value - find it, turn the others off
- and update my value"
-
- |newValue|
-
- self keysAndValuesDo:[:index :aComponent |
- ((aToggle == aComponent) or:[aToggle isComponentOf:aComponent]) ifTrue:[
- value ifTrue:[newValue := index]
- ] ifFalse:[
-"/ aComponent isOn ifTrue:[
-"/ aComponent turnOff
-"/ ]
- ]
- ].
-"/ aToggle turnOn.
- valueChannel value:newValue.
- self changed:#queryFrom:
-
- "Modified: 21.9.1995 / 13:42:06 / claus"
- "Modified: 5.6.1996 / 14:25:51 / cg"
-!
-
-queryFrom:aToggle
- "a query from a toggle, if its the selected one"
-
- self keysAndValuesDo:[:index :aComponent |
- ((aToggle == aComponent) or:[aToggle isComponentOf:aComponent]) ifTrue:[
- ^ valueChannel value == index
- ]
- ].
- ^ false
-
- "Modified: 5.6.1996 / 14:25:53 / cg"
-!
-
-update:something with:someArgument from:changedButton
- "
- a RadioButton in this group has changed - notify the others
- "
-
- self elementChanged:(changedButton isOn) from:changedButton
-! !
-