pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Edvin Syse <ed...@sysedata.no>
Subject Best practises
Date Fri, 06 May 2011 13:18:42 GMT
I just implemented my first TreeView, and reused the images from the 
wtk-terra theme. To set the images in my nodes, I did:

TreeBranch branch = new TreeBranch(Gfx.folder(), "title");

To load the actual Icon i created a helper class with a generic image 
loader method that checks the cache or constructs from url and puts in 
cache if it wasn't there. Since folder is an icon I think I'll use a 
lot, I even added a spesific method to retrieve it, that calls the 
generic method.

Is this a good practise or should I do any of this differently? Just 
trying to get a feel for "The pivot way" of doing things :)

-- Edvin

public class Gfx {
     public static Image getImage(String name) {
         URL url = Gfx.class.getResource(name);
         Object cached = ApplicationContext.getResourceCache().get(url);

         if (cached != null)
             return (Image) cached;

         try {
             Image image = Image.load(url);
             ApplicationContext.getResourceCache().put(url, image);
             return image;
         } catch (TaskExecutionException e) {
             return null;

     public static Image folder() {
         return getImage("/org/apache/pivot/wtk/skin/terra/folder.png");

     public static Image page_white() {
         return getImage("/org/apache/pivot/wtk/skin/terra/page_white.png");

View raw message