1 /* Copyright (C) 2000, 2002, 2003 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
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;
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;
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.).
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.
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.
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
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
77 * <p>The initial state for graphics object of most raster displays
78 * would call for two levels of indirection:
81 * Graphics2D object ---> IntegerGraphicsState ---> DirectRasterGraphics
84 public class Graphics2DImpl extends Graphics2D implements Cloneable
86 GraphicsConfiguration config;
88 AbstractGraphicsState state;
95 public Graphics2DImpl(GraphicsConfiguration config)
100 public void setState(AbstractGraphicsState state)
103 this.state.setFrontend(this);
106 public Object clone()
108 Graphics2DImpl gfxCopy = (Graphics2DImpl) super.clone();
109 AbstractGraphicsState stateCopy =
110 (AbstractGraphicsState) state.clone();
111 gfxCopy.setState(stateCopy);
117 // -------- Graphics methods:
119 public Graphics create()
121 Graphics2DImpl gfxCopy = (Graphics2DImpl) clone();
125 public Color getColor()
130 public void setColor(Color color)
133 state.setColor(color);
136 public void setPaintMode()
138 state.setPaintMode();
141 public void setXORMode(Color altColor)
143 state.setXORMode(altColor);
146 public Font getFont()
151 public void setFont(Font font)
157 public FontMetrics getFontMetrics(Font font)
159 return state.getFontMetrics(font);
162 public Rectangle getClipBounds()
164 return state.getClipBounds();
167 public void clipRect(int x, int y, int width, int height)
169 Shape clip = state.getClip();
170 if (clip instanceof Rectangle)
172 Rectangle clipRect = (Rectangle) clip;
173 clip = clipRect.intersection(new Rectangle(x, y, width, height));
179 "intersecting current clip shape " + clip + " with new rectangle " +
180 "has not been implemented yet";
181 throw new UnsupportedOperationException(msg);
184 public void setClip(int x, int y, int width, int height)
186 Rectangle clip = new Rectangle(x, y, width, height);
190 public Shape getClip()
192 return state.getClip();
195 public void setClip(Shape clip)
200 public void copyArea(int x, int y, int width, int height,
203 state.copyArea(x, y, width, height, dx, dy);
206 public void drawLine(int x1, int y1, int x2, int y2)
208 state.drawLine(x1, y1, x2, y2);
211 public void fillRect(int x, int y, int width, int height)
213 state.fillRect(x, y, width, height);
216 public void clearRect(int x, int y, int width, int height)
218 state.clearRect(x, y, width, height);
221 public void drawRoundRect(int x, int y, int width, int height,
222 int arcWidth, int arcHeight)
224 state.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
227 public void fillRoundRect(int x, int y, int width, int height,
228 int arcWidth, int arcHeight)
230 state.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
233 public void drawOval(int x, int y, int width, int height)
235 state.drawOval(x, y, width, height);
238 public void fillOval(int x, int y, int width, int height)
240 state.fillOval(x, y, width, height);
243 public void drawArc(int x, int y, int width, int height,
244 int startAngle, int arcAngle)
246 state.drawArc(x, y, width, height, startAngle, arcAngle);
249 public void fillArc(int x, int y, int width, int height,
250 int startAngle, int arcAngle)
252 state.fillArc(x, y, width, height, startAngle, arcAngle);
255 public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
257 state.drawPolyline(xPoints, yPoints, nPoints);
260 public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
262 state.drawPolygon(xPoints, yPoints, nPoints);
265 public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
267 state.fillPolygon(xPoints, yPoints, nPoints);
270 public boolean drawImage(Image image, int x, int y,
271 ImageObserver observer)
273 return state.drawImage(image, x, y, observer);
276 public boolean drawImage(Image img, int x, int y,
277 int width, int height,
278 ImageObserver observer)
280 throw new UnsupportedOperationException("not implemented yet");
283 public boolean drawImage(Image img, int x, int y, Color bgcolor,
284 ImageObserver observer)
286 throw new UnsupportedOperationException("not implemented yet");
289 public boolean drawImage(Image img, int x, int y,
290 int width, int height, Color bgcolor,
291 ImageObserver observer)
293 throw new UnsupportedOperationException("not implemented yet");
296 public boolean drawImage(Image img,
297 int dx1, int dy1, int dx2, int dy2,
298 int sx1, int sy1, int sx2, int sy2,
299 ImageObserver observer)
301 throw new UnsupportedOperationException("not implemented yet");
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 Color bgcolor, ImageObserver observer)
309 throw new UnsupportedOperationException("not implemented yet");
312 public void dispose()
314 AbstractGraphicsState lState = state;
328 // -------- Graphics2D methods:
330 public void draw(Shape shape)
335 public boolean drawImage(Image image, AffineTransform xform,
338 throw new UnsupportedOperationException("not implemented yet");
342 public void drawString(String text, int x, int y)
344 state.drawString(text, x, y);
347 public void drawString(String text, float x, float y)
349 state.drawString(text, x, y);
352 public void fill(Shape shape)
357 public boolean hit(Rectangle rect, Shape text, boolean onStroke)
359 return state.hit(rect, text, onStroke);
362 public GraphicsConfiguration getDeviceConfiguration()
367 public void setPaint(Paint paint)
369 throw new UnsupportedOperationException("not implemented yet");
372 public void setRenderingHint(RenderingHints.Key hintKey,
375 throw new UnsupportedOperationException("not implemented yet");
378 public Object getRenderingHint(RenderingHints.Key hintKey)
380 throw new UnsupportedOperationException("not implemented yet");
383 public RenderingHints getRenderingHints()
385 throw new UnsupportedOperationException("not implemented yet");
388 public void translate(int x, int y)
390 state.translate(x, y);
393 public void translate(double tx, double ty)
395 state.translate(tx, ty);
398 public void rotate(double theta)
403 public void rotate(double theta, double x, double y)
405 state.rotate(theta, x, y);
408 public void scale(double scaleX, double scaleY)
410 state.scale(scaleX, scaleY);
413 public void shear(double shearX, double shearY)
415 state.shear(shearX, shearY);
418 public void transform(AffineTransform Tx)
420 throw new UnsupportedOperationException("not implemented yet");
423 public void setTransform(AffineTransform Tx)
425 throw new UnsupportedOperationException("not implemented yet");
428 public AffineTransform getTransform()
430 throw new UnsupportedOperationException("not implemented yet");
433 public Paint getPaint()
435 throw new UnsupportedOperationException("not implemented yet");
438 public void setBackground(Color color)
443 public Color getBackground()
448 public void clip(Shape shape)
450 Shape clip = state.getClip();
452 if ((shape instanceof Rectangle) && (clip instanceof Rectangle))
454 clip = ((Rectangle) clip).intersection((Rectangle) shape);
460 "intersecting current clip shape " + clip + " with new shape " + shape +
461 "has not been implemented yet";
462 throw new UnsupportedOperationException(msg);
465 public void drawImage(BufferedImage image, BufferedImageOp op, int x, int y)
467 throw new UnsupportedOperationException("not implemented yet");
470 public void drawRenderedImage(RenderedImage image, AffineTransform xform)
472 throw new UnsupportedOperationException("not implemented yet");
475 public void drawRenderableImage(RenderableImage image, AffineTransform xform)
477 throw new UnsupportedOperationException("not implemented yet");
480 public void drawString(AttributedCharacterIterator iterator,
483 throw new UnsupportedOperationException("not implemented yet");
486 public void drawString(AttributedCharacterIterator iterator, float x,
489 throw new UnsupportedOperationException("not implemented yet");
492 public void setComposite(Composite comp)
494 throw new UnsupportedOperationException("not implemented yet");
497 public void setStroke(Stroke stroke)
499 throw new UnsupportedOperationException("not implemented yet");
502 public void setRenderingHints(Map hints)
504 throw new UnsupportedOperationException("not implemented yet");
507 public void addRenderingHints(Map hints)
509 throw new UnsupportedOperationException("not implemented yet");
512 public Composite getComposite()
514 throw new UnsupportedOperationException("not implemented yet");
517 public Stroke getStroke()
519 throw new UnsupportedOperationException("not implemented yet");
522 public FontRenderContext getFontRenderContext ()
524 throw new UnsupportedOperationException("not implemented yet");
527 public void drawGlyphVector (GlyphVector g, float x, float y)
529 throw new UnsupportedOperationException("not implemented yet");