I am a presener for reuse. I hold a title and a group of radio buttons. I can help to create and to manage a group of SpRadioButtonPresenters.
title-a SpLabelPresenterholds the caption of the groupitems-an OrderedCollectionof objects that are displayed as radio buttonsbuttons-an OrderedCollectionof radio buttonsdisplay-a BlockClosurean unary block defines the way to display the itemscolumnCount-an Integerbetween 1 and 4 - the number of columns that the buttons are divided intoindex-an Integerbetween 1 and buttons size - the indes of the selected buttonwhenIndexChangedDo-a BlockClosurean unary block - the event handlerwhenColumnsChangedDo-a BlockClosurean unary block - the event handlerisEvenEvent-a Booleanhelper variable
beSingleColumn,beDoubleColumn,beTripleColumn,beQuatroColumnchanges the count of columns of the buttons. The single column is set by default.display: anUnaryBlocsets a block to define the way to display the itemstitle: aStringsets the caption of the group of the buttonswhenColumnsChangedDo: anUnaryBlocsets the event handler. ThecolumnsCountwill pass to the blockwhenIndexChangedDo: anUnaryBlocsets the event handler. Theindexwill pass to the blockitems: aCollectionchanges the collection of objects that are displayed as radio buttonsaddItem: anObjectadds the item to the collection of objects that are displayed as radio buttonsitemSelectedreturns the object that corresponds to the selected buttoncolumnCount,indexSelected,titleare simple getters
To load the progect execute
Metacello new
baseline: 'RadioGroupProject';
repository: 'github://LNUitTutor/RadioGroupProject/src';
loadTo create an instance use SpRadioGroupPresenter class >> on: aCollection or SpPresenter >> instantiate: SpRadioGroupPresenter on: aCollection. For example
| group |
group := (SpRadioGroupPresenter on: 'ABCDEFGH') title: 'Choose a letter'; beDoubleColumn.
group openBy using SpRadioGroupPresenter new you will get SpRadioGroupPresenter on: #( 'Button 1' 'Button 2' 'Button 3' )