1 29 30 package nextapp.echo2.app.componentxml.propertypeer; 31 32 import org.w3c.dom.Element ; 33 34 import nextapp.echo2.app.Color; 35 import nextapp.echo2.app.componentxml.InvalidPropertyException; 36 import nextapp.echo2.app.componentxml.PropertyXmlPeer; 37 38 42 public class ColorPeer 43 implements PropertyXmlPeer { 44 45 51 public static Color toColor(String value) 52 throws InvalidPropertyException { 53 try { 54 int colorValue = Integer.parseInt(value.substring(1), 16); 55 return new Color(colorValue); 56 } catch (IndexOutOfBoundsException ex) { 57 throw new InvalidPropertyException("Invalid color value: " + value, ex); 58 } catch (NumberFormatException ex) { 59 throw new InvalidPropertyException("Invalid color value: " + value, ex); 60 } 61 } 62 63 67 public Object getValue(ClassLoader classLoader, Class objectClass, Element propertyElement) 68 throws InvalidPropertyException { 69 String value = propertyElement.getAttribute("value"); 70 return toColor(value); 71 } 72 } 73 | Popular Tags |