KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > Graphics2D


1 /*
2  * @(#)Graphics2D.java 1.81 04/05/05
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.awt;
9
10 import java.awt.RenderingHints.Key;
11 import java.awt.geom.AffineTransform JavaDoc;
12 import java.awt.image.ImageObserver JavaDoc;
13 import java.awt.image.BufferedImageOp JavaDoc;
14 import java.awt.image.BufferedImage JavaDoc;
15 import java.awt.image.RenderedImage JavaDoc;
16 import java.awt.image.renderable.RenderableImage JavaDoc;
17 import java.awt.font.GlyphVector JavaDoc;
18 import java.awt.font.FontRenderContext JavaDoc;
19 import java.awt.font.TextAttribute JavaDoc;
20 import java.text.AttributedCharacterIterator JavaDoc;
21 import java.util.Map JavaDoc;
22
23 /**
24  * This <code>Graphics2D</code> class extends the
25  * {@link Graphics} class to provide more sophisticated
26  * control over geometry, coordinate transformations, color management,
27  * and text layout. This is the fundamental class for rendering
28  * 2-dimensional shapes, text and images on the Java(tm) platform.
29  * <p>
30  * <h2>Coordinate Spaces</h2>
31  * All coordinates passed to a <code>Graphics2D</code> object are specified
32  * in a device-independent coordinate system called User Space, which is
33  * used by applications. The <code>Graphics2D</code> object contains
34  * an {@link AffineTransform} object as part of its rendering state
35  * that defines how to convert coordinates from user space to
36  * device-dependent coordinates in Device Space.
37  * <p>
38  * Coordinates in device space usually refer to individual device pixels
39  * and are aligned on the infinitely thin gaps between these pixels.
40  * Some <code>Graphics2D</code> objects can be used to capture rendering
41  * operations for storage into a graphics metafile for playback on a
42  * concrete device of unknown physical resolution at a later time. Since
43  * the resolution might not be known when the rendering operations are
44  * captured, the <code>Graphics2D</code> <code>Transform</code> is set up
45  * to transform user coordinates to a virtual device space that
46  * approximates the expected resolution of the target device. Further
47  * transformations might need to be applied at playback time if the
48  * estimate is incorrect.
49  * <p>
50  * Some of the operations performed by the rendering attribute objects
51  * occur in the device space, but all <code>Graphics2D</code> methods take
52  * user space coordinates.
53  * <p>
54  * Every <code>Graphics2D</code> object is associated with a target that
55  * defines where rendering takes place. A
56  * {@link GraphicsConfiguration} object defines the characteristics
57  * of the rendering target, such as pixel format and resolution.
58  * The same rendering target is used throughout the life of a
59  * <code>Graphics2D</code> object.
60  * <p>
61  * When creating a <code>Graphics2D</code> object, the
62  * <code>GraphicsConfiguration</code>
63  * specifies the <a name="#deftransform">default transform</a> for
64  * the target of the <code>Graphics2D</code> (a
65  * {@link Component} or {@link Image}). This default transform maps the
66  * user space coordinate system to screen and printer device coordinates
67  * such that the origin maps to the upper left hand corner of the
68  * target region of the device with increasing X coordinates extending
69  * to the right and increasing Y coordinates extending downward.
70  * The scaling of the default transform is set to identity for those devices
71  * that are close to 72 dpi, such as screen devices.
72  * The scaling of the default transform is set to approximately 72 user
73  * space coordinates per square inch for high resolution devices, such as
74  * printers. For image buffers, the default transform is the
75  * <code>Identity</code> transform.
76  *
77  * <h2>Rendering Process</h2>
78  * The Rendering Process can be broken down into four phases that are
79  * controlled by the <code>Graphics2D</code> rendering attributes.
80  * The renderer can optimize many of these steps, either by caching the
81  * results for future calls, by collapsing multiple virtual steps into
82  * a single operation, or by recognizing various attributes as common
83  * simple cases that can be eliminated by modifying other parts of the
84  * operation.
85  * <p>
86  * The steps in the rendering process are:
87  * <ol>
88  * <li>
89  * Determine what to render.
90  * <li>
91  * Constrain the rendering operation to the current <code>Clip</code>.
92  * The <code>Clip</code> is specified by a {@link Shape} in user
93  * space and is controlled by the program using the various clip
94  * manipulation methods of <code>Graphics</code> and
95  * <code>Graphics2D</code>. This <i>user clip</i>
96  * is transformed into device space by the current
97  * <code>Transform</code> and combined with the
98  * <i>device clip</i>, which is defined by the visibility of windows and
99  * device extents. The combination of the user clip and device clip
100  * defines the <i>composite clip</i>, which determines the final clipping
101  * region. The user clip is not modified by the rendering
102  * system to reflect the resulting composite clip.
103  * <li>
104  * Determine what colors to render.
105  * <li>
106  * Apply the colors to the destination drawing surface using the current
107  * {@link Composite} attribute in the <code>Graphics2D</code> context.
108  * </ol>
109  * <br>
110  * The three types of rendering operations, along with details of each
111  * of their particular rendering processes are:
112  * <ol>
113  * <li>
114  * <b><a name="rendershape"><code>Shape</code> operations</a></b>
115  * <ol>
116  * <li>
117  * If the operation is a <code>draw(Shape)</code> operation, then
118  * the {@link Stroke#createStrokedShape(Shape) createStrokedShape}
119  * method on the current {@link Stroke} attribute in the
120  * <code>Graphics2D</code> context is used to construct a new
121  * <code>Shape</code> object that contains the outline of the specified
122  * <code>Shape</code>.
123  * <li>
124  * The <code>Shape</code> is transformed from user space to device space
125  * using the current <code>Transform</code>
126  * in the <code>Graphics2D</code> context.
127  * <li>
128  * The outline of the <code>Shape</code> is extracted using the
129  * {@link Shape#getPathIterator(AffineTransform) getPathIterator} method of
130  * <code>Shape</code>, which returns a
131  * {@link java.awt.geom.PathIterator PathIterator}
132  * object that iterates along the boundary of the <code>Shape</code>.
133  * <li>
134  * If the <code>Graphics2D</code> object cannot handle the curved segments
135  * that the <code>PathIterator</code> object returns then it can call the
136  * alternate
137  * {@link Shape#getPathIterator(AffineTransform, double) getPathIterator}
138  * method of <code>Shape</code>, which flattens the <code>Shape</code>.
139  * <li>
140  * The current {@link Paint} in the <code>Graphics2D</code> context
141  * is queried for a {@link PaintContext}, which specifies the
142  * colors to render in device space.
143  * </ol>
144  * <li>
145  * <b><a name=rendertext>Text operations</a></b>
146  * <ol>
147  * <li>
148  * The following steps are used to determine the set of glyphs required
149  * to render the indicated <code>String</code>:
150  * <ol>
151  * <li>
152  * If the argument is a <code>String</code>, then the current
153  * <code>Font</code> in the <code>Graphics2D</code> context is asked to
154  * convert the Unicode characters in the <code>String</code> into a set of
155  * glyphs for presentation with whatever basic layout and shaping
156  * algorithms the font implements.
157  * <li>
158  * If the argument is an
159  * {@link AttributedCharacterIterator},
160  * the iterator is asked to convert itself to a
161  * {@link java.awt.font.TextLayout TextLayout}
162  * using its embedded font attributes. The <code>TextLayout</code>
163  * implements more sophisticated glyph layout algorithms that
164  * perform Unicode bi-directional layout adjustments automatically
165  * for multiple fonts of differing writing directions.
166   * <li>
167  * If the argument is a
168  * {@link GlyphVector}, then the
169  * <code>GlyphVector</code> object already contains the appropriate
170  * font-specific glyph codes with explicit coordinates for the position of
171  * each glyph.
172  * </ol>
173  * <li>
174  * The current <code>Font</code> is queried to obtain outlines for the
175  * indicated glyphs. These outlines are treated as shapes in user space
176  * relative to the position of each glyph that was determined in step 1.
177  * <li>
178  * The character outlines are filled as indicated above
179  * under <a HREF="#rendershape"><code>Shape</code> operations</a>.
180  * <li>
181  * The current <code>Paint</code> is queried for a
182  * <code>PaintContext</code>, which specifies
183  * the colors to render in device space.
184  * </ol>
185  * <li>
186  * <b><a name= renderingimage><code>Image</code> Operations</a></b>
187  * <ol>
188  * <li>
189  * The region of interest is defined by the bounding box of the source
190  * <code>Image</code>.
191  * This bounding box is specified in Image Space, which is the
192  * <code>Image</code> object's local coordinate system.
193  * <li>
194  * If an <code>AffineTransform</code> is passed to
195  * {@link #drawImage(java.awt.Image, java.awt.geom.AffineTransform, java.awt.image.ImageObserver) drawImage(Image, AffineTransform, ImageObserver)},
196  * the <code>AffineTransform</code> is used to transform the bounding
197  * box from image space to user space. If no <code>AffineTransform</code>
198  * is supplied, the bounding box is treated as if it is already in user space.
199  * <li>
200  * The bounding box of the source <code>Image</code> is transformed from user
201  * space into device space using the current <code>Transform</code>.
202  * Note that the result of transforming the bounding box does not
203  * necessarily result in a rectangular region in device space.
204  * <li>
205  * The <code>Image</code> object determines what colors to render,
206  * sampled according to the source to destination
207  * coordinate mapping specified by the current <code>Transform</code> and the
208  * optional image transform.
209  * </ol>
210  * </ol>
211  *
212  * <h2>Default Rendering Attributes</h2>
213  * The default values for the <code>Graphics2D</code> rendering attributes are:
214  * <dl compact>
215  * <dt><i><code>Paint</code></i>
216  * <dd>The color of the <code>Component</code>.
217  * <dt><i><code>Font</code></i>
218  * <dd>The <code>Font</code> of the <code>Component</code>.
219  * <dt><i><code>Stroke</code></i>
220  * <dd>A square pen with a linewidth of 1, no dashing, miter segment joins
221  * and square end caps.
222  * <dt><i><code>Transform</code></i>
223  * <dd>The
224  * {@link GraphicsConfiguration#getDefaultTransform() getDefaultTransform}
225  * for the <code>GraphicsConfiguration</code> of the <code>Component</code>.
226  * <dt><i><code>Composite</code></i>
227  * <dd>The {@link AlphaComposite#SRC_OVER} rule.
228  * <dt><i><code>Clip</code></i>
229  * <dd>No rendering <code>Clip</code>, the output is clipped to the
230  * <code>Component</code>.
231  * </dl>
232  *
233  * <h2>Rendering Compatibility Issues</h2>
234  * The JDK(tm) 1.1 rendering model is based on a pixelization model
235  * that specifies that coordinates
236  * are infinitely thin, lying between the pixels. Drawing operations are
237  * performed using a one-pixel wide pen that fills the
238  * pixel below and to the right of the anchor point on the path.
239  * The JDK 1.1 rendering model is consistent with the
240  * capabilities of most of the existing class of platform
241  * renderers that need to resolve integer coordinates to a
242  * discrete pen that must fall completely on a specified number of pixels.
243  * <p>
244  * The Java 2D(tm) (Java(tm) 2 platform) API supports antialiasing renderers.
245  * A pen with a width of one pixel does not need to fall
246  * completely on pixel N as opposed to pixel N+1. The pen can fall
247  * partially on both pixels. It is not necessary to choose a bias
248  * direction for a wide pen since the blending that occurs along the
249  * pen traversal edges makes the sub-pixel position of the pen
250  * visible to the user. On the other hand, when antialiasing is
251  * turned off by setting the
252  * {@link RenderingHints#KEY_ANTIALIASING KEY_ANTIALIASING} hint key
253  * to the
254  * {@link RenderingHints#VALUE_ANTIALIAS_OFF VALUE_ANTIALIAS_OFF}
255  * hint value, the renderer might need
256  * to apply a bias to determine which pixel to modify when the pen
257  * is straddling a pixel boundary, such as when it is drawn
258  * along an integer coordinate in device space. While the capabilities
259  * of an antialiasing renderer make it no longer necessary for the
260  * rendering model to specify a bias for the pen, it is desirable for the
261  * antialiasing and non-antialiasing renderers to perform similarly for
262  * the common cases of drawing one-pixel wide horizontal and vertical
263  * lines on the screen. To ensure that turning on antialiasing by
264  * setting the
265  * {@link RenderingHints#KEY_ANTIALIASING KEY_ANTIALIASING} hint
266  * key to
267  * {@link RenderingHints#VALUE_ANTIALIAS_ON VALUE_ANTIALIAS_ON}
268  * does not cause such lines to suddenly become twice as wide and half
269  * as opaque, it is desirable to have the model specify a path for such
270  * lines so that they completely cover a particular set of pixels to help
271  * increase their crispness.
272  * <p>
273  * Java 2D API maintains compatibility with JDK 1.1 rendering
274  * behavior, such that legacy operations and existing renderer
275  * behavior is unchanged under Java 2D API. Legacy
276  * methods that map onto general <code>draw</code> and
277  * <code>fill</code> methods are defined, which clearly indicates
278  * how <code>Graphics2D</code> extends <code>Graphics</code> based
279  * on settings of <code>Stroke</code> and <code>Transform</code>
280  * attributes and rendering hints. The definition
281  * performs identically under default attribute settings.
282  * For example, the default <code>Stroke</code> is a
283  * <code>BasicStroke</code> with a width of 1 and no dashing and the
284  * default Transform for screen drawing is an Identity transform.
285  * <p>
286  * The following two rules provide predictable rendering behavior whether
287  * aliasing or antialiasing is being used.
288  * <ul>
289  * <li> Device coordinates are defined to be between device pixels which
290  * avoids any inconsistent results between aliased and antaliased
291  * rendering. If coordinates were defined to be at a pixel's center, some
292  * of the pixels covered by a shape, such as a rectangle, would only be
293  * half covered.
294  * With aliased rendering, the half covered pixels would either be
295  * rendered inside the shape or outside the shape. With anti-aliased
296  * rendering, the pixels on the entire edge of the shape would be half
297  * covered. On the other hand, since coordinates are defined to be
298  * between pixels, a shape like a rectangle would have no half covered
299  * pixels, whether or not it is rendered using antialiasing.
300  * <li> Lines and paths stroked using the <code>BasicStroke</code>
301  * object may be "normalized" to provide consistent rendering of the
302  * outlines when positioned at various points on the drawable and
303  * whether drawn with aliased or antialiased rendering. This
304  * normalization process is controlled by the
305  * {@link RenderingHints#KEY_STROKE_CONTROL KEY_STROKE_CONTROL} hint.
306  * The exact normalization algorithm is not specified, but the goals
307  * of this normalization are to ensure that lines are rendered with
308  * consistent visual appearance regardless of how they fall on the
309  * pixel grid and to promote more solid horizontal and vertical
310  * lines in antialiased mode so that they resemble their non-antialiased
311  * counterparts more closely. A typical normalization step might
312  * promote antialiased line endpoints to pixel centers to reduce the
313  * amount of blending or adjust the subpixel positioning of
314  * non-antialiased lines so that the floating point line widths
315  * round to even or odd pixel counts with equal likelihood. This
316  * process can move endpoints by up to half a pixel (usually towards
317  * positive infinity along both axes) to promote these consistent
318  * results.
319  * </ul>
320  * <p>
321  * The following definitions of general legacy methods
322  * perform identically to previously specified behavior under default
323  * attribute settings:
324  * <ul>
325  * <li>
326  * For <code>fill</code> operations, including <code>fillRect</code>,
327  * <code>fillRoundRect</code>, <code>fillOval</code>,
328  * <code>fillArc</code>, <code>fillPolygon</code>, and
329  * <code>clearRect</code>, {@link #fill(Shape) fill} can now be called
330  * with the desired <code>Shape</code>. For example, when filling a
331  * rectangle:
332  * <pre>
333  * fill(new Rectangle(x, y, w, h));
334  * </pre>
335  * is called.
336  * <p>
337  * <li>
338  * Similarly, for draw operations, including <code>drawLine</code>,
339  * <code>drawRect</code>, <code>drawRoundRect</code>,
340  * <code>drawOval</code>, <code>drawArc</code>, <code>drawPolyline</code>,
341  * and <code>drawPolygon</code>, {@link #draw(Shape) draw} can now be
342  * called with the desired <code>Shape</code>. For example, when drawing a
343  * rectangle:
344  * <pre>
345  * draw(new Rectangle(x, y, w, h));
346  * </pre>
347  * is called.
348  * <p>
349  * <li>
350  * The <code>draw3DRect</code> and <code>fill3DRect</code> methods were
351  * implemented in terms of the <code>drawLine</code> and
352  * <code>fillRect</code> methods in the <code>Graphics</code> class which
353  * would predicate their behavior upon the current <code>Stroke</code>
354  * and <code>Paint</code> objects in a <code>Graphics2D</code> context.
355  * This class overrides those implementations with versions that use
356  * the current <code>Color</code> exclusively, overriding the current
357  * <code>Paint</code> and which uses <code>fillRect</code> to describe
358  * the exact same behavior as the preexisting methods regardless of the
359  * setting of the current <code>Stroke</code>.
360  * </ul>
361  * The <code>Graphics</code> class defines only the <code>setColor</code>
362  * method to control the color to be painted. Since the Java 2D API extends
363  * the <code>Color</code> object to implement the new <code>Paint</code>
364  * interface, the existing
365  * <code>setColor</code> method is now a convenience method for setting the
366  * current <code>Paint</code> attribute to a <code>Color</code> object.
367  * <code>setColor(c)</code> is equivalent to <code>setPaint(c)</code>.
368  * <p>
369  * The <code>Graphics</code> class defines two methods for controlling
370  * how colors are applied to the destination.
371  * <ol>
372  * <li>
373  * The <code>setPaintMode</code> method is implemented as a convenience
374  * method to set the default <code>Composite</code>, equivalent to
375  * <code>setComposite(new AlphaComposite.SrcOver)</code>.
376  * <li>
377  * The <code>setXORMode(Color xorcolor)</code> method is implemented
378  * as a convenience method to set a special <code>Composite</code> object that
379  * ignores the <code>Alpha</code> components of source colors and sets the
380  * destination color to the value:
381  * <pre>
382  * dstpixel = (PixelOf(srccolor) ^ PixelOf(xorcolor) ^ dstpixel);
383  * </pre>
384  * </ol>
385  *
386  * @version 1.81, 05/05/04
387  * @author Jim Graham
388  * @see java.awt.RenderingHints
389  */

390 public abstract class Graphics2D extends Graphics JavaDoc {
391
392     /**
393      * Constructs a new <code>Graphics2D</code> object. Since
394      * <code>Graphics2D</code> is an abstract class, and since it must be
395      * customized by subclasses for different output devices,
396      * <code>Graphics2D</code> objects cannot be created directly.
397      * Instead, <code>Graphics2D</code> objects must be obtained from another
398      * <code>Graphics2D</code> object, created by a
399      * <code>Component</code>, or obtained from images such as
400      * {@link BufferedImage} objects.
401      * @see java.awt.Component#getGraphics
402      * @see java.awt.Graphics#create
403      */

404     protected Graphics2D() {
405     }
406
407     /**
408      * Draws a 3-D highlighted outline of the specified rectangle.
409      * The edges of the rectangle are highlighted so that they
410      * appear to be beveled and lit from the upper left corner.
411      * <p>
412      * The colors used for the highlighting effect are determined
413      * based on the current color.
414      * The resulting rectangle covers an area that is
415      * <code>width&nbsp;+&nbsp;1</code> pixels wide
416      * by <code>height&nbsp;+&nbsp;1</code> pixels tall. This method
417      * uses the current <code>Color</code> exclusively and ignores
418      * the current <code>Paint</code>.
419      * @param x the x coordinate of the rectangle to be drawn.
420      * @param y the y coordinate of the rectangle to be drawn.
421      * @param width the width of the rectangle to be drawn.
422      * @param height the height of the rectangle to be drawn.
423      * @param raised a boolean that determines whether the rectangle
424      * appears to be raised above the surface
425      * or sunk into the surface.
426      * @see java.awt.Graphics#fill3DRect
427      */

428     public void draw3DRect(int x, int y, int width, int height,
429                boolean raised) {
430     Paint JavaDoc p = getPaint();
431     Color JavaDoc c = getColor();
432     Color JavaDoc brighter = c.brighter();
433     Color JavaDoc darker = c.darker();
434
435     setColor(raised ? brighter : darker);
436     //drawLine(x, y, x, y + height);
437
fillRect(x, y, 1, height + 1);
438     //drawLine(x + 1, y, x + width - 1, y);
439
fillRect(x + 1, y, width - 1, 1);
440     setColor(raised ? darker : brighter);
441     //drawLine(x + 1, y + height, x + width, y + height);
442
fillRect(x + 1, y + height, width, 1);
443     //drawLine(x + width, y, x + width, y + height - 1);
444
fillRect(x + width, y, 1, height);
445     setPaint(p);
446     }
447
448     /**
449      * Paints a 3-D highlighted rectangle filled with the current color.
450      * The edges of the rectangle are highlighted so that it appears
451      * as if the edges were beveled and lit from the upper left corner.
452      * The colors used for the highlighting effect and for filling are
453      * determined from the current <code>Color</code>. This method uses
454      * the current <code>Color</code> exclusively and ignores the current
455      * <code>Paint</code>.
456      * @param x the x coordinate of the rectangle to be filled.
457      * @param y the y coordinate of the rectangle to be filled.
458      * @param width the width of the rectangle to be filled.
459      * @param height the height of the rectangle to be filled.
460      * @param raised a boolean value that determines whether the
461      * rectangle appears to be raised above the surface
462      * or etched into the surface.
463      * @see java.awt.Graphics#draw3DRect
464      */

465     public void fill3DRect(int x, int y, int width, int height,
466                boolean raised) {
467     Paint JavaDoc p = getPaint();
468     Color JavaDoc c = getColor();
469     Color JavaDoc brighter = c.brighter();
470     Color JavaDoc darker = c.darker();
471
472     if (!raised) {
473         setColor(darker);
474     } else if (p != c) {
475         setColor(c);
476     }
477     fillRect(x+1, y+1, width-2, height-2);
478     setColor(raised ? brighter : darker);
479     //drawLine(x, y, x, y + height - 1);
480
fillRect(x, y, 1, height);
481     //drawLine(x + 1, y, x + width - 2, y);
482
fillRect(x + 1, y, width - 2, 1);
483     setColor(raised ? darker : brighter);
484     //drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1);
485
fillRect(x + 1, y + height - 1, width - 1, 1);
486     //drawLine(x + width - 1, y, x + width - 1, y + height - 2);
487
fillRect(x + width - 1, y, 1, height - 1);
488     setPaint(p);
489     }
490
491     /**
492      * Strokes the outline of a <code>Shape</code> using the settings of the
493      * current <code>Graphics2D</code> context. The rendering attributes
494      * applied include the <code>Clip</code>, <code>Transform</code>,
495      * <code>Paint</code>, <code>Composite</code> and
496      * <code>Stroke</code> attributes.
497      * @param s the <code>Shape</code> to be rendered
498      * @see #setStroke
499      * @see #setPaint
500      * @see java.awt.Graphics#setColor
501      * @see #transform
502      * @see #setTransform
503      * @see #clip
504      * @see #setClip
505      * @see #setComposite
506      */

507     public abstract void draw(Shape JavaDoc s);
508
509     /**
510      * Renders an image, applying a transform from image space into user space
511      * before drawing.
512      * The transformation from user space into device space is done with
513      * the current <code>Transform</code> in the <code>Graphics2D</code>.
514      * The specified transformation is applied to the image before the
515      * transform attribute in the <code>Graphics2D</code> context is applied.
516      * The rendering attributes applied include the <code>Clip</code>,
517      * <code>Transform</code>, and <code>Composite</code> attributes.
518      * Note that no rendering is done if the specified transform is
519      * noninvertible.
520      * @param img the specified image to be rendered.
521      * This method does nothing if <code>img</code> is null.
522      * @param xform the transformation from image space into user space
523      * @param obs the {@link ImageObserver}
524      * to be notified as more of the <code>Image</code>
525      * is converted
526      * @return <code>true</code> if the <code>Image</code> is
527      * fully loaded and completely rendered, or if it's null;
528      * <code>false</code> if the <code>Image</code> is still being loaded.
529      * @see #transform
530      * @see #setTransform
531      * @see #setComposite
532      * @see #clip
533      * @see #setClip
534      */

535     public abstract boolean drawImage(Image JavaDoc img,
536                                       AffineTransform JavaDoc xform,
537                                       ImageObserver JavaDoc obs);
538
539     /**
540      * Renders a <code>BufferedImage</code> that is
541      * filtered with a
542      * {@link BufferedImageOp}.
543      * The rendering attributes applied include the <code>Clip</code>,
544      * <code>Transform</code>
545      * and <code>Composite</code> attributes. This is equivalent to:
546      * <pre>
547      * img1 = op.filter(img, null);
548      * drawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null);
549      * </pre>
550      * @param op the filter to be applied to the image before rendering
551      * @param img the specified <code>BufferedImage</code> to be rendered.
552      * This method does nothing if <code>img</code> is null.
553      * @param x the x coordinate of the location in user space where
554      * the upper left corner of the image is rendered
555      * @param y the y coordinate of the location in user space where
556      * the upper left corner of the image is rendered
557      *
558      * @see #transform
559      * @see #setTransform
560      * @see #setComposite
561      * @see #clip
562      * @see #setClip
563      */

564     public abstract void drawImage(BufferedImage JavaDoc img,
565                    BufferedImageOp JavaDoc op,
566                    int x,
567                    int y);
568
569     /**
570      * Renders a {@link RenderedImage},
571      * applying a transform from image
572      * space into user space before drawing.
573      * The transformation from user space into device space is done with
574      * the current <code>Transform</code> in the <code>Graphics2D</code>.
575      * The specified transformation is applied to the image before the
576      * transform attribute in the <code>Graphics2D</code> context is applied.
577      * The rendering attributes applied include the <code>Clip</code>,
578      * <code>Transform</code>, and <code>Composite</code> attributes. Note
579      * that no rendering is done if the specified transform is
580      * noninvertible.
581      * @param img the image to be rendered. This method does
582      * nothing if <code>img</code> is null.
583      * @param xform the transformation from image space into user space
584      * @see #transform
585      * @see #setTransform
586      * @see #setComposite
587      * @see #clip
588      * @see #setClip
589      */

590     public abstract void drawRenderedImage(RenderedImage JavaDoc img,
591                                            AffineTransform JavaDoc xform);
592
593     /**
594      * Renders a
595      * {@link RenderableImage},
596      * applying a transform from image space into user space before drawing.
597      * The transformation from user space into device space is done with
598      * the current <code>Transform</code> in the <code>Graphics2D</code>.
599      * The specified transformation is applied to the image before the
600      * transform attribute in the <code>Graphics2D</code> context is applied.
601      * The rendering attributes applied include the <code>Clip</code>,
602      * <code>Transform</code>, and <code>Composite</code> attributes. Note
603      * that no rendering is done if the specified transform is
604      * noninvertible.
605      *<p>
606      * Rendering hints set on the <code>Graphics2D</code> object might
607      * be used in rendering the <code>RenderableImage</code>.
608      * If explicit control is required over specific hints recognized by a
609      * specific <code>RenderableImage</code>, or if knowledge of which hints
610      * are used is required, then a <code>RenderedImage</code> should be
611      * obtained directly from the <code>RenderableImage</code>
612      * and rendered using
613      *{@link #drawRenderedImage(RenderedImage, AffineTransform) drawRenderedImage}.
614      * @param img the image to be rendered. This method does
615      * nothing if <code>img</code> is null.
616      * @param xform the transformation from image space into user space
617      * @see #transform
618      * @see #setTransform
619      * @see #setComposite
620      * @see #clip
621      * @see #setClip
622      * @see #drawRenderedImage
623      */

624     public abstract void drawRenderableImage(RenderableImage JavaDoc img,
625                                              AffineTransform JavaDoc xform);
626
627     /**
628      * Renders the text of the specified <code>String</code>, using the
629      * current text attribute state in the <code>Graphics2D</code> context.
630      * The baseline of the
631      * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in
632      * the User Space.
633      * The rendering attributes applied include the <code>Clip</code>,
634      * <code>Transform</code>, <code>Paint</code>, <code>Font</code> and
635      * <code>Composite</code> attributes. For characters in script
636      * systems such as Hebrew and Arabic, the glyphs can be rendered from
637      * right to left, in which case the coordinate supplied is the
638      * location of the leftmost character on the baseline.
639      * @param str the string to be rendered
640      * @param x the x coordinate of the location where the
641      * <code>String</code> should be rendered
642      * @param y the y coordinate of the location where the
643      * <code>String</code> should be rendered
644      * @throws NullPointerException if <code>str</code> is
645      * <code>null</code>
646      * @see java.awt.Graphics#drawBytes
647      * @see java.awt.Graphics#drawChars
648      * @since JDK1.0
649      */

650     public abstract void drawString(String JavaDoc str, int x, int y);
651
652     /**
653      * Renders the text specified by the specified <code>String</code>,
654      * using the current text attribute state in the <code>Graphics2D</code> context.
655      * The baseline of the first character is at position
656      * (<i>x</i>,&nbsp;<i>y</i>) in the User Space.
657      * The rendering attributes applied include the <code>Clip</code>,
658      * <code>Transform</code>, <code>Paint</code>, <code>Font</code> and
659      * <code>Composite</code> attributes. For characters in script systems
660      * such as Hebrew and Arabic, the glyphs can be rendered from right to
661      * left, in which case the coordinate supplied is the location of the
662      * leftmost character on the baseline.
663      * @param s the <code>String</code> to be rendered
664      * @param x the x coordinate of the location where the
665      * <code>String</code> should be rendered
666      * @param y the y coordinate of the location where the
667      * <code>String</code> should be rendered
668      * @throws NullPointerException if <code>str</code> is
669      * <code>null</code>
670      * @see #setPaint
671      * @see java.awt.Graphics#setColor
672      * @see java.awt.Graphics#setFont
673      * @see #setTransform
674      * @see #setComposite
675      * @see #setClip
676      */

677     public abstract void drawString(String JavaDoc s, float x, float y);
678
679     /**
680      * Renders the text of the specified iterator, using the
681      * <code>Graphics2D</code> context's current <code>Paint</code>. The
682      * iterator has to specify a font
683      * for each character. The baseline of the
684      * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in the
685      * User Space.
686      * The rendering attributes applied include the <code>Clip</code>,
687      * <code>Transform</code>, <code>Paint</code>, and
688      * <code>Composite</code> attributes.
689      * For characters in script systems such as Hebrew and Arabic,
690      * the glyphs can be rendered from right to left, in which case the
691      * coordinate supplied is the location of the leftmost character
692      * on the baseline.
693      * @param iterator the iterator whose text is to be rendered
694      * @param x the x coordinate where the iterator's text is to be
695      * rendered
696      * @param y the y coordinate where the iterator's text is to be
697      * rendered
698      * @see #setPaint
699      * @see java.awt.Graphics#setColor
700      * @see #setTransform
701      * @see #setComposite
702      * @see #setClip
703      */

704     public abstract void drawString(AttributedCharacterIterator JavaDoc iterator,
705                                     int x, int y);
706
707     /**
708      * Renders the text of the specified iterator, using the
709      * <code>Graphics2D</code> context's current <code>Paint</code>. The
710      * iterator must specify a font
711      * for each character. The baseline of the
712      * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in the
713      * User Space.
714      * The rendering attributes applied include the <code>Clip</code>,
715      * <code>Transform</code>, <code>Paint</code>, and
716      * <code>Composite</code> attributes.
717      * For characters in script systems such as Hebrew and Arabic,
718      * the glyphs can be rendered from right to left, in which case the
719      * coordinate supplied is the location of the leftmost character
720      * on the baseline.
721      * @param iterator the iterator whose text is to be rendered
722      * @param x the x coordinate where the iterator's text is to be
723      * rendered
724      * @param y the y coordinate where the iterator's text is to be
725      * rendered
726      * @see #setPaint
727      * @see java.awt.Graphics#setColor
728      * @see #setTransform
729      * @see #setComposite
730      * @see #setClip
731      */

732     public abstract void drawString(AttributedCharacterIterator JavaDoc iterator,
733                                     float x, float y);
734
735     /**
736      * Renders the text of the specified
737      * {@link GlyphVector} using
738      * the <code>Graphics2D</code> context's rendering attributes.
739      * The rendering attributes applied include the <code>Clip</code>,
740      * <code>Transform</code>, <code>Paint</code>, and
741      * <code>Composite</code> attributes. The <code>GlyphVector</code>
742      * specifies individual glyphs from a {@link Font}.
743      * The <code>GlyphVector</code> can also contain the glyph positions.
744      * This is the fastest way to render a set of characters to the
745      * screen.
746      * @param g the <code>GlyphVector</code> to be rendered
747      * @param x the x position in User Space where the glyphs should
748      * be rendered
749      * @param y the y position in User Space where the glyphs should
750      * be rendered
751      *
752      * @see java.awt.Font#createGlyphVector
753      * @see java.awt.font.GlyphVector
754      * @see #setPaint
755      * @see java.awt.Graphics#setColor
756      * @see #setTransform
757      * @see #setComposite
758      * @see #setClip
759      */

760     public abstract void drawGlyphVector(GlyphVector JavaDoc g, float x, float y);
761
762     /**
763      * Fills the interior of a <code>Shape</code> using the settings of the
764      * <code>Graphics2D</code> context. The rendering attributes applied
765      * include the <code>Clip</code>, <code>Transform</code>,
766      * <code>Paint</code>, and <code>Composite</code>.
767      * @param s the <code>Shape</code> to be filled
768      * @see #setPaint
769      * @see java.awt.Graphics#setColor
770      * @see #transform
771      * @see #setTransform
772      * @see #setComposite
773      * @see #clip
774      * @see #setClip
775      */

776     public abstract void fill(Shape JavaDoc s);
777
778     /**
779      * Checks whether or not the specified <code>Shape</code> intersects
780      * the specified {@link Rectangle}, which is in device
781      * space. If <code>onStroke</code> is false, this method checks
782      * whether or not the interior of the specified <code>Shape</code>
783      * intersects the specified <code>Rectangle</code>. If
784      * <code>onStroke</code> is <code>true</code>, this method checks
785      * whether or not the <code>Stroke</code> of the specified
786      * <code>Shape</code> outline intersects the specified
787      * <code>Rectangle</code>.
788      * The rendering attributes taken into account include the
789      * <code>Clip</code>, <code>Transform</code>, and <code>Stroke</code>
790      * attributes.
791      * @param rect the area in device space to check for a hit
792      * @param s the <code>Shape</code> to check for a hit
793      * @param onStroke flag used to choose between testing the
794      * stroked or the filled shape. If the flag is <code>true</code>, the
795      * <code>Stroke</code> oultine is tested. If the flag is
796      * <code>false</code>, the filled <code>Shape</code> is tested.
797      * @return <code>true</code> if there is a hit; <code>false</code>
798      * otherwise.
799      * @see #setStroke
800      * @see #fill
801      * @see #draw
802      * @see #transform
803      * @see #setTransform
804      * @see #clip
805      * @see #setClip
806      */

807     public abstract boolean hit(Rectangle JavaDoc rect,
808                 Shape JavaDoc s,
809                 boolean onStroke);
810
811     /**
812      * Returns the device configuration associated with this
813      * <code>Graphics2D</code>.
814      * @return the device configuration of this <code>Graphics2D</code>.
815      */

816     public abstract GraphicsConfiguration JavaDoc getDeviceConfiguration();
817
818     /**
819      * Sets the <code>Composite</code> for the <code>Graphics2D</code> context.
820      * The <code>Composite</code> is used in all drawing methods such as
821      * <code>drawImage</code>, <code>drawString</code>, <code>draw</code>,
822      * and <code>fill</code>. It specifies how new pixels are to be combined
823      * with the existing pixels on the graphics device during the rendering
824      * process.
825      * <p>If this <code>Graphics2D</code> context is drawing to a
826      * <code>Component</code> on the display screen and the
827      * <code>Composite</code> is a custom object rather than an
828      * instance of the <code>AlphaComposite</code> class, and if
829      * there is a security manager, its <code>checkPermission</code>
830      * method is called with an <code>AWTPermission("readDisplayPixels")</code>
831      * permission.
832      * @throws SecurityException
833      * if a custom <code>Composite</code> object is being
834      * used to render to the screen and a security manager
835      * is set and its <code>checkPermission</code> method
836      * does not allow the operation.
837      * @param comp the <code>Composite</code> object to be used for rendering
838      * @see java.awt.Graphics#setXORMode
839      * @see java.awt.Graphics#setPaintMode
840      * @see #getComposite
841      * @see AlphaComposite
842      * @see SecurityManager#checkPermission
843      * @see java.awt.AWTPermission
844      */

845     public abstract void setComposite(Composite JavaDoc comp);
846
847     /**
848      * Sets the <code>Paint</code> attribute for the
849      * <code>Graphics2D</code> context. Calling this method
850      * with a <code>null</code> <code>Paint</code> object does
851      * not have any effect on the current <code>Paint</code> attribute
852      * of this <code>Graphics2D</code>.
853      * @param paint the <code>Paint</code> object to be used to generate
854      * color during the rendering process, or <code>null</code>
855      * @see java.awt.Graphics#setColor
856      * @see #getPaint
857      * @see GradientPaint
858      * @see TexturePaint
859      */

860     public abstract void setPaint( Paint JavaDoc paint );
861
862     /**
863      * Sets the <code>Stroke</code> for the <code>Graphics2D</code> context.
864      * @param s the <code>Stroke</code> object to be used to stroke a
865      * <code>Shape</code> during the rendering process
866      * @see BasicStroke
867      * @see #getStroke
868      */

869     public abstract void setStroke(Stroke JavaDoc s);
870
871     /**
872      * Sets the value of a single preference for the rendering algorithms.
873      * Hint categories include controls for rendering quality and overall
874      * time/quality trade-off in the rendering process. Refer to the
875      * <code>RenderingHints</code> class for definitions of some common
876      * keys and values.
877      * @param hintKey the key of the hint to be set.
878      * @param hintValue the value indicating preferences for the specified
879      * hint category.
880      * @see #getRenderingHint(RenderingHints.Key)
881      * @see RenderingHints
882      */

883     public abstract void setRenderingHint(Key hintKey, Object JavaDoc hintValue);
884
885     /**
886      * Returns the value of a single preference for the rendering algorithms.
887      * Hint categories include controls for rendering quality and overall
888      * time/quality trade-off in the rendering process. Refer to the
889      * <code>RenderingHints</code> class for definitions of some common
890      * keys and values.
891      * @param hintKey the key corresponding to the hint to get.
892      * @return an object representing the value for the specified hint key.
893      * Some of the keys and their associated values are defined in the
894      * <code>RenderingHints</code> class.
895      * @see RenderingHints
896      * @see #setRenderingHint(RenderingHints.Key, Object)
897      */

898     public abstract Object JavaDoc getRenderingHint(Key hintKey);
899
900     /**
901      * Replaces the values of all preferences for the rendering
902      * algorithms with the specified <code>hints</code>.
903      * The existing values for all rendering hints are discarded and
904      * the new set of known hints and values are initialized from the
905      * specified {@link Map} object.
906      * Hint categories include controls for rendering quality and
907      * overall time/quality trade-off in the rendering process.
908      * Refer to the <code>RenderingHints</code> class for definitions of
909      * some common keys and values.
910      * @param hints the rendering hints to be set
911      * @see #getRenderingHints
912      * @see RenderingHints
913      */

914     public abstract void setRenderingHints(Map JavaDoc<?,?> hints);
915
916     /**
917      * Sets the values of an arbitrary number of preferences for the
918      * rendering algorithms.
919      * Only values for the rendering hints that are present in the
920      * specified <code>Map</code> object are modified.
921      * All other preferences not present in the specified
922      * object are left unmodified.
923      * Hint categories include controls for rendering quality and
924      * overall time/quality trade-off in the rendering process.
925      * Refer to the <code>RenderingHints</code> class for definitions of
926      * some common keys and values.
927      * @param hints the rendering hints to be set
928      * @see RenderingHints
929      */

930     public abstract void addRenderingHints(Map JavaDoc<?,?> hints);
931
932     /**
933      * Gets the preferences for the rendering algorithms. Hint categories
934      * include controls for rendering quality and overall time/quality
935      * trade-off in the rendering process.
936      * Returns all of the hint key/value pairs that were ever specified in
937      * one operation. Refer to the
938      * <code>RenderingHints</code> class for definitions of some common
939      * keys and values.
940      * @return a reference to an instance of <code>RenderingHints</code>
941      * that contains the current preferences.
942      * @see RenderingHints
943      * @see #setRenderingHints(Map)
944      */

945     public abstract RenderingHints JavaDoc getRenderingHints();
946
947     /**
948      * Translates the origin of the <code>Graphics2D</code> context to the
949      * point (<i>x</i>,&nbsp;<i>y</i>) in the current coordinate system.
950      * Modifies the <code>Graphics2D</code> context so that its new origin
951      * corresponds to the point (<i>x</i>,&nbsp;<i>y</i>) in the
952      * <code>Graphics2D</code> context's former coordinate system. All
953      * coordinates used in subsequent rendering operations on this graphics
954      * context are relative to this new origin.
955      * @param x the specified x coordinate
956      * @param y the specified y coordinate
957      * @since JDK1.0
958      */

959     public abstract void translate(int x, int y);
960
961     /**
962      * Concatenates the current
963      * <code>Graphics2D</code> <code>Transform</code>
964      * with a translation transform.
965      * Subsequent rendering is translated by the specified
966      * distance relative to the previous position.
967      * This is equivalent to calling transform(T), where T is an
968      * <code>AffineTransform</code> represented by the following matrix:
969      * <pre>
970      * [ 1 0 tx ]
971      * [ 0 1 ty ]
972      * [ 0 0 1 ]
973      * </pre>
974      * @param tx the distance to translate along the x-axis
975      * @param ty the distance to translate along the y-axis
976      */

977     public abstract void translate(double tx, double ty);
978
979     /**
980      * Concatenates the current <code>Graphics2D</code>
981      * <code>Transform</code> with a rotation transform.
982      * Subsequent rendering is rotated by the specified radians relative
983      * to the previous origin.
984      * This is equivalent to calling <code>transform(R)</code>, where R is an
985      * <code>AffineTransform</code> represented by the following matrix:
986      * <pre>
987      * [ cos(theta) -sin(theta) 0 ]
988      * [ sin(theta) cos(theta) 0 ]
989      * [ 0 0 1 ]
990      * </pre>
991      * Rotating with a positive angle theta rotates points on the positive
992      * x axis toward the positive y axis.
993      * @param theta the angle of rotation in radians
994      */

995     public abstract void rotate(double theta);
996
997     /**
998      * Concatenates the current <code>Graphics2D</code>
999      * <code>Transform</code> with a translated rotation
1000     * transform. Subsequent rendering is transformed by a transform
1001     * which is constructed by translating to the specified location,
1002     * rotating by the specified radians, and translating back by the same
1003     * amount as the original translation. This is equivalent to the
1004     * following sequence of calls:
1005     * <pre>
1006     * translate(x, y);
1007     * rotate(theta);
1008     * translate(-x, -y);
1009     * </pre>
1010     * Rotating with a positive angle theta rotates points on the positive
1011     * x axis toward the positive y axis.
1012     * @param theta the angle of rotation in radians
1013     * @param x the x coordinate of the origin of the rotation
1014     * @param y the y coordinate of the origin of the rotation
1015     */

1016    public abstract void rotate(double theta, double x, double y);
1017
1018    /**
1019     * Concatenates the current <code>Graphics2D</code>
1020     * <code>Transform</code> with a scaling transformation
1021     * Subsequent rendering is resized according to the specified scaling
1022     * factors relative to the previous scaling.
1023     * This is equivalent to calling <code>transform(S)</code>, where S is an
1024     * <code>AffineTransform</code> represented by the following matrix:
1025     * <pre>
1026     * [ sx 0 0 ]
1027     * [ 0 sy 0 ]
1028     * [ 0 0 1 ]
1029     * </pre>
1030     * @param sx the amount by which X coordinates in subsequent
1031     * rendering operations are multiplied relative to previous
1032     * rendering operations.
1033     * @param sy the amount by which Y coordinates in subsequent
1034     * rendering operations are multiplied relative to previous
1035     * rendering operations.
1036     */

1037    public abstract void scale(double sx, double sy);
1038
1039    /**
1040     * Concatenates the current <code>Graphics2D</code>
1041     * <code>Transform</code> with a shearing transform.
1042     * Subsequent renderings are sheared by the specified
1043     * multiplier relative to the previous position.
1044     * This is equivalent to calling <code>transform(SH)</code>, where SH
1045     * is an <code>AffineTransform</code> represented by the following
1046     * matrix:
1047     * <pre>
1048     * [ 1 shx 0 ]
1049     * [ shy 1 0 ]
1050     * [ 0 0 1 ]
1051     * </pre>
1052     * @param shx the multiplier by which coordinates are shifted in
1053     * the positive X axis direction as a function of their Y coordinate
1054     * @param shy the multiplier by which coordinates are shifted in
1055     * the positive Y axis direction as a function of their X coordinate
1056     */

1057    public abstract void shear(double shx, double shy);
1058
1059    /**
1060     * Composes an <code>AffineTransform</code> object with the
1061     * <code>Transform</code> in this <code>Graphics2D</code> according
1062     * to the rule last-specified-first-applied. If the current
1063     * <code>Transform</code> is Cx, the result of composition
1064     * with Tx is a new <code>Transform</code> Cx'. Cx' becomes the
1065     * current <code>Transform</code> for this <code>Graphics2D</code>.
1066     * Transforming a point p by the updated <code>Transform</code> Cx' is
1067     * equivalent to first transforming p by Tx and then transforming
1068     * the result by the original <code>Transform</code> Cx. In other
1069     * words, Cx'(p) = Cx(Tx(p)). A copy of the Tx is made, if necessary,
1070     * so further modifications to Tx do not affect rendering.
1071     * @param Tx the <code>AffineTransform</code> object to be composed with
1072     * the current <code>Transform</code>
1073     * @see #setTransform
1074     * @see AffineTransform
1075     */

1076    public abstract void transform(AffineTransform JavaDoc Tx);
1077
1078    /**
1079     * Overwrites the Transform in the <code>Graphics2D</code> context.
1080     * WARNING: This method should <b>never</b> be used to apply a new
1081     * coordinate transform on top of an existing transform because the
1082     * <code>Graphics2D</code> might already have a transform that is
1083     * needed for other purposes, such as rendering Swing
1084     * components or applying a scaling transformation to adjust for the
1085     * resolution of a printer.
1086     * <p>To add a coordinate transform, use the
1087     * <code>transform</code>, <code>rotate</code>, <code>scale</code>,
1088     * or <code>shear</code> methods. The <code>setTransform</code>
1089     * method is intended only for restoring the original
1090     * <code>Graphics2D</code> transform after rendering, as shown in this
1091     * example:
1092     * <pre><blockquote>
1093     * // Get the current transform
1094     * AffineTransform saveAT = g2.getTransform();
1095     * // Perform transformation
1096     * g2d.transform(...);
1097     * // Render
1098     * g2d.draw(...);
1099     * // Restore original transform
1100     * g2d.setTransform(saveAT);
1101     * </blockquote></pre>
1102     *
1103     * @param Tx the <code>AffineTransform</code> that was retrieved
1104     * from the <code>getTransform</code> method
1105     * @see #transform
1106     * @see #getTransform
1107     * @see AffineTransform
1108     */

1109    public abstract void setTransform(AffineTransform JavaDoc Tx);
1110
1111    /**
1112     * Returns a copy of the current <code>Transform</code> in the
1113     * <code>Graphics2D</code> context.
1114     * @return the current <code>AffineTransform</code> in the
1115     * <code>Graphics2D</code> context.
1116     * @see #transform
1117     * @see #setTransform
1118     */

1119    public abstract AffineTransform JavaDoc getTransform();
1120
1121    /**
1122     * Returns the current <code>Paint</code> of the
1123     * <code>Graphics2D</code> context.
1124     * @return the current <code>Graphics2D</code> <code>Paint</code>,
1125     * which defines a color or pattern.
1126     * @see #setPaint
1127     * @see java.awt.Graphics#setColor
1128     */

1129    public abstract Paint JavaDoc getPaint();
1130
1131    /**
1132     * Returns the current <code>Composite</code> in the
1133     * <code>Graphics2D</code> context.
1134     * @return the current <code>Graphics2D</code> <code>Composite</code>,
1135     * which defines a compositing style.
1136     * @see #setComposite
1137     */

1138    public abstract Composite JavaDoc getComposite();
1139
1140    /**
1141     * Sets the background color for the <code>Graphics2D</code> context.
1142     * The background color is used for clearing a region.
1143     * When a <code>Graphics2D</code> is constructed for a
1144     * <code>Component</code>, the background color is
1145     * inherited from the <code>Component</code>. Setting the background color
1146     * in the <code>Graphics2D</code> context only affects the subsequent
1147     * <code>clearRect</code> calls and not the background color of the
1148     * <code>Component</code>. To change the background
1149     * of the <code>Component</code>, use appropriate methods of
1150     * the <code>Component</code>.
1151     * @param color the background color that isused in
1152     * subsequent calls to <code>clearRect</code>
1153     * @see #getBackground
1154     * @see java.awt.Graphics#clearRect
1155     */

1156    public abstract void setBackground(Color JavaDoc color);
1157
1158    /**
1159     * Returns the background color used for clearing a region.
1160     * @return the current <code>Graphics2D</code> <code>Color</code>,
1161     * which defines the background color.
1162     * @see #setBackground
1163     */

1164    public abstract Color JavaDoc getBackground();
1165
1166    /**
1167     * Returns the current <code>Stroke</code> in the
1168     * <code>Graphics2D</code> context.
1169     * @return the current <code>Graphics2D</code> <code>Stroke</code>,
1170     * which defines the line style.
1171     * @see #setStroke
1172     */

1173    public abstract Stroke JavaDoc getStroke();
1174
1175    /**
1176     * Intersects the current <code>Clip</code> with the interior of the
1177     * specified <code>Shape</code> and sets the <code>Clip</code> to the
1178     * resulting intersection. The specified <code>Shape</code> is
1179     * transformed with the current <code>Graphics2D</code>
1180     * <code>Transform</code> before being intersected with the current
1181     * <code>Clip</code>. This method is used to make the current
1182     * <code>Clip</code> smaller.
1183     * To make the <code>Clip</code> larger, use <code>setClip</code>.
1184     * The <i>user clip</i> modified by this method is independent of the
1185     * clipping associated with device bounds and visibility. If no clip has
1186     * previously been set, or if the clip has been cleared using
1187     * {@link Graphics#setClip(Shape) setClip} with a <code>null</code>
1188     * argument, the specified <code>Shape</code> becomes the new
1189     * user clip.
1190     * @param s the <code>Shape</code> to be intersected with the current
1191     * <code>Clip</code>. If <code>s</code> is <code>null</code>,
1192     * this method clears the current <code>Clip</code>.
1193     */

1194     public abstract void clip(Shape JavaDoc s);
1195
1196     /**
1197     * Get the rendering context of the <code>Font</code> within this
1198     * <code>Graphics2D</code> context.
1199     * The {@link FontRenderContext}
1200     * encapsulates application hints such as anti-aliasing and
1201     * fractional metrics, as well as target device specific information
1202     * such as dots-per-inch. This information should be provided by the
1203     * application when using objects that perform typographical
1204     * formatting, such as <code>Font</code> and
1205     * <code>TextLayout</code>. This information should also be provided
1206     * by applications that perform their own layout and need accurate
1207     * measurements of various characteristics of glyphs such as advance
1208     * and line height when various rendering hints have been applied to
1209     * the text rendering.
1210     *
1211     * @return a reference to an instance of FontRenderContext.
1212     * @see java.awt.font.FontRenderContext
1213     * @see java.awt.Font#createGlyphVector
1214     * @see java.awt.font.TextLayout
1215     * @since 1.2
1216     */

1217
1218    public abstract FontRenderContext JavaDoc getFontRenderContext();
1219
1220}
1221
Popular Tags