01: /*
02: * This program is free software; you can redistribute it and/or
03: * modify it under the terms of the GNU General Public License
04: * as published by the Free Software Foundation; either version 2
05: * of the License, or (at your option) any later version.
06: *
07: * This program is distributed in the hope that it will be useful,
08: * but WITHOUT ANY WARRANTY; without even the implied warranty of
09: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10: * GNU General Public License for more details.
11:
12: * You should have received a copy of the GNU General Public License
13: * along with this program; if not, write to the Free Software
14: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15: */
16: package net.sf.jftp.gui.framework;
17:
18: import net.sf.jftp.system.logging.Log;
19: import net.sf.jftp.util.*;
20:
21: import java.awt.*;
22: import java.awt.image.*;
23:
24: import javax.swing.*;
25:
26: public class HImage {
27: public static synchronized Image getImage(Component c, String name) {
28: Image img = null;
29:
30: try {
31: java.net.URL url = ClassLoader.getSystemResource(name);
32:
33: if (url == null) {
34: url = HImage.class.getResource("/" + name);
35: }
36:
37: //System.out.println(name + ":" + url);
38: // this is used in case the image not found, and we are packaged as a jar.
39: if (url == null) {
40: url = HImage.class.getResource("/"
41: + name.replace('\\', '/'));
42: }
43:
44: img = (url != null) ? Toolkit.getDefaultToolkit().getImage(
45: url) : null;
46:
47: //Image img = Toolkit.getDefaultToolkit().getImage(name);
48: MediaTracker mt = new MediaTracker(c);
49: mt.addImage(img, 1);
50: mt.waitForAll();
51: } catch (Exception ex) {
52: Log.debug("\n\n\nError fetching image!");
53: ex.printStackTrace();
54:
55: //System.exit(1);
56: //System.out.println(ex);
57: return img;
58: }
59:
60: return img;
61: }
62:
63: public static synchronized ImageIcon getImageIcon(String name,
64: String desc) {
65: java.net.URL url = ClassLoader.getSystemResource(name);
66:
67: if (url == null) {
68: url = HImage.class.getResource("/" + name);
69: }
70:
71: //System.out.println(name + ":" + url);
72: ImageIcon img = (url != null) ? new ImageIcon(url) : null;
73:
74: return img;
75: }
76: }
|