Source Code Cross Referenced for DebugGraphics.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » javax package » javax.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
0003:         *  contributor license agreements.  See the NOTICE file distributed with
0004:         *  this work for additional information regarding copyright ownership.
0005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
0006:         *  (the "License"); you may not use this file except in compliance with
0007:         *  the License.  You may obtain a copy of the License at
0008:         *
0009:         *     http://www.apache.org/licenses/LICENSE-2.0
0010:         *
0011:         *  Unless required by applicable law or agreed to in writing, software
0012:         *  distributed under the License is distributed on an "AS IS" BASIS,
0013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         *  See the License for the specific language governing permissions and
0015:         *  limitations under the License.
0016:         */
0017:
0018:        package javax.swing;
0019:
0020:        import java.awt.Color;
0021:        import java.awt.Font;
0022:        import java.awt.FontMetrics;
0023:        import java.awt.Frame;
0024:        import java.awt.Graphics;
0025:        import java.awt.Graphics2D;
0026:        import java.awt.Image;
0027:        import java.awt.Point;
0028:        import java.awt.Polygon;
0029:        import java.awt.Rectangle;
0030:        import java.awt.Shape;
0031:        import java.awt.event.ActionEvent;
0032:        import java.awt.image.ImageObserver;
0033:        import java.io.PrintStream;
0034:        import java.text.AttributedCharacterIterator;
0035:        import java.util.HashMap;
0036:        import java.util.Map;
0037:        import org.apache.harmony.x.swing.Utilities;
0038:
0039:        /**
0040:         * <p>
0041:         * <i>DebugGraphics</i>
0042:         * </p>
0043:         * <h3>Implementation Notes:</h3>
0044:         * <ul>
0045:         * <li>The <code>serialVersionUID</code> fields are explicitly declared as a performance
0046:         * optimization, not as a guarantee of serialization compatibility.</li>
0047:         * </ul>
0048:         */
0049:        public class DebugGraphics extends Graphics {
0050:            private abstract static class FlashAction extends AbstractAction {
0051:                private Graphics g;
0052:
0053:                public FlashAction(Graphics g) {
0054:                    this .g = g;
0055:                }
0056:
0057:                public void actionPerformed(ActionEvent e) {
0058:                    for (int i = 0; i < flashCount; i++) {
0059:                        Color oldColor = g.getColor();
0060:                        paint(g);
0061:                        sleep(flashTime);
0062:                        g.setColor(flashColor);
0063:                        paint(g);
0064:                        sleep(flashTime);
0065:                        g.setColor(oldColor);
0066:                    }
0067:                }
0068:
0069:                private void sleep(int millis) {
0070:                    try {
0071:                        Thread.sleep(millis);
0072:                    } catch (InterruptedException e) {
0073:
0074:                    }
0075:                }
0076:
0077:                public abstract void paint(Graphics g);
0078:            }
0079:
0080:            private abstract class BufferedDrawAction extends AbstractAction {
0081:                public void actionPerformed(ActionEvent e) {
0082:                    if (externalFrames == null) {
0083:                        externalFrames = new HashMap<JComponent, Frame>();
0084:                    }
0085:                    Frame externalFrame = externalFrames.get(component);
0086:                    if (externalFrame == null || !externalFrame.isDisplayable()) {
0087:                        externalFrame = new Frame();
0088:                        externalFrames.put(component, externalFrame);
0089:                        externalFrame.setVisible(true);
0090:                    }
0091:                    if (component != null) {
0092:                        externalFrame.setSize(Utilities.addInsets(component
0093:                                .getSize(), externalFrame.getInsets()));
0094:                    } else {
0095:                        externalFrame.setSize(200, 200);
0096:                    }
0097:
0098:                    Graphics g = externalFrame.getGraphics();
0099:                    g.clearRect(0, 0, 200, 200);
0100:                    externalFrame.paint(g);
0101:                    g.translate(externalFrame.getInsets().left, externalFrame
0102:                            .getInsets().top);
0103:                    ((Graphics2D) g)
0104:                            .setTransform(((Graphics2D) originalGraphics)
0105:                                    .getTransform());
0106:
0107:                    g.setColor(originalGraphics.getColor());
0108:
0109:                    if (isFlashing()) {
0110:                        new FlashAction(g) {
0111:                            private static final long serialVersionUID = 1L;
0112:
0113:                            @Override
0114:                            public void paint(Graphics g) {
0115:                                BufferedDrawAction.this .paint(g);
0116:                            }
0117:                        }.actionPerformed(null);
0118:                    }
0119:                    g.drawRect(0, 0, 40, 40);
0120:                    paint(g);
0121:                    g.dispose();
0122:                }
0123:
0124:                public abstract void paint(Graphics g);
0125:            }
0126:
0127:            public static final int NONE_OPTION = -1;
0128:            public static final int LOG_OPTION = 1;
0129:            public static final int FLASH_OPTION = 2;
0130:            public static final int BUFFERED_OPTION = 4;
0131:
0132:            private static int debugGraphicsCount;
0133:            private static Map<JComponent, Frame> externalFrames;
0134:
0135:            private Graphics originalGraphics;
0136:            private JComponent component;
0137:            private int debugOptions;
0138:            private int this Number;
0139:            private boolean drawingBuffer;
0140:
0141:            private static Color flashColor = Color.RED;
0142:            private static int flashCount = 2;
0143:            private static int flashTime = 100;
0144:            private static PrintStream logStream = System.out;
0145:
0146:            public static void setFlashColor(Color flashColor) {
0147:                DebugGraphics.flashColor = flashColor;
0148:            }
0149:
0150:            public static Color flashColor() {
0151:                return flashColor;
0152:            }
0153:
0154:            public static void setFlashCount(int flashCount) {
0155:                DebugGraphics.flashCount = flashCount;
0156:            }
0157:
0158:            public static int flashCount() {
0159:                return flashCount;
0160:            }
0161:
0162:            public static void setFlashTime(int flashTime) {
0163:                DebugGraphics.flashTime = flashTime;
0164:            }
0165:
0166:            public static int flashTime() {
0167:                return flashTime;
0168:            }
0169:
0170:            public static void setLogStream(PrintStream stream) {
0171:                logStream = stream;
0172:            }
0173:
0174:            public static PrintStream logStream() {
0175:                return logStream;
0176:            }
0177:
0178:            public DebugGraphics(Graphics g, JComponent c) {
0179:                originalGraphics = (g == null ? null : g.create());
0180:                component = c;
0181:                this Number = debugGraphicsCount++;
0182:            }
0183:
0184:            public DebugGraphics(Graphics g) {
0185:                this (g, null);
0186:            }
0187:
0188:            public DebugGraphics() {
0189:                this (null, null);
0190:            }
0191:
0192:            public int getDebugOptions() {
0193:                return debugOptions;
0194:            }
0195:
0196:            public void setDebugOptions(int options) {
0197:                boolean wasLogging = isLogging();
0198:                if (options == NONE_OPTION) {
0199:                    debugOptions = 0;
0200:                } else {
0201:                    debugOptions |= options;
0202:                }
0203:                if (isLogging() && !wasLogging) {
0204:                    log("logging enabled");
0205:                }
0206:                if (!isLogging() && wasLogging) {
0207:                    log("logging disabled");
0208:                }
0209:            }
0210:
0211:            public boolean isDrawingBuffer() {
0212:                return drawingBuffer;
0213:            }
0214:
0215:            @Override
0216:            public void clearRect(final int x, final int y, final int width,
0217:                    final int height) {
0218:                if (isLogging()) {
0219:                    log("Clearing rect: " + new Rectangle(x, y, width, height));
0220:                }
0221:                if (isFlashing()) {
0222:                    new FlashAction(originalGraphics) {
0223:                        private static final long serialVersionUID = 1L;
0224:
0225:                        @Override
0226:                        public void paint(Graphics g) {
0227:                            g.fillRect(x, y, width, height);
0228:                        }
0229:                    }.actionPerformed(null);
0230:                }
0231:                if (isBuffered()) {
0232:                    new BufferedDrawAction() {
0233:                        private static final long serialVersionUID = 1L;
0234:
0235:                        @Override
0236:                        public void paint(Graphics g) {
0237:                            g.fillRect(x, y, width, height);
0238:                        }
0239:                    }.actionPerformed(null);
0240:                }
0241:                originalGraphics.clearRect(x, y, width, height);
0242:            }
0243:
0244:            @Override
0245:            public void clipRect(final int x, final int y, final int width,
0246:                    final int height) {
0247:                if (isLogging()) {
0248:                    log("Setting clipRect: "
0249:                            + new Rectangle(x, y, width, height));
0250:                }
0251:                if (isFlashing()) {
0252:                }
0253:                if (isBuffered()) {
0254:                }
0255:                originalGraphics.clipRect(x, y, width, height);
0256:            }
0257:
0258:            @Override
0259:            public void copyArea(final int x, final int y, final int width,
0260:                    final int height, final int destX, final int destY) {
0261:                if (isLogging()) {
0262:                    log("Copying area from: "
0263:                            + new Rectangle(x, y, width, height) + " to : "
0264:                            + new Point(destX, destY));
0265:                }
0266:                if (isFlashing()) {
0267:                    fillRect(x, y, width, height);
0268:                    new FlashAction(originalGraphics) {
0269:                        private static final long serialVersionUID = 1L;
0270:
0271:                        @Override
0272:                        public void paint(Graphics g) {
0273:                            g.fillRect(x, y, width, height);
0274:                        }
0275:                    }.actionPerformed(null);
0276:                }
0277:                if (isBuffered()) {
0278:                }
0279:                originalGraphics.copyArea(x, y, width, height, destX, destY);
0280:            }
0281:
0282:            @Override
0283:            public Graphics create() {
0284:                DebugGraphics result = new DebugGraphics(originalGraphics,
0285:                        component);
0286:                result.setDebugOptions(debugOptions);
0287:                return result;
0288:            }
0289:
0290:            @Override
0291:            public Graphics create(final int x, final int y, final int width,
0292:                    final int height) {
0293:                DebugGraphics result = new DebugGraphics(originalGraphics
0294:                        .create(x, y, width, height), component);
0295:                result.setDebugOptions(debugOptions);
0296:                return result;
0297:            }
0298:
0299:            @Override
0300:            public void dispose() {
0301:                originalGraphics.dispose();
0302:            }
0303:
0304:            @Override
0305:            public void draw3DRect(final int x, final int y, final int width,
0306:                    final int height, final boolean raised) {
0307:                if (isLogging()) {
0308:                    log("Drawing 3D rect: "
0309:                            + new Rectangle(x, y, width, height)
0310:                            + ", raised bezel: " + raised);
0311:                }
0312:                if (isFlashing()) {
0313:                    new FlashAction(originalGraphics) {
0314:                        private static final long serialVersionUID = 1L;
0315:
0316:                        @Override
0317:                        public void paint(Graphics g) {
0318:                            g.draw3DRect(x, y, width, height, raised);
0319:                        }
0320:                    }.actionPerformed(null);
0321:                }
0322:                if (isBuffered()) {
0323:                }
0324:                originalGraphics.draw3DRect(x, y, width, height, raised);
0325:            }
0326:
0327:            @Override
0328:            public void drawArc(final int x, final int y, final int width,
0329:                    final int height, final int startAngle, final int arcAngle) {
0330:                if (isLogging()) {
0331:                    log("Drawing arc: " + new Rectangle(x, y, width, height)
0332:                            + ", startAngle: " + startAngle + ", arcAngle: "
0333:                            + arcAngle);
0334:                }
0335:                if (isFlashing()) {
0336:                    new FlashAction(originalGraphics) {
0337:                        private static final long serialVersionUID = 1L;
0338:
0339:                        @Override
0340:                        public void paint(Graphics g) {
0341:                            g
0342:                                    .drawArc(x, y, width, height, startAngle,
0343:                                            arcAngle);
0344:                        }
0345:                    }.actionPerformed(null);
0346:                }
0347:                if (isBuffered()) {
0348:                }
0349:                originalGraphics.drawArc(x, y, width, height, startAngle,
0350:                        arcAngle);
0351:            }
0352:
0353:            @Override
0354:            public void drawBytes(final byte[] data, final int offset,
0355:                    final int length, final int x, final int y) {
0356:                if (isLogging()) {
0357:                    log("Drawing bytes at: " + new Point(x, y));
0358:                }
0359:                if (isFlashing()) {
0360:                    new FlashAction(originalGraphics) {
0361:                        private static final long serialVersionUID = 1L;
0362:
0363:                        @Override
0364:                        public void paint(Graphics g) {
0365:                            g.drawBytes(data, offset, length, x, y);
0366:                        }
0367:                    }.actionPerformed(null);
0368:                }
0369:                if (isBuffered()) {
0370:                }
0371:                originalGraphics.drawBytes(data, offset, length, x, y);
0372:            }
0373:
0374:            @Override
0375:            public void drawChars(final char[] data, final int offset,
0376:                    final int length, final int x, final int y) {
0377:                if (isLogging()) {
0378:                    log("Drawing chars at: " + new Point(x, y));
0379:                }
0380:                if (isFlashing()) {
0381:                    new FlashAction(originalGraphics) {
0382:                        private static final long serialVersionUID = 1L;
0383:
0384:                        @Override
0385:                        public void paint(Graphics g) {
0386:                            g.drawChars(data, offset, length, x, y);
0387:                        }
0388:                    }.actionPerformed(null);
0389:                }
0390:                if (isBuffered()) {
0391:                }
0392:                originalGraphics.drawChars(data, offset, length, x, y);
0393:            }
0394:
0395:            @Override
0396:            public boolean drawImage(final Image img, final int x, final int y,
0397:                    final Color bgcolor, final ImageObserver observer) {
0398:                if (isLogging()) {
0399:                    log("Drawing image: " + img + " at " + new Point(x, y)
0400:                            + ", bgcolor: " + bgcolor);
0401:                }
0402:                if (isFlashing()) {
0403:                    new FlashAction(originalGraphics) {
0404:                        private static final long serialVersionUID = 1L;
0405:
0406:                        @Override
0407:                        public void paint(Graphics g) {
0408:                            g.fillRect(x, y, img.getHeight(observer), img
0409:                                    .getHeight(observer));
0410:                        }
0411:                    }.actionPerformed(null);
0412:                }
0413:                if (isBuffered()) {
0414:                }
0415:                return originalGraphics.drawImage(img, x, y, bgcolor, observer);
0416:            }
0417:
0418:            @Override
0419:            public boolean drawImage(final Image img, final int x, final int y,
0420:                    final ImageObserver observer) {
0421:                if (isLogging()) {
0422:                    log("Drawing image: " + img + " at " + new Point(x, y));
0423:                }
0424:                if (isFlashing()) {
0425:                    new FlashAction(originalGraphics) {
0426:                        private static final long serialVersionUID = 1L;
0427:
0428:                        @Override
0429:                        public void paint(Graphics g) {
0430:                            g.fillRect(x, y, img.getHeight(observer), img
0431:                                    .getHeight(observer));
0432:                        }
0433:                    }.actionPerformed(null);
0434:                }
0435:                if (isBuffered()) {
0436:                }
0437:                return originalGraphics.drawImage(img, x, y, observer);
0438:            }
0439:
0440:            @Override
0441:            public boolean drawImage(final Image img, final int x, final int y,
0442:                    final int width, final int height, final Color bgcolor,
0443:                    final ImageObserver observer) {
0444:
0445:                if (isLogging()) {
0446:                    log("Drawing image: " + img + " at "
0447:                            + new Rectangle(x, y, width, height)
0448:                            + ", bgcolor: " + bgcolor);
0449:                }
0450:                if (isFlashing()) {
0451:                    new FlashAction(originalGraphics) {
0452:                        private static final long serialVersionUID = 1L;
0453:
0454:                        @Override
0455:                        public void paint(Graphics g) {
0456:                            g.fillRect(x, y, img.getHeight(observer), img
0457:                                    .getHeight(observer));
0458:                        }
0459:                    }.actionPerformed(null);
0460:                }
0461:                if (isBuffered()) {
0462:                }
0463:                return originalGraphics.drawImage(img, x, y, width, height,
0464:                        bgcolor, observer);
0465:            }
0466:
0467:            @Override
0468:            public boolean drawImage(final Image img, final int x, final int y,
0469:                    final int width, final int height,
0470:                    final ImageObserver observer) {
0471:                if (isLogging()) {
0472:                    log("Drawing image: " + img + " at "
0473:                            + new Rectangle(x, y, width, height));
0474:                }
0475:                if (isFlashing()) {
0476:                    new FlashAction(originalGraphics) {
0477:                        private static final long serialVersionUID = 1L;
0478:
0479:                        @Override
0480:                        public void paint(Graphics g) {
0481:                            g.fillRect(x, y, img.getHeight(observer), img
0482:                                    .getHeight(observer));
0483:                        }
0484:                    }.actionPerformed(null);
0485:                }
0486:                if (isBuffered()) {
0487:                }
0488:                return originalGraphics.drawImage(img, x, y, width, height,
0489:                        observer);
0490:            }
0491:
0492:            @Override
0493:            public boolean drawImage(final Image img, final int dx1,
0494:                    final int dy1, final int dx2, final int dy2, final int sx1,
0495:                    final int sy1, final int sx2, final int sy2,
0496:                    final Color bgcolor, final ImageObserver observer) {
0497:                if (isLogging()) {
0498:                    log("Drawing image: " + img + ", destination: "
0499:                            + new Rectangle(dx1, dy1, dx2, dy2) + ", source: "
0500:                            + new Rectangle(sx1, sy1, sx2, sy2) + ", bgcolor: "
0501:                            + bgcolor);
0502:                }
0503:                if (isFlashing()) {
0504:                    new FlashAction(originalGraphics) {
0505:                        private static final long serialVersionUID = 1L;
0506:
0507:                        @Override
0508:                        public void paint(Graphics g) {
0509:                            g.fillRect(dx1, dy1, dx2 - dx1, dy2 - dy1);
0510:                        }
0511:                    }.actionPerformed(null);
0512:                }
0513:                if (isBuffered()) {
0514:                }
0515:                return originalGraphics.drawImage(img, dx1, dy1, dx2, dy2, sx1,
0516:                        sy1, sx2, sy2, bgcolor, observer);
0517:            }
0518:
0519:            @Override
0520:            public boolean drawImage(final Image img, final int dx1,
0521:                    final int dy1, final int dx2, final int dy2, final int sx1,
0522:                    final int sy1, final int sx2, final int sy2,
0523:                    final ImageObserver observer) {
0524:
0525:                if (isLogging()) {
0526:                    log("Drawing image: " + img + ", destination: "
0527:                            + new Rectangle(dx1, dy1, dx2, dy2) + ", source: "
0528:                            + new Rectangle(sx1, sy1, sx2, sy2));
0529:                }
0530:                if (isFlashing()) {
0531:                    new FlashAction(originalGraphics) {
0532:                        private static final long serialVersionUID = 1L;
0533:
0534:                        @Override
0535:                        public void paint(Graphics g) {
0536:                            g.fillRect(dx1, dy1, dx2 - dx1, dy2 - dy1);
0537:                        }
0538:                    }.actionPerformed(null);
0539:                }
0540:                if (isBuffered()) {
0541:                }
0542:                return originalGraphics.drawImage(img, dx1, dy1, dx2, dy2, sx1,
0543:                        sy1, sx2, sy2, observer);
0544:            }
0545:
0546:            @Override
0547:            public void drawLine(final int x1, final int y1, final int x2,
0548:                    final int y2) {
0549:                if (isLogging()) {
0550:                    log("Drawing line: from (" + x1 + ", " + y1 + ") to (" + x2
0551:                            + ", " + y2 + ")");
0552:                }
0553:                if (isFlashing()) {
0554:                    new FlashAction(originalGraphics) {
0555:                        private static final long serialVersionUID = 1L;
0556:
0557:                        @Override
0558:                        public void paint(Graphics g) {
0559:                            g.drawLine(x1, y1, x2, y2);
0560:                        }
0561:                    }.actionPerformed(null);
0562:                }
0563:                if (isBuffered()) {
0564:                    new BufferedDrawAction() {
0565:                        private static final long serialVersionUID = 1L;
0566:
0567:                        @Override
0568:                        public void paint(Graphics g) {
0569:                            g.drawLine(x1, y1, x2, y2);
0570:                        }
0571:                    }.actionPerformed(null);
0572:                }
0573:                originalGraphics.drawLine(x1, y1, x2, y2);
0574:            }
0575:
0576:            @Override
0577:            public void drawOval(final int x, final int y, final int width,
0578:                    final int height) {
0579:                if (isLogging()) {
0580:                    log("Drawing oval: " + new Rectangle(x, y, width, height));
0581:                }
0582:                if (isFlashing()) {
0583:                    new FlashAction(originalGraphics) {
0584:                        private static final long serialVersionUID = 1L;
0585:
0586:                        @Override
0587:                        public void paint(Graphics g) {
0588:                            g.drawOval(x, y, width, height);
0589:                        }
0590:                    }.actionPerformed(null);
0591:                }
0592:                if (isBuffered()) {
0593:                }
0594:                originalGraphics.drawOval(x, y, width, height);
0595:            }
0596:
0597:            @Override
0598:            public void drawPolygon(final int[] xPoints, final int[] yPoints,
0599:                    final int nPoints) {
0600:                if (isLogging()) {
0601:                    log("Drawing polygon: "
0602:                            + new Polygon(xPoints, yPoints, nPoints));
0603:                }
0604:                if (isFlashing()) {
0605:                    new FlashAction(originalGraphics) {
0606:                        private static final long serialVersionUID = 1L;
0607:
0608:                        @Override
0609:                        public void paint(Graphics g) {
0610:                            g.drawPolygon(xPoints, yPoints, nPoints);
0611:                        }
0612:                    }.actionPerformed(null);
0613:                }
0614:                if (isBuffered()) {
0615:                }
0616:                originalGraphics.drawPolygon(xPoints, yPoints, nPoints);
0617:            }
0618:
0619:            @Override
0620:            public void drawPolyline(final int[] xPoints, final int[] yPoints,
0621:                    final int nPoints) {
0622:                if (isLogging()) {
0623:                    log("Drawing polyline: "
0624:                            + new Polygon(xPoints, yPoints, nPoints));
0625:                }
0626:                if (isFlashing()) {
0627:                    new FlashAction(originalGraphics) {
0628:                        private static final long serialVersionUID = 1L;
0629:
0630:                        @Override
0631:                        public void paint(Graphics g) {
0632:                            g.drawPolyline(xPoints, yPoints, nPoints);
0633:                        }
0634:                    }.actionPerformed(null);
0635:                }
0636:                if (isBuffered()) {
0637:                }
0638:                originalGraphics.drawPolyline(xPoints, yPoints, nPoints);
0639:            }
0640:
0641:            @Override
0642:            public void drawRect(final int x, final int y, final int width,
0643:                    final int height) {
0644:                if (isLogging()) {
0645:                    log("Drawing rectangle: "
0646:                            + new Rectangle(x, y, width, height));
0647:                }
0648:                if (isFlashing()) {
0649:                    new FlashAction(originalGraphics) {
0650:                        private static final long serialVersionUID = 1L;
0651:
0652:                        @Override
0653:                        public void paint(Graphics g) {
0654:                            g.drawRect(x, y, width, height);
0655:                        }
0656:                    }.actionPerformed(null);
0657:                }
0658:                if (isBuffered()) {
0659:                }
0660:                originalGraphics.drawRect(x, y, width, height);
0661:            }
0662:
0663:            @Override
0664:            public void drawRoundRect(final int x, final int y,
0665:                    final int width, final int height, final int arcWidth,
0666:                    final int arcHeight) {
0667:                if (isLogging()) {
0668:                    log("Drawing round rectangle: "
0669:                            + new Rectangle(x, y, width, height)
0670:                            + ", arcWidth " + arcWidth + ", arcHeight "
0671:                            + arcHeight);
0672:                }
0673:                if (isFlashing()) {
0674:                    new FlashAction(originalGraphics) {
0675:                        private static final long serialVersionUID = 1L;
0676:
0677:                        @Override
0678:                        public void paint(Graphics g) {
0679:                            g.drawRoundRect(x, y, width, height, arcWidth,
0680:                                    arcHeight);
0681:                        }
0682:                    }.actionPerformed(null);
0683:                }
0684:                if (isBuffered()) {
0685:                }
0686:                originalGraphics.drawRoundRect(x, y, width, height, arcWidth,
0687:                        arcHeight);
0688:            }
0689:
0690:            @Override
0691:            public void drawString(final AttributedCharacterIterator iterator,
0692:                    final int x, final int y) {
0693:                if (isLogging()) {
0694:                    log("Drawing string: " + iterator + " at "
0695:                            + new Point(x, y));
0696:                }
0697:                if (isFlashing()) {
0698:                    new FlashAction(originalGraphics) {
0699:                        private static final long serialVersionUID = 1L;
0700:
0701:                        @Override
0702:                        public void paint(Graphics g) {
0703:                            g.drawString(iterator, x, y);
0704:                        }
0705:                    }.actionPerformed(null);
0706:                }
0707:                if (isBuffered()) {
0708:                }
0709:                originalGraphics.drawString(iterator, x, y);
0710:            }
0711:
0712:            @Override
0713:            public void drawString(final String str, final int x, final int y) {
0714:                if (isLogging()) {
0715:                    log("Drawing string: " + str + " at " + new Point(x, y));
0716:                }
0717:                if (isFlashing()) {
0718:                    new FlashAction(originalGraphics) {
0719:                        private static final long serialVersionUID = 1L;
0720:
0721:                        @Override
0722:                        public void paint(Graphics g) {
0723:                            g.drawString(str, x, y);
0724:                        }
0725:                    }.actionPerformed(null);
0726:                }
0727:                if (isBuffered()) {
0728:                }
0729:                originalGraphics.drawString(str, x, y);
0730:            }
0731:
0732:            @Override
0733:            public void fill3DRect(final int x, final int y, final int width,
0734:                    final int height, final boolean raised) {
0735:                if (isLogging()) {
0736:                    log("Filling 3D rect: "
0737:                            + new Rectangle(x, y, width, height)
0738:                            + ", raised bezel: " + raised);
0739:                }
0740:                if (isFlashing()) {
0741:                    new FlashAction(originalGraphics) {
0742:                        private static final long serialVersionUID = 1L;
0743:
0744:                        @Override
0745:                        public void paint(Graphics g) {
0746:                            g.fill3DRect(x, y, width, height, raised);
0747:                        }
0748:                    }.actionPerformed(null);
0749:                }
0750:                if (isBuffered()) {
0751:                }
0752:                originalGraphics.fill3DRect(x, y, width, height, raised);
0753:            }
0754:
0755:            @Override
0756:            public void fillArc(final int x, final int y, final int width,
0757:                    final int height, final int startAngle, final int arcAngle) {
0758:                if (isLogging()) {
0759:                    log("Filling arc: " + new Rectangle(x, y, width, height)
0760:                            + ", startAngle: " + startAngle + ", arcAngle: "
0761:                            + arcAngle);
0762:                }
0763:                if (isFlashing()) {
0764:                    new FlashAction(originalGraphics) {
0765:                        private static final long serialVersionUID = 1L;
0766:
0767:                        @Override
0768:                        public void paint(Graphics g) {
0769:                            g
0770:                                    .fillArc(x, y, width, height, startAngle,
0771:                                            arcAngle);
0772:                        }
0773:                    }.actionPerformed(null);
0774:                }
0775:                if (isBuffered()) {
0776:                }
0777:                originalGraphics.fillArc(x, y, width, height, startAngle,
0778:                        arcAngle);
0779:            }
0780:
0781:            @Override
0782:            public void fillOval(final int x, final int y, final int width,
0783:                    final int height) {
0784:                if (isLogging()) {
0785:                    log("Filling oval: " + new Rectangle(x, y, width, height));
0786:                }
0787:                if (isFlashing()) {
0788:                    new FlashAction(originalGraphics) {
0789:                        private static final long serialVersionUID = 1L;
0790:
0791:                        @Override
0792:                        public void paint(Graphics g) {
0793:                            g.fillOval(x, y, width, height);
0794:                        }
0795:                    }.actionPerformed(null);
0796:                }
0797:                if (isBuffered()) {
0798:                }
0799:                originalGraphics.fillOval(x, y, width, height);
0800:            }
0801:
0802:            @Override
0803:            public void fillPolygon(final int[] xPoints, final int[] yPoints,
0804:                    final int nPoints) {
0805:                if (isLogging()) {
0806:                    log("Filling polygon: "
0807:                            + new Polygon(xPoints, yPoints, nPoints));
0808:                }
0809:                if (isFlashing()) {
0810:                    new FlashAction(originalGraphics) {
0811:                        private static final long serialVersionUID = 1L;
0812:
0813:                        @Override
0814:                        public void paint(Graphics g) {
0815:                            g.fillPolygon(xPoints, yPoints, nPoints);
0816:                        }
0817:                    }.actionPerformed(null);
0818:                }
0819:                if (isBuffered()) {
0820:                }
0821:                originalGraphics.fillPolygon(xPoints, yPoints, nPoints);
0822:            }
0823:
0824:            @Override
0825:            public void fillRect(final int x, final int y, final int width,
0826:                    final int height) {
0827:                if (isLogging()) {
0828:                    log("Filling rectangle: "
0829:                            + new Rectangle(x, y, width, height));
0830:                }
0831:                if (isFlashing()) {
0832:                    new FlashAction(originalGraphics) {
0833:                        private static final long serialVersionUID = 1L;
0834:
0835:                        @Override
0836:                        public void paint(Graphics g) {
0837:                            g.fillRect(x, y, width, height);
0838:                        }
0839:                    }.actionPerformed(null);
0840:                }
0841:                if (isBuffered()) {
0842:                    new BufferedDrawAction() {
0843:                        private static final long serialVersionUID = 1L;
0844:
0845:                        @Override
0846:                        public void paint(Graphics g) {
0847:                            g.fillRect(x, y, width, height);
0848:                        }
0849:                    }.actionPerformed(null);
0850:                }
0851:                originalGraphics.fillRect(x, y, width, height);
0852:            }
0853:
0854:            @Override
0855:            public void fillRoundRect(final int x, final int y,
0856:                    final int width, final int height, final int arcWidth,
0857:                    final int arcHeight) {
0858:                if (isLogging()) {
0859:                    log("Filling round rectangle: "
0860:                            + new Rectangle(x, y, width, height)
0861:                            + ", arcWidth " + arcWidth + ", arcHeight "
0862:                            + arcHeight);
0863:                }
0864:                if (isFlashing()) {
0865:                    new FlashAction(originalGraphics) {
0866:                        private static final long serialVersionUID = 1L;
0867:
0868:                        @Override
0869:                        public void paint(Graphics g) {
0870:                            g.fillRoundRect(x, y, width, height, arcWidth,
0871:                                    arcHeight);
0872:                        }
0873:                    }.actionPerformed(null);
0874:                }
0875:                if (isBuffered()) {
0876:                }
0877:                originalGraphics.fillRoundRect(x, y, width, height, arcWidth,
0878:                        arcHeight);
0879:            }
0880:
0881:            @Override
0882:            public Shape getClip() {
0883:                return originalGraphics.getClip();
0884:            }
0885:
0886:            @Override
0887:            public Rectangle getClipBounds() {
0888:                return originalGraphics.getClipBounds();
0889:            }
0890:
0891:            @Override
0892:            public Color getColor() {
0893:                return originalGraphics.getColor();
0894:            }
0895:
0896:            @Override
0897:            public Font getFont() {
0898:                return originalGraphics.getFont();
0899:            }
0900:
0901:            @Override
0902:            public FontMetrics getFontMetrics() {
0903:                return originalGraphics.getFontMetrics();
0904:            }
0905:
0906:            @Override
0907:            public FontMetrics getFontMetrics(final Font f) {
0908:                return originalGraphics.getFontMetrics(f);
0909:            }
0910:
0911:            @Override
0912:            public void setClip(final int x, final int y, final int width,
0913:                    final int height) {
0914:                if (isLogging()) {
0915:                    log("Setting new clipRect: "
0916:                            + new Rectangle(x, y, width, height));
0917:                }
0918:                if (isFlashing()) {
0919:                }
0920:                if (isBuffered()) {
0921:                }
0922:                originalGraphics.setClip(x, y, width, height);
0923:            }
0924:
0925:            @Override
0926:            public void setClip(final Shape shape) {
0927:                if (isLogging()) {
0928:                    log("Setting clip: " + shape);
0929:                }
0930:                if (isFlashing()) {
0931:                }
0932:                if (isBuffered()) {
0933:                }
0934:                originalGraphics.setClip(shape);
0935:            }
0936:
0937:            @Override
0938:            public void setColor(final Color c) {
0939:                if (isLogging()) {
0940:                    log("Setting color: " + c);
0941:                }
0942:                if (isFlashing()) {
0943:                }
0944:                if (isBuffered()) {
0945:                }
0946:                originalGraphics.setColor(c);
0947:            }
0948:
0949:            @Override
0950:            public void setFont(final Font font) {
0951:                if (isLogging()) {
0952:                    log("Setting font: " + font);
0953:                }
0954:                if (isFlashing()) {
0955:                }
0956:                if (isBuffered()) {
0957:                }
0958:                originalGraphics.setFont(font);
0959:            }
0960:
0961:            @Override
0962:            public void setPaintMode() {
0963:                if (isLogging()) {
0964:                    log("Setting paint mode");
0965:                }
0966:                if (isFlashing()) {
0967:                }
0968:                if (isBuffered()) {
0969:                }
0970:                originalGraphics.setPaintMode();
0971:            }
0972:
0973:            @Override
0974:            public void setXORMode(final Color c) {
0975:                if (isLogging()) {
0976:                    log("Setting XOR mode, color : " + c);
0977:                }
0978:                if (isFlashing()) {
0979:                }
0980:                if (isBuffered()) {
0981:                }
0982:                originalGraphics.setXORMode(c);
0983:            }
0984:
0985:            @Override
0986:            public void translate(final int x, final int y) {
0987:                if (isLogging()) {
0988:                    log("Translating by: " + new Point(x, y));
0989:                }
0990:                if (isFlashing()) {
0991:                }
0992:                if (isBuffered()) {
0993:                }
0994:                originalGraphics.translate(x, y);
0995:            }
0996:
0997:            private String getName() {
0998:                return "DebugGraphics(" + this Number + ", mode " + debugOptions
0999:                        + ")";
1000:            }
1001:
1002:            private void log(final String text) {
1003:                logStream.println(getName() + " " + text);
1004:            }
1005:
1006:            private boolean isLogging() {
1007:                return (debugOptions & LOG_OPTION) != 0;
1008:            }
1009:
1010:            private boolean isFlashing() {
1011:                return (debugOptions & FLASH_OPTION) != 0;
1012:            }
1013:
1014:            private boolean isBuffered() {
1015:                //        return (debugOptions & BUFFERED_OPTION) != 0;
1016:                return false;
1017:            }
1018:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.