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