1 43 44 package org.jfree.xml.factory.objects; 45 46 import java.awt.geom.Rectangle2D ; 47 48 53 public class Rectangle2DObjectDescription extends AbstractObjectDescription { 54 55 58 public Rectangle2DObjectDescription() { 59 super(Rectangle2D .class); 60 setParameterDefinition("width", Float .class); 61 setParameterDefinition("height", Float .class); 62 setParameterDefinition("x", Float .class); 63 setParameterDefinition("y", Float .class); 64 } 65 66 71 public Object createObject() { 72 final Rectangle2D rect = new Rectangle2D.Float (); 73 74 final float w = getFloatParameter("width"); 75 final float h = getFloatParameter("height"); 76 final float x = getFloatParameter("x"); 77 final float y = getFloatParameter("y"); 78 rect.setRect(x, y, w, h); 79 return rect; 80 } 81 82 89 private float getFloatParameter(final String param) { 90 final Float p = (Float ) getParameter(param); 91 if (p == null) { 92 return 0; 93 } 94 return p.floatValue(); 95 } 96 97 104 public void setParameterFromObject(final Object o) throws ObjectFactoryException { 105 if (!(o instanceof Rectangle2D )) { 106 throw new ObjectFactoryException("The given object is no java.awt.geom.Rectangle2D."); 107 } 108 109 final Rectangle2D rect = (Rectangle2D ) o; 110 final float x = (float) rect.getX(); 111 final float y = (float) rect.getY(); 112 final float w = (float) rect.getWidth(); 113 final float h = (float) rect.getHeight(); 114 115 setParameter("x", new Float (x)); 116 setParameter("y", new Float (y)); 117 setParameter("width", new Float (w)); 118 setParameter("height", new Float (h)); 119 } 120 121 } 122 | Popular Tags |