source: trunk/gcc/libjava/gnu/awt/j2d/Graphics2DImpl.java

Last change on this file was 1392, checked in by bird, 21 years ago

This commit was generated by cvs2svn to compensate for changes in r1391,
which included commits to RCS files with non-trunk default branches.

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