1 29 30 package nextapp.echo2.app.componentxml.propertypeer; 31 32 import java.util.StringTokenizer ; 33 34 import org.w3c.dom.Element ; 35 36 import nextapp.echo2.app.Extent; 37 import nextapp.echo2.app.Insets; 38 import nextapp.echo2.app.componentxml.InvalidPropertyException; 39 import nextapp.echo2.app.componentxml.PropertyXmlPeer; 40 41 45 public class InsetsPeer 46 implements PropertyXmlPeer { 47 48 public static Insets toInsets(String value) 49 throws InvalidPropertyException { 50 StringTokenizer st = new StringTokenizer (value, " "); 51 int count = st.countTokens(); 52 switch (count) { 53 case 1: 54 Extent extent = ExtentPeer.toExtent(st.nextToken()); 55 return new Insets(extent); 56 case 2: 57 Extent horizontal = ExtentPeer.toExtent(st.nextToken()); 58 Extent vertical = ExtentPeer.toExtent(st.nextToken()); 59 return new Insets(horizontal, vertical); 60 case 4: 61 Extent left = ExtentPeer.toExtent(st.nextToken()); 62 Extent top = ExtentPeer.toExtent(st.nextToken()); 63 Extent right = ExtentPeer.toExtent(st.nextToken()); 64 Extent bottom = ExtentPeer.toExtent(st.nextToken()); 65 return new Insets(left, top, right, bottom); 66 default: 67 throw new InvalidPropertyException("Invalid Insets value: " + value, null); 68 } 69 } 70 71 75 public Object getValue(ClassLoader classLoader, Class objectClass, Element propertyElement) 76 throws InvalidPropertyException { 77 String value = propertyElement.getAttribute("value"); 78 return toInsets(value); 79 } 80 } 81 | Popular Tags |