OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [gnu/] [awt/] [j2d/] [Graphics2DImpl.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* Copyright (C) 2000, 2002, 2003  Free Software Foundation
2
 
3
   This file is part of libgcj.
4
 
5
This software is copyrighted work licensed under the terms of the
6
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
7
details.  */
8
 
9
package gnu.awt.j2d;
10
 
11
import java.awt.Color;
12
import java.awt.Composite;
13
import java.awt.Image;
14
import java.awt.Shape;
15
import java.awt.Rectangle;
16
import java.awt.Graphics;
17
import java.awt.Graphics2D;
18
import java.awt.GraphicsConfiguration;
19
import java.awt.Font;
20
import java.awt.FontMetrics;
21
import java.awt.Paint;
22
import java.awt.RenderingHints;
23
import java.awt.Stroke;
24
import java.awt.font.FontRenderContext;
25
import java.awt.font.GlyphVector;
26
import java.awt.geom.AffineTransform;
27
import java.awt.image.ImageObserver;
28
import java.awt.image.BufferedImage;
29
import java.awt.image.BufferedImageOp;
30
import java.awt.image.RenderedImage;
31
import java.awt.image.renderable.RenderableImage;
32
import java.text.AttributedCharacterIterator;
33
import java.util.Map;
34
 
35
/**
36
 * Delegates almost all work to a state object, that allows us to
37
 * hot-swap rendering strategies based on state changes inflicted on
38
 * this Graphics object. This class keeps track of properties that are
39
 * not affected by the state, (such as clip shape,
40
 * foreground/background color, font, etc.).
41
 *
42
 * <p>The far front-end of the rendering pipeline consists of the
43
 * Graphics2D API. In the far back-end, lies the native graphics
44
 * libraries. In most cases the native graphics libraries only have
45
 * direct support for a subset of the properties of Graphics2D. To
46
 * make up missing features in the native graphics libraries, the
47
 * pipeline between the front-end and the back-end need to translate
48
 * drawing request to primitive operations that are supported by the
49
 * back-end. E.g. for X11, drawing a straight line will translate to
50
 * an XDrawLine, drawing a bezier curve will trigger flattening of the
51
 * curve and will result in a call to XDrawLines.
52
 *
53
 * <p>This is the basic strategy for the rendering pipeline: Whenever
54
 * a graphics property change occurs, that causes the current pipeline
55
 * to be insufficient, amend or replace parts of the pipeline so that
56
 * the pipeline will once again be able to translate requests to the
57
 * set of primitives supported by the native graphics library.
58
 *
59
 * <p>Most graphics libraries share common subsets of
60
 * functionality. To be able to reuse pieces of the rendering pipeline
61
 * for several backends, we define interfaces that describe subsets of
62
 * characteristics supported by the backends. A wrapper for the native
63
 * library can implement several interfaces to describe its range of
64
 * functionality.
65
 *
66
 * <p>Typically, most painting is done with a graphics object with
67
 * simple properties. Unless one is using a complex Look & Feel, the
68
 * painting of Swing components will never require affine transforms,
69
 * alpha blending, non-rectangular clipping, etc. When graphics
70
 * objects are created, they start off in a state where all the
71
 * properties are simple. Most graphics objects experience only
72
 * trivial property changes, and never leave this simple state. It is
73
 * therefore wise to ensure that the rendering pipeline for this
74
 * initial state is lean and as much as possible plugs directly into
75
 * the backend.
76
 *
77
 * <p>The initial state for graphics object of most raster displays
78
 * would call for two levels of indirection:
79
 *
80
 * <pre>
81
 * Graphics2D object ---> IntegerGraphicsState ---> DirectRasterGraphics
82
 * </pre>
83
 */
84
public class Graphics2DImpl extends Graphics2D implements Cloneable
85
{
86
  GraphicsConfiguration config;
87
 
88
  AbstractGraphicsState state;
89
 
90
  Color fg;
91
  Color bg;
92
 
93
  Font font;
94
 
95
  public Graphics2DImpl(GraphicsConfiguration config)
96
  {
97
    this.config = config;
98
  }
99
 
100
  public void setState(AbstractGraphicsState state)
101
  {
102
    this.state = state;
103
    this.state.setFrontend(this);
104
  }
105
 
106
  public Object clone()
107
  {
108
    try
109
      {
110
        Graphics2DImpl gfxCopy = (Graphics2DImpl) super.clone();
111
        AbstractGraphicsState stateCopy =
112
          (AbstractGraphicsState) state.clone();
113
        gfxCopy.setState(stateCopy);
114
 
115
        return gfxCopy;
116
      }
117
    catch (CloneNotSupportedException ex)
118
      {
119
        // This should never happen.
120
        throw new InternalError ();
121
      }
122
  }
123
 
124
 
125
  // -------- Graphics methods:
126
 
127
  public Graphics create()
128
  {
129
    Graphics2DImpl gfxCopy = (Graphics2DImpl) clone();
130
    return gfxCopy;
131
  }
132
 
133
  public Color getColor()
134
  {
135
    return fg;
136
  }
137
 
138
  public void setColor(Color color)
139
  {
140
    fg = color;
141
    state.setColor(color);
142
  }
143
 
144
  public void setPaintMode()
145
  {
146
    state.setPaintMode();
147
  }
148
 
149
  public void setXORMode(Color altColor)
150
  {
151
    state.setXORMode(altColor);
152
  }
153
 
154
  public Font getFont()
155
  {
156
    return font;
157
  }
158
 
159
  public void setFont(Font font)
160
  {
161
    this.font = font;
162
    state.setFont(font);
163
  }
164
 
165
  public FontMetrics getFontMetrics(Font font)
166
  {
167
    return state.getFontMetrics(font);
168
  }
169
 
170
  public Rectangle getClipBounds()
171
  {
172
    return state.getClipBounds();
173
  }
174
 
175
  public void clipRect(int x, int y, int width, int height)
176
  {
177
    Shape clip = state.getClip();
178
    if (clip instanceof Rectangle)
179
      {
180
        Rectangle clipRect = (Rectangle) clip;
181
        clip = clipRect.intersection(new Rectangle(x, y, width, height));
182
        setClip(clip);
183
        return;
184
      }
185
 
186
    String msg =
187
      "intersecting current clip shape " + clip + " with new rectangle " +
188
      "has not been implemented yet";
189
    throw new UnsupportedOperationException(msg);
190
  }
191
 
192
  public void setClip(int x, int y, int width, int height)
193
  {
194
    Rectangle clip = new Rectangle(x, y, width, height);
195
    setClip(clip);
196
  }
197
 
198
  public Shape getClip()
199
  {
200
    return state.getClip();
201
  }
202
 
203
  public void setClip(Shape clip)
204
  {
205
    state.setClip(clip);
206
  }
207
 
208
  public void copyArea(int x, int y, int width, int height,
209
                       int dx, int dy)
210
  {
211
    state.copyArea(x, y, width, height, dx, dy);
212
  }
213
 
214
  public void drawLine(int x1, int y1, int x2, int y2)
215
  {
216
    state.drawLine(x1, y1, x2, y2);
217
  }
218
 
219
  public void fillRect(int x, int y, int width, int height)
220
  {
221
    state.fillRect(x, y, width, height);
222
  }
223
 
224
  public void clearRect(int x, int y, int width, int height)
225
  {
226
    state.clearRect(x, y, width, height);
227
  }
228
 
229
  public void drawRoundRect(int x, int y, int width, int height,
230
                            int arcWidth, int arcHeight)
231
  {
232
    state.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
233
  }
234
 
235
  public void fillRoundRect(int x, int y, int width, int height,
236
                            int arcWidth, int arcHeight)
237
  {
238
    state.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
239
  }
240
 
241
  public void drawOval(int x, int y, int width, int height)
242
  {
243
    state.drawOval(x, y, width, height);
244
  }
245
 
246
  public void fillOval(int x, int y, int width, int height)
247
  {
248
    state.fillOval(x, y, width, height);
249
  }
250
 
251
  public void drawArc(int x, int y, int width, int height,
252
                      int startAngle, int arcAngle)
253
  {
254
    state.drawArc(x, y, width, height, startAngle, arcAngle);
255
  }
256
 
257
  public void fillArc(int x, int y, int width, int height,
258
                      int startAngle, int arcAngle)
259
  {
260
    state.fillArc(x, y, width, height, startAngle, arcAngle);
261
  }
262
 
263
  public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
264
  {
265
    state.drawPolyline(xPoints, yPoints, nPoints);
266
  }
267
 
268
  public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
269
  {
270
    state.drawPolygon(xPoints, yPoints, nPoints);
271
  }
272
 
273
  public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
274
  {
275
    state.fillPolygon(xPoints, yPoints, nPoints);
276
  }
277
 
278
  public boolean drawImage(Image image, int x, int y,
279
                           ImageObserver observer)
280
  {
281
    return state.drawImage(image, x, y, observer);
282
  }
283
 
284
  public boolean drawImage(Image img, int x, int y,
285
                           int width, int height,
286
                           ImageObserver observer)
287
  {
288
    throw new UnsupportedOperationException("not implemented yet");
289
  }
290
 
291
  public boolean drawImage(Image img, int x, int y, Color bgcolor,
292
                           ImageObserver observer)
293
  {
294
    throw new UnsupportedOperationException("not implemented yet");
295
  }
296
 
297
  public boolean drawImage(Image img, int x, int y,
298
                           int width, int height, Color bgcolor,
299
                           ImageObserver observer)
300
  {
301
    throw new UnsupportedOperationException("not implemented yet");
302
  }
303
 
304
  public boolean drawImage(Image img,
305
                           int dx1, int dy1, int dx2, int dy2,
306
                           int sx1, int sy1, int sx2, int sy2,
307
                           ImageObserver observer)
308
  {
309
    throw new UnsupportedOperationException("not implemented yet");
310
  }
311
 
312
  public boolean drawImage(Image img,
313
                           int dx1, int dy1, int dx2, int dy2,
314
                           int sx1, int sy1, int sx2, int sy2,
315
                           Color bgcolor, ImageObserver observer)
316
  {
317
    throw new UnsupportedOperationException("not implemented yet");
318
  }
319
 
320
  public void dispose()
321
  {
322
    AbstractGraphicsState lState = state;
323
 
324
    state = null;
325
    config = null;
326
    font = null;
327
    fg = null;
328
    bg = null;
329
 
330
    if (lState != null)
331
      lState.dispose();
332
  }
333
 
334
 
335
 
336
  // -------- Graphics2D methods:
337
 
338
  public void draw(Shape shape)
339
  {
340
    state.draw(shape);
341
  }
342
 
343
  public boolean drawImage(Image image, AffineTransform xform,
344
                           ImageObserver obs)
345
  {
346
    throw new UnsupportedOperationException("not implemented yet");
347
  }
348
 
349
 
350
  public void drawString(String text, int x, int y)
351
  {
352
    state.drawString(text, x, y);
353
  }
354
 
355
  public void drawString(String text, float x, float y)
356
  {
357
    state.drawString(text, x, y);
358
  }
359
 
360
  public void fill(Shape shape)
361
  {
362
    state.fill(shape);
363
  }
364
 
365
  public boolean hit(Rectangle rect, Shape text, boolean onStroke)
366
  {
367
    return state.hit(rect, text, onStroke);
368
  }
369
 
370
  public GraphicsConfiguration getDeviceConfiguration()
371
  {
372
    return config;
373
  }
374
 
375
  public void setPaint(Paint paint)
376
  {
377
    throw new UnsupportedOperationException("not implemented yet");
378
  }
379
 
380
  public void setRenderingHint(RenderingHints.Key hintKey,
381
                               Object hintValue)
382
  {
383
    throw new UnsupportedOperationException("not implemented yet");
384
  }
385
 
386
  public Object getRenderingHint(RenderingHints.Key hintKey)
387
  {
388
    throw new UnsupportedOperationException("not implemented yet");
389
  }
390
 
391
  public RenderingHints getRenderingHints()
392
  {
393
    throw new UnsupportedOperationException("not implemented yet");
394
  }
395
 
396
  public void translate(int x, int y)
397
  {
398
    state.translate(x, y);
399
  }
400
 
401
  public void translate(double tx, double ty)
402
  {
403
    state.translate(tx, ty);
404
  }
405
 
406
  public void rotate(double theta)
407
  {
408
    state.rotate(theta);
409
  }
410
 
411
  public void rotate(double theta, double x, double y)
412
  {
413
    state.rotate(theta, x, y);
414
  }
415
 
416
  public void scale(double scaleX, double scaleY)
417
  {
418
    state.scale(scaleX, scaleY);
419
  }
420
 
421
  public void shear(double shearX, double shearY)
422
  {
423
    state.shear(shearX, shearY);
424
  }
425
 
426
  public void transform(AffineTransform Tx)
427
  {
428
    throw new UnsupportedOperationException("not implemented yet");
429
  }
430
 
431
  public void setTransform(AffineTransform Tx)
432
  {
433
    throw new UnsupportedOperationException("not implemented yet");
434
  }
435
 
436
  public AffineTransform getTransform()
437
  {
438
    throw new UnsupportedOperationException("not implemented yet");
439
  }
440
 
441
  public Paint getPaint()
442
  {
443
    throw new UnsupportedOperationException("not implemented yet");
444
  }
445
 
446
  public void setBackground(Color color)
447
  {
448
    bg = color;
449
  }
450
 
451
  public Color getBackground()
452
  {
453
    return bg;
454
  }
455
 
456
  public void clip(Shape shape)
457
  {
458
    Shape clip = state.getClip();
459
 
460
    if ((shape instanceof Rectangle) && (clip instanceof Rectangle))
461
      {
462
        clip = ((Rectangle) clip).intersection((Rectangle) shape);
463
        state.setClip(clip);
464
        return;
465
      }
466
 
467
    String msg =
468
      "intersecting current clip shape " + clip + " with new shape " + shape +
469
      "has not been implemented yet";
470
    throw new UnsupportedOperationException(msg);
471
  }
472
 
473
  public void drawImage(BufferedImage image, BufferedImageOp op, int x, int y)
474
  {
475
    throw new UnsupportedOperationException("not implemented yet");
476
  }
477
 
478
  public void drawRenderedImage(RenderedImage image, AffineTransform xform)
479
  {
480
    throw new UnsupportedOperationException("not implemented yet");
481
  }
482
 
483
  public void drawRenderableImage(RenderableImage image, AffineTransform xform)
484
  {
485
    throw new UnsupportedOperationException("not implemented yet");
486
  }
487
 
488
  public void drawString(AttributedCharacterIterator iterator,
489
                                  int x, int y)
490
  {
491
    throw new UnsupportedOperationException("not implemented yet");
492
  }
493
 
494
  public void drawString(AttributedCharacterIterator iterator, float x,
495
                         float y)
496
  {
497
    throw new UnsupportedOperationException("not implemented yet");
498
  }
499
 
500
  public void setComposite(Composite comp)
501
  {
502
    throw new UnsupportedOperationException("not implemented yet");
503
  }
504
 
505
  public void setStroke(Stroke stroke)
506
  {
507
    throw new UnsupportedOperationException("not implemented yet");
508
  }
509
 
510
  public void setRenderingHints(Map hints)
511
  {
512
    throw new UnsupportedOperationException("not implemented yet");
513
  }
514
 
515
  public void addRenderingHints(Map hints)
516
  {
517
    throw new UnsupportedOperationException("not implemented yet");
518
  }
519
 
520
  public Composite getComposite()
521
  {
522
    throw new UnsupportedOperationException("not implemented yet");
523
  }
524
 
525
  public Stroke getStroke()
526
  {
527
    throw new UnsupportedOperationException("not implemented yet");
528
  }
529
 
530
  public FontRenderContext getFontRenderContext ()
531
  {
532
    throw new UnsupportedOperationException("not implemented yet");
533
  }
534
 
535
  public void drawGlyphVector (GlyphVector g, float x, float y)
536
  {
537
    throw new UnsupportedOperationException("not implemented yet");
538
  }
539
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.