ResourceRetriever moved
authorClaus Gittinger <cg@exept.de>
Sun, 30 Aug 1998 14:13:51 +0200
changeset 1058 b2c92c42d129
parent 1057 c3d117379a33
child 1059 8a4afedf7f10
ResourceRetriever moved
Make.proto
ResourceRetriever.st
--- a/Make.proto	Thu Aug 27 13:07:33 1998 +0200
+++ b/Make.proto	Sun Aug 30 14:13:51 1998 +0200
@@ -1,4 +1,4 @@
-# $Header: /cvs/stx/stx/libview2/Make.proto,v 1.57 1998-07-06 10:58:46 cg Exp $
+# $Header: /cvs/stx/stx/libview2/Make.proto,v 1.58 1998-08-30 12:13:49 cg Exp $
 #
 # -------------- no need to change anything below ----------
 
@@ -73,6 +73,7 @@
 	  DropTarget.$(O)               \
 	  DragHandler.$(O)              \
 	  VisualRegion.$(O)		\
+	  ResourceRetriever.$(O)	\
 	  WinBuilder.$(O)               \
 	      UIBuilder.$(O)            \
 	      TIFFRdr.$(O)		\
@@ -175,6 +176,7 @@
 TIFFRdr.$(O): TIFFRdr.st $(STCHDR)
 TargaReader.$(O): TargaReader.st $(INCLUDE)/ImageRdr.H $(STCHDR)
 ToolApplicationModel.$(O): ToolApplicationModel.st $(STCHDR)
+ResourceRetriever.$(O): ResourceRetriever.st $(STCHDR)
 ResourceSpecEditor.$(O): ResourceSpecEditor.st $(STCHDR)
 TriggerVal.$(O): TriggerVal.st $(STCHDR)
 TypeConv.$(O): TypeConv.st $(STCHDR)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ResourceRetriever.st	Sun Aug 30 14:13:51 1998 +0200
@@ -0,0 +1,291 @@
+"
+ 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-Support-UI'
+!
+
+ResourceRetriever class instanceVariableNames:'LabelResources'
+
+"
+ The following class instance variables are inherited by this class:
+
+	Object - 
+"
+!
+
+!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
+"
+    ST80 compatibility class.
+
+    The class is not completed yet and certainly not bug free.
+    Also, it is not guaranteed that all winSpecs are understood.
+
+    Notice: 
+        this class was implemented using protocol information
+        from alpha testers, literature and by reading public domain code
+        - it may not be complete or compatible to
+        the corresponding ST-80 class. 
+        If you encounter any incompatibilities, please forward a note 
+        describing the incompatibility verbal (i.e. no code) to the ST/X team.
+
+    [author:]
+        Claus Atzkern
+
+    [see also:]
+        Application
+        Menu
+        MenuItem
+"
+
+
+
+! !
+
+!ResourceRetriever class methodsFor:'accessing resource'!
+
+findResourceLabel: label in: aResourceOwner
+    "look for a string 
+        in aResourceOwner, 
+        in class of aResourceOwner,
+        in resources of class of aResourceOwner,
+        and finally in my label resources
+    "
+
+    aResourceOwner isNil ifTrue: [^label].
+
+    label isSymbol
+    ifTrue:
+    [
+        (aResourceOwner respondsTo: label)
+        ifTrue:
+        [           
+            ^aResourceOwner perform: label
+        ].
+
+        (aResourceOwner isClass not and: [aResourceOwner class respondsTo: label])
+        ifTrue:
+        [            
+            ^aResourceOwner perform: label
+        ].
+    ].
+
+    ((aResourceOwner isKindOf: ApplicationModel) or: 
+    [aResourceOwner isKindOf: SimpleView]) 
+    ifTrue:
+    [
+        ^aResourceOwner resources string: label
+    ].
+
+    ((aResourceOwner isSubclassOf: ApplicationModel) or: 
+    [aResourceOwner isSubclassOf: SimpleView]) 
+    ifTrue:
+    [
+        ^aResourceOwner resources string: label
+    ].
+
+    ^self labelResources string:label
+  
+!
+
+labelResources
+    "if not already loaded, get the common label resourcePack
+     and return it"
+
+    LabelResources isNil ifTrue:[
+        LabelResources := ResourcePack for:self.
+    ].
+    ^ LabelResources
+! !
+
+!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.
+!
+
+labelText
+    ^ labelText
+!
+
+labelText:aText
+    labelText := aText
+!
+
+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 the value assigned to resource or nil
+    "
+    |resource|
+
+    (resource := self resource) isNil ifTrue:[
+        ^ labelText
+    ].
+
+    (labelText notNil and:[resource isImage]) ifTrue:[
+        ^ LabelAndIcon icon:resource string:labelText
+    ].
+  ^ resource
+
+    "Modified: / 31.10.1997 / 12:10:05 / cg"
+! !
+
+!ResourceRetriever methodsFor:'accessing resource'!
+
+findGuiResourcesIn:aResourceContainer
+    "setup a resource owner
+    "
+    className isNil ifTrue:[
+        resourceOwner := aResourceContainer
+    ].
+!
+
+resource
+    "returns a form assigned to resource or nil
+    "
+    |img cls|
+
+    selector isNil ifTrue:[
+        ^nil
+    ].
+
+    resourceOwner isNil ifTrue:[
+        (resourceOwner := Smalltalk resolveName:className inClass:self class) isNil ifTrue:[
+            ^ nil
+        ]
+    ].
+
+    (resourceOwner respondsTo:#visualFor:) ifTrue:[
+        (img := resourceOwner visualFor:selector) notNil ifTrue:[
+            ^ img
+        ]
+    ].
+
+    (resourceOwner respondsTo:selector) ifTrue:[
+        ^ resourceOwner perform:selector
+    ].
+
+    resourceOwner isClass ifFalse:[
+        cls := resourceOwner class.
+
+        (cls respondsTo:selector) ifTrue:[
+            ^ cls perform:selector
+        ]
+    ].
+    ^ nil
+
+    "Modified: / 31.10.1997 / 12:09:52 / cg"
+! !
+
+!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)
+    "
+    |myClassName|
+
+    myClassName := self class name.
+    labelText isNil ifTrue:[
+        ^ Array with:myClassName with:className with:selector
+    ] ifFalse:[
+        ^ Array with:myClassName with:className with:selector with:labelText
+    ].
+
+    "Modified: / 26.1.1998 / 13:52:43 / cg"
+! !
+
+!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: /cvs/stx/stx/libview2/ResourceRetriever.st,v 1.1 1998-08-30 12:13:51 cg Exp $'
+! !