AspectAdaptor.st
branchjv
changeset 4471 df7515191c90
parent 3614 3272e655d847
equal deleted inserted replaced
4470:7f3f95ba596d 4471:df7515191c90
     1 "
     1 "
     2  COPYRIGHT (c) 1995 by Claus Gittinger
     2  COPYRIGHT (c) 1995 by Claus Gittinger
       
     3  COPYRIGHT (c) 2022 LabWare
     3 	      All Rights Reserved
     4 	      All Rights Reserved
     4 
     5 
     5  This software is furnished under a license and may be used
     6  This software is furnished under a license and may be used
     6  only in accordance with the terms of that license and with the
     7  only in accordance with the terms of that license and with the
     7  inclusion of the above copyright notice.   This software may not
     8  inclusion of the above copyright notice.   This software may not
    23 !AspectAdaptor class methodsFor:'documentation'!
    24 !AspectAdaptor class methodsFor:'documentation'!
    24 
    25 
    25 copyright
    26 copyright
    26 "
    27 "
    27  COPYRIGHT (c) 1995 by Claus Gittinger
    28  COPYRIGHT (c) 1995 by Claus Gittinger
       
    29  COPYRIGHT (c) 2022 LabWare
    28 	      All Rights Reserved
    30 	      All Rights Reserved
    29 
    31 
    30  This software is furnished under a license and may be used
    32  This software is furnished under a license and may be used
    31  only in accordance with the terms of that license and with the
    33  only in accordance with the terms of that license and with the
    32  inclusion of the above copyright notice.   This software may not
    34  inclusion of the above copyright notice.   This software may not
    67 "
    69 "
    68 !
    70 !
    69 
    71 
    70 examples
    72 examples
    71 "
    73 "
    72     a dialog on a points x/y coordinates:
    74     a dialog on a point's x/y coordinates:
    73                                                                         [exBegin]
    75                                                                         [exBegin]
    74         |dialog data f|
    76         |dialog data f|
    75 
    77 
    76         data := 0@0.
    78         data := 0@0.
    77 
    79 
   139         dialog open.
   141         dialog open.
   140         dialog accepted ifTrue:[
   142         dialog accepted ifTrue:[
   141             Transcript showCR:'data now: ' , data printString
   143             Transcript showCR:'data now: ' , data printString
   142         ]
   144         ]
   143                                                                         [exEnd]
   145                                                                         [exEnd]
       
   146 
       
   147     a dialog on elements of a dictionary:
       
   148     (notice: the dicationary elements change as soon as a field of the dialog is
       
   149      left - i.e. I write immediately to the model)
       
   150                                                                         [exBegin]
       
   151         |dialog data|
       
   152 
       
   153         data := JSONObject new
       
   154                     at:'Name' put:'Fritz';
       
   155                     at:'Tel' put:'1234567';
       
   156                     at:'City' put:'Stuttgart';
       
   157                     yourself.
       
   158 
       
   159         dialog := DialogBox new.
       
   160         dialog addTextLabel:'Name:'.
       
   161         dialog addInputFieldOn:(AspectAdaptor new
       
   162                                         subject:data; 
       
   163                                         accessWith:#Name
       
   164                                         assignWith:#Name:). 
       
   165         dialog addTextLabel:'Tel:'.
       
   166         dialog addInputFieldOn:(AspectAdaptor new
       
   167                                         subject:data; 
       
   168                                         forAspect:#Tel).
       
   169         dialog addTextLabel:'City:'.
       
   170         dialog addInputFieldOn:(AspectAdaptor new
       
   171                                         subject:data; 
       
   172                                         forAspect:#City).
       
   173         dialog addOkButton.
       
   174         data inspect.
       
   175         dialog open.
       
   176         dialog accepted ifTrue:[
       
   177             Transcript showCR:'data now: ' , data printString
       
   178         ]
       
   179                                                                         [exEnd]
   144 "
   180 "
   145 ! !
   181 ! !
   146 
   182 
   147 !AspectAdaptor class methodsFor:'instance creation'!
   183 !AspectAdaptor class methodsFor:'instance creation'!
   148 
   184 
   149 accessWith:getSelector assignWith:putSelector 
   185 accessWith:getSelector assignWith:putSelector 
   150     "create and return an adaptor which uses getSelector to fetch a value
   186     "create and return an adaptor which uses getSelector to fetch a value
   151      and setSelector to change it."
   187      from the subject and setSelector to change it.
       
   188      The returned object can be used in place of a ValueHolder"
   152 
   189 
   153     ^ (self new) accessWith:getSelector assignWith:putSelector
   190     ^ (self new) accessWith:getSelector assignWith:putSelector
       
   191 
       
   192     "Modified (comment): / 25-07-2022 / 08:21:28 / cg"
   154 !
   193 !
   155 
   194 
   156 forAspect:anAspect
   195 forAspect:anAspect
   157     "create and return a new adaptor, which forwards requests
   196     "create and return a new adaptor, which forwards requests
       
   197      to the subject, using anAspect as get-selector and anAspect-colon as putSelector
       
   198      for access. 
       
   199      The returned object can be used in place of a ValueHolder"
       
   200 
       
   201     ^ self new forAspect:anAspect
       
   202 
       
   203     "Modified: / 22-01-1997 / 12:00:42 / cg"
       
   204     "Modified (comment): / 25-07-2022 / 08:20:55 / cg"
       
   205 !
       
   206 
       
   207 forAspect:anAspect subject:anObject
       
   208     "create and return a new adaptor, which forwards requests
   158      to anObject, using anAspect as get-selector and anAspect-colon as putSelector
   209      to anObject, using anAspect as get-selector and anAspect-colon as putSelector
   159      for access. The returned object can be used in place of a ValueHolder"
   210      for access. 
   160 
   211      The returned object can be used in place of a ValueHolder"
   161     ^ self new forAspect:anAspect
   212 
   162 
   213     ^ (self new forAspect:anAspect) subject:anObject
   163     "Modified: 22.1.1997 / 12:00:42 / cg"
   214 
       
   215     "Created: / 25-07-2022 / 08:20:17 / cg"
       
   216 !
       
   217 
       
   218 forAspect:anAspect subjectChannel:aSubjectProvider
       
   219     "create and return a new adaptor, which forwards requests
       
   220      to the object provided by aSubjectProvider,
       
   221      accessing the subject via #value from aSubjectProvider.
       
   222      using anAspect as get-selector and anAspect-colon as putSelector for access. 
       
   223      The returned object can be used in place of a ValueHolder"
       
   224 
       
   225     ^ (self new forAspect:anAspect) subjectChannel:aSubjectProvider
       
   226 
       
   227     "Created: / 25-07-2022 / 08:22:33 / cg"
   164 !
   228 !
   165 
   229 
   166 subject:anObject sendsUpdates:aBoolean accessWith:getSel assignWith:putSel aspect:aspect
   230 subject:anObject sendsUpdates:aBoolean accessWith:getSel assignWith:putSel aspect:aspect
   167     "create and return a new adaptor, which forwards requests
   231     "create and return a new adaptor, which forwards requests
   168      to anObject, using getSel/putSel for access.
   232      to anObject, using getSel/putSel for access.
   196 
   260 
   197     "Modified: 22.1.1997 / 18:28:51 / cg"
   261     "Modified: 22.1.1997 / 18:28:51 / cg"
   198 !
   262 !
   199 
   263 
   200 aspect:aSelector
   264 aspect:aSelector
   201     "set the adapters change aspect - this is the aspect of the update message,
   265     "set the adaptor's change aspect - this is the aspect of the update message,
   202      on which the adaptor reacts"
   266      on which the adaptor reacts"
   203 
   267 
   204     myAspect := aSelector.
   268     myAspect := aSelector.
       
   269 
       
   270     "Modified (comment): / 25-07-2022 / 08:19:45 / cg"
   205 !
   271 !
   206 
   272 
   207 forAspect
   273 forAspect
   208     "get the adapters aspect - if none was defined, the getMsg is returned"
   274     "get the adaptor's aspect - if none was defined, the getMsg is returned"
   209 
   275 
   210     myAspect isNil ifTrue:[
   276     myAspect isNil ifTrue:[
   211         ^ getMsg
   277         ^ getMsg
   212     ].
   278     ].
   213     ^ myAspect
   279     ^ myAspect
   214 
   280 
   215     "Modified: 22.1.1997 / 18:27:24 / cg"
   281     "Modified: / 22-01-1997 / 18:27:24 / cg"
       
   282     "Modified (comment): / 25-07-2022 / 08:19:53 / cg"
   216 !
   283 !
   217 
   284 
   218 forAspect:aSelector
   285 forAspect:aSelector
   219     "set the adapters aspect - this sets both the get- and put-Messages
   286     "set the adaptor's aspect - this sets both the get- and put-Messages
   220      (the putMessage is the aspect with a colon)"
   287      (the putMessage is the aspect with a colon)"
   221 
   288 
   222     getMsg := myAspect := aSelector.
   289     getMsg := myAspect := aSelector.
   223     putMsg := aSelector asMutator.
   290     putMsg := aSelector asMutator.
   224 
   291 
   225     "Modified: 22.1.1997 / 18:29:05 / cg"
   292     "Modified: / 22-01-1997 / 18:29:05 / cg"
       
   293     "Modified (comment): / 25-07-2022 / 08:19:49 / cg"
   226 ! !
   294 ! !
   227 
   295 
   228 !AspectAdaptor methodsFor:'accessing-value'!
   296 !AspectAdaptor methodsFor:'accessing-value'!
   229 
   297 
   230 defaultValueIfNoSubject
   298 defaultValueIfNoSubject
   296     or:[changedObject == subjectChannel]) ifTrue:[
   364     or:[changedObject == subjectChannel]) ifTrue:[
   297         self changed:#value
   365         self changed:#value
   298     ].
   366     ].
   299 ! !
   367 ! !
   300 
   368 
       
   369 !AspectAdaptor methodsFor:'printing'!
       
   370 
       
   371 displayOn:aStreamOrGC
       
   372     aStreamOrGC isStream ifFalse:[
       
   373         ^ super displayOn:aStreamOrGC
       
   374     ].
       
   375     aStreamOrGC nextPutAll:(self class name); nextPutAll:'('.
       
   376     aStreamOrGC store:getMsg.
       
   377     aStreamOrGC nextPutAll:' to '.
       
   378     (subject ? subjectChannel) displayOn:aStreamOrGC.
       
   379     aStreamOrGC nextPutAll:')'.
       
   380 
       
   381     "Created: / 10-03-2022 / 08:25:24 / exept MBP"
       
   382 ! !
       
   383 
   301 !AspectAdaptor class methodsFor:'documentation'!
   384 !AspectAdaptor class methodsFor:'documentation'!
   302 
   385 
   303 version
   386 version
   304     ^ '$Header$'
   387     ^ '$Header$'
   305 ! !
   388 !
   306 
   389 
       
   390 version_HG
       
   391 
       
   392     ^ '$Changeset: <not expanded> $'
       
   393 ! !
       
   394