1 42 43 package org.jfree.xml.factory.objects; 44 45 import java.awt.Dimension ; 46 import java.awt.geom.Dimension2D ; 47 48 53 public class DimensionObjectDescription extends AbstractObjectDescription { 54 55 58 public DimensionObjectDescription() { 59 super(Dimension .class); 60 setParameterDefinition("width", Float .class); 61 setParameterDefinition("height", Float .class); 62 } 63 64 69 public Object createObject() { 70 final Dimension2D dim = new Dimension (); 71 72 final float width = getFloatParameter("width"); 73 final float height = getFloatParameter("height"); 74 dim.setSize(width, height); 75 return dim; 76 } 77 78 85 private float getFloatParameter(final String param) { 86 final Float p = (Float ) getParameter(param); 87 if (p == null) { 88 return 0; 89 } 90 return p.floatValue(); 91 } 92 93 94 101 public void setParameterFromObject(final Object o) throws ObjectFactoryException { 102 if (!(o instanceof Dimension )) { 103 throw new ObjectFactoryException("The given object is no java.awt.geom.Dimension2D."); 104 } 105 106 final Dimension dim = (Dimension ) o; 107 final float width = (float) dim.getWidth(); 108 final float height = (float) dim.getHeight(); 109 110 setParameter("width", new Float (width)); 111 setParameter("height", new Float (height)); 112 } 113 } 114 | Popular Tags |