1 43 44 package org.jfree.xml.factory.objects; 45 46 import java.awt.BasicStroke ; 47 48 53 public class BasicStrokeObjectDescription extends AbstractObjectDescription { 54 55 58 public BasicStrokeObjectDescription() { 59 super(BasicStroke .class); 60 setParameterDefinition("value", String .class); 61 setParameterDefinition("width", Float .class); 62 setParameterDefinition("dashes", Float [].class); 63 } 64 65 72 private float getFloatParameter(final String param) { 73 final String p = (String ) getParameter(param); 74 if (p == null) { 75 return 0; 76 } 77 try { 78 return Float.parseFloat(p); 79 } 80 catch (Exception e) { 81 return 0; 82 } 83 } 84 85 90 public Object createObject() { 91 92 final float width = getFloatParameter("value"); 93 if (width > 0) { 94 return new BasicStroke (width); 95 } 96 97 Float realWidth = (Float ) getParameter("width"); 98 Float [] dashes = (Float []) getParameter("dashes"); 99 if (realWidth == null || dashes == null) { 100 return null; 101 } 102 float[] dashesPrimitive = new float[dashes.length]; 103 for (int i = 0; i < dashes.length; i++) { 104 Float dash = dashes[i]; 105 dashesPrimitive[i] = dash.floatValue(); 106 } 107 return new BasicStroke (realWidth.floatValue(), 108 BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 109 10.0f, dashesPrimitive, 0.0f); 110 } 111 112 120 public void setParameterFromObject(final Object o) throws ObjectFactoryException { 121 if (!(o instanceof BasicStroke )) { 122 throw new ObjectFactoryException("Expected object of type BasicStroke"); 123 } 124 final BasicStroke bs = (BasicStroke ) o; 125 setParameter("value", String.valueOf(bs.getLineWidth())); 126 } 127 } 128 | Popular Tags |