Hi,

My application will by displaying a country flag depending on a locale
selected form list. All the flags are gathered within LocaleFlag
(extends ImageBundle).
I want to be able to get flag image out of LocaleFlag having only a
locale name string in hand.

List selection -> Locale name string (e.g. uk) -> LocaleFlag ->
corresponding com.google.gwt.user.client.ui.Image instance.

So far I came up with a bit brute force spaghetti code solution. I
created LocaleName enumeration with getImage():Image abstract method.
Every enum value implements the method to return corresponding image
instance.
        public enum CountryCode {
                ...
                UK() {

                        @Override
                        public Image getImage() {
                                return 
LocaleFlags.Util.create().flagUnitedKingdom().createImage
();
                        }
                };

                abstract Image getImage();
                ...
        }

With this enum in hand I can call CountyCode.valueOf("UK").getImage()
and this satisfies my requirement. What I don't like is massive amount
of copy-paste code I have to create ( getImage() implementation have
to be developed for every single enum value).

Can you guys come up with a better solution? Ideally that would be
LocaleFlag.getImage("UK") method that could internally discover,
create and return Image instance.

The constraint is we use ImageBundle. I'm aware of the fact the Image
itself could be used instead with an url created on-fly but that's not
an option. You should not concentrate on the subject itself (Locale
and flags) but on the solution (large enumeration code).

Regards,
Marcin.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to