summaryrefslogtreecommitdiffstats
path: root/awt/java/awt/image/renderable/RenderContext.java
blob: 0db512faf19ff23df5aca3575678e9c511386963 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
/**
 * @author Igor V. Stolyarov
 * @version $Revision$
 */

package java.awt.image.renderable;

import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.geom.AffineTransform;

/**
 * The Class RenderContext stores data on how an image is to be rendered: the
 * affine transform, the area of interest, and the rendering hints.
 * 
 * @since Android 1.0
 */
public class RenderContext implements Cloneable {

    /**
     * The affine transform.
     */
    AffineTransform transform;

    /**
     * The area of interest.
     */
    Shape aoi;

    /**
     * The rendering hints.
     */
    RenderingHints hints;

    /**
     * Instantiates a new render context.
     * 
     * @param usr2dev
     *            the affine transform.
     * @param aoi
     *            the area of interest.
     * @param hints
     *            the rendering hints.
     */
    public RenderContext(AffineTransform usr2dev, Shape aoi, RenderingHints hints) {
        this.transform = (AffineTransform)usr2dev.clone();
        this.aoi = aoi;
        this.hints = hints;
    }

    /**
     * Instantiates a new render context with no specified hints.
     * 
     * @param usr2dev
     *            the affine transform.
     * @param aoi
     *            the area of interest.
     */
    public RenderContext(AffineTransform usr2dev, Shape aoi) {
        this(usr2dev, aoi, null);
    }

    /**
     * Instantiates a new render context with no specified area of interest.
     * 
     * @param usr2dev
     *            the affine transform.
     * @param hints
     *            the rendering hints.
     */
    public RenderContext(AffineTransform usr2dev, RenderingHints hints) {
        this(usr2dev, null, hints);
    }

    /**
     * Instantiates a new render context with no rendering hints or area of
     * interest.
     * 
     * @param usr2dev
     *            the affine transform.
     */
    public RenderContext(AffineTransform usr2dev) {
        this(usr2dev, null, null);
    }

    @Override
    public Object clone() {
        return new RenderContext(transform, aoi, hints);
    }

    /**
     * Sets the affine transform for this render context.
     * 
     * @param newTransform
     *            the new affine transform.
     */
    public void setTransform(AffineTransform newTransform) {
        transform = (AffineTransform)newTransform.clone();
    }

    /**
     * Concatenates the current transform with the specified transform (so they
     * are applied with the specified transform acting first) and sets the
     * resulting transform as the affine transform of this rendering context.
     * 
     * @param modTransform
     *            the new transform which modifies the current transform.
     * @deprecated use
     *             {@link RenderContext#preConcatenateTransform(AffineTransform)}
     *             .
     */
    @Deprecated
    public void preConcetenateTransform(AffineTransform modTransform) {
        preConcatenateTransform(modTransform);
    }

    /**
     * Concatenates the current transform with the specified transform (so they
     * are applied with the specified transform acting first) and sets the
     * resulting transform as the affine transform of this rendering context.
     * 
     * @param modTransform
     *            the new transform which modifies the current transform.
     */
    public void preConcatenateTransform(AffineTransform modTransform) {
        transform.preConcatenate(modTransform);
    }

    /**
     * Concatenate the specified transform with the current transform.
     * 
     * @param modTransform
     *            the new transform which modifies the current transform.
     * @deprecated use
     *             {@link RenderContext#concatenateTransform(AffineTransform)}.
     */
    @Deprecated
    public void concetenateTransform(AffineTransform modTransform) {
        concatenateTransform(modTransform);
    }

    /**
     * Concatenate the specified transform with the current transform.
     * 
     * @param modTransform
     *            the new transform which modifies the current transform.
     */
    public void concatenateTransform(AffineTransform modTransform) {
        transform.concatenate(modTransform);
    }

    /**
     * Gets the transform.
     * 
     * @return the transform.
     */
    public AffineTransform getTransform() {
        return (AffineTransform)transform.clone();
    }

    /**
     * Sets the area of interest.
     * 
     * @param newAoi
     *            the new area of interest.
     */
    public void setAreaOfInterest(Shape newAoi) {
        aoi = newAoi;
    }

    /**
     * Gets the area of interest.
     * 
     * @return the area of interest.
     */
    public Shape getAreaOfInterest() {
        return aoi;
    }

    /**
     * Sets the rendering hints.
     * 
     * @param hints
     *            the new rendering hints.
     */
    public void setRenderingHints(RenderingHints hints) {
        this.hints = hints;
    }

    /**
     * Gets the rendering hints.
     * 
     * @return the rendering hints.
     */
    public RenderingHints getRenderingHints() {
        return hints;
    }
}