1 19 20 package org.netbeans.api.enode; 21 22 import java.util.*; 23 24 import javax.swing.ImageIcon ; 25 import java.beans.PropertyChangeListener ; 26 27 import org.netbeans.modules.enode.ExtensibleIconsImpl; 28 import org.netbeans.modules.enode.TimedSoftReference; 29 30 36 public abstract class ExtensibleIcons { 37 42 private static Map cache = new HashMap(); 43 44 49 protected ExtensibleIcons() { 50 if (! getClass().equals(ExtensibleIconsImpl.class)) { 51 throw new IllegalStateException ("You cannot create a subclass of this class. Please read the JavaDoc comment"); } 53 } 54 55 60 public abstract int getDefaultSize( ); 61 62 63 72 public abstract ImageIcon getIcon( String name, int size ); 73 74 75 81 public abstract ImageIcon getDefaultIcon( int size ); 82 83 84 92 public abstract ImageIcon getDefaultIcon( ); 93 94 99 public abstract String getDescription( ); 100 101 111 public abstract String getIconDisplayName( String name ); 112 113 114 122 public abstract String [] getAllIconNames( int size ); 123 124 128 public abstract void addPropertyChangeListener(PropertyChangeListener pcl); 129 130 134 public abstract void removePropertyChangeListener(PropertyChangeListener pcl); 135 136 148 public static ExtensibleIcons getInstance(String path, boolean recurse) { 149 String [] paths = null; 150 if (recurse) { 151 paths = ExtensibleNode.computeHierarchicalPaths(path); 152 } else { 153 paths = new String [] { path }; 154 } 155 return getInstance(paths); 156 } 157 158 168 public static ExtensibleIcons getInstance(String [] paths) { 169 Object key = Arrays.asList(paths); 172 173 TimedSoftReference ref = null; 174 synchronized (cache) { 175 ref = (TimedSoftReference)cache.get(key); 176 } 177 ExtensibleIcons instance = null; 178 if (ref != null) { 179 instance = (ExtensibleIcons)ref.get(); 180 } 181 if (instance == null) { 182 instance = new ExtensibleIconsImpl(paths); 183 synchronized (cache) { 184 cache.put(key, new TimedSoftReference(instance, cache, key)); 185 } 186 } 187 return instance; 188 } 189 } 190 | Popular Tags |