CheckBox.st
changeset 56 aa651da467e2
parent 55 75c4a8031e66
child 58 2bdd35f8aef0
equal deleted inserted replaced
55:75c4a8031e66 56:aa651da467e2
    22 
    22 
    23 !CheckBox class methodsFor:'documentation'!
    23 !CheckBox class methodsFor:'documentation'!
    24 
    24 
    25 version
    25 version
    26 "
    26 "
    27 $Header: /cvs/stx/stx/libwidg2/CheckBox.st,v 1.3 1995-05-09 01:57:57 claus Exp $
    27 $Header: /cvs/stx/stx/libwidg2/CheckBox.st,v 1.4 1995-05-12 18:34:07 claus Exp $
    28 "
    28 "
    29 !
    29 !
    30 
    30 
    31 documentation
    31 documentation
    32 "
    32 "
    47      b := CheckBox new.
    47      b := CheckBox new.
    48      b label:'foo'.
    48      b label:'foo'.
    49      b open
    49      b open
    50 
    50 
    51 
    51 
    52   changing colors (a demo only: it is no good style to fight the styleSheet):
    52   no-op checkBox, disabled:
       
    53 
       
    54      |b|
       
    55 
       
    56      b := CheckBox new.
       
    57      b label:'foo'.
       
    58      b disable.
       
    59      b open
       
    60 
       
    61 
       
    62   changing colors 
       
    63   (a demo only: it is no good style to fight the styleSheet):
    53 
    64 
    54      |panel b|
    65      |panel b|
    55 
    66 
    56      panel := VerticalPanelView new.
    67      panel := VerticalPanelView new.
    57 
    68 
    90      b label:'check'.
   101      b label:'check'.
    91      b model:model.
   102      b model:model.
    92      b open.
   103      b open.
    93      model inspect.
   104      model inspect.
    94 
   105 
       
   106 
    95   with a model and different changeSelector
   107   with a model and different changeSelector
    96   (using a plug here, for demonstration only):
   108   (using a plug here, for demonstration only):
    97 
   109 
    98      |b model|
   110      |b model|
    99 
   111 
   102 
   114 
   103      b := CheckBox new.
   115      b := CheckBox new.
   104      b label:'check'.
   116      b label:'check'.
   105      b model:model; change:#changeCheck:.
   117      b model:model; change:#changeCheck:.
   106      b open.
   118      b open.
       
   119 
       
   120 
       
   121   with models, one checkBox disabling the others:
       
   122 
       
   123      |dialog translator enableChannel val1 val2 val3 eBox box1 box2 box3|
       
   124 
       
   125      translator := Plug new.
       
   126      translator respondTo:#enableDisable 
       
   127 		with:[enableChannel value
       
   128 			 ifTrue:[box1 enable.
       
   129 				 box2 enable.
       
   130 				 box3 enable.]
       
   131 			 ifFalse:[box1 disable.
       
   132 				  box2 disable.
       
   133 				  box3 disable.]].
       
   134 
       
   135      enableChannel := true asValue.
       
   136      enableChannel onChangeSend:#enableDisable to:translator.
       
   137      val1 := true asValue.
       
   138      val2 := false asValue.
       
   139      val3 := true asValue.
       
   140 
       
   141      dialog := Dialog new.
       
   142      dialog addCheckBox:'enable' on:enableChannel.
       
   143      dialog addVerticalSpace.
       
   144      dialog leftIndent:30.
       
   145      box1 := dialog addCheckBox:'value1' on:val1.
       
   146      dialog addVerticalSpace.
       
   147      box2 := dialog addCheckBox:'value2' on:val2.
       
   148      dialog addVerticalSpace.
       
   149      box3 := dialog addCheckBox:'value3' on:val3.
       
   150      dialog addVerticalSpace.
       
   151      dialog addOkButton.
       
   152 
       
   153      dialog open.
       
   154 
   107 
   155 
   108   multiple checkBoxes on a single model (using different aspects)
   156   multiple checkBoxes on a single model (using different aspects)
   109 
   157 
   110      |top panel b model value1 value2 ok|
   158      |top panel b model value1 value2 ok|
   111 
   159 
   156  hereby transferred.
   204  hereby transferred.
   157 "
   205 "
   158 
   206 
   159 ! !
   207 ! !
   160 
   208 
       
   209 !CheckBox methodsFor:'accessing-mvc'!
       
   210 
       
   211 changeMessage:aChangeSelector
       
   212     "forward to toggle"
       
   213 
       
   214     toggleView changeMessage:aChangeSelector
       
   215 !
       
   216 
       
   217 aspect:aspectSymbol
       
   218     "forward to label & toggle"
       
   219 
       
   220     labelView aspect:aspectSymbol.
       
   221     toggleView aspect:aspectSymbol
       
   222 !
       
   223 
       
   224 model:aModel
       
   225     "forward to label & toggle"
       
   226 
       
   227     labelView model:aModel.
       
   228     toggleView model:aModel
       
   229 ! !
       
   230 
       
   231 !CheckBox methodsFor:'accessing-behavior'!
       
   232 
       
   233 action:aBlock
       
   234     "forward to toggle"
       
   235 
       
   236     toggleView action:aBlock
       
   237 !
       
   238 
       
   239 enable
       
   240     "forward to toggle & change labels color"
       
   241 
       
   242     toggleView enable.
       
   243     labelView foregroundColor:(toggleView foregroundColor).
       
   244 !
       
   245 
       
   246 disable
       
   247     "forward to toggle & change labels color"
       
   248 
       
   249     toggleView disable.
       
   250     labelView foregroundColor:(toggleView disabledForegroundColor).
       
   251 !
       
   252 
       
   253 turnOff
       
   254     "forward to toggle"
       
   255 
       
   256     toggleView turnOff
       
   257 !
       
   258 
       
   259 turnOn
       
   260     "forward to toggle"
       
   261 
       
   262     toggleView turnOn
       
   263 ! !
       
   264 
   161 !CheckBox methodsFor:'accessing'!
   265 !CheckBox methodsFor:'accessing'!
   162 
   266 
       
   267 labelView
       
   268     "return the labelView; allows manipulation of the
       
   269      labels attributes (colors etc.)"
       
   270 
       
   271     ^ labelView
       
   272 !
       
   273 
       
   274 toggleView
       
   275     "return the toggleView; allows manipulation of the
       
   276      toggles attributes (colors etc.)"
       
   277 
       
   278     ^ toggleView
       
   279 ! !
       
   280 
       
   281 !CheckBox methodsFor:'accessing-look'!
       
   282 
   163 label:aString
   283 label:aString
       
   284     "forward to label & resize"
       
   285 
   164     labelView label:aString.
   286     labelView label:aString.
   165     labelView forceResize.
   287     labelView forceResize.
   166     mustRearrange := true.
   288     mustRearrange := true.
   167 !
   289 !
   168 
   290 
   169 font:aFont
   291 font:aFont
       
   292     "forward to label & resize"
       
   293 
   170     labelView font:aFont.
   294     labelView font:aFont.
   171     labelView forceResize.
   295     labelView forceResize.
   172     mustRearrange := true.
   296     mustRearrange := true.
   173 !
   297 !
   174 
   298 
   175 font
   299 font
       
   300     "forward from label"
       
   301 
   176     ^ labelView font
   302     ^ labelView font
   177 !
   303 !
   178 
   304 
   179 change:aChangeSelector
       
   180     toggleView change:aChangeSelector
       
   181 !
       
   182 
       
   183 label
   305 label
       
   306     "forward from label"
       
   307 
   184     ^ labelView label
   308     ^ labelView label
   185 !
   309 ! !
   186 
   310 
   187 model:aModel
   311 !CheckBox methodsFor:'private'!
   188     labelView model:aModel.
       
   189     toggleView model:aModel
       
   190 !
       
   191 
       
   192 labelView
       
   193     "return the labelView; allows manipulation of the
       
   194      labels attributes (colors etc.)"
       
   195 
       
   196     ^ labelView
       
   197 !
       
   198 
       
   199 toggleView
       
   200     "return the toggleView; allows manipulation of the
       
   201      toggles attributes (colors etc.)"
       
   202 
       
   203     ^ toggleView
       
   204 !
       
   205 
       
   206 aspect:aspectSymbol
       
   207     labelView aspect:aspectSymbol.
       
   208     toggleView aspect:aspectSymbol
       
   209 !
       
   210 
       
   211 turnOn
       
   212     toggleView turnOn
       
   213 !
       
   214 
       
   215 action:aBlock
       
   216     toggleView action:aBlock
       
   217 !
       
   218 
       
   219 enable
       
   220     toggleView enable
       
   221 !
       
   222 
       
   223 turnOff
       
   224     toggleView turnOff
       
   225 !
       
   226 
   312 
   227 sendChangeMessageWith:aValue
   313 sendChangeMessageWith:aValue
       
   314     "redefined to have mimic changes being sent from the toggle
       
   315      instead of myself"
       
   316 
   228     toggleView sendChangeMessageWith:aValue
   317     toggleView sendChangeMessageWith:aValue
   229 !
       
   230 
       
   231 disable
       
   232     toggleView disable
       
   233 ! !
   318 ! !
   234 
   319 
   235 !CheckBox methodsFor:'initialization'!
   320 !CheckBox methodsFor:'initialization'!
   236 
   321 
   237 initialize
   322 initialize
   238     |panel|
       
   239 
       
   240     super initialize.
   323     super initialize.
       
   324 
       
   325     borderWidth := 0.
   241 
   326 
   242     hLayout := #fixLeftSpace.
   327     hLayout := #fixLeftSpace.
   243     vLayout := #center.
   328     vLayout := #center.
   244 
   329 
   245     toggleView := CheckToggle in:self.
   330     toggleView := CheckToggle in:self.
   247     labelView := Label in:self.
   332     labelView := Label in:self.
   248     labelView label:'check'.
   333     labelView label:'check'.
   249     labelView forceResize.
   334     labelView forceResize.
   250     labelView adjust:#left.
   335     labelView adjust:#left.
   251     self height:labelView preferedExtent y + ViewSpacing.
   336     self height:labelView preferedExtent y + ViewSpacing.
   252 "/    self delegate:(KeyboardForwarder toView:toggleView).
   337 
   253 
   338     "
   254     self controller:(toggleView controller view:toggleView).
   339      all of my input goes to the toggle
       
   340     "
       
   341     self delegate:(KeyboardForwarder toView:toggleView).
   255 
   342 
   256     "
   343     "
   257      |b|
   344      |b|
   258 
   345 
   259      b := CheckBox new.
   346      b := CheckBox new.
   260      b label:'foo'.
   347      b label:'foo'.
   261      b open
   348      b open
   262     "
   349     "
   263 ! !
   350 ! !
   264