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. *** COPYRIGHT (c) Eastman Kodak Company, 1997 ***
  11. *** As an unpublished work pursuant to Title 17 of the United ***
  12. *** States Code. All rights reserved. ***
  13. **********************************************************************
  14. **********************************************************************
  15. **********************************************************************/
  16. package java.awt.image.renderable;
  17. import java.util.*;
  18. import java.awt.geom.*;
  19. import java.awt.*;
  20. import java.awt.image.*;
  21. /**
  22. * A RenderContext encapsulates the information needed to produce a
  23. * specific rendering from a RenderableImage. It contains the area to
  24. * be rendered specified in rendering-independent terms, the
  25. * resolution at which the rendering is to be performed, and hints
  26. * used to control the rendering process.
  27. *
  28. * <p> Users create RenderContexts and pass them to the
  29. * RenderableImage via the createRendering method. Most of the methods of
  30. * RenderContexts are not meant to be used directly by applications,
  31. * but by the RenderableImage and operator classes to which it is
  32. * passed.
  33. *
  34. * <p> The AffineTransform parameter passed into and out of this class
  35. * are cloned. The RenderingHints and Shape parameters are not
  36. * necessarily cloneable and are therefore only reference copied.
  37. * Altering RenderingHints or Shape instances that are in use by
  38. * instances of RenderContext may have undesired side effects.
  39. */
  40. public class RenderContext implements Cloneable {
  41. /** Table of hints. May be null. */
  42. RenderingHints hints;
  43. /** Transform to convert user coordinates to device coordinates. */
  44. AffineTransform usr2dev;
  45. /** The area of interest. May be null. */
  46. Shape aoi;
  47. // Various constructors that allow different levels of
  48. // specificity. If the Shape is missing the whole renderable area
  49. // is assumed. If hints is missing no hints are assumed.
  50. /**
  51. * Constructs a RenderContext with a given transform.
  52. * The area of interest is supplied as a Shape,
  53. * and the rendering hints are supplied as a RenderingHints object.
  54. *
  55. * @param usr2dev an AffineTransform.
  56. * @param aoi a Shape representing the area of interest.
  57. * @param hints a RenderingHints object containing rendering hints.
  58. */
  59. public RenderContext(AffineTransform usr2dev,
  60. Shape aoi,
  61. RenderingHints hints) {
  62. this.hints = hints;
  63. this.aoi = aoi;
  64. this.usr2dev = (AffineTransform)usr2dev.clone();
  65. }
  66. /**
  67. * Constructs a RenderContext with a given transform.
  68. * The area of interest is taken to be the entire renderable area.
  69. * No rendering hints are used.
  70. *
  71. * @param usr2dev an AffineTransform.
  72. */
  73. public RenderContext(AffineTransform usr2dev) {
  74. this(usr2dev, null, null);
  75. }
  76. /**
  77. * Constructs a RenderContext with a given transform and rendering hints.
  78. * The area of interest is taken to be the entire renderable area.
  79. *
  80. * @param usr2dev an AffineTransform.
  81. * @param hints a RenderingHints object containing rendering hints.
  82. */
  83. public RenderContext(AffineTransform usr2dev, RenderingHints hints) {
  84. this(usr2dev, null, hints);
  85. }
  86. /**
  87. * Constructs a RenderContext with a given transform and area of interest.
  88. * The area of interest is supplied as a Shape.
  89. * No rendering hints are used.
  90. *
  91. * @param usr2dev an AffineTransform.
  92. * @param aoi a Shape representing the area of interest.
  93. */
  94. public RenderContext(AffineTransform usr2dev, Shape aoi) {
  95. this(usr2dev, aoi, null);
  96. }
  97. /**
  98. * Gets the rendering hints of this <code>RenderContext</code>.
  99. * @return a <code>RenderingHints</code> object that represents
  100. * the rendering hints of this <code>RenderContext</code>.
  101. * @see #setRenderingHints(RenderingHints)
  102. */
  103. public RenderingHints getRenderingHints() {
  104. return hints;
  105. }
  106. /**
  107. * Sets the rendering hints of this <code>RenderContext</code>.
  108. * @param hints a <code>RenderingHints</code> object that represents
  109. * the rendering hints to assign to this <code>RenderContext</code>.
  110. * @see #getRenderingHints
  111. */
  112. public void setRenderingHints(RenderingHints hints) {
  113. this.hints = hints;
  114. }
  115. /**
  116. * Sets the current user-to-device AffineTransform contained
  117. * in the RenderContext to a given transform.
  118. *
  119. * @param newTransform the new AffineTransform.
  120. * @see #getTransform
  121. */
  122. public void setTransform(AffineTransform newTransform) {
  123. usr2dev = (AffineTransform)newTransform.clone();
  124. }
  125. /**
  126. * Modifies the current user-to-device transform by prepending another
  127. * transform. In matrix notation the operation is:
  128. * <pre>
  129. * [this] = [modTransform] x [this]
  130. * </pre>
  131. *
  132. * @param modTransform the AffineTransform to prepend to the
  133. * current usr2dev transform.
  134. */
  135. public void preConcatenateTransform(AffineTransform modTransform) {
  136. this.preConcetenateTransform(modTransform);
  137. }
  138. /**
  139. * Modifies the current user-to-device transform by prepending another
  140. * transform. In matrix notation the operation is:
  141. * <pre>
  142. * [this] = [modTransform] x [this]
  143. * </pre>
  144. * This method does the same thing as the preConcatenateTransform
  145. * method. It is here for backward compatibility with previous releases
  146. * which misspelled the method name.
  147. *
  148. * @param modTransform the AffineTransform to prepend to the
  149. * current usr2dev transform.
  150. * @deprecated replaced by
  151. * <code>preConcatenateTransform(AffineTransform)</code>.
  152. */
  153. @Deprecated
  154. public void preConcetenateTransform(AffineTransform modTransform) {
  155. usr2dev.preConcatenate(modTransform);
  156. }
  157. /**
  158. * Modifies the current user-to-device transform by appending another
  159. * transform. In matrix notation the operation is:
  160. * <pre>
  161. * [this] = [this] x [modTransform]
  162. * </pre>
  163. *
  164. * @param modTransform the AffineTransform to append to the
  165. * current usr2dev transform.
  166. */
  167. public void concatenateTransform(AffineTransform modTransform) {
  168. this.concetenateTransform(modTransform);
  169. }
  170. /**
  171. * Modifies the current user-to-device transform by appending another
  172. * transform. In matrix notation the operation is:
  173. * <pre>
  174. * [this] = [this] x [modTransform]
  175. * </pre>
  176. * This method does the same thing as the concatenateTransform
  177. * method. It is here for backward compatibility with previous releases
  178. * which misspelled the method name.
  179. *
  180. * @param modTransform the AffineTransform to append to the
  181. * current usr2dev transform.
  182. * @deprecated replaced by
  183. * <code>concatenateTransform(AffineTransform)</code>.
  184. */
  185. @Deprecated
  186. public void concetenateTransform(AffineTransform modTransform) {
  187. usr2dev.concatenate(modTransform);
  188. }
  189. /**
  190. * Gets the current user-to-device AffineTransform.
  191. *
  192. * @return a reference to the current AffineTransform.
  193. * @see #setTransform(AffineTransform)
  194. */
  195. public AffineTransform getTransform() {
  196. return (AffineTransform)usr2dev.clone();
  197. }
  198. /**
  199. * Sets the current area of interest. The old area is discarded.
  200. *
  201. * @param newAoi The new area of interest.
  202. * @see #getAreaOfInterest
  203. */
  204. public void setAreaOfInterest(Shape newAoi) {
  205. aoi = newAoi;
  206. }
  207. /**
  208. * Gets the ares of interest currently contained in the
  209. * RenderContext.
  210. *
  211. * @return a reference to the area of interest of the RenderContext,
  212. * or null if none is specified.
  213. * @see #setAreaOfInterest(Shape)
  214. */
  215. public Shape getAreaOfInterest() {
  216. return aoi;
  217. }
  218. /**
  219. * Makes a copy of a RenderContext. The area of interest is copied
  220. * by reference. The usr2dev AffineTransform and hints are cloned,
  221. * while the area of interest is copied by reference.
  222. *
  223. * @return the new cloned RenderContext.
  224. */
  225. public Object clone() {
  226. RenderContext newRenderContext = new RenderContext(usr2dev,
  227. aoi, hints);
  228. return newRenderContext;
  229. }
  230. }