1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
14 * @author Toni Kalajainen
16 package org.simantics.g2d.chassis;
18 import java.awt.Color;
19 import java.awt.Composite;
21 import java.awt.FontMetrics;
22 import java.awt.Graphics;
23 import java.awt.Graphics2D;
24 import java.awt.GraphicsConfiguration;
25 import java.awt.Image;
26 import java.awt.Paint;
27 import java.awt.Rectangle;
28 import java.awt.RenderingHints;
29 import java.awt.Shape;
30 import java.awt.Stroke;
31 import java.awt.RenderingHints.Key;
32 import java.awt.font.FontRenderContext;
33 import java.awt.font.GlyphVector;
34 import java.awt.geom.AffineTransform;
35 import java.awt.image.BufferedImage;
36 import java.awt.image.BufferedImageOp;
37 import java.awt.image.ImageObserver;
38 import java.awt.image.RenderedImage;
39 import java.awt.image.renderable.RenderableImage;
40 import java.io.PrintStream;
41 import java.text.AttributedCharacterIterator;
42 import java.util.Arrays;
45 public class DebugGraphics extends GraphicsAdapter {
47 public final PrintStream o;
49 public DebugGraphics(Graphics2D g, PrintStream out)
55 public DebugGraphics(Graphics2D g)
61 public void print(Object ... args)
63 StackTraceElement[] e = Thread.currentThread().getStackTrace();
64 o.print( e[2].getMethodName() );
65 if (args!=null && args.length>0) {
66 o.print(Arrays.toString(args));
72 public void addRenderingHints(Map<?, ?> hints) {
74 super.addRenderingHints(hints);
78 public void clip(Shape s) {
84 public void draw(Shape s) {
90 public void drawGlyphVector(GlyphVector g, float x, float y) {
91 super.drawGlyphVector(g, x, y);
96 public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) {
97 print(img, xform, obs);
98 return g.drawImage(img, xform, obs);
102 public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) {
103 print(img, op, x, y);
104 super.drawImage(img, op, x, y);
108 public void drawRenderableImage(RenderableImage img, AffineTransform xform) {
110 super.drawRenderableImage(img, xform);
114 public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
116 super.drawRenderedImage(img, xform);
120 public void drawString(String str, int x, int y) {
122 super.drawString(str, x, y);
126 public void drawString(String str, float x, float y) {
128 super.drawString(str, x, y);
132 public void drawString(AttributedCharacterIterator iterator, int x, int y) {
133 print(iterator, x, y);
134 super.drawString(iterator, x, y);
138 public void drawString(AttributedCharacterIterator iterator, float x, float y) {
139 print(iterator, x, y);
140 super.drawString(iterator, x, y);
144 public void fill(Shape s) {
150 public Color getBackground() {
152 return g.getBackground();
156 public Composite getComposite() {
158 return g.getComposite();
162 public GraphicsConfiguration getDeviceConfiguration() {
164 return g.getDeviceConfiguration();
168 public FontRenderContext getFontRenderContext() {
170 return g.getFontRenderContext();
174 public Paint getPaint() {
180 public Object getRenderingHint(Key hintKey) {
182 return g.getRenderingHint(hintKey);
186 public RenderingHints getRenderingHints() {
188 return g.getRenderingHints();
192 public Stroke getStroke() {
194 return g.getStroke();
198 public AffineTransform getTransform() {
200 return g.getTransform();
204 public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
205 print(rect, s, onStroke);
206 return g.hit(rect, s, onStroke);
210 public void rotate(double theta) {
216 public void rotate(double theta, double x, double y) {
218 super.rotate(theta, x, y);
222 public void scale(double sx, double sy) {
228 public void setBackground(Color color) {
230 super.setBackground(color);
234 public void setComposite(Composite comp) {
236 super.setComposite(comp);
240 public void setPaint(Paint paint) {
242 super.setPaint(paint);
246 public void setRenderingHint(Key hintKey, Object hintValue) {
247 print(hintKey, hintValue);
248 super.setRenderingHint(hintKey, hintValue);
252 public void setRenderingHints(Map<?, ?> hints) {
254 super.setRenderingHints(hints);
258 public void setStroke(Stroke s) {
264 public void setTransform(AffineTransform Tx) {
266 super.setTransform(Tx);
270 public void shear(double shx, double shy) {
272 super.shear(shx, shy);
276 public void transform(AffineTransform Tx) {
282 public void translate(int x, int y) {
284 super.translate(x, y);
288 public void translate(double tx, double ty) {
290 super.translate(tx, ty);
294 public void clearRect(int x, int y, int width, int height) {
295 print(x, y, width, height);
296 super.clearRect(x, y, width, height);
300 public void clipRect(int x, int y, int width, int height) {
301 print(x, y, width, height);
302 super.clearRect(x, y, width, height);
306 public void copyArea(int x, int y, int width, int height, int dx, int dy) {
307 print(x, y, width, height, dx, dy);
308 super.copyArea(x, y, width, height, dx, dy);
312 public Graphics create() {
314 return new DebugGraphics((Graphics2D) g.create());
318 public void dispose() {
324 public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
325 print(x, y, width, height, startAngle, arcAngle);
326 super.drawArc(x, y, width, height, startAngle, arcAngle);
330 public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
331 print(img, x, y, observer);
332 return g.drawImage(img, x, y, observer);
336 public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) {
337 print(img, x, y, bgcolor, observer);
338 return g.drawImage(img, x, y, bgcolor, observer);
342 public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) {
343 print(img, x, y, width, height, observer);
344 return g.drawImage(img, x, y, width, height, observer);
348 public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) {
349 print(img, x, y, width, height, bgcolor, observer);
350 return g.drawImage(img, x, y, width, height, bgcolor, observer);
354 public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2,
355 ImageObserver observer) {
356 print(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer);
357 return g.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer);
361 public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2,
362 Color bgcolor, ImageObserver observer) {
363 print(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
364 return g.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
368 public void drawLine(int x1, int y1, int x2, int y2) {
369 print(x1, y1, x2, y2);
370 super.drawLine(x1, y1, x2, y2);
374 public void drawOval(int x, int y, int width, int height) {
375 print(x, y, width, height);
376 super.drawOval(x, y, width, height);
380 public void drawPolygon(int[] points, int[] points2, int points3) {
381 print(points, points2, points3);
382 super.drawPolygon(points, points2, points3);
386 public void drawPolyline(int[] points, int[] points2, int points3) {
387 print(points, points2, points3);
388 super.drawPolyline(points, points2, points3);
392 public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
393 print(x, y, width, height, arcWidth, arcHeight);
394 super.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
398 public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
399 print(x, y, width, height, startAngle, arcAngle);
400 super.fillArc(x, y, width, height, startAngle, arcAngle);
404 public void fillOval(int x, int y, int width, int height) {
405 print(x, y, width, height);
406 super.fillOval(x, y, width, height);
410 public void fillPolygon(int[] points, int[] points2, int points3) {
411 print(points, points2, points3);
412 super.fillPolygon(points, points2, points3);
416 public void fillRect(int x, int y, int width, int height) {
417 print(x, y, width, height);
418 super.fillRect(x, y, width, height);
422 public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
423 print(x, y, width, height, arcWidth, arcHeight);
424 super.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
428 public Shape getClip() {
434 public Rectangle getClipBounds() {
436 return g.getClipBounds();
440 public Color getColor() {
446 public Font getFont() {
452 public FontMetrics getFontMetrics(Font f) {
454 return g.getFontMetrics(f);
458 public void setClip(Shape clip) {
464 public void setClip(int x, int y, int width, int height) {
465 print(x, y, width, height);
466 super.setClip(x, y, width, height);
470 public void setColor(Color c) {
476 public void setFont(Font font) {
482 public void setPaintMode() {
484 super.setPaintMode();
488 public void setXORMode(Color c1) {
490 super.setXORMode(c1);