1 42 43 package org.jfree.xml.parser.coretypes; 44 45 import java.awt.Color ; 46 import java.awt.GradientPaint ; 47 import java.awt.geom.Point2D ; 48 49 import org.jfree.xml.parser.AbstractXmlReadHandler; 50 import org.jfree.xml.parser.XmlReadHandler; 51 import org.jfree.xml.parser.XmlReaderException; 52 import org.xml.sax.Attributes ; 53 import org.xml.sax.SAXException ; 54 55 58 public class GradientPaintReadHandler extends AbstractXmlReadHandler { 59 60 61 private GradientPaint gradient; 62 63 64 private XmlReadHandler color1Handler; 65 66 67 private XmlReadHandler color2Handler; 68 69 70 private XmlReadHandler point1Handler; 71 72 73 private XmlReadHandler point2Handler; 74 75 78 public GradientPaintReadHandler() { 79 super(); 80 } 81 82 87 public Object getObject() { 88 return this.gradient; 89 } 90 91 101 protected XmlReadHandler getHandlerForChild(final String tagName, final Attributes atts) 102 throws SAXException , XmlReaderException { 103 if ("color1".equals(tagName)) { 104 this.color1Handler = getRootHandler().createHandler(Color .class, tagName, atts); 105 return this.color1Handler; 106 } 107 else if ("color2".equals(tagName)) { 108 this.color2Handler = getRootHandler().createHandler(Color .class, tagName, atts); 109 return this.color2Handler; 110 } 111 else if ("point1".equals(tagName)) { 112 this.point1Handler = getRootHandler().createHandler(Point2D .class, tagName, atts); 113 return this.point1Handler; 114 } 115 else if ("point2".equals(tagName)) { 116 this.point2Handler = getRootHandler().createHandler(Point2D .class, tagName, atts); 117 return this.point2Handler; 118 } 119 return null; 120 } 121 122 127 protected void doneParsing() throws XmlReaderException { 128 if (this.point1Handler == null || this.point2Handler == null 129 || this.color1Handler == null || this.color2Handler == null) { 130 throw new XmlReaderException("Not all required subelements are defined."); 131 } 132 this.gradient = new GradientPaint 133 ((Point2D ) this.point1Handler.getObject(), 134 (Color ) this.color1Handler.getObject(), 135 (Point2D ) this.point2Handler.getObject(), 136 (Color ) this.color2Handler.getObject()); 137 } 138 139 } 140 | Popular Tags |