001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * GeneralPathSerializer.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.util.serializers;
030:
031: import java.awt.geom.AffineTransform;
032: import java.awt.geom.GeneralPath;
033: import java.awt.geom.PathIterator;
034: import java.io.IOException;
035: import java.io.ObjectInputStream;
036: import java.io.ObjectOutputStream;
037:
038: import org.jfree.report.util.SerializeMethod;
039:
040: /**
041: * A serialize method that handles java.awt.geom.GeneralPath objects.
042: *
043: * @deprecated Delete me.
044: * @author Thomas Morgner
045: */
046: public class GeneralPathSerializer implements SerializeMethod {
047: /**
048: * Default constructor.
049: */
050: public GeneralPathSerializer() {
051: }
052:
053: /**
054: * The class of the object, which this object can serialize.
055: *
056: * @return the class of the object type, which this method handles.
057: */
058: public Class getObjectClass() {
059: return GeneralPath.class;
060: }
061:
062: /**
063: * Reads the object from the object input stream.
064: *
065: * @param in the object input stream from where to read the serialized data.
066: * @return the generated object.
067: *
068: * @throws java.io.IOException if reading the stream failed.
069: * @throws ClassNotFoundException if serialized object class cannot be found.
070: */
071: public Object readObject(final ObjectInputStream in)
072: throws IOException, ClassNotFoundException {
073: final int winding = in.readInt();
074: final GeneralPath gp = new GeneralPath(winding);
075:
076: // type will be -1 at the end of the GPath ..
077: int type = in.readInt();
078: while (type >= 0) {
079: switch (type) {
080: case PathIterator.SEG_MOVETO: {
081: final float x = in.readFloat();
082: final float y = in.readFloat();
083: gp.moveTo(x, y);
084: break;
085: }
086: case PathIterator.SEG_LINETO: {
087: final float x = in.readFloat();
088: final float y = in.readFloat();
089: gp.lineTo(x, y);
090: break;
091: }
092: case PathIterator.SEG_QUADTO: {
093: final float x1 = in.readFloat();
094: final float y1 = in.readFloat();
095: final float x2 = in.readFloat();
096: final float y2 = in.readFloat();
097: gp.quadTo(x1, y1, x2, y2);
098: break;
099: }
100: case PathIterator.SEG_CUBICTO: {
101: final float x1 = in.readFloat();
102: final float y1 = in.readFloat();
103: final float x2 = in.readFloat();
104: final float y2 = in.readFloat();
105: final float x3 = in.readFloat();
106: final float y3 = in.readFloat();
107: gp.curveTo(x1, y1, x2, y2, x3, y3);
108: break;
109: }
110: case PathIterator.SEG_CLOSE: {
111: break;
112: }
113: default:
114: throw new IOException("Unexpected type encountered: "
115: + type);
116: }
117: type = in.readInt();
118: }
119: return gp;
120: }
121:
122: /**
123: * Writes a serializable object description to the given object output stream.
124: *
125: * @param o the to be serialized object.
126: * @param out the outputstream that should receive the object.
127: * @throws java.io.IOException if an I/O error occured.
128: */
129: public void writeObject(final Object o, final ObjectOutputStream out)
130: throws IOException {
131: final GeneralPath gp = (GeneralPath) o;
132: final PathIterator it = gp
133: .getPathIterator(new AffineTransform());
134: out.writeInt(it.getWindingRule());
135: while (it.isDone() == false) {
136: final float[] corrds = new float[6];
137: final int type = it.currentSegment(corrds);
138: out.writeInt(type);
139:
140: switch (type) {
141: case PathIterator.SEG_MOVETO: {
142: out.writeFloat(corrds[0]);
143: out.writeFloat(corrds[1]);
144: break;
145: }
146: case PathIterator.SEG_LINETO: {
147: out.writeFloat(corrds[0]);
148: out.writeFloat(corrds[1]);
149: break;
150: }
151: case PathIterator.SEG_QUADTO: {
152: out.writeFloat(corrds[0]);
153: out.writeFloat(corrds[1]);
154: out.writeFloat(corrds[2]);
155: out.writeFloat(corrds[3]);
156: break;
157: }
158: case PathIterator.SEG_CUBICTO: {
159: out.writeFloat(corrds[0]);
160: out.writeFloat(corrds[1]);
161: out.writeFloat(corrds[2]);
162: out.writeFloat(corrds[3]);
163: out.writeFloat(corrds[4]);
164: out.writeFloat(corrds[5]);
165: break;
166: }
167: case PathIterator.SEG_CLOSE: {
168: break;
169: }
170: default:
171: throw new IOException("Unexpected type encountered: "
172: + type);
173: }
174: it.next();
175: }
176: out.writeInt(-1);
177: }
178: }
|