1. /*
  2. * @(#)Graphics2D.java 1.78 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. 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.78, 01/23/03
  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 <code>Image</code> to be rendered
  511. * @param xform the transformation from image space into user space
  512. * @param obs the {@link ImageObserver}
  513. * to be notified as more of the <code>Image</code>
  514. * is converted
  515. * @return <code>true</code> if the <code>Image</code> is
  516. * fully loaded and completely rendered;
  517. * <code>false</code> if the <code>Image</code> is still being loaded.
  518. * @see #transform
  519. * @see #setTransform
  520. * @see #setComposite
  521. * @see #clip
  522. * @see #setClip
  523. */
  524. public abstract boolean drawImage(Image img,
  525. AffineTransform xform,
  526. ImageObserver obs);
  527. /**
  528. * Renders a <code>BufferedImage</code> that is
  529. * filtered with a
  530. * {@link BufferedImageOp}.
  531. * The rendering attributes applied include the <code>Clip</code>,
  532. * <code>Transform</code>
  533. * and <code>Composite</code> attributes. This is equivalent to:
  534. * <pre>
  535. * img1 = op.filter(img, null);
  536. * drawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null);
  537. * </pre>
  538. * @param op the filter to be applied to the image before rendering
  539. * @param img the <code>BufferedImage</code> to be rendered
  540. * @param x the x coordinate of the location in user space where
  541. * the upper left corner of the image is rendered
  542. * @param y the y coordinate of the location in user space where
  543. * the upper left corner of the image is rendered
  544. *
  545. * @see #transform
  546. * @see #setTransform
  547. * @see #setComposite
  548. * @see #clip
  549. * @see #setClip
  550. */
  551. public abstract void drawImage(BufferedImage img,
  552. BufferedImageOp op,
  553. int x,
  554. int y);
  555. /**
  556. * Renders a {@link RenderedImage},
  557. * applying a transform from image
  558. * space into user space before drawing.
  559. * The transformation from user space into device space is done with
  560. * the current <code>Transform</code> in the <code>Graphics2D</code>.
  561. * The specified transformation is applied to the image before the
  562. * transform attribute in the <code>Graphics2D</code> context is applied.
  563. * The rendering attributes applied include the <code>Clip</code>,
  564. * <code>Transform</code>, and <code>Composite</code> attributes. Note
  565. * that no rendering is done if the specified transform is
  566. * noninvertible.
  567. * @param img the image to be rendered
  568. * @param xform the transformation from image space into user space
  569. * @see #transform
  570. * @see #setTransform
  571. * @see #setComposite
  572. * @see #clip
  573. * @see #setClip
  574. */
  575. public abstract void drawRenderedImage(RenderedImage img,
  576. AffineTransform xform);
  577. /**
  578. * Renders a
  579. * {@link RenderableImage},
  580. * applying a transform from image space into user space before drawing.
  581. * The transformation from user space into device space is done with
  582. * the current <code>Transform</code> in the <code>Graphics2D</code>.
  583. * The specified transformation is applied to the image before the
  584. * transform attribute in the <code>Graphics2D</code> context is applied.
  585. * The rendering attributes applied include the <code>Clip</code>,
  586. * <code>Transform</code>, and <code>Composite</code> attributes. Note
  587. * that no rendering is done if the specified transform is
  588. * noninvertible.
  589. *<p>
  590. * Rendering hints set on the <code>Graphics2D</code> object might
  591. * be used in rendering the <code>RenderableImage</code>.
  592. * If explicit control is required over specific hints recognized by a
  593. * specific <code>RenderableImage</code>, or if knowledge of which hints
  594. * are used is required, then a <code>RenderedImage</code> should be
  595. * obtained directly from the <code>RenderableImage</code>
  596. * and rendered using
  597. *{@link #drawRenderedImage(RenderedImage, AffineTransform) drawRenderedImage}.
  598. * @param img the image to be rendered
  599. * @param xform the transformation from image space into user space
  600. * @see #transform
  601. * @see #setTransform
  602. * @see #setComposite
  603. * @see #clip
  604. * @see #setClip
  605. * @see #drawRenderedImage
  606. */
  607. public abstract void drawRenderableImage(RenderableImage img,
  608. AffineTransform xform);
  609. /**
  610. * Renders the text of the specified <code>String</code>, using the
  611. * current text attribute state in the <code>Graphics2D</code> context.
  612. * The baseline of the
  613. * first character is at position (<i>x</i>, <i>y</i>) in
  614. * the User Space.
  615. * The rendering attributes applied include the <code>Clip</code>,
  616. * <code>Transform</code>, <code>Paint</code>, <code>Font</code> and
  617. * <code>Composite</code> attributes. For characters in script
  618. * systems such as Hebrew and Arabic, the glyphs can be rendered from
  619. * right to left, in which case the coordinate supplied is the
  620. * location of the leftmost character on the baseline.
  621. * @param str the string to be rendered
  622. * @param x the x coordinate of the location where the
  623. * <code>String</code> should be rendered
  624. * @param y the y coordinate of the location where the
  625. * <code>String</code> should be rendered
  626. * @throws NullPointerException if <code>str</code> is
  627. * <code>null</code>
  628. * @see java.awt.Graphics#drawBytes
  629. * @see java.awt.Graphics#drawChars
  630. * @since JDK1.0
  631. */
  632. public abstract void drawString(String str, int x, int y);
  633. /**
  634. * Renders the text specified by the specified <code>String</code>,
  635. * using the current text attribute state in the <code>Graphics2D</code> context.
  636. * The baseline of the first character is at position
  637. * (<i>x</i>, <i>y</i>) in the User Space.
  638. * The rendering attributes applied include the <code>Clip</code>,
  639. * <code>Transform</code>, <code>Paint</code>, <code>Font</code> and
  640. * <code>Composite</code> attributes. For characters in script systems
  641. * such as Hebrew and Arabic, the glyphs can be rendered from right to
  642. * left, in which case the coordinate supplied is the location of the
  643. * leftmost character on the baseline.
  644. * @param s the <code>String</code> to be rendered
  645. * @param x the x coordinate of the location where the
  646. * <code>String</code> should be rendered
  647. * @param y the y coordinate of the location where the
  648. * <code>String</code> should be rendered
  649. * @throws NullPointerException if <code>str</code> is
  650. * <code>null</code>
  651. * @see #setPaint
  652. * @see java.awt.Graphics#setColor
  653. * @see java.awt.Graphics#setFont
  654. * @see #setTransform
  655. * @see #setComposite
  656. * @see #setClip
  657. */
  658. public abstract void drawString(String s, float x, float y);
  659. /**
  660. * Renders the text of the specified iterator, using the
  661. * <code>Graphics2D</code> context's current <code>Paint</code>. The
  662. * iterator has to specify a font
  663. * for each character. The baseline of the
  664. * first character is at position (<i>x</i>, <i>y</i>) in the
  665. * User Space.
  666. * The rendering attributes applied include the <code>Clip</code>,
  667. * <code>Transform</code>, <code>Paint</code>, and
  668. * <code>Composite</code> attributes.
  669. * For characters in script systems such as Hebrew and Arabic,
  670. * the glyphs can be rendered from right to left, in which case the
  671. * coordinate supplied is the location of the leftmost character
  672. * on the baseline.
  673. * @param iterator the iterator whose text is to be rendered
  674. * @param x the x coordinate where the iterator's text is to be
  675. * rendered
  676. * @param y the y coordinate where the iterator's text is to be
  677. * rendered
  678. * @see #setPaint
  679. * @see java.awt.Graphics#setColor
  680. * @see #setTransform
  681. * @see #setComposite
  682. * @see #setClip
  683. */
  684. public abstract void drawString(AttributedCharacterIterator iterator,
  685. int x, int y);
  686. /**
  687. * Renders the text of the specified iterator, using the
  688. * <code>Graphics2D</code> context's current <code>Paint</code>. The
  689. * iterator must specify a font
  690. * for each character. The baseline of the
  691. * first character is at position (<i>x</i>, <i>y</i>) in the
  692. * User Space.
  693. * The rendering attributes applied include the <code>Clip</code>,
  694. * <code>Transform</code>, <code>Paint</code>, and
  695. * <code>Composite</code> attributes.
  696. * For characters in script systems such as Hebrew and Arabic,
  697. * the glyphs can be rendered from right to left, in which case the
  698. * coordinate supplied is the location of the leftmost character
  699. * on the baseline.
  700. * @param iterator the iterator whose text is to be rendered
  701. * @param x the x coordinate where the iterator's text is to be
  702. * rendered
  703. * @param y the y coordinate where the iterator's text is to be
  704. * rendered
  705. * @see #setPaint
  706. * @see java.awt.Graphics#setColor
  707. * @see #setTransform
  708. * @see #setComposite
  709. * @see #setClip
  710. */
  711. public abstract void drawString(AttributedCharacterIterator iterator,
  712. float x, float y);
  713. /**
  714. * Renders the text of the specified
  715. * {@link GlyphVector} using
  716. * the <code>Graphics2D</code> context's rendering attributes.
  717. * The rendering attributes applied include the <code>Clip</code>,
  718. * <code>Transform</code>, <code>Paint</code>, and
  719. * <code>Composite</code> attributes. The <code>GlyphVector</code>
  720. * specifies individual glyphs from a {@link Font}.
  721. * The <code>GlyphVector</code> can also contain the glyph positions.
  722. * This is the fastest way to render a set of characters to the
  723. * screen.
  724. * @param g the <code>GlyphVector</code> to be rendered
  725. * @param x the x position in User Space where the glyphs should
  726. * be rendered
  727. * @param y the y position in User Space where the glyphs should
  728. * be rendered
  729. *
  730. * @see java.awt.Font#createGlyphVector
  731. * @see java.awt.font.GlyphVector
  732. * @see #setPaint
  733. * @see java.awt.Graphics#setColor
  734. * @see #setTransform
  735. * @see #setComposite
  736. * @see #setClip
  737. */
  738. public abstract void drawGlyphVector(GlyphVector g, float x, float y);
  739. /**
  740. * Fills the interior of a <code>Shape</code> using the settings of the
  741. * <code>Graphics2D</code> context. The rendering attributes applied
  742. * include the <code>Clip</code>, <code>Transform</code>,
  743. * <code>Paint</code>, and <code>Composite</code>.
  744. * @param s the <code>Shape</code> to be filled
  745. * @see #setPaint
  746. * @see java.awt.Graphics#setColor
  747. * @see #transform
  748. * @see #setTransform
  749. * @see #setComposite
  750. * @see #clip
  751. * @see #setClip
  752. */
  753. public abstract void fill(Shape s);
  754. /**
  755. * Checks whether or not the specified <code>Shape</code> intersects
  756. * the specified {@link Rectangle}, which is in device
  757. * space. If <code>onStroke</code> is false, this method checks
  758. * whether or not the interior of the specified <code>Shape</code>
  759. * intersects the specified <code>Rectangle</code>. If
  760. * <code>onStroke</code> is <code>true</code>, this method checks
  761. * whether or not the <code>Stroke</code> of the specified
  762. * <code>Shape</code> outline intersects the specified
  763. * <code>Rectangle</code>.
  764. * The rendering attributes taken into account include the
  765. * <code>Clip</code>, <code>Transform</code>, and <code>Stroke</code>
  766. * attributes.
  767. * @param rect the area in device space to check for a hit
  768. * @param s the <code>Shape</code> to check for a hit
  769. * @param onStroke flag used to choose between testing the
  770. * stroked or the filled shape. If the flag is <code>true</code>, the
  771. * <code>Stroke</code> oultine is tested. If the flag is
  772. * <code>false</code>, the filled <code>Shape</code> is tested.
  773. * @return <code>true</code> if there is a hit; <code>false</code>
  774. * otherwise.
  775. * @see #setStroke
  776. * @see #fill
  777. * @see #draw
  778. * @see #transform
  779. * @see #setTransform
  780. * @see #clip
  781. * @see #setClip
  782. */
  783. public abstract boolean hit(Rectangle rect,
  784. Shape s,
  785. boolean onStroke);
  786. /**
  787. * Returns the device configuration associated with this
  788. * <code>Graphics2D</code>.
  789. * @return the device configuration of this <code>Graphics2D</code>.
  790. */
  791. public abstract GraphicsConfiguration getDeviceConfiguration();
  792. /**
  793. * Sets the <code>Composite</code> for the <code>Graphics2D</code> context.
  794. * The <code>Composite</code> is used in all drawing methods such as
  795. * <code>drawImage</code>, <code>drawString</code>, <code>draw</code>,
  796. * and <code>fill</code>. It specifies how new pixels are to be combined
  797. * with the existing pixels on the graphics device during the rendering
  798. * process.
  799. * <p>If this <code>Graphics2D</code> context is drawing to a
  800. * <code>Component</code> on the display screen and the
  801. * <code>Composite</code> is a custom object rather than an
  802. * instance of the <code>AlphaComposite</code> class, and if
  803. * there is a security manager, its <code>checkPermission</code>
  804. * method is called with an <code>AWTPermission("readDisplayPixels")</code>
  805. * permission.
  806. * @throws SecurityException
  807. * if a custom <code>Composite</code> object is being
  808. * used to render to the screen and a security manager
  809. * is set and its <code>checkPermission</code> method
  810. * does not allow the operation.
  811. * @param comp the <code>Composite</code> object to be used for rendering
  812. * @see java.awt.Graphics#setXORMode
  813. * @see java.awt.Graphics#setPaintMode
  814. * @see #getComposite
  815. * @see AlphaComposite
  816. * @see SecurityManager#checkPermission
  817. * @see java.awt.AWTPermission
  818. */
  819. public abstract void setComposite(Composite comp);
  820. /**
  821. * Sets the <code>Paint</code> attribute for the
  822. * <code>Graphics2D</code> context. Calling this method
  823. * with a <code>null</code> <code>Paint</code> object does
  824. * not have any effect on the current <code>Paint</code> attribute
  825. * of this <code>Graphics2D</code>.
  826. * @param paint the <code>Paint</code> object to be used to generate
  827. * color during the rendering process, or <code>null</code>
  828. * @see java.awt.Graphics#setColor
  829. * @see #getPaint
  830. * @see GradientPaint
  831. * @see TexturePaint
  832. */
  833. public abstract void setPaint( Paint paint );
  834. /**
  835. * Sets the <code>Stroke</code> for the <code>Graphics2D</code> context.
  836. * @param s the <code>Stroke</code> object to be used to stroke a
  837. * <code>Shape</code> during the rendering process
  838. * @see BasicStroke
  839. * @see #getStroke
  840. */
  841. public abstract void setStroke(Stroke s);
  842. /**
  843. * Sets the value of a single preference for the rendering algorithms.
  844. * Hint categories include controls for rendering quality and overall
  845. * time/quality trade-off in the rendering process. Refer to the
  846. * <code>RenderingHints</code> class for definitions of some common
  847. * keys and values.
  848. * @param hintKey the key of the hint to be set.
  849. * @param hintValue the value indicating preferences for the specified
  850. * hint category.
  851. * @see #getRenderingHint(RenderingHints.Key)
  852. * @see RenderingHints
  853. */
  854. public abstract void setRenderingHint(Key hintKey, Object hintValue);
  855. /**
  856. * Returns the value of a single preference for the rendering algorithms.
  857. * Hint categories include controls for rendering quality and overall
  858. * time/quality trade-off in the rendering process. Refer to the
  859. * <code>RenderingHints</code> class for definitions of some common
  860. * keys and values.
  861. * @param hintKey the key corresponding to the hint to get.
  862. * @return an object representing the value for the specified hint key.
  863. * Some of the keys and their associated values are defined in the
  864. * <code>RenderingHints</code> class.
  865. * @see RenderingHints
  866. * @see #setRenderingHint(RenderingHints.Key, Object)
  867. */
  868. public abstract Object getRenderingHint(Key hintKey);
  869. /**
  870. * Replaces the values of all preferences for the rendering
  871. * algorithms with the specified <code>hints</code>.
  872. * The existing values for all rendering hints are discarded and
  873. * the new set of known hints and values are initialized from the
  874. * specified {@link Map} object.
  875. * Hint categories include controls for rendering quality and
  876. * overall time/quality trade-off in the rendering process.
  877. * Refer to the <code>RenderingHints</code> class for definitions of
  878. * some common keys and values.
  879. * @param hints the rendering hints to be set
  880. * @see #getRenderingHints
  881. * @see RenderingHints
  882. */
  883. public abstract void setRenderingHints(Map hints);
  884. /**
  885. * Sets the values of an arbitrary number of preferences for the
  886. * rendering algorithms.
  887. * Only values for the rendering hints that are present in the
  888. * specified <code>Map</code> object are modified.
  889. * All other preferences not present in the specified
  890. * object are left unmodified.
  891. * Hint categories include controls for rendering quality and
  892. * overall time/quality trade-off in the rendering process.
  893. * Refer to the <code>RenderingHints</code> class for definitions of
  894. * some common keys and values.
  895. * @param hints the rendering hints to be set
  896. * @see RenderingHints
  897. */
  898. public abstract void addRenderingHints(Map hints);
  899. /**
  900. * Gets the preferences for the rendering algorithms. Hint categories
  901. * include controls for rendering quality and overall time/quality
  902. * trade-off in the rendering process.
  903. * Returns all of the hint key/value pairs that were ever specified in
  904. * one operation. Refer to the
  905. * <code>RenderingHints</code> class for definitions of some common
  906. * keys and values.
  907. * @return a reference to an instance of <code>RenderingHints</code>
  908. * that contains the current preferences.
  909. * @see RenderingHints
  910. * @see #setRenderingHints(Map)
  911. */
  912. public abstract RenderingHints getRenderingHints();
  913. /**
  914. * Translates the origin of the <code>Graphics2D</code> context to the
  915. * point (<i>x</i>, <i>y</i>) in the current coordinate system.
  916. * Modifies the <code>Graphics2D</code> context so that its new origin
  917. * corresponds to the point (<i>x</i>, <i>y</i>) in the
  918. * <code>Graphics2D</code> context's former coordinate system. All
  919. * coordinates used in subsequent rendering operations on this graphics
  920. * context are relative to this new origin.
  921. * @param x the specified x coordinate
  922. * @param y the specified y coordinate
  923. * @since JDK1.0
  924. */
  925. public abstract void translate(int x, int y);
  926. /**
  927. * Concatenates the current
  928. * <code>Graphics2D</code> <code>Transform</code>
  929. * with a translation transform.
  930. * Subsequent rendering is translated by the specified
  931. * distance relative to the previous position.
  932. * This is equivalent to calling transform(T), where T is an
  933. * <code>AffineTransform</code> represented by the following matrix:
  934. * <pre>
  935. * [ 1 0 tx ]
  936. * [ 0 1 ty ]
  937. * [ 0 0 1 ]
  938. * </pre>
  939. * @param tx the distance to translate along the x-axis
  940. * @param ty the distance to translate along the y-axis
  941. */
  942. public abstract void translate(double tx, double ty);
  943. /**
  944. * Concatenates the current <code>Graphics2D</code>
  945. * <code>Transform</code> with a rotation transform.
  946. * Subsequent rendering is rotated by the specified radians relative
  947. * to the previous origin.
  948. * This is equivalent to calling <code>transform(R)</code>, where R is an
  949. * <code>AffineTransform</code> represented by the following matrix:
  950. * <pre>
  951. * [ cos(theta) -sin(theta) 0 ]
  952. * [ sin(theta) cos(theta) 0 ]
  953. * [ 0 0 1 ]
  954. * </pre>
  955. * Rotating with a positive angle theta rotates points on the positive
  956. * x axis toward the positive y axis.
  957. * @param theta the angle of rotation in radians
  958. */
  959. public abstract void rotate(double theta);
  960. /**
  961. * Concatenates the current <code>Graphics2D</code>
  962. * <code>Transform</code> with a translated rotation
  963. * transform. Subsequent rendering is transformed by a transform
  964. * which is constructed by translating to the specified location,
  965. * rotating by the specified radians, and translating back by the same
  966. * amount as the original translation. This is equivalent to the
  967. * following sequence of calls:
  968. * <pre>
  969. * translate(x, y);
  970. * rotate(theta);
  971. * translate(-x, -y);
  972. * </pre>
  973. * Rotating with a positive angle theta rotates points on the positive
  974. * x axis toward the positive y axis.
  975. * @param theta the angle of rotation in radians
  976. * @param x the x coordinate of the origin of the rotation
  977. * @param y the y coordinate of the origin of the rotation
  978. */
  979. public abstract void rotate(double theta, double x, double y);
  980. /**
  981. * Concatenates the current <code>Graphics2D</code>
  982. * <code>Transform</code> with a scaling transformation
  983. * Subsequent rendering is resized according to the specified scaling
  984. * factors relative to the previous scaling.
  985. * This is equivalent to calling <code>transform(S)</code>, where S is an
  986. * <code>AffineTransform</code> represented by the following matrix:
  987. * <pre>
  988. * [ sx 0 0 ]
  989. * [ 0 sy 0 ]
  990. * [ 0 0 1 ]
  991. * </pre>
  992. * @param sx the amount by which X coordinates in subsequent
  993. * rendering operations are multiplied relative to previous
  994. * rendering operations.
  995. * @param sy the amount by which Y coordinates in subsequent
  996. * rendering operations are multiplied relative to previous
  997. * rendering operations.
  998. */
  999. public abstract void scale(double sx, double sy);
  1000. /**
  1001. * Concatenates the current <code>Graphics2D</code>
  1002. * <code>Transform</code> with a shearing transform.
  1003. * Subsequent renderings are sheared by the specified
  1004. * multiplier relative to the previous position.
  1005. * This is equivalent to calling <code>transform(SH)</code>, where SH
  1006. * is an <code>AffineTransform</code> represented by the following
  1007. * matrix:
  1008. * <pre>
  1009. * [ 1 shx 0 ]
  1010. * [ shy 1 0 ]
  1011. * [ 0 0 1 ]
  1012. * </pre>
  1013. * @param shx the multiplier by which coordinates are shifted in
  1014. * the positive X axis direction as a function of their Y coordinate
  1015. * @param shy the multiplier by which coordinates are shifted in
  1016. * the positive Y axis direction as a function of their X coordinate
  1017. */
  1018. public abstract void shear(double shx, double shy);
  1019. /**
  1020. * Composes an <code>AffineTransform</code> object with the
  1021. * <code>Transform</code> in this <code>Graphics2D</code> according
  1022. * to the rule last-specified-first-applied. If the current
  1023. * <code>Transform</code> is Cx, the result of composition
  1024. * with Tx is a new <code>Transform</code> Cx'. Cx' becomes the
  1025. * current <code>Transform</code> for this <code>Graphics2D</code>.
  1026. * Transforming a point p by the updated <code>Transform</code> Cx' is
  1027. * equivalent to first transforming p by Tx and then transforming
  1028. * the result by the original <code>Transform</code> Cx. In other
  1029. * words, Cx'(p) = Cx(Tx(p)). A copy of the Tx is made, if necessary,
  1030. * so further modifications to Tx do not affect rendering.
  1031. * @param Tx the <code>AffineTransform</code> object to be composed with
  1032. * the current <code>Transform</code>
  1033. * @see #setTransform
  1034. * @see AffineTransform
  1035. */
  1036. public abstract void transform(AffineTransform Tx);
  1037. /**
  1038. * Overwrites the Transform in the <code>Graphics2D</code> context.
  1039. * WARNING: This method should <b>never</b> be used to apply a new
  1040. * coordinate transform on top of an existing transform because the
  1041. * <code>Graphics2D</code> might already have a transform that is
  1042. * needed for other purposes, such as rendering Swing
  1043. * components or applying a scaling transformation to adjust for the
  1044. * resolution of a printer.
  1045. * <p>To add a coordinate transform, use the
  1046. * <code>transform</code>, <code>rotate</code>, <code>scale</code>,
  1047. * or <code>shear</code> methods. The <code>setTransform</code>
  1048. * method is intended only for restoring the original
  1049. * <code>Graphics2D</code> transform after rendering, as shown in this
  1050. * example:
  1051. * <pre><blockquote>
  1052. * // Get the current transform
  1053. * AffineTransform saveAT = g2.getTransform();
  1054. * // Perform transformation
  1055. * g2d.transform(...);
  1056. * // Render
  1057. * g2d.draw(...);
  1058. * // Restore original transform
  1059. * g2d.setTransform(saveAT);
  1060. * </blockquote></pre>
  1061. *
  1062. * @param Tx the <code>AffineTransform</code> that was retrieved
  1063. * from the <code>getTransform</code> method
  1064. * @see #transform
  1065. * @see #getTransform
  1066. * @see AffineTransform
  1067. */
  1068. public abstract void setTransform(AffineTransform Tx);
  1069. /**
  1070. * Returns a copy of the current <code>Transform</code> in the
  1071. * <code>Graphics2D</code> context.
  1072. * @return the current <code>AffineTransform</code> in the
  1073. * <code>Graphics2D</code> context.
  1074. * @see #transform
  1075. * @see #setTransform
  1076. */
  1077. public abstract AffineTransform getTransform();
  1078. /**
  1079. * Returns the current <code>Paint</code> of the
  1080. * <code>Graphics2D</code> context.
  1081. * @return the current <code>Graphics2D</code> <code>Paint</code>,
  1082. * which defines a color or pattern.
  1083. * @see #setPaint
  1084. * @see java.awt.Graphics#setColor
  1085. */
  1086. public abstract Paint getPaint();
  1087. /**
  1088. * Returns the current <code>Composite</code> in the
  1089. * <code>Graphics2D</code> context.
  1090. * @return the current <code>Graphics2D</code> <code>Composite</code>,
  1091. * which defines a compositing style.
  1092. * @see #setComposite
  1093. */
  1094. public abstract Composite getComposite();
  1095. /**
  1096. * Sets the background color for the <code>Graphics2D</code> context.
  1097. * The background color is used for clearing a region.
  1098. * When a <code>Graphics2D</code> is constructed for a
  1099. * <code>Component</code>, the background color is
  1100. * inherited from the <code>Component</code>. Setting the background color
  1101. * in the <code>Graphics2D</code> context only affects the subsequent
  1102. * <code>clearRect</code> calls and not the background color of the
  1103. * <code>Component</code>. To change the background
  1104. * of the <code>Component</code>, use appropriate methods of
  1105. * the <code>Component</code>.
  1106. * @param color the background color that isused in
  1107. * subsequent calls to <code>clearRect</code>
  1108. * @see #getBackground
  1109. * @see java.awt.Graphics#clearRect
  1110. */
  1111. public abstract void setBackground(Color color);
  1112. /**
  1113. * Returns the background color used for clearing a region.
  1114. * @return the current <code>Graphics2D</code> <code>Color</code>,
  1115. * which defines the background color.
  1116. * @see #setBackground
  1117. */
  1118. public abstract Color getBackground();
  1119. /**
  1120. * Returns the current <code>Stroke</code> in the
  1121. * <code>Graphics2D</code> context.
  1122. * @return the current <code>Graphics2D</code> <code>Stroke</code>,
  1123. * which defines the line style.
  1124. * @see #setStroke
  1125. */
  1126. public abstract Stroke getStroke();
  1127. /**
  1128. * Intersects the current <code>Clip</code> with the interior of the
  1129. * specified <code>Shape</code> and sets the <code>Clip</code> to the
  1130. * resulting intersection. The specified <code>Shape</code> is
  1131. * transformed with the current <code>Graphics2D</code>
  1132. * <code>Transform</code> before being intersected with the current
  1133. * <code>Clip</code>. This method is used to make the current
  1134. * <code>Clip</code> smaller.
  1135. * To make the <code>Clip</code> larger, use <code>setClip</code>.
  1136. * The <i>user clip</i> modified by this method is independent of the
  1137. * clipping associated with device bounds and visibility. If no clip has
  1138. * previously been set, or if the clip has been cleared using
  1139. * {@link Graphics#setClip(Shape) setClip} with a <code>null</code>
  1140. * argument, the specified <code>Shape</code> becomes the new
  1141. * user clip.
  1142. * @param s the <code>Shape</code> to be intersected with the current
  1143. * <code>Clip</code>. If <code>s</code> is <code>null</code>,
  1144. * this method clears the current <code>Clip</code>.
  1145. */
  1146. public abstract void clip(Shape s);
  1147. /**
  1148. * Get the rendering context of the <code>Font</code> within this
  1149. * <code>Graphics2D</code> context.
  1150. * The {@link FontRenderContext}
  1151. * encapsulates application hints such as anti-aliasing and
  1152. * fractional metrics, as well as target device specific information
  1153. * such as dots-per-inch. This information should be provided by the
  1154. * application when using objects that perform typographical
  1155. * formatting, such as <code>Font</code> and
  1156. * <code>TextLayout</code>. This information should also be provided
  1157. * by applications that perform their own layout and need accurate
  1158. * measurements of various characteristics of glyphs such as advance
  1159. * and line height when various rendering hints have been applied to
  1160. * the text rendering.
  1161. *
  1162. * @return a reference to an instance of FontRenderContext.
  1163. * @see java.awt.font.FontRenderContext
  1164. * @see java.awt.Font#createGlyphVector
  1165. * @see java.awt.font.TextLayout
  1166. * @since 1.2
  1167. */
  1168. public abstract FontRenderContext getFontRenderContext();
  1169. }