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 RectangleConverter implements Converter { 79 80 public static final Class TEMPLATE = Rectangle.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 x = 0; 92 int y = 0; 93 int width = 0; 94 int height = 0; 95 if (st.hasMoreTokens()) { 96 x = Integer.parseInt( st.nextToken().trim() ); 97 } 98 if (st.hasMoreTokens()) { 99 y = Integer.parseInt( st.nextToken().trim() ); 100 } 101 if (st.hasMoreTokens()) { 102 width = Integer.parseInt( st.nextToken().trim() ); 103 } 104 if (st.hasMoreTokens()) { 105 height = Integer.parseInt( st.nextToken().trim() ); 106 } 107 return new Rectangle( x, y, width, height ); 108 } 109 return null; 110 } 111 112 113 118 public Class convertsTo() { 119 return TEMPLATE; 120 } 121 } | Popular Tags |