1. /*
  2. * @(#)RenderContext.java 1.14 03/01/23
  3. *
  4. * Copyright 2003 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. public void preConcetenateTransform(AffineTransform modTransform) {
  154. usr2dev.preConcatenate(modTransform);
  155. }
  156. /**
  157. * Modifies the current user-to-device transform by appending another
  158. * transform. In matrix notation the operation is:
  159. * <pre>
  160. * [this] = [this] x [modTransform]
  161. * </pre>
  162. *
  163. * @param modTransform the AffineTransform to append to the
  164. * current usr2dev transform.
  165. */
  166. public void concatenateTransform(AffineTransform modTransform) {
  167. this.concetenateTransform(modTransform);
  168. }
  169. /**
  170. * Modifies the current user-to-device transform by appending another
  171. * transform. In matrix notation the operation is:
  172. * <pre>
  173. * [this] = [this] x [modTransform]
  174. * </pre>
  175. * This method does the same thing as the concatenateTransform
  176. * method. It is here for backward compatibility with previous releases
  177. * which misspelled the method name.
  178. *
  179. * @param modTransform the AffineTransform to append to the
  180. * current usr2dev transform.
  181. * @deprecated replaced by
  182. * <code>concatenateTransform(AffineTransform)</code>.
  183. */
  184. public void concetenateTransform(AffineTransform modTransform) {
  185. usr2dev.concatenate(modTransform);
  186. }
  187. /**
  188. * Gets the current user-to-device AffineTransform.
  189. *
  190. * @return a reference to the current AffineTransform.
  191. * @see #setTransform(AffineTransform)
  192. */
  193. public AffineTransform getTransform() {
  194. return (AffineTransform)usr2dev.clone();
  195. }
  196. /**
  197. * Sets the current area of interest. The old area is discarded.
  198. *
  199. * @param newAoi The new area of interest.
  200. * @see #getAreaOfInterest
  201. */
  202. public void setAreaOfInterest(Shape newAoi) {
  203. aoi = newAoi;
  204. }
  205. /**
  206. * Gets the ares of interest currently contained in the
  207. * RenderContext.
  208. *
  209. * @return a reference to the area of interest of the RenderContext,
  210. * or null if none is specified.
  211. * @see #setAreaOfInterest(Shape)
  212. */
  213. public Shape getAreaOfInterest() {
  214. return aoi;
  215. }
  216. /**
  217. * Makes a copy of a RenderContext. The area of interest is copied
  218. * by reference. The usr2dev AffineTransform and hints are cloned,
  219. * while the area of interest is copied by reference.
  220. *
  221. * @return the new cloned RenderContext.
  222. */
  223. public Object clone() {
  224. RenderContext newRenderContext = new RenderContext(usr2dev,
  225. aoi, hints);
  226. return newRenderContext;
  227. }
  228. }