1. /*
  2. * @(#)RenderContext.java 1.11 00/02/02
  3. *
  4. * Copyright 1998-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. /* ********************************************************************
  11. **********************************************************************
  12. **********************************************************************
  13. *** COPYRIGHT (c) Eastman Kodak Company, 1997 ***
  14. *** As an unpublished work pursuant to Title 17 of the United ***
  15. *** States Code. All rights reserved. ***
  16. **********************************************************************
  17. **********************************************************************
  18. **********************************************************************/
  19. package java.awt.image.renderable;
  20. import java.util.*;
  21. import java.awt.geom.*;
  22. import java.awt.*;
  23. import java.awt.image.*;
  24. /**
  25. * A RenderContext encapsulates the information needed to produce a
  26. * specific rendering from a RenderableImage. It contains the area to
  27. * be rendered specified in rendering-independent terms, the
  28. * resolution at which the rendering is to be performed, and hints
  29. * used to control the rendering process.
  30. *
  31. * <p> Users create RenderContexts and pass them to the
  32. * RenderableImage via the createRendering method. Most of the methods of
  33. * RenderContexts are not meant to be used directly by applications,
  34. * but by the RenderableImage and operator classes to which it is
  35. * passed.
  36. *
  37. * <p> The AffineTransform parameter passed into and out of this class
  38. * are cloned. The RenderingHints and Shape parameters are not
  39. * necessarily cloneable and are therefore only reference copied.
  40. * Altering RenderingHints or Shape instances that are in use by
  41. * instances of RenderContext may have undesired side effects.
  42. */
  43. public class RenderContext implements Cloneable {
  44. /** Table of hints. May be null. */
  45. RenderingHints hints;
  46. /** Transform to convert user coordinates to device coordinates. */
  47. AffineTransform usr2dev;
  48. /** The area of interest. May be null. */
  49. Shape aoi;
  50. // Various constructors that allow different levels of
  51. // specificity. If the Shape is missing the whole renderable area
  52. // is assumed. If hints is missing no hints are assumed.
  53. /**
  54. * Constructs a RenderContext with a given transform.
  55. * The area of interest is supplied as a Shape,
  56. * and the rendering hints are supplied as a RenderingHints object.
  57. *
  58. * @param usr2dev an AffineTransform.
  59. * @param aoi a Shape representing the area of interest.
  60. * @param hints a RenderingHints object containing rendering hints.
  61. */
  62. public RenderContext(AffineTransform usr2dev,
  63. Shape aoi,
  64. RenderingHints hints) {
  65. this.hints = hints;
  66. this.aoi = aoi;
  67. this.usr2dev = (AffineTransform)usr2dev.clone();
  68. }
  69. /**
  70. * Constructs a RenderContext with a given transform.
  71. * The area of interest is taken to be the entire renderable area.
  72. * No rendering hints are used.
  73. *
  74. * @param usr2dev an AffineTransform.
  75. */
  76. public RenderContext(AffineTransform usr2dev) {
  77. this(usr2dev, null, null);
  78. }
  79. /**
  80. * Constructs a RenderContext with a given transform and rendering hints.
  81. * The area of interest is taken to be the entire renderable area.
  82. *
  83. * @param usr2dev an AffineTransform.
  84. * @param hints a RenderingHints object containing rendering hints.
  85. */
  86. public RenderContext(AffineTransform usr2dev, RenderingHints hints) {
  87. this(usr2dev, null, hints);
  88. }
  89. /**
  90. * Constructs a RenderContext with a given transform and area of interest.
  91. * The area of interest is supplied as a Shape.
  92. * No rendering hints are used.
  93. *
  94. * @param usr2dev an AffineTransform.
  95. * @param aoi a Shape representing the area of interest.
  96. */
  97. public RenderContext(AffineTransform usr2dev, Shape aoi) {
  98. this(usr2dev, aoi, null);
  99. }
  100. /**
  101. * Gets the rendering hints of this <code>RenderContext</code>.
  102. * @return a <code>RenderingHints</code> object that represents
  103. * the rendering hints of this <code>RenderContext</code>.
  104. */
  105. public RenderingHints getRenderingHints() {
  106. return hints;
  107. }
  108. /**
  109. * Sets the rendering hints of this <code>RenderContext</code>.
  110. * @param hints a <code>RenderingHints</code> object that represents
  111. * the rendering hints to assign to this <code>RenderContext</code>.
  112. */
  113. public void setRenderingHints(RenderingHints hints) {
  114. this.hints = hints;
  115. }
  116. /**
  117. * Sets the current user-to-device AffineTransform contained
  118. * in the RenderContext to a given transform.
  119. *
  120. * @param newTransform the new AffineTransform.
  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. */
  192. public AffineTransform getTransform() {
  193. return (AffineTransform)usr2dev.clone();
  194. }
  195. /**
  196. * Sets the current area of interest. The old area is discarded.
  197. *
  198. * @param newAoi The new area of interest.
  199. */
  200. public void setAreaOfInterest(Shape newAoi) {
  201. aoi = newAoi;
  202. }
  203. /**
  204. * Gets the ares of interest currently contained in the
  205. * RenderContext.
  206. *
  207. * @return a reference to the area of interest of the RenderContext,
  208. * or null if none is specified.
  209. */
  210. public Shape getAreaOfInterest() {
  211. return aoi;
  212. }
  213. /**
  214. * Makes a copy of a RenderContext. The area of interest is copied
  215. * by reference. The usr2dev AffineTransform and hints are cloned,
  216. * while the area of interest is copied by reference.
  217. *
  218. * @return the new cloned RenderContext.
  219. */
  220. public Object clone() {
  221. RenderContext newRenderContext = new RenderContext(usr2dev,
  222. aoi, hints);
  223. return newRenderContext;
  224. }
  225. }