Plug.st
author Claus Gittinger <cg@exept.de>
Sun, 29 Jan 2017 02:26:51 +0100
changeset 3853 5a78ffcf69de
parent 2101 58a78b51f78e
child 3940 d5fb7f7790eb
permissions -rw-r--r--
#FEATURE by cg class: TypeConverter changed: #timeOfClass:withFormat:orDefault:language:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
88
claus
parents: 82
diff changeset
     1
"
claus
parents: 82
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
114
e577a2f332d0 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
     3
	      All Rights Reserved
88
claus
parents: 82
diff changeset
     4
claus
parents: 82
diff changeset
     5
 This software is furnished under a license and may be used
claus
parents: 82
diff changeset
     6
 only in accordance with the terms of that license and with the
claus
parents: 82
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
claus
parents: 82
diff changeset
     8
 be provided or otherwise made available to, or used by, any
claus
parents: 82
diff changeset
     9
 other person.  No title to or ownership of the software is
claus
parents: 82
diff changeset
    10
 hereby transferred.
claus
parents: 82
diff changeset
    11
"
claus
parents: 82
diff changeset
    12
1554
d01ffa42ca7a implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
    13
"{ Package: 'stx:libview2' }"
d01ffa42ca7a implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
    14
55
409211feffa2 *** empty log message ***
claus
parents: 54
diff changeset
    15
Model subclass:#Plug
2100
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
    16
	instanceVariableNames:'simulatedProtocol inheritedClasses'
162
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    17
	classVariableNames:''
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    18
	poolDictionaries:''
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    19
	category:'Kernel-Objects'
54
f8592e95890f Initial revision
claus
parents:
diff changeset
    20
!
f8592e95890f Initial revision
claus
parents:
diff changeset
    21
f8592e95890f Initial revision
claus
parents:
diff changeset
    22
!Plug class methodsFor:'documentation'!
f8592e95890f Initial revision
claus
parents:
diff changeset
    23
88
claus
parents: 82
diff changeset
    24
copyright
claus
parents: 82
diff changeset
    25
"
claus
parents: 82
diff changeset
    26
 COPYRIGHT (c) 1995 by Claus Gittinger
114
e577a2f332d0 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
    27
	      All Rights Reserved
88
claus
parents: 82
diff changeset
    28
claus
parents: 82
diff changeset
    29
 This software is furnished under a license and may be used
claus
parents: 82
diff changeset
    30
 only in accordance with the terms of that license and with the
claus
parents: 82
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
claus
parents: 82
diff changeset
    32
 be provided or otherwise made available to, or used by, any
claus
parents: 82
diff changeset
    33
 other person.  No title to or ownership of the software is
claus
parents: 82
diff changeset
    34
 hereby transferred.
claus
parents: 82
diff changeset
    35
"
claus
parents: 82
diff changeset
    36
!
claus
parents: 82
diff changeset
    37
54
f8592e95890f Initial revision
claus
parents:
diff changeset
    38
documentation
f8592e95890f Initial revision
claus
parents:
diff changeset
    39
"
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    40
    A Plug is an object which simulates a protocol and evaluates
54
f8592e95890f Initial revision
claus
parents:
diff changeset
    41
    a corresponding block when receiving messages.
2100
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
    42
    A plug's interface can be changed dynamically.
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
    43
    A plug can also be told to simulate inheriting messages from other classes,
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
    44
    even multiple inheritance is possible.
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    45
226
c5a265ceddd1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 224
diff changeset
    46
    Its main use is for the demo doIts, to play the role of a model,
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    47
    when no actual modelClass is available for the demonstration.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    48
    However, it can be used wherever some object is needed which responds to
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    49
    some protocol AND you do not want to add a class for it
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    50
    (lightWeight objects).
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    51
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    52
    There is a slight performance penalty - compared to `normal' objects,
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    53
    getting `normal' messages, though.
224
fe3164373601 documentation
Claus Gittinger <cg@exept.de>
parents: 162
diff changeset
    54
fe3164373601 documentation
Claus Gittinger <cg@exept.de>
parents: 162
diff changeset
    55
    [author:]
fe3164373601 documentation
Claus Gittinger <cg@exept.de>
parents: 162
diff changeset
    56
        Claus Gittinger
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    57
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    58
    [see also:]
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    59
        Model
54
f8592e95890f Initial revision
claus
parents:
diff changeset
    60
"
f8592e95890f Initial revision
claus
parents:
diff changeset
    61
!
f8592e95890f Initial revision
claus
parents:
diff changeset
    62
f8592e95890f Initial revision
claus
parents:
diff changeset
    63
examples
f8592e95890f Initial revision
claus
parents:
diff changeset
    64
"
2100
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
    65
  a simple plug:
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    66
                                                                        [exBegin]
2100
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
    67
        |plug|
54
f8592e95890f Initial revision
claus
parents:
diff changeset
    68
2100
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
    69
        plug := Plug new.
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
    70
        plug respondTo:#foo  with:[Transcript showCR:'Plug received foo'].
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
    71
        plug respondTo:#foo: with:[:arg | Transcript showCR:'Plug received foo: ', arg printString].
54
f8592e95890f Initial revision
claus
parents:
diff changeset
    72
2100
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
    73
        plug foo.
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
    74
        plug foo:'some argument'
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    75
                                                                        [exEnd]
162
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    76
2101
58a78b51f78e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2100
diff changeset
    77
360
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    78
  using a plug as a generator (simulates a readStream):
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    79
                                                                        [exBegin]
2100
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
    80
        |generator num|
360
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    81
2100
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
    82
        num := 0.
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
    83
        generator := Plug new.
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
    84
        generator respondTo:#next   with:[num := num + 1. num].
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
    85
        generator respondTo:#atEnd  with:[false].
360
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    86
2100
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
    87
        10 timesRepeat:[
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
    88
            Transcript showCR:(generator next)
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
    89
        ]
360
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    90
                                                                        [exEnd]
162
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    91
2101
58a78b51f78e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2100
diff changeset
    92
58a78b51f78e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2100
diff changeset
    93
  simulating a big collection:
58a78b51f78e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2100
diff changeset
    94
                                                                        [exBegin]
58a78b51f78e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2100
diff changeset
    95
        |virtualList|
58a78b51f78e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2100
diff changeset
    96
58a78b51f78e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2100
diff changeset
    97
        virtualList := Plug new.
58a78b51f78e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2100
diff changeset
    98
        virtualList inheritFrom:SequenceableCollection.
58a78b51f78e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2100
diff changeset
    99
        virtualList respondTo:#size with:[ 1000000 ].
58a78b51f78e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2100
diff changeset
   100
        virtualList respondTo:#at:  with:[:lineNr | 'List line Nr. ' , lineNr printString ].
58a78b51f78e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2100
diff changeset
   101
        virtualList inspect.
58a78b51f78e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2100
diff changeset
   102
                                                                        [exEnd]
58a78b51f78e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2100
diff changeset
   103
58a78b51f78e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2100
diff changeset
   104
162
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
   105
  simulating ``instance variables'':
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
   106
  (actually, this is somewhat expensive - the contexts locals are used for them ...)
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
   107
  be careful with unintended variable sharing (if plugs are created in a loop ..)
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   108
                                                                        [exBegin]
2100
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   109
        |plug1 plug2 local1 local2|
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   110
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   111
        plug1 := Plug new.
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   112
        plug1 respondTo:#get  with:[local1].
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   113
        plug1 respondTo:#set: with:[:arg | local1 := arg].
162
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
   114
2100
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   115
        plug2 := Plug new.
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   116
        plug2 respondTo:#get  with:[local2].
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   117
        plug2 respondTo:#set: with:[:arg | local2 := arg].
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   118
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   119
        Transcript show:'plug1''s value: '; showCR:plug1 get.
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   120
        Transcript show:'plug2''s value: '; showCR:plug2 get.
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   121
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   122
        plug1 set:5.
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   123
        plug2 set:17.
162
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
   124
2100
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   125
        Transcript show:'plug1''s value: '; showCR:plug1 get.
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   126
        Transcript show:'plug2''s value: '; showCR:plug2 get.
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   127
                                                                        [exEnd]
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   128
2101
58a78b51f78e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2100
diff changeset
   129
2100
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   130
  simulating a big list in a ListView 
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   131
  (real applications would read the lines from a database or file):
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   132
                                                                        [exBegin]
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   133
        |virtualList top lv|
162
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
   134
2100
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   135
        virtualList := Plug new.
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   136
        virtualList inheritFrom:SequenceableCollection.
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   137
        virtualList respondTo:#size with:[ 1000000 ].
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   138
        virtualList respondTo:#at:  with:[:lineNr | 'List line Nr. ' , lineNr printString ].
162
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
   139
2100
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   140
        top := StandardSystemView extent:200@200.
162
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
   141
2100
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   142
        lv := ScrollableView for:ListView in:top.
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   143
        lv origin:0.0 @ 0.0 corner:1.0 @ 1.0. 
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   144
        lv list:virtualList expandTabs:false scanForNonStrings:false includesNonStrings:false.
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   145
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   146
        top open.
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   147
                                                                        [exEnd]
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   148
"
f8592e95890f Initial revision
claus
parents:
diff changeset
   149
! !
f8592e95890f Initial revision
claus
parents:
diff changeset
   150
f8592e95890f Initial revision
claus
parents:
diff changeset
   151
!Plug class methodsFor:'instance creation'!
f8592e95890f Initial revision
claus
parents:
diff changeset
   152
f8592e95890f Initial revision
claus
parents:
diff changeset
   153
new
232
b898f5762952 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
   154
    ^ super basicNew privateInitialize
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   155
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   156
    "Modified: 27.4.1996 / 16:16:59 / cg"
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   157
! !
f8592e95890f Initial revision
claus
parents:
diff changeset
   158
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   159
!Plug methodsFor:'initialization'!
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   160
232
b898f5762952 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
   161
privateInitialize
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   162
    "this method is NOT called `#initialize' to allow plugging that
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   163
     selector ..."
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   164
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   165
    simulatedProtocol := IdentityDictionary new.
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   166
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   167
    "Modified: 27.4.1996 / 16:15:45 / cg"
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   168
    "Created: 27.4.1996 / 16:17:07 / cg"
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   169
! !
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   170
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   171
!Plug methodsFor:'message sending'!
f8592e95890f Initial revision
claus
parents:
diff changeset
   172
1760
48478a48da82 *** empty log message ***
martin
parents: 1554
diff changeset
   173
at:key
48478a48da82 *** empty log message ***
martin
parents: 1554
diff changeset
   174
    "catch this one - its so common"
48478a48da82 *** empty log message ***
martin
parents: 1554
diff changeset
   175
48478a48da82 *** empty log message ***
martin
parents: 1554
diff changeset
   176
    ^ self doesNotUnderstand:(Message selector:#at: arguments:(Array with:key))
48478a48da82 *** empty log message ***
martin
parents: 1554
diff changeset
   177
!
48478a48da82 *** empty log message ***
martin
parents: 1554
diff changeset
   178
48478a48da82 *** empty log message ***
martin
parents: 1554
diff changeset
   179
at:key put:value
48478a48da82 *** empty log message ***
martin
parents: 1554
diff changeset
   180
    ^ self doesNotUnderstand:(Message selector:#at:put: arguments:(Array with:key with:value))
48478a48da82 *** empty log message ***
martin
parents: 1554
diff changeset
   181
!
48478a48da82 *** empty log message ***
martin
parents: 1554
diff changeset
   182
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   183
doesNotUnderstand:aMessage
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   184
    "catch unhandled messages by looking in my simulated protocol
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   185
     definition; if there is some block for it, return its value.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   186
     Otherwise, fall into the real doesNotUnderstand error."
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   187
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   188
    |block|
f8592e95890f Initial revision
claus
parents:
diff changeset
   189
2041
fd1527246662 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1982
diff changeset
   190
    block := simulatedProtocol at:(aMessage selector) ifAbsent:[].
2100
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   191
    block notNil ifTrue:[
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   192
        ^ block valueWithArguments:(aMessage arguments)
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   193
    ].
2100
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   194
    inheritedClasses notNil ifTrue:[
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   195
        inheritedClasses do:[:eachClass |
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   196
            |method|
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   197
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   198
            method := eachClass lookupMethodFor:(aMessage selector).
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   199
            method notNil ifTrue:[
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   200
                ^ method valueWithReceiver:self arguments:(aMessage arguments).
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   201
            ].
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   202
        ].
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   203
    ].
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   204
    ^ super doesNotUnderstand:aMessage
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   205
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   206
    "Modified: 27.4.1996 / 16:15:34 / cg"
377
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   207
!
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   208
2101
58a78b51f78e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2100
diff changeset
   209
isSequenceable
58a78b51f78e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2100
diff changeset
   210
    "catch this one - its so common"
58a78b51f78e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2100
diff changeset
   211
58a78b51f78e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2100
diff changeset
   212
    ^ self doesNotUnderstand:(Message selector:#isSequenceable arguments:#())
58a78b51f78e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2100
diff changeset
   213
!
58a78b51f78e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2100
diff changeset
   214
2100
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   215
size
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   216
    "catch this one - its so common"
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   217
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   218
    ^ self doesNotUnderstand:(Message selector:#size arguments:#())
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   219
!
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   220
1317
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   221
update:something with:aParameter from:changedObject
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   222
    "catch unhandled messages by looking in my simulated protocol
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   223
     definition; if there is some block for it, return its value.
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   224
     Otherwise, fall into the real update."
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   225
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   226
    |block|
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   227
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   228
    block := simulatedProtocol at:#'update:with:from:' ifAbsent:[].
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   229
    block isNil ifTrue:[
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   230
        ^ super update:something with:aParameter from:changedObject
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   231
    ].
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   232
    ^ block valueWithArguments:(Array with:something with:aParameter with:changedObject)
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   233
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   234
!
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   235
377
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   236
value
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   237
    "catch this one - its so common"
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   238
1982
61c4a1986224 special case for #value message
Claus Gittinger <cg@exept.de>
parents: 1760
diff changeset
   239
    |block|
377
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   240
1982
61c4a1986224 special case for #value message
Claus Gittinger <cg@exept.de>
parents: 1760
diff changeset
   241
    block := simulatedProtocol at:#value ifAbsent:[].
61c4a1986224 special case for #value message
Claus Gittinger <cg@exept.de>
parents: 1760
diff changeset
   242
    block isNil ifTrue:[
61c4a1986224 special case for #value message
Claus Gittinger <cg@exept.de>
parents: 1760
diff changeset
   243
        ^ self
61c4a1986224 special case for #value message
Claus Gittinger <cg@exept.de>
parents: 1760
diff changeset
   244
    ].
61c4a1986224 special case for #value message
Claus Gittinger <cg@exept.de>
parents: 1760
diff changeset
   245
    ^ block valueWithArguments:#()
377
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   246
!
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   247
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   248
value:arg
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   249
    "catch this one - its so common"
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   250
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   251
    ^ self doesNotUnderstand:(Message selector:#value: argument:arg)
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   252
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   253
    "Created: 21.1.1997 / 15:21:36 / cg"
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   254
! !
f8592e95890f Initial revision
claus
parents:
diff changeset
   255
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   256
!Plug methodsFor:'protocol definition'!
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   257
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   258
forgetAbout:aSelector
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   259
    "tell the receiver to forget about how to respond to the given by selector"
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   260
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   261
    simulatedProtocol removeKey:aSelector ifAbsent:nil
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   262
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   263
    "
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   264
     |p|
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   265
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   266
     p := Plug new.
268
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
   267
     p respondTo:#foo  with:[Transcript showCR:'foo'].
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
   268
     p respondTo:#foo: with:[:arg | Transcript show:'foo:'; showCR:arg].
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   269
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   270
     p foo.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   271
     p foo:'hello'.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   272
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   273
     p forgetAbout:#foo.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   274
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   275
     p foo.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   276
    "
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   277
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   278
    "Modified: 27.4.1996 / 16:14:19 / cg"
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   279
    "Created: 27.4.1996 / 16:19:08 / cg"
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   280
!
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   281
2100
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   282
inheritFrom:aClass
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   283
    "very tricky - change the inheritance.
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   284
     This cannot be done by changing my class directly, because the instance layout
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   285
     must still be correct for Plugs instance variables.
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   286
     Therefore, the inheritance is remembered, and done dynamically in the doesNotUnderstand
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   287
     implementation."
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   288
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   289
    self assert:(aClass instSize == 0).
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   290
    inheritedClasses isNil ifTrue:[
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   291
        inheritedClasses := Array with:aClass
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   292
    ] ifFalse:[
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   293
        inheritedClasses := inheritedClasses copyWith:aClass
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   294
    ].
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   295
!
17cc7c9aa82d plugs can now inherit
Claus Gittinger <cg@exept.de>
parents: 2041
diff changeset
   296
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   297
respondTo:aSelector with:aBlock
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   298
    "tell the receiver to respond to a message given by selector,
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   299
     with evaluating aBlock. The number of arguments as defined by the 
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   300
     selector must match the number of blockArsg expected by the block.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   301
     The value returned from aBlock will be the value returned from the
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   302
     message."
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   303
1554
d01ffa42ca7a implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   304
    (self class includesSelector:aSelector) ifFalse:[
444
4ad5cc26ad6a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   305
        (self class superclass canUnderstand:aSelector) ifTrue:[
377
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   306
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   307
            "/ sorry - this implementation is too quick of a hack.
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   308
            "/ (must be rewritten to inherit from nil, in order 
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   309
            "/  to be able to catch more ...)
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   310
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   311
            self error:'inherited message cannot be redefined: ' , aSelector.
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   312
        ]
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   313
    ].
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   314
    simulatedProtocol at:aSelector put:aBlock
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   315
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   316
    "
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   317
     |p|
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   318
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   319
     p := Plug new.
268
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
   320
     p respondTo:#foo  with:[Transcript showCR:'foo'].
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
   321
     p respondTo:#foo: with:[:arg | Transcript show:'foo:'; showCR:arg].
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   322
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   323
     p foo.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   324
     p foo:'hello'
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   325
    "
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   326
444
4ad5cc26ad6a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   327
    "Modified: 21.2.1997 / 18:35:07 / cg"
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   328
! !
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   329
82
claus
parents: 55
diff changeset
   330
!Plug methodsFor:'queries'!
claus
parents: 55
diff changeset
   331
claus
parents: 55
diff changeset
   332
respondsTo:aSelector
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   333
    "return true, if the receiver responds to a message"
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   334
82
claus
parents: 55
diff changeset
   335
    (simulatedProtocol includesKey:aSelector) ifTrue:[^ true].
claus
parents: 55
diff changeset
   336
    ^ super respondsTo:aSelector
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   337
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   338
    "Modified: 27.4.1996 / 16:14:41 / cg"
82
claus
parents: 55
diff changeset
   339
! !
claus
parents: 55
diff changeset
   340
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   341
!Plug class methodsFor:'documentation'!
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   342
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   343
version
2101
58a78b51f78e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2100
diff changeset
   344
    ^ '$Header: /cvs/stx/stx/libview2/Plug.st,v 1.23 2006-02-14 11:08:47 cg Exp $'
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   345
! !