1. /*
  2. * @(#)DebugGraphics.java 1.25 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing;
  8. import java.awt.*;
  9. import java.awt.image.*;
  10. import java.text.AttributedCharacterIterator;
  11. /**
  12. * Graphics subclass supporting graphics debugging. Overrides most methods
  13. * from Graphics. DebugGraphics objects are rarely created by hand. They
  14. * are most frequently created automatically when a JComponent's
  15. * debugGraphicsOptions are changed using the setDebugGraphicsOptions()
  16. * method.
  17. * <p>
  18. * NOTE: You must turn off double buffering to use DebugGraphics:
  19. * RepaintManager repaintManager = RepaintManager.currentManager(component);
  20. * repaintManager.setDoubleBufferingEnabled(false);
  21. *
  22. * @see JComponent#setDebugGraphicsOptions
  23. * @see RepaintManager#currentManager
  24. * @see RepaintManager#setDoubleBufferingEnabled
  25. *
  26. * @version 1.25 12/19/03
  27. * @author Dave Karlton
  28. */
  29. public class DebugGraphics extends Graphics {
  30. Graphics graphics;
  31. Image buffer;
  32. int debugOptions;
  33. int graphicsID = graphicsCount++;
  34. int xOffset, yOffset;
  35. private static int graphicsCount = 0;
  36. /** Log graphics operations. */
  37. public static final int LOG_OPTION = 1 << 0;
  38. /** Flash graphics operations. */
  39. public static final int FLASH_OPTION = 1 << 1;
  40. /** Show buffered operations in a separate <code>Frame</code>. */
  41. public static final int BUFFERED_OPTION = 1 << 2;
  42. /** Don't debug graphics operations. */
  43. public static final int NONE_OPTION = -1;
  44. static {
  45. JComponent.DEBUG_GRAPHICS_LOADED = true;
  46. }
  47. /**
  48. * Constructs a new debug graphics context that supports slowed
  49. * down drawing.
  50. */
  51. public DebugGraphics() {
  52. super();
  53. buffer = null;
  54. xOffset = yOffset = 0;
  55. }
  56. /**
  57. * Constructs a debug graphics context from an existing graphics
  58. * context that slows down drawing for the specified component.
  59. *
  60. * @param graphics the Graphics context to slow down
  61. * @param component the JComponent to draw slowly
  62. */
  63. public DebugGraphics(Graphics graphics, JComponent component) {
  64. this(graphics);
  65. setDebugOptions(component.shouldDebugGraphics());
  66. }
  67. /**
  68. * Constructs a debug graphics context from an existing graphics
  69. * context that supports slowed down drawing.
  70. *
  71. * @param graphics the Graphics context to slow down
  72. */
  73. public DebugGraphics(Graphics graphics) {
  74. this();
  75. this.graphics = graphics;
  76. }
  77. /**
  78. * Overrides <code>Graphics.create</code> to return a DebugGraphics object.
  79. */
  80. public Graphics create() {
  81. DebugGraphics debugGraphics;
  82. debugGraphics = new DebugGraphics();
  83. debugGraphics.graphics = graphics.create();
  84. debugGraphics.debugOptions = debugOptions;
  85. debugGraphics.buffer = buffer;
  86. return debugGraphics;
  87. }
  88. /**
  89. * Overrides <code>Graphics.create</code> to return a DebugGraphics object.
  90. */
  91. public Graphics create(int x, int y, int width, int height) {
  92. DebugGraphics debugGraphics;
  93. debugGraphics = new DebugGraphics();
  94. debugGraphics.graphics = graphics.create(x, y, width, height);
  95. debugGraphics.debugOptions = debugOptions;
  96. debugGraphics.buffer = buffer;
  97. debugGraphics.xOffset = xOffset + x;
  98. debugGraphics.yOffset = yOffset + y;
  99. return debugGraphics;
  100. }
  101. //------------------------------------------------
  102. // NEW METHODS
  103. //------------------------------------------------
  104. /**
  105. * Sets the Color used to flash drawing operations.
  106. */
  107. public static void setFlashColor(Color flashColor) {
  108. info().flashColor = flashColor;
  109. }
  110. /**
  111. * Returns the Color used to flash drawing operations.
  112. * @see #setFlashColor
  113. */
  114. public static Color flashColor() {
  115. return info().flashColor;
  116. }
  117. /**
  118. * Sets the time delay of drawing operation flashing.
  119. */
  120. public static void setFlashTime(int flashTime) {
  121. info().flashTime = flashTime;
  122. }
  123. /**
  124. * Returns the time delay of drawing operation flashing.
  125. * @see #setFlashTime
  126. */
  127. public static int flashTime() {
  128. return info().flashTime;
  129. }
  130. /**
  131. * Sets the number of times that drawing operations will flash.
  132. */
  133. public static void setFlashCount(int flashCount) {
  134. info().flashCount = flashCount;
  135. }
  136. /** Returns the number of times that drawing operations will flash.
  137. * @see #setFlashCount
  138. */
  139. public static int flashCount() {
  140. return info().flashCount;
  141. }
  142. /** Sets the stream to which the DebugGraphics logs drawing operations.
  143. */
  144. public static void setLogStream(java.io.PrintStream stream) {
  145. info().stream = stream;
  146. }
  147. /** Returns the stream to which the DebugGraphics logs drawing operations.
  148. * @see #setLogStream
  149. */
  150. public static java.io.PrintStream logStream() {
  151. return info().stream;
  152. }
  153. /** Sets the Font used for text drawing operations.
  154. */
  155. public void setFont(Font aFont) {
  156. if (debugLog()) {
  157. info().log(toShortString() + " Setting font: " + aFont);
  158. }
  159. graphics.setFont(aFont);
  160. }
  161. /** Returns the Font used for text drawing operations.
  162. * @see #setFont
  163. */
  164. public Font getFont() {
  165. return graphics.getFont();
  166. }
  167. /** Sets the color to be used for drawing and filling lines and shapes.
  168. */
  169. public void setColor(Color aColor) {
  170. if (debugLog()) {
  171. info().log(toShortString() + " Setting color: " + aColor);
  172. }
  173. graphics.setColor(aColor);
  174. }
  175. /** Returns the Color used for text drawing operations.
  176. * @see #setColor
  177. */
  178. public Color getColor() {
  179. return graphics.getColor();
  180. }
  181. //-----------------------------------------------
  182. // OVERRIDDEN METHODS
  183. //------------------------------------------------
  184. /**
  185. * Overrides <code>Graphics.getFontMetrics</code>.
  186. */
  187. public FontMetrics getFontMetrics() {
  188. return graphics.getFontMetrics();
  189. }
  190. /**
  191. * Overrides <code>Graphics.getFontMetrics</code>.
  192. */
  193. public FontMetrics getFontMetrics(Font f) {
  194. return graphics.getFontMetrics(f);
  195. }
  196. /**
  197. * Overrides <code>Graphics.translate</code>.
  198. */
  199. public void translate(int x, int y) {
  200. if (debugLog()) {
  201. info().log(toShortString() +
  202. " Translating by: " + new Point(x, y));
  203. }
  204. xOffset += x;
  205. yOffset += y;
  206. graphics.translate(x, y);
  207. }
  208. /**
  209. * Overrides <code>Graphics.setPaintMode</code>.
  210. */
  211. public void setPaintMode() {
  212. if (debugLog()) {
  213. info().log(toShortString() + " Setting paint mode");
  214. }
  215. graphics.setPaintMode();
  216. }
  217. /**
  218. * Overrides <code>Graphics.setXORMode</code>.
  219. */
  220. public void setXORMode(Color aColor) {
  221. if (debugLog()) {
  222. info().log(toShortString() + " Setting XOR mode: " + aColor);
  223. }
  224. graphics.setXORMode(aColor);
  225. }
  226. /**
  227. * Overrides <code>Graphics.getClipBounds</code>.
  228. */
  229. public Rectangle getClipBounds() {
  230. return graphics.getClipBounds();
  231. }
  232. /**
  233. * Overrides <code>Graphics.clipRect</code>.
  234. */
  235. public void clipRect(int x, int y, int width, int height) {
  236. graphics.clipRect(x, y, width, height);
  237. if (debugLog()) {
  238. info().log(toShortString() +
  239. " Setting clipRect: " + (new Rectangle(x, y, width, height)) +
  240. " New clipRect: " + graphics.getClip());
  241. }
  242. }
  243. /**
  244. * Overrides <code>Graphics.setClip</code>.
  245. */
  246. public void setClip(int x, int y, int width, int height) {
  247. graphics.setClip(x, y, width, height);
  248. if (debugLog()) {
  249. info().log(toShortString() +
  250. " Setting new clipRect: " + graphics.getClip());
  251. }
  252. }
  253. /**
  254. * Overrides <code>Graphics.getClip</code>.
  255. */
  256. public Shape getClip() {
  257. return graphics.getClip();
  258. }
  259. /**
  260. * Overrides <code>Graphics.setClip</code>.
  261. */
  262. public void setClip(Shape clip) {
  263. graphics.setClip(clip);
  264. if (debugLog()) {
  265. info().log(toShortString() +
  266. " Setting new clipRect: " + graphics.getClip());
  267. }
  268. }
  269. /**
  270. * Overrides <code>Graphics.drawRect</code>.
  271. */
  272. public void drawRect(int x, int y, int width, int height) {
  273. DebugGraphicsInfo info = info();
  274. if (debugLog()) {
  275. info().log(toShortString() +
  276. " Drawing rect: " +
  277. new Rectangle(x, y, width, height));
  278. }
  279. if (isDrawingBuffer()) {
  280. if (debugBuffered()) {
  281. Graphics debugGraphics = debugGraphics();
  282. debugGraphics.drawRect(x, y, width, height);
  283. debugGraphics.dispose();
  284. }
  285. } else if (debugFlash()) {
  286. Color oldColor = getColor();
  287. int i, count = (info.flashCount * 2) - 1;
  288. for (i = 0; i < count; i++) {
  289. graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
  290. graphics.drawRect(x, y, width, height);
  291. Toolkit.getDefaultToolkit().sync();
  292. sleep(info.flashTime);
  293. }
  294. graphics.setColor(oldColor);
  295. }
  296. graphics.drawRect(x, y, width, height);
  297. }
  298. /**
  299. * Overrides <code>Graphics.fillRect</code>.
  300. */
  301. public void fillRect(int x, int y, int width, int height) {
  302. DebugGraphicsInfo info = info();
  303. if (debugLog()) {
  304. info().log(toShortString() +
  305. " Filling rect: " +
  306. new Rectangle(x, y, width, height));
  307. }
  308. if (isDrawingBuffer()) {
  309. if (debugBuffered()) {
  310. Graphics debugGraphics = debugGraphics();
  311. debugGraphics.fillRect(x, y, width, height);
  312. debugGraphics.dispose();
  313. }
  314. } else if (debugFlash()) {
  315. Color oldColor = getColor();
  316. int i, count = (info.flashCount * 2) - 1;
  317. for (i = 0; i < count; i++) {
  318. graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
  319. graphics.fillRect(x, y, width, height);
  320. Toolkit.getDefaultToolkit().sync();
  321. sleep(info.flashTime);
  322. }
  323. graphics.setColor(oldColor);
  324. }
  325. graphics.fillRect(x, y, width, height);
  326. }
  327. /**
  328. * Overrides <code>Graphics.clearRect</code>.
  329. */
  330. public void clearRect(int x, int y, int width, int height) {
  331. DebugGraphicsInfo info = info();
  332. if (debugLog()) {
  333. info().log(toShortString() +
  334. " Clearing rect: " +
  335. new Rectangle(x, y, width, height));
  336. }
  337. if (isDrawingBuffer()) {
  338. if (debugBuffered()) {
  339. Graphics debugGraphics = debugGraphics();
  340. debugGraphics.clearRect(x, y, width, height);
  341. debugGraphics.dispose();
  342. }
  343. } else if (debugFlash()) {
  344. Color oldColor = getColor();
  345. int i, count = (info.flashCount * 2) - 1;
  346. for (i = 0; i < count; i++) {
  347. graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
  348. graphics.clearRect(x, y, width, height);
  349. Toolkit.getDefaultToolkit().sync();
  350. sleep(info.flashTime);
  351. }
  352. graphics.setColor(oldColor);
  353. }
  354. graphics.clearRect(x, y, width, height);
  355. }
  356. /**
  357. * Overrides <code>Graphics.drawRoundRect</code>.
  358. */
  359. public void drawRoundRect(int x, int y, int width, int height,
  360. int arcWidth, int arcHeight) {
  361. DebugGraphicsInfo info = info();
  362. if (debugLog()) {
  363. info().log(toShortString() +
  364. " Drawing round rect: " +
  365. new Rectangle(x, y, width, height) +
  366. " arcWidth: " + arcWidth +
  367. " archHeight: " + arcHeight);
  368. }
  369. if (isDrawingBuffer()) {
  370. if (debugBuffered()) {
  371. Graphics debugGraphics = debugGraphics();
  372. debugGraphics.drawRoundRect(x, y, width, height,
  373. arcWidth, arcHeight);
  374. debugGraphics.dispose();
  375. }
  376. } else if (debugFlash()) {
  377. Color oldColor = getColor();
  378. int i, count = (info.flashCount * 2) - 1;
  379. for (i = 0; i < count; i++) {
  380. graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
  381. graphics.drawRoundRect(x, y, width, height,
  382. arcWidth, arcHeight);
  383. Toolkit.getDefaultToolkit().sync();
  384. sleep(info.flashTime);
  385. }
  386. graphics.setColor(oldColor);
  387. }
  388. graphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
  389. }
  390. /**
  391. * Overrides <code>Graphics.fillRoundRect</code>.
  392. */
  393. public void fillRoundRect(int x, int y, int width, int height,
  394. int arcWidth, int arcHeight) {
  395. DebugGraphicsInfo info = info();
  396. if (debugLog()) {
  397. info().log(toShortString() +
  398. " Filling round rect: " +
  399. new Rectangle(x, y, width, height) +
  400. " arcWidth: " + arcWidth +
  401. " archHeight: " + arcHeight);
  402. }
  403. if (isDrawingBuffer()) {
  404. if (debugBuffered()) {
  405. Graphics debugGraphics = debugGraphics();
  406. debugGraphics.fillRoundRect(x, y, width, height,
  407. arcWidth, arcHeight);
  408. debugGraphics.dispose();
  409. }
  410. } else if (debugFlash()) {
  411. Color oldColor = getColor();
  412. int i, count = (info.flashCount * 2) - 1;
  413. for (i = 0; i < count; i++) {
  414. graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
  415. graphics.fillRoundRect(x, y, width, height,
  416. arcWidth, arcHeight);
  417. Toolkit.getDefaultToolkit().sync();
  418. sleep(info.flashTime);
  419. }
  420. graphics.setColor(oldColor);
  421. }
  422. graphics.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
  423. }
  424. /**
  425. * Overrides <code>Graphics.drawLine</code>.
  426. */
  427. public void drawLine(int x1, int y1, int x2, int y2) {
  428. DebugGraphicsInfo info = info();
  429. if (debugLog()) {
  430. info().log(toShortString() +
  431. " Drawing line: from " + pointToString(x1, y1) +
  432. " to " + pointToString(x2, y2));
  433. }
  434. if (isDrawingBuffer()) {
  435. if (debugBuffered()) {
  436. Graphics debugGraphics = debugGraphics();
  437. debugGraphics.drawLine(x1, y1, x2, y2);
  438. debugGraphics.dispose();
  439. }
  440. } else if (debugFlash()) {
  441. Color oldColor = getColor();
  442. int i, count = (info.flashCount * 2) - 1;
  443. for (i = 0; i < count; i++) {
  444. graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
  445. graphics.drawLine(x1, y1, x2, y2);
  446. Toolkit.getDefaultToolkit().sync();
  447. sleep(info.flashTime);
  448. }
  449. graphics.setColor(oldColor);
  450. }
  451. graphics.drawLine(x1, y1, x2, y2);
  452. }
  453. /**
  454. * Overrides <code>Graphics.draw3DRect</code>.
  455. */
  456. public void draw3DRect(int x, int y, int width, int height,
  457. boolean raised) {
  458. DebugGraphicsInfo info = info();
  459. if (debugLog()) {
  460. info().log(toShortString() +
  461. " Drawing 3D rect: " +
  462. new Rectangle(x, y, width, height) +
  463. " Raised bezel: " + raised);
  464. }
  465. if (isDrawingBuffer()) {
  466. if (debugBuffered()) {
  467. Graphics debugGraphics = debugGraphics();
  468. debugGraphics.draw3DRect(x, y, width, height, raised);
  469. debugGraphics.dispose();
  470. }
  471. } else if (debugFlash()) {
  472. Color oldColor = getColor();
  473. int i, count = (info.flashCount * 2) - 1;
  474. for (i = 0; i < count; i++) {
  475. graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
  476. graphics.draw3DRect(x, y, width, height, raised);
  477. Toolkit.getDefaultToolkit().sync();
  478. sleep(info.flashTime);
  479. }
  480. graphics.setColor(oldColor);
  481. }
  482. graphics.draw3DRect(x, y, width, height, raised);
  483. }
  484. /**
  485. * Overrides <code>Graphics.fill3DRect</code>.
  486. */
  487. public void fill3DRect(int x, int y, int width, int height,
  488. boolean raised) {
  489. DebugGraphicsInfo info = info();
  490. if (debugLog()) {
  491. info().log(toShortString() +
  492. " Filling 3D rect: " +
  493. new Rectangle(x, y, width, height) +
  494. " Raised bezel: " + raised);
  495. }
  496. if (isDrawingBuffer()) {
  497. if (debugBuffered()) {
  498. Graphics debugGraphics = debugGraphics();
  499. debugGraphics.fill3DRect(x, y, width, height, raised);
  500. debugGraphics.dispose();
  501. }
  502. } else if (debugFlash()) {
  503. Color oldColor = getColor();
  504. int i, count = (info.flashCount * 2) - 1;
  505. for (i = 0; i < count; i++) {
  506. graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
  507. graphics.fill3DRect(x, y, width, height, raised);
  508. Toolkit.getDefaultToolkit().sync();
  509. sleep(info.flashTime);
  510. }
  511. graphics.setColor(oldColor);
  512. }
  513. graphics.fill3DRect(x, y, width, height, raised);
  514. }
  515. /**
  516. * Overrides <code>Graphics.drawOval</code>.
  517. */
  518. public void drawOval(int x, int y, int width, int height) {
  519. DebugGraphicsInfo info = info();
  520. if (debugLog()) {
  521. info().log(toShortString() +
  522. " Drawing oval: " +
  523. new Rectangle(x, y, width, height));
  524. }
  525. if (isDrawingBuffer()) {
  526. if (debugBuffered()) {
  527. Graphics debugGraphics = debugGraphics();
  528. debugGraphics.drawOval(x, y, width, height);
  529. debugGraphics.dispose();
  530. }
  531. } else if (debugFlash()) {
  532. Color oldColor = getColor();
  533. int i, count = (info.flashCount * 2) - 1;
  534. for (i = 0; i < count; i++) {
  535. graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
  536. graphics.drawOval(x, y, width, height);
  537. Toolkit.getDefaultToolkit().sync();
  538. sleep(info.flashTime);
  539. }
  540. graphics.setColor(oldColor);
  541. }
  542. graphics.drawOval(x, y, width, height);
  543. }
  544. /**
  545. * Overrides <code>Graphics.fillOval</code>.
  546. */
  547. public void fillOval(int x, int y, int width, int height) {
  548. DebugGraphicsInfo info = info();
  549. if (debugLog()) {
  550. info().log(toShortString() +
  551. " Filling oval: " +
  552. new Rectangle(x, y, width, height));
  553. }
  554. if (isDrawingBuffer()) {
  555. if (debugBuffered()) {
  556. Graphics debugGraphics = debugGraphics();
  557. debugGraphics.fillOval(x, y, width, height);
  558. debugGraphics.dispose();
  559. }
  560. } else if (debugFlash()) {
  561. Color oldColor = getColor();
  562. int i, count = (info.flashCount * 2) - 1;
  563. for (i = 0; i < count; i++) {
  564. graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
  565. graphics.fillOval(x, y, width, height);
  566. Toolkit.getDefaultToolkit().sync();
  567. sleep(info.flashTime);
  568. }
  569. graphics.setColor(oldColor);
  570. }
  571. graphics.fillOval(x, y, width, height);
  572. }
  573. /**
  574. * Overrides <code>Graphics.drawArc</code>.
  575. */
  576. public void drawArc(int x, int y, int width, int height,
  577. int startAngle, int arcAngle) {
  578. DebugGraphicsInfo info = info();
  579. if (debugLog()) {
  580. info().log(toShortString() +
  581. " Drawing arc: " +
  582. new Rectangle(x, y, width, height) +
  583. " startAngle: " + startAngle +
  584. " arcAngle: " + arcAngle);
  585. }
  586. if (isDrawingBuffer()) {
  587. if (debugBuffered()) {
  588. Graphics debugGraphics = debugGraphics();
  589. debugGraphics.drawArc(x, y, width, height,
  590. startAngle, arcAngle);
  591. debugGraphics.dispose();
  592. }
  593. } else if (debugFlash()) {
  594. Color oldColor = getColor();
  595. int i, count = (info.flashCount * 2) - 1;
  596. for (i = 0; i < count; i++) {
  597. graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
  598. graphics.drawArc(x, y, width, height, startAngle, arcAngle);
  599. Toolkit.getDefaultToolkit().sync();
  600. sleep(info.flashTime);
  601. }
  602. graphics.setColor(oldColor);
  603. }
  604. graphics.drawArc(x, y, width, height, startAngle, arcAngle);
  605. }
  606. /**
  607. * Overrides <code>Graphics.fillArc</code>.
  608. */
  609. public void fillArc(int x, int y, int width, int height,
  610. int startAngle, int arcAngle) {
  611. DebugGraphicsInfo info = info();
  612. if (debugLog()) {
  613. info().log(toShortString() +
  614. " Filling arc: " +
  615. new Rectangle(x, y, width, height) +
  616. " startAngle: " + startAngle +
  617. " arcAngle: " + arcAngle);
  618. }
  619. if (isDrawingBuffer()) {
  620. if (debugBuffered()) {
  621. Graphics debugGraphics = debugGraphics();
  622. debugGraphics.fillArc(x, y, width, height,
  623. startAngle, arcAngle);
  624. debugGraphics.dispose();
  625. }
  626. } else if (debugFlash()) {
  627. Color oldColor = getColor();
  628. int i, count = (info.flashCount * 2) - 1;
  629. for (i = 0; i < count; i++) {
  630. graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
  631. graphics.fillArc(x, y, width, height, startAngle, arcAngle);
  632. Toolkit.getDefaultToolkit().sync();
  633. sleep(info.flashTime);
  634. }
  635. graphics.setColor(oldColor);
  636. }
  637. graphics.fillArc(x, y, width, height, startAngle, arcAngle);
  638. }
  639. /**
  640. * Overrides <code>Graphics.drawPolyline</code>.
  641. */
  642. public void drawPolyline(int xPoints[], int yPoints[], int nPoints) {
  643. DebugGraphicsInfo info = info();
  644. if (debugLog()) {
  645. info().log(toShortString() +
  646. " Drawing polyline: " +
  647. " nPoints: " + nPoints +
  648. " X's: " + xPoints +
  649. " Y's: " + yPoints);
  650. }
  651. if (isDrawingBuffer()) {
  652. if (debugBuffered()) {
  653. Graphics debugGraphics = debugGraphics();
  654. debugGraphics.drawPolyline(xPoints, yPoints, nPoints);
  655. debugGraphics.dispose();
  656. }
  657. } else if (debugFlash()) {
  658. Color oldColor = getColor();
  659. int i, count = (info.flashCount * 2) - 1;
  660. for (i = 0; i < count; i++) {
  661. graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
  662. graphics.drawPolyline(xPoints, yPoints, nPoints);
  663. Toolkit.getDefaultToolkit().sync();
  664. sleep(info.flashTime);
  665. }
  666. graphics.setColor(oldColor);
  667. }
  668. graphics.drawPolyline(xPoints, yPoints, nPoints);
  669. }
  670. /**
  671. * Overrides <code>Graphics.drawPolygon</code>.
  672. */
  673. public void drawPolygon(int xPoints[], int yPoints[], int nPoints) {
  674. DebugGraphicsInfo info = info();
  675. if (debugLog()) {
  676. info().log(toShortString() +
  677. " Drawing polygon: " +
  678. " nPoints: " + nPoints +
  679. " X's: " + xPoints +
  680. " Y's: " + yPoints);
  681. }
  682. if (isDrawingBuffer()) {
  683. if (debugBuffered()) {
  684. Graphics debugGraphics = debugGraphics();
  685. debugGraphics.drawPolygon(xPoints, yPoints, nPoints);
  686. debugGraphics.dispose();
  687. }
  688. } else if (debugFlash()) {
  689. Color oldColor = getColor();
  690. int i, count = (info.flashCount * 2) - 1;
  691. for (i = 0; i < count; i++) {
  692. graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
  693. graphics.drawPolygon(xPoints, yPoints, nPoints);
  694. Toolkit.getDefaultToolkit().sync();
  695. sleep(info.flashTime);
  696. }
  697. graphics.setColor(oldColor);
  698. }
  699. graphics.drawPolygon(xPoints, yPoints, nPoints);
  700. }
  701. /**
  702. * Overrides <code>Graphics.fillPolygon</code>.
  703. */
  704. public void fillPolygon(int xPoints[], int yPoints[], int nPoints) {
  705. DebugGraphicsInfo info = info();
  706. if (debugLog()) {
  707. info().log(toShortString() +
  708. " Filling polygon: " +
  709. " nPoints: " + nPoints +
  710. " X's: " + xPoints +
  711. " Y's: " + yPoints);
  712. }
  713. if (isDrawingBuffer()) {
  714. if (debugBuffered()) {
  715. Graphics debugGraphics = debugGraphics();
  716. debugGraphics.fillPolygon(xPoints, yPoints, nPoints);
  717. debugGraphics.dispose();
  718. }
  719. } else if (debugFlash()) {
  720. Color oldColor = getColor();
  721. int i, count = (info.flashCount * 2) - 1;
  722. for (i = 0; i < count; i++) {
  723. graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
  724. graphics.fillPolygon(xPoints, yPoints, nPoints);
  725. Toolkit.getDefaultToolkit().sync();
  726. sleep(info.flashTime);
  727. }
  728. graphics.setColor(oldColor);
  729. }
  730. graphics.fillPolygon(xPoints, yPoints, nPoints);
  731. }
  732. /**
  733. * Overrides <code>Graphics.drawString</code>.
  734. */
  735. public void drawString(String aString, int x, int y) {
  736. DebugGraphicsInfo info = info();
  737. if (debugLog()) {
  738. info().log(toShortString() +
  739. " Drawing string: \"" + aString +
  740. "\" at: " + new Point(x, y));
  741. }
  742. if (isDrawingBuffer()) {
  743. if (debugBuffered()) {
  744. Graphics debugGraphics = debugGraphics();
  745. debugGraphics.drawString(aString, x, y);
  746. debugGraphics.dispose();
  747. }
  748. } else if (debugFlash()) {
  749. Color oldColor = getColor();
  750. int i, count = (info.flashCount * 2) - 1;
  751. for (i = 0; i < count; i++) {
  752. graphics.setColor((i % 2) == 0 ? info.flashColor
  753. : oldColor);
  754. graphics.drawString(aString, x, y);
  755. Toolkit.getDefaultToolkit().sync();
  756. sleep(info.flashTime);
  757. }
  758. graphics.setColor(oldColor);
  759. }
  760. graphics.drawString(aString, x, y);
  761. }
  762. /**
  763. * Overrides <code>Graphics.drawString</code>.
  764. */
  765. public void drawString(AttributedCharacterIterator iterator, int x, int y) {
  766. DebugGraphicsInfo info = info();
  767. if (debugLog()) {
  768. info().log(toShortString() +
  769. " Drawing text: \"" + iterator +
  770. "\" at: " + new Point(x, y));
  771. }
  772. if (isDrawingBuffer()) {
  773. if (debugBuffered()) {
  774. Graphics debugGraphics = debugGraphics();
  775. debugGraphics.drawString(iterator, x, y);
  776. debugGraphics.dispose();
  777. }
  778. } else if (debugFlash()) {
  779. Color oldColor = getColor();
  780. int i, count = (info.flashCount * 2) - 1;
  781. for (i = 0; i < count; i++) {
  782. graphics.setColor((i % 2) == 0 ? info.flashColor
  783. : oldColor);
  784. graphics.drawString(iterator, x, y);
  785. Toolkit.getDefaultToolkit().sync();
  786. sleep(info.flashTime);
  787. }
  788. graphics.setColor(oldColor);
  789. }
  790. graphics.drawString(iterator, x, y);
  791. }
  792. /**
  793. * Overrides <code>Graphics.drawBytes</code>.
  794. */
  795. public void drawBytes(byte data[], int offset, int length, int x, int y) {
  796. DebugGraphicsInfo info = info();
  797. Font font = graphics.getFont();
  798. if (debugLog()) {
  799. info().log(toShortString() +
  800. " Drawing bytes at: " + new Point(x, y));
  801. }
  802. if (isDrawingBuffer()) {
  803. if (debugBuffered()) {
  804. Graphics debugGraphics = debugGraphics();
  805. debugGraphics.drawBytes(data, offset, length, x, y);
  806. debugGraphics.dispose();
  807. }
  808. } else if (debugFlash()) {
  809. Color oldColor = getColor();
  810. int i, count = (info.flashCount * 2) - 1;
  811. for (i = 0; i < count; i++) {
  812. graphics.setColor((i % 2) == 0 ? info.flashColor
  813. : oldColor);
  814. graphics.drawBytes(data, offset, length, x, y);
  815. Toolkit.getDefaultToolkit().sync();
  816. sleep(info.flashTime);
  817. }
  818. graphics.setColor(oldColor);
  819. }
  820. graphics.drawBytes(data, offset, length, x, y);
  821. }
  822. /**
  823. * Overrides <code>Graphics.drawChars</code>.
  824. */
  825. public void drawChars(char data[], int offset, int length, int x, int y) {
  826. DebugGraphicsInfo info = info();
  827. Font font = graphics.getFont();
  828. if (debugLog()) {
  829. info().log(toShortString() +
  830. " Drawing chars at " + new Point(x, y));
  831. }
  832. if (isDrawingBuffer()) {
  833. if (debugBuffered()) {
  834. Graphics debugGraphics = debugGraphics();
  835. debugGraphics.drawChars(data, offset, length, x, y);
  836. debugGraphics.dispose();
  837. }
  838. } else if (debugFlash()) {
  839. Color oldColor = getColor();
  840. int i, count = (info.flashCount * 2) - 1;
  841. for (i = 0; i < count; i++) {
  842. graphics.setColor((i % 2) == 0 ? info.flashColor
  843. : oldColor);
  844. graphics.drawChars(data, offset, length, x, y);
  845. Toolkit.getDefaultToolkit().sync();
  846. sleep(info.flashTime);
  847. }
  848. graphics.setColor(oldColor);
  849. }
  850. graphics.drawChars(data, offset, length, x, y);
  851. }
  852. /**
  853. * Overrides <code>Graphics.drawImage</code>.
  854. */
  855. public boolean drawImage(Image img, int x, int y,
  856. ImageObserver observer) {
  857. DebugGraphicsInfo info = info();
  858. if (debugLog()) {
  859. info.log(toShortString() +
  860. " Drawing image: " + img +
  861. " at: " + new Point(x, y));
  862. }
  863. if (isDrawingBuffer()) {
  864. if (debugBuffered()) {
  865. Graphics debugGraphics = debugGraphics();
  866. debugGraphics.drawImage(img, x, y, observer);
  867. debugGraphics.dispose();
  868. }
  869. } else if (debugFlash()) {
  870. int i, count = (info.flashCount * 2) - 1;
  871. ImageProducer oldProducer = img.getSource();
  872. ImageProducer newProducer
  873. = new FilteredImageSource(oldProducer,
  874. new DebugGraphicsFilter(info.flashColor));
  875. Image newImage
  876. = Toolkit.getDefaultToolkit().createImage(newProducer);
  877. DebugGraphicsObserver imageObserver
  878. = new DebugGraphicsObserver();
  879. for (i = 0; i < count; i++) {
  880. graphics.drawImage((i % 2) == 0 ? newImage : img, x, y,
  881. imageObserver);
  882. Toolkit.getDefaultToolkit().sync();
  883. while (!imageObserver.allBitsPresent() &&
  884. !imageObserver.imageHasProblem()) {
  885. sleep(10);
  886. }
  887. sleep(info.flashTime);
  888. }
  889. }
  890. return graphics.drawImage(img, x, y, observer);
  891. }
  892. /**
  893. * Overrides <code>Graphics.drawImage</code>.
  894. */
  895. public boolean drawImage(Image img, int x, int y, int width, int height,
  896. ImageObserver observer) {
  897. DebugGraphicsInfo info = info();
  898. if (debugLog()) {
  899. info.log(toShortString() +
  900. " Drawing image: " + img +
  901. " at: " + new Rectangle(x, y, width, height));
  902. }
  903. if (isDrawingBuffer()) {
  904. if (debugBuffered()) {
  905. Graphics debugGraphics = debugGraphics();
  906. debugGraphics.drawImage(img, x, y, width, height, observer);
  907. debugGraphics.dispose();
  908. }
  909. } else if (debugFlash()) {
  910. int i, count = (info.flashCount * 2) - 1;
  911. ImageProducer oldProducer = img.getSource();
  912. ImageProducer newProducer
  913. = new FilteredImageSource(oldProducer,
  914. new DebugGraphicsFilter(info.flashColor));
  915. Image newImage
  916. = Toolkit.getDefaultToolkit().createImage(newProducer);
  917. DebugGraphicsObserver imageObserver
  918. = new DebugGraphicsObserver();
  919. for (i = 0; i < count; i++) {
  920. graphics.drawImage((i % 2) == 0 ? newImage : img, x, y,
  921. width, height, imageObserver);
  922. Toolkit.getDefaultToolkit().sync();
  923. while (!imageObserver.allBitsPresent() &&
  924. !imageObserver.imageHasProblem()) {
  925. sleep(10);
  926. }
  927. sleep(info.flashTime);
  928. }
  929. }
  930. return graphics.drawImage(img, x, y, width, height, observer);
  931. }
  932. /**
  933. * Overrides <code>Graphics.drawImage</code>.
  934. */
  935. public boolean drawImage(Image img, int x, int y,
  936. Color bgcolor,
  937. ImageObserver observer) {
  938. DebugGraphicsInfo info = info();
  939. if (debugLog()) {
  940. info.log(toShortString() +
  941. " Drawing image: " + img +
  942. " at: " + new Point(x, y) +
  943. ", bgcolor: " + bgcolor);
  944. }
  945. if (isDrawingBuffer()) {
  946. if (debugBuffered()) {
  947. Graphics debugGraphics = debugGraphics();
  948. debugGraphics.drawImage(img, x, y, bgcolor, observer);
  949. debugGraphics.dispose();
  950. }
  951. } else if (debugFlash()) {
  952. int i, count = (info.flashCount * 2) - 1;
  953. ImageProducer oldProducer = img.getSource();
  954. ImageProducer newProducer
  955. = new FilteredImageSource(oldProducer,
  956. new DebugGraphicsFilter(info.flashColor));
  957. Image newImage
  958. = Toolkit.getDefaultToolkit().createImage(newProducer);
  959. DebugGraphicsObserver imageObserver
  960. = new DebugGraphicsObserver();
  961. for (i = 0; i < count; i++) {
  962. graphics.drawImage((i % 2) == 0 ? newImage : img, x, y,
  963. bgcolor, imageObserver);
  964. Toolkit.getDefaultToolkit().sync();
  965. while (!imageObserver.allBitsPresent() &&
  966. !imageObserver.imageHasProblem()) {
  967. sleep(10);
  968. }
  969. sleep(info.flashTime);
  970. }
  971. }
  972. return graphics.drawImage(img, x, y, bgcolor, observer);
  973. }
  974. /**
  975. * Overrides <code>Graphics.drawImage</code>.
  976. */
  977. public boolean drawImage(Image img, int x, int y,int width, int height,
  978. Color bgcolor,
  979. ImageObserver observer) {
  980. DebugGraphicsInfo info = info();
  981. if (debugLog()) {
  982. info.log(toShortString() +
  983. " Drawing image: " + img +
  984. " at: " + new Rectangle(x, y, width, height) +
  985. ", bgcolor: " + bgcolor);
  986. }
  987. if (isDrawingBuffer()) {
  988. if (debugBuffered()) {
  989. Graphics debugGraphics = debugGraphics();
  990. debugGraphics.drawImage(img, x, y, width, height,
  991. bgcolor, observer);
  992. debugGraphics.dispose();
  993. }
  994. } else if (debugFlash()) {
  995. int i, count = (info.flashCount * 2) - 1;
  996. ImageProducer oldProducer = img.getSource();
  997. ImageProducer newProducer
  998. = new FilteredImageSource(oldProducer,
  999. new DebugGraphicsFilter(info.flashColor));
  1000. Image newImage
  1001. = Toolkit.getDefaultToolkit().createImage(newProducer);
  1002. DebugGraphicsObserver imageObserver
  1003. = new DebugGraphicsObserver();
  1004. for (i = 0; i < count; i++) {
  1005. graphics.drawImage((i % 2) == 0 ? newImage : img, x, y,
  1006. width, height, bgcolor, imageObserver);
  1007. Toolkit.getDefaultToolkit().sync();
  1008. while (!imageObserver.allBitsPresent() &&
  1009. !imageObserver.imageHasProblem()) {
  1010. sleep(10);
  1011. }
  1012. sleep(info.flashTime);
  1013. }
  1014. }
  1015. return graphics.drawImage(img, x, y, width, height, bgcolor, observer);
  1016. }
  1017. /**
  1018. * Overrides <code>Graphics.drawImage</code>.
  1019. */
  1020. public boolean drawImage(Image img,
  1021. int dx1, int dy1, int dx2, int dy2,
  1022. int sx1, int sy1, int sx2, int sy2,
  1023. ImageObserver observer) {
  1024. DebugGraphicsInfo info = info();
  1025. if (debugLog()) {
  1026. info.log(toShortString() +
  1027. " Drawing image: " + img +
  1028. " destination: " + new Rectangle(dx1, dy1, dx2, dy2) +
  1029. " source: " + new Rectangle(sx1, sy1, sx2, sy2));
  1030. }
  1031. if (isDrawingBuffer()) {
  1032. if (debugBuffered()) {
  1033. Graphics debugGraphics = debugGraphics();
  1034. debugGraphics.drawImage(img, dx1, dy1, dx2, dy2,
  1035. sx1, sy1, sx2, sy2, observer);
  1036. debugGraphics.dispose();
  1037. }
  1038. } else if (debugFlash()) {
  1039. int i, count = (info.flashCount * 2) - 1;
  1040. ImageProducer oldProducer = img.getSource();
  1041. ImageProducer newProducer
  1042. = new FilteredImageSource(oldProducer,
  1043. new DebugGraphicsFilter(info.flashColor));
  1044. Image newImage
  1045. = Toolkit.getDefaultToolkit().createImage(newProducer);
  1046. DebugGraphicsObserver imageObserver
  1047. = new DebugGraphicsObserver();
  1048. for (i = 0; i < count; i++) {
  1049. graphics.drawImage((i % 2) == 0 ? newImage : img,
  1050. dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2,
  1051. imageObserver);
  1052. Toolkit.getDefaultToolkit().sync();
  1053. while (!imageObserver.allBitsPresent() &&
  1054. !imageObserver.imageHasProblem()) {
  1055. sleep(10);
  1056. }
  1057. sleep(info.flashTime);
  1058. }
  1059. }
  1060. return graphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2,
  1061. observer);
  1062. }
  1063. /**
  1064. * Overrides <code>Graphics.drawImage</code>.
  1065. */
  1066. public boolean drawImage(Image img,
  1067. int dx1, int dy1, int dx2, int dy2,
  1068. int sx1, int sy1, int sx2, int sy2,
  1069. Color bgcolor,
  1070. ImageObserver observer) {
  1071. DebugGraphicsInfo info = info();
  1072. if (debugLog()) {
  1073. info.log(toShortString() +
  1074. " Drawing image: " + img +
  1075. " destination: " + new Rectangle(dx1, dy1, dx2, dy2) +
  1076. " source: " + new Rectangle(sx1, sy1, sx2, sy2) +
  1077. ", bgcolor: " + bgcolor);
  1078. }
  1079. if (isDrawingBuffer()) {
  1080. if (debugBuffered()) {
  1081. Graphics debugGraphics = debugGraphics();
  1082. debugGraphics.drawImage(img, dx1, dy1, dx2, dy2,
  1083. sx1, sy1, sx2, sy2, bgcolor, observer);
  1084. debugGraphics.dispose();
  1085. }
  1086. } else if (debugFlash()) {
  1087. int i, count = (info.flashCount * 2) - 1;
  1088. ImageProducer oldProducer = img.getSource();
  1089. ImageProducer newProducer
  1090. = new FilteredImageSource(oldProducer,
  1091. new DebugGraphicsFilter(info.flashColor));
  1092. Image newImage
  1093. = Toolkit.getDefaultToolkit().createImage(newProducer);
  1094. DebugGraphicsObserver imageObserver
  1095. = new DebugGraphicsObserver();
  1096. for (i = 0; i < count; i++) {
  1097. graphics.drawImage((i % 2) == 0 ? newImage : img,
  1098. dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2,
  1099. bgcolor, imageObserver);
  1100. Toolkit.getDefaultToolkit().sync();
  1101. while (!imageObserver.allBitsPresent() &&
  1102. !imageObserver.imageHasProblem()) {
  1103. sleep(10);
  1104. }
  1105. sleep(info.flashTime);
  1106. }
  1107. }
  1108. return graphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2,
  1109. bgcolor, observer);
  1110. }
  1111. /**
  1112. * Overrides <code>Graphics.copyArea</code>.
  1113. */
  1114. public void copyArea(int x, int y, int width, int height,
  1115. int destX, int destY) {
  1116. if (debugLog()) {
  1117. info().log(toShortString() +
  1118. " Copying area from: " +
  1119. new Rectangle(x, y, width, height) +
  1120. " to: " + new Point(destX, destY));
  1121. }
  1122. graphics.copyArea(x, y, width, height, destX, destY);
  1123. }
  1124. final void sleep(int mSecs) {
  1125. try {
  1126. Thread.sleep(mSecs);
  1127. } catch (Exception e) {
  1128. }
  1129. }
  1130. /**
  1131. * Overrides <code>Graphics.dispose</code>.
  1132. */
  1133. public void dispose() {
  1134. graphics.dispose();
  1135. graphics = null;
  1136. }
  1137. // ALERT!
  1138. /**
  1139. * Returns the drawingBuffer value.
  1140. *
  1141. * @return true if this object is drawing from a Buffer
  1142. */
  1143. public boolean isDrawingBuffer() {
  1144. return buffer != null;
  1145. }
  1146. String toShortString() {
  1147. StringBuffer buffer = new StringBuffer("Graphics" + (isDrawingBuffer() ? "<B>" : "") + "(" + graphicsID + "-" + debugOptions + ")");
  1148. return buffer.toString();
  1149. }
  1150. String pointToString(int x, int y) {
  1151. StringBuffer buffer = new StringBuffer("(" + x + ", " + y + ")");
  1152. return buffer.toString();
  1153. }
  1154. /** Enables/disables diagnostic information about every graphics
  1155. * operation. The value of <b>options</b> indicates how this information
  1156. * should be displayed. LOG_OPTION causes a text message to be printed.
  1157. * FLASH_OPTION causes the drawing to flash several times. BUFFERED_OPTION
  1158. * creates a new Frame that shows each operation on an
  1159. * offscreen buffer. The value of <b>options</b> is bitwise OR'd into
  1160. * the current value. To disable debugging use NONE_OPTION.
  1161. */
  1162. public void setDebugOptions(int options) {
  1163. if (options != 0) {
  1164. if (options == NONE_OPTION) {
  1165. if (debugOptions != 0) {
  1166. System.err.println(toShortString() + " Disabling debug");
  1167. debugOptions = 0;
  1168. }
  1169. } else {
  1170. if (debugOptions != options) {
  1171. debugOptions |= options;
  1172. if (debugLog()) {
  1173. System.err.println(toShortString() + " Enabling debug");
  1174. }
  1175. }
  1176. }
  1177. }
  1178. }
  1179. /** Returns the current debugging options for this DebugGraphics.
  1180. * @see #setDebugOptions
  1181. */
  1182. public int getDebugOptions() {
  1183. return debugOptions;
  1184. }
  1185. /** Static wrapper method for DebugGraphicsInfo.setDebugOptions(). Stores
  1186. * options on a per component basis.
  1187. */
  1188. static void setDebugOptions(JComponent component, int options) {
  1189. info().setDebugOptions(component, options);
  1190. }
  1191. /** Static wrapper method for DebugGraphicsInfo.getDebugOptions().
  1192. */
  1193. static int getDebugOptions(JComponent component) {
  1194. DebugGraphicsInfo debugGraphicsInfo = info();
  1195. if (debugGraphicsInfo == null) {
  1196. return 0;
  1197. } else {
  1198. return debugGraphicsInfo.getDebugOptions(component);
  1199. }
  1200. }
  1201. /** Returns non-zero if <b>component</b> should display with DebugGraphics,
  1202. * zero otherwise. Walks the JComponent's parent tree to determine if
  1203. * any debugging options have been set.
  1204. */
  1205. static int shouldComponentDebug(JComponent component) {
  1206. DebugGraphicsInfo info = info();
  1207. if (info == null) {
  1208. return 0;
  1209. } else {
  1210. Container container = (Container)component;
  1211. int debugOptions = 0;
  1212. while (container != null && (container instanceof JComponent)) {
  1213. debugOptions |= info.getDebugOptions((JComponent)container);
  1214. container = container.getParent();
  1215. }
  1216. return debugOptions;
  1217. }
  1218. }
  1219. /** Returns the number of JComponents that have debugging options turned
  1220. * on.
  1221. */
  1222. static int debugComponentCount() {
  1223. DebugGraphicsInfo debugGraphicsInfo = info();
  1224. if (debugGraphicsInfo != null &&
  1225. debugGraphicsInfo.componentToDebug != null) {
  1226. return debugGraphicsInfo.componentToDebug.size();
  1227. } else {
  1228. return 0;
  1229. }
  1230. }
  1231. boolean debugLog() {
  1232. return (debugOptions & LOG_OPTION) == LOG_OPTION;
  1233. }
  1234. boolean debugFlash() {
  1235. return (debugOptions & FLASH_OPTION) == FLASH_OPTION;
  1236. }
  1237. boolean debugBuffered() {
  1238. return (debugOptions & BUFFERED_OPTION) == BUFFERED_OPTION;
  1239. }
  1240. /** Returns a DebugGraphics for use in buffering window.
  1241. */
  1242. private Graphics debugGraphics() {
  1243. DebugGraphics debugGraphics;
  1244. DebugGraphicsInfo info = info();
  1245. JFrame debugFrame;
  1246. if (info.debugFrame == null) {
  1247. info.debugFrame = new JFrame();
  1248. info.debugFrame.setSize(500, 500);
  1249. }
  1250. debugFrame = info.debugFrame;
  1251. debugFrame.show();
  1252. debugGraphics = new DebugGraphics(debugFrame.getGraphics());
  1253. debugGraphics.setFont(getFont());
  1254. debugGraphics.setColor(getColor());
  1255. debugGraphics.translate(xOffset, yOffset);
  1256. debugGraphics.setClip(getClipBounds());
  1257. if (debugFlash()) {
  1258. debugGraphics.setDebugOptions(FLASH_OPTION);
  1259. }
  1260. return debugGraphics;
  1261. }
  1262. /** Returns DebugGraphicsInfo, or creates one if none exists.
  1263. */
  1264. static DebugGraphicsInfo info() {
  1265. DebugGraphicsInfo debugGraphicsInfo = (DebugGraphicsInfo)
  1266. SwingUtilities.appContextGet(debugGraphicsInfoKey);
  1267. if (debugGraphicsInfo == null) {
  1268. debugGraphicsInfo = new DebugGraphicsInfo();
  1269. SwingUtilities.appContextPut(debugGraphicsInfoKey,
  1270. debugGraphicsInfo);
  1271. }
  1272. return debugGraphicsInfo;
  1273. }
  1274. private static final Class debugGraphicsInfoKey = DebugGraphicsInfo.class;
  1275. }