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