01: /*
02: * $RCSfile: RenderContextState.java,v $
03: *
04: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
05: *
06: * Use is subject to license terms.
07: *
08: * $Revision: 1.1 $
09: * $Date: 2005/02/11 04:56:53 $
10: * $State: Exp $
11: */
12: package com.sun.media.jai.rmi;
13:
14: import java.awt.Rectangle;
15: import java.awt.RenderingHints;
16: import java.awt.Shape;
17: import java.awt.geom.AffineTransform;
18: import java.awt.image.renderable.RenderContext;
19: import java.io.IOException;
20: import java.io.ObjectInputStream;
21: import java.io.ObjectOutputStream;
22: import java.io.Serializable;
23: import javax.media.jai.ROIShape;
24: import javax.media.jai.remote.SerializableState;
25: import javax.media.jai.remote.SerializerFactory;
26:
27: /**
28: * This class is a serializable proxy for a RenderContext from which the
29: * RenderContext may be reconstituted.
30: *
31: *
32: * @since 1.1
33: */
34: public class RenderContextState extends SerializableStateImpl {
35: public static Class[] getSupportedClasses() {
36: return new Class[] { RenderContext.class };
37: }
38:
39: /**
40: * Constructs a <code>RenderContextState</code> from a
41: * <code>RenderContext</code>.
42: *
43: * @param c The class of the object to be serialized.
44: * @param o The <code>RenderContext</code> to be serialized.
45: * @param h The <code>RenderingHints</code> (ignored).
46: */
47: public RenderContextState(Class c, Object o, RenderingHints h) {
48: super (c, o, h);
49: }
50:
51: /**
52: * Serialize the <code>RenderContextState</code>.
53: *
54: * @param out The <code>ObjectOutputStream</code>.
55: */
56: private void writeObject(ObjectOutputStream out) throws IOException {
57:
58: RenderContext renderContext = (RenderContext) theObject;
59:
60: // Extract the affine transform.
61: AffineTransform usr2dev = renderContext.getTransform();
62:
63: // Extract the hints.
64: RenderingHints hints = renderContext.getRenderingHints();
65:
66: // Extract the AOI
67: Shape aoi = renderContext.getAreaOfInterest();
68:
69: // Write serialized form to the stream.
70: out.writeObject(usr2dev);
71: out.writeObject(SerializerFactory.getState(aoi));
72: out.writeObject(SerializerFactory.getState(hints, null));
73: }
74:
75: /**
76: * Deserialize the <code>RenderContextState</code>.
77: *
78: * @param out The <code>ObjectInputStream</code>.
79: */
80: private void readObject(ObjectInputStream in) throws IOException,
81: ClassNotFoundException {
82:
83: RenderContext renderContext = null;
84:
85: // Read serialized form from the stream.
86: AffineTransform usr2dev = (AffineTransform) in.readObject();
87:
88: SerializableState aoi = (SerializableState) in.readObject();
89: Shape shape = (Shape) aoi.getObject();
90:
91: SerializableState rhs = (SerializableState) in.readObject();
92: RenderingHints hints = (RenderingHints) rhs.getObject();
93:
94: // Restore the transient RenderContext.
95: renderContext = new RenderContext(usr2dev, shape, hints);
96: theObject = renderContext;
97: }
98: }
|