1. /*
  2. * @(#)RenderContext.java 1.8 01/11/29
  3. *
  4. * Copyright 2002 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. */
  102. public RenderingHints getRenderingHints() {
  103. return hints;
  104. }
  105. /**
  106. * Sets the rendering hints of this <code>RenderContext</code>.
  107. * @param hints a <code>RenderingHints</code> object that represents
  108. * the rendering hints to assign to this <code>RenderContext</code>.
  109. */
  110. public void setRenderingHints(RenderingHints hints) {
  111. this.hints = hints;
  112. }
  113. /**
  114. * Sets the current user-to-device AffineTransform contained
  115. * in the RenderContext to a given transform.
  116. *
  117. * @param newTransform the new AffineTransform.
  118. */
  119. public void setTransform(AffineTransform newTransform) {
  120. usr2dev = (AffineTransform)newTransform.clone();
  121. }
  122. /**
  123. * Modifies the current user-to-device transform by prepending another
  124. * transform. In matrix notation the operation is:
  125. * <pre>
  126. * [this] = [modTransform] x [this]
  127. * </pre>
  128. *
  129. * @param modTransform the AffineTransform to prepend to the
  130. * current usr2dev transform.
  131. */
  132. public void preConcetenateTransform(AffineTransform modTransform) {
  133. usr2dev.preConcatenate(modTransform);
  134. }
  135. /**
  136. * Modifies the current user-to-device transform by appending another
  137. * transform. In matrix notation the operation is:
  138. * <pre>
  139. * [this] = [this] x [modTransform]
  140. * </pre>
  141. *
  142. * @param modTransform the AffineTransform to append to the
  143. * current usr2dev transform.
  144. */
  145. public void concetenateTransform(AffineTransform modTransform) {
  146. usr2dev.concatenate(modTransform);
  147. }
  148. /**
  149. * Gets the current user-to-device AffineTransform.
  150. *
  151. * @return a reference to the current AffineTransform.
  152. */
  153. public AffineTransform getTransform() {
  154. return (AffineTransform)usr2dev.clone();
  155. }
  156. /**
  157. * Sets the current area of interest. The old area is discarded.
  158. *
  159. * @param newAoi The new area of interest.
  160. */
  161. public void setAreaOfInterest(Shape newAoi) {
  162. aoi = newAoi;
  163. }
  164. /**
  165. * Gets the ares of interest currently contained in the
  166. * RenderContext.
  167. *
  168. * @return a reference to the area of interest of the RenderContext,
  169. * or null if none is specified.
  170. */
  171. public Shape getAreaOfInterest() {
  172. return aoi;
  173. }
  174. /**
  175. * Makes a copy of a RenderContext. The area of interest is copied
  176. * by reference. The usr2dev AffineTransform and hints are cloned,
  177. * while the area of interest is copied by reference.
  178. *
  179. * @return the new cloned RenderContext.
  180. */
  181. public Object clone() {
  182. RenderContext newRenderContext = new RenderContext(usr2dev,
  183. aoi, hints);
  184. return newRenderContext;
  185. }
  186. }