1
/* ========================================================================
2
* JCommon : a free general purpose class library for the Java(tm) platform
3
* ========================================================================
5
* (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
7
* Project Info: http://www.jfree.org/jcommon/index.html
9
* This library is free software; you can redistribute it and/or modify it
10
* under the terms of the GNU Lesser General Public License as published by
11
* the Free Software Foundation; either version 2.1 of the License, or
12
* (at your option) any later version.
14
* This library is distributed in the hope that it will be useful, but
15
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
* License for more details.
19
* You should have received a copy of the GNU Lesser General Public
20
* License along with this library; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25
* in the United States and other countries.]
27
* ------------------------
28
* GradientPaintReadHandler
29
* ------------------------
30
* (C) Copyright 2003, by Thomas Morgner and Contributors.
32
* Original Author: Thomas Morgner;
33
* Contributor(s): David Gilbert (for Object Refinery Limited);
35
* $Id: GradientPaintReadHandler.java,v 1.2 2005/10/18 13:33:32 mungady Exp $
37
* Changes (from 25-Nov-2003)
38
* --------------------------
39
* 25-Nov-2003 : Added standard header and Javadocs (DG);
43
package org.jfree.xml.parser.coretypes;
45
import java.awt.Color;
46
import java.awt.GradientPaint;
47
import java.awt.geom.Point2D;
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;
56
* A SAX handler for reading a {@link GradientPaint} from an XML element.
58
public class GradientPaintReadHandler extends AbstractXmlReadHandler {
60
/** The gradient paint under construction. */
61
private GradientPaint gradient;
63
/** The handler for color 1. */
64
private XmlReadHandler color1Handler;
66
/** The handler for color 2. */
67
private XmlReadHandler color2Handler;
69
/** The handler for point 1. */
70
private XmlReadHandler point1Handler;
72
/** The handler for point 2. */
73
private XmlReadHandler point2Handler;
76
* Creates a new handler.
78
public GradientPaintReadHandler() {
83
* Returns the gradient paint under construction.
85
* @return the gradient paint.
87
public Object getObject() {
92
* Returns the handler for a child element.
94
* @param tagName the tag name.
95
* @param atts the attributes.
97
* @return the handler.
98
* @throws SAXException to indicate a parsing error.
99
* @throws XmlReaderException if there is a reader error.
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;
107
else if ("color2".equals(tagName)) {
108
this.color2Handler = getRootHandler().createHandler(Color.class, tagName, atts);
109
return this.color2Handler;
111
else if ("point1".equals(tagName)) {
112
this.point1Handler = getRootHandler().createHandler(Point2D.class, tagName, atts);
113
return this.point1Handler;
115
else if ("point2".equals(tagName)) {
116
this.point2Handler = getRootHandler().createHandler(Point2D.class, tagName, atts);
117
return this.point2Handler;
123
* At the end of parsing the element, the gradient paint is constructed.
125
* @throws XmlReaderException if there is a parsing error.
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.");
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());