1. /*
  2. * @(#)Graphics2D.java 1.81 04/05/05
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.awt;
  8. import java.awt.RenderingHints.Key;
  9. import java.awt.geom.AffineTransform;
  10. import java.awt.image.ImageObserver;
  11. import java.awt.image.BufferedImageOp;
  12. import java.awt.image.BufferedImage;
  13. import java.awt.image.RenderedImage;
  14. import java.awt.image.renderable.RenderableImage;
  15. import java.awt.font.GlyphVector;
  16. import java.awt.font.FontRenderContext;
  17. import java.awt.font.TextAttribute;
  18. import java.text.AttributedCharacterIterator;
  19. import java.util.Map;
  20. /**
  21. * This <code>Graphics2D</code> class extends the
  22. * {@link Graphics} class to provide more sophisticated
  23. * control over geometry, coordinate transformations, color management,
  24. * and text layout. This is the fundamental class for rendering
  25. * 2-dimensional shapes, text and images on the Java(tm) platform.
  26. * <p>
  27. * <h2>Coordinate Spaces</h2>
  28. * All coordinates passed to a <code>Graphics2D</code> object are specified
  29. * in a device-independent coordinate system called User Space, which is
  30. * used by applications. The <code>Graphics2D</code> object contains
  31. * an {@link AffineTransform} object as part of its rendering state
  32. * that defines how to convert coordinates from user space to
  33. * device-dependent coordinates in Device Space.
  34. * <p>
  35. * Coordinates in device space usually refer to individual device pixels
  36. * and are aligned on the infinitely thin gaps between these pixels.
  37. * Some <code>Graphics2D</code> objects can be used to capture rendering
  38. * operations for storage into a graphics metafile for playback on a
  39. * concrete device of unknown physical resolution at a later time. Since
  40. * the resolution might not be known when the rendering operations are
  41. * captured, the <code>Graphics2D</code> <code>Transform</code> is set up
  42. * to transform user coordinates to a virtual device space that
  43. * approximates the expected resolution of the target device. Further
  44. * transformations might need to be applied at playback time if the
  45. * estimate is incorrect.
  46. * <p>
  47. * Some of the operations performed by the rendering attribute objects
  48. * occur in the device space, but all <code>Graphics2D</code> methods take
  49. * user space coordinates.
  50. * <p>
  51. * Every <code>Graphics2D</code> object is associated with a target that
  52. * defines where rendering takes place. A
  53. * {@link GraphicsConfiguration} object defines the characteristics
  54. * of the rendering target, such as pixel format and resolution.
  55. * The same rendering target is used throughout the life of a
  56. * <code>Graphics2D</code> object.
  57. * <p>
  58. * When creating a <code>Graphics2D</code> object, the
  59. * <code>GraphicsConfiguration</code>
  60. * specifies the <a name="#deftransform">default transform</a> for
  61. * the target of the <code>Graphics2D</code> (a
  62. * {@link Component} or {@link Image}). This default transform maps the
  63. * user space coordinate system to screen and printer device coordinates
  64. * such that the origin maps to the upper left hand corner of the
  65. * target region of the device with increasing X coordinates extending
  66. * to the right and increasing Y coordinates extending downward.
  67. * The scaling of the default transform is set to identity for those devices
  68. * that are close to 72 dpi, such as screen devices.
  69. * The scaling of the default transform is set to approximately 72 user
  70. * space coordinates per square inch for high resolution devices, such as
  71. * printers. For image buffers, the default transform is the
  72. * <code>Identity</code> transform.
  73. *
  74. * <h2>Rendering Process</h2>
  75. * The Rendering Process can be broken down into four phases that are
  76. * controlled by the <code>Graphics2D</code> rendering attributes.
  77. * The renderer can optimize many of these steps, either by caching the
  78. * results for future calls, by collapsing multiple virtual steps into
  79. * a single operation, or by recognizing various attributes as common
  80. * simple cases that can be eliminated by modifying other parts of the
  81. * operation.
  82. * <p>
  83. * The steps in the rendering process are:
  84. * <ol>
  85. * <li>
  86. * Determine what to render.
  87. * <li>
  88. * Constrain the rendering operation to the current <code>Clip</code>.
  89. * The <code>Clip</code> is specified by a {@link Shape} in user
  90. * space and is controlled by the program using the various clip
  91. * manipulation methods of <code>Graphics</code> and
  92. * <code>Graphics2D</code>. This <i>user clip</i>
  93. * is transformed into device space by the current
  94. * <code>Transform</code> and combined with the
  95. * <i>device clip</i>, which is defined by the visibility of windows and
  96. * device extents. The combination of the user clip and device clip
  97. * defines the <i>composite clip</i>, which determines the final clipping
  98. * region. The user clip is not modified by the rendering
  99. * system to reflect the resulting composite clip.
  100. * <li>
  101. * Determine what colors to render.
  102. * <li>
  103. * Apply the colors to the destination drawing surface using the current
  104. * {@link Composite} attribute in the <code>Graphics2D</code> context.
  105. * </ol>
  106. * <br>
  107. * The three types of rendering operations, along with details of each
  108. * of their particular rendering processes are:
  109. * <ol>
  110. * <li>
  111. * <b><a name="rendershape"><code>Shape</code> operations</a></b>
  112. * <ol>
  113. * <li>
  114. * If the operation is a <code>draw(Shape)</code> operation, then
  115. * the {@link Stroke#createStrokedShape(Shape) createStrokedShape}
  116. * method on the current {@link Stroke} attribute in the
  117. * <code>Graphics2D</code> context is used to construct a new
  118. * <code>Shape</code> object that contains the outline of the specified
  119. * <code>Shape</code>.
  120. * <li>
  121. * The <code>Shape</code> is transformed from user space to device space
  122. * using the current <code>Transform</code>
  123. * in the <code>Graphics2D</code> context.
  124. * <li>
  125. * The outline of the <code>Shape</code> is extracted using the
  126. * {@link Shape#getPathIterator(AffineTransform) getPathIterator} method of
  127. * <code>Shape</code>, which returns a
  128. * {@link java.awt.geom.PathIterator PathIterator}
  129. * object that iterates along the boundary of the <code>Shape</code>.
  130. * <li>
  131. * If the <code>Graphics2D</code> object cannot handle the curved segments
  132. * that the <code>PathIterator</code> object returns then it can call the
  133. * alternate
  134. * {@link Shape#getPathIterator(AffineTransform, double) getPathIterator}
  135. * method of <code>Shape</code>, which flattens the <code>Shape</code>.
  136. * <li>
  137. * The current {@link Paint} in the <code>Graphics2D</code> context
  138. * is queried for a {@link PaintContext}, which specifies the
  139. * colors to render in device space.
  140. * </ol>
  141. * <li>
  142. * <b><a name=rendertext>Text operations</a></b>
  143. * <ol>
  144. * <li>
  145. * The following steps are used to determine the set of glyphs required
  146. * to render the indicated <code>String</code>:
  147. * <ol>
  148. * <li>
  149. * If the argument is a <code>String</code>, then the current
  150. * <code>Font</code> in the <code>Graphics2D</code> context is asked to
  151. * convert the Unicode characters in the <code>String</code> into a set of
  152. * glyphs for presentation with whatever basic layout and shaping
  153. * algorithms the font implements.
  154. * <li>
  155. * If the argument is an
  156. * {@link AttributedCharacterIterator},
  157. * the iterator is asked to convert itself to a
  158. * {@link java.awt.font.TextLayout TextLayout}
  159. * using its embedded font attributes. The <code>TextLayout</code>
  160. * implements more sophisticated glyph layout algorithms that
  161. * perform Unicode bi-directional layout adjustments automatically
  162. * for multiple fonts of differing writing directions.
  163. * <li>
  164. * If the argument is a
  165. * {@link GlyphVector}, then the
  166. * <code>GlyphVector</code> object already contains the appropriate
  167. * font-specific glyph codes with explicit coordinates for the position of
  168. * each glyph.
  169. * </ol>
  170. * <li>
  171. * The current <code>Font</code> is queried to obtain outlines for the
  172. * indicated glyphs. These outlines are treated as shapes in user space
  173. * relative to the position of each glyph that was determined in step 1.
  174. * <li>
  175. * The character outlines are filled as indicated above
  176. * under <a href="#rendershape"><code>Shape</code> operations</a>.
  177. * <li>
  178. * The current <code>Paint</code> is queried for a
  179. * <code>PaintContext</code>, which specifies
  180. * the colors to render in device space.
  181. * </ol>
  182. * <li>
  183. * <b><a name= renderingimage><code>Image</code> Operations</a></b>
  184. * <ol>
  185. * <li>
  186. * The region of interest is defined by the bounding box of the source
  187. * <code>Image</code>.
  188. * This bounding box is specified in Image Space, which is the
  189. * <code>Image</code> object's local coordinate system.
  190. * <li>
  191. * If an <code>AffineTransform</code> is passed to
  192. * {@link #drawImage(java.awt.Image, java.awt.geom.AffineTransform, java.awt.image.ImageObserver) drawImage(Image, AffineTransform, ImageObserver)},
  193. * the <code>AffineTransform</code> is used to transform the bounding
  194. * box from image space to user space. If no <code>AffineTransform</code>
  195. * is supplied, the bounding box is treated as if it is already in user space.
  196. * <li>
  197. * The bounding box of the source <code>Image</code> is transformed from user
  198. * space into device space using the current <code>Transform</code>.
  199. * Note that the result of transforming the bounding box does not
  200. * necessarily result in a rectangular region in device space.
  201. * <li>
  202. * The <code>Image</code> object determines what colors to render,
  203. * sampled according to the source to destination
  204. * coordinate mapping specified by the current <code>Transform</code> and the
  205. * optional image transform.
  206. * </ol>
  207. * </ol>
  208. *
  209. * <h2>Default Rendering Attributes</h2>
  210. * The default values for the <code>Graphics2D</code> rendering attributes are:
  211. * <dl compact>
  212. * <dt><i><code>Paint</code></i>
  213. * <dd>The color of the <code>Component</code>.
  214. * <dt><i><code>Font</code></i>
  215. * <dd>The <code>Font</code> of the <code>Component</code>.
  216. * <dt><i><code>Stroke</code></i>
  217. * <dd>A square pen with a linewidth of 1, no dashing, miter segment joins
  218. * and square end caps.
  219. * <dt><i><code>Transform</code></i>
  220. * <dd>The
  221. * {@link GraphicsConfiguration#getDefaultTransform() getDefaultTransform}
  222. * for the <code>GraphicsConfiguration</code> of the <code>Component</code>.
  223. * <dt><i><code>Composite</code></i>
  224. * <dd>The {@link AlphaComposite#SRC_OVER} rule.
  225. * <dt><i><code>Clip</code></i>
  226. * <dd>No rendering <code>Clip</code>, the output is clipped to the
  227. * <code>Component</code>.
  228. * </dl>
  229. *
  230. * <h2>Rendering Compatibility Issues</h2>
  231. * The JDK(tm) 1.1 rendering model is based on a pixelization model
  232. * that specifies that coordinates
  233. * are infinitely thin, lying between the pixels. Drawing operations are
  234. * performed using a one-pixel wide pen that fills the
  235. * pixel below and to the right of the anchor point on the path.
  236. * The JDK 1.1 rendering model is consistent with the
  237. * capabilities of most of the existing class of platform
  238. * renderers that need to resolve integer coordinates to a
  239. * discrete pen that must fall completely on a specified number of pixels.
  240. * <p>
  241. * The Java 2D(tm) (Java(tm) 2 platform) API supports antialiasing renderers.
  242. * A pen with a width of one pixel does not need to fall
  243. * completely on pixel N as opposed to pixel N+1. The pen can fall
  244. * partially on both pixels. It is not necessary to choose a bias
  245. * direction for a wide pen since the blending that occurs along the
  246. * pen traversal edges makes the sub-pixel position of the pen
  247. * visible to the user. On the other hand, when antialiasing is
  248. * turned off by setting the
  249. * {@link RenderingHints#KEY_ANTIALIASING KEY_ANTIALIASING} hint key
  250. * to the
  251. * {@link RenderingHints#VALUE_ANTIALIAS_OFF VALUE_ANTIALIAS_OFF}
  252. * hint value, the renderer might need
  253. * to apply a bias to determine which pixel to modify when the pen
  254. * is straddling a pixel boundary, such as when it is drawn
  255. * along an integer coordinate in device space. While the capabilities
  256. * of an antialiasing renderer make it no longer necessary for the
  257. * rendering model to specify a bias for the pen, it is desirable for the
  258. * antialiasing and non-antialiasing renderers to perform similarly for
  259. * the common cases of drawing one-pixel wide horizontal and vertical
  260. * lines on the screen. To ensure that turning on antialiasing by
  261. * setting the
  262. * {@link RenderingHints#KEY_ANTIALIASING KEY_ANTIALIASING} hint
  263. * key to
  264. * {@link RenderingHints#VALUE_ANTIALIAS_ON VALUE_ANTIALIAS_ON}
  265. * does not cause such lines to suddenly become twice as wide and half
  266. * as opaque, it is desirable to have the model specify a path for such
  267. * lines so that they completely cover a particular set of pixels to help
  268. * increase their crispness.
  269. * <p>
  270. * Java 2D API maintains compatibility with JDK 1.1 rendering
  271. * behavior, such that legacy operations and existing renderer
  272. * behavior is unchanged under Java 2D API. Legacy
  273. * methods that map onto general <code>draw</code> and
  274. * <code>fill</code> methods are defined, which clearly indicates
  275. * how <code>Graphics2D</code> extends <code>Graphics</code> based
  276. * on settings of <code>Stroke</code> and <code>Transform</code>
  277. * attributes and rendering hints. The definition
  278. * performs identically under default attribute settings.
  279. * For example, the default <code>Stroke</code> is a
  280. * <code>BasicStroke</code> with a width of 1 and no dashing and the
  281. * default Transform for screen drawing is an Identity transform.
  282. * <p>
  283. * The following two rules provide predictable rendering behavior whether
  284. * aliasing or antialiasing is being used.
  285. * <ul>
  286. * <li> Device coordinates are defined to be between device pixels which
  287. * avoids any inconsistent results between aliased and antaliased
  288. * rendering. If coordinates were defined to be at a pixel's center, some
  289. * of the pixels covered by a shape, such as a rectangle, would only be
  290. * half covered.
  291. * With aliased rendering, the half covered pixels would either be
  292. * rendered inside the shape or outside the shape. With anti-aliased
  293. * rendering, the pixels on the entire edge of the shape would be half
  294. * covered. On the other hand, since coordinates are defined to be
  295. * between pixels, a shape like a rectangle would have no half covered
  296. * pixels, whether or not it is rendered using antialiasing.
  297. * <li> Lines and paths stroked using the <code>BasicStroke</code>
  298. * object may be "normalized" to provide consistent rendering of the
  299. * outlines when positioned at various points on the drawable and
  300. * whether drawn with aliased or antialiased rendering. This
  301. * normalization process is controlled by the
  302. * {@link RenderingHints#KEY_STROKE_CONTROL KEY_STROKE_CONTROL} hint.
  303. * The exact normalization algorithm is not specified, but the goals
  304. * of this normalization are to ensure that lines are rendered with
  305. * consistent visual appearance regardless of how they fall on the
  306. * pixel grid and to promote more solid horizontal and vertical
  307. * lines in antialiased mode so that they resemble their non-antialiased
  308. * counterparts more closely. A typical normalization step might
  309. * promote antialiased line endpoints to pixel centers to reduce the
  310. * amount of blending or adjust the subpixel positioning of
  311. * non-antialiased lines so that the floating point line widths
  312. * round to even or odd pixel counts with equal likelihood. This
  313. * process can move endpoints by up to half a pixel (usually towards
  314. * positive infinity along both axes) to promote these consistent
  315. * results.
  316. * </ul>
  317. * <p>
  318. * The following definitions of general legacy methods
  319. * perform identically to previously specified behavior under default
  320. * attribute settings:
  321. * <ul>
  322. * <li>
  323. * For <code>fill</code> operations, including <code>fillRect</code>,
  324. * <code>fillRoundRect</code>, <code>fillOval</code>,
  325. * <code>fillArc</code>, <code>fillPolygon</code>, and
  326. * <code>clearRect</code>, {@link #fill(Shape) fill} can now be called
  327. * with the desired <code>Shape</code>. For example, when filling a
  328. * rectangle:
  329. * <pre>
  330. * fill(new Rectangle(x, y, w, h));
  331. * </pre>
  332. * is called.
  333. * <p>
  334. * <li>
  335. * Similarly, for draw operations, including <code>drawLine</code>,
  336. * <code>drawRect</code>, <code>drawRoundRect</code>,
  337. * <code>drawOval</code>, <code>drawArc</code>, <code>drawPolyline</code>,
  338. * and <code>drawPolygon</code>, {@link #draw(Shape) draw} can now be
  339. * called with the desired <code>Shape</code>. For example, when drawing a
  340. * rectangle:
  341. * <pre>
  342. * draw(new Rectangle(x, y, w, h));
  343. * </pre>
  344. * is called.
  345. * <p>
  346. * <li>
  347. * The <code>draw3DRect</code> and <code>fill3DRect</code> methods were
  348. * implemented in terms of the <code>drawLine</code> and
  349. * <code>fillRect</code> methods in the <code>Graphics</code> class which
  350. * would predicate their behavior upon the current <code>Stroke</code>
  351. * and <code>Paint</code> objects in a <code>Graphics2D</code> context.
  352. * This class overrides those implementations with versions that use
  353. * the current <code>Color</code> exclusively, overriding the current
  354. * <code>Paint</code> and which uses <code>fillRect</code> to describe
  355. * the exact same behavior as the preexisting methods regardless of the
  356. * setting of the current <code>Stroke</code>.
  357. * </ul>
  358. * The <code>Graphics</code> class defines only the <code>setColor</code>
  359. * method to control the color to be painted. Since the Java 2D API extends
  360. * the <code>Color</code> object to implement the new <code>Paint</code>
  361. * interface, the existing
  362. * <code>setColor</code> method is now a convenience method for setting the
  363. * current <code>Paint</code> attribute to a <code>Color</code> object.
  364. * <code>setColor(c)</code> is equivalent to <code>setPaint(c)</code>.
  365. * <p>
  366. * The <code>Graphics</code> class defines two methods for controlling
  367. * how colors are applied to the destination.
  368. * <ol>
  369. * <li>
  370. * The <code>setPaintMode</code> method is implemented as a convenience
  371. * method to set the default <code>Composite</code>, equivalent to
  372. * <code>setComposite(new AlphaComposite.SrcOver)</code>.
  373. * <li>
  374. * The <code>setXORMode(Color xorcolor)</code> method is implemented
  375. * as a convenience method to set a special <code>Composite</code> object that
  376. * ignores the <code>Alpha</code> components of source colors and sets the
  377. * destination color to the value:
  378. * <pre>
  379. * dstpixel = (PixelOf(srccolor) ^ PixelOf(xorcolor) ^ dstpixel);
  380. * </pre>
  381. * </ol>
  382. *
  383. * @version 1.81, 05/05/04
  384. * @author Jim Graham
  385. * @see java.awt.RenderingHints
  386. */
  387. public abstract class Graphics2D extends Graphics {
  388. /**
  389. * Constructs a new <code>Graphics2D</code> object. Since
  390. * <code>Graphics2D</code> is an abstract class, and since it must be
  391. * customized by subclasses for different output devices,
  392. * <code>Graphics2D</code> objects cannot be created directly.
  393. * Instead, <code>Graphics2D</code> objects must be obtained from another
  394. * <code>Graphics2D</code> object, created by a
  395. * <code>Component</code>, or obtained from images such as
  396. * {@link BufferedImage} objects.
  397. * @see java.awt.Component#getGraphics
  398. * @see java.awt.Graphics#create
  399. */
  400. protected Graphics2D() {
  401. }
  402. /**
  403. * Draws a 3-D highlighted outline of the specified rectangle.
  404. * The edges of the rectangle are highlighted so that they
  405. * appear to be beveled and lit from the upper left corner.
  406. * <p>
  407. * The colors used for the highlighting effect are determined
  408. * based on the current color.
  409. * The resulting rectangle covers an area that is
  410. * <code>width + 1</code> pixels wide
  411. * by <code>height + 1</code> pixels tall. This method
  412. * uses the current <code>Color</code> exclusively and ignores
  413. * the current <code>Paint</code>.
  414. * @param x the x coordinate of the rectangle to be drawn.
  415. * @param y the y coordinate of the rectangle to be drawn.
  416. * @param width the width of the rectangle to be drawn.
  417. * @param height the height of the rectangle to be drawn.
  418. * @param raised a boolean that determines whether the rectangle
  419. * appears to be raised above the surface
  420. * or sunk into the surface.
  421. * @see java.awt.Graphics#fill3DRect
  422. */
  423. public void draw3DRect(int x, int y, int width, int height,
  424. boolean raised) {
  425. Paint p = getPaint();
  426. Color c = getColor();
  427. Color brighter = c.brighter();
  428. Color darker = c.darker();
  429. setColor(raised ? brighter : darker);
  430. //drawLine(x, y, x, y + height);
  431. fillRect(x, y, 1, height + 1);
  432. //drawLine(x + 1, y, x + width - 1, y);
  433. fillRect(x + 1, y, width - 1, 1);
  434. setColor(raised ? darker : brighter);
  435. //drawLine(x + 1, y + height, x + width, y + height);
  436. fillRect(x + 1, y + height, width, 1);
  437. //drawLine(x + width, y, x + width, y + height - 1);
  438. fillRect(x + width, y, 1, height);
  439. setPaint(p);
  440. }
  441. /**
  442. * Paints a 3-D highlighted rectangle filled with the current color.
  443. * The edges of the rectangle are highlighted so that it appears
  444. * as if the edges were beveled and lit from the upper left corner.
  445. * The colors used for the highlighting effect and for filling are
  446. * determined from the current <code>Color</code>. This method uses
  447. * the current <code>Color</code> exclusively and ignores the current
  448. * <code>Paint</code>.
  449. * @param x the x coordinate of the rectangle to be filled.
  450. * @param y the y coordinate of the rectangle to be filled.
  451. * @param width the width of the rectangle to be filled.
  452. * @param height the height of the rectangle to be filled.
  453. * @param raised a boolean value that determines whether the
  454. * rectangle appears to be raised above the surface
  455. * or etched into the surface.
  456. * @see java.awt.Graphics#draw3DRect
  457. */
  458. public void fill3DRect(int x, int y, int width, int height,
  459. boolean raised) {
  460. Paint p = getPaint();
  461. Color c = getColor();
  462. Color brighter = c.brighter();
  463. Color darker = c.darker();
  464. if (!raised) {
  465. setColor(darker);
  466. } else if (p != c) {
  467. setColor(c);
  468. }
  469. fillRect(x+1, y+1, width-2, height-2);
  470. setColor(raised ? brighter : darker);
  471. //drawLine(x, y, x, y + height - 1);
  472. fillRect(x, y, 1, height);
  473. //drawLine(x + 1, y, x + width - 2, y);
  474. fillRect(x + 1, y, width - 2, 1);
  475. setColor(raised ? darker : brighter);
  476. //drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1);
  477. fillRect(x + 1, y + height - 1, width - 1, 1);
  478. //drawLine(x + width - 1, y, x + width - 1, y + height - 2);
  479. fillRect(x + width - 1, y, 1, height - 1);
  480. setPaint(p);
  481. }
  482. /**
  483. * Strokes the outline of a <code>Shape</code> using the settings of the
  484. * current <code>Graphics2D</code> context. The rendering attributes
  485. * applied include the <code>Clip</code>, <code>Transform</code>,
  486. * <code>Paint</code>, <code>Composite</code> and
  487. * <code>Stroke</code> attributes.
  488. * @param s the <code>Shape</code> to be rendered
  489. * @see #setStroke
  490. * @see #setPaint
  491. * @see java.awt.Graphics#setColor
  492. * @see #transform
  493. * @see #setTransform
  494. * @see #clip
  495. * @see #setClip
  496. * @see #setComposite
  497. */
  498. public abstract void draw(Shape s);
  499. /**
  500. * Renders an image, applying a transform from image space into user space
  501. * before drawing.
  502. * The transformation from user space into device space is done with
  503. * the current <code>Transform</code> in the <code>Graphics2D</code>.
  504. * The specified transformation is applied to the image before the
  505. * transform attribute in the <code>Graphics2D</code> context is applied.
  506. * The rendering attributes applied include the <code>Clip</code>,
  507. * <code>Transform</code>, and <code>Composite</code> attributes.
  508. * Note that no rendering is done if the specified transform is
  509. * noninvertible.
  510. * @param img the specified image to be rendered.
  511. * This method does nothing if <code>img</code> is null.
  512. * @param xform the transformation from image space into user space
  513. * @param obs the {@link ImageObserver}
  514. * to be notified as more of the <code>Image</code>
  515. * is converted
  516. * @return <code>true</code> if the <code>Image</code> is
  517. * fully loaded and completely rendered, or if it's null;
  518. * <code>false</code> if the <code>Image</code> is still being loaded.
  519. * @see #transform
  520. * @see #setTransform
  521. * @see #setComposite
  522. * @see #clip
  523. * @see #setClip
  524. */
  525. public abstract boolean drawImage(Image img,
  526. AffineTransform xform,
  527. ImageObserver obs);
  528. /**
  529. * Renders a <code>BufferedImage</code> that is
  530. * filtered with a
  531. * {@link BufferedImageOp}.
  532. * The rendering attributes applied include the <code>Clip</code>,
  533. * <code>Transform</code>
  534. * and <code>Composite</code> attributes. This is equivalent to:
  535. * <pre>
  536. * img1 = op.filter(img, null);
  537. * drawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null);
  538. * </pre>
  539. * @param op the filter to be applied to the image before rendering
  540. * @param img the specified <code>BufferedImage</code> to be rendered.
  541. * This method does nothing if <code>img</code> is null.
  542. * @param x the x coordinate of the location in user space where
  543. * the upper left corner of the image is rendered
  544. * @param y the y coordinate of the location in user space where
  545. * the upper left corner of the image is rendered
  546. *
  547. * @see #transform
  548. * @see #setTransform
  549. * @see #setComposite
  550. * @see #clip
  551. * @see #setClip
  552. */
  553. public abstract void drawImage(BufferedImage img,
  554. BufferedImageOp op,
  555. int x,
  556. int y);
  557. /**
  558. * Renders a {@link RenderedImage},
  559. * applying a transform from image
  560. * space into user space before drawing.
  561. * The transformation from user space into device space is done with
  562. * the current <code>Transform</code> in the <code>Graphics2D</code>.
  563. * The specified transformation is applied to the image before the
  564. * transform attribute in the <code>Graphics2D</code> context is applied.
  565. * The rendering attributes applied include the <code>Clip</code>,
  566. * <code>Transform</code>, and <code>Composite</code> attributes. Note
  567. * that no rendering is done if the specified transform is
  568. * noninvertible.
  569. * @param img the image to be rendered. This method does
  570. * nothing if <code>img</code> is null.
  571. * @param xform the transformation from image space into user space
  572. * @see #transform
  573. * @see #setTransform
  574. * @see #setComposite
  575. * @see #clip
  576. * @see #setClip
  577. */
  578. public abstract void drawRenderedImage(RenderedImage img,
  579. AffineTransform xform);
  580. /**
  581. * Renders a
  582. * {@link RenderableImage},
  583. * applying a transform from image space into user space before drawing.
  584. * The transformation from user space into device space is done with
  585. * the current <code>Transform</code> in the <code>Graphics2D</code>.
  586. * The specified transformation is applied to the image before the
  587. * transform attribute in the <code>Graphics2D</code> context is applied.
  588. * The rendering attributes applied include the <code>Clip</code>,
  589. * <code>Transform</code>, and <code>Composite</code> attributes. Note
  590. * that no rendering is done if the specified transform is
  591. * noninvertible.
  592. *<p>
  593. * Rendering hints set on the <code>Graphics2D</code> object might
  594. * be used in rendering the <code>RenderableImage</code>.
  595. * If explicit control is required over specific hints recognized by a
  596. * specific <code>RenderableImage</code>, or if knowledge of which hints
  597. * are used is required, then a <code>RenderedImage</code> should be
  598. * obtained directly from the <code>RenderableImage</code>
  599. * and rendered using
  600. *{@link #drawRenderedImage(RenderedImage, AffineTransform) drawRenderedImage}.
  601. * @param img the image to be rendered. This method does
  602. * nothing if <code>img</code> is null.
  603. * @param xform the transformation from image space into user space
  604. * @see #transform
  605. * @see #setTransform
  606. * @see #setComposite
  607. * @see #clip
  608. * @see #setClip
  609. * @see #drawRenderedImage
  610. */
  611. public abstract void drawRenderableImage(RenderableImage img,
  612. AffineTransform xform);
  613. /**
  614. * Renders the text of the specified <code>String</code>, using the
  615. * current text attribute state in the <code>Graphics2D</code> context.
  616. * The baseline of the
  617. * first character is at position (<i>x</i>, <i>y</i>) in
  618. * the User Space.
  619. * The rendering attributes applied include the <code>Clip</code>,
  620. * <code>Transform</code>, <code>Paint</code>, <code>Font</code> and
  621. * <code>Composite</code> attributes. For characters in script
  622. * systems such as Hebrew and Arabic, the glyphs can be rendered from
  623. * right to left, in which case the coordinate supplied is the
  624. * location of the leftmost character on the baseline.
  625. * @param str the string to be rendered
  626. * @param x the x coordinate of the location where the
  627. * <code>String</code> should be rendered
  628. * @param y the y coordinate of the location where the
  629. * <code>String</code> should be rendered
  630. * @throws NullPointerException if <code>str</code> is
  631. * <code>null</code>
  632. * @see java.awt.Graphics#drawBytes
  633. * @see java.awt.Graphics#drawChars
  634. * @since JDK1.0
  635. */
  636. public abstract void drawString(String str, int x, int y);
  637. /**
  638. * Renders the text specified by the specified <code>String</code>,
  639. * using the current text attribute state in the <code>Graphics2D</code> context.
  640. * The baseline of the first character is at position
  641. * (<i>x</i>, <i>y</i>) in the User Space.
  642. * The rendering attributes applied include the <code>Clip</code>,
  643. * <code>Transform</code>, <code>Paint</code>, <code>Font</code> and
  644. * <code>Composite</code> attributes. For characters in script systems
  645. * such as Hebrew and Arabic, the glyphs can be rendered from right to
  646. * left, in which case the coordinate supplied is the location of the
  647. * leftmost character on the baseline.
  648. * @param s the <code>String</code> to be rendered
  649. * @param x the x coordinate of the location where the
  650. * <code>String</code> should be rendered
  651. * @param y the y coordinate of the location where the
  652. * <code>String</code> should be rendered
  653. * @throws NullPointerException if <code>str</code> is
  654. * <code>null</code>
  655. * @see #setPaint
  656. * @see java.awt.Graphics#setColor
  657. * @see java.awt.Graphics#setFont
  658. * @see #setTransform
  659. * @see #setComposite
  660. * @see #setClip
  661. */
  662. public abstract void drawString(String s, float x, float y);
  663. /**
  664. * Renders the text of the specified iterator, using the
  665. * <code>Graphics2D</code> context's current <code>Paint</code>. The
  666. * iterator has to specify a font
  667. * for each character. The baseline of the
  668. * first character is at position (<i>x</i>, <i>y</i>) in the
  669. * User Space.
  670. * The rendering attributes applied include the <code>Clip</code>,
  671. * <code>Transform</code>, <code>Paint</code>, and
  672. * <code>Composite</code> attributes.
  673. * For characters in script systems such as Hebrew and Arabic,
  674. * the glyphs can be rendered from right to left, in which case the
  675. * coordinate supplied is the location of the leftmost character
  676. * on the baseline.
  677. * @param iterator the iterator whose text is to be rendered
  678. * @param x the x coordinate where the iterator's text is to be
  679. * rendered
  680. * @param y the y coordinate where the iterator's text is to be
  681. * rendered
  682. * @see #setPaint
  683. * @see java.awt.Graphics#setColor
  684. * @see #setTransform
  685. * @see #setComposite
  686. * @see #setClip
  687. */
  688. public abstract void drawString(AttributedCharacterIterator iterator,
  689. int x, int y);
  690. /**
  691. * Renders the text of the specified iterator, using the
  692. * <code>Graphics2D</code> context's current <code>Paint</code>. The
  693. * iterator must specify a font
  694. * for each character. The baseline of the
  695. * first character is at position (<i>x</i>, <i>y</i>) in the
  696. * User Space.
  697. * The rendering attributes applied include the <code>Clip</code>,
  698. * <code>Transform</code>, <code>Paint</code>, and
  699. * <code>Composite</code> attributes.
  700. * For characters in script systems such as Hebrew and Arabic,
  701. * the glyphs can be rendered from right to left, in which case the
  702. * coordinate supplied is the location of the leftmost character
  703. * on the baseline.
  704. * @param iterator the iterator whose text is to be rendered
  705. * @param x the x coordinate where the iterator's text is to be
  706. * rendered
  707. * @param y the y coordinate where the iterator's text is to be
  708. * rendered
  709. * @see #setPaint
  710. * @see java.awt.Graphics#setColor
  711. * @see #setTransform
  712. * @see #setComposite
  713. * @see #setClip
  714. */
  715. public abstract void drawString(AttributedCharacterIterator iterator,
  716. float x, float y);
  717. /**
  718. * Renders the text of the specified
  719. * {@link GlyphVector} using
  720. * the <code>Graphics2D</code> context's rendering attributes.
  721. * The rendering attributes applied include the <code>Clip</code>,
  722. * <code>Transform</code>, <code>Paint</code>, and
  723. * <code>Composite</code> attributes. The <code>GlyphVector</code>
  724. * specifies individual glyphs from a {@link Font}.
  725. * The <code>GlyphVector</code> can also contain the glyph positions.
  726. * This is the fastest way to render a set of characters to the
  727. * screen.
  728. * @param g the <code>GlyphVector</code> to be rendered
  729. * @param x the x position in User Space where the glyphs should
  730. * be rendered
  731. * @param y the y position in User Space where the glyphs should
  732. * be rendered
  733. *
  734. * @see java.awt.Font#createGlyphVector
  735. * @see java.awt.font.GlyphVector
  736. * @see #setPaint
  737. * @see java.awt.Graphics#setColor
  738. * @see #setTransform
  739. * @see #setComposite
  740. * @see #setClip
  741. */
  742. public abstract void drawGlyphVector(GlyphVector g, float x, float y);
  743. /**
  744. * Fills the interior of a <code>Shape</code> using the settings of the
  745. * <code>Graphics2D</code> context. The rendering attributes applied
  746. * include the <code>Clip</code>, <code>Transform</code>,
  747. * <code>Paint</code>, and <code>Composite</code>.
  748. * @param s the <code>Shape</code> to be filled
  749. * @see #setPaint
  750. * @see java.awt.Graphics#setColor
  751. * @see #transform
  752. * @see #setTransform
  753. * @see #setComposite
  754. * @see #clip
  755. * @see #setClip
  756. */
  757. public abstract void fill(Shape s);
  758. /**
  759. * Checks whether or not the specified <code>Shape</code> intersects
  760. * the specified {@link Rectangle}, which is in device
  761. * space. If <code>onStroke</code> is false, this method checks
  762. * whether or not the interior of the specified <code>Shape</code>
  763. * intersects the specified <code>Rectangle</code>. If
  764. * <code>onStroke</code> is <code>true</code>, this method checks
  765. * whether or not the <code>Stroke</code> of the specified
  766. * <code>Shape</code> outline intersects the specified
  767. * <code>Rectangle</code>.
  768. * The rendering attributes taken into account include the
  769. * <code>Clip</code>, <code>Transform</code>, and <code>Stroke</code>
  770. * attributes.
  771. * @param rect the area in device space to check for a hit
  772. * @param s the <code>Shape</code> to check for a hit
  773. * @param onStroke flag used to choose between testing the
  774. * stroked or the filled shape. If the flag is <code>true</code>, the
  775. * <code>Stroke</code> oultine is tested. If the flag is
  776. * <code>false</code>, the filled <code>Shape</code> is tested.
  777. * @return <code>true</code> if there is a hit; <code>false</code>
  778. * otherwise.
  779. * @see #setStroke
  780. * @see #fill
  781. * @see #draw
  782. * @see #transform
  783. * @see #setTransform
  784. * @see #clip
  785. * @see #setClip
  786. */
  787. public abstract boolean hit(Rectangle rect,
  788. Shape s,
  789. boolean onStroke);
  790. /**
  791. * Returns the device configuration associated with this
  792. * <code>Graphics2D</code>.
  793. * @return the device configuration of this <code>Graphics2D</code>.
  794. */
  795. public abstract GraphicsConfiguration getDeviceConfiguration();
  796. /**
  797. * Sets the <code>Composite</code> for the <code>Graphics2D</code> context.
  798. * The <code>Composite</code> is used in all drawing methods such as
  799. * <code>drawImage</code>, <code>drawString</code>, <code>draw</code>,
  800. * and <code>fill</code>. It specifies how new pixels are to be combined
  801. * with the existing pixels on the graphics device during the rendering
  802. * process.
  803. * <p>If this <code>Graphics2D</code> context is drawing to a
  804. * <code>Component</code> on the display screen and the
  805. * <code>Composite</code> is a custom object rather than an
  806. * instance of the <code>AlphaComposite</code> class, and if
  807. * there is a security manager, its <code>checkPermission</code>
  808. * method is called with an <code>AWTPermission("readDisplayPixels")</code>
  809. * permission.
  810. * @throws SecurityException
  811. * if a custom <code>Composite</code> object is being
  812. * used to render to the screen and a security manager
  813. * is set and its <code>checkPermission</code> method
  814. * does not allow the operation.
  815. * @param comp the <code>Composite</code> object to be used for rendering
  816. * @see java.awt.Graphics#setXORMode
  817. * @see java.awt.Graphics#setPaintMode
  818. * @see #getComposite
  819. * @see AlphaComposite
  820. * @see SecurityManager#checkPermission
  821. * @see java.awt.AWTPermission
  822. */
  823. public abstract void setComposite(Composite comp);
  824. /**
  825. * Sets the <code>Paint</code> attribute for the
  826. * <code>Graphics2D</code> context. Calling this method
  827. * with a <code>null</code> <code>Paint</code> object does
  828. * not have any effect on the current <code>Paint</code> attribute
  829. * of this <code>Graphics2D</code>.
  830. * @param paint the <code>Paint</code> object to be used to generate
  831. * color during the rendering process, or <code>null</code>
  832. * @see java.awt.Graphics#setColor
  833. * @see #getPaint
  834. * @see GradientPaint
  835. * @see TexturePaint
  836. */
  837. public abstract void setPaint( Paint paint );
  838. /**
  839. * Sets the <code>Stroke</code> for the <code>Graphics2D</code> context.
  840. * @param s the <code>Stroke</code> object to be used to stroke a
  841. * <code>Shape</code> during the rendering process
  842. * @see BasicStroke
  843. * @see #getStroke
  844. */
  845. public abstract void setStroke(Stroke s);
  846. /**
  847. * Sets the value of a single preference for the rendering algorithms.
  848. * Hint categories include controls for rendering quality and overall
  849. * time/quality trade-off in the rendering process. Refer to the
  850. * <code>RenderingHints</code> class for definitions of some common
  851. * keys and values.
  852. * @param hintKey the key of the hint to be set.
  853. * @param hintValue the value indicating preferences for the specified
  854. * hint category.
  855. * @see #getRenderingHint(RenderingHints.Key)
  856. * @see RenderingHints
  857. */
  858. public abstract void setRenderingHint(Key hintKey, Object hintValue);
  859. /**
  860. * Returns the value of a single preference for the rendering algorithms.
  861. * Hint categories include controls for rendering quality and overall
  862. * time/quality trade-off in the rendering process. Refer to the
  863. * <code>RenderingHints</code> class for definitions of some common
  864. * keys and values.
  865. * @param hintKey the key corresponding to the hint to get.
  866. * @return an object representing the value for the specified hint key.
  867. * Some of the keys and their associated values are defined in the
  868. * <code>RenderingHints</code> class.
  869. * @see RenderingHints
  870. * @see #setRenderingHint(RenderingHints.Key, Object)
  871. */
  872. public abstract Object getRenderingHint(Key hintKey);
  873. /**
  874. * Replaces the values of all preferences for the rendering
  875. * algorithms with the specified <code>hints</code>.
  876. * The existing values for all rendering hints are discarded and
  877. * the new set of known hints and values are initialized from the
  878. * specified {@link Map} object.
  879. * Hint categories include controls for rendering quality and
  880. * overall time/quality trade-off in the rendering process.
  881. * Refer to the <code>RenderingHints</code> class for definitions of
  882. * some common keys and values.
  883. * @param hints the rendering hints to be set
  884. * @see #getRenderingHints
  885. * @see RenderingHints
  886. */
  887. public abstract void setRenderingHints(Map<?,?> hints);
  888. /**
  889. * Sets the values of an arbitrary number of preferences for the
  890. * rendering algorithms.
  891. * Only values for the rendering hints that are present in the
  892. * specified <code>Map</code> object are modified.
  893. * All other preferences not present in the specified
  894. * object are left unmodified.
  895. * Hint categories include controls for rendering quality and
  896. * overall time/quality trade-off in the rendering process.
  897. * Refer to the <code>RenderingHints</code> class for definitions of
  898. * some common keys and values.
  899. * @param hints the rendering hints to be set
  900. * @see RenderingHints
  901. */
  902. public abstract void addRenderingHints(Map<?,?> hints);
  903. /**
  904. * Gets the preferences for the rendering algorithms. Hint categories
  905. * include controls for rendering quality and overall time/quality
  906. * trade-off in the rendering process.
  907. * Returns all of the hint key/value pairs that were ever specified in
  908. * one operation. Refer to the
  909. * <code>RenderingHints</code> class for definitions of some common
  910. * keys and values.
  911. * @return a reference to an instance of <code>RenderingHints</code>
  912. * that contains the current preferences.
  913. * @see RenderingHints
  914. * @see #setRenderingHints(Map)
  915. */
  916. public abstract RenderingHints getRenderingHints();
  917. /**
  918. * Translates the origin of the <code>Graphics2D</code> context to the
  919. * point (<i>x</i>, <i>y</i>) in the current coordinate system.
  920. * Modifies the <code>Graphics2D</code> context so that its new origin
  921. * corresponds to the point (<i>x</i>, <i>y</i>) in the
  922. * <code>Graphics2D</code> context's former coordinate system. All
  923. * coordinates used in subsequent rendering operations on this graphics
  924. * context are relative to this new origin.
  925. * @param x the specified x coordinate
  926. * @param y the specified y coordinate
  927. * @since JDK1.0
  928. */
  929. public abstract void translate(int x, int y);
  930. /**
  931. * Concatenates the current
  932. * <code>Graphics2D</code> <code>Transform</code>
  933. * with a translation transform.
  934. * Subsequent rendering is translated by the specified
  935. * distance relative to the previous position.
  936. * This is equivalent to calling transform(T), where T is an
  937. * <code>AffineTransform</code> represented by the following matrix:
  938. * <pre>
  939. * [ 1 0 tx ]
  940. * [ 0 1 ty ]
  941. * [ 0 0 1 ]
  942. * </pre>
  943. * @param tx the distance to translate along the x-axis
  944. * @param ty the distance to translate along the y-axis
  945. */
  946. public abstract void translate(double tx, double ty);
  947. /**
  948. * Concatenates the current <code>Graphics2D</code>
  949. * <code>Transform</code> with a rotation transform.
  950. * Subsequent rendering is rotated by the specified radians relative
  951. * to the previous origin.
  952. * This is equivalent to calling <code>transform(R)</code>, where R is an
  953. * <code>AffineTransform</code> represented by the following matrix:
  954. * <pre>
  955. * [ cos(theta) -sin(theta) 0 ]
  956. * [ sin(theta) cos(theta) 0 ]
  957. * [ 0 0 1 ]
  958. * </pre>
  959. * Rotating with a positive angle theta rotates points on the positive
  960. * x axis toward the positive y axis.
  961. * @param theta the angle of rotation in radians
  962. */
  963. public abstract void rotate(double theta);
  964. /**
  965. * Concatenates the current <code>Graphics2D</code>
  966. * <code>Transform</code> with a translated rotation
  967. * transform. Subsequent rendering is transformed by a transform
  968. * which is constructed by translating to the specified location,
  969. * rotating by the specified radians, and translating back by the same
  970. * amount as the original translation. This is equivalent to the
  971. * following sequence of calls:
  972. * <pre>
  973. * translate(x, y);
  974. * rotate(theta);
  975. * translate(-x, -y);
  976. * </pre>
  977. * Rotating with a positive angle theta rotates points on the positive
  978. * x axis toward the positive y axis.
  979. * @param theta the angle of rotation in radians
  980. * @param x the x coordinate of the origin of the rotation
  981. * @param y the y coordinate of the origin of the rotation
  982. */
  983. public abstract void rotate(double theta, double x, double y);
  984. /**
  985. * Concatenates the current <code>Graphics2D</code>
  986. * <code>Transform</code> with a scaling transformation
  987. * Subsequent rendering is resized according to the specified scaling
  988. * factors relative to the previous scaling.
  989. * This is equivalent to calling <code>transform(S)</code>, where S is an
  990. * <code>AffineTransform</code> represented by the following matrix:
  991. * <pre>
  992. * [ sx 0 0 ]
  993. * [ 0 sy 0 ]
  994. * [ 0 0 1 ]
  995. * </pre>
  996. * @param sx the amount by which X coordinates in subsequent
  997. * rendering operations are multiplied relative to previous
  998. * rendering operations.
  999. * @param sy the amount by which Y coordinates in subsequent
  1000. * rendering operations are multiplied relative to previous
  1001. * rendering operations.
  1002. */
  1003. public abstract void scale(double sx, double sy);
  1004. /**
  1005. * Concatenates the current <code>Graphics2D</code>
  1006. * <code>Transform</code> with a shearing transform.
  1007. * Subsequent renderings are sheared by the specified
  1008. * multiplier relative to the previous position.
  1009. * This is equivalent to calling <code>transform(SH)</code>, where SH
  1010. * is an <code>AffineTransform</code> represented by the following
  1011. * matrix:
  1012. * <pre>
  1013. * [ 1 shx 0 ]
  1014. * [ shy 1 0 ]
  1015. * [ 0 0 1 ]
  1016. * </pre>
  1017. * @param shx the multiplier by which coordinates are shifted in
  1018. * the positive X axis direction as a function of their Y coordinate
  1019. * @param shy the multiplier by which coordinates are shifted in
  1020. * the positive Y axis direction as a function of their X coordinate
  1021. */
  1022. public abstract void shear(double shx, double shy);
  1023. /**
  1024. * Composes an <code>AffineTransform</code> object with the
  1025. * <code>Transform</code> in this <code>Graphics2D</code> according
  1026. * to the rule last-specified-first-applied. If the current
  1027. * <code>Transform</code> is Cx, the result of composition
  1028. * with Tx is a new <code>Transform</code> Cx'. Cx' becomes the
  1029. * current <code>Transform</code> for this <code>Graphics2D</code>.
  1030. * Transforming a point p by the updated <code>Transform</code> Cx' is
  1031. * equivalent to first transforming p by Tx and then transforming
  1032. * the result by the original <code>Transform</code> Cx. In other
  1033. * words, Cx'(p) = Cx(Tx(p)). A copy of the Tx is made, if necessary,
  1034. * so further modifications to Tx do not affect rendering.
  1035. * @param Tx the <code>AffineTransform</code> object to be composed with
  1036. * the current <code>Transform</code>
  1037. * @see #setTransform
  1038. * @see AffineTransform
  1039. */
  1040. public abstract void transform(AffineTransform Tx);
  1041. /**
  1042. * Overwrites the Transform in the <code>Graphics2D</code> context.
  1043. * WARNING: This method should <b>never</b> be used to apply a new
  1044. * coordinate transform on top of an existing transform because the
  1045. * <code>Graphics2D</code> might already have a transform that is
  1046. * needed for other purposes, such as rendering Swing
  1047. * components or applying a scaling transformation to adjust for the
  1048. * resolution of a printer.
  1049. * <p>To add a coordinate transform, use the
  1050. * <code>transform</code>, <code>rotate</code>, <code>scale</code>,
  1051. * or <code>shear</code> methods. The <code>setTransform</code>
  1052. * method is intended only for restoring the original
  1053. * <code>Graphics2D</code> transform after rendering, as shown in this
  1054. * example:
  1055. * <pre><blockquote>
  1056. * // Get the current transform
  1057. * AffineTransform saveAT = g2.getTransform();
  1058. * // Perform transformation
  1059. * g2d.transform(...);
  1060. * // Render
  1061. * g2d.draw(...);
  1062. * // Restore original transform
  1063. * g2d.setTransform(saveAT);
  1064. * </blockquote></pre>
  1065. *
  1066. * @param Tx the <code>AffineTransform</code> that was retrieved
  1067. * from the <code>getTransform</code> method
  1068. * @see #transform
  1069. * @see #getTransform
  1070. * @see AffineTransform
  1071. */
  1072. public abstract void setTransform(AffineTransform Tx);
  1073. /**
  1074. * Returns a copy of the current <code>Transform</code> in the
  1075. * <code>Graphics2D</code> context.
  1076. * @return the current <code>AffineTransform</code> in the
  1077. * <code>Graphics2D</code> context.
  1078. * @see #transform
  1079. * @see #setTransform
  1080. */
  1081. public abstract AffineTransform getTransform();
  1082. /**
  1083. * Returns the current <code>Paint</code> of the
  1084. * <code>Graphics2D</code> context.
  1085. * @return the current <code>Graphics2D</code> <code>Paint</code>,
  1086. * which defines a color or pattern.
  1087. * @see #setPaint
  1088. * @see java.awt.Graphics#setColor
  1089. */
  1090. public abstract Paint getPaint();
  1091. /**
  1092. * Returns the current <code>Composite</code> in the
  1093. * <code>Graphics2D</code> context.
  1094. * @return the current <code>Graphics2D</code> <code>Composite</code>,
  1095. * which defines a compositing style.
  1096. * @see #setComposite
  1097. */
  1098. public abstract Composite getComposite();
  1099. /**
  1100. * Sets the background color for the <code>Graphics2D</code> context.
  1101. * The background color is used for clearing a region.
  1102. * When a <code>Graphics2D</code> is constructed for a
  1103. * <code>Component</code>, the background color is
  1104. * inherited from the <code>Component</code>. Setting the background color
  1105. * in the <code>Graphics2D</code> context only affects the subsequent
  1106. * <code>clearRect</code> calls and not the background color of the
  1107. * <code>Component</code>. To change the background
  1108. * of the <code>Component</code>, use appropriate methods of
  1109. * the <code>Component</code>.
  1110. * @param color the background color that isused in
  1111. * subsequent calls to <code>clearRect</code>
  1112. * @see #getBackground
  1113. * @see java.awt.Graphics#clearRect
  1114. */
  1115. public abstract void setBackground(Color color);
  1116. /**
  1117. * Returns the background color used for clearing a region.
  1118. * @return the current <code>Graphics2D</code> <code>Color</code>,
  1119. * which defines the background color.
  1120. * @see #setBackground
  1121. */
  1122. public abstract Color getBackground();
  1123. /**
  1124. * Returns the current <code>Stroke</code> in the
  1125. * <code>Graphics2D</code> context.
  1126. * @return the current <code>Graphics2D</code> <code>Stroke</code>,
  1127. * which defines the line style.
  1128. * @see #setStroke
  1129. */
  1130. public abstract Stroke getStroke();
  1131. /**
  1132. * Intersects the current <code>Clip</code> with the interior of the
  1133. * specified <code>Shape</code> and sets the <code>Clip</code> to the
  1134. * resulting intersection. The specified <code>Shape</code> is
  1135. * transformed with the current <code>Graphics2D</code>
  1136. * <code>Transform</code> before being intersected with the current
  1137. * <code>Clip</code>. This method is used to make the current
  1138. * <code>Clip</code> smaller.
  1139. * To make the <code>Clip</code> larger, use <code>setClip</code>.
  1140. * The <i>user clip</i> modified by this method is independent of the
  1141. * clipping associated with device bounds and visibility. If no clip has
  1142. * previously been set, or if the clip has been cleared using
  1143. * {@link Graphics#setClip(Shape) setClip} with a <code>null</code>
  1144. * argument, the specified <code>Shape</code> becomes the new
  1145. * user clip.
  1146. * @param s the <code>Shape</code> to be intersected with the current
  1147. * <code>Clip</code>. If <code>s</code> is <code>null</code>,
  1148. * this method clears the current <code>Clip</code>.
  1149. */
  1150. public abstract void clip(Shape s);
  1151. /**
  1152. * Get the rendering context of the <code>Font</code> within this
  1153. * <code>Graphics2D</code> context.
  1154. * The {@link FontRenderContext}
  1155. * encapsulates application hints such as anti-aliasing and
  1156. * fractional metrics, as well as target device specific information
  1157. * such as dots-per-inch. This information should be provided by the
  1158. * application when using objects that perform typographical
  1159. * formatting, such as <code>Font</code> and
  1160. * <code>TextLayout</code>. This information should also be provided
  1161. * by applications that perform their own layout and need accurate
  1162. * measurements of various characteristics of glyphs such as advance
  1163. * and line height when various rendering hints have been applied to
  1164. * the text rendering.
  1165. *
  1166. * @return a reference to an instance of FontRenderContext.
  1167. * @see java.awt.font.FontRenderContext
  1168. * @see java.awt.Font#createGlyphVector
  1169. * @see java.awt.font.TextLayout
  1170. * @since 1.2
  1171. */
  1172. public abstract FontRenderContext getFontRenderContext();
  1173. }