KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > image > renderable > RenderContext


1 /*
2  * @(#)RenderContext.java 1.16 04/05/18
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 /* ********************************************************************
9  **********************************************************************
10  **********************************************************************
11  *** COPYRIGHT (c) Eastman Kodak Company, 1997 ***
12  *** As an unpublished work pursuant to Title 17 of the United ***
13  *** States Code. All rights reserved. ***
14  **********************************************************************
15  **********************************************************************
16  **********************************************************************/

17
18 package java.awt.image.renderable;
19 import java.util.*;
20 import java.awt.geom.*;
21 import java.awt.*;
22 import java.awt.image.*;
23
24 /**
25  * A RenderContext encapsulates the information needed to produce a
26  * specific rendering from a RenderableImage. It contains the area to
27  * be rendered specified in rendering-independent terms, the
28  * resolution at which the rendering is to be performed, and hints
29  * used to control the rendering process.
30  *
31  * <p> Users create RenderContexts and pass them to the
32  * RenderableImage via the createRendering method. Most of the methods of
33  * RenderContexts are not meant to be used directly by applications,
34  * but by the RenderableImage and operator classes to which it is
35  * passed.
36  *
37  * <p> The AffineTransform parameter passed into and out of this class
38  * are cloned. The RenderingHints and Shape parameters are not
39  * necessarily cloneable and are therefore only reference copied.
40  * Altering RenderingHints or Shape instances that are in use by
41  * instances of RenderContext may have undesired side effects.
42  */

43 public class RenderContext implements Cloneable JavaDoc {
44     
45     /** Table of hints. May be null. */
46     RenderingHints hints;
47     
48     /** Transform to convert user coordinates to device coordinates. */
49     AffineTransform usr2dev;
50     
51     /** The area of interest. May be null. */
52     Shape aoi;
53     
54     // Various constructors that allow different levels of
55
// specificity. If the Shape is missing the whole renderable area
56
// is assumed. If hints is missing no hints are assumed.
57

58     /**
59      * Constructs a RenderContext with a given transform.
60      * The area of interest is supplied as a Shape,
61      * and the rendering hints are supplied as a RenderingHints object.
62      *
63      * @param usr2dev an AffineTransform.
64      * @param aoi a Shape representing the area of interest.
65      * @param hints a RenderingHints object containing rendering hints.
66      */

67     public RenderContext(AffineTransform usr2dev,
68                          Shape aoi,
69                          RenderingHints hints) {
70         this.hints = hints;
71         this.aoi = aoi;
72         this.usr2dev = (AffineTransform)usr2dev.clone();
73     }
74     
75     /**
76      * Constructs a RenderContext with a given transform.
77      * The area of interest is taken to be the entire renderable area.
78      * No rendering hints are used.
79      *
80      * @param usr2dev an AffineTransform.
81      */

82     public RenderContext(AffineTransform usr2dev) {
83         this(usr2dev, null, null);
84     }
85     
86     /**
87      * Constructs a RenderContext with a given transform and rendering hints.
88      * The area of interest is taken to be the entire renderable area.
89      *
90      * @param usr2dev an AffineTransform.
91      * @param hints a RenderingHints object containing rendering hints.
92      */

93     public RenderContext(AffineTransform usr2dev, RenderingHints hints) {
94         this(usr2dev, null, hints);
95     }
96     
97     /**
98      * Constructs a RenderContext with a given transform and area of interest.
99      * The area of interest is supplied as a Shape.
100      * No rendering hints are used.
101      *
102      * @param usr2dev an AffineTransform.
103      * @param aoi a Shape representing the area of interest.
104      */

105     public RenderContext(AffineTransform usr2dev, Shape aoi) {
106         this(usr2dev, aoi, null);
107     }
108
109     /**
110      * Gets the rendering hints of this <code>RenderContext</code>.
111      * @return a <code>RenderingHints</code> object that represents
112      * the rendering hints of this <code>RenderContext</code>.
113      * @see #setRenderingHints(RenderingHints)
114      */

115     public RenderingHints getRenderingHints() {
116         return hints;
117     }
118
119     /**
120      * Sets the rendering hints of this <code>RenderContext</code>.
121      * @param hints a <code>RenderingHints</code> object that represents
122      * the rendering hints to assign to this <code>RenderContext</code>.
123      * @see #getRenderingHints
124      */

125     public void setRenderingHints(RenderingHints hints) {
126         this.hints = hints;
127     }
128     
129     /**
130      * Sets the current user-to-device AffineTransform contained
131      * in the RenderContext to a given transform.
132      *
133      * @param newTransform the new AffineTransform.
134      * @see #getTransform
135      */

136     public void setTransform(AffineTransform newTransform) {
137         usr2dev = (AffineTransform)newTransform.clone();
138     }
139         
140     /**
141      * Modifies the current user-to-device transform by prepending another
142      * transform. In matrix notation the operation is:
143      * <pre>
144      * [this] = [modTransform] x [this]
145      * </pre>
146      *
147      * @param modTransform the AffineTransform to prepend to the
148      * current usr2dev transform.
149      */

150     public void preConcatenateTransform(AffineTransform modTransform) {
151         this.preConcetenateTransform(modTransform);
152     }
153     
154     /**
155      * Modifies the current user-to-device transform by prepending another
156      * transform. In matrix notation the operation is:
157      * <pre>
158      * [this] = [modTransform] x [this]
159      * </pre>
160      * This method does the same thing as the preConcatenateTransform
161      * method. It is here for backward compatibility with previous releases
162      * which misspelled the method name.
163      *
164      * @param modTransform the AffineTransform to prepend to the
165      * current usr2dev transform.
166      * @deprecated replaced by
167      * <code>preConcatenateTransform(AffineTransform)</code>.
168      */

169     @Deprecated JavaDoc
170     public void preConcetenateTransform(AffineTransform modTransform) {
171         usr2dev.preConcatenate(modTransform);
172     }
173
174     /**
175      * Modifies the current user-to-device transform by appending another
176      * transform. In matrix notation the operation is:
177      * <pre>
178      * [this] = [this] x [modTransform]
179      * </pre>
180      *
181      * @param modTransform the AffineTransform to append to the
182      * current usr2dev transform.
183      */

184     public void concatenateTransform(AffineTransform modTransform) {
185         this.concetenateTransform(modTransform);
186     }
187     
188     /**
189      * Modifies the current user-to-device transform by appending another
190      * transform. In matrix notation the operation is:
191      * <pre>
192      * [this] = [this] x [modTransform]
193      * </pre>
194      * This method does the same thing as the concatenateTransform
195      * method. It is here for backward compatibility with previous releases
196      * which misspelled the method name.
197      *
198      * @param modTransform the AffineTransform to append to the
199      * current usr2dev transform.
200      * @deprecated replaced by
201      * <code>concatenateTransform(AffineTransform)</code>.
202      */

203     @Deprecated JavaDoc
204     public void concetenateTransform(AffineTransform modTransform) {
205         usr2dev.concatenate(modTransform);
206     }
207     
208     /**
209      * Gets the current user-to-device AffineTransform.
210      *
211      * @return a reference to the current AffineTransform.
212      * @see #setTransform(AffineTransform)
213      */

214     public AffineTransform getTransform() {
215         return (AffineTransform)usr2dev.clone();
216     }
217
218     /**
219      * Sets the current area of interest. The old area is discarded.
220      *
221      * @param newAoi The new area of interest.
222      * @see #getAreaOfInterest
223      */

224     public void setAreaOfInterest(Shape newAoi) {
225         aoi = newAoi;
226     }
227
228     /**
229      * Gets the ares of interest currently contained in the
230      * RenderContext.
231      *
232      * @return a reference to the area of interest of the RenderContext,
233      * or null if none is specified.
234      * @see #setAreaOfInterest(Shape)
235      */

236     public Shape getAreaOfInterest() {
237         return aoi;
238     }
239
240     /**
241      * Makes a copy of a RenderContext. The area of interest is copied
242      * by reference. The usr2dev AffineTransform and hints are cloned,
243      * while the area of interest is copied by reference.
244      *
245      * @return the new cloned RenderContext.
246      */

247     public Object JavaDoc clone() {
248         RenderContext JavaDoc newRenderContext = new RenderContext JavaDoc(usr2dev,
249                                                            aoi, hints);
250         return newRenderContext;
251     }
252 }
253
Popular Tags