65a66,71 > /********************************************************************* > * > * Basic methods for image/icon retrieval. > * > ********************************************************************/ > 66a73,74 > * Just gets the image pointed to by the URL and doesn't store > * it in cache. 67,70d72 < * Loads all registered images. < * If component is null, the component supplied in the < * constructor will be used. < * @see #registerImage 72,79d187 < public void loadRegisteredImages(Component component) { < if (fRegisteredImages.size() == 0) < return; < < if (component == null) { < component = fComponent; < } < 80,80c188,188 < MediaTracker tracker = new MediaTracker(component); --- > MediaTracker tracker = new MediaTracker(component); 81,81c189,189 < // register images with MediaTracker --- > // register images with MediaTracker 82,82c190,190 < Iterator iter = fRegisteredImages.iterator(); --- > Iterator iter = fRegisteredImages.iterator(); 83,83c191,191 < while (iter.hasNext()) { --- > while (iter.hasNext()) { 84,84c192,192 < URL url = (URL)iter.next(); --- > URL url = (URL)iter.next(); 84a193,193 > if (! fMap.containsKey(url)) { 85,85d192 < if (basicGetImageURL(url) == null) { 86,86c194,194 < tracker.addImage(loadImageURL(url), ID); --- > tracker.addImage(loadImageURL(url), ID); 87,91d194 < } < } < fRegisteredImages.clear(); < < // block until all images are loaded 92a79,79 > return toolkit.createImage((ImageProducer) url.getContent()); 93,93d78 < tracker.waitForAll(); 95,95c203,203 < catch (Exception e) { --- > catch (Exception e) { 96,96c204,204 < // ignore: do nothing --- > // ignore: do nothing 100a87,87 > * Just gets the file but doesn't store it in cache. 100a156,156 > /** 101,101c157,157 < * Registers a URL that is then loaded together with --- > * Registers a URL that is then loaded together with 102,102c158,158 < * the other registered images by loadRegisteredImages. --- > * the other registered images by loadRegisteredImages. 103,103c159,159 < * @see #loadRegisteredImages --- > * @see #loadRegisteredImages 103a160,162 > */ > public void registerImageURL(URL url) { > fRegisteredImages.add(url); 105,106d88 < public void registerImageURL(URL url) { < fRegisteredImages.add(url); 110,110c166,166 < * Registers the URL for the image resource --- > * Registers the URL for the image resource 111,111c167,167 < * @see #registerImageURL --- > * @see #registerImageURL 112a115,119 > * Loads an image file with the given name, caches it, and > * optionally waits for it to finish loading. > */ > public Image loadImage(String fileName, boolean waitForLoad) { > return loadImageURL(getResourceURL(fileName), waitForLoad); 113,114d114 < public void registerImage(String fileName) { < registerImageURL(getResourceURL(fileName)); 115,115c120,120 < } --- > } 115a121,121 > 116,116d120 < 117a123,123 > * Loads an image URL with the given name and caches it 117,117c122,122 < /** --- > /** 118,118d122 < * Loads an image URL with the given name. 119,119c124,124 < */ --- > */ 120a126,130 > return loadImageURL(url, false); > } > > /** > * Loads an image with the given fileName and caches it. 120,120c125,125 < public Image loadImageURL(URL url) { --- > public Image loadImageURL(URL url) { 123a101,101 > 124a103,103 > 124,124c102,102 < Image image = loadImageResourceURL(url); --- > Image image = loadImageUncachedURL(url); 126a106,108 > if (waitForLoad) { > waitForLoadedImage(image); > } 127a110,110 > 132a95,95 > * optionally waits for it to finish loading. 132,132c94,94 < * Loads an image with the given name. --- > * Loads an image URL with the given name, caches it, and 135,135c133,133 < return loadImageURL(getResourceURL(fileName)); --- > return loadImageURL(getResourceURL(fileName), false); 137a76,76 > public Image loadImageUncachedURL(URL url) { 138,138d75 < public Image loadImageResourceURL(URL url) { 139,139c77,77 < Toolkit toolkit = Toolkit.getDefaultToolkit(); --- > Toolkit toolkit = Toolkit.getDefaultToolkit(); 140,141d77 < try { < return toolkit.createImage((ImageProducer) url.getContent()); 143,143c81,81 < catch (Exception ex) { --- > catch (Exception ex) { 144,144c82,82 < return null; --- > return null; 147a89,89 > public Image loadImageUncached(String fileName) { 148,148d88 < public Image loadImageResource(String fileName) { 149,149c90,90 < return loadImageResourceURL(getResourceURL(fileName)); --- > return loadImageUncachedURL(getResourceURL(fileName)); 152a225,225 > /** 153,153c226,226 < * Registers and loads an image. --- > * Registers and loads an image. 154,154c227,227 < * If component is null, the component supplied in the --- > * If component is null, the component supplied in the 155a229,235 > * > * @deprecated use loadImage instead > */ > public Image registerAndLoadImage(Component component, String fileName) { > registerImage(fileName); > loadRegisteredImages(component); > return loadImage(fileName, true); 155,155c228,228 < * constructor will be used. --- > * constructor will be used. 157,160d168 < public Image registerAndLoadImageURL(Component component, URL url) { < registerImageURL(url); < loadRegisteredImages(component); < return getImageURL(url); 161a172,172 > 162a174,174 > * Loads all registered images. 163,163d173 < * Registers and loads an image. 165a177,178 > * @see #registerImage > * @see #registerImageURL 166a180,185 > public void loadRegisteredImages(Component component) { > if (fRegisteredImages.size() == 0) > return; > > if (component == null) { > component = fComponent; 166a169,169 > public void registerImage(String fileName) { 167,167d168 < public Image registerAndLoadImage(Component component, String fileName) { 168,168c170,170 < return registerAndLoadImageURL(component, getResourceURL(fileName)); --- > registerImageURL(getResourceURL(fileName)); 170a136,141 > /** > * Blocks while image loads and returns a completely loaded > * version of image. > */ > public Image waitForLoadedImage(Image image) { > if (image!=null) { 171,173d135 < public Image loadImageURL(URL url, boolean waitForLoad) { < Image image = loadImageURL(url); < if (image!=null && waitForLoad) { 174,174c142,142 < ImageIcon icon = new ImageIcon(image); --- > ImageIcon icon = new ImageIcon(image); 175,175c143,143 < image = icon.getImage(); //this forces the wait to happen --- > // icon.getImage forces the wait to happen 175a144,144 > image = icon.getImage(); 177,177c146,146 < return image; --- > return image; 178a197,197 > fRegisteredImages.clear(); 179a199,201 > // block until all images are loaded > try { > tracker.waitForAll(); 180,180c97,97 < public Image loadImage(String fileName, boolean waitForLoad) { --- > public Image loadImageURL(URL url, boolean waitForLoad) { 181,181d97 < return loadImageURL(getResourceURL(fileName), waitForLoad); 183,192d202 < < /** < * Gets the image with the given URL. If the image can't be < * found it tries it again after registering the image and < * loading all the registered images. < */ < public Image getImageURL(URL url) { < Image image = basicGetImageURL(url); < if (image != null) { < return image; 194,198d205 < registerImageURL(url); < // load registered images and try again < loadRegisteredImages(fComponent); < // try again < return basicGetImageURL(url); 199a207,213 > > /********************************************************************* > * > * Deprecated methods > * > ********************************************************************/ > 203a218,219 > * > * @deprecated use loadImage instead 206,206c222,222 < return getImageURL(getResourceURL(fileName)); --- > return loadImage(fileName, true); 208a148,151 > > /** > * To translate between a resource and a URL > */ 209,209c152,152 < private URL getResourceURL(String resourceName) { --- > private URL getResourceURL(String resourceName) { 210,210c153,153 < return getClass().getResource(resourceName); --- > return getClass().getResource(resourceName); 212a238,244 > /** > * Loads an image but does not put in in the cache. > * > * @deprecated use loadImageUncached instead > */ > public Image loadImageResource(String fileName) { > return loadImageUncached(fileName); 213,217d237 < private Image basicGetImageURL(URL url) { < if (fMap.containsKey(url)) { < return (Image) fMap.get(url); < } < return null; 219a247,247 >