Icon.st
author Claus Gittinger <cg@exept.de>
Fri, 10 Jan 1997 16:10:28 +0100
changeset 356 0f90fb1e9db9
parent 269 6c70d392634b
child 358 6b9671f01908
permissions -rw-r--r--
new infoMessage scheme

"
 COPYRIGHT (c) 1995 by Claus Gittinger
	      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:#Icon
	instanceVariableNames:'image mask'
	classVariableNames:'KnownIcons'
	poolDictionaries:''
	category:'Graphics-Images'
!

!Icon class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1995 by Claus Gittinger
	      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
"
    The Icon class keeps track of already loaded Images and caches
    them for later reuse.
    Icons are accessed by a symbolic name, so there is no need to
    remember their names (they must have been registered under that name
    before - of course).

    Icon was mostly added for ST-80 Compatibility:

    Images are returned via the #constantNamed: message which is used by 
    some ST-80 PD classes and returns corresponding ST/X icons.
    Notice, that ST/X does not provide Icon instances - Icon only consists
    of class mimicri protocol, to make your life easier.

    If you like the original ST-80 icons, install the image files in the `bitmap'
    directory under a name foo.xbm, where `foo' corresponds to the icons
    name symbol 
    (i.e. for the `Icon constantNamed:#foo', a 'foo.xbm' file is required).

    You can grab those icons from manchester or from the PrimeTime Freeware 
    (PTF) CD. A copy of those bitmaps (from the PTF-CD) is found in 
    'goodies/bitmaps/st80bitmaps'.

    CAVEAT:
        masks are not yet implemented

    [See also:]
        Image Form ImageReader

    [author:]
        Claus Gittinger
"
! !

!Icon class methodsFor:'initialization'!

initialize
    KnownIcons isNil ifTrue:[
        KnownIcons := Dictionary new
    ]

    "
     Icon initialize
    "

    "Modified: 20.5.1996 / 09:24:10 / cg"
!

replacementNameFor:aName
    "return a replacement ST/X name for an ST80 icon name."

    self replacementNames do:[:aPair |
	(aPair at:1) == aName ifTrue:[^ aPair at:2].
    ].
    ^ nil
!

replacementNames
    "return an ST-80 constant name to ST/X file name translation.
     This was added for ST-80 compatibility, to support code which uses
     things like 'Icon constantNamed:#categoryBrowser'."

    ^ #( 
        #(file             FBrowser)
        #(debugger         Debugger)
        #(systembrowser    SBrowser)
        #(classbrowser     SBrowser)
        #(categoryBrowser  SBrowser)
        #(hierarchyBrowser SBrowser)
        #(methodBrowser    SBrowser)
        #(launcher         SmalltalkX)
        #(workspace        SmalltalkX)
        #(transcript       SmalltalkX)
        #(inspector        Inspector)
        #(default          SmalltalkX)
       )

    "
     Icon constantNamed:#categoryBrowser
     Icon constantNamed:#default
    "

    "Modified: 13.5.1996 / 10:29:43 / cg"
! !

!Icon class methodsFor:'accessing'!

constantNamed:aName
    "return the image registered under aName."

    |icon nm|

    icon := KnownIcons at:aName ifAbsent:[].
    icon isNil ifTrue:[
        nm := self replacementNameFor:aName.
        nm notNil ifTrue:[
            icon := Image fromFile:('bitmaps/' , nm).
            icon isNil ifTrue:[
                icon := Image fromFile:('bitmaps/' , nm , '.xbm').
            ]
        ].
        icon isNil ifTrue:[
            icon := Image fromFile:('bitmaps/' , aName).
            icon isNil ifTrue:[
                icon := Image fromFile:('bitmaps/' , aName , '.xbm').
            ].
            icon isNil ifTrue:[
                ('Icon [info]: no icon named ' , aName) infoPrintNL.
                ^ nil
            ].
            icon := icon on:Screen default.
        ].
        KnownIcons at:aName put:icon.
    ].
    ^ icon

    "
     Icon constantNamed:#file     
     Icon constantNamed:#debugger     
     Icon constantNamed:#systembrowser     
     Icon constantNamed:#SBrowser     
     Icon constantNamed:#SBrowser     
    "

    "Modified: 10.1.1997 / 15:45:44 / cg"
!

constantNamed:aName put:anImage
    "register anImage under aName."

    KnownIcons at:aName put:anImage

    "Modified: 23.4.1996 / 11:40:51 / cg"
! !

!Icon class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libview2/Icon.st,v 1.13 1997-01-10 15:10:28 cg Exp $'
! !
Icon initialize!