1 /**
2 * This is a simple mechanism to bind Inkscape to Java, and thence
3 * to all of the nice things that can be layered upon that.
4 *
5 * Authors:
6 * Bob Jamison
7 *
8 * Copyright (C) 2007-2008 Bob Jamison
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 3 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
25 package org.inkscape.cmn;
27 import java.awt.Image;
28 import javax.swing.ImageIcon;
29 import java.net.URL;
33 /**
34 * This class will hold various functions for getting a
35 * resource from the classpath or jarfile
36 */
37 public class Resource
38 {
41 public static ImageIcon getIcon(String name)
42 {
44 String path = "/data/icons/" + name;
45 URL imgurl = Resource.class.getResource(path);
46 if (imgurl == null)
47 {
48 System.err.println("Icon '" + path + "' not found");
49 return null;
50 }
51 ImageIcon icon = new ImageIcon(imgurl);
52 return icon;
53 }
55 public static Image getImage(String name)
56 {
58 ImageIcon icon = getIcon(name);
59 if (icon == null)
60 return null;
61 return icon.getImage();
62 }
65 }