1 package net.suberic.util.gui; 2 import java.awt.Component ; 3 import javax.swing.*; 4 import java.util.*; 5 6 import net.suberic.util.VariableBundle; 7 8 12 public class IconManager { 13 14 VariableBundle mResources = null; 16 17 String mProperty = null; 19 20 String mIconDirectory = null; 22 23 String mIconExtension = null;; 25 26 static HashMap sManagers = new HashMap(); 28 29 static HashMap sImageMap = new HashMap(); 31 32 38 protected IconManager(VariableBundle pResources, String pResourceBase) { 39 mResources = pResources; 40 mProperty = pResources.getProperty(pResourceBase, ""); 41 mIconDirectory = mResources.getProperty(mProperty + ".defaultDirectory", "images"); 42 mIconExtension = mResources.getProperty(mProperty + ".defaultExtension", "images"); 43 } 44 45 49 public static IconManager getIconManager(VariableBundle pResources, String pResourceBase) { 50 IconManager returnValue = (IconManager) sManagers.get(pResourceBase + pResources.getProperty(pResourceBase, "") + System.identityHashCode(pResources)); 51 if (returnValue == null) { 52 synchronized(sManagers) { 53 returnValue = (IconManager) sManagers.get(pResourceBase + pResources.getProperty(pResourceBase, "") + System.identityHashCode(pResources)); 54 if (returnValue == null) { 55 returnValue = new IconManager(pResources, pResourceBase); 56 sManagers.put(pResourceBase + pResources.getProperty(pResourceBase, "") + System.identityHashCode(pResources), returnValue); 57 } 58 } 59 } 60 61 return returnValue; 62 } 63 64 67 public ImageIcon getIcon(String pIconString) { 68 java.net.URL imageURL = this.getClass().getResource(mResources.getProperty(mProperty + ".icon." + pIconString, mIconDirectory + "/" + pIconString + "." + mIconExtension)); 69 if (imageURL != null) { 70 ImageIcon returnValue = (ImageIcon) sImageMap.get(imageURL); 71 if (returnValue == null) { 72 synchronized(sImageMap) { 73 returnValue = (ImageIcon) sImageMap.get(imageURL); 74 if (returnValue == null) { 75 returnValue = new ImageIcon(imageURL); 76 sImageMap.put(imageURL, returnValue); 77 } 78 } 79 } 80 return returnValue; 81 } else { 82 System.err.println("got null for iconString " + pIconString + ", file " + mResources.getProperty(mProperty + ".icon." + pIconString, mIconDirectory + "/" + pIconString + "." + mIconExtension)); 83 return null; 84 } 85 } 86 87 88 } 89 90 | Popular Tags |