1 53 54 package org.swixml.converters; 55 56 import org.jdom.Attribute; 57 import org.swixml.Converter; 58 import org.swixml.Localizer; 59 import org.swixml.Parser; 60 61 import javax.swing.*; 62 63 71 public class ImageIconConverter implements Converter { 72 73 74 public static final Class TEMPLATE = ImageIcon.class; 75 76 77 84 public Object convert( final Class type, final Attribute attr, Localizer localizer ) { 85 return ImageIconConverter.conv( type, attr, localizer ); 86 } 87 88 95 public static Object conv( final Class type, final Attribute attr, Localizer localizer ) { 96 ImageIcon icon = null; 97 if (attr != null) { 98 if (Parser.LOCALIZED_ATTRIBUTES.contains( attr.getName().toLowerCase() )) { 99 if (attr.getAttributeType() == Attribute.CDATA_TYPE) { 100 attr.setValue( localizer.getString( attr.getValue() ) ); 101 } 102 } 103 try { 104 icon = new ImageIcon( localizer.getClassLoader().getResource( attr.getValue() ) ); 107 } catch (Exception e) { 108 } 110 } 111 return icon; 112 } 113 114 119 public Class convertsTo() { 120 return TEMPLATE; 121 } 122 } 123 | Popular Tags |