0

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!

Casey Jordan
  • 1,204
  • 1
  • 20
  • 39

1 Answers1

0

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 @sprite in your CssResource) or provide results for the various ImageResource methods. The @Source annotation 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 ImageResource method directly - one option would be to instantiate a com.google.gwt.resources.client.impl.ImageResourcePrototype instance, 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.

Colin Alworth
  • 17,801
  • 2
  • 26
  • 39
  • Well it's not being selected dynamically per-se. It would be doing the same exact thing as @Source, just resolving it from a different relative path. Does that change anything? – Casey Jordan Jul 19 '13 at 14:08