]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/chassis/DebugGraphics.java
G2DParentNode handles "undefined" child bounds separately
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / chassis / DebugGraphics.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 /*
13  *
14  * @author Toni Kalajainen
15  */
16 package org.simantics.g2d.chassis;
17
18 import java.awt.Color;
19 import java.awt.Composite;
20 import java.awt.Font;
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;
43 import java.util.Map;
44
45 public class DebugGraphics extends GraphicsAdapter {
46
47     public final PrintStream o;
48     
49     public DebugGraphics(Graphics2D g, PrintStream out)
50     {
51         super(g);
52         this.o = out;
53     }
54
55     public DebugGraphics(Graphics2D g)
56     {
57         super(g);
58         this.o = System.out;
59     }
60
61     public void print(Object ... args)
62     {
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));
67         }
68         o.println();
69     }
70     
71     @Override
72     public void addRenderingHints(Map<?, ?> hints) {
73         print();
74         super.addRenderingHints(hints);
75     }
76
77     @Override
78     public void clip(Shape s) {
79         print();
80         super.clip(s);
81     }
82
83     @Override
84     public void draw(Shape s) {
85         print(s);
86         super.draw(s);
87     }
88
89     @Override
90     public void drawGlyphVector(GlyphVector g, float x, float y) {
91         super.drawGlyphVector(g, x, y);
92         print(g, x, y);
93     }
94
95     @Override
96     public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) {
97         print(img, xform, obs);
98         return g.drawImage(img, xform, obs);
99     }
100
101     @Override
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);
105     }
106
107     @Override
108     public void drawRenderableImage(RenderableImage img, AffineTransform xform) {
109         print(img, xform);
110         super.drawRenderableImage(img, xform);
111     }
112
113     @Override
114     public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
115         print(img, xform);
116         super.drawRenderedImage(img, xform);
117     }
118
119     @Override
120     public void drawString(String str, int x, int y) {
121         print(str, x, y);
122         super.drawString(str, x, y);
123     }
124
125     @Override
126     public void drawString(String str, float x, float y) {
127         print(str, x, y);
128         super.drawString(str, x, y);
129     }
130
131     @Override
132     public void drawString(AttributedCharacterIterator iterator, int x, int y) {
133         print(iterator, x, y);
134         super.drawString(iterator, x, y);
135     }
136
137     @Override
138     public void drawString(AttributedCharacterIterator iterator, float x, float y) {
139         print(iterator, x, y);
140         super.drawString(iterator, x, y);
141     }
142
143     @Override
144     public void fill(Shape s) {
145         print(s);
146         super.fill(s);
147     }
148
149     @Override
150     public Color getBackground() {
151         print();
152         return g.getBackground();
153     }
154
155     @Override
156     public Composite getComposite() {
157         print();
158         return g.getComposite();
159     }
160
161     @Override
162     public GraphicsConfiguration getDeviceConfiguration() {
163         print();
164         return g.getDeviceConfiguration();
165     }
166
167     @Override
168     public FontRenderContext getFontRenderContext() {
169         print();
170         return g.getFontRenderContext();
171     }
172
173     @Override
174     public Paint getPaint() {
175         print();
176         return g.getPaint();
177     }
178
179     @Override
180     public Object getRenderingHint(Key hintKey) {
181         print(hintKey);
182         return g.getRenderingHint(hintKey);
183     }
184
185     @Override
186     public RenderingHints getRenderingHints() {
187         print();
188         return g.getRenderingHints();
189     }
190
191     @Override
192     public Stroke getStroke() {
193         print();
194         return g.getStroke();
195     }
196
197     @Override
198     public AffineTransform getTransform() {
199         print();
200         return g.getTransform();
201     }
202
203     @Override
204     public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
205         print(rect, s, onStroke);
206         return g.hit(rect, s, onStroke);
207     }
208
209     @Override
210     public void rotate(double theta) {
211         print(theta);
212         super.rotate(theta);
213     }
214
215     @Override
216     public void rotate(double theta, double x, double y) {
217         print(theta, x, y);
218         super.rotate(theta, x, y);
219     }
220
221     @Override
222     public void scale(double sx, double sy) {
223         print(sx, sy);
224         super.scale(sx, sy);
225     }
226
227     @Override
228     public void setBackground(Color color) {
229         print(color);
230         super.setBackground(color);
231     }
232
233     @Override
234     public void setComposite(Composite comp) {
235         print(comp);
236         super.setComposite(comp);
237     }
238
239     @Override
240     public void setPaint(Paint paint) {
241         print(paint);
242         super.setPaint(paint);
243     }
244
245     @Override
246     public void setRenderingHint(Key hintKey, Object hintValue) {
247         print(hintKey, hintValue);
248         super.setRenderingHint(hintKey, hintValue);
249     }
250
251     @Override
252     public void setRenderingHints(Map<?, ?> hints) { 
253         print(hints);
254         super.setRenderingHints(hints);
255     }
256
257     @Override
258     public void setStroke(Stroke s) {
259         print(s);
260         super.setStroke(s);
261     }
262
263     @Override
264     public void setTransform(AffineTransform Tx) {
265         print(Tx);
266         super.setTransform(Tx);
267     }
268
269     @Override
270     public void shear(double shx, double shy) {
271         print(shx, shy);
272         super.shear(shx, shy);
273     }
274
275     @Override
276     public void transform(AffineTransform Tx) {
277         print(Tx);
278         super.transform(Tx);
279     }
280
281     @Override
282     public void translate(int x, int y) {
283         print(x, y);
284         super.translate(x, y);
285     }
286
287     @Override
288     public void translate(double tx, double ty) {
289         print(tx, ty);
290         super.translate(tx, ty);
291     }
292
293     @Override
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);
297     }
298
299     @Override
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);
303     }
304
305     @Override
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);
309     }
310
311     @Override
312     public Graphics create() {
313         print();
314         return new DebugGraphics((Graphics2D) g.create());
315     }
316
317     @Override
318     public void dispose() {
319         print();
320         super.dispose();
321     }
322
323     @Override
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);
327     }
328
329     @Override
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);
333     }
334
335     @Override
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);
339     }
340
341     @Override
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);
345     }
346
347     @Override
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);
351     }
352
353     @Override
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);
358     }
359
360     @Override
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);
365     }
366
367     @Override
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);
371     }
372
373     @Override
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);
377     }
378
379     @Override
380     public void drawPolygon(int[] points, int[] points2, int points3) {
381         print(points, points2, points3);
382         super.drawPolygon(points, points2, points3);
383     }
384
385     @Override
386     public void drawPolyline(int[] points, int[] points2, int points3) {
387         print(points, points2, points3);
388         super.drawPolyline(points, points2, points3);
389     }
390
391     @Override
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);
395     }
396
397     @Override
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);
401     }
402
403     @Override
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);
407     }
408
409     @Override
410     public void fillPolygon(int[] points, int[] points2, int points3) {
411         print(points, points2, points3);
412         super.fillPolygon(points, points2, points3);
413     }
414
415     @Override
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);
419     }
420
421     @Override
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);
425     }
426
427     @Override
428     public Shape getClip() {
429         print();
430         return g.getClip();
431     }
432
433     @Override
434     public Rectangle getClipBounds() {
435         print();
436         return g.getClipBounds();
437     }
438
439     @Override
440     public Color getColor() {
441         print();
442         return g.getColor();
443     }
444
445     @Override
446     public Font getFont() {
447         print();
448         return g.getFont();
449     }
450
451     @Override
452     public FontMetrics getFontMetrics(Font f) {
453         print();
454         return g.getFontMetrics(f);
455     }
456
457     @Override
458     public void setClip(Shape clip) {
459         print(clip);
460         super.setClip(clip);
461     }
462
463     @Override
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);
467     }
468
469     @Override
470     public void setColor(Color c) {
471         print(c);
472         super.setColor(c);
473     }
474
475     @Override
476     public void setFont(Font font) {
477         print(font);
478         super.setFont(font);
479     }
480
481     @Override
482     public void setPaintMode() {
483         print();
484         super.setPaintMode();
485     }
486
487     @Override
488     public void setXORMode(Color c1) {
489         print(c1);
490         super.setXORMode(c1);
491     }
492
493 }