ResourceRetriever.st
author ca
Mon, 23 Jun 1997 12:53:14 +0200
changeset 174 0e87610c2768
parent 120 d83c307f3bf5
child 198 7d495c01a8a6
permissions -rw-r--r--
pick a view

"
 COPYRIGHT (c) 1997 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"




Object subclass:#ResourceRetriever
	instanceVariableNames:'className resourceOwner selector labelText'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-UIPainter'
!

!ResourceRetriever class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1997 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"



!

documentation
"
        This class is used to retrieve resources for a painted interface of
        some sort. If the className is specified, then the owner of the resource
        is fixed at painting time. If not, then the ApplicationModel which invokes
        the painted interface is assumed to be the owner of the resource.

        When the retriever is sent the message #value, it sends the message #valueFor:
        to the resource owner, to retrive the resource

    [author:]
        Claus Atzkern

    [see also:]
        Application
        Menu
        MenuItem
"



! !

!ResourceRetriever methodsFor:'accessing'!

className
    "return the value of the instance variable 'className' (automatically generated)"

    ^ className!

className:something
    "set the class which provides the resources
    "
    className     := something.
    resourceOwner := nil.
!

selector
    "return the value of the instance variable 'selector' (automatically generated)"

    ^ selector!

selector:something
    "set the value of the instance variable 'selector' (automatically generated)"

    selector := something.
!

value
    "returns value assigned to resource or nil
    "
    |resource|

    (resource := self resource) isNil ifTrue:[
        ^ labelText
    ].

    (labelText notNil and:[resource isImage]) ifTrue:[
        ^ LabelAndIcon icon:resource string:(Text string:labelText emphasis:#bold)
    ].
  ^ resource
! !

!ResourceRetriever methodsFor:'accessing resource'!

findGuiResourcesIn:aResourceContainer
    "setup a resource owner
    "
    className isNil ifTrue:[
        resourceOwner := aResourceContainer
    ].
!

resource
    "returns form assigned to resource or nil
    "
    selector isNil ifTrue:[
        ^nil
    ].

    resourceOwner isNil ifTrue:[
        (    className isNil
          or:[(resourceOwner := Smalltalk at:className ifAbsent:nil) isNil]
        ) ifTrue:[
            ^ nil
        ]
    ].
  ^ resourceOwner visualFor:selector.
! !

!ResourceRetriever methodsFor:'converting'!

fromLiteralArrayEncoding:anArray
    "read my values from an encoding.
    "
    className     := anArray at: 2.
    selector      := anArray at: 3.

    anArray size == 4 ifTrue:[
        labelText := anArray at:4
    ].
    resourceOwner := nil.

!

literalArrayEncoding
    "encode myself as an array, from which a copy of the receiver can be
     reconstructed with #decodeAsLiteralArray.

     The encoding is: 
        (#ResourceRetriever className selector)

     or if labelText not nil:
        (#ResourceRetriever className selector labelText)
    "
    labelText isNil ifTrue:[
        ^ Array with:(self class name) with:className with:selector
    ] ifFalse:[
        ^ Array with:(self class name) with:className with:selector with:labelText
    ].

! !

!ResourceRetriever methodsFor:'testing'!

isDefined
    "returns true if resource exists
    "
    selector notNil ifTrue:[
        ^ (resourceOwner notNil or:[className notNil])
    ].
  ^ false
!

notDefined
    "returns false if resource is not defined
    "
    self isDefined ifTrue:[^ false ]
                  ifFalse:[^ true  ]
! !

!ResourceRetriever class methodsFor:'documentation'!

version
    ^ '$Header$'
! !