01: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
02: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
03: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
04: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
05: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
06: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
07: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
08: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
09: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
10: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
11: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
12: // POSSIBILITY OF SUCH DAMAGE.
13: //
14: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
15: package com.metaboss.applications.designstudio.icons;
16:
17: import java.awt.Image;
18: import java.awt.Toolkit;
19: import java.net.URL;
20: import java.util.Hashtable;
21:
22: import javax.swing.ImageIcon;
23:
24: /* graphical resources holder */
25:
26: public class IconsHolder {
27: private static Hashtable mIcons = new Hashtable();
28: private static Hashtable mImages = new Hashtable();
29:
30: // load icon
31: public static ImageIcon loadIcon(String pIconName) {
32: // check if there is a cached version first
33: ImageIcon icon = (ImageIcon) mIcons.get(pIconName);
34: if (icon != null)
35: return icon;
36:
37: // get the icon
38: if (pIconName.startsWith("file:")) {
39: icon = new ImageIcon(pIconName.substring(5));
40: } else {
41: //URL url = getClass().getResource(
42: // "/org/gjt/sp/jedit/icons/" + iconName);
43: URL url = IconsHolder.class.getResource(pIconName);
44: if (url == null) {
45: //Log.log(Log.ERROR,GUIUtilities.class,
46: // "Icon not found: " + iconName);
47: return null;
48: }
49:
50: icon = new ImageIcon(url);
51: }
52:
53: mIcons.put(pIconName, icon);
54: return icon;
55: }
56:
57: // load image
58: public static Image loadImage(String pIconName) {
59: // check if there is a cached version first
60: Image icon = (Image) mImages.get(pIconName);
61: if (icon != null)
62: return icon;
63:
64: //URL url = getClass().getResource(
65: // "/org/gjt/sp/jedit/icons/" + iconName);
66: URL url = IconsHolder.class.getResource(pIconName);
67: if (url == null) {
68: //Log.log(Log.ERROR,GUIUtilities.class,
69: // "Icon not found: " + iconName);
70: return null;
71: }
72: icon = Toolkit.getDefaultToolkit().getImage(url);
73: if (icon == null)
74: System.out.println("Loaded null image from "
75: + url.toExternalForm());
76: mImages.put(pIconName, icon);
77:
78: return icon;
79: }
80: }
|