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 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
/* * @(#)RenderContext.java 1.18 06/04/07 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /* ******************************************************************** ********************************************************************** ********************************************************************** *** COPYRIGHT (c) Eastman Kodak Company, 1997 *** *** As an unpublished work pursuant to Title 17 of the United *** *** States Code. All rights reserved. *** ********************************************************************** ********************************************************************** **********************************************************************/ package java.awt.image.renderable; import java.util.*; import java.awt.geom.*; import java.awt.*; import java.awt.image.*; /** * A RenderContext encapsulates the information needed to produce a * specific rendering from a RenderableImage. It contains the area to * be rendered specified in rendering-independent terms, the * resolution at which the rendering is to be performed, and hints * used to control the rendering process. * * <p> Users create RenderContexts and pass them to the * RenderableImage via the createRendering method. Most of the methods of * RenderContexts are not meant to be used directly by applications, * but by the RenderableImage and operator classes to which it is * passed. * * <p> The AffineTransform parameter passed into and out of this class * are cloned. The RenderingHints and Shape parameters are not * necessarily cloneable and are therefore only reference copied. * Altering RenderingHints or Shape instances that are in use by * instances of RenderContext may have undesired side effects. */ public class RenderContext implements Cloneable { /** Table of hints. May be null. */ RenderingHints hints; /** Transform to convert user coordinates to device coordinates. */ AffineTransform usr2dev; /** The area of interest. May be null. */ Shape aoi; // Various constructors that allow different levels of // specificity. If the Shape is missing the whole renderable area // is assumed. If hints is missing no hints are assumed. /** * Constructs a RenderContext with a given transform. * The area of interest is supplied as a Shape, * and the rendering hints are supplied as a RenderingHints object. * * @param usr2dev an AffineTransform. * @param aoi a Shape representing the area of interest. * @param hints a RenderingHints object containing rendering hints. */ public RenderContext(AffineTransform usr2dev, Shape aoi, RenderingHints hints) { this.hints = hints; this.aoi = aoi; this.usr2dev = (AffineTransform)usr2dev.clone(); } /** * Constructs a RenderContext with a given transform. * The area of interest is taken to be the entire renderable area. * No rendering hints are used. * * @param usr2dev an AffineTransform. */ public RenderContext(AffineTransform usr2dev) { this(usr2dev, null, null); } /** * Constructs a RenderContext with a given transform and rendering hints. * The area of interest is taken to be the entire renderable area. * * @param usr2dev an AffineTransform. * @param hints a RenderingHints object containing rendering hints. */ public RenderContext(AffineTransform usr2dev, RenderingHints hints) { this(usr2dev, null, hints); } /** * Constructs a RenderContext with a given transform and area of interest. * The area of interest is supplied as a Shape. * No rendering hints are used. * * @param usr2dev an AffineTransform. * @param aoi a Shape representing the area of interest. */ public RenderContext(AffineTransform usr2dev, Shape aoi) { this(usr2dev, aoi, null); } /** * Gets the rendering hints of this <code>RenderContext</code>. * @return a <code>RenderingHints</code> object that represents * the rendering hints of this <code>RenderContext</code>. * @see #setRenderingHints(RenderingHints) */ public RenderingHints getRenderingHints() { return hints; } /** * Sets the rendering hints of this <code>RenderContext</code>. * @param hints a <code>RenderingHints</code> object that represents * the rendering hints to assign to this <code>RenderContext</code>. * @see #getRenderingHints */ public void setRenderingHints(RenderingHints hints) { this.hints = hints; } /** * Sets the current user-to-device AffineTransform contained * in the RenderContext to a given transform. * * @param newTransform the new AffineTransform. * @see #getTransform */ public void setTransform(AffineTransform newTransform) { usr2dev = (AffineTransform)newTransform.clone(); } /** * Modifies the current user-to-device transform by prepending another * transform. In matrix notation the operation is: * <pre> * [this] = [modTransform] x [this] * </pre> * * @param modTransform the AffineTransform to prepend to the * current usr2dev transform. * @since 1.3 */ public void preConcatenateTransform(AffineTransform modTransform) { this.preConcetenateTransform(modTransform); } /** * Modifies the current user-to-device transform by prepending another * transform. In matrix notation the operation is: * <pre> * [this] = [modTransform] x [this] * </pre> * This method does the same thing as the preConcatenateTransform * method. It is here for backward compatibility with previous releases * which misspelled the method name. * * @param modTransform the AffineTransform to prepend to the * current usr2dev transform. * @deprecated replaced by * <code>preConcatenateTransform(AffineTransform)</code>. */ @Deprecated public void preConcetenateTransform(AffineTransform modTransform) { usr2dev.preConcatenate(modTransform); } /** * Modifies the current user-to-device transform by appending another * transform. In matrix notation the operation is: * <pre> * [this] = [this] x [modTransform] * </pre> * * @param modTransform the AffineTransform to append to the * current usr2dev transform. * @since 1.3 */ public void concatenateTransform(AffineTransform modTransform) { this.concetenateTransform(modTransform); } /** * Modifies the current user-to-device transform by appending another * transform. In matrix notation the operation is: * <pre> * [this] = [this] x [modTransform] * </pre> * This method does the same thing as the concatenateTransform * method. It is here for backward compatibility with previous releases * which misspelled the method name. * * @param modTransform the AffineTransform to append to the * current usr2dev transform. * @deprecated replaced by * <code>concatenateTransform(AffineTransform)</code>. */ @Deprecated public void concetenateTransform(AffineTransform modTransform) { usr2dev.concatenate(modTransform); } /** * Gets the current user-to-device AffineTransform. * * @return a reference to the current AffineTransform. * @see #setTransform(AffineTransform) */ public AffineTransform getTransform() { return (AffineTransform)usr2dev.clone(); } /** * Sets the current area of interest. The old area is discarded. * * @param newAoi The new area of interest. * @see #getAreaOfInterest */ public void setAreaOfInterest(Shape newAoi) { aoi = newAoi; } /** * Gets the ares of interest currently contained in the * RenderContext. * * @return a reference to the area of interest of the RenderContext, * or null if none is specified. * @see #setAreaOfInterest(Shape) */ public Shape getAreaOfInterest() { return aoi; } /** * Makes a copy of a RenderContext. The area of interest is copied * by reference. The usr2dev AffineTransform and hints are cloned, * while the area of interest is copied by reference. * * @return the new cloned RenderContext. */ public Object clone() { RenderContext newRenderContext = new RenderContext(usr2dev, aoi, hints); return newRenderContext; } }