I have a ClientBundle in which I am referencing a bunch of icons as ImageResource's
public interface DefaultCMSResources extends ClientBundle {
String baseImgLoc = "com/jorsek/ui/client/style/images/base/";
String baseIconLoc = "com/jorsek/ui/client/style/images/icons/";
String fugeIconsLoc = baseIconLoc+"fugue/";
/* Icons */
@Source(fugeIconsLoc+"book-open.png")
ImageResource getBookIcon();
}
For a number of reasons I really don't like having to reference the static file location via the @Source annotation.
I really would like to create a custom annotation like @FugueIcon, which would generate the static path dynamically somewhere. IE:
public interface DefaultCMSResources extends ClientBundle {
/* Icons */
@FugueIcon("book-open")
ImageResource getBookIcon();
}
I was looking through the code for the @Source annotation and nothing popped out at me. I was hoping someone could provide the steps I might take to accomplish this.
Thanks!
The problem with this is that if the file is selected dynamically, the compiler won't know ahead of time what the image will be - it won't know the size, so it can't write proper css for it (if using
@spritein your CssResource) or provide results for the variousImageResourcemethods. The@Sourceannotation means that the compiler can know all it needs to about the image before the app has turned into JS, so it can write in that JS details about the image it will have.Instead, you might want to look at a way to implement that
ImageResourcemethod directly - one option would be to instantiate acom.google.gwt.resources.client.impl.ImageResourcePrototypeinstance, which implements that interface, and lets you specify details about the image that are needed - a name (mostly optional) the url it can be found at, and the position in that url (if you are spriting) as well as the size to use.