1 53 54 package org.swixml.converters; 55 56 import org.jdom.Attribute; 57 import org.swixml.Converter; 58 import org.swixml.Localizer; 59 60 import java.awt.*; 61 import java.util.StringTokenizer ; 62 63 77 78 public final class DimensionConverter implements Converter { 79 80 public static final Class TEMPLATE = Dimension.class; 81 82 88 public Object convert( final Class type, final Attribute attr, Localizer localizer ) { 89 if (attr != null) { 90 StringTokenizer st = new StringTokenizer ( attr.getValue(), "," ); 91 int width = 0; 92 int height = 0; 93 if (st.hasMoreTokens()) { 94 width = Integer.parseInt( st.nextToken().trim() ); 95 } 96 if (st.hasMoreTokens()) { 97 height = Integer.parseInt( st.nextToken().trim() ); 98 } 99 return new Dimension( width, height ); 100 } 101 return null; 102 } 103 104 105 110 public Class convertsTo() { 111 return TEMPLATE; 112 } 113 } | Popular Tags |