ResourceRetriever.st
author Claus Gittinger <cg@exept.de>
Thu, 04 Sep 1997 23:20:49 +0200
changeset 309 c59bbc7a0a85
parent 226 07e81ce2d32f
child 320 5915a3370a59
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
120
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
     1
"
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
     2
 COPYRIGHT (c) 1997 by eXept Software AG
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
     3
              All Rights Reserved
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
     4
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
     5
 This software is furnished under a license and may be used
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    10
 hereby transferred.
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    11
"
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    12
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    13
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    14
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    15
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    16
Object subclass:#ResourceRetriever
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    17
	instanceVariableNames:'className resourceOwner selector labelText'
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    18
	classVariableNames:''
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    19
	poolDictionaries:''
200
bae1541cda28 generate help specs moved to UIHelpTool
ca
parents: 198
diff changeset
    20
	category:'Interface-Support-UI'
120
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    21
!
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    22
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    23
!ResourceRetriever class methodsFor:'documentation'!
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    24
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    25
copyright
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    26
"
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    27
 COPYRIGHT (c) 1997 by eXept Software AG
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    28
              All Rights Reserved
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    29
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    30
 This software is furnished under a license and may be used
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    35
 hereby transferred.
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    36
"
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    37
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    38
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    39
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    40
!
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    41
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    42
documentation
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    43
"
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    44
        This class is used to retrieve resources for a painted interface of
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    45
        some sort. If the className is specified, then the owner of the resource
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    46
        is fixed at painting time. If not, then the ApplicationModel which invokes
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    47
        the painted interface is assumed to be the owner of the resource.
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    48
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    49
        When the retriever is sent the message #value, it sends the message #valueFor:
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    50
        to the resource owner, to retrive the resource
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    51
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    52
    [author:]
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    53
        Claus Atzkern
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    54
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    55
    [see also:]
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    56
        Application
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    57
        Menu
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    58
        MenuItem
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    59
"
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    60
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    61
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    62
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    63
! !
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    64
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    65
!ResourceRetriever methodsFor:'accessing'!
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    66
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    67
className
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    68
    "return the value of the instance variable 'className' (automatically generated)"
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    69
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    70
    ^ className!
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    71
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    72
className:something
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    73
    "set the class which provides the resources
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    74
    "
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    75
    className     := something.
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    76
    resourceOwner := nil.
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    77
!
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    78
198
7d495c01a8a6 access methods for labelText edited
ca
parents: 120
diff changeset
    79
labelText
7d495c01a8a6 access methods for labelText edited
ca
parents: 120
diff changeset
    80
    ^ labelText
7d495c01a8a6 access methods for labelText edited
ca
parents: 120
diff changeset
    81
!
7d495c01a8a6 access methods for labelText edited
ca
parents: 120
diff changeset
    82
7d495c01a8a6 access methods for labelText edited
ca
parents: 120
diff changeset
    83
labelText:aText
7d495c01a8a6 access methods for labelText edited
ca
parents: 120
diff changeset
    84
    labelText := aText
7d495c01a8a6 access methods for labelText edited
ca
parents: 120
diff changeset
    85
!
7d495c01a8a6 access methods for labelText edited
ca
parents: 120
diff changeset
    86
120
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    87
selector
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    88
    "return the value of the instance variable 'selector' (automatically generated)"
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    89
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    90
    ^ selector!
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    91
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    92
selector:something
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    93
    "set the value of the instance variable 'selector' (automatically generated)"
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    94
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    95
    selector := something.
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    96
!
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    97
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    98
value
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
    99
    "returns value assigned to resource or nil
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   100
    "
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   101
    |resource|
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   102
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   103
    (resource := self resource) isNil ifTrue:[
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   104
        ^ labelText
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   105
    ].
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   106
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   107
    (labelText notNil and:[resource isImage]) ifTrue:[
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   108
        ^ LabelAndIcon icon:resource string:(Text string:labelText emphasis:#bold)
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   109
    ].
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   110
  ^ resource
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   111
! !
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   112
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   113
!ResourceRetriever methodsFor:'accessing resource'!
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   114
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   115
findGuiResourcesIn:aResourceContainer
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   116
    "setup a resource owner
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   117
    "
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   118
    className isNil ifTrue:[
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   119
        resourceOwner := aResourceContainer
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   120
    ].
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   121
!
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   122
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   123
resource
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   124
    "returns form assigned to resource or nil
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   125
    "
226
07e81ce2d32f accessing a resource
ca
parents: 200
diff changeset
   126
    |img|
07e81ce2d32f accessing a resource
ca
parents: 200
diff changeset
   127
120
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   128
    selector isNil ifTrue:[
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   129
        ^nil
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   130
    ].
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   131
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   132
    resourceOwner isNil ifTrue:[
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   133
        (    className isNil
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   134
          or:[(resourceOwner := Smalltalk at:className ifAbsent:nil) isNil]
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   135
        ) ifTrue:[
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   136
            ^ nil
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   137
        ]
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   138
    ].
226
07e81ce2d32f accessing a resource
ca
parents: 200
diff changeset
   139
    (resourceOwner respondsTo:#visualFor:) ifTrue:[
07e81ce2d32f accessing a resource
ca
parents: 200
diff changeset
   140
        (img := resourceOwner visualFor:selector) notNil ifTrue:[
07e81ce2d32f accessing a resource
ca
parents: 200
diff changeset
   141
            ^ img
07e81ce2d32f accessing a resource
ca
parents: 200
diff changeset
   142
        ]
07e81ce2d32f accessing a resource
ca
parents: 200
diff changeset
   143
    ].
07e81ce2d32f accessing a resource
ca
parents: 200
diff changeset
   144
  ^ resourceOwner perform:selector.
120
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   145
! !
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   146
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   147
!ResourceRetriever methodsFor:'converting'!
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   148
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   149
fromLiteralArrayEncoding:anArray
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   150
    "read my values from an encoding.
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   151
    "
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   152
    className     := anArray at: 2.
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   153
    selector      := anArray at: 3.
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   154
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   155
    anArray size == 4 ifTrue:[
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   156
        labelText := anArray at:4
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   157
    ].
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   158
    resourceOwner := nil.
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   159
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   160
!
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   161
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   162
literalArrayEncoding
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   163
    "encode myself as an array, from which a copy of the receiver can be
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   164
     reconstructed with #decodeAsLiteralArray.
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   165
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   166
     The encoding is: 
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   167
        (#ResourceRetriever className selector)
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   168
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   169
     or if labelText not nil:
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   170
        (#ResourceRetriever className selector labelText)
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   171
    "
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   172
    labelText isNil ifTrue:[
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   173
        ^ Array with:(self class name) with:className with:selector
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   174
    ] ifFalse:[
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   175
        ^ Array with:(self class name) with:className with:selector with:labelText
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   176
    ].
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   177
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   178
! !
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   179
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   180
!ResourceRetriever methodsFor:'testing'!
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   181
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   182
isDefined
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   183
    "returns true if resource exists
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   184
    "
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   185
    selector notNil ifTrue:[
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   186
        ^ (resourceOwner notNil or:[className notNil])
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   187
    ].
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   188
  ^ false
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   189
!
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   190
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   191
notDefined
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   192
    "returns false if resource is not defined
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   193
    "
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   194
    self isDefined ifTrue:[^ false ]
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   195
                  ifFalse:[^ true  ]
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   196
! !
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   197
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   198
!ResourceRetriever class methodsFor:'documentation'!
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   199
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   200
version
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   201
    ^ '$Header$'
d83c307f3bf5 intitial checkin
ca
parents:
diff changeset
   202
! !