1. /*
  2. * @(#)Graphics.java 1.58 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.awt;
  8. import java.io.*;
  9. import java.lang.*;
  10. import java.util.*;
  11. import java.awt.image.ImageObserver;
  12. import java.text.AttributedCharacterIterator;
  13. /**
  14. * The <code>Graphics</code> class is the abstract base class for
  15. * all graphics contexts that allow an application to draw onto
  16. * components that are realized on various devices, as well as
  17. * onto off-screen images.
  18. * <p>
  19. * A <code>Graphics</code> object encapsulates state information needed
  20. * for the basic rendering operations that Java supports. This
  21. * state information includes the following properties:
  22. * <p>
  23. * <ul>
  24. * <li>The <code>Component</code> object on which to draw.
  25. * <li>A translation origin for rendering and clipping coordinates.
  26. * <li>The current clip.
  27. * <li>The current color.
  28. * <li>The current font.
  29. * <li>The current logical pixel operation function (XOR or Paint).
  30. * <li>The current XOR alternation color
  31. * (see {@link Graphics#setXORMode}).
  32. * </ul>
  33. * <p>
  34. * Coordinates are infinitely thin and lie between the pixels of the
  35. * output device.
  36. * Operations that draw the outline of a figure operate by traversing
  37. * an infinitely thin path between pixels with a pixel-sized pen that hangs
  38. * down and to the right of the anchor point on the path.
  39. * Operations that fill a figure operate by filling the interior
  40. * of that infinitely thin path.
  41. * Operations that render horizontal text render the ascending
  42. * portion of character glyphs entirely above the baseline coordinate.
  43. * <p>
  44. * The graphics pen hangs down and to the right from the path it traverses.
  45. * This has the following implications:
  46. * <p><ul>
  47. * <li>If you draw a figure that covers a given rectangle, that
  48. * figure occupies one extra row of pixels on the right and bottom edges
  49. * as compared to filling a figure that is bounded by that same rectangle.
  50. * <li>If you draw a horizontal line along the same <i>y</i> coordinate as
  51. * the baseline of a line of text, that line is drawn entirely below
  52. * the text, except for any descenders.
  53. * </ul><p>
  54. * All coordinates that appear as arguments to the methods of this
  55. * <code>Graphics</code> object are considered relative to the
  56. * translation origin of this <code>Graphics</code> object prior to
  57. * the invocation of the method.
  58. * <p>
  59. * All rendering operations modify only pixels which lie within the
  60. * area bounded by the current clip, which is specified by a {@link Shape}
  61. * in user space and is controlled by the program using the
  62. * <code>Graphics</code> object. This <i>user clip</i>
  63. * is transformed into device space and combined with the
  64. * <i>device clip</i>, which is defined by the visibility of windows and
  65. * device extents. The combination of the user clip and device clip
  66. * defines the <i>composite clip</i>, which determines the final clipping
  67. * region. The user clip cannot be modified by the rendering
  68. * system to reflect the resulting composite clip. The user clip can only
  69. * be changed through the <code>setClip</code> or <code>clipRect</code>
  70. * methods.
  71. * All drawing or writing is done in the current color,
  72. * using the current paint mode, and in the current font.
  73. *
  74. * @version 1.58, 11/29/01
  75. * @author Sami Shaio
  76. * @author Arthur van Hoff
  77. * @see java.awt.Component
  78. * @see java.awt.Graphics#clipRect(int, int, int, int)
  79. * @see java.awt.Graphics#setColor(java.awt.Color)
  80. * @see java.awt.Graphics#setPaintMode()
  81. * @see java.awt.Graphics#setXORMode(java.awt.Color)
  82. * @see java.awt.Graphics#setFont(java.awt.Font)
  83. * @since JDK1.0
  84. */
  85. public abstract class Graphics {
  86. /**
  87. * Constructs a new <code>Graphics</code> object.
  88. * This constructor is the default contructor for a graphics
  89. * context.
  90. * <p>
  91. * Since <code>Graphics</code> is an abstract class, applications
  92. * cannot call this constructor directly. Graphics contexts are
  93. * obtained from other graphics contexts or are created by calling
  94. * <code>getGraphics</code> on a component.
  95. * @see java.awt.Graphics#create()
  96. * @see java.awt.Component#getGraphics
  97. */
  98. protected Graphics() {
  99. }
  100. /**
  101. * Creates a new <code>Graphics</code> object that is
  102. * a copy of this <code>Graphics</code> object.
  103. * @return a new graphics context that is a copy of
  104. * this graphics context.
  105. */
  106. public abstract Graphics create();
  107. /**
  108. * Creates a new <code>Graphics</code> object based on this
  109. * <code>Graphics</code> object, but with a new translation and clip area.
  110. * The new <code>Graphics</code> object has its origin
  111. * translated to the specified point (<i>x</i>, <i>y</i>).
  112. * Its clip area is determined by the intersection of the original
  113. * clip area with the specified rectangle. The arguments are all
  114. * interpreted in the coordinate system of the original
  115. * <code>Graphics</code> object. The new graphics context is
  116. * identical to the original, except in two respects:
  117. * <p>
  118. * <ul>
  119. * <li>
  120. * The new graphics context is translated by (<i>x</i>, <i>y</i>).
  121. * That is to say, the point (<code>0</code>, <code>0</code>) in the
  122. * new graphics context is the same as (<i>x</i>, <i>y</i>) in
  123. * the original graphics context.
  124. * <li>
  125. * The new graphics context has an additional clipping rectangle, in
  126. * addition to whatever (translated) clipping rectangle it inherited
  127. * from the original graphics context. The origin of the new clipping
  128. * rectangle is at (<code>0</code>, <code>0</code>), and its size
  129. * is specified by the <code>width</code> and <code>height</code>
  130. * arguments.
  131. * </ul>
  132. * <p>
  133. * @param x the <i>x</i> coordinate.
  134. * @param y the <i>y</i> coordinate.
  135. * @param width the width of the clipping rectangle.
  136. * @param height the height of the clipping rectangle.
  137. * @return a new graphics context.
  138. * @see java.awt.Graphics#translate
  139. * @see java.awt.Graphics#clipRect
  140. */
  141. public Graphics create(int x, int y, int width, int height) {
  142. Graphics g = create();
  143. g.translate(x, y);
  144. g.clipRect(0, 0, width, height);
  145. return g;
  146. }
  147. /**
  148. * Translates the origin of the graphics context to the point
  149. * (<i>x</i>, <i>y</i>) in the current coordinate system.
  150. * Modifies this graphics context so that its new origin corresponds
  151. * to the point (<i>x</i>, <i>y</i>) in this graphics context's
  152. * original coordinate system. All coordinates used in subsequent
  153. * rendering operations on this graphics context will be relative
  154. * to this new origin.
  155. * @param x the <i>x</i> coordinate.
  156. * @param y the <i>y</i> coordinate.
  157. */
  158. public abstract void translate(int x, int y);
  159. /**
  160. * Gets this graphics context's current color.
  161. * @return this graphics context's current color.
  162. * @see java.awt.Color
  163. * @see java.awt.Graphics#setColor
  164. */
  165. public abstract Color getColor();
  166. /**
  167. * Sets this graphics context's current color to the specified
  168. * color. All subsequent graphics operations using this graphics
  169. * context use this specified color.
  170. * @param c the new rendering color.
  171. * @see java.awt.Color
  172. * @see java.awt.Graphics#getColor
  173. */
  174. public abstract void setColor(Color c);
  175. /**
  176. * Sets the paint mode of this graphics context to overwrite the
  177. * destination with this graphics context's current color.
  178. * This sets the logical pixel operation function to the paint or
  179. * overwrite mode. All subsequent rendering operations will
  180. * overwrite the destination with the current color.
  181. */
  182. public abstract void setPaintMode();
  183. /**
  184. * Sets the paint mode of this graphics context to alternate between
  185. * this graphics context's current color and the new specified color.
  186. * This specifies that logical pixel operations are performed in the
  187. * XOR mode, which alternates pixels between the current color and
  188. * a specified XOR color.
  189. * <p>
  190. * When drawing operations are performed, pixels which are the
  191. * current color are changed to the specified color, and vice versa.
  192. * <p>
  193. * Pixels that are of colors other than those two colors are changed
  194. * in an unpredictable but reversible manner; if the same figure is
  195. * drawn twice, then all pixels are restored to their original values.
  196. * @param c1 the XOR alternation color
  197. */
  198. public abstract void setXORMode(Color c1);
  199. /**
  200. * Gets the current font.
  201. * @return this graphics context's current font.
  202. * @see java.awt.Font
  203. * @see java.awt.Graphics#setFont
  204. */
  205. public abstract Font getFont();
  206. /**
  207. * Sets this graphics context's font to the specified font.
  208. * All subsequent text operations using this graphics context
  209. * use this font.
  210. * @param font the font.
  211. * @see java.awt.Graphics#getFont
  212. * @see java.awt.Graphics#drawChars(java.lang.String, int, int)
  213. * @see java.awt.Graphics#drawString(byte[], int, int, int, int)
  214. * @see java.awt.Graphics#drawBytes(char[], int, int, int, int)
  215. */
  216. public abstract void setFont(Font font);
  217. /**
  218. * Gets the font metrics of the current font.
  219. * @return the font metrics of this graphics
  220. * context's current font.
  221. * @see java.awt.Graphics#getFont
  222. * @see java.awt.FontMetrics
  223. * @see java.awt.Graphics#getFontMetrics(Font)
  224. */
  225. public FontMetrics getFontMetrics() {
  226. return getFontMetrics(getFont());
  227. }
  228. /**
  229. * Gets the font metrics for the specified font.
  230. * @return the font metrics for the specified font.
  231. * @param f the specified font
  232. * @see java.awt.Graphics#getFont
  233. * @see java.awt.FontMetrics
  234. * @see java.awt.Graphics#getFontMetrics()
  235. */
  236. public abstract FontMetrics getFontMetrics(Font f);
  237. /**
  238. * Returns the bounding rectangle of the current clipping area.
  239. * This method refers to the user clip, which is independent of the
  240. * clipping associated with device bounds and window visibility.
  241. * If no clip has previously been set, or if the clip has been
  242. * cleared using <code>setClip(null)</code>, this method returns
  243. * <code>null</code>.
  244. * The coordinates in the rectangle are relative to the coordinate
  245. * system origin of this graphics context.
  246. * @return the bounding rectangle of the current clipping area,
  247. * or <code>null</code> if no clip is set.
  248. * @see java.awt.Graphics#getClip
  249. * @see java.awt.Graphics#clipRect
  250. * @see java.awt.Graphics#setClip(int, int, int, int)
  251. * @see java.awt.Graphics#setClip(Shape)
  252. * @since JDK1.1
  253. */
  254. public abstract Rectangle getClipBounds();
  255. /**
  256. * Intersects the current clip with the specified rectangle.
  257. * The resulting clipping area is the intersection of the current
  258. * clipping area and the specified rectangle. If there is no
  259. * current clipping area, either because the clip has never been
  260. * set, or the clip has been cleared using <code>setClip(null)</code>,
  261. * the specified rectangle becomes the new clip.
  262. * This method sets the user clip, which is independent of the
  263. * clipping associated with device bounds and window visibility.
  264. * This method can only be used to make the current clip smaller.
  265. * To set the current clip larger, use any of the setClip methods.
  266. * Rendering operations have no effect outside of the clipping area.
  267. * @param x the x coordinate of the rectangle to intersect the clip with
  268. * @param y the y coordinate of the rectangle to intersect the clip with
  269. * @param width the width of the rectangle to intersect the clip with
  270. * @param height the height of the rectangle to intersect the clip with
  271. * @see #setClip(int, int, int, int)
  272. * @see #setClip(Shape)
  273. */
  274. public abstract void clipRect(int x, int y, int width, int height);
  275. /**
  276. * Sets the current clip to the rectangle specified by the given
  277. * coordinates. This method sets the user clip, which is
  278. * independent of the clipping associated with device bounds
  279. * and window visibility.
  280. * Rendering operations have no effect outside of the clipping area.
  281. * @param x the <i>x</i> coordinate of the new clip rectangle.
  282. * @param y the <i>y</i> coordinate of the new clip rectangle.
  283. * @param width the width of the new clip rectangle.
  284. * @param height the height of the new clip rectangle.
  285. * @see java.awt.Graphics#clipRect
  286. * @see java.awt.Graphics#setClip(Shape)
  287. * @since JDK1.1
  288. */
  289. public abstract void setClip(int x, int y, int width, int height);
  290. /**
  291. * Gets the current clipping area.
  292. * This method returns the user clip, which is independent of the
  293. * clipping associated with device bounds and window visibility.
  294. * If no clip has previously been set, or if the clip has been
  295. * cleared using <code>setClip(null)</code>, this method returns
  296. * <code>null</code>.
  297. * @return a <code>Shape</code> object representing the
  298. * current clipping area, or <code>null</code> if
  299. * no clip is set.
  300. * @see java.awt.Graphics#getClipBounds
  301. * @see java.awt.Graphics#clipRect
  302. * @see java.awt.Graphics#setClip(int, int, int, int)
  303. * @see java.awt.Graphics#setClip(Shape)
  304. * @since JDK1.1
  305. */
  306. public abstract Shape getClip();
  307. /**
  308. * Sets the current clipping area to an arbitrary clip shape.
  309. * Not all objects that implement the <code>Shape</code>
  310. * interface can be used to set the clip. The only
  311. * <code>Shape</code> objects that are guaranteed to be
  312. * supported are <code>Shape</code> objects that are
  313. * obtained via the <code>getClip</code> method and via
  314. * <code>Rectangle</code> objects. This method sets the
  315. * user clip, which is independent of the clipping associated
  316. * with device bounds and window visibility.
  317. * @param clip the <code>Shape</code> to use to set the clip
  318. * @see java.awt.Graphics#getClip()
  319. * @see java.awt.Graphics#clipRect
  320. * @see java.awt.Graphics#setClip(int, int, int, int)
  321. * @since JDK1.1
  322. */
  323. public abstract void setClip(Shape clip);
  324. /**
  325. * Copies an area of the component by a distance specified by
  326. * <code>dx</code> and <code>dy</code>. From the point specified
  327. * by <code>x</code> and <code>y</code>, this method
  328. * copies downwards and to the right. To copy an area of the
  329. * component to the left or upwards, specify a negative value for
  330. * <code>dx</code> or <code>dy</code>.
  331. * If a portion of the source rectangle lies outside the bounds
  332. * of the component, or is obscured by another window or component,
  333. * <code>copyArea</code> will be unable to copy the associated
  334. * pixels. The area that is omitted can be refreshed by calling
  335. * the component's <code>paint</code> method.
  336. * @param x the <i>x</i> coordinate of the source rectangle.
  337. * @param y the <i>y</i> coordinate of the source rectangle.
  338. * @param width the width of the source rectangle.
  339. * @param height the height of the source rectangle.
  340. * @param dx the horizontal distance to copy the pixels.
  341. * @param dy the vertical distance to copy the pixels.
  342. */
  343. public abstract void copyArea(int x, int y, int width, int height,
  344. int dx, int dy);
  345. /**
  346. * Draws a line, using the current color, between the points
  347. * <code>(x1, y1)</code> and <code>(x2, y2)</code>
  348. * in this graphics context's coordinate system.
  349. * @param x1 the first point's <i>x</i> coordinate.
  350. * @param y1 the first point's <i>y</i> coordinate.
  351. * @param x2 the second point's <i>x</i> coordinate.
  352. * @param y2 the second point's <i>y</i> coordinate.
  353. */
  354. public abstract void drawLine(int x1, int y1, int x2, int y2);
  355. /**
  356. * Fills the specified rectangle.
  357. * The left and right edges of the rectangle are at
  358. * <code>x</code> and <code>x + width - 1</code>.
  359. * The top and bottom edges are at
  360. * <code>y</code> and <code>y + height - 1</code>.
  361. * The resulting rectangle covers an area
  362. * <code>width</code> pixels wide by
  363. * <code>height</code> pixels tall.
  364. * The rectangle is filled using the graphics context's current color.
  365. * @param x the <i>x</i> coordinate
  366. * of the rectangle to be filled.
  367. * @param y the <i>y</i> coordinate
  368. * of the rectangle to be filled.
  369. * @param width the width of the rectangle to be filled.
  370. * @param height the height of the rectangle to be filled.
  371. * @see java.awt.Graphics#clearRect
  372. * @see java.awt.Graphics#drawRect
  373. */
  374. public abstract void fillRect(int x, int y, int width, int height);
  375. /**
  376. * Draws the outline of the specified rectangle.
  377. * The left and right edges of the rectangle are at
  378. * <code>x</code> and <code>x + width</code>.
  379. * The top and bottom edges are at
  380. * <code>y</code> and <code>y + height</code>.
  381. * The rectangle is drawn using the graphics context's current color.
  382. * @param x the <i>x</i> coordinate
  383. * of the rectangle to be drawn.
  384. * @param y the <i>y</i> coordinate
  385. * of the rectangle to be drawn.
  386. * @param width the width of the rectangle to be drawn.
  387. * @param height the height of the rectangle to be drawn.
  388. * @see java.awt.Graphics#fillRect
  389. * @see java.awt.Graphics#clearRect
  390. */
  391. public void drawRect(int x, int y, int width, int height) {
  392. if ((width < 0) || (height < 0)) {
  393. return;
  394. }
  395. if (height == 0 || width == 0) {
  396. drawLine(x, y, x + width, y + height);
  397. } else {
  398. drawLine(x, y, x + width - 1, y);
  399. drawLine(x + width, y, x + width, y + height - 1);
  400. drawLine(x + width, y + height, x + 1, y + height);
  401. drawLine(x, y + height, x, y + 1);
  402. }
  403. }
  404. /**
  405. * Clears the specified rectangle by filling it with the background
  406. * color of the current drawing surface. This operation does not
  407. * use the current paint mode.
  408. * <p>
  409. * Beginning with Java 1.1, the background color
  410. * of offscreen images may be system dependent. Applications should
  411. * use <code>setColor</code> followed by <code>fillRect</code> to
  412. * ensure that an offscreen image is cleared to a specific color.
  413. * @param x the <i>x</i> coordinate of the rectangle to clear.
  414. * @param y the <i>y</i> coordinate of the rectangle to clear.
  415. * @param width the width of the rectangle to clear.
  416. * @param height the height of the rectangle to clear.
  417. * @see java.awt.Graphics#fillRect(int, int, int, int)
  418. * @see java.awt.Graphics#drawRect
  419. * @see java.awt.Graphics#setColor(java.awt.Color)
  420. * @see java.awt.Graphics#setPaintMode
  421. * @see java.awt.Graphics#setXORMode(java.awt.Color)
  422. */
  423. public abstract void clearRect(int x, int y, int width, int height);
  424. /**
  425. * Draws an outlined round-cornered rectangle using this graphics
  426. * context's current color. The left and right edges of the rectangle
  427. * are at <code>x</code> and <code>x + width</code>,
  428. * respectively. The top and bottom edges of the rectangle are at
  429. * <code>y</code> and <code>y + height</code>.
  430. * @param x the <i>x</i> coordinate of the rectangle to be drawn.
  431. * @param y the <i>y</i> coordinate of the rectangle to be drawn.
  432. * @param width the width of the rectangle to be drawn.
  433. * @param height the height of the rectangle to be drawn.
  434. * @param arcWidth the horizontal diameter of the arc
  435. * at the four corners.
  436. * @param arcHeight the vertical diameter of the arc
  437. * at the four corners.
  438. * @see java.awt.Graphics#fillRoundRect
  439. */
  440. public abstract void drawRoundRect(int x, int y, int width, int height,
  441. int arcWidth, int arcHeight);
  442. /**
  443. * Fills the specified rounded corner rectangle with the current color.
  444. * The left and right edges of the rectangle
  445. * are at <code>x</code> and <code>x + width - 1</code>,
  446. * respectively. The top and bottom edges of the rectangle are at
  447. * <code>y</code> and <code>y + height - 1</code>.
  448. * @param x the <i>x</i> coordinate of the rectangle to be filled.
  449. * @param y the <i>y</i> coordinate of the rectangle to be filled.
  450. * @param width the width of the rectangle to be filled.
  451. * @param height the height of the rectangle to be filled.
  452. * @param arcWidth the horizontal diameter
  453. * of the arc at the four corners.
  454. * @param arcHeight the vertical diameter
  455. * of the arc at the four corners.
  456. * @see java.awt.Graphics#drawRoundRect
  457. */
  458. public abstract void fillRoundRect(int x, int y, int width, int height,
  459. int arcWidth, int arcHeight);
  460. /**
  461. * Draws a 3-D highlighted outline of the specified rectangle.
  462. * The edges of the rectangle are highlighted so that they
  463. * appear to be beveled and lit from the upper left corner.
  464. * <p>
  465. * The colors used for the highlighting effect are determined
  466. * based on the current color.
  467. * The resulting rectangle covers an area that is
  468. * <code>width + 1</code> pixels wide
  469. * by <code>height + 1</code> pixels tall.
  470. * @param x the <i>x</i> coordinate of the rectangle to be drawn.
  471. * @param y the <i>y</i> coordinate of the rectangle to be drawn.
  472. * @param width the width of the rectangle to be drawn.
  473. * @param height the height of the rectangle to be drawn.
  474. * @param raised a boolean that determines whether the rectangle
  475. * appears to be raised above the surface
  476. * or sunk into the surface.
  477. * @see java.awt.Graphics#fill3DRect
  478. */
  479. public void draw3DRect(int x, int y, int width, int height,
  480. boolean raised) {
  481. Color c = getColor();
  482. Color brighter = c.brighter();
  483. Color darker = c.darker();
  484. setColor(raised ? brighter : darker);
  485. drawLine(x, y, x, y + height);
  486. drawLine(x + 1, y, x + width - 1, y);
  487. setColor(raised ? darker : brighter);
  488. drawLine(x + 1, y + height, x + width, y + height);
  489. drawLine(x + width, y, x + width, y + height - 1);
  490. setColor(c);
  491. }
  492. /**
  493. * Paints a 3-D highlighted rectangle filled with the current color.
  494. * The edges of the rectangle will be highlighted so that it appears
  495. * as if the edges were beveled and lit from the upper left corner.
  496. * The colors used for the highlighting effect will be determined from
  497. * the current color.
  498. * @param x the <i>x</i> coordinate of the rectangle to be filled.
  499. * @param y the <i>y</i> coordinate of the rectangle to be filled.
  500. * @param width the width of the rectangle to be filled.
  501. * @param height the height of the rectangle to be filled.
  502. * @param raised a boolean value that determines whether the
  503. * rectangle appears to be raised above the surface
  504. * or etched into the surface.
  505. * @see java.awt.Graphics#draw3DRect
  506. */
  507. public void fill3DRect(int x, int y, int width, int height,
  508. boolean raised) {
  509. Color c = getColor();
  510. Color brighter = c.brighter();
  511. Color darker = c.darker();
  512. if (!raised) {
  513. setColor(darker);
  514. }
  515. fillRect(x+1, y+1, width-2, height-2);
  516. setColor(raised ? brighter : darker);
  517. drawLine(x, y, x, y + height - 1);
  518. drawLine(x + 1, y, x + width - 2, y);
  519. setColor(raised ? darker : brighter);
  520. drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1);
  521. drawLine(x + width - 1, y, x + width - 1, y + height - 2);
  522. setColor(c);
  523. }
  524. /**
  525. * Draws the outline of an oval.
  526. * The result is a circle or ellipse that fits within the
  527. * rectangle specified by the <code>x</code>, <code>y</code>,
  528. * <code>width</code>, and <code>height</code> arguments.
  529. * <p>
  530. * The oval covers an area that is
  531. * <code>width + 1</code> pixels wide
  532. * and <code>height + 1</code> pixels tall.
  533. * @param x the <i>x</i> coordinate of the upper left
  534. * corner of the oval to be drawn.
  535. * @param y the <i>y</i> coordinate of the upper left
  536. * corner of the oval to be drawn.
  537. * @param width the width of the oval to be drawn.
  538. * @param height the height of the oval to be drawn.
  539. * @see java.awt.Graphics#fillOval
  540. */
  541. public abstract void drawOval(int x, int y, int width, int height);
  542. /**
  543. * Fills an oval bounded by the specified rectangle with the
  544. * current color.
  545. * @param x the <i>x</i> coordinate of the upper left corner
  546. * of the oval to be filled.
  547. * @param y the <i>y</i> coordinate of the upper left corner
  548. * of the oval to be filled.
  549. * @param width the width of the oval to be filled.
  550. * @param height the height of the oval to be filled.
  551. * @see java.awt.Graphics#drawOval
  552. */
  553. public abstract void fillOval(int x, int y, int width, int height);
  554. /**
  555. * Draws the outline of a circular or elliptical arc
  556. * covering the specified rectangle.
  557. * <p>
  558. * The resulting arc begins at <code>startAngle</code> and extends
  559. * for <code>arcAngle</code> degrees, using the current color.
  560. * Angles are interpreted such that 0 degrees
  561. * is at the 3 o'clock position.
  562. * A positive value indicates a counter-clockwise rotation
  563. * while a negative value indicates a clockwise rotation.
  564. * <p>
  565. * The center of the arc is the center of the rectangle whose origin
  566. * is (<i>x</i>, <i>y</i>) and whose size is specified by the
  567. * <code>width</code> and <code>height</code> arguments.
  568. * <p>
  569. * The resulting arc covers an area
  570. * <code>width + 1</code> pixels wide
  571. * by <code>height + 1</code> pixels tall.
  572. * <p>
  573. * The angles are specified relative to the non-square extents of
  574. * the bounding rectangle such that 45 degrees always falls on the
  575. * line from the center of the ellipse to the upper right corner of
  576. * the bounding rectangle. As a result, if the bounding rectangle is
  577. * noticeably longer in one axis than the other, the angles to the
  578. * start and end of the arc segment will be skewed farther along the
  579. * longer axis of the bounds.
  580. * @param x the <i>x</i> coordinate of the
  581. * upper-left corner of the arc to be drawn.
  582. * @param y the <i>y</i> coordinate of the
  583. * upper-left corner of the arc to be drawn.
  584. * @param width the width of the arc to be drawn.
  585. * @param height the height of the arc to be drawn.
  586. * @param startAngle the beginning angle.
  587. * @param arcAngle the angular extent of the arc,
  588. * relative to the start angle.
  589. * @see java.awt.Graphics#fillArc
  590. */
  591. public abstract void drawArc(int x, int y, int width, int height,
  592. int startAngle, int arcAngle);
  593. /**
  594. * Fills a circular or elliptical arc covering the specified rectangle.
  595. * <p>
  596. * The resulting arc begins at <code>startAngle</code> and extends
  597. * for <code>arcAngle</code> degrees.
  598. * Angles are interpreted such that 0 degrees
  599. * is at the 3 o'clock position.
  600. * A positive value indicates a counter-clockwise rotation
  601. * while a negative value indicates a clockwise rotation.
  602. * <p>
  603. * The center of the arc is the center of the rectangle whose origin
  604. * is (<i>x</i>, <i>y</i>) and whose size is specified by the
  605. * <code>width</code> and <code>height</code> arguments.
  606. * <p>
  607. * The resulting arc covers an area
  608. * <code>width + 1</code> pixels wide
  609. * by <code>height + 1</code> pixels tall.
  610. * <p>
  611. * The angles are specified relative to the non-square extents of
  612. * the bounding rectangle such that 45 degrees always falls on the
  613. * line from the center of the ellipse to the upper right corner of
  614. * the bounding rectangle. As a result, if the bounding rectangle is
  615. * noticeably longer in one axis than the other, the angles to the
  616. * start and end of the arc segment will be skewed farther along the
  617. * longer axis of the bounds.
  618. * @param x the <i>x</i> coordinate of the
  619. * upper-left corner of the arc to be filled.
  620. * @param y the <i>y</i> coordinate of the
  621. * upper-left corner of the arc to be filled.
  622. * @param width the width of the arc to be filled.
  623. * @param height the height of the arc to be filled.
  624. * @param startAngle the beginning angle.
  625. * @param arcAngle the angular extent of the arc,
  626. * relative to the start angle.
  627. * @see java.awt.Graphics#drawArc
  628. */
  629. public abstract void fillArc(int x, int y, int width, int height,
  630. int startAngle, int arcAngle);
  631. /**
  632. * Draws a sequence of connected lines defined by
  633. * arrays of <i>x</i> and <i>y</i> coordinates.
  634. * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
  635. * The figure is not closed if the first point
  636. * differs from the last point.
  637. * @param xPoints an array of <i>x</i> points
  638. * @param yPoints an array of <i>y</i> points
  639. * @param nPoints the total number of points
  640. * @see java.awt.Graphics#drawPolygon(int[], int[], int)
  641. * @since JDK1.1
  642. */
  643. public abstract void drawPolyline(int xPoints[], int yPoints[],
  644. int nPoints);
  645. /**
  646. * Draws a closed polygon defined by
  647. * arrays of <i>x</i> and <i>y</i> coordinates.
  648. * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
  649. * <p>
  650. * This method draws the polygon defined by <code>nPoint</code> line
  651. * segments, where the first <code>nPoint - 1</code>
  652. * line segments are line segments from
  653. * <code>(xPoints[i - 1], yPoints[i - 1])</code>
  654. * to <code>(xPoints[i], yPoints[i])</code>, for
  655. * 1 ≤ <i>i</i> ≤ <code>nPoints</code>.
  656. * The figure is automatically closed by drawing a line connecting
  657. * the final point to the first point, if those points are different.
  658. * @param xPoints a an array of <code>x</code> coordinates.
  659. * @param yPoints a an array of <code>y</code> coordinates.
  660. * @param nPoints a the total number of points.
  661. * @see java.awt.Graphics#fillPolygon
  662. * @see java.awt.Graphics#drawPolyline
  663. */
  664. public abstract void drawPolygon(int xPoints[], int yPoints[],
  665. int nPoints);
  666. /**
  667. * Draws the outline of a polygon defined by the specified
  668. * <code>Polygon</code> object.
  669. * @param p the polygon to draw.
  670. * @see java.awt.Graphics#fillPolygon
  671. * @see java.awt.Graphics#drawPolyline
  672. */
  673. public void drawPolygon(Polygon p) {
  674. drawPolygon(p.xpoints, p.ypoints, p.npoints);
  675. }
  676. /**
  677. * Fills a closed polygon defined by
  678. * arrays of <i>x</i> and <i>y</i> coordinates.
  679. * <p>
  680. * This method draws the polygon defined by <code>nPoint</code> line
  681. * segments, where the first <code>nPoint - 1</code>
  682. * line segments are line segments from
  683. * <code>(xPoints[i - 1], yPoints[i - 1])</code>
  684. * to <code>(xPoints[i], yPoints[i])</code>, for
  685. * 1 ≤ <i>i</i> ≤ <code>nPoints</code>.
  686. * The figure is automatically closed by drawing a line connecting
  687. * the final point to the first point, if those points are different.
  688. * <p>
  689. * The area inside the polygon is defined using an
  690. * even-odd fill rule, also known as the alternating rule.
  691. * @param xPoints a an array of <code>x</code> coordinates.
  692. * @param yPoints a an array of <code>y</code> coordinates.
  693. * @param nPoints a the total number of points.
  694. * @see java.awt.Graphics#drawPolygon(int[], int[], int)
  695. */
  696. public abstract void fillPolygon(int xPoints[], int yPoints[],
  697. int nPoints);
  698. /**
  699. * Fills the polygon defined by the specified Polygon object with
  700. * the graphics context's current color.
  701. * <p>
  702. * The area inside the polygon is defined using an
  703. * even-odd fill rule, also known as the alternating rule.
  704. * @param p the polygon to fill.
  705. * @see java.awt.Graphics#drawPolygon(int[], int[], int)
  706. */
  707. public void fillPolygon(Polygon p) {
  708. fillPolygon(p.xpoints, p.ypoints, p.npoints);
  709. }
  710. /**
  711. * Draws the text given by the specified string, using this
  712. * graphics context's current font and color. The baseline of the
  713. * first character is at position (<i>x</i>, <i>y</i>) in this
  714. * graphics context's coordinate system.
  715. * @param str the string to be drawn.
  716. * @param x the <i>x</i> coordinate.
  717. * @param y the <i>y</i> coordinate.
  718. * @see java.awt.Graphics#drawBytes
  719. * @see java.awt.Graphics#drawChars
  720. */
  721. public abstract void drawString(String str, int x, int y);
  722. /**
  723. * Draws the text given by the specified iterator, using this
  724. * graphics context's current color. The iterator has to specify a font
  725. * for each character. The baseline of the
  726. * first character is at position (<i>x</i>, <i>y</i>) in this
  727. * graphics context's coordinate system.
  728. * @param iterator the iterator whose text is to be drawn
  729. * @param x the <i>x</i> coordinate.
  730. * @param y the <i>y</i> coordinate.
  731. * @see java.awt.Graphics#drawBytes
  732. * @see java.awt.Graphics#drawChars
  733. */
  734. public abstract void drawString(AttributedCharacterIterator iterator,
  735. int x, int y);
  736. /**
  737. * Draws the text given by the specified character array, using this
  738. * graphics context's current font and color. The baseline of the
  739. * first character is at position (<i>x</i>, <i>y</i>) in this
  740. * graphics context's coordinate system.
  741. * @param data the array of characters to be drawn
  742. * @param offset the start offset in the data
  743. * @param length the number of characters to be drawn
  744. * @param x the <i>x</i> coordinate of the baseline of the text
  745. * @param y the <i>y</i> coordinate of the baseline of the text
  746. * @see java.awt.Graphics#drawBytes
  747. * @see java.awt.Graphics#drawString
  748. */
  749. public void drawChars(char data[], int offset, int length, int x, int y) {
  750. drawString(new String(data, offset, length), x, y);
  751. }
  752. /**
  753. * Draws the text given by the specified byte array, using this
  754. * graphics context's current font and color. The baseline of the
  755. * first character is at position (<i>x</i>, <i>y</i>) in this
  756. * graphics context's coordinate system.
  757. * @param data the data to be drawn
  758. * @param offset the start offset in the data
  759. * @param length the number of bytes that are drawn
  760. * @param x the <i>x</i> coordinate of the baseline of the text
  761. * @param y the <i>y</i> coordinate of the baseline of the text
  762. * @see java.awt.Graphics#drawChars
  763. * @see java.awt.Graphics#drawString
  764. */
  765. public void drawBytes(byte data[], int offset, int length, int x, int y) {
  766. drawString(new String(data, 0, offset, length), x, y);
  767. }
  768. /**
  769. * Draws as much of the specified image as is currently available.
  770. * The image is drawn with its top-left corner at
  771. * (<i>x</i>, <i>y</i>) in this graphics context's coordinate
  772. * space. Transparent pixels in the image do not affect whatever
  773. * pixels are already there.
  774. * <p>
  775. * This method returns immediately in all cases, even if the
  776. * complete image has not yet been loaded, and it has not been dithered
  777. * and converted for the current output device.
  778. * <p>
  779. * If the image has not yet been completely loaded, then
  780. * <code>drawImage</code> returns <code>false</code>. As more of
  781. * the image becomes available, the process that draws the image notifies
  782. * the specified image observer.
  783. * @param img the specified image to be drawn.
  784. * @param x the <i>x</i> coordinate.
  785. * @param y the <i>y</i> coordinate.
  786. * @param observer object to be notified as more of
  787. * the image is converted.
  788. * @see java.awt.Image
  789. * @see java.awt.image.ImageObserver
  790. * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
  791. */
  792. public abstract boolean drawImage(Image img, int x, int y,
  793. ImageObserver observer);
  794. /**
  795. * Draws as much of the specified image as has already been scaled
  796. * to fit inside the specified rectangle.
  797. * <p>
  798. * The image is drawn inside the specified rectangle of this
  799. * graphics context's coordinate space, and is scaled if
  800. * necessary. Transparent pixels do not affect whatever pixels
  801. * are already there.
  802. * <p>
  803. * This method returns immediately in all cases, even if the
  804. * entire image has not yet been scaled, dithered, and converted
  805. * for the current output device.
  806. * If the current output representation is not yet complete, then
  807. * <code>drawImage</code> returns <code>false</code>. As more of
  808. * the image becomes available, the process that draws the image notifies
  809. * the image observer by calling its <code>imageUpdate</code> method.
  810. * <p>
  811. * A scaled version of an image will not necessarily be
  812. * available immediately just because an unscaled version of the
  813. * image has been constructed for this output device. Each size of
  814. * the image may be cached separately and generated from the original
  815. * data in a separate image production sequence.
  816. * @param img the specified image to be drawn.
  817. * @param x the <i>x</i> coordinate.
  818. * @param y the <i>y</i> coordinate.
  819. * @param width the width of the rectangle.
  820. * @param height the height of the rectangle.
  821. * @param observer object to be notified as more of
  822. * the image is converted.
  823. * @see java.awt.Image
  824. * @see java.awt.image.ImageObserver
  825. * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
  826. */
  827. public abstract boolean drawImage(Image img, int x, int y,
  828. int width, int height,
  829. ImageObserver observer);
  830. /**
  831. * Draws as much of the specified image as is currently available.
  832. * The image is drawn with its top-left corner at
  833. * (<i>x</i>, <i>y</i>) in this graphics context's coordinate
  834. * space. Transparent pixels are drawn in the specified
  835. * background color.
  836. * <p>
  837. * This operation is equivalent to filling a rectangle of the
  838. * width and height of the specified image with the given color and then
  839. * drawing the image on top of it, but possibly more efficient.
  840. * <p>
  841. * This method returns immediately in all cases, even if the
  842. * complete image has not yet been loaded, and it has not been dithered
  843. * and converted for the current output device.
  844. * <p>
  845. * If the image has not yet been completely loaded, then
  846. * <code>drawImage</code> returns <code>false</code>. As more of
  847. * the image becomes available, the process that draws the image notifies
  848. * the specified image observer.
  849. * @param img the specified image to be drawn.
  850. * @param x the <i>x</i> coordinate.
  851. * @param y the <i>y</i> coordinate.
  852. * @param bgcolor the background color to paint under the
  853. * non-opaque portions of the image.
  854. * @param observer object to be notified as more of
  855. * the image is converted.
  856. * @see java.awt.Image
  857. * @see java.awt.image.ImageObserver
  858. * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
  859. */
  860. public abstract boolean drawImage(Image img, int x, int y,
  861. Color bgcolor,
  862. ImageObserver observer);
  863. /**
  864. * Draws as much of the specified image as has already been scaled
  865. * to fit inside the specified rectangle.
  866. * <p>
  867. * The image is drawn inside the specified rectangle of this
  868. * graphics context's coordinate space, and is scaled if
  869. * necessary. Transparent pixels are drawn in the specified
  870. * background color.
  871. * This operation is equivalent to filling a rectangle of the
  872. * width and height of the specified image with the given color and then
  873. * drawing the image on top of it, but possibly more efficient.
  874. * <p>
  875. * This method returns immediately in all cases, even if the
  876. * entire image has not yet been scaled, dithered, and converted
  877. * for the current output device.
  878. * If the current output representation is not yet complete then
  879. * <code>drawImage</code> returns <code>false</code>. As more of
  880. * the image becomes available, the process that draws the image notifies
  881. * the specified image observer.
  882. * <p>
  883. * A scaled version of an image will not necessarily be
  884. * available immediately just because an unscaled version of the
  885. * image has been constructed for this output device. Each size of
  886. * the image may be cached separately and generated from the original
  887. * data in a separate image production sequence.
  888. * @param img the specified image to be drawn.
  889. * @param x the <i>x</i> coordinate.
  890. * @param y the <i>y</i> coordinate.
  891. * @param width the width of the rectangle.
  892. * @param height the height of the rectangle.
  893. * @param bgcolor the background color to paint under the
  894. * non-opaque portions of the image.
  895. * @param observer object to be notified as more of
  896. * the image is converted.
  897. * @see java.awt.Image
  898. * @see java.awt.image.ImageObserver
  899. * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
  900. */
  901. public abstract boolean drawImage(Image img, int x, int y,
  902. int width, int height,
  903. Color bgcolor,
  904. ImageObserver observer);
  905. /**
  906. * Draws as much of the specified area of the specified image as is
  907. * currently available, scaling it on the fly to fit inside the
  908. * specified area of the destination drawable surface. Transparent pixels
  909. * do not affect whatever pixels are already there.
  910. * <p>
  911. * This method returns immediately in all cases, even if the
  912. * image area to be drawn has not yet been scaled, dithered, and converted
  913. * for the current output device.
  914. * If the current output representation is not yet complete then
  915. * <code>drawImage</code> returns <code>false</code>. As more of
  916. * the image becomes available, the process that draws the image notifies
  917. * the specified image observer.
  918. * <p>
  919. * This method always uses the unscaled version of the image
  920. * to render the scaled rectangle and performs the required
  921. * scaling on the fly. It does not use a cached, scaled version
  922. * of the image for this operation. Scaling of the image from source
  923. * to destination is performed such that the first coordinate
  924. * of the source rectangle is mapped to the first coordinate of
  925. * the destination rectangle, and the second source coordinate is
  926. * mapped to the second destination coordinate. The subimage is
  927. * scaled and flipped as needed to preserve those mappings.
  928. * @param img the specified image to be drawn
  929. * @param dx1 the <i>x</i> coordinate of the first corner of the
  930. * destination rectangle.
  931. * @param dy1 the <i>y</i> coordinate of the first corner of the
  932. * destination rectangle.
  933. * @param dx2 the <i>x</i> coordinate of the second corner of the
  934. * destination rectangle.
  935. * @param dy2 the <i>y</i> coordinate of the second corner of the
  936. * destination rectangle.
  937. * @param sx1 the <i>x</i> coordinate of the first corner of the
  938. * source rectangle.
  939. * @param sy1 the <i>y</i> coordinate of the first corner of the
  940. * source rectangle.
  941. * @param sx2 the <i>x</i> coordinate of the second corner of the
  942. * source rectangle.
  943. * @param sy2 the <i>y</i> coordinate of the second corner of the
  944. * source rectangle.
  945. * @param observer object to be notified as more of the image is
  946. * scaled and converted.
  947. * @see java.awt.Image
  948. * @see java.awt.image.ImageObserver
  949. * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
  950. * @since JDK1.1
  951. */
  952. public abstract boolean drawImage(Image img,
  953. int dx1, int dy1, int dx2, int dy2,
  954. int sx1, int sy1, int sx2, int sy2,
  955. ImageObserver observer);
  956. /**
  957. * Draws as much of the specified area of the specified image as is
  958. * currently available, scaling it on the fly to fit inside the
  959. * specified area of the destination drawable surface.
  960. * <p>
  961. * Transparent pixels are drawn in the specified background color.
  962. * This operation is equivalent to filling a rectangle of the
  963. * width and height of the specified image with the given color and then
  964. * drawing the image on top of it, but possibly more efficient.
  965. * <p>
  966. * This method returns immediately in all cases, even if the
  967. * image area to be drawn has not yet been scaled, dithered, and converted
  968. * for the current output device.
  969. * If the current output representation is not yet complete then
  970. * <code>drawImage</code> returns <code>false</code>. As more of
  971. * the image becomes available, the process that draws the image notifies
  972. * the specified image observer.
  973. * <p>
  974. * This method always uses the unscaled version of the image
  975. * to render the scaled rectangle and performs the required
  976. * scaling on the fly. It does not use a cached, scaled version
  977. * of the image for this operation. Scaling of the image from source
  978. * to destination is performed such that the first coordinate
  979. * of the source rectangle is mapped to the first coordinate of
  980. * the destination rectangle, and the second source coordinate is
  981. * mapped to the second destination coordinate. The subimage is
  982. * scaled and flipped as needed to preserve those mappings.
  983. * @param img the specified image to be drawn
  984. * @param dx1 the <i>x</i> coordinate of the first corner of the
  985. * destination rectangle.
  986. * @param dy1 the <i>y</i> coordinate of the first corner of the
  987. * destination rectangle.
  988. * @param dx2 the <i>x</i> coordinate of the second corner of the
  989. * destination rectangle.
  990. * @param dy2 the <i>y</i> coordinate of the second corner of the
  991. * destination rectangle.
  992. * @param sx1 the <i>x</i> coordinate of the first corner of the
  993. * source rectangle.
  994. * @param sy1 the <i>y</i> coordinate of the first corner of the
  995. * source rectangle.
  996. * @param sx2 the <i>x</i> coordinate of the second corner of the
  997. * source rectangle.
  998. * @param sy2 the <i>y</i> coordinate of the second corner of the
  999. * source rectangle.
  1000. * @param bgcolor the background color to paint under the
  1001. * non-opaque portions of the image.
  1002. * @param observer object to be notified as more of the image is
  1003. * scaled and converted.
  1004. * @see java.awt.Image
  1005. * @see java.awt.image.ImageObserver
  1006. * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
  1007. * @since JDK1.1
  1008. */
  1009. public abstract boolean drawImage(Image img,
  1010. int dx1, int dy1, int dx2, int dy2,
  1011. int sx1, int sy1, int sx2, int sy2,
  1012. Color bgcolor,
  1013. ImageObserver observer);
  1014. /**
  1015. * Disposes of this graphics context and releases
  1016. * any system resources that it is using.
  1017. * A <code>Graphics</code> object cannot be used after
  1018. * <code>dispose</code>has been called.
  1019. * <p>
  1020. * When a Java program runs, a large number of <code>Graphics</code>
  1021. * objects can be created within a short time frame.
  1022. * Although the finalization process of the garbage collector
  1023. * also disposes of the same system resources, it is preferable
  1024. * to manually free the associated resources by calling this
  1025. * method rather than to rely on a finalization process which
  1026. * may not run to completion for a long period of time.
  1027. * <p>
  1028. * Graphics objects which are provided as arguments to the
  1029. * <code>paint</code> and <code>update</code> methods
  1030. * of components are automatically released by the system when
  1031. * those methods return. For efficiency, programmers should
  1032. * call <code>dispose</code> when finished using
  1033. * a <code>Graphics</code> object only if it was created
  1034. * directly from a component or another <code>Graphics</code> object.
  1035. * @see java.awt.Graphics#finalize
  1036. * @see java.awt.Component#paint
  1037. * @see java.awt.Component#update
  1038. * @see java.awt.Component#getGraphics
  1039. * @see java.awt.Graphics#create
  1040. */
  1041. public abstract void dispose();
  1042. /**
  1043. * Disposes of this graphics context once it is no longer referenced.
  1044. * @see #dispose
  1045. */
  1046. public void finalize() {
  1047. dispose();
  1048. }
  1049. /**
  1050. * Returns a <code>String</code> object representing this
  1051. * <code>Graphics</code> object's value.
  1052. * @return a string representation of this graphics context.
  1053. */
  1054. public String toString() {
  1055. return getClass().getName() + "[font=" + getFont() + ",color=" + getColor() + "]";
  1056. }
  1057. /**
  1058. * @deprecated As of JDK version 1.1,
  1059. * replaced by <code>getClipBounds()</code>.
  1060. */
  1061. public Rectangle getClipRect() {
  1062. return getClipBounds();
  1063. }
  1064. /**
  1065. * Returns true if the specified rectangular area intersects
  1066. * the bounding rectangle of the current clipping area.
  1067. * The coordinates in the rectangle are relative to the coordinate
  1068. * system origin of this graphics context.
  1069. *
  1070. * @param x the x coordinate of the rectangle to test against the clip
  1071. * @param y the y coordinate of the rectangle to test against the clip
  1072. * @param width the width of the rectangle to test against the clip
  1073. * @param height the height of the rectangle to test against the clip
  1074. */
  1075. public boolean hitClip(int x, int y, int width, int height) {
  1076. // Note, this implementation is not very efficient.
  1077. // Subclasses should override this method and calculate
  1078. // the results more directly.
  1079. Rectangle clipRect = getClipBounds();
  1080. if (clipRect == null) {
  1081. return true;
  1082. }
  1083. return clipRect.intersects(x, y, width, height);
  1084. }
  1085. /**
  1086. * Returns the bounding rectangle of the current clipping area.
  1087. * The coordinates in the rectangle are relative to the coordinate
  1088. * system origin of this graphics context. This method differs
  1089. * from {@link getClipBounds() getClipBounds} in that an existing
  1090. * rectangle is used instead of allocating a new one.
  1091. * This method refers to the user clip, which is independent of the
  1092. * clipping associated with device bounds and window visibility.
  1093. * If no clip has previously been set, or if the clip has been
  1094. * cleared using <code>setClip(null)</code>, this method returns the
  1095. * specified <code>Rectangle</code>.
  1096. * @param r the rectangle where the current clipping area is
  1097. * copied to. Any current values in this rectangle are
  1098. * overwritten.
  1099. * @return the bounding rectangle of the current clipping area.
  1100. */
  1101. public Rectangle getClipBounds(Rectangle r) {
  1102. // Note, this implementation is not very efficient.
  1103. // Subclasses should override this method and avoid
  1104. // the allocation overhead of getClipBounds().
  1105. Rectangle clipRect = getClipBounds();
  1106. if (clipRect != null) {
  1107. r.x = clipRect.x;
  1108. r.y = clipRect.y;
  1109. r.width = clipRect.width;
  1110. r.height = clipRect.height;
  1111. } else if (r == null) {
  1112. throw new NullPointerException("null rectangle parameter");
  1113. }
  1114. return r;
  1115. }
  1116. }