KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jftp > gui > framework > HImage


1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * 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
27 public class HImage
28 {
29     public static synchronized Image getImage(Component c, String JavaDoc name)
30     {
31         Image img = null;
32
33         try
34         {
35             java.net.URL JavaDoc url = ClassLoader.getSystemResource(name);
36
37             if(url == null)
38             {
39                 url = HImage.class.getResource("/" + name);
40             }
41
42             //System.out.println(name + ":" + url);
43
// this is used in case the image not found, and we are packaged as a jar.
44
if(url == null)
45             {
46                 url = HImage.class.getResource("/" + name.replace('\\', '/'));
47             }
48
49             img = (url != null) ? Toolkit.getDefaultToolkit().getImage(url) : null;
50
51             //Image img = Toolkit.getDefaultToolkit().getImage(name);
52
MediaTracker mt = new MediaTracker(c);
53             mt.addImage(img, 1);
54             mt.waitForAll();
55         }
56         catch(Exception JavaDoc ex)
57         {
58             Log.debug("\n\n\nError fetching image!");
59             ex.printStackTrace();
60
61             //System.exit(1);
62
//System.out.println(ex);
63
return img;
64         }
65
66         return img;
67     }
68
69     public static synchronized ImageIcon getImageIcon(String JavaDoc name, String JavaDoc desc)
70     {
71         java.net.URL JavaDoc url = ClassLoader.getSystemResource(name);
72
73         if(url == null)
74         {
75             url = HImage.class.getResource("/" + name);
76         }
77
78         //System.out.println(name + ":" + url);
79
ImageIcon img = (url != null) ? new ImageIcon(url) : null;
80
81         return img;
82     }
83 }
84
Popular Tags