previous chapter alt="previous chapter"> contents
page top page next chapter chapter">


ChooseOneBox

February 29, 1996

Inherits from Box 



Class Description

The ChooseOneBox class allows you to create a collection of switches, such as check boxes or toggle switches, only one of which can be turned on at any time. The ChooseOneBox object ensures that only one (or none) of its switch subviews is on. If the user touches a switch that's off, ththat switch is turned on and the switch that was previously on goes off.

A ChooseOneBox object can contain other items in addition to switches. These other items aren't affected by the ChooseOneBox's rule of mutual exclusivity for switches. The switches need not be of the same type (as in the choose-one box in the lower left of the illustration), though you should probably avoid confusing your users with a mishmash of switches.

Programming Information

Instantiate: sometimes
Subclass: rarely
Call its methods: rarely


Version Note: Previous versions of the software included a ChooseOneBox object on the Boxes page of the Magic Hat. More recent versions of the software do not. You will have to create choose-one boxes by copying existing boxes, or by adding one by hand to an object definition file.

Class ChooseOneBox is a direct descendant of class Box, adding the methods that allow only one contained switch to be on at once. You can add or remove ChooseOneBox contents by using standard construction features. Any switches dropped into a ChooseOneBox object are automatically and immediately subject to the box's mutual exclusivity rule.

The ChooseOneBox class doesn't add any additional fields beyond those provided by its superclasses, and it only defines a few methods of its own.

Methods defined by class ChooseOneBox

Class ChooseOneBox defines the following methods:

Method Description
ChangedContents Overridden to take action when a new switch is added to box
CurrentChoice Returns the current choice in the box
ValueChangeNotice Overridden to force other switches off when one turns on

Description of fields

Class ChooseOneBox defines no fields.

Method Descriptions

You'll rarely have to call or override any methods of class ChooseOneBox.

ChangedContents

overrides ChangedContents(whatCausedChange: Object)

Call: rarely
Override: rarely

Magic Cap calls ChangedContents when an object moves from one superview to another, to give both the old superview and the new superview a chance to perform some action. ChooseOneBox_ChangedContents uses this notification to learn when a new switch has been dropped into the box.

See Viewable_ChangedContents for more information.

CurrentChoice

operation CurrentChoice(): Object

Call: rarely
Override: rarely

Call CurrentChoice to get the switch inside the ChooseOneBox that's turned on. The ChooseOneBox's mutual exclusivity rule ensures that only one switch is on. If no switch is turned on, GetCurrentChoice returns nilObject.

ValueChangeNotice

overrides ValueChangeNotice

Call: rarely
Override: rarely

Call ValueChangeNotice to notify a viewable that the value of one of its subviews has changed.

When a switch changes its value, usually because of a user's touch, the switch calls its superview's ValueChangeNotice method to give the superview a chance to perform some action. ChooseOneBox_ValueChangeNotice enforces the box's mutual exclusivity rule, forcing all other switches off if a switch was just turned on. ChooseOneBox_ValueChangeNotice calls EnforceMutEx to perform part of its action.

See Viewable_ValueChangeNotice for more information.