OSDN Git Service

auto import from //depot/cupcake/@135843
[android-x86/frameworks-native.git] / awt / java / awt / image / renderable / RenderContext.java
1 /*
2  *  Licensed to the Apache Software Foundation (ASF) under one or more
3  *  contributor license agreements.  See the NOTICE file distributed with
4  *  this work for additional information regarding copyright ownership.
5  *  The ASF licenses this file to You under the Apache License, Version 2.0
6  *  (the "License"); you may not use this file except in compliance with
7  *  the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  */
17 /**
18  * @author Igor V. Stolyarov
19  * @version $Revision$
20  */
21
22 package java.awt.image.renderable;
23
24 import java.awt.RenderingHints;
25 import java.awt.Shape;
26 import java.awt.geom.AffineTransform;
27
28 /**
29  * The Class RenderContext stores data on how an image is to be rendered: the
30  * affine transform, the area of interest, and the rendering hints.
31  * 
32  * @since Android 1.0
33  */
34 public class RenderContext implements Cloneable {
35
36     /**
37      * The affine transform.
38      */
39     AffineTransform transform;
40
41     /**
42      * The area of interest.
43      */
44     Shape aoi;
45
46     /**
47      * The rendering hints.
48      */
49     RenderingHints hints;
50
51     /**
52      * Instantiates a new render context.
53      * 
54      * @param usr2dev
55      *            the affine transform.
56      * @param aoi
57      *            the area of interest.
58      * @param hints
59      *            the rendering hints.
60      */
61     public RenderContext(AffineTransform usr2dev, Shape aoi, RenderingHints hints) {
62         this.transform = (AffineTransform)usr2dev.clone();
63         this.aoi = aoi;
64         this.hints = hints;
65     }
66
67     /**
68      * Instantiates a new render context with no specified hints.
69      * 
70      * @param usr2dev
71      *            the affine transform.
72      * @param aoi
73      *            the area of interest.
74      */
75     public RenderContext(AffineTransform usr2dev, Shape aoi) {
76         this(usr2dev, aoi, null);
77     }
78
79     /**
80      * Instantiates a new render context with no specified area of interest.
81      * 
82      * @param usr2dev
83      *            the affine transform.
84      * @param hints
85      *            the rendering hints.
86      */
87     public RenderContext(AffineTransform usr2dev, RenderingHints hints) {
88         this(usr2dev, null, hints);
89     }
90
91     /**
92      * Instantiates a new render context with no rendering hints or area of
93      * interest.
94      * 
95      * @param usr2dev
96      *            the affine transform.
97      */
98     public RenderContext(AffineTransform usr2dev) {
99         this(usr2dev, null, null);
100     }
101
102     @Override
103     public Object clone() {
104         return new RenderContext(transform, aoi, hints);
105     }
106
107     /**
108      * Sets the affine transform for this render context.
109      * 
110      * @param newTransform
111      *            the new affine transform.
112      */
113     public void setTransform(AffineTransform newTransform) {
114         transform = (AffineTransform)newTransform.clone();
115     }
116
117     /**
118      * Concatenates the current transform with the specified transform (so they
119      * are applied with the specified transform acting first) and sets the
120      * resulting transform as the affine transform of this rendering context.
121      * 
122      * @param modTransform
123      *            the new transform which modifies the current transform.
124      * @deprecated use
125      *             {@link RenderContext#preConcatenateTransform(AffineTransform)}
126      *             .
127      */
128     @Deprecated
129     public void preConcetenateTransform(AffineTransform modTransform) {
130         preConcatenateTransform(modTransform);
131     }
132
133     /**
134      * Concatenates the current transform with the specified transform (so they
135      * are applied with the specified transform acting first) and sets the
136      * resulting transform as the affine transform of this rendering context.
137      * 
138      * @param modTransform
139      *            the new transform which modifies the current transform.
140      */
141     public void preConcatenateTransform(AffineTransform modTransform) {
142         transform.preConcatenate(modTransform);
143     }
144
145     /**
146      * Concatenate the specified transform with the current transform.
147      * 
148      * @param modTransform
149      *            the new transform which modifies the current transform.
150      * @deprecated use
151      *             {@link RenderContext#concatenateTransform(AffineTransform)}.
152      */
153     @Deprecated
154     public void concetenateTransform(AffineTransform modTransform) {
155         concatenateTransform(modTransform);
156     }
157
158     /**
159      * Concatenate the specified transform with the current transform.
160      * 
161      * @param modTransform
162      *            the new transform which modifies the current transform.
163      */
164     public void concatenateTransform(AffineTransform modTransform) {
165         transform.concatenate(modTransform);
166     }
167
168     /**
169      * Gets the transform.
170      * 
171      * @return the transform.
172      */
173     public AffineTransform getTransform() {
174         return (AffineTransform)transform.clone();
175     }
176
177     /**
178      * Sets the area of interest.
179      * 
180      * @param newAoi
181      *            the new area of interest.
182      */
183     public void setAreaOfInterest(Shape newAoi) {
184         aoi = newAoi;
185     }
186
187     /**
188      * Gets the area of interest.
189      * 
190      * @return the area of interest.
191      */
192     public Shape getAreaOfInterest() {
193         return aoi;
194     }
195
196     /**
197      * Sets the rendering hints.
198      * 
199      * @param hints
200      *            the new rendering hints.
201      */
202     public void setRenderingHints(RenderingHints hints) {
203         this.hints = hints;
204     }
205
206     /**
207      * Gets the rendering hints.
208      * 
209      * @return the rendering hints.
210      */
211     public RenderingHints getRenderingHints() {
212         return hints;
213     }
214 }