CheckBox.st
author claus
Tue, 09 May 1995 03:58:26 +0200
changeset 55 75c4a8031e66
parent 49 4dd0f5c3353e
child 56 aa651da467e2
permissions -rw-r--r--
.

"
 COPYRIGHT (c) 1995 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.
"


'From Smalltalk/X, Version:2.10.5 on 8-may-1995 at 3:48:28 am'!

HorizontalPanelView subclass:#CheckBox
	 instanceVariableNames:'toggleView labelView'
	 classVariableNames:''
	 poolDictionaries:''
	 category:'Views-Interactors'
!

!CheckBox class methodsFor:'documentation'!

version
"
$Header: /cvs/stx/stx/libwidg2/CheckBox.st,v 1.3 1995-05-09 01:57:57 claus Exp $
"
!

documentation
"
    CheckBox has been added somwehat in a hurry 
    - obviously, much more protocol is needed.

    For now, set actions etc. via sends to the components,
    labelView and toggleView.
"
!

examples
"
  no-op checkBox:

     |b|

     b := CheckBox new.
     b label:'foo'.
     b open


  changing colors (a demo only: it is no good style to fight the styleSheet):

     |panel b|

     panel := VerticalPanelView new.

     b := CheckBox in:panel.
     b label:'foo'.

     b := CheckBox in:panel.
     b label:'bar'.
     b labelView foregroundColor:Color red.

     b := CheckBox in:panel.
     b label:'baz'.
     b toggleView activeForegroundColor:Color blue.

     panel open


  using action-blocks:

     |b|

     b := CheckBox new.
     b label:'check'.
     b action:[:value | Transcript show:'set to: '; showCr:value].
     b open.


  with a model (default ST-80 behavior, sending #value: to the model):
  (see changing value in the inspector)

     |b model|

     model := ValueHolder newBoolean.

     b := CheckBox new.
     b label:'check'.
     b model:model.
     b open.
     model inspect.

  with a model and different changeSelector
  (using a plug here, for demonstration only):

     |b model|

     model := Plug new.
     model respondTo:#changeCheck: with:[:arg | Transcript showCr:'change to ' , arg printString].

     b := CheckBox new.
     b label:'check'.
     b model:model; change:#changeCheck:.
     b open.

  multiple checkBoxes on a single model (using different aspects)

     |top panel b model value1 value2 ok|

     value1 := true.
     value2 := false.
     model := Plug new.
     model respondTo:#value1 with:[value1].
     model respondTo:#value1: with:[:val | value1 := val].
     model respondTo:#value2 with:[value2].
     model respondTo:#value2: with:[:val | value2 := val].

     top := DialogBox new.
     top extent:200@300.

     panel := VerticalPanelView new.

     b := CheckBox in:panel.
     b label:'check1'.
     b model:model; aspect:#value1; change:#value1:.

     b := CheckBox in:panel.
     b label:'check2'.
     b model:model; aspect:#value2; change:#value2:.

     top addComponent:panel.
     top addAbortButton; addOkButton.
     top okAction:[ok := true].
     ok := false.
     top openModal.

     ok ifTrue:[
	 Transcript show:'value1: '; showCr:model value1.
	 Transcript show:'value2: '; showCr:model value2.
     ]
"
!

copyright
"
 COPYRIGHT (c) 1995 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.
"

! !

!CheckBox methodsFor:'accessing'!

label:aString
    labelView label:aString.
    labelView forceResize.
    mustRearrange := true.
!

font:aFont
    labelView font:aFont.
    labelView forceResize.
    mustRearrange := true.
!

font
    ^ labelView font
!

change:aChangeSelector
    toggleView change:aChangeSelector
!

label
    ^ labelView label
!

model:aModel
    labelView model:aModel.
    toggleView model:aModel
!

labelView
    "return the labelView; allows manipulation of the
     labels attributes (colors etc.)"

    ^ labelView
!

toggleView
    "return the toggleView; allows manipulation of the
     toggles attributes (colors etc.)"

    ^ toggleView
!

aspect:aspectSymbol
    labelView aspect:aspectSymbol.
    toggleView aspect:aspectSymbol
!

turnOn
    toggleView turnOn
!

action:aBlock
    toggleView action:aBlock
!

enable
    toggleView enable
!

turnOff
    toggleView turnOff
!

sendChangeMessageWith:aValue
    toggleView sendChangeMessageWith:aValue
!

disable
    toggleView disable
! !

!CheckBox methodsFor:'initialization'!

initialize
    |panel|

    super initialize.

    hLayout := #fixLeftSpace.
    vLayout := #center.

    toggleView := CheckToggle in:self.

    labelView := Label in:self.
    labelView label:'check'.
    labelView forceResize.
    labelView adjust:#left.
    self height:labelView preferedExtent y + ViewSpacing.
"/    self delegate:(KeyboardForwarder toView:toggleView).

    self controller:(toggleView controller view:toggleView).

    "
     |b|

     b := CheckBox new.
     b label:'foo'.
     b open
    "
! !