Is there any possibility to create ImageResource instance by resource file name (or other string identifier)?

29 views
Skip to first unread message

eugene.bochkov

unread,
Apr 4, 2012, 11:43:20 AM4/4/12
to Google Web Toolkit
Hello guys,

Is there any possibility to create ImageResource instance by resource
file name (or other string identifier)?

As far as I undestand the common way to retrieve an instance of
ImageResource for some image is an appropriate method call like:

public interface MyResources extends ClientBundle {

@Source("foo.png")
ImageResource foo();
}

// Elsewhere in code:
MyResources res = GWT.create(MyResources.class);
Image fooImage = res.foo();

I've faced with a situation where the common approach in not
convinient. For example I need to create virtual keyboard. Obviously
for this purpose I need quite big number of small images. As I
understand it's right case for using ClientBundle mechanism.

And I need to place all this key images on the keyboard panel. Without
ClientBundle I would use something like that:

for (int i = 0; i < keys.length; i++) {
Image img = new Image(appBaseUrl + "/img/"+keys[i] + ".png");
keysPanel.add(img);
}

Unfortunatelly I can't find similar solution with ImageResource.

I will be pleased for any ideas that help to build up similar solution
based on ImageResource

Thanks with advanced.




Joseph Lust

unread,
Apr 9, 2012, 5:00:07 PM4/9/12
to google-we...@googlegroups.com
Is it possible to create the keyboard with some Div's and CSS? Seems that you might not need images at all.

You can make a code generator for this interface if you don't want to just copy/paste and hard code these entries, but that would likely prove complex and difficult to test. I'd suggest CTRL+ALT+DOWN in Eclipse 7 times (2^7) to get the 104+ keys?


Sincerely,
Joseph
Reply all
Reply to author
Forward
0 new messages