1 /*
2 Copyright 2002-2006 Martin van den Bemt
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16 package org.xulux.guilayer.swing.util;
17
18 import java.awt.Image;
19 import java.net.URL;
20
21 import javax.swing.ImageIcon;
22
23 import com.sun.jimi.core.Jimi;
24
25 /**
26 * Loads images using jimi, so also ico, xpm, etc is supported
27 * by Xulux. This is wrapped up in an interface so you don't
28 * get any strange exceptions when jimi is not there.
29 * This dependency is mainly there for jdk1.3 or lower. As from jdk1.4
30 * images will be processed using the core.
31 *
32 * @author <a href="mailto:martin@mvdb.net">Martin van den Bemt</a>
33 * @version $Id: JimiImageLoader.java,v 1.3 2004/01/28 15:09:24 mvdb Exp $
34 */
35 public class JimiImageLoader implements ImageLoaderInterface {
36
37 /**
38 * The JIMI Main class
39 */
40 private static String JIMI_MAIN_CLASS = "com.sun.jimi.core.Jimi";
41
42 /**
43 * Constructor for JimiImageLoader.
44 */
45 public JimiImageLoader() {
46 }
47
48 /**
49 * For now we don't provide any exceptions or logging in case a
50 * resrouce is null.
51 *
52 * @see org.xulux.nyx.swing.util.ImageLoaderInterface#getImage(java.net.URL)
53 */
54 public Image getImage(URL url) {
55 try {
56 return Jimi.getImage(url);
57 } catch (Exception e) {
58 return null;
59 }
60 }
61 /**
62 * @see org.xulux.nyx.swing.util.ImageLoaderInterface#getIcon(java.net.URL)
63 */
64 public ImageIcon getIcon(URL url) {
65 Image image = getImage(url);
66 if (image != null) {
67 return new ImageIcon(image);
68 } else {
69 return null;
70 }
71 }
72
73 /**
74 * @see org.xulux.nyx.swing.util.ImageLoaderInterface#isUsable()
75 */
76 public boolean isUsable() {
77 try {
78 Class.forName(JIMI_MAIN_CLASS);
79 } catch (ClassNotFoundException e) {
80 return false;
81 }
82 return true;
83 }
84
85 }