-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathGraphics2DLog.java
550 lines (460 loc) · 15 KB
/
Graphics2DLog.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.ui;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ImageObserver;
import java.awt.image.RenderedImage;
import java.awt.image.renderable.RenderableImage;
import java.text.AttributedCharacterIterator;
import java.util.Map;
/**
* Wrap a graphics2d objects to debug internals paintings
*
* @author Konstantin Bulenkov
*/
@SuppressWarnings("UnusedDeclaration")
public class Graphics2DLog extends Graphics2D {
protected final Graphics2D myPeer;
public Graphics2DLog(Graphics g) {
myPeer = (Graphics2D)g;
}
@SuppressWarnings({"MethodMayBeStatic", "UseOfSystemOutOrSystemErr"})
protected void log(String msg) {
System.out.println(msg);
}
@Override
public void draw3DRect(int x, int y, int width, int height, boolean raised) {
log(String.format("draw3DRect(%d, %d, %d, %d, %b)", x, y, width, height, raised));
myPeer.draw3DRect(x, y, width, height, raised);
}
@Override
public void fill3DRect(int x, int y, int width, int height, boolean raised) {
log(String.format("draw3DRect(%d, %d, %d, %d, %b)", x, y, width, height, raised));
myPeer.fill3DRect(x, y, width, height, raised);
}
@Override
public void draw(Shape s) {
log("draw(" + s + ")");
myPeer.draw(s);
}
@Override
public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) {
log("drawImage(Image, AffineTransform, ImageObserver)");
return myPeer.drawImage(img, xform, obs);
}
@Override
public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) {
log(String.format("drawImage(BufferedImage, BufferedImageOp, %d, %d)", x, y));
myPeer.drawImage(img, op, x, y);
}
@Override
public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
log("drawRenderedImage(RenderedImage, AffineTransform)");
myPeer.drawRenderedImage(img, xform);
}
@Override
public void drawRenderableImage(RenderableImage img, AffineTransform xform) {
log("drawRenderableImage(RenderableImage, AffineTransform)");
myPeer.drawRenderableImage(img, xform);
}
@Override
public void drawString(String str, int x, int y) {
log(String.format("drawString(%s, %d, %d)", str, x, y));
myPeer.drawString(str, x, y);
}
@Override
public void drawString(String str, float x, float y) {
log(String.format("drawString(%s, %f, %f)", str, x, y));
myPeer.drawString(str, x, y);
}
@Override
public void drawString(AttributedCharacterIterator iterator, int x, int y) {
log(String.format("drawString(%s, %d, %d)", iterator, x, y));
myPeer.drawString(iterator, x, y);
}
@Override
public void drawString(AttributedCharacterIterator iterator, float x, float y) {
log(String.format("drawString(%s, %f, %f)", iterator, x, y));
myPeer.drawString(iterator, x, y);
}
@Override
public void drawGlyphVector(GlyphVector g, float x, float y) {
log(String.format("drawGlyphVector(%s, %f, %f)", g, x, y));
myPeer.drawGlyphVector(g, x, y);
}
@Override
public void fill(Shape s) {
log(String.format("fill(%s)", s));
myPeer.fill(s);
}
@Override
public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
log(String.format("hit(%s, %s, %s)", rect, s, onStroke));
return myPeer.hit(rect, s, onStroke);
}
@Override
public GraphicsConfiguration getDeviceConfiguration() {
return myPeer.getDeviceConfiguration();
}
@Override
public void setComposite(Composite comp) {
log(String.format("setComposite(%s)", comp));
myPeer.setComposite(comp);
}
@Override
public void setPaint(Paint paint) {
log(String.format("setPaint(%s)", paint));
myPeer.setPaint(paint);
}
@Override
public void setStroke(Stroke s) {
log(String.format("setStroke(%s)", s));
myPeer.setStroke(s);
}
@Override
public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue) {
log(String.format("setRenderingHint(%s, %s)", hintKey, hintValue));
myPeer.setRenderingHint(hintKey, hintValue);
}
@Override
public Object getRenderingHint(RenderingHints.Key hintKey) {
log(String.format("getRenderingHints(%s)", hintKey));
return myPeer.getRenderingHint(hintKey);
}
@Override
public void setRenderingHints(Map<?, ?> hints) {
log(String.format("setRenderingHints(%s)", hints));
myPeer.setRenderingHints(hints);
}
@Override
public void addRenderingHints(Map<?, ?> hints) {
log(String.format("addRenderingHints(%s)", hints));
myPeer.addRenderingHints(hints);
}
@Override
public RenderingHints getRenderingHints() {
log(String.format("getRenderingHints()"));
return myPeer.getRenderingHints();
}
@Override
public void translate(int x, int y) {
log(String.format("translate(%d, %d)", x, y));
myPeer.translate(x, y);
}
@Override
public void translate(double tx, double ty) {
log(String.format("translate(%f, %f)", tx, ty));
myPeer.translate(tx, ty);
}
@Override
public void rotate(double theta) {
log(String.format("rotate(%f)", theta));
myPeer.rotate(theta);
}
@Override
public void rotate(double theta, double x, double y) {
log(String.format("rotate(%f, %f, %f)", theta, x, y));
myPeer.rotate(theta, x, y);
}
@Override
public void scale(double sx, double sy) {
log(String.format("scale(%f, %f)", sx, sy));
myPeer.scale(sx, sy);
}
@Override
public void shear(double shx, double shy) {
log(String.format("shear(%f, %f)", shx, shy));
myPeer.shear(shx, shy);
}
@Override
public void transform(AffineTransform Tx) {
log(String.format("transform(%s)", Tx));
myPeer.transform(Tx);
}
@Override
public void setTransform(AffineTransform Tx) {
log(String.format("setTransform(%s)", Tx));
myPeer.setTransform(Tx);
}
@Override
public AffineTransform getTransform() {
return myPeer.getTransform();
}
@Override
public Paint getPaint() {
return myPeer.getPaint();
}
@Override
public Composite getComposite() {
return myPeer.getComposite();
}
@Override
public void setBackground(Color color) {
log(String.format("setBackground(%s)", toHex(color)));
myPeer.setBackground(color);
}
@Override
public Color getBackground() {
return myPeer.getBackground();
}
@Override
public Stroke getStroke() {
return myPeer.getStroke();
}
@Override
public void clip(Shape s) {
log(String.format("clip(%s)", s));
myPeer.clip(s);
}
@Override
public FontRenderContext getFontRenderContext() {
return myPeer.getFontRenderContext();
}
@Override
public Graphics create() {
return new Graphics2DLog(myPeer.create());
}
@Override
public Graphics create(int x, int y, int width, int height) {
log(String.format("create(%d, %d %d, %d)", x, y, width, height));
return new Graphics2DLog(myPeer.create(x, y, width, height));
}
@Override
public Color getColor() {
return myPeer.getColor();
}
@Override
public void setColor(Color c) {
log(String.format("setColor(%s) alpha=%d", toHex(c), c == null ? 0 : c.getAlpha()));
myPeer.setColor(c);
}
@Override
public void setPaintMode() {
log(String.format("setPaintMode()"));
myPeer.setPaintMode();
}
@Override
public void setXORMode(Color c1) {
log(String.format("setXORMode(%s)", toHex(c1)));
myPeer.setXORMode(c1);
}
@Override
public Font getFont() {
return myPeer.getFont();
}
@Override
public void setFont(Font font) {
log(String.format("setFont(%s)", font));
myPeer.setFont(font);
}
@Override
public FontMetrics getFontMetrics() {
return myPeer.getFontMetrics();
}
@Override
public FontMetrics getFontMetrics(Font f) {
return myPeer.getFontMetrics(f);
}
@Override
public Rectangle getClipBounds() {
return myPeer.getClipBounds();
}
@Override
public void clipRect(int x, int y, int width, int height) {
log(String.format("clipRect(%d, %d, %d, %d)", x, y, width, height));
myPeer.clipRect(x, y, width, height);
}
@Override
public void setClip(int x, int y, int width, int height) {
log(String.format("setClip(%d, %d, %d, %d)", x, y, width, height));
myPeer.setClip(x, y, width, height);
}
@Override
public Shape getClip() {
log("getClip()");
return myPeer.getClip();
}
@Override
public void setClip(Shape clip) {
log(String.format("setClip(%s)", clip));
myPeer.setClip(clip);
}
@Override
public void copyArea(int x, int y, int width, int height, int dx, int dy) {
log(String.format("copyArea(%d, %d, %d, %d, %d, %d)", x, y, width, height, dx, dy));
myPeer.copyArea(x, y, width, height, dx, dy);
}
@Override
public void drawLine(int x1, int y1, int x2, int y2) {
log(String.format("drawLine(%d, %d, %d, %d)", x1, y1, x2, y2));
myPeer.drawLine(x1, y1, x2, y2);
}
@Override
public void fillRect(int x, int y, int width, int height) {
log(String.format("fillRect(%d, %d, %d, %d)", x, y, width, height));
myPeer.fillRect(x, y, width, height);
}
@Override
public void drawRect(int x, int y, int width, int height) {
log(String.format("drawRect(%d, %d, %d, %d)", x, y, width, height));
myPeer.drawRect(x, y, width, height);
}
@Override
public void clearRect(int x, int y, int width, int height) {
log(String.format("clearRect(%d, %d, %d, %d)", x, y, width, height));
myPeer.clearRect(x, y, width, height);
}
@Override
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
log(String.format("drawRoundRect(%d, %d, %d, %d, %d, %d)", x, y, width, height, arcWidth, arcHeight));
myPeer.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
}
@Override
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
log(String.format("fillRoundRect(%d, %d, %d, %d, %d, %d)", x, y, width, height, arcWidth, arcHeight));
myPeer.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
}
@Override
public void drawOval(int x, int y, int width, int height) {
log(String.format("drawOval(%d, %d, %d, %d)", x, y, width, height));
myPeer.drawOval(x, y, width, height);
}
@Override
public void fillOval(int x, int y, int width, int height) {
log(String.format("fillOval(%d, %d, %d, %d)", x, y, width, height));
myPeer.fillOval(x, y, width, height);
}
@Override
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
myPeer.drawArc(x, y, width, height, startAngle, arcAngle);
}
@Override
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
myPeer.fillArc(x, y, width, height, startAngle, arcAngle);
}
@Override
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) {
log("drawPolyline(int[], int[], int)");
myPeer.drawPolyline(xPoints, yPoints, nPoints);
}
@Override
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) {
log("drawPolygon(int[], int[], int)");
myPeer.drawPolygon(xPoints, yPoints, nPoints);
}
@Override
public void drawPolygon(Polygon p) {
log("drawPolygon()");
myPeer.drawPolygon(p);
}
@Override
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) {
log("fillPolygon(int[], int[], int)");
myPeer.fillPolygon(xPoints, yPoints, nPoints);
}
@Override
public void fillPolygon(Polygon p) {
log("fillPolygon(" + p + ")");
myPeer.fillPolygon(p);
}
@Override
public void drawChars(char[] data, int offset, int length, int x, int y) {
log("drawChars()");
myPeer.drawChars(data, offset, length, x, y);
}
@Override
public void drawBytes(byte[] data, int offset, int length, int x, int y) {
log("drawBytes");
myPeer.drawBytes(data, offset, length, x, y);
}
@Override
public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
log(String.format("drawImage(Image, %d, %d, ImageObserver)", x, y));
return myPeer.drawImage(img, x, y, observer);
}
@Override
public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) {
log("drawImage(Image,int,int,int,int,ImageObserver)");
return myPeer.drawImage(img, x, y, width, height, observer);
}
@Override
public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) {
log("drawImage(Image,int,int,Color,ImageObserver)");
return myPeer.drawImage(img, x, y, bgcolor, observer);
}
@Override
public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) {
log("drawImage(Image,int,int,int,int,Color,ImageObserver)");
return myPeer.drawImage(img, x, y, width, height, bgcolor, observer);
}
@Override
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) {
log("drawImage(Image,int,int,int,int,int,int,int,int,ImageObserver)");
return myPeer.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer);
}
@Override
public boolean drawImage(Image img,
int dx1,
int dy1,
int dx2,
int dy2,
int sx1,
int sy1,
int sx2,
int sy2,
Color bgcolor,
ImageObserver observer) {
log("drawImage(Image,int,int,int,int,int,int,int,int,Color,ImageObserver)");
return myPeer.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
}
@Override
public void dispose() {
log(String.format("dispose()"));
myPeer.dispose();
}
@Override
public void finalize() {
myPeer.finalize();
}
@Override
public String toString() {
return myPeer.toString();
}
@Override
@Deprecated
public Rectangle getClipRect() {
return myPeer.getClipRect();
}
@Override
public boolean hitClip(int x, int y, int width, int height) {
log(String.format("hitClip(%d, %d, %d, %d)", x, y, width, height));
return myPeer.hitClip(x, y, width, height);
}
@Override
public Rectangle getClipBounds(Rectangle r) {
return myPeer.getClipBounds(r);
}
@Nullable
private static String toHex(Color c) {
return c == null ? null : ColorUtil.toHex(c);
}
}