Those pesky icons--in an applet this time.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Those pesky icons--in an applet this time.

Keith Alcock
Does anyone out there know how to get icons to show up correctly in an
applet?

My test application works just fine when icons are stored in .\resources
(relative to the image during development time, application directory
when deployed).  Now I'd like to try this thing out as an applet.  That
it works at all is about the slickest thing since sliced bread, but all
those default question mark icons are none too pretty.  Of the examples
at my disposal, only one uses icons: the registry editor.  The version
at http://www.object-arts.com/Plug-in/Samples/RegistryEditor.htm has the
same problem, so it is of little help.

The icons I'm using are in a view and are defined as

    Icon fromFile: 'resources\up.ico'.

Based on the HelloWorldApplet, I think that they had might better be

    Icon fromFile: 'resources\up.ico' usingLocator: self fileLocator.

The self fileLocator is supposed to arrange for the icon file to be read
from the web site.  It doesn't seem to work that way, though.  In case
the slash is a problem on my unix web server, I also tried without the
directory name.  That didn't help either.  Does anyone have a solution?

I think someone else pointed out that Splash.jpg wasn't delivered with
version 4.0 of Dolphin.  Didn't see it in 4.01 either.  Maybe next time.

Thanks for any advice received.

Keith Alcock


Reply | Threaded
Open this post in threaded view
|

Re: Those pesky icons--in an applet this time.

Keith Alcock
Continuing my habit of partially answering my own posts...

Some progress was made today and the application icon does show up now.  The
code for it had previously been PresenterClass class>>icon ^Icon fromFile:
'resources\icon.ico'.  This results in a default file locator being used and
that turns out to be image relative.  So, it did work to put the icons down
in the Internet Explorer folder.  If the method was changed to
PresenterClass>>icon ^Icon fromFile: 'resources\icon.ico' usingLocator: self
fileLocator, then the locator used seemed to be dependent on whether the
presenter was an application or an applet and I get an icon in the web
browser.

However, there is still a problem with the icons used in the views.  I have
a push button with an icon.  The icon is specified at development time and
saved in the pak file, so it will have whatever fileLocator I was using
during development.  That one by necessity reads from the local file system
and does work if I read in the applet from the local system as well.  It
won't work via http, though.  For that I made an ImageBlockPushButton which
takes a block that returns the icon to use so that it can be set at
runtime.  That seems to happen in onFullyCreated.  So, the block was [ :view
| Icon fromFile: 'resources\icon.ico' usingLocator: view fileLocator ].
This seems to match well with HelloWorldApplet.  Of course it didn't work.
If I debugged, the fileLocator continued to be imageRelative.  That could
have been because of the debugging process itself, as it required an image
name, etc.  At one point message propertyAt: #site was sent and #site was
not in the dictionary.

So, the problem is still not solved.  Any help would be greatly
appreciated.  It this is a general problem, I think that it would be good if
all resources that take an icon were also able to take a block returning an
icon so that something like this would work.

Keith Alcock



Keith Alcock wrote:

> Does anyone out there know how to get icons to show up correctly in an
> applet?
>
> My test application works just fine when icons are stored in .\resources
> (relative to the image during development time, application directory
> when deployed).  Now I'd like to try this thing out as an applet.  That
> it works at all is about the slickest thing since sliced bread, but all
> those default question mark icons are none too pretty.  Of the examples
> at my disposal, only one uses icons: the registry editor.  The version
> at http://www.object-arts.com/Plug-in/Samples/RegistryEditor.htm has the
> same problem, so it is of little help.
>
> The icons I'm using are in a view and are defined as
>
>     Icon fromFile: 'resources\up.ico'.
>
> Based on the HelloWorldApplet, I think that they had might better be
>
>     Icon fromFile: 'resources\up.ico' usingLocator: self fileLocator.
>
> The self fileLocator is supposed to arrange for the icon file to be read
> from the web site.  It doesn't seem to work that way, though.  In case
> the slash is a problem on my unix web server, I also tried without the
> directory name.  That didn't help either.  Does anyone have a solution?
>
> I think someone else pointed out that Splash.jpg wasn't delivered with
> version 4.0 of Dolphin.  Didn't see it in 4.01 either.  Maybe next time.
>
> Thanks for any advice received.
>
> Keith Alcock


Reply | Threaded
Open this post in threaded view
|

Re: Those pesky icons--in an applet this time.

Keith Alcock
In reply to this post by Keith Alcock
Still working on it.  Part of the problem is the following class method in
Shell:

show: aResourceNameString inPlugin: appletContext
 "Show a new view instance of the receiver as a subview of the applet
contexts site."

 | applet |
 applet := self create: aResourceNameString.
 applet view propertyAt: #site put: appletContext site.
 ^applet show

Since the resources get created before the site property is set, the
resources cannot use site or fileLocator until after creation.  This makes
it tricky to get the icons configured even using blocks.

Keith Alcock




Keith Alcock wrote:

> Does anyone out there know how to get icons to show up correctly in an
> applet?
>
> My test application works just fine when icons are stored in .\resources
> (relative to the image during development time, application directory
> when deployed).  Now I'd like to try this thing out as an applet.  That
> it works at all is about the slickest thing since sliced bread, but all
> those default question mark icons are none too pretty.  Of the examples
> at my disposal, only one uses icons: the registry editor.  The version
> at http://www.object-arts.com/Plug-in/Samples/RegistryEditor.htm has the
> same problem, so it is of little help.
>
> The icons I'm using are in a view and are defined as
>
>     Icon fromFile: 'resources\up.ico'.
>
> Based on the HelloWorldApplet, I think that they had might better be
>
>     Icon fromFile: 'resources\up.ico' usingLocator: self fileLocator.
>
> The self fileLocator is supposed to arrange for the icon file to be read
> from the web site.  It doesn't seem to work that way, though.  In case
> the slash is a problem on my unix web server, I also tried without the
> directory name.  That didn't help either.  Does anyone have a solution?
>
> I think someone else pointed out that Splash.jpg wasn't delivered with
> version 4.0 of Dolphin.  Didn't see it in 4.01 either.  Maybe next time.
>
> Thanks for any advice received.
>
> Keith Alcock


Reply | Threaded
Open this post in threaded view
|

Re: Those pesky icons--in an applet this time.

Steve Waring-2
Hi Keith,

I think you are very close to a solution.

The way I have solved a similar problem is by creating my own Locator with a
class variable that lazily initializes itself to a FileLocator
imageRelative.

My Applets class method is then;

show: aResourceNameString inPlugin: appletContext
  BinaryPackage loadUsing: (appletContext classLocator copyWithCodeBase
packageName: 'SWAdditionsApplets').
  RelativeLocator setCurrent: appletContext classLocator.
  ^show: aResourceNameString inPlugin: appletContext

The package SWAdditionsApplets contains my RelativeLocator class.

I then just use RelativeLocator current to access a locator that will work
in either my development image or when deployed as an applet.

You need to make sure you are not saving the actual locator into your
resource, but I think I saw that one of your examples is already guarding
against this.

I has been a while since I did this, but I remember thinking that I would
have problems with multiple applet running in the same image.

You can download the code for any of my applets on www.chartexplorer.com,
and they all contain a package with this code.

Good luck!

Steve


"Keith Alcock" <[hidden email]> wrote in message
news:[hidden email]...

> Still working on it.  Part of the problem is the following class method in
> Shell:
>
> show: aResourceNameString inPlugin: appletContext
>  "Show a new view instance of the receiver as a subview of the applet
> contexts site."
>
>  | applet |
>  applet := self create: aResourceNameString.
>  applet view propertyAt: #site put: appletContext site.
>  ^applet show
>
> Since the resources get created before the site property is set, the
> resources cannot use site or fileLocator until after creation.  This makes
> it tricky to get the icons configured even using blocks.
>
> Keith Alcock
>
>
>
>
> Keith Alcock wrote:
>
> > Does anyone out there know how to get icons to show up correctly in an
> > applet?
> >
> > My test application works just fine when icons are stored in .\resources
> > (relative to the image during development time, application directory
> > when deployed).  Now I'd like to try this thing out as an applet.  That
> > it works at all is about the slickest thing since sliced bread, but all
> > those default question mark icons are none too pretty.  Of the examples
> > at my disposal, only one uses icons: the registry editor.  The version
> > at http://www.object-arts.com/Plug-in/Samples/RegistryEditor.htm has the
> > same problem, so it is of little help.
> >
> > The icons I'm using are in a view and are defined as
> >
> >     Icon fromFile: 'resources\up.ico'.
> >
> > Based on the HelloWorldApplet, I think that they had might better be
> >
> >     Icon fromFile: 'resources\up.ico' usingLocator: self fileLocator.
> >
> > The self fileLocator is supposed to arrange for the icon file to be read
> > from the web site.  It doesn't seem to work that way, though.  In case
> > the slash is a problem on my unix web server, I also tried without the
> > directory name.  That didn't help either.  Does anyone have a solution?
> >
> > I think someone else pointed out that Splash.jpg wasn't delivered with
> > version 4.0 of Dolphin.  Didn't see it in 4.01 either.  Maybe next time.
> >
> > Thanks for any advice received.
> >
> > Keith Alcock
>


Reply | Threaded
Open this post in threaded view
|

Re: Those pesky icons--in an applet this time.

Ian Bartholomew
In reply to this post by Keith Alcock
Keith,

I thought I'd better reply so that you can avoid talking to yourself too
much <g>

It's a bit difficult to see exactly what the problem is from your
description. Couldn't you put together a simple package that we could try it
for ourselves and see if we can come up with a workaround/explanation?

Ian


Reply | Threaded
Open this post in threaded view
|

Re: Those pesky icons--in an applet this time.

Keith Alcock
Ian,

Yes, indeed, that would be a good idea and I have attached one.  It is an
application with two push buttons, each with an icon, and there is an
application icon as well.  One push button is normal and the other is an
ImageBlockPushButton that uses a block to return the image.  While I thought
that the application icon was working previously, it doesn't seem to be doing so
now.  I probably had an extra icon floating around in the IE directory that was
being used instead.

It seems to me that any application that uses views with resources that include
icons cannot work as an applet, because the fileLocator is stored in the view
(unless it is very lazily initialized).  Even for cases when the fileLocator is
generated programmatically, the views don't know about #site until after the
resources have been read, which is too late for my ImageBlockPushButton.  (I'll
have to try Steve Waring's method.)

This problem probably affects any program that has a tool bar as well as the
registry editor example.  The documentation and design imply that this should
all work, but something probably very small is missing.

Keith Alcock


<HTML>
 <BODY>
  <H1>Applet Test</H1>
  <EMBED
   TYPE=application/x-dolphin-applet
   SRC="AppletTest.pak"
   APPLET=AppletTestPresenter
   WIDTH=300
   HEIGHT=300
   PLUGINSPAGE=http://www.object-arts.com/Plug-in/GoGetIt.htm
  >
 </BODY>
</HTML>




Ian Bartholomew wrote:

> Keith,
>
> I thought I'd better reply so that you can avoid talking to yourself too
> much <g>
>
> It's a bit difficult to see exactly what the problem is from your
> description. Couldn't you put together a simple package that we could try it
> for ourselves and see if we can come up with a workaround/explanation?
>
> Ian

AppletTest.pac (15K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Those pesky icons--in an applet this time.

Keith Alcock
In reply to this post by Ian Bartholomew
Ian,

These icons would probably help...

Keith


Ian Bartholomew wrote:

>
> Keith,
>
> I thought I'd better reply so that you can avoid talking to yourself too
> much <g>
>
> It's a bit difficult to see exactly what the problem is from your
> description. Couldn't you put together a simple package that we could try it
> for ourselves and see if we can come up with a workaround/explanation?
>
> Ian

icon3.ico (434 bytes) Download Attachment
icon1.ico (434 bytes) Download Attachment
icon2.ico (434 bytes) Download Attachment
icon.ico (434 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Those pesky icons--in an applet this time.

Keith Alcock
In reply to this post by Keith Alcock
If anyone is interested in making their application containing icons and
bitmaps work as an applet as well, the information below might be
useful:

1) Your views cannot contain hard-coded icons and bitmaps because these
will have been assigned a file locator at design time which will not get
the resources from the web site, but rather look on the local computer.
I don't have a solution for a Toolbar or any kinds of trees or lists,
but in the cases of the PushButton and CheckBox, use the
ImageBlockPushButton and ImageBlockCheckBox classes below.  For the
imageBlock property, program something like [ :view | Icon fromFile:
'resources\icon.ico' usingLocator: view fileLocator. ].  The ImageBlock
views have a modified #site method that first checks a top level view
for its site.  That is set in step two.  If would be great if the top
level views propogated the site down to their subviews, but that doesn't
happen.

2) In the presenter for the application, add the following two class
methods:

show: aResourceNameString inPlugin: appletContext
        "Show a new view instance of the receiver as a subview of the applet
contexts site."

        | applet |
        applet := self create: aResourceNameString inPlugin: appletContext.
        applet view propertyAt: #site put: appletContext site.
        ^applet show

create: aResourceNameString inPlugin: appletContext

        | newOne |
        newOne := self new.
        newOne site: appletContext site.
        View desktop propertyAt: #site put: appletContext site.
        newOne view: (self loadViewResource: aResourceNameString inContext:
View desktop).
        ^newOne

The first one is the same as the super version except that it calls
#create:inPlugin: instead of simply #create:.  The second method is new
and lets both the presenter and the desktop view know that things are
running in an applet context.

Also add the following instance methods to the presenter (along with
instance variable site):

site

        ^site notNil ifTrue: [
                site.
        ] ifFalse: [
                super site.
        ].

site: anNPAppletSite

        site := anNPAppletSite.

fileLocator

        ^self site getFileLocator.


This is done so that the fileLocator can be determined by the presenter
instead of the views.  The views do not keep track of the site
properly.  The presenter needs the site information for its own icon:

icon

        ^Icon fromFile: self class iconFile usingLocator: self fileLocator.

3) You have to put the ImageBlockPushButton and ImageBlockCheckBox into
the same package as the presenter; otherwise, the classes will not be
found.  The methods added to the presenter could also be placed higher
up in the class hierarchy, but this would require rebuilding the
plug-in, I believe.

4) Make the pak files and deploy them as usual.  There is an example
applet that runs from the same code as the application at:


http://www.best.com/~alcock/keith/Smalltalk/EquationGame/EquationGame.html

If you don't see any of the icons, please let me know.

5) Maybe trees and lists later.  Debugging these things is extremely
difficult because of all the caching that goes on.  Unless you really
need your application to run in a browser, don't do the conversion just
for the fun of it.


Keith Alcock


"Filed out from Dolphin Smalltalk 2000 release 4.01"!

CheckBox subclass: #ImageBlockCheckBox
        instanceVariableNames: 'imageBlock'
        classVariableNames: ''
        poolDictionaries: ''
        classInstanceVariableNames: ''!
ImageBlockCheckBox comment: ''!

ImageBlockCheckBox guid: (GUID fromString:
'{ACC472F3-9F34-4888-83F4-9AF358EB77FA}')!

!ImageBlockCheckBox categoriesForClass!Unclassified! !
!ImageBlockCheckBox methodsFor!

imageBlock

        ^imageBlock.
!

imageBlock: aBlockOrNil

        | anImageOrNil |
        imageBlock := aBlockOrNil.
        anImageOrNil := aBlockOrNil notNil ifTrue: [
                imageBlock value: self.
        ] ifFalse: [
                nil.
        ].
        ^self image: anImageOrNil.
!

initialize

        super initialize.
        imageBlock := nil.
        ^self.
!

onFullyCreated

        super onFullyCreated.
        self imageBlock: self imageBlock.
!

site

        ^self topView creationParentView propertyAt: #site ifAbsent: [self
parentView].
! !
!ImageBlockCheckBox categoriesFor: #imageBlock!*-unclassified!public! !
!ImageBlockCheckBox categoriesFor: #imageBlock:!*-unclassified!public! !
!ImageBlockCheckBox categoriesFor: #initialize!*-unclassified!public! !
!ImageBlockCheckBox categoriesFor: #onFullyCreated!event
handling!public! !
!ImageBlockCheckBox categoriesFor: #site!*-unclassified!public! !

!ImageBlockCheckBox class methodsFor!

publishedAspectsOfInstances

        ^super publishedAspectsOfInstances
                add: (Aspect block: #imageBlock);
                removeKey: #image;
                yourself.
! !
!ImageBlockCheckBox class categoriesFor:
#publishedAspectsOfInstances!constants!development!public! !


"Filed out from Dolphin Smalltalk 2000 release 4.01"!

PushButton subclass: #ImageBlockPushButton
        instanceVariableNames: 'imageBlock'
        classVariableNames: ''
        poolDictionaries: ''
        classInstanceVariableNames: ''!
ImageBlockPushButton comment: ''!

ImageBlockPushButton guid: (GUID fromString:
'{C55B673B-E6F3-4603-A2F2-2CC50E2A28B8}')!

!ImageBlockPushButton categoriesForClass!Unclassified! !
!ImageBlockPushButton methodsFor!

imageBlock

        ^imageBlock.
!

imageBlock: aBlockOrNil

        | anImageOrNil |
        imageBlock := aBlockOrNil.
        anImageOrNil := aBlockOrNil notNil ifTrue: [
                imageBlock value: self.
        ] ifFalse: [
                nil.
        ].
        ^self image: anImageOrNil.
!

initialize

        super initialize.
        imageBlock := nil.
        ^self.
!

onFullyCreated

        super onFullyCreated.
        self imageBlock: self imageBlock.
!

site

        ^self topView creationParentView propertyAt: #site ifAbsent: [self
parentView].
! !
!ImageBlockPushButton categoriesFor: #imageBlock!*-unclassified!public!
!
!ImageBlockPushButton categoriesFor: #imageBlock:!*-unclassified!public!
!
!ImageBlockPushButton categoriesFor: #initialize!*-unclassified!public!
!
!ImageBlockPushButton categoriesFor: #onFullyCreated!event
handling!public! !
!ImageBlockPushButton categoriesFor: #site!*-unclassified!public! !

!ImageBlockPushButton class methodsFor!

publishedAspectsOfInstances

        ^super publishedAspectsOfInstances
                add: (Aspect block: #imageBlock);
                removeKey: #image;
                yourself.
! !
!ImageBlockPushButton class categoriesFor:
#publishedAspectsOfInstances!constants!development!public! !






Keith Alcock wrote:

>
> Does anyone out there know how to get icons to show up correctly in an
> applet?
>
> My test application works just fine when icons are stored in .\resources
> (relative to the image during development time, application directory
> when deployed).  Now I'd like to try this thing out as an applet.  That
> it works at all is about the slickest thing since sliced bread, but all
> those default question mark icons are none too pretty.  Of the examples
> at my disposal, only one uses icons: the registry editor.  The version
> at http://www.object-arts.com/Plug-in/Samples/RegistryEditor.htm has the
> same problem, so it is of little help.
>
> The icons I'm using are in a view and are defined as
>
>     Icon fromFile: 'resources\up.ico'.
>
> Based on the HelloWorldApplet, I think that they had might better be
>
>     Icon fromFile: 'resources\up.ico' usingLocator: self fileLocator.
>
> The self fileLocator is supposed to arrange for the icon file to be read
> from the web site.  It doesn't seem to work that way, though.  In case
> the slash is a problem on my unix web server, I also tried without the
> directory name.  That didn't help either.  Does anyone have a solution?
>
> I think someone else pointed out that Splash.jpg wasn't delivered with
> version 4.0 of Dolphin.  Didn't see it in 4.01 either.  Maybe next time.
>
> Thanks for any advice received.
>
> Keith Alcock


Reply | Threaded
Open this post in threaded view
|

Re: Those pesky icons--in an applet this time.

Keith Alcock
In reply to this post by Keith Alcock
In case anyone is interested...

I made a few changes to the RegEdit program so that the icons show
up correctly in an applet context.  The new version, RegEditApplet
can be seen and downloaded from

http://www.best.com/~alcock/keith/Smalltalk/RegEditApplet

If someone from OA would like to improve the example program, the
changes are there for the taking.

Keith Alcock



Keith Alcock wrote:

>
> Does anyone out there know how to get icons to show up correctly in an
> applet?
>
> My test application works just fine when icons are stored in .\resources
> (relative to the image during development time, application directory
> when deployed).  Now I'd like to try this thing out as an applet.  That
> it works at all is about the slickest thing since sliced bread, but all
> those default question mark icons are none too pretty.  Of the examples
> at my disposal, only one uses icons: the registry editor.  The version
> at http://www.object-arts.com/Plug-in/Samples/RegistryEditor.htm has the
> same problem, so it is of little help.
>
> The icons I'm using are in a view and are defined as
>
>     Icon fromFile: 'resources\up.ico'.
>
> Based on the HelloWorldApplet, I think that they had might better be
>
>     Icon fromFile: 'resources\up.ico' usingLocator: self fileLocator.
>
> The self fileLocator is supposed to arrange for the icon file to be read
> from the web site.  It doesn't seem to work that way, though.  In case
> the slash is a problem on my unix web server, I also tried without the
> directory name.  That didn't help either.  Does anyone have a solution?
>
> I think someone else pointed out that Splash.jpg wasn't delivered with
> version 4.0 of Dolphin.  Didn't see it in 4.01 either.  Maybe next time.
>
> Thanks for any advice received.
>
> Keith Alcock