KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > ext > awt > g2d > AbstractGraphics2D


1 /*
2
3    Copyright 2001,2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.ext.awt.g2d;
19
20 import java.awt.AlphaComposite JavaDoc;
21 import java.awt.Color JavaDoc;
22 import java.awt.Composite JavaDoc;
23 import java.awt.Font JavaDoc;
24 import java.awt.Graphics2D JavaDoc;
25 import java.awt.Image JavaDoc;
26 import java.awt.Paint JavaDoc;
27 import java.awt.Polygon JavaDoc;
28 import java.awt.Rectangle JavaDoc;
29 import java.awt.RenderingHints JavaDoc;
30 import java.awt.Shape JavaDoc;
31 import java.awt.Stroke JavaDoc;
32 import java.awt.font.FontRenderContext JavaDoc;
33 import java.awt.font.GlyphVector JavaDoc;
34 import java.awt.geom.AffineTransform JavaDoc;
35 import java.awt.geom.Arc2D JavaDoc;
36 import java.awt.geom.Ellipse2D JavaDoc;
37 import java.awt.geom.GeneralPath JavaDoc;
38 import java.awt.geom.Line2D JavaDoc;
39 import java.awt.geom.NoninvertibleTransformException JavaDoc;
40 import java.awt.geom.RoundRectangle2D JavaDoc;
41 import java.awt.image.BufferedImage JavaDoc;
42 import java.awt.image.BufferedImageOp JavaDoc;
43 import java.awt.image.ImageObserver JavaDoc;
44 import java.text.AttributedCharacterIterator JavaDoc;
45 import java.util.Map JavaDoc;
46
47 /**
48  * This extension of the <tt>java.awt.Graphics2D</tt> abstract class
49  * is still abstract, but it implements a lot of the <tt>Graphics2D</tt>
50  * method in a way that concrete implementations can reuse.
51  *
52  * This class uses a <tt>GraphicContext</tt> to store the state of
53  * its various attributes that control the rendering, such as the
54  * current <tt>Font</tt>, <tt>Paint</tt> or clip.
55  *
56  * Concrete implementations can focus on implementing the rendering
57  * methods, such as <tt>drawShape</tt>. As a convenience, rendering
58  * methods that can be expressed with other rendering methods (e.g.,
59  * <tt>drawRect</tt> can be expressed as <tt>draw(new Rectangle(..))</tt>),
60  * are implemented by <tt>AbstractGraphics2D</tt>
61  *
62  * @author <a HREF="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
63  * @version $Id: AbstractGraphics2D.java,v 1.10 2005/04/02 12:58:17 deweese Exp $
64  * @see org.apache.batik.ext.awt.g2d.GraphicContext
65  */

66 public abstract class AbstractGraphics2D extends Graphics2D JavaDoc implements Cloneable JavaDoc {
67     /**
68      * Current state of the Graphic Context. The GraphicsContext
69      * class manages the state of this <tt>Graphics2D</tt> graphic context
70      * attributes.
71      */

72     protected GraphicContext gc;
73
74     /**
75      * Text handling strategy.
76      */

77     protected boolean textAsShapes = false;
78
79     /**
80      * @param textAsShapes if true, all text is turned into shapes in the
81      * convertion. No text is output.
82      *
83      */

84     public AbstractGraphics2D(boolean textAsShapes){
85         this.textAsShapes = textAsShapes;
86     }
87
88     /**
89      * This private constructor is used in create
90      *
91      * @see #create
92      */

93     public AbstractGraphics2D(AbstractGraphics2D g){
94         this.gc = (GraphicContext)g.gc.clone();
95         this.gc.validateTransformStack();
96         this.textAsShapes = g.textAsShapes;
97     }
98
99     /**
100      * Translates the origin of the graphics context to the point
101      * (<i>x</i>,&nbsp;<i>y</i>) in the current coordinate system.
102      * Modifies this graphics context so that its new origin corresponds
103      * to the point (<i>x</i>,&nbsp;<i>y</i>) in this graphics context's
104      * original coordinate system. All coordinates used in subsequent
105      * rendering operations on this graphics context will be relative
106      * to this new origin.
107      * @param x the <i>x</i> coordinate.
108      * @param y the <i>y</i> coordinate.
109      */

110     public void translate(int x, int y){
111         gc.translate(x, y);
112     }
113
114     /**
115      * Gets this graphics context's current color.
116      * @return this graphics context's current color.
117      * @see java.awt.Color
118      * @see java.awt.Graphics#setColor
119      */

120     public Color JavaDoc getColor(){
121         return gc.getColor();
122     }
123
124     /**
125      * Sets this graphics context's current color to the specified
126      * color. All subsequent graphics operations using this graphics
127      * context use this specified color.
128      * @param c the new rendering color.
129      * @see java.awt.Color
130      * @see java.awt.Graphics#getColor
131      */

132     public void setColor(Color JavaDoc c){
133         gc.setColor(c);
134     }
135
136     /**
137      * Sets the paint mode of this graphics context to overwrite the
138      * destination with this graphics context's current color.
139      * This sets the logical pixel operation function to the paint or
140      * overwrite mode. All subsequent rendering operations will
141      * overwrite the destination with the current color.
142      */

143     public void setPaintMode(){
144         gc.setComposite(AlphaComposite.SrcOver);
145     }
146
147     /**
148      * Gets the current font.
149      * @return this graphics context's current font.
150      * @see java.awt.Font
151      * @see java.awt.Graphics#setFont
152      */

153     public Font JavaDoc getFont(){
154         return gc.getFont();
155     }
156
157     /**
158      * Sets this graphics context's font to the specified font.
159      * All subsequent text operations using this graphics context
160      * use this font.
161      * @param font the font.
162      * @see java.awt.Graphics#getFont
163      */

164     public void setFont(Font JavaDoc font){
165         gc.setFont(font);
166     }
167
168     /**
169      * Returns the bounding rectangle of the current clipping area.
170      * This method refers to the user clip, which is independent of the
171      * clipping associated with device bounds and window visibility.
172      * If no clip has previously been set, or if the clip has been
173      * cleared using <code>setClip(null)</code>, this method returns
174      * <code>null</code>.
175      * The coordinates in the rectangle are relative to the coordinate
176      * system origin of this graphics context.
177      * @return the bounding rectangle of the current clipping area,
178      * or <code>null</code> if no clip is set.
179      * @see java.awt.Graphics#getClip
180      * @see java.awt.Graphics#clipRect
181      * @see java.awt.Graphics#setClip(int, int, int, int)
182      * @see java.awt.Graphics#setClip(Shape)
183      * @since JDK1.1
184      */

185     public Rectangle JavaDoc getClipBounds(){
186         return gc.getClipBounds();
187     }
188
189
190     /**
191      * Intersects the current clip with the specified rectangle.
192      * The resulting clipping area is the intersection of the current
193      * clipping area and the specified rectangle. If there is no
194      * current clipping area, either because the clip has never been
195      * set, or the clip has been cleared using <code>setClip(null)</code>,
196      * the specified rectangle becomes the new clip.
197      * This method sets the user clip, which is independent of the
198      * clipping associated with device bounds and window visibility.
199      * This method can only be used to make the current clip smaller.
200      * To set the current clip larger, use any of the setClip methods.
201      * Rendering operations have no effect outside of the clipping area.
202      * @param x the x coordinate of the rectangle to intersect the clip with
203      * @param y the y coordinate of the rectangle to intersect the clip with
204      * @param width the width of the rectangle to intersect the clip with
205      * @param height the height of the rectangle to intersect the clip with
206      * @see #setClip(int, int, int, int)
207      * @see #setClip(Shape)
208      */

209     public void clipRect(int x, int y, int width, int height){
210         gc.clipRect(x, y, width, height);
211     }
212
213
214     /**
215      * Sets the current clip to the rectangle specified by the given
216      * coordinates. This method sets the user clip, which is
217      * independent of the clipping associated with device bounds
218      * and window visibility.
219      * Rendering operations have no effect outside of the clipping area.
220      * @param x the <i>x</i> coordinate of the new clip rectangle.
221      * @param y the <i>y</i> coordinate of the new clip rectangle.
222      * @param width the width of the new clip rectangle.
223      * @param height the height of the new clip rectangle.
224      * @see java.awt.Graphics#clipRect
225      * @see java.awt.Graphics#setClip(Shape)
226      * @since JDK1.1
227      */

228     public void setClip(int x, int y, int width, int height){
229         gc.setClip(x, y, width, height);
230     }
231
232
233     /**
234      * Gets the current clipping area.
235      * This method returns the user clip, which is independent of the
236      * clipping associated with device bounds and window visibility.
237      * If no clip has previously been set, or if the clip has been
238      * cleared using <code>setClip(null)</code>, this method returns
239      * <code>null</code>.
240      * @return a <code>Shape</code> object representing the
241      * current clipping area, or <code>null</code> if
242      * no clip is set.
243      * @see java.awt.Graphics#getClipBounds
244      * @see java.awt.Graphics#clipRect
245      * @see java.awt.Graphics#setClip(int, int, int, int)
246      * @see java.awt.Graphics#setClip(Shape)
247      * @since JDK1.1
248      */

249     public Shape JavaDoc getClip(){
250         return gc.getClip();
251     }
252
253
254     /**
255      * Sets the current clipping area to an arbitrary clip shape.
256      * Not all objects that implement the <code>Shape</code>
257      * interface can be used to set the clip. The only
258      * <code>Shape</code> objects that are guaranteed to be
259      * supported are <code>Shape</code> objects that are
260      * obtained via the <code>getClip</code> method and via
261      * <code>Rectangle</code> objects. This method sets the
262      * user clip, which is independent of the clipping associated
263      * with device bounds and window visibility.
264      * @param clip the <code>Shape</code> to use to set the clip
265      * @see java.awt.Graphics#getClip()
266      * @see java.awt.Graphics#clipRect
267      * @see java.awt.Graphics#setClip(int, int, int, int)
268      * @since JDK1.1
269      */

270     public void setClip(Shape JavaDoc clip){
271         gc.setClip(clip);
272     }
273
274
275     /**
276      * Draws a line, using the current color, between the points
277      * <code>(x1,&nbsp;y1)</code> and <code>(x2,&nbsp;y2)</code>
278      * in this graphics context's coordinate system.
279      * @param x1 the first point's <i>x</i> coordinate.
280      * @param y1 the first point's <i>y</i> coordinate.
281      * @param x2 the second point's <i>x</i> coordinate.
282      * @param y2 the second point's <i>y</i> coordinate.
283      */

284     public void drawLine(int x1, int y1, int x2, int y2){
285         Line2D JavaDoc line = new Line2D.Float JavaDoc(x1, y1, x2, y2);
286         draw(line);
287     }
288
289
290     /**
291      * Fills the specified rectangle.
292      * The left and right edges of the rectangle are at
293      * <code>x</code> and <code>x&nbsp;+&nbsp;width&nbsp;-&nbsp;1</code>.
294      * The top and bottom edges are at
295      * <code>y</code> and <code>y&nbsp;+&nbsp;height&nbsp;-&nbsp;1</code>.
296      * The resulting rectangle covers an area
297      * <code>width</code> pixels wide by
298      * <code>height</code> pixels tall.
299      * The rectangle is filled using the graphics context's current color.
300      * @param x the <i>x</i> coordinate
301      * of the rectangle to be filled.
302      * @param y the <i>y</i> coordinate
303      * of the rectangle to be filled.
304      * @param width the width of the rectangle to be filled.
305      * @param height the height of the rectangle to be filled.
306      * @see java.awt.Graphics#clearRect
307      * @see java.awt.Graphics#drawRect
308      */

309     public void fillRect(int x, int y, int width, int height){
310         Rectangle JavaDoc rect = new Rectangle JavaDoc(x, y, width, height);
311         fill(rect);
312     }
313
314     public void drawRect(int x, int y, int width, int height){
315         Rectangle JavaDoc rect = new Rectangle JavaDoc(x, y, width, height);
316         draw(rect);
317     }
318
319
320
321     /**
322      * Clears the specified rectangle by filling it with the background
323      * color of the current drawing surface. This operation does not
324      * use the current paint mode.
325      * <p>
326      * Beginning with Java&nbsp;1.1, the background color
327      * of offscreen images may be system dependent. Applications should
328      * use <code>setColor</code> followed by <code>fillRect</code> to
329      * ensure that an offscreen image is cleared to a specific color.
330      * @param x the <i>x</i> coordinate of the rectangle to clear.
331      * @param y the <i>y</i> coordinate of the rectangle to clear.
332      * @param width the width of the rectangle to clear.
333      * @param height the height of the rectangle to clear.
334      * @see java.awt.Graphics#fillRect(int, int, int, int)
335      * @see java.awt.Graphics#drawRect
336      * @see java.awt.Graphics#setColor(java.awt.Color)
337      * @see java.awt.Graphics#setPaintMode
338      * @see java.awt.Graphics#setXORMode(java.awt.Color)
339      */

340     public void clearRect(int x, int y, int width, int height){
341         Paint JavaDoc paint = gc.getPaint();
342         gc.setColor(gc.getBackground());
343         fillRect(x, y, width, height);
344         gc.setPaint(paint);
345     }
346
347     /**
348      * Draws an outlined round-cornered rectangle using this graphics
349      * context's current color. The left and right edges of the rectangle
350      * are at <code>x</code> and <code>x&nbsp;+&nbsp;width</code>,
351      * respectively. The top and bottom edges of the rectangle are at
352      * <code>y</code> and <code>y&nbsp;+&nbsp;height</code>.
353      * @param x the <i>x</i> coordinate of the rectangle to be drawn.
354      * @param y the <i>y</i> coordinate of the rectangle to be drawn.
355      * @param width the width of the rectangle to be drawn.
356      * @param height the height of the rectangle to be drawn.
357      * @param arcWidth the horizontal diameter of the arc
358      * at the four corners.
359      * @param arcHeight the vertical diameter of the arc
360      * at the four corners.
361      * @see java.awt.Graphics#fillRoundRect
362      */

363     public void drawRoundRect(int x, int y, int width, int height,
364                               int arcWidth, int arcHeight){
365         RoundRectangle2D JavaDoc rect = new RoundRectangle2D.Float JavaDoc(x, y, width, height, arcWidth, arcHeight);
366         draw(rect);
367     }
368
369
370     /**
371      * Fills the specified rounded corner rectangle with the current color.
372      * The left and right edges of the rectangle
373      * are at <code>x</code> and <code>x&nbsp;+&nbsp;width&nbsp;-&nbsp;1</code>,
374      * respectively. The top and bottom edges of the rectangle are at
375      * <code>y</code> and <code>y&nbsp;+&nbsp;height&nbsp;-&nbsp;1</code>.
376      * @param x the <i>x</i> coordinate of the rectangle to be filled.
377      * @param y the <i>y</i> coordinate of the rectangle to be filled.
378      * @param width the width of the rectangle to be filled.
379      * @param height the height of the rectangle to be filled.
380      * @param arcWidth the horizontal diameter
381      * of the arc at the four corners.
382      * @param arcHeight the vertical diameter
383      * of the arc at the four corners.
384      * @see java.awt.Graphics#drawRoundRect
385      */

386     public void fillRoundRect(int x, int y, int width, int height,
387                               int arcWidth, int arcHeight){
388         RoundRectangle2D JavaDoc rect = new RoundRectangle2D.Float JavaDoc(x, y, width, height, arcWidth, arcHeight);
389         fill(rect);
390     }
391
392
393     /**
394      * Draws the outline of an oval.
395      * The result is a circle or ellipse that fits within the
396      * rectangle specified by the <code>x</code>, <code>y</code>,
397      * <code>width</code>, and <code>height</code> arguments.
398      * <p>
399      * The oval covers an area that is
400      * <code>width&nbsp;+&nbsp;1</code> pixels wide
401      * and <code>height&nbsp;+&nbsp;1</code> pixels tall.
402      * @param x the <i>x</i> coordinate of the upper left
403      * corner of the oval to be drawn.
404      * @param y the <i>y</i> coordinate of the upper left
405      * corner of the oval to be drawn.
406      * @param width the width of the oval to be drawn.
407      * @param height the height of the oval to be drawn.
408      * @see java.awt.Graphics#fillOval
409      */

410     public void drawOval(int x, int y, int width, int height){
411         Ellipse2D JavaDoc oval = new Ellipse2D.Float JavaDoc(x, y, width, height);
412         draw(oval);
413     }
414
415
416     /**
417      * Fills an oval bounded by the specified rectangle with the
418      * current color.
419      * @param x the <i>x</i> coordinate of the upper left corner
420      * of the oval to be filled.
421      * @param y the <i>y</i> coordinate of the upper left corner
422      * of the oval to be filled.
423      * @param width the width of the oval to be filled.
424      * @param height the height of the oval to be filled.
425      * @see java.awt.Graphics#drawOval
426      */

427     public void fillOval(int x, int y, int width, int height){
428         Ellipse2D JavaDoc oval = new Ellipse2D.Float JavaDoc(x, y, width, height);
429         fill(oval);
430     }
431
432
433     /**
434      * Draws the outline of a circular or elliptical arc
435      * covering the specified rectangle.
436      * <p>
437      * The resulting arc begins at <code>startAngle</code> and extends
438      * for <code>arcAngle</code> degrees, using the current color.
439      * Angles are interpreted such that 0&nbsp;degrees
440      * is at the 3&nbsp;o'clock position.
441      * A positive value indicates a counter-clockwise rotation
442      * while a negative value indicates a clockwise rotation.
443      * <p>
444      * The center of the arc is the center of the rectangle whose origin
445      * is (<i>x</i>,&nbsp;<i>y</i>) and whose size is specified by the
446      * <code>width</code> and <code>height</code> arguments.
447      * <p>
448      * The resulting arc covers an area
449      * <code>width&nbsp;+&nbsp;1</code> pixels wide
450      * by <code>height&nbsp;+&nbsp;1</code> pixels tall.
451      * <p>
452      * The angles are specified relative to the non-square extents of
453      * the bounding rectangle such that 45 degrees always falls on the
454      * line from the center of the ellipse to the upper right corner of
455      * the bounding rectangle. As a result, if the bounding rectangle is
456      * noticeably longer in one axis than the other, the angles to the
457      * start and end of the arc segment will be skewed farther along the
458      * longer axis of the bounds.
459      * @param x the <i>x</i> coordinate of the
460      * upper-left corner of the arc to be drawn.
461      * @param y the <i>y</i> coordinate of the
462      * upper-left corner of the arc to be drawn.
463      * @param width the width of the arc to be drawn.
464      * @param height the height of the arc to be drawn.
465      * @param startAngle the beginning angle.
466      * @param arcAngle the angular extent of the arc,
467      * relative to the start angle.
468      * @see java.awt.Graphics#fillArc
469      */

470     public void drawArc(int x, int y, int width, int height,
471                         int startAngle, int arcAngle){
472         Arc2D JavaDoc arc = new Arc2D.Float JavaDoc(x, y, width, height, startAngle, arcAngle, Arc2D.OPEN);
473         draw(arc);
474     }
475
476
477     /**
478      * Fills a circular or elliptical arc covering the specified rectangle.
479      * <p>
480      * The resulting arc begins at <code>startAngle</code> and extends
481      * for <code>arcAngle</code> degrees.
482      * Angles are interpreted such that 0&nbsp;degrees
483      * is at the 3&nbsp;o'clock position.
484      * A positive value indicates a counter-clockwise rotation
485      * while a negative value indicates a clockwise rotation.
486      * <p>
487      * The center of the arc is the center of the rectangle whose origin
488      * is (<i>x</i>,&nbsp;<i>y</i>) and whose size is specified by the
489      * <code>width</code> and <code>height</code> arguments.
490      * <p>
491      * The resulting arc covers an area
492      * <code>width&nbsp;+&nbsp;1</code> pixels wide
493      * by <code>height&nbsp;+&nbsp;1</code> pixels tall.
494      * <p>
495      * The angles are specified relative to the non-square extents of
496      * the bounding rectangle such that 45 degrees always falls on the
497      * line from the center of the ellipse to the upper right corner of
498      * the bounding rectangle. As a result, if the bounding rectangle is
499      * noticeably longer in one axis than the other, the angles to the
500      * start and end of the arc segment will be skewed farther along the
501      * longer axis of the bounds.
502      * @param x the <i>x</i> coordinate of the
503      * upper-left corner of the arc to be filled.
504      * @param y the <i>y</i> coordinate of the
505      * upper-left corner of the arc to be filled.
506      * @param width the width of the arc to be filled.
507      * @param height the height of the arc to be filled.
508      * @param startAngle the beginning angle.
509      * @param arcAngle the angular extent of the arc,
510      * relative to the start angle.
511      * @see java.awt.Graphics#drawArc
512      */

513     public void fillArc(int x, int y, int width, int height,
514                         int startAngle, int arcAngle){
515         Arc2D JavaDoc arc = new Arc2D.Float JavaDoc(x, y, width, height, startAngle, arcAngle, Arc2D.PIE);
516         fill(arc);
517     }
518
519
520     /**
521      * Draws a sequence of connected lines defined by
522      * arrays of <i>x</i> and <i>y</i> coordinates.
523      * Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines a point.
524      * The figure is not closed if the first point
525      * differs from the last point.
526      * @param xPoints an array of <i>x</i> points
527      * @param yPoints an array of <i>y</i> points
528      * @param nPoints the total number of points
529      * @see java.awt.Graphics#drawPolygon(int[], int[], int)
530      * @since JDK1.1
531      */

532     public void drawPolyline(int xPoints[], int yPoints[],
533                              int nPoints){
534         if(nPoints > 0){
535             GeneralPath JavaDoc path = new GeneralPath JavaDoc();
536             path.moveTo(xPoints[0], yPoints[0]);
537             for(int i=1; i<nPoints; i++)
538                 path.lineTo(xPoints[i], yPoints[i]);
539
540             draw(path);
541         }
542     }
543
544     /**
545      * Draws a closed polygon defined by
546      * arrays of <i>x</i> and <i>y</i> coordinates.
547      * Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines a point.
548      * <p>
549      * This method draws the polygon defined by <code>nPoint</code> line
550      * segments, where the first <code>nPoint&nbsp;-&nbsp;1</code>
551      * line segments are line segments from
552      * <code>(xPoints[i&nbsp;-&nbsp;1],&nbsp;yPoints[i&nbsp;-&nbsp;1])</code>
553      * to <code>(xPoints[i],&nbsp;yPoints[i])</code>, for
554      * 1&nbsp;&le;&nbsp;<i>i</i>&nbsp;&le;&nbsp;<code>nPoints</code>.
555      * The figure is automatically closed by drawing a line connecting
556      * the final point to the first point, if those points are different.
557      * @param xPoints a an array of <code>x</code> coordinates.
558      * @param yPoints a an array of <code>y</code> coordinates.
559      * @param nPoints a the total number of points.
560      * @see java.awt.Graphics#fillPolygon
561      * @see java.awt.Graphics#drawPolyline
562      */

563     public void drawPolygon(int xPoints[], int yPoints[],
564                             int nPoints){
565         Polygon JavaDoc polygon = new Polygon JavaDoc(xPoints, yPoints, nPoints);
566         draw(polygon);
567     }
568
569
570     /**
571      * Fills a closed polygon defined by
572      * arrays of <i>x</i> and <i>y</i> coordinates.
573      * <p>
574      * This method draws the polygon defined by <code>nPoint</code> line
575      * segments, where the first <code>nPoint&nbsp;-&nbsp;1</code>
576      * line segments are line segments from
577      * <code>(xPoints[i&nbsp;-&nbsp;1],&nbsp;yPoints[i&nbsp;-&nbsp;1])</code>
578      * to <code>(xPoints[i],&nbsp;yPoints[i])</code>, for
579      * 1&nbsp;&le;&nbsp;<i>i</i>&nbsp;&le;&nbsp;<code>nPoints</code>.
580      * The figure is automatically closed by drawing a line connecting
581      * the final point to the first point, if those points are different.
582      * <p>
583      * The area inside the polygon is defined using an
584      * even-odd fill rule, also known as the alternating rule.
585      * @param xPoints a an array of <code>x</code> coordinates.
586      * @param yPoints a an array of <code>y</code> coordinates.
587      * @param nPoints a the total number of points.
588      * @see java.awt.Graphics#drawPolygon(int[], int[], int)
589      */

590     public void fillPolygon(int xPoints[], int yPoints[],
591                             int nPoints){
592         Polygon JavaDoc polygon = new Polygon JavaDoc(xPoints, yPoints, nPoints);
593         fill(polygon);
594     }
595
596     /**
597      * Draws the text given by the specified string, using this
598      * graphics context's current font and color. The baseline of the
599      * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
600      * graphics context's coordinate system.
601      * @param str the string to be drawn.
602      * @param x the <i>x</i> coordinate.
603      * @param y the <i>y</i> coordinate.
604      * @see java.awt.Graphics#drawBytes
605      * @see java.awt.Graphics#drawChars
606      */

607     public void drawString(String JavaDoc str, int x, int y){
608         drawString(str, (float)x, (float)y);
609     }
610
611
612     /**
613      * Draws the text given by the specified iterator, using this
614      * graphics context's current color. The iterator has to specify a font
615      * for each character. The baseline of the
616      * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
617      * graphics context's coordinate system.
618      * @param iterator the iterator whose text is to be drawn
619      * @param x the <i>x</i> coordinate.
620      * @param y the <i>y</i> coordinate.
621      * @see java.awt.Graphics#drawBytes
622      * @see java.awt.Graphics#drawChars
623      */

624     public void drawString(AttributedCharacterIterator JavaDoc iterator,
625                            int x, int y){
626         drawString(iterator, (float)x, (float)y);
627     }
628
629     /**
630      * Draws as much of the specified image as is currently available.
631      * The image is drawn with its top-left corner at
632      * (<i>x</i>,&nbsp;<i>y</i>) in this graphics context's coordinate
633      * space. Transparent pixels are drawn in the specified
634      * background color.
635      * <p>
636      * This operation is equivalent to filling a rectangle of the
637      * width and height of the specified image with the given color and then
638      * drawing the image on top of it, but possibly more efficient.
639      * <p>
640      * This method returns immediately in all cases, even if the
641      * complete image has not yet been loaded, and it has not been dithered
642      * and converted for the current output device.
643      * <p>
644      * If the image has not yet been completely loaded, then
645      * <code>drawImage</code> returns <code>false</code>. As more of
646      * the image becomes available, the process that draws the image notifies
647      * the specified image observer.
648      * @param img the specified image to be drawn.
649      * @param x the <i>x</i> coordinate.
650      * @param y the <i>y</i> coordinate.
651      * @param bgcolor the background color to paint under the
652      * non-opaque portions of the image.
653      * @param observer object to be notified as more of
654      * the image is converted.
655      * @see java.awt.Image
656      * @see java.awt.image.ImageObserver
657      * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
658      */

659     public boolean drawImage(Image JavaDoc img, int x, int y,
660                              Color JavaDoc bgcolor,
661                              ImageObserver JavaDoc observer){
662         return drawImage(img, x, y, img.getWidth(null), img.getHeight(null),
663                          bgcolor, observer);
664     }
665
666
667     /**
668      * Draws as much of the specified image as has already been scaled
669      * to fit inside the specified rectangle.
670      * <p>
671      * The image is drawn inside the specified rectangle of this
672      * graphics context's coordinate space, and is scaled if
673      * necessary. Transparent pixels are drawn in the specified
674      * background color.
675      * This operation is equivalent to filling a rectangle of the
676      * width and height of the specified image with the given color and then
677      * drawing the image on top of it, but possibly more efficient.
678      * <p>
679      * This method returns immediately in all cases, even if the
680      * entire image has not yet been scaled, dithered, and converted
681      * for the current output device.
682      * If the current output representation is not yet complete then
683      * <code>drawImage</code> returns <code>false</code>. As more of
684      * the image becomes available, the process that draws the image notifies
685      * the specified image observer.
686      * <p>
687      * A scaled version of an image will not necessarily be
688      * available immediately just because an unscaled version of the
689      * image has been constructed for this output device. Each size of
690      * the image may be cached separately and generated from the original
691      * data in a separate image production sequence.
692      * @param img the specified image to be drawn.
693      * @param x the <i>x</i> coordinate.
694      * @param y the <i>y</i> coordinate.
695      * @param width the width of the rectangle.
696      * @param height the height of the rectangle.
697      * @param bgcolor the background color to paint under the
698      * non-opaque portions of the image.
699      * @param observer object to be notified as more of
700      * the image is converted.
701      * @see java.awt.Image
702      * @see java.awt.image.ImageObserver
703      * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
704      */

705     public boolean drawImage(Image JavaDoc img, int x, int y,
706                              int width, int height,
707                              Color JavaDoc bgcolor,
708                              ImageObserver JavaDoc observer){
709         Paint JavaDoc paint = gc.getPaint();
710         gc.setPaint(bgcolor);
711         fillRect(x, y, width, height);
712         gc.setPaint(paint);
713         drawImage(img, x, y, width, height, observer);
714
715         return true;
716     }
717
718     /**
719      * Draws as much of the specified area of the specified image as is
720      * currently available, scaling it on the fly to fit inside the
721      * specified area of the destination drawable surface. Transparent pixels
722      * do not affect whatever pixels are already there.
723      * <p>
724      * This method returns immediately in all cases, even if the
725      * image area to be drawn has not yet been scaled, dithered, and converted
726      * for the current output device.
727      * If the current output representation is not yet complete then
728      * <code>drawImage</code> returns <code>false</code>. As more of
729      * the image becomes available, the process that draws the image notifies
730      * the specified image observer.
731      * <p>
732      * This method always uses the unscaled version of the image
733      * to render the scaled rectangle and performs the required
734      * scaling on the fly. It does not use a cached, scaled version
735      * of the image for this operation. Scaling of the image from source
736      * to destination is performed such that the first coordinate
737      * of the source rectangle is mapped to the first coordinate of
738      * the destination rectangle, and the second source coordinate is
739      * mapped to the second destination coordinate. The subimage is
740      * scaled and flipped as needed to preserve those mappings.
741      * @param img the specified image to be drawn
742      * @param dx1 the <i>x</i> coordinate of the first corner of the
743      * destination rectangle.
744      * @param dy1 the <i>y</i> coordinate of the first corner of the
745      * destination rectangle.
746      * @param dx2 the <i>x</i> coordinate of the second corner of the
747      * destination rectangle.
748      * @param dy2 the <i>y</i> coordinate of the second corner of the
749      * destination rectangle.
750      * @param sx1 the <i>x</i> coordinate of the first corner of the
751      * source rectangle.
752      * @param sy1 the <i>y</i> coordinate of the first corner of the
753      * source rectangle.
754      * @param sx2 the <i>x</i> coordinate of the second corner of the
755      * source rectangle.
756      * @param sy2 the <i>y</i> coordinate of the second corner of the
757      * source rectangle.
758      * @param observer object to be notified as more of the image is
759      * scaled and converted.
760      * @see java.awt.Image
761      * @see java.awt.image.ImageObserver
762      * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
763      * @since JDK1.1
764      */

765     public boolean drawImage(Image JavaDoc img,
766                              int dx1, int dy1, int dx2, int dy2,
767                              int sx1, int sy1, int sx2, int sy2,
768                              ImageObserver JavaDoc observer){
769         BufferedImage JavaDoc src = new BufferedImage JavaDoc(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
770         Graphics2D JavaDoc g = src.createGraphics();
771         g.drawImage(img, 0, 0, null);
772         g.dispose();
773
774         src = src.getSubimage(sx1, sy1, sx2-sx1, sy2-sy1);
775
776         return drawImage(src, dx1, dy1, dx2-dx1, dy2-dy1, observer);
777     }
778
779
780     /**
781      * Draws as much of the specified area of the specified image as is
782      * currently available, scaling it on the fly to fit inside the
783      * specified area of the destination drawable surface.
784      * <p>
785      * Transparent pixels are drawn in the specified background color.
786      * This operation is equivalent to filling a rectangle of the
787      * width and height of the specified image with the given color and then
788      * drawing the image on top of it, but possibly more efficient.
789      * <p>
790      * This method returns immediately in all cases, even if the
791      * image area to be drawn has not yet been scaled, dithered, and converted
792      * for the current output device.
793      * If the current output representation is not yet complete then
794      * <code>drawImage</code> returns <code>false</code>. As more of
795      * the image becomes available, the process that draws the image notifies
796      * the specified image observer.
797      * <p>
798      * This method always uses the unscaled version of the image
799      * to render the scaled rectangle and performs the required
800      * scaling on the fly. It does not use a cached, scaled version
801      * of the image for this operation. Scaling of the image from source
802      * to destination is performed such that the first coordinate
803      * of the source rectangle is mapped to the first coordinate of
804      * the destination rectangle, and the second source coordinate is
805      * mapped to the second destination coordinate. The subimage is
806      * scaled and flipped as needed to preserve those mappings.
807      * @param img the specified image to be drawn
808      * @param dx1 the <i>x</i> coordinate of the first corner of the
809      * destination rectangle.
810      * @param dy1 the <i>y</i> coordinate of the first corner of the
811      * destination rectangle.
812      * @param dx2 the <i>x</i> coordinate of the second corner of the
813      * destination rectangle.
814      * @param dy2 the <i>y</i> coordinate of the second corner of the
815      * destination rectangle.
816      * @param sx1 the <i>x</i> coordinate of the first corner of the
817      * source rectangle.
818      * @param sy1 the <i>y</i> coordinate of the first corner of the
819      * source rectangle.
820      * @param sx2 the <i>x</i> coordinate of the second corner of the
821      * source rectangle.
822      * @param sy2 the <i>y</i> coordinate of the second corner of the
823      * source rectangle.
824      * @param bgcolor the background color to paint under the
825      * non-opaque portions of the image.
826      * @param observer object to be notified as more of the image is
827      * scaled and converted.
828      * @see java.awt.Image
829      * @see java.awt.image.ImageObserver
830      * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
831      * @since JDK1.1
832      */

833     public boolean drawImage(Image JavaDoc img,
834                              int dx1, int dy1, int dx2, int dy2,
835                              int sx1, int sy1, int sx2, int sy2,
836                              Color JavaDoc bgcolor,
837                              ImageObserver JavaDoc observer){
838         Paint JavaDoc paint = gc.getPaint();
839         gc.setPaint(bgcolor);
840         fillRect(dx1, dy1, dx2-dx1, dy2-dy1);
841         gc.setPaint(paint);
842         return drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer);
843     }
844
845
846     /**
847      * Renders an image, applying a transform from image space into user space
848      * before drawing.
849      * The transformation from user space into device space is done with
850      * the current <code>Transform</code> in the <code>Graphics2D</code>.
851      * The specified transformation is applied to the image before the
852      * transform attribute in the <code>Graphics2D</code> context is applied.
853      * The rendering attributes applied include the <code>Clip</code>,
854      * <code>Transform</code>, and <code>Composite</code> attributes.
855      * Note that no rendering is done if the specified transform is
856      * noninvertible.
857      * @param img the <code>Image</code> to be rendered
858      * @param xform the transformation from image space into user space
859      * @param obs the {@link ImageObserver}
860      * to be notified as more of the <code>Image</code>
861      * is converted
862      * @return <code>true</code> if the <code>Image</code> is
863      * fully loaded and completely rendered;
864      * <code>false</code> if the <code>Image</code> is still being loaded.
865      * @see #transform
866      * @see #setTransform
867      * @see #setComposite
868      * @see #clip
869      * @see #setClip
870      */

871     public boolean drawImage(Image JavaDoc img,
872                              AffineTransform JavaDoc xform,
873                              ImageObserver JavaDoc obs){
874         boolean retVal = true;
875
876         if(xform.getDeterminant() != 0){
877             AffineTransform JavaDoc inverseTransform = null;
878             try{
879                 inverseTransform = xform.createInverse();
880             } catch(NoninvertibleTransformException JavaDoc e){
881                                 // Should never happen since we checked the
882
// matrix determinant
883
throw new Error JavaDoc();
884             }
885
886             gc.transform(xform);
887             retVal = drawImage(img, 0, 0, null);
888             gc.transform(inverseTransform);
889         }
890         else{
891             AffineTransform JavaDoc savTransform = new AffineTransform JavaDoc(gc.getTransform());
892             gc.transform(xform);
893             retVal = drawImage(img, 0, 0, null);
894             gc.setTransform(savTransform);
895         }
896
897         return retVal;
898
899     }
900
901
902     /**
903      * Renders a <code>BufferedImage</code> that is
904      * filtered with a
905      * {@link BufferedImageOp}.
906      * The rendering attributes applied include the <code>Clip</code>,
907      * <code>Transform</code>
908      * and <code>Composite</code> attributes. This is equivalent to:
909      * <pre>
910      * img1 = op.filter(img, null);
911      * drawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null);
912      * </pre>
913      * @param img the <code>BufferedImage</code> to be rendered
914      * @param op the filter to be applied to the image before rendering
915      * @param x the x coordinate in user space where the image is rendered
916      * @param y the y coordinate in user space where the image is rendered
917      * @see #transform
918      * @see #setTransform
919      * @see #setComposite
920      * @see #clip
921      * @see #setClip
922      */

923     public void drawImage(BufferedImage JavaDoc img,
924                           BufferedImageOp JavaDoc op,
925                           int x,
926                           int y){
927         img = op.filter(img, null);
928         drawImage(img, x, y, null);
929     }
930
931
932
933     /**
934      * Renders the text of the specified
935      * {@link GlyphVector} using
936      * the <code>Graphics2D</code> context's rendering attributes.
937      * The rendering attributes applied include the <code>Clip</code>,
938      * <code>Transform</code>, <code>Paint</code>, and
939      * <code>Composite</code> attributes. The <code>GlyphVector</code>
940      * specifies individual glyphs from a {@link Font}.
941      * The <code>GlyphVector</code> can also contain the glyph positions.
942      * This is the fastest way to render a set of characters to the
943      * screen.
944      *
945      * @param g the <code>GlyphVector</code> to be rendered
946      * @param x the x position in user space where the glyphs should be
947      * rendered
948      * @param y the y position in user space where the glyphs should be
949      * rendered
950      *
951      * @see java.awt.Font#createGlyphVector
952      * @see java.awt.font.GlyphVector
953      * @see #setPaint
954      * @see java.awt.Graphics#setColor
955      * @see #setTransform
956      * @see #setComposite
957      * @see #setClip
958      */

959     public void drawGlyphVector(GlyphVector JavaDoc g, float x, float y){
960         Shape JavaDoc glyphOutline = g.getOutline(x, y);
961         fill(glyphOutline);
962     }
963
964     /**
965      * Checks whether or not the specified <code>Shape</code> intersects
966      * the specified {@link Rectangle}, which is in device
967      * space. If <code>onStroke</code> is false, this method checks
968      * whether or not the interior of the specified <code>Shape</code>
969      * intersects the specified <code>Rectangle</code>. If
970      * <code>onStroke</code> is <code>true</code>, this method checks
971      * whether or not the <code>Stroke</code> of the specified
972      * <code>Shape</code> outline intersects the specified
973      * <code>Rectangle</code>.
974      * The rendering attributes taken into account include the
975      * <code>Clip</code>, <code>Transform</code>, and <code>Stroke</code>
976      * attributes.
977      * @param rect the area in device space to check for a hit
978      * @param s the <code>Shape</code> to check for a hit
979      * @param onStroke flag used to choose between testing the
980      * stroked or the filled shape. If the flag is <code>true</code>, the
981      * <code>Stroke</code> oultine is tested. If the flag is
982      * <code>false</code>, the filled <code>Shape</code> is tested.
983      * @return <code>true</code> if there is a hit; <code>false</code>
984      * otherwise.
985      * @see #setStroke
986      * @see #fill
987      * @see #draw
988      * @see #transform
989      * @see #setTransform
990      * @see #clip
991      * @see #setClip
992      */

993     public boolean hit(Rectangle JavaDoc rect,
994                        Shape JavaDoc s,
995                        boolean onStroke){
996         if (onStroke) {
997             s = gc.getStroke().createStrokedShape(s);
998         }
999
1000        s = gc.getTransform().createTransformedShape(s);
1001
1002        return s.intersects(rect);
1003    }
1004
1005    /**
1006     * Sets the <code>Composite</code> for the <code>Graphics2D</code> context.
1007     * The <code>Composite</code> is used in all drawing methods such as
1008     * <code>drawImage</code>, <code>drawString</code>, <code>draw</code>,
1009     * and <code>fill</code>. It specifies how new pixels are to be combined
1010     * with the existing pixels on the graphics device during the rendering
1011     * process.
1012     * <p>If this <code>Graphics2D</code> context is drawing to a
1013     * <code>Component</code> on the display screen and the
1014     * <code>Composite</code> is a custom object rather than an
1015     * instance of the <code>AlphaComposite</code> class, and if
1016     * there is a security manager, its <code>checkPermission</code>
1017     * method is called with an <code>AWTPermission("readDisplayPixels")</code>
1018     * permission.
1019     * @throws SecurityException
1020     * if a custom <code>Composite</code> object is being
1021     * used to render to the screen and a security manager
1022     * is set and its <code>checkPermission</code> method
1023     * does not allow the operation.
1024     * @param comp the <code>Composite</code> object to be used for rendering
1025     * @see java.awt.Graphics#setXORMode
1026     * @see java.awt.Graphics#setPaintMode
1027     * @see java.awt.AlphaComposite
1028     */

1029    public void setComposite(Composite JavaDoc comp){
1030        gc.setComposite(comp);
1031    }
1032
1033
1034    /**
1035     * Sets the <code>Paint</code> attribute for the
1036     * <code>Graphics2D</code> context. Calling this method
1037     * with a <code>null</code> <code>Paint</code> object does
1038     * not have any effect on the current <code>Paint</code> attribute
1039     * of this <code>Graphics2D</code>.
1040     * @param paint the <code>Paint</code> object to be used to generate
1041     * color during the rendering process, or <code>null</code>
1042     * @see java.awt.Graphics#setColor
1043     */

1044    public void setPaint(Paint JavaDoc paint) {
1045        gc.setPaint(paint);
1046    }
1047
1048
1049    /**
1050     * Sets the <code>Stroke</code> for the <code>Graphics2D</code> context.
1051     * @param s the <code>Stroke</code> object to be used to stroke a
1052     * <code>Shape</code> during the rendering process
1053     */

1054    public void setStroke(Stroke JavaDoc s){
1055        gc.setStroke(s);
1056    }
1057
1058
1059    /**
1060     * Sets the value of a single preference for the rendering algorithms.
1061     * Hint categories include controls for rendering quality and overall
1062     * time/quality trade-off in the rendering process. Refer to the
1063     * <code>RenderingHints</code> class for definitions of some common
1064     * keys and values.
1065     * @param hintKey the key of the hint to be set.
1066     * @param hintValue the value indicating preferences for the specified
1067     * hint category.
1068     * @see RenderingHints
1069     */

1070    public void setRenderingHint(RenderingHints.Key JavaDoc hintKey, Object JavaDoc hintValue){
1071        gc.setRenderingHint(hintKey, hintValue);
1072    }
1073
1074
1075    /**
1076     * Returns the value of a single preference for the rendering algorithms.
1077     * Hint categories include controls for rendering quality and overall
1078     * time/quality trade-off in the rendering process. Refer to the
1079     * <code>RenderingHints</code> class for definitions of some common
1080     * keys and values.
1081     * @param hintKey the key corresponding to the hint to get.
1082     * @return an object representing the value for the specified hint key.
1083     * Some of the keys and their associated values are defined in the
1084     * <code>RenderingHints</code> class.
1085     * @see RenderingHints
1086     */

1087    public Object JavaDoc getRenderingHint(RenderingHints.Key JavaDoc hintKey){
1088        return gc.getRenderingHint(hintKey);
1089    }
1090
1091
1092    /**
1093     * Replaces the values of all preferences for the rendering
1094     * algorithms with the specified <code>hints</code>.
1095     * The existing values for all rendering hints are discarded and
1096     * the new set of known hints and values are initialized from the
1097     * specified {@link Map} object.
1098     * Hint categories include controls for rendering quality and
1099     * overall time/quality trade-off in the rendering process.
1100     * Refer to the <code>RenderingHints</code> class for definitions of
1101     * some common keys and values.
1102     * @param hints the rendering hints to be set
1103     * @see RenderingHints
1104     */

1105    public void setRenderingHints(Map JavaDoc hints){
1106        gc.setRenderingHints(hints);
1107    }
1108
1109
1110    /**
1111     * Sets the values of an arbitrary number of preferences for the
1112     * rendering algorithms.
1113     * Only values for the rendering hints that are present in the
1114     * specified <code>Map</code> object are modified.
1115     * All other preferences not present in the specified
1116     * object are left unmodified.
1117     * Hint categories include controls for rendering quality and
1118     * overall time/quality trade-off in the rendering process.
1119     * Refer to the <code>RenderingHints</code> class for definitions of
1120     * some common keys and values.
1121     * @param hints the rendering hints to be set
1122     * @see RenderingHints
1123     */

1124    public void addRenderingHints(Map JavaDoc hints){
1125        gc.addRenderingHints(hints);
1126    }
1127
1128
1129    /**
1130     * Gets the preferences for the rendering algorithms. Hint categories
1131     * include controls for rendering quality and overall time/quality
1132     * trade-off in the rendering process.
1133     * Returns all of the hint key/value pairs that were ever specified in
1134     * one operation. Refer to the
1135     * <code>RenderingHints</code> class for definitions of some common
1136     * keys and values.
1137     * @return a reference to an instance of <code>RenderingHints</code>
1138     * that contains the current preferences.
1139     * @see RenderingHints
1140     */

1141    public RenderingHints JavaDoc getRenderingHints(){
1142        return gc.getRenderingHints();
1143    }
1144
1145    /**
1146     * Concatenates the current
1147     * <code>Graphics2D</code> <code>Transform</code>
1148     * with a translation transform.
1149     * Subsequent rendering is translated by the specified
1150     * distance relative to the previous position.
1151     * This is equivalent to calling transform(T), where T is an
1152     * <code>AffineTransform</code> represented by the following matrix:
1153     * <pre>
1154     * [ 1 0 tx ]
1155     * [ 0 1 ty ]
1156     * [ 0 0 1 ]
1157     * </pre>
1158     * @param tx the distance to translate along the x-axis
1159     * @param ty the distance to translate along the y-axis
1160     */

1161    public void translate(double tx, double ty){
1162        gc.translate(tx, ty);
1163    }
1164
1165
1166    /**
1167     * Concatenates the current <code>Graphics2D</code>
1168     * <code>Transform</code> with a rotation transform.
1169     * Subsequent rendering is rotated by the specified radians relative
1170     * to the previous origin.
1171     * This is equivalent to calling <code>transform(R)</code>, where R is an
1172     * <code>AffineTransform</code> represented by the following matrix:
1173     * <pre>
1174     * [ cos(theta) -sin(theta) 0 ]
1175     * [ sin(theta) cos(theta) 0 ]
1176     * [ 0 0 1 ]
1177     * </pre>
1178     * Rotating with a positive angle theta rotates points on the positive
1179     * x axis toward the positive y axis.
1180     * @param theta the angle of rotation in radians
1181     */

1182    public void rotate(double theta){
1183        gc.rotate(theta);
1184    }
1185
1186
1187    /**
1188     * Concatenates the current <code>Graphics2D</code>
1189     * <code>Transform</code> with a translated rotation
1190     * transform. Subsequent rendering is transformed by a transform
1191     * which is constructed by translating to the specified location,
1192     * rotating by the specified radians, and translating back by the same
1193     * amount as the original translation. This is equivalent to the
1194     * following sequence of calls:
1195     * <pre>
1196     * translate(x, y);
1197     * rotate(theta);
1198     * translate(-x, -y);
1199     * </pre>
1200     * Rotating with a positive angle theta rotates points on the positive
1201     * x axis toward the positive y axis.
1202     * @param theta the angle of rotation in radians
1203     * @param x the x coordinate of the origin of the rotation
1204     * @param y the y coordinate of the origin of the rotation
1205     */

1206    public void rotate(double theta, double x, double y){
1207        gc.rotate(theta, x, y);
1208    }
1209
1210
1211    /**
1212     * Concatenates the current <code>Graphics2D</code>
1213     * <code>Transform</code> with a scaling transformation
1214     * Subsequent rendering is resized according to the specified scaling
1215     * factors relative to the previous scaling.
1216     * This is equivalent to calling <code>transform(S)</code>, where S is an
1217     * <code>AffineTransform</code> represented by the following matrix:
1218     * <pre>
1219     * [ sx 0 0 ]
1220     * [ 0 sy 0 ]
1221     * [ 0 0 1 ]
1222     * </pre>
1223     * @param sx the amount by which X coordinates in subsequent
1224     * rendering operations are multiplied relative to previous
1225     * rendering operations.
1226     * @param sy the amount by which Y coordinates in subsequent
1227     * rendering operations are multiplied relative to previous
1228     * rendering operations.
1229     */

1230    public void scale(double sx, double sy){
1231        gc.scale(sx, sy);
1232    }
1233
1234    /**
1235     * Concatenates the current <code>Graphics2D</code>
1236     * <code>Transform</code> with a shearing transform.
1237     * Subsequent renderings are sheared by the specified
1238     * multiplier relative to the previous position.
1239     * This is equivalent to calling <code>transform(SH)</code>, where SH
1240     * is an <code>AffineTransform</code> represented by the following
1241     * matrix:
1242     * <pre>
1243     * [ 1 shx 0 ]
1244     * [ shy 1 0 ]
1245     * [ 0 0 1 ]
1246     * </pre>
1247     * @param shx the multiplier by which coordinates are shifted in
1248     * the positive X axis direction as a function of their Y coordinate
1249     * @param shy the multiplier by which coordinates are shifted in
1250     * the positive Y axis direction as a function of their X coordinate
1251     */

1252    public void shear(double shx, double shy){
1253        gc.shear(shx, shy);
1254    }
1255
1256    /**
1257     * Composes an <code>AffineTransform</code> object with the
1258     * <code>Transform</code> in this <code>Graphics2D</code> according
1259     * to the rule last-specified-first-applied. If the current
1260     * <code>Transform</code> is Cx, the result of composition
1261     * with Tx is a new <code>Transform</code> Cx'. Cx' becomes the
1262     * current <code>Transform</code> for this <code>Graphics2D</code>.
1263     * Transforming a point p by the updated <code>Transform</code> Cx' is
1264     * equivalent to first transforming p by Tx and then transforming
1265     * the result by the original <code>Transform</code> Cx. In other
1266     * words, Cx'(p) = Cx(Tx(p)). A copy of the Tx is made, if necessary,
1267     * so further modifications to Tx do not affect rendering.
1268     * @param Tx the <code>AffineTransform</code> object to be composed with
1269     * the current <code>Transform</code>
1270     * @see #setTransform
1271     * @see AffineTransform
1272     */

1273    public void transform(AffineTransform JavaDoc Tx){
1274        gc.transform(Tx);
1275    }
1276
1277    /**
1278     * Sets the <code>Transform</code> in the <code>Graphics2D</code>
1279     * context.
1280     * @param Tx the <code>AffineTransform</code> object to be used in the
1281     * rendering process
1282     * @see #transform
1283     * @see AffineTransform
1284     */

1285    public void setTransform(AffineTransform JavaDoc Tx){
1286        gc.setTransform(Tx);
1287    }
1288
1289
1290    /**
1291     * Returns a copy of the current <code>Transform</code> in the
1292     * <code>Graphics2D</code> context.
1293     * @return the current <code>AffineTransform</code> in the
1294     * <code>Graphics2D</code> context.
1295     * @see #transform
1296     * @see #setTransform
1297     */

1298    public AffineTransform JavaDoc getTransform(){
1299        return gc.getTransform();
1300    }
1301
1302
1303    /**
1304     * Returns the current <code>Paint</code> of the
1305     * <code>Graphics2D</code> context.
1306     * @return the current <code>Graphics2D</code> <code>Paint</code>,
1307     * which defines a color or pattern.
1308     * @see #setPaint
1309     * @see java.awt.Graphics#setColor
1310     */

1311    public Paint JavaDoc getPaint(){
1312        return gc.getPaint();
1313    }
1314
1315
1316    /**
1317     * Returns the current <code>Composite</code> in the
1318     * <code>Graphics2D</code> context.
1319     * @return the current <code>Graphics2D</code> <code>Composite</code>,
1320     * which defines a compositing style.
1321     * @see #setComposite
1322     */

1323    public Composite JavaDoc getComposite(){
1324        return gc.getComposite();
1325    }
1326
1327
1328    /**
1329     * Sets the background color for the <code>Graphics2D</code> context.
1330     * The background color is used for clearing a region.
1331     * When a <code>Graphics2D</code> is constructed for a
1332     * <code>Component</code>, the background color is
1333     * inherited from the <code>Component</code>. Setting the background color
1334     * in the <code>Graphics2D</code> context only affects the subsequent
1335     * <code>clearRect</code> calls and not the background color of the
1336     * <code>Component</code>. To change the background
1337     * of the <code>Component</code>, use appropriate methods of
1338     * the <code>Component</code>.
1339     * @param color the background color that isused in
1340     * subsequent calls to <code>clearRect</code>
1341     * @see #getBackground
1342     * @see java.awt.Graphics#clearRect
1343     */

1344    public void setBackground(Color JavaDoc color){
1345        gc.setBackground(color);
1346    }
1347
1348
1349    /**
1350     * Returns the background color used for clearing a region.
1351     * @return the current <code>Graphics2D</code> <code>Color</code>,
1352     * which defines the background color.
1353     * @see #setBackground
1354     */

1355    public Color JavaDoc getBackground(){
1356        return gc.getBackground();
1357    }
1358
1359
1360    /**
1361     * Returns the current <code>Stroke</code> in the
1362     * <code>Graphics2D</code> context.
1363     * @return the current <code>Graphics2D</code> <code>Stroke</code>,
1364     * which defines the line style.
1365     * @see #setStroke
1366     */

1367    public Stroke JavaDoc getStroke(){
1368        return gc.getStroke();
1369    }
1370
1371
1372    /**
1373     * Intersects the current <code>Clip</code> with the interior of the
1374     * specified <code>Shape</code> and sets the <code>Clip</code> to the
1375     * resulting intersection. The specified <code>Shape</code> is
1376     * transformed with the current <code>Graphics2D</code>
1377     * <code>Transform</code> before being intersected with the current
1378     * <code>Clip</code>. This method is used to make the current
1379     * <code>Clip</code> smaller.
1380     * To make the <code>Clip</code> larger, use <code>setClip</code>.
1381     * The <i>user clip</i> modified by this method is independent of the
1382     * clipping associated with device bounds and visibility. If no clip has
1383     * previously been set, or if the clip has been cleared using
1384     * {@link java.awt.Graphics#setClip(Shape) setClip} with a
1385     * <code>null</code> argument, the specified <code>Shape</code> becomes
1386     * the new user clip.
1387     * @param s the <code>Shape</code> to be intersected with the current
1388     * <code>Clip</code>. If <code>s</code> is <code>null</code>,
1389     * this method clears the current <code>Clip</code>.
1390     */

1391    public void clip(Shape JavaDoc s){
1392        gc.clip(s);
1393    }
1394
1395
1396    /**
1397     * Get the rendering context of the <code>Font</code> within this
1398     * <code>Graphics2D</code> context.
1399     * The {@link FontRenderContext}
1400     * encapsulates application hints such as anti-aliasing and
1401     * fractional metrics, as well as target device specific information
1402     * such as dots-per-inch. This information should be provided by the
1403     * application when using objects that perform typographical
1404     * formatting, such as <code>Font</code> and
1405     * <code>TextLayout</code>. This information should also be provided
1406     * by applications that perform their own layout and need accurate
1407     * measurements of various characteristics of glyphs such as advance
1408     * and line height when various rendering hints have been applied to
1409     * the text rendering.
1410     *
1411     * @return a reference to an instance of FontRenderContext.
1412     * @see java.awt.font.FontRenderContext
1413     * @see java.awt.Font#createGlyphVector
1414     * @see java.awt.font.TextLayout
1415     * @since JDK1.2
1416     */

1417    public FontRenderContext JavaDoc getFontRenderContext(){
1418        return gc.getFontRenderContext();
1419    }
1420
1421    /**
1422     * @return the {@link GraphicContext} of this <code>Graphics2D</code>.
1423     */

1424    public GraphicContext getGraphicContext() {
1425        return gc;
1426    }
1427}
1428
Popular Tags