1
2
3
4
5
6
7
8
9 package tsukuba_bunko.peko.resource;
10
11 import java.net.URL;
12
13 import javax.swing.ImageIcon;
14
15 import org.xml.sax.SAXException;
16
17 import tsukuba_bunko.resource.SimpleDeserializer;
18
19
20 /***
21 * {@link javax.swing.ImageIcon} 型のリソースに対する {@link tsukuba_bunko.resource.ResourceDeserializer} 実装です。
22 * @author $Author: ppoi $
23 * @version $Revision: 1.1 $
24 * @see <a href="http://softlab.tsukuba-bunko.org/peko/userguide/resource.html#type-peko:icon">peko:icon 型のリソース</a>
25 */
26 public class IconDeserializer extends SimpleDeserializer {
27
28 /***
29 * ベース URL
30 */
31 private URL _baseURL = null;
32
33
34 /***
35 * <code>IconDeserializer</code> のインスタンスを作成します。
36 */
37 public IconDeserializer()
38 {
39 super();
40 }
41
42
43 /***
44 * ベース URL を設定します.
45 * @param baseURL ベース URL
46 */
47 public void setBaseURL( URL baseURL )
48 {
49 _baseURL = baseURL;
50 }
51
52
53
54
55
56 public Object convertValue( String source )
57 throws SAXException
58 {
59 try {
60 if( _baseURL != null ) {
61 return new ImageIcon( new URL(_baseURL, source) );
62 }
63 else {
64 return new ImageIcon( source );
65 }
66 }
67 catch( Exception e ) {
68 throw new SAXException( e );
69 }
70 }
71 }