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
|
/* Copyright (C) 2000, 2002, 2003 Free Software Foundation
This file is part of libgcj.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
package gnu.awt.j2d;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Image;
import java.awt.Shape;
import java.awt.Rectangle;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Paint;
import java.awt.RenderingHints;
import java.awt.Stroke;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
import java.awt.image.ImageObserver;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.RenderedImage;
import java.awt.image.renderable.RenderableImage;
import java.text.AttributedCharacterIterator;
import java.util.Map;
/**
* Delegates almost all work to a state object, that allows us to
* hot-swap rendering strategies based on state changes inflicted on
* this Graphics object. This class keeps track of properties that are
* not affected by the state, (such as clip shape,
* foreground/background color, font, etc.).
*
* <p>The far front-end of the rendering pipeline consists of the
* Graphics2D API. In the far back-end, lies the native graphics
* libraries. In most cases the native graphics libraries only have
* direct support for a subset of the properties of Graphics2D. To
* make up missing features in the native graphics libraries, the
* pipeline between the front-end and the back-end need to translate
* drawing request to primitive operations that are supported by the
* back-end. E.g. for X11, drawing a straight line will translate to
* an XDrawLine, drawing a bezier curve will trigger flattening of the
* curve and will result in a call to XDrawLines.
*
* <p>This is the basic strategy for the rendering pipeline: Whenever
* a graphics property change occurs, that causes the current pipeline
* to be insufficient, amend or replace parts of the pipeline so that
* the pipeline will once again be able to translate requests to the
* set of primitives supported by the native graphics library.
*
* <p>Most graphics libraries share common subsets of
* functionality. To be able to reuse pieces of the rendering pipeline
* for several backends, we define interfaces that describe subsets of
* characteristics supported by the backends. A wrapper for the native
* library can implement several interfaces to describe its range of
* functionality.
*
* <p>Typically, most painting is done with a graphics object with
* simple properties. Unless one is using a complex Look & Feel, the
* painting of Swing components will never require affine transforms,
* alpha blending, non-rectangular clipping, etc. When graphics
* objects are created, they start off in a state where all the
* properties are simple. Most graphics objects experience only
* trivial property changes, and never leave this simple state. It is
* therefore wise to ensure that the rendering pipeline for this
* initial state is lean and as much as possible plugs directly into
* the backend.
*
* <p>The initial state for graphics object of most raster displays
* would call for two levels of indirection:
*
* <pre>
* Graphics2D object ---> IntegerGraphicsState ---> DirectRasterGraphics
* </pre>
*/
public class Graphics2DImpl extends Graphics2D implements Cloneable
{
GraphicsConfiguration config;
AbstractGraphicsState state;
Color fg;
Color bg;
Font font;
public Graphics2DImpl(GraphicsConfiguration config)
{
this.config = config;
}
public void setState(AbstractGraphicsState state)
{
this.state = state;
this.state.setFrontend(this);
}
public Object clone()
{
try
{
Graphics2DImpl gfxCopy = (Graphics2DImpl) super.clone();
AbstractGraphicsState stateCopy =
(AbstractGraphicsState) state.clone();
gfxCopy.setState(stateCopy);
return gfxCopy;
}
catch (CloneNotSupportedException ex)
{
// This should never happen.
throw new InternalError ();
}
}
// -------- Graphics methods:
public Graphics create()
{
Graphics2DImpl gfxCopy = (Graphics2DImpl) clone();
return gfxCopy;
}
public Color getColor()
{
return fg;
}
public void setColor(Color color)
{
fg = color;
state.setColor(color);
}
public void setPaintMode()
{
state.setPaintMode();
}
public void setXORMode(Color altColor)
{
state.setXORMode(altColor);
}
public Font getFont()
{
return font;
}
public void setFont(Font font)
{
this.font = font;
state.setFont(font);
}
public FontMetrics getFontMetrics(Font font)
{
return state.getFontMetrics(font);
}
public Rectangle getClipBounds()
{
return state.getClipBounds();
}
public void clipRect(int x, int y, int width, int height)
{
Shape clip = state.getClip();
if (clip == null)
{
clip = new Rectangle (x,y,width,height);
setClip (clip);
return;
}
if (clip instanceof Rectangle)
{
Rectangle clipRect = (Rectangle) clip;
clip = clipRect.intersection(new Rectangle(x, y, width, height));
setClip(clip);
return;
}
String msg =
"intersecting current clip shape " + clip + " with new rectangle " +
"has not been implemented yet";
throw new UnsupportedOperationException(msg);
}
public void setClip(int x, int y, int width, int height)
{
Rectangle clip = new Rectangle(x, y, width, height);
setClip(clip);
}
public Shape getClip()
{
return state.getClip();
}
public void setClip(Shape clip)
{
state.setClip(clip);
}
public void copyArea(int x, int y, int width, int height,
int dx, int dy)
{
state.copyArea(x, y, width, height, dx, dy);
}
public void drawLine(int x1, int y1, int x2, int y2)
{
state.drawLine(x1, y1, x2, y2);
}
public void fillRect(int x, int y, int width, int height)
{
state.fillRect(x, y, width, height);
}
public void clearRect(int x, int y, int width, int height)
{
state.clearRect(x, y, width, height);
}
public void drawRoundRect(int x, int y, int width, int height,
int arcWidth, int arcHeight)
{
state.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
}
public void fillRoundRect(int x, int y, int width, int height,
int arcWidth, int arcHeight)
{
state.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
}
public void drawOval(int x, int y, int width, int height)
{
state.drawOval(x, y, width, height);
}
public void fillOval(int x, int y, int width, int height)
{
state.fillOval(x, y, width, height);
}
public void drawArc(int x, int y, int width, int height,
int startAngle, int arcAngle)
{
state.drawArc(x, y, width, height, startAngle, arcAngle);
}
public void fillArc(int x, int y, int width, int height,
int startAngle, int arcAngle)
{
state.fillArc(x, y, width, height, startAngle, arcAngle);
}
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
{
state.drawPolyline(xPoints, yPoints, nPoints);
}
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
{
state.drawPolygon(xPoints, yPoints, nPoints);
}
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
{
state.fillPolygon(xPoints, yPoints, nPoints);
}
public boolean drawImage(Image image, int x, int y,
ImageObserver observer)
{
return state.drawImage(image, x, y, observer);
}
public boolean drawImage(Image img, int x, int y,
int width, int height,
ImageObserver observer)
{
throw new UnsupportedOperationException("not implemented yet");
}
public boolean drawImage(Image img, int x, int y, Color bgcolor,
ImageObserver observer)
{
throw new UnsupportedOperationException("not implemented yet");
}
public boolean drawImage(Image img, int x, int y,
int width, int height, Color bgcolor,
ImageObserver observer)
{
throw new UnsupportedOperationException("not implemented yet");
}
public boolean drawImage(Image img,
int dx1, int dy1, int dx2, int dy2,
int sx1, int sy1, int sx2, int sy2,
ImageObserver observer)
{
throw new UnsupportedOperationException("not implemented yet");
}
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)
{
throw new UnsupportedOperationException("not implemented yet");
}
public void dispose()
{
AbstractGraphicsState lState = state;
state = null;
config = null;
font = null;
fg = null;
bg = null;
if (lState != null)
lState.dispose();
}
// -------- Graphics2D methods:
public void draw(Shape shape)
{
state.draw(shape);
}
public boolean drawImage(Image image, AffineTransform xform,
ImageObserver obs)
{
throw new UnsupportedOperationException("not implemented yet");
}
public void drawString(String text, int x, int y)
{
state.drawString(text, x, y);
}
public void drawString(String text, float x, float y)
{
state.drawString(text, x, y);
}
public void fill(Shape shape)
{
state.fill(shape);
}
public boolean hit(Rectangle rect, Shape text, boolean onStroke)
{
return state.hit(rect, text, onStroke);
}
public GraphicsConfiguration getDeviceConfiguration()
{
return config;
}
public void setPaint(Paint paint)
{
throw new UnsupportedOperationException("not implemented yet");
}
public void setRenderingHint(RenderingHints.Key hintKey,
Object hintValue)
{
throw new UnsupportedOperationException("not implemented yet");
}
public Object getRenderingHint(RenderingHints.Key hintKey)
{
throw new UnsupportedOperationException("not implemented yet");
}
public RenderingHints getRenderingHints()
{
throw new UnsupportedOperationException("not implemented yet");
}
public void translate(int x, int y)
{
state.translate(x, y);
}
public void translate(double tx, double ty)
{
state.translate(tx, ty);
}
public void rotate(double theta)
{
state.rotate(theta);
}
public void rotate(double theta, double x, double y)
{
state.rotate(theta, x, y);
}
public void scale(double scaleX, double scaleY)
{
state.scale(scaleX, scaleY);
}
public void shear(double shearX, double shearY)
{
state.shear(shearX, shearY);
}
public void transform(AffineTransform Tx)
{
throw new UnsupportedOperationException("not implemented yet");
}
public void setTransform(AffineTransform Tx)
{
throw new UnsupportedOperationException("not implemented yet");
}
public AffineTransform getTransform()
{
throw new UnsupportedOperationException("not implemented yet");
}
public Paint getPaint()
{
throw new UnsupportedOperationException("not implemented yet");
}
public void setBackground(Color color)
{
bg = color;
}
public Color getBackground()
{
return bg;
}
public void clip(Shape shape)
{
Shape clip = state.getClip();
if ((shape instanceof Rectangle) && (clip instanceof Rectangle))
{
clip = ((Rectangle) clip).intersection((Rectangle) shape);
state.setClip(clip);
return;
}
String msg =
"intersecting current clip shape " + clip + " with new shape " + shape +
"has not been implemented yet";
throw new UnsupportedOperationException(msg);
}
public void drawImage(BufferedImage image, BufferedImageOp op, int x, int y)
{
throw new UnsupportedOperationException("not implemented yet");
}
public void drawRenderedImage(RenderedImage image, AffineTransform xform)
{
throw new UnsupportedOperationException("not implemented yet");
}
public void drawRenderableImage(RenderableImage image, AffineTransform xform)
{
throw new UnsupportedOperationException("not implemented yet");
}
public void drawString(AttributedCharacterIterator iterator,
int x, int y)
{
throw new UnsupportedOperationException("not implemented yet");
}
public void drawString(AttributedCharacterIterator iterator, float x,
float y)
{
throw new UnsupportedOperationException("not implemented yet");
}
public void setComposite(Composite comp)
{
throw new UnsupportedOperationException("not implemented yet");
}
public void setStroke(Stroke stroke)
{
throw new UnsupportedOperationException("not implemented yet");
}
public void setRenderingHints(Map hints)
{
throw new UnsupportedOperationException("not implemented yet");
}
public void addRenderingHints(Map hints)
{
throw new UnsupportedOperationException("not implemented yet");
}
public Composite getComposite()
{
throw new UnsupportedOperationException("not implemented yet");
}
public Stroke getStroke()
{
throw new UnsupportedOperationException("not implemented yet");
}
public FontRenderContext getFontRenderContext ()
{
throw new UnsupportedOperationException("not implemented yet");
}
public void drawGlyphVector (GlyphVector g, float x, float y)
{
throw new UnsupportedOperationException("not implemented yet");
}
}
|