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