149 * to which drawing occurred.
150 */
151 public Spans getDrawingArea() {
152 return mDrawingArea;
153 }
154
155 /**
156 * Returns the device configuration associated with this Graphics2D.
157 */
158 public GraphicsConfiguration getDeviceConfiguration() {
159 return ((RasterPrinterJob)mPrinterJob).getPrinterGraphicsConfig();
160 }
161
162 /* The Delegated Graphics Methods */
163
164 /**
165 * Creates a new <code>Graphics</code> object that is
166 * a copy of this <code>Graphics</code> object.
167 * @return a new graphics context that is a copy of
168 * this graphics context.
169 * @since JDK1.0
170 */
171 public Graphics create() {
172 PeekGraphics newGraphics = null;
173
174 try {
175 newGraphics = (PeekGraphics) clone();
176 newGraphics.mGraphics = (Graphics2D) mGraphics.create();
177
178 /* This exception can not happen unless this
179 * class no longer implements the Cloneable
180 * interface.
181 */
182 } catch (CloneNotSupportedException e) {
183 // can never happen.
184 }
185
186 return newGraphics;
187 }
188
189 /**
190 * Translates the origin of the graphics context to the point
191 * (<i>x</i>, <i>y</i>) in the current coordinate system.
192 * Modifies this graphics context so that its new origin corresponds
193 * to the point (<i>x</i>, <i>y</i>) in this graphics context's
194 * original coordinate system. All coordinates used in subsequent
195 * rendering operations on this graphics context will be relative
196 * to this new origin.
197 * @param x the <i>x</i> coordinate.
198 * @param y the <i>y</i> coordinate.
199 * @since JDK1.0
200 */
201 public void translate(int x, int y) {
202 mGraphics.translate(x, y);
203 }
204
205 /**
206 * Concatenates the current transform of this Graphics2D with a
207 * translation transformation.
208 * This is equivalent to calling transform(T), where T is an
209 * AffineTransform represented by the following matrix:
210 * <pre>
211 * [ 1 0 tx ]
212 * [ 0 1 ty ]
213 * [ 0 0 1 ]
214 * </pre>
215 */
216 public void translate(double tx, double ty) {
217 mGraphics.translate(tx, ty);
218 }
219
276 * AffineTransform represented by the following matrix:
277 * <pre>
278 * [ 1 shx 0 ]
279 * [ shy 1 0 ]
280 * [ 0 0 1 ]
281 * </pre>
282 * @param shx The factor by which coordinates are shifted towards the
283 * positive X axis direction according to their Y coordinate
284 * @param shy The factor by which coordinates are shifted towards the
285 * positive Y axis direction according to their X coordinate
286 */
287 public void shear(double shx, double shy) {
288 mGraphics.shear(shx, shy);
289 }
290
291 /**
292 * Gets this graphics context's current color.
293 * @return this graphics context's current color.
294 * @see java.awt.Color
295 * @see java.awt.Graphics#setColor
296 * @since JDK1.0
297 */
298 public Color getColor() {
299 return mGraphics.getColor();
300 }
301
302 /**
303 * Sets this graphics context's current color to the specified
304 * color. All subsequent graphics operations using this graphics
305 * context use this specified color.
306 * @param c the new rendering color.
307 * @see java.awt.Color
308 * @see java.awt.Graphics#getColor
309 * @since JDK1.0
310 */
311 public void setColor(Color c) {
312 mGraphics.setColor(c);
313 }
314
315 /**
316 * Sets the paint mode of this graphics context to overwrite the
317 * destination with this graphics context's current color.
318 * This sets the logical pixel operation function to the paint or
319 * overwrite mode. All subsequent rendering operations will
320 * overwrite the destination with the current color.
321 * @since JDK1.0
322 */
323 public void setPaintMode() {
324 mGraphics.setPaintMode();
325 }
326
327 /**
328 * Sets the paint mode of this graphics context to alternate between
329 * this graphics context's current color and the new specified color.
330 * This specifies that logical pixel operations are performed in the
331 * XOR mode, which alternates pixels between the current color and
332 * a specified XOR color.
333 * <p>
334 * When drawing operations are performed, pixels which are the
335 * current color are changed to the specified color, and vice versa.
336 * <p>
337 * Pixels that are of colors other than those two colors are changed
338 * in an unpredictable but reversible manner; if the same figure is
339 * drawn twice, then all pixels are restored to their original values.
340 * @param c1 the XOR alternation color
341 * @since JDK1.0
342 */
343 public void setXORMode(Color c1) {
344 mGraphics.setXORMode(c1);
345 }
346
347 /**
348 * Gets the current font.
349 * @return this graphics context's current font.
350 * @see java.awt.Font
351 * @see java.awt.Graphics#setFont
352 * @since JDK1.0
353 */
354 public Font getFont() {
355 return mGraphics.getFont();
356 }
357
358 /**
359 * Sets this graphics context's font to the specified font.
360 * All subsequent text operations using this graphics context
361 * use this font.
362 * @param font the font.
363 * @see java.awt.Graphics#getFont
364 * @see java.awt.Graphics#drawChars(java.lang.String, int, int)
365 * @see java.awt.Graphics#drawString(byte[], int, int, int, int)
366 * @see java.awt.Graphics#drawBytes(char[], int, int, int, int)
367 * @since JDK1.0
368 */
369 public void setFont(Font font) {
370 mGraphics.setFont(font);
371 }
372
373 /**
374 * Gets the font metrics for the specified font.
375 * @return the font metrics for the specified font.
376 * @param f the specified font
377 * @see java.awt.Graphics#getFont
378 * @see java.awt.FontMetrics
379 * @see java.awt.Graphics#getFontMetrics()
380 * @since JDK1.0
381 */
382 public FontMetrics getFontMetrics(Font f) {
383 return mGraphics.getFontMetrics(f);
384 }
385
386 /**
387 * Get the rendering context of the font
388 * within this Graphics2D context.
389 */
390 public FontRenderContext getFontRenderContext() {
391 return mGraphics.getFontRenderContext();
392 }
393
394 /**
395 * Returns the bounding rectangle of the current clipping area.
396 * The coordinates in the rectangle are relative to the coordinate
397 * system origin of this graphics context.
398 * @return the bounding rectangle of the current clipping area.
399 * @see java.awt.Graphics#getClip
400 * @see java.awt.Graphics#clipRect
401 * @see java.awt.Graphics#setClip(int, int, int, int)
402 * @see java.awt.Graphics#setClip(Shape)
403 * @since JDK1.1
404 */
405 public Rectangle getClipBounds() {
406 return mGraphics.getClipBounds();
407 }
408
409
410 /**
411 * Intersects the current clip with the specified rectangle.
412 * The resulting clipping area is the intersection of the current
413 * clipping area and the specified rectangle.
414 * This method can only be used to make the current clip smaller.
415 * To set the current clip larger, use any of the setClip methods.
416 * Rendering operations have no effect outside of the clipping area.
417 * @param x the x coordinate of the rectangle to intersect the clip with
418 * @param y the y coordinate of the rectangle to intersect the clip with
419 * @param width the width of the rectangle to intersect the clip with
420 * @param height the height of the rectangle to intersect the clip with
421 * @see #setClip(int, int, int, int)
422 * @see #setClip(Shape)
423 */
424 public void clipRect(int x, int y, int width, int height) {
425 mGraphics.clipRect(x, y, width, height);
426 }
427
428
429 /**
430 * Sets the current clip to the rectangle specified by the given
431 * coordinates.
432 * Rendering operations have no effect outside of the clipping area.
433 * @param x the <i>x</i> coordinate of the new clip rectangle.
434 * @param y the <i>y</i> coordinate of the new clip rectangle.
435 * @param width the width of the new clip rectangle.
436 * @param height the height of the new clip rectangle.
437 * @see java.awt.Graphics#clipRect
438 * @see java.awt.Graphics#setClip(Shape)
439 * @since JDK1.1
440 */
441 public void setClip(int x, int y, int width, int height) {
442 mGraphics.setClip(x, y, width, height);
443 }
444
445 /**
446 * Gets the current clipping area.
447 * @return a <code>Shape</code> object representing the
448 * current clipping area.
449 * @see java.awt.Graphics#getClipBounds
450 * @see java.awt.Graphics#clipRect
451 * @see java.awt.Graphics#setClip(int, int, int, int)
452 * @see java.awt.Graphics#setClip(Shape)
453 * @since JDK1.1
454 */
455 public Shape getClip() {
456 return mGraphics.getClip();
457 }
458
459
460 /**
461 * Sets the current clipping area to an arbitrary clip shape.
462 * Not all objects which implement the <code>Shape</code>
463 * interface can be used to set the clip. The only
464 * <code>Shape</code> objects which are guaranteed to be
465 * supported are <code>Shape</code> objects which are
466 * obtained via the <code>getClip</code> method and via
467 * <code>Rectangle</code> objects.
468 * @see java.awt.Graphics#getClip()
469 * @see java.awt.Graphics#clipRect
470 * @see java.awt.Graphics#setClip(int, int, int, int)
471 * @since JDK1.1
472 */
473 public void setClip(Shape clip) {
474 mGraphics.setClip(clip);
475 }
476
477
478 /**
479 * Copies an area of the component by a distance specified by
480 * <code>dx</code> and <code>dy</code>. From the point specified
481 * by <code>x</code> and <code>y</code>, this method
482 * copies downwards and to the right. To copy an area of the
483 * component to the left or upwards, specify a negative value for
484 * <code>dx</code> or <code>dy</code>.
485 * If a portion of the source rectangle lies outside the bounds
486 * of the component, or is obscured by another window or component,
487 * <code>copyArea</code> will be unable to copy the associated
488 * pixels. The area that is omitted can be refreshed by calling
489 * the component's <code>paint</code> method.
490 * @param x the <i>x</i> coordinate of the source rectangle.
491 * @param y the <i>y</i> coordinate of the source rectangle.
492 * @param width the width of the source rectangle.
493 * @param height the height of the source rectangle.
494 * @param dx the horizontal distance to copy the pixels.
495 * @param dy the vertical distance to copy the pixels.
496 * @since JDK1.0
497 */
498 public void copyArea(int x, int y, int width, int height,
499 int dx, int dy) {
500 // This method is not supported for printing so we do nothing here.
501 }
502
503 /**
504 * Draws a line, using the current color, between the points
505 * <code>(x1, y1)</code> and <code>(x2, y2)</code>
506 * in this graphics context's coordinate system.
507 * @param x1 the first point's <i>x</i> coordinate.
508 * @param y1 the first point's <i>y</i> coordinate.
509 * @param x2 the second point's <i>x</i> coordinate.
510 * @param y2 the second point's <i>y</i> coordinate.
511 * @since JDK1.0
512 */
513 public void drawLine(int x1, int y1, int x2, int y2) {
514 addStrokeShape(new Line2D.Float(x1, y1, x2, y2));
515 mPrintMetrics.draw(this);
516 }
517
518
519
520 /**
521 * Fills the specified rectangle.
522 * The left and right edges of the rectangle are at
523 * <code>x</code> and <code>x + width - 1</code>.
524 * The top and bottom edges are at
525 * <code>y</code> and <code>y + height - 1</code>.
526 * The resulting rectangle covers an area
527 * <code>width</code> pixels wide by
528 * <code>height</code> pixels tall.
529 * The rectangle is filled using the graphics context's current color.
530 * @param x the <i>x</i> coordinate
531 * of the rectangle to be filled.
532 * @param y the <i>y</i> coordinate
533 * of the rectangle to be filled.
534 * @param width the width of the rectangle to be filled.
535 * @param height the height of the rectangle to be filled.
536 * @see java.awt.Graphics#fillRect
537 * @see java.awt.Graphics#clearRect
538 * @since JDK1.0
539 */
540 public void fillRect(int x, int y, int width, int height) {
541
542 addDrawingRect(new Rectangle2D.Float(x, y, width, height));
543 mPrintMetrics.fill(this);
544
545 }
546
547 /**
548 * Clears the specified rectangle by filling it with the background
549 * color of the current drawing surface. This operation does not
550 * use the current paint mode.
551 * <p>
552 * Beginning with Java 1.1, the background color
553 * of offscreen images may be system dependent. Applications should
554 * use <code>setColor</code> followed by <code>fillRect</code> to
555 * ensure that an offscreen image is cleared to a specific color.
556 * @param x the <i>x</i> coordinate of the rectangle to clear.
557 * @param y the <i>y</i> coordinate of the rectangle to clear.
558 * @param width the width of the rectangle to clear.
559 * @param height the height of the rectangle to clear.
560 * @see java.awt.Graphics#fillRect(int, int, int, int)
561 * @see java.awt.Graphics#drawRect
562 * @see java.awt.Graphics#setColor(java.awt.Color)
563 * @see java.awt.Graphics#setPaintMode
564 * @see java.awt.Graphics#setXORMode(java.awt.Color)
565 * @since JDK1.0
566 */
567 public void clearRect(int x, int y, int width, int height) {
568 Rectangle2D.Float rect = new Rectangle2D.Float(x, y, width, height);
569 addDrawingRect(rect);
570 mPrintMetrics.clear(this);
571 }
572
573 /**
574 * Draws an outlined round-cornered rectangle using this graphics
575 * context's current color. The left and right edges of the rectangle
576 * are at <code>x</code> and <code>x + width</code>,
577 * respectively. The top and bottom edges of the rectangle are at
578 * <code>y</code> and <code>y + height</code>.
579 * @param x the <i>x</i> coordinate of the rectangle to be drawn.
580 * @param y the <i>y</i> coordinate of the rectangle to be drawn.
581 * @param width the width of the rectangle to be drawn.
582 * @param height the height of the rectangle to be drawn.
583 * @param arcWidth the horizontal diameter of the arc
584 * at the four corners.
585 * @param arcHeight the vertical diameter of the arc
586 * at the four corners.
587 * @see java.awt.Graphics#fillRoundRect
588 * @since JDK1.0
589 */
590 public void drawRoundRect(int x, int y, int width, int height,
591 int arcWidth, int arcHeight) {
592 addStrokeShape(new RoundRectangle2D.Float(x, y, width, height, arcWidth, arcHeight));
593 mPrintMetrics.draw(this);
594
595 }
596
597 /**
598 * Fills the specified rounded corner rectangle with the current color.
599 * The left and right edges of the rectangle
600 * are at <code>x</code> and <code>x + width - 1</code>,
601 * respectively. The top and bottom edges of the rectangle are at
602 * <code>y</code> and <code>y + height - 1</code>.
603 * @param x the <i>x</i> coordinate of the rectangle to be filled.
604 * @param y the <i>y</i> coordinate of the rectangle to be filled.
605 * @param width the width of the rectangle to be filled.
606 * @param height the height of the rectangle to be filled.
607 * @param arcWidth the horizontal diameter
608 * of the arc at the four corners.
609 * @param arcHeight the vertical diameter
610 * of the arc at the four corners.
611 * @see java.awt.Graphics#drawRoundRect
612 * @since JDK1.0
613 */
614 public void fillRoundRect(int x, int y, int width, int height,
615 int arcWidth, int arcHeight) {
616 Rectangle2D.Float rect = new Rectangle2D.Float(x, y,width, height);
617 addDrawingRect(rect);
618 mPrintMetrics.fill(this);
619 }
620
621 /**
622 * Draws the outline of an oval.
623 * The result is a circle or ellipse that fits within the
624 * rectangle specified by the <code>x</code>, <code>y</code>,
625 * <code>width</code>, and <code>height</code> arguments.
626 * <p>
627 * The oval covers an area that is
628 * <code>width + 1</code> pixels wide
629 * and <code>height + 1</code> pixels tall.
630 * @param x the <i>x</i> coordinate of the upper left
631 * corner of the oval to be drawn.
632 * @param y the <i>y</i> coordinate of the upper left
633 * corner of the oval to be drawn.
634 * @param width the width of the oval to be drawn.
635 * @param height the height of the oval to be drawn.
636 * @see java.awt.Graphics#fillOval
637 * @since JDK1.0
638 */
639 public void drawOval(int x, int y, int width, int height) {
640 addStrokeShape(new Rectangle2D.Float(x, y, width, height));
641 mPrintMetrics.draw(this);
642 }
643
644 /**
645 * Fills an oval bounded by the specified rectangle with the
646 * current color.
647 * @param x the <i>x</i> coordinate of the upper left corner
648 * of the oval to be filled.
649 * @param y the <i>y</i> coordinate of the upper left corner
650 * of the oval to be filled.
651 * @param width the width of the oval to be filled.
652 * @param height the height of the oval to be filled.
653 * @see java.awt.Graphics#drawOval
654 * @since JDK1.0
655 */
656 public void fillOval(int x, int y, int width, int height) {
657 Rectangle2D.Float rect = new Rectangle2D.Float(x, y, width, height);
658 addDrawingRect(rect);
659 mPrintMetrics.fill(this);
660
661 }
662
663
664 /**
665 * Draws the outline of a circular or elliptical arc
666 * covering the specified rectangle.
667 * <p>
668 * The resulting arc begins at <code>startAngle</code> and extends
669 * for <code>arcAngle</code> degrees, using the current color.
670 * Angles are interpreted such that 0 degrees
671 * is at the 3 o'clock position.
672 * A positive value indicates a counter-clockwise rotation
673 * while a negative value indicates a clockwise rotation.
674 * <p>
675 * The center of the arc is the center of the rectangle whose origin
676 * is (<i>x</i>, <i>y</i>) and whose size is specified by the
677 * <code>width</code> and <code>height</code> arguments.
678 * <p>
679 * The resulting arc covers an area
680 * <code>width + 1</code> pixels wide
681 * by <code>height + 1</code> pixels tall.
682 * @param x the <i>x</i> coordinate of the
683 * upper-left corner of the arc to be drawn.
684 * @param y the <i>y</i> coordinate of the
685 * upper-left corner of the arc to be drawn.
686 * @param width the width of the arc to be drawn.
687 * @param height the height of the arc to be drawn.
688 * @param startAngle the beginning angle.
689 * @param arcAngle the angular extent of the arc,
690 * relative to the start angle.
691 * @see java.awt.Graphics#fillArc
692 * @since JDK1.0
693 */
694 public void drawArc(int x, int y, int width, int height,
695 int startAngle, int arcAngle) {
696 addStrokeShape(new Rectangle2D.Float(x, y, width, height));
697 mPrintMetrics.draw(this);
698
699 }
700
701 /**
702 * Fills a circular or elliptical arc covering the specified rectangle.
703 * <p>
704 * The resulting arc begins at <code>startAngle</code> and extends
705 * for <code>arcAngle</code> degrees.
706 * Angles are interpreted such that 0 degrees
707 * is at the 3 o'clock position.
708 * A positive value indicates a counter-clockwise rotation
709 * while a negative value indicates a clockwise rotation.
710 * <p>
711 * The center of the arc is the center of the rectangle whose origin
712 * is (<i>x</i>, <i>y</i>) and whose size is specified by the
713 * <code>width</code> and <code>height</code> arguments.
714 * <p>
715 * The resulting arc covers an area
716 * <code>width + 1</code> pixels wide
717 * by <code>height + 1</code> pixels tall.
718 * @param x the <i>x</i> coordinate of the
719 * upper-left corner of the arc to be filled.
720 * @param y the <i>y</i> coordinate of the
721 * upper-left corner of the arc to be filled.
722 * @param width the width of the arc to be filled.
723 * @param height the height of the arc to be filled.
724 * @param startAngle the beginning angle.
725 * @param arcAngle the angular extent of the arc,
726 * relative to the start angle.
727 * @see java.awt.Graphics#drawArc
728 * @since JDK1.0
729 */
730 public void fillArc(int x, int y, int width, int height,
731 int startAngle, int arcAngle) {
732 Rectangle2D.Float rect = new Rectangle2D.Float(x, y,width, height);
733 addDrawingRect(rect);
734 mPrintMetrics.fill(this);
735
736 }
737
738 /**
739 * Draws a sequence of connected lines defined by
740 * arrays of <i>x</i> and <i>y</i> coordinates.
741 * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
742 * The figure is not closed if the first point
743 * differs from the last point.
744 * @param xPoints an array of <i>x</i> points
745 * @param yPoints an array of <i>y</i> points
746 * @param nPoints the total number of points
747 * @see java.awt.Graphics#drawPolygon(int[], int[], int)
748 * @since JDK1.1
749 */
750 public void drawPolyline(int xPoints[], int yPoints[],
751 int nPoints) {
752 if (nPoints > 0) {
753 int x = xPoints[0];
754 int y = yPoints[0];
755
756 for (int i = 1; i < nPoints; i++) {
757 drawLine(x, y, xPoints[i], yPoints[i]);
758 x = xPoints[i];
759 y = yPoints[i];
760 }
761 }
762
763 }
764
765 /**
766 * Draws a closed polygon defined by
767 * arrays of <i>x</i> and <i>y</i> coordinates.
768 * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
769 * <p>
770 * This method draws the polygon defined by <code>nPoint</code> line
771 * segments, where the first <code>nPoint - 1</code>
772 * line segments are line segments from
773 * <code>(xPoints[i - 1], yPoints[i - 1])</code>
774 * to <code>(xPoints[i], yPoints[i])</code>, for
775 * 1 ≤ <i>i</i> ≤ <code>nPoints</code>.
776 * The figure is automatically closed by drawing a line connecting
777 * the final point to the first point, if those points are different.
778 * @param xPoints a an array of <code>x</code> coordinates.
779 * @param yPoints a an array of <code>y</code> coordinates.
780 * @param nPoints a the total number of points.
781 * @see java.awt.Graphics#fillPolygon
782 * @see java.awt.Graphics#drawPolyline
783 * @since JDK1.0
784 */
785 public void drawPolygon(int xPoints[], int yPoints[],
786 int nPoints) {
787 if (nPoints > 0) {
788 drawPolyline(xPoints, yPoints, nPoints);
789 drawLine(xPoints[nPoints - 1], yPoints[nPoints - 1],
790 xPoints[0], yPoints[0]);
791 }
792
793 }
794
795 /**
796 * Fills a closed polygon defined by
797 * arrays of <i>x</i> and <i>y</i> coordinates.
798 * <p>
799 * This method draws the polygon defined by <code>nPoint</code> line
800 * segments, where the first <code>nPoint - 1</code>
801 * line segments are line segments from
802 * <code>(xPoints[i - 1], yPoints[i - 1])</code>
803 * to <code>(xPoints[i], yPoints[i])</code>, for
804 * 1 ≤ <i>i</i> ≤ <code>nPoints</code>.
805 * The figure is automatically closed by drawing a line connecting
806 * the final point to the first point, if those points are different.
807 * <p>
808 * The area inside the polygon is defined using an
809 * even-odd fill rule, also known as the alternating rule.
810 * @param xPoints a an array of <code>x</code> coordinates.
811 * @param yPoints a an array of <code>y</code> coordinates.
812 * @param nPoints a the total number of points.
813 * @see java.awt.Graphics#drawPolygon(int[], int[], int)
814 * @since JDK1.0
815 */
816 public void fillPolygon(int xPoints[], int yPoints[],
817 int nPoints) {
818 if (nPoints > 0) {
819 int minX = xPoints[0];
820 int minY = yPoints[0];
821 int maxX = xPoints[0];
822 int maxY = yPoints[0];
823
824 for (int i = 1; i < nPoints; i++) {
825
826 if (xPoints[i] < minX) {
827 minX = xPoints[i];
828 } else if (xPoints[i] > maxX) {
829 maxX = xPoints[i];
830 }
831
832 if (yPoints[i] < minY) {
833 minY = yPoints[i];
834 } else if (yPoints[i] > maxY) {
837 }
838
839 addDrawingRect(minX, minY, maxX - minX, maxY - minY);
840 }
841
842 mPrintMetrics.fill(this);
843
844 }
845
846
847 /**
848 * Draws the text given by the specified string, using this
849 * graphics context's current font and color. The baseline of the
850 * first character is at position (<i>x</i>, <i>y</i>) in this
851 * graphics context's coordinate system.
852 * @param str the string to be drawn.
853 * @param x the <i>x</i> coordinate.
854 * @param y the <i>y</i> coordinate.
855 * @see java.awt.Graphics#drawBytes
856 * @see java.awt.Graphics#drawChars
857 * @since JDK1.0
858 */
859 public void drawString(String str, int x, int y) {
860
861 drawString(str, (float)x, (float)y);
862 }
863
864 /**
865 * Draws the text given by the specified iterator, using this
866 * graphics context's current color. The iterator has to specify a font
867 * for each character. The baseline of the
868 * first character is at position (<i>x</i>, <i>y</i>) in this
869 * graphics context's coordinate system.
870 * The rendering attributes applied include the clip, transform,
871 * paint or color, and composite attributes.
872 * For characters in script systems such as Hebrew and Arabic,
873 * the glyphs may be draw from right to left, in which case the
874 * coordinate supplied is the the location of the leftmost character
875 * on the baseline.
876 * @param iterator the iterator whose text is to be drawn
877 * @param x,y the coordinates where the iterator's text should be drawn.
925 * (<i>x</i>, <i>y</i>) in this graphics context's coordinate
926 * space. Transparent pixels in the image do not affect whatever
927 * pixels are already there.
928 * <p>
929 * This method returns immediately in all cases, even if the
930 * complete image has not yet been loaded, and it has not been dithered
931 * and converted for the current output device.
932 * <p>
933 * If the image has not yet been completely loaded, then
934 * <code>drawImage</code> returns <code>false</code>. As more of
935 * the image becomes available, the process that draws the image notifies
936 * the specified image observer.
937 * @param img the specified image to be drawn.
938 * @param x the <i>x</i> coordinate.
939 * @param y the <i>y</i> coordinate.
940 * @param observer object to be notified as more of
941 * the image is converted.
942 * @see java.awt.Image
943 * @see java.awt.image.ImageObserver
944 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
945 * @since JDK1.0
946 */
947 public boolean drawImage(Image img, int x, int y,
948 ImageObserver observer) {
949
950 if (img == null) {
951 return true;
952 }
953
954 /* The ImageWaiter creation does not return until the
955 * image is loaded.
956 */
957 ImageWaiter dim = new ImageWaiter(img);
958
959 addDrawingRect(x, y, dim.getWidth(), dim.getHeight());
960 mPrintMetrics.drawImage(this, img);
961
962 return mGraphics.drawImage(img, x, y, observer);
963 }
964
965
978 * If the current output representation is not yet complete, then
979 * <code>drawImage</code> returns <code>false</code>. As more of
980 * the image becomes available, the process that draws the image notifies
981 * the image observer by calling its <code>imageUpdate</code> method.
982 * <p>
983 * A scaled version of an image will not necessarily be
984 * available immediately just because an unscaled version of the
985 * image has been constructed for this output device. Each size of
986 * the image may be cached separately and generated from the original
987 * data in a separate image production sequence.
988 * @param img the specified image to be drawn.
989 * @param x the <i>x</i> coordinate.
990 * @param y the <i>y</i> coordinate.
991 * @param width the width of the rectangle.
992 * @param height the height of the rectangle.
993 * @param observer object to be notified as more of
994 * the image is converted.
995 * @see java.awt.Image
996 * @see java.awt.image.ImageObserver
997 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
998 * @since JDK1.0
999 */
1000 public boolean drawImage(Image img, int x, int y,
1001 int width, int height,
1002 ImageObserver observer) {
1003
1004 if (img == null) {
1005 return true;
1006 }
1007 addDrawingRect(x, y, width, height);
1008 mPrintMetrics.drawImage(this, img);
1009
1010 return mGraphics.drawImage(img, x, y, width, height, observer);
1011
1012 }
1013
1014 /**
1015 * Draws as much of the specified image as is currently available.
1016 * The image is drawn with its top-left corner at
1017 * (<i>x</i>, <i>y</i>) in this graphics context's coordinate
1018 * space. Transparent pixels are drawn in the specified
1023 * drawing the image on top of it, but possibly more efficient.
1024 * <p>
1025 * This method returns immediately in all cases, even if the
1026 * complete image has not yet been loaded, and it has not been dithered
1027 * and converted for the current output device.
1028 * <p>
1029 * If the image has not yet been completely loaded, then
1030 * <code>drawImage</code> returns <code>false</code>. As more of
1031 * the image becomes available, the process that draws the image notifies
1032 * the specified image observer.
1033 * @param img the specified image to be drawn.
1034 * @param x the <i>x</i> coordinate.
1035 * @param y the <i>y</i> coordinate.
1036 * @param bgcolor the background color to paint under the
1037 * non-opaque portions of the image.
1038 * @param observer object to be notified as more of
1039 * the image is converted.
1040 * @see java.awt.Image
1041 * @see java.awt.image.ImageObserver
1042 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
1043 * @since JDK1.0
1044 */
1045 public boolean drawImage(Image img, int x, int y,
1046 Color bgcolor,
1047 ImageObserver observer) {
1048
1049 if (img == null) {
1050 return true;
1051 }
1052
1053 /* The ImageWaiter creation does not return until the
1054 * image is loaded.
1055 */
1056 ImageWaiter dim = new ImageWaiter(img);
1057
1058 addDrawingRect(x, y, dim.getWidth(), dim.getHeight());
1059 mPrintMetrics.drawImage(this, img);
1060
1061 return mGraphics.drawImage(img, x, y, bgcolor, observer);
1062 }
1063
1082 * the image becomes available, the process that draws the image notifies
1083 * the specified image observer.
1084 * <p>
1085 * A scaled version of an image will not necessarily be
1086 * available immediately just because an unscaled version of the
1087 * image has been constructed for this output device. Each size of
1088 * the image may be cached separately and generated from the original
1089 * data in a separate image production sequence.
1090 * @param img the specified image to be drawn.
1091 * @param x the <i>x</i> coordinate.
1092 * @param y the <i>y</i> coordinate.
1093 * @param width the width of the rectangle.
1094 * @param height the height of the rectangle.
1095 * @param bgcolor the background color to paint under the
1096 * non-opaque portions of the image.
1097 * @param observer object to be notified as more of
1098 * the image is converted.
1099 * @see java.awt.Image
1100 * @see java.awt.image.ImageObserver
1101 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
1102 * @since JDK1.0
1103 */
1104 public boolean drawImage(Image img, int x, int y,
1105 int width, int height,
1106 Color bgcolor,
1107 ImageObserver observer) {
1108
1109 if (img == null) {
1110 return true;
1111 }
1112
1113 addDrawingRect(x, y, width, height);
1114 mPrintMetrics.drawImage(this, img);
1115
1116 return mGraphics.drawImage(img, x, y, width, height, bgcolor, observer);
1117
1118 }
1119
1120 /**
1121 * Draws as much of the specified area of the specified image as is
1122 * currently available, scaling it on the fly to fit inside the
1145 * destination rectangle.
1146 * @param dy1 the <i>y</i> coordinate of the first corner of the
1147 * destination rectangle.
1148 * @param dx2 the <i>x</i> coordinate of the second corner of the
1149 * destination rectangle.
1150 * @param dy2 the <i>y</i> coordinate of the second corner of the
1151 * destination rectangle.
1152 * @param sx1 the <i>x</i> coordinate of the first corner of the
1153 * source rectangle.
1154 * @param sy1 the <i>y</i> coordinate of the first corner of the
1155 * source rectangle.
1156 * @param sx2 the <i>x</i> coordinate of the second corner of the
1157 * source rectangle.
1158 * @param sy2 the <i>y</i> coordinate of the second corner of the
1159 * source rectangle.
1160 * @param observer object to be notified as more of the image is
1161 * scaled and converted.
1162 * @see java.awt.Image
1163 * @see java.awt.image.ImageObserver
1164 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
1165 * @since JDK1.1
1166 */
1167 public boolean drawImage(Image img,
1168 int dx1, int dy1, int dx2, int dy2,
1169 int sx1, int sy1, int sx2, int sy2,
1170 ImageObserver observer) {
1171
1172 if (img == null) {
1173 return true;
1174 }
1175
1176 int width = dx2 - dx1;
1177 int height = dy2 - dy1;
1178
1179 addDrawingRect(dx1, dy1, width, height);
1180 mPrintMetrics.drawImage(this, img);
1181
1182 return mGraphics.drawImage(img, dx1, dy1, dx2, dy2,
1183 sx1, sy1, sx2, sy2, observer);
1184
1185 }
1219 * destination rectangle.
1220 * @param dx2 the <i>x</i> coordinate of the second corner of the
1221 * destination rectangle.
1222 * @param dy2 the <i>y</i> coordinate of the second corner of the
1223 * destination rectangle.
1224 * @param sx1 the <i>x</i> coordinate of the first corner of the
1225 * source rectangle.
1226 * @param sy1 the <i>y</i> coordinate of the first corner of the
1227 * source rectangle.
1228 * @param sx2 the <i>x</i> coordinate of the second corner of the
1229 * source rectangle.
1230 * @param sy2 the <i>y</i> coordinate of the second corner of the
1231 * source rectangle.
1232 * @param bgcolor the background color to paint under the
1233 * non-opaque portions of the image.
1234 * @param observer object to be notified as more of the image is
1235 * scaled and converted.
1236 * @see java.awt.Image
1237 * @see java.awt.image.ImageObserver
1238 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
1239 * @since JDK1.1
1240 */
1241 public boolean drawImage(Image img,
1242 int dx1, int dy1, int dx2, int dy2,
1243 int sx1, int sy1, int sx2, int sy2,
1244 Color bgcolor,
1245 ImageObserver observer) {
1246
1247 if (img == null) {
1248 return true;
1249 }
1250
1251 int width = dx2 - dx1;
1252 int height = dy2 - dy1;
1253
1254 addDrawingRect(dx1, dy1, width, height);
1255 mPrintMetrics.drawImage(this, img);
1256
1257 return mGraphics.drawImage(img, dx1, dy1, dx2, dy2,
1258 sx1, sy1, sx2, sy2, bgcolor, observer);
1259
1310 * When a Java program runs, a large number of <code>Graphics</code>
1311 * objects can be created within a short time frame.
1312 * Although the finalization process of the garbage collector
1313 * also disposes of the same system resources, it is preferable
1314 * to manually free the associated resources by calling this
1315 * method rather than to rely on a finalization process which
1316 * may not run to completion for a long period of time.
1317 * <p>
1318 * Graphics objects which are provided as arguments to the
1319 * <code>paint</code> and <code>update</code> methods
1320 * of components are automatically released by the system when
1321 * those methods return. For efficiency, programmers should
1322 * call <code>dispose</code> when finished using
1323 * a <code>Graphics</code> object only if it was created
1324 * directly from a component or another <code>Graphics</code> object.
1325 * @see java.awt.Graphics#finalize
1326 * @see java.awt.Component#paint
1327 * @see java.awt.Component#update
1328 * @see java.awt.Component#getGraphics
1329 * @see java.awt.Graphics#create
1330 * @since JDK1.0
1331 */
1332 public void dispose() {
1333 mGraphics.dispose();
1334 }
1335
1336 /**
1337 * Empty finalizer as no clean up needed here.
1338 */
1339 public void finalize() {
1340 }
1341
1342 /* The Delegated Graphics2D Methods */
1343
1344 /**
1345 * Strokes the outline of a Shape using the settings of the current
1346 * graphics state. The rendering attributes applied include the
1347 * clip, transform, paint or color, composite and stroke attributes.
1348 * @param s The shape to be drawn.
1349 * @see #setStroke
1350 * @see #setPaint
|
149 * to which drawing occurred.
150 */
151 public Spans getDrawingArea() {
152 return mDrawingArea;
153 }
154
155 /**
156 * Returns the device configuration associated with this Graphics2D.
157 */
158 public GraphicsConfiguration getDeviceConfiguration() {
159 return ((RasterPrinterJob)mPrinterJob).getPrinterGraphicsConfig();
160 }
161
162 /* The Delegated Graphics Methods */
163
164 /**
165 * Creates a new <code>Graphics</code> object that is
166 * a copy of this <code>Graphics</code> object.
167 * @return a new graphics context that is a copy of
168 * this graphics context.
169 * @since 1.0
170 */
171 public Graphics create() {
172 PeekGraphics newGraphics = null;
173
174 try {
175 newGraphics = (PeekGraphics) clone();
176 newGraphics.mGraphics = (Graphics2D) mGraphics.create();
177
178 /* This exception can not happen unless this
179 * class no longer implements the Cloneable
180 * interface.
181 */
182 } catch (CloneNotSupportedException e) {
183 // can never happen.
184 }
185
186 return newGraphics;
187 }
188
189 /**
190 * Translates the origin of the graphics context to the point
191 * (<i>x</i>, <i>y</i>) in the current coordinate system.
192 * Modifies this graphics context so that its new origin corresponds
193 * to the point (<i>x</i>, <i>y</i>) in this graphics context's
194 * original coordinate system. All coordinates used in subsequent
195 * rendering operations on this graphics context will be relative
196 * to this new origin.
197 * @param x the <i>x</i> coordinate.
198 * @param y the <i>y</i> coordinate.
199 * @since 1.0
200 */
201 public void translate(int x, int y) {
202 mGraphics.translate(x, y);
203 }
204
205 /**
206 * Concatenates the current transform of this Graphics2D with a
207 * translation transformation.
208 * This is equivalent to calling transform(T), where T is an
209 * AffineTransform represented by the following matrix:
210 * <pre>
211 * [ 1 0 tx ]
212 * [ 0 1 ty ]
213 * [ 0 0 1 ]
214 * </pre>
215 */
216 public void translate(double tx, double ty) {
217 mGraphics.translate(tx, ty);
218 }
219
276 * AffineTransform represented by the following matrix:
277 * <pre>
278 * [ 1 shx 0 ]
279 * [ shy 1 0 ]
280 * [ 0 0 1 ]
281 * </pre>
282 * @param shx The factor by which coordinates are shifted towards the
283 * positive X axis direction according to their Y coordinate
284 * @param shy The factor by which coordinates are shifted towards the
285 * positive Y axis direction according to their X coordinate
286 */
287 public void shear(double shx, double shy) {
288 mGraphics.shear(shx, shy);
289 }
290
291 /**
292 * Gets this graphics context's current color.
293 * @return this graphics context's current color.
294 * @see java.awt.Color
295 * @see java.awt.Graphics#setColor
296 * @since 1.0
297 */
298 public Color getColor() {
299 return mGraphics.getColor();
300 }
301
302 /**
303 * Sets this graphics context's current color to the specified
304 * color. All subsequent graphics operations using this graphics
305 * context use this specified color.
306 * @param c the new rendering color.
307 * @see java.awt.Color
308 * @see java.awt.Graphics#getColor
309 * @since 1.0
310 */
311 public void setColor(Color c) {
312 mGraphics.setColor(c);
313 }
314
315 /**
316 * Sets the paint mode of this graphics context to overwrite the
317 * destination with this graphics context's current color.
318 * This sets the logical pixel operation function to the paint or
319 * overwrite mode. All subsequent rendering operations will
320 * overwrite the destination with the current color.
321 * @since 1.0
322 */
323 public void setPaintMode() {
324 mGraphics.setPaintMode();
325 }
326
327 /**
328 * Sets the paint mode of this graphics context to alternate between
329 * this graphics context's current color and the new specified color.
330 * This specifies that logical pixel operations are performed in the
331 * XOR mode, which alternates pixels between the current color and
332 * a specified XOR color.
333 * <p>
334 * When drawing operations are performed, pixels which are the
335 * current color are changed to the specified color, and vice versa.
336 * <p>
337 * Pixels that are of colors other than those two colors are changed
338 * in an unpredictable but reversible manner; if the same figure is
339 * drawn twice, then all pixels are restored to their original values.
340 * @param c1 the XOR alternation color
341 * @since 1.0
342 */
343 public void setXORMode(Color c1) {
344 mGraphics.setXORMode(c1);
345 }
346
347 /**
348 * Gets the current font.
349 * @return this graphics context's current font.
350 * @see java.awt.Font
351 * @see java.awt.Graphics#setFont
352 * @since 1.0
353 */
354 public Font getFont() {
355 return mGraphics.getFont();
356 }
357
358 /**
359 * Sets this graphics context's font to the specified font.
360 * All subsequent text operations using this graphics context
361 * use this font.
362 * @param font the font.
363 * @see java.awt.Graphics#getFont
364 * @see java.awt.Graphics#drawChars(java.lang.String, int, int)
365 * @see java.awt.Graphics#drawString(byte[], int, int, int, int)
366 * @see java.awt.Graphics#drawBytes(char[], int, int, int, int)
367 * @since 1.0
368 */
369 public void setFont(Font font) {
370 mGraphics.setFont(font);
371 }
372
373 /**
374 * Gets the font metrics for the specified font.
375 * @return the font metrics for the specified font.
376 * @param f the specified font
377 * @see java.awt.Graphics#getFont
378 * @see java.awt.FontMetrics
379 * @see java.awt.Graphics#getFontMetrics()
380 * @since 1.0
381 */
382 public FontMetrics getFontMetrics(Font f) {
383 return mGraphics.getFontMetrics(f);
384 }
385
386 /**
387 * Get the rendering context of the font
388 * within this Graphics2D context.
389 */
390 public FontRenderContext getFontRenderContext() {
391 return mGraphics.getFontRenderContext();
392 }
393
394 /**
395 * Returns the bounding rectangle of the current clipping area.
396 * The coordinates in the rectangle are relative to the coordinate
397 * system origin of this graphics context.
398 * @return the bounding rectangle of the current clipping area.
399 * @see java.awt.Graphics#getClip
400 * @see java.awt.Graphics#clipRect
401 * @see java.awt.Graphics#setClip(int, int, int, int)
402 * @see java.awt.Graphics#setClip(Shape)
403 * @since 1.1
404 */
405 public Rectangle getClipBounds() {
406 return mGraphics.getClipBounds();
407 }
408
409
410 /**
411 * Intersects the current clip with the specified rectangle.
412 * The resulting clipping area is the intersection of the current
413 * clipping area and the specified rectangle.
414 * This method can only be used to make the current clip smaller.
415 * To set the current clip larger, use any of the setClip methods.
416 * Rendering operations have no effect outside of the clipping area.
417 * @param x the x coordinate of the rectangle to intersect the clip with
418 * @param y the y coordinate of the rectangle to intersect the clip with
419 * @param width the width of the rectangle to intersect the clip with
420 * @param height the height of the rectangle to intersect the clip with
421 * @see #setClip(int, int, int, int)
422 * @see #setClip(Shape)
423 */
424 public void clipRect(int x, int y, int width, int height) {
425 mGraphics.clipRect(x, y, width, height);
426 }
427
428
429 /**
430 * Sets the current clip to the rectangle specified by the given
431 * coordinates.
432 * Rendering operations have no effect outside of the clipping area.
433 * @param x the <i>x</i> coordinate of the new clip rectangle.
434 * @param y the <i>y</i> coordinate of the new clip rectangle.
435 * @param width the width of the new clip rectangle.
436 * @param height the height of the new clip rectangle.
437 * @see java.awt.Graphics#clipRect
438 * @see java.awt.Graphics#setClip(Shape)
439 * @since 1.1
440 */
441 public void setClip(int x, int y, int width, int height) {
442 mGraphics.setClip(x, y, width, height);
443 }
444
445 /**
446 * Gets the current clipping area.
447 * @return a <code>Shape</code> object representing the
448 * current clipping area.
449 * @see java.awt.Graphics#getClipBounds
450 * @see java.awt.Graphics#clipRect
451 * @see java.awt.Graphics#setClip(int, int, int, int)
452 * @see java.awt.Graphics#setClip(Shape)
453 * @since 1.1
454 */
455 public Shape getClip() {
456 return mGraphics.getClip();
457 }
458
459
460 /**
461 * Sets the current clipping area to an arbitrary clip shape.
462 * Not all objects which implement the <code>Shape</code>
463 * interface can be used to set the clip. The only
464 * <code>Shape</code> objects which are guaranteed to be
465 * supported are <code>Shape</code> objects which are
466 * obtained via the <code>getClip</code> method and via
467 * <code>Rectangle</code> objects.
468 * @see java.awt.Graphics#getClip()
469 * @see java.awt.Graphics#clipRect
470 * @see java.awt.Graphics#setClip(int, int, int, int)
471 * @since 1.1
472 */
473 public void setClip(Shape clip) {
474 mGraphics.setClip(clip);
475 }
476
477
478 /**
479 * Copies an area of the component by a distance specified by
480 * <code>dx</code> and <code>dy</code>. From the point specified
481 * by <code>x</code> and <code>y</code>, this method
482 * copies downwards and to the right. To copy an area of the
483 * component to the left or upwards, specify a negative value for
484 * <code>dx</code> or <code>dy</code>.
485 * If a portion of the source rectangle lies outside the bounds
486 * of the component, or is obscured by another window or component,
487 * <code>copyArea</code> will be unable to copy the associated
488 * pixels. The area that is omitted can be refreshed by calling
489 * the component's <code>paint</code> method.
490 * @param x the <i>x</i> coordinate of the source rectangle.
491 * @param y the <i>y</i> coordinate of the source rectangle.
492 * @param width the width of the source rectangle.
493 * @param height the height of the source rectangle.
494 * @param dx the horizontal distance to copy the pixels.
495 * @param dy the vertical distance to copy the pixels.
496 * @since 1.0
497 */
498 public void copyArea(int x, int y, int width, int height,
499 int dx, int dy) {
500 // This method is not supported for printing so we do nothing here.
501 }
502
503 /**
504 * Draws a line, using the current color, between the points
505 * <code>(x1, y1)</code> and <code>(x2, y2)</code>
506 * in this graphics context's coordinate system.
507 * @param x1 the first point's <i>x</i> coordinate.
508 * @param y1 the first point's <i>y</i> coordinate.
509 * @param x2 the second point's <i>x</i> coordinate.
510 * @param y2 the second point's <i>y</i> coordinate.
511 * @since 1.0
512 */
513 public void drawLine(int x1, int y1, int x2, int y2) {
514 addStrokeShape(new Line2D.Float(x1, y1, x2, y2));
515 mPrintMetrics.draw(this);
516 }
517
518
519
520 /**
521 * Fills the specified rectangle.
522 * The left and right edges of the rectangle are at
523 * <code>x</code> and <code>x + width - 1</code>.
524 * The top and bottom edges are at
525 * <code>y</code> and <code>y + height - 1</code>.
526 * The resulting rectangle covers an area
527 * <code>width</code> pixels wide by
528 * <code>height</code> pixels tall.
529 * The rectangle is filled using the graphics context's current color.
530 * @param x the <i>x</i> coordinate
531 * of the rectangle to be filled.
532 * @param y the <i>y</i> coordinate
533 * of the rectangle to be filled.
534 * @param width the width of the rectangle to be filled.
535 * @param height the height of the rectangle to be filled.
536 * @see java.awt.Graphics#fillRect
537 * @see java.awt.Graphics#clearRect
538 * @since 1.0
539 */
540 public void fillRect(int x, int y, int width, int height) {
541
542 addDrawingRect(new Rectangle2D.Float(x, y, width, height));
543 mPrintMetrics.fill(this);
544
545 }
546
547 /**
548 * Clears the specified rectangle by filling it with the background
549 * color of the current drawing surface. This operation does not
550 * use the current paint mode.
551 * <p>
552 * Beginning with Java 1.1, the background color
553 * of offscreen images may be system dependent. Applications should
554 * use <code>setColor</code> followed by <code>fillRect</code> to
555 * ensure that an offscreen image is cleared to a specific color.
556 * @param x the <i>x</i> coordinate of the rectangle to clear.
557 * @param y the <i>y</i> coordinate of the rectangle to clear.
558 * @param width the width of the rectangle to clear.
559 * @param height the height of the rectangle to clear.
560 * @see java.awt.Graphics#fillRect(int, int, int, int)
561 * @see java.awt.Graphics#drawRect
562 * @see java.awt.Graphics#setColor(java.awt.Color)
563 * @see java.awt.Graphics#setPaintMode
564 * @see java.awt.Graphics#setXORMode(java.awt.Color)
565 * @since 1.0
566 */
567 public void clearRect(int x, int y, int width, int height) {
568 Rectangle2D.Float rect = new Rectangle2D.Float(x, y, width, height);
569 addDrawingRect(rect);
570 mPrintMetrics.clear(this);
571 }
572
573 /**
574 * Draws an outlined round-cornered rectangle using this graphics
575 * context's current color. The left and right edges of the rectangle
576 * are at <code>x</code> and <code>x + width</code>,
577 * respectively. The top and bottom edges of the rectangle are at
578 * <code>y</code> and <code>y + height</code>.
579 * @param x the <i>x</i> coordinate of the rectangle to be drawn.
580 * @param y the <i>y</i> coordinate of the rectangle to be drawn.
581 * @param width the width of the rectangle to be drawn.
582 * @param height the height of the rectangle to be drawn.
583 * @param arcWidth the horizontal diameter of the arc
584 * at the four corners.
585 * @param arcHeight the vertical diameter of the arc
586 * at the four corners.
587 * @see java.awt.Graphics#fillRoundRect
588 * @since 1.0
589 */
590 public void drawRoundRect(int x, int y, int width, int height,
591 int arcWidth, int arcHeight) {
592 addStrokeShape(new RoundRectangle2D.Float(x, y, width, height, arcWidth, arcHeight));
593 mPrintMetrics.draw(this);
594
595 }
596
597 /**
598 * Fills the specified rounded corner rectangle with the current color.
599 * The left and right edges of the rectangle
600 * are at <code>x</code> and <code>x + width - 1</code>,
601 * respectively. The top and bottom edges of the rectangle are at
602 * <code>y</code> and <code>y + height - 1</code>.
603 * @param x the <i>x</i> coordinate of the rectangle to be filled.
604 * @param y the <i>y</i> coordinate of the rectangle to be filled.
605 * @param width the width of the rectangle to be filled.
606 * @param height the height of the rectangle to be filled.
607 * @param arcWidth the horizontal diameter
608 * of the arc at the four corners.
609 * @param arcHeight the vertical diameter
610 * of the arc at the four corners.
611 * @see java.awt.Graphics#drawRoundRect
612 * @since 1.0
613 */
614 public void fillRoundRect(int x, int y, int width, int height,
615 int arcWidth, int arcHeight) {
616 Rectangle2D.Float rect = new Rectangle2D.Float(x, y,width, height);
617 addDrawingRect(rect);
618 mPrintMetrics.fill(this);
619 }
620
621 /**
622 * Draws the outline of an oval.
623 * The result is a circle or ellipse that fits within the
624 * rectangle specified by the <code>x</code>, <code>y</code>,
625 * <code>width</code>, and <code>height</code> arguments.
626 * <p>
627 * The oval covers an area that is
628 * <code>width + 1</code> pixels wide
629 * and <code>height + 1</code> pixels tall.
630 * @param x the <i>x</i> coordinate of the upper left
631 * corner of the oval to be drawn.
632 * @param y the <i>y</i> coordinate of the upper left
633 * corner of the oval to be drawn.
634 * @param width the width of the oval to be drawn.
635 * @param height the height of the oval to be drawn.
636 * @see java.awt.Graphics#fillOval
637 * @since 1.0
638 */
639 public void drawOval(int x, int y, int width, int height) {
640 addStrokeShape(new Rectangle2D.Float(x, y, width, height));
641 mPrintMetrics.draw(this);
642 }
643
644 /**
645 * Fills an oval bounded by the specified rectangle with the
646 * current color.
647 * @param x the <i>x</i> coordinate of the upper left corner
648 * of the oval to be filled.
649 * @param y the <i>y</i> coordinate of the upper left corner
650 * of the oval to be filled.
651 * @param width the width of the oval to be filled.
652 * @param height the height of the oval to be filled.
653 * @see java.awt.Graphics#drawOval
654 * @since 1.0
655 */
656 public void fillOval(int x, int y, int width, int height) {
657 Rectangle2D.Float rect = new Rectangle2D.Float(x, y, width, height);
658 addDrawingRect(rect);
659 mPrintMetrics.fill(this);
660
661 }
662
663
664 /**
665 * Draws the outline of a circular or elliptical arc
666 * covering the specified rectangle.
667 * <p>
668 * The resulting arc begins at <code>startAngle</code> and extends
669 * for <code>arcAngle</code> degrees, using the current color.
670 * Angles are interpreted such that 0 degrees
671 * is at the 3 o'clock position.
672 * A positive value indicates a counter-clockwise rotation
673 * while a negative value indicates a clockwise rotation.
674 * <p>
675 * The center of the arc is the center of the rectangle whose origin
676 * is (<i>x</i>, <i>y</i>) and whose size is specified by the
677 * <code>width</code> and <code>height</code> arguments.
678 * <p>
679 * The resulting arc covers an area
680 * <code>width + 1</code> pixels wide
681 * by <code>height + 1</code> pixels tall.
682 * @param x the <i>x</i> coordinate of the
683 * upper-left corner of the arc to be drawn.
684 * @param y the <i>y</i> coordinate of the
685 * upper-left corner of the arc to be drawn.
686 * @param width the width of the arc to be drawn.
687 * @param height the height of the arc to be drawn.
688 * @param startAngle the beginning angle.
689 * @param arcAngle the angular extent of the arc,
690 * relative to the start angle.
691 * @see java.awt.Graphics#fillArc
692 * @since 1.0
693 */
694 public void drawArc(int x, int y, int width, int height,
695 int startAngle, int arcAngle) {
696 addStrokeShape(new Rectangle2D.Float(x, y, width, height));
697 mPrintMetrics.draw(this);
698
699 }
700
701 /**
702 * Fills a circular or elliptical arc covering the specified rectangle.
703 * <p>
704 * The resulting arc begins at <code>startAngle</code> and extends
705 * for <code>arcAngle</code> degrees.
706 * Angles are interpreted such that 0 degrees
707 * is at the 3 o'clock position.
708 * A positive value indicates a counter-clockwise rotation
709 * while a negative value indicates a clockwise rotation.
710 * <p>
711 * The center of the arc is the center of the rectangle whose origin
712 * is (<i>x</i>, <i>y</i>) and whose size is specified by the
713 * <code>width</code> and <code>height</code> arguments.
714 * <p>
715 * The resulting arc covers an area
716 * <code>width + 1</code> pixels wide
717 * by <code>height + 1</code> pixels tall.
718 * @param x the <i>x</i> coordinate of the
719 * upper-left corner of the arc to be filled.
720 * @param y the <i>y</i> coordinate of the
721 * upper-left corner of the arc to be filled.
722 * @param width the width of the arc to be filled.
723 * @param height the height of the arc to be filled.
724 * @param startAngle the beginning angle.
725 * @param arcAngle the angular extent of the arc,
726 * relative to the start angle.
727 * @see java.awt.Graphics#drawArc
728 * @since 1.0
729 */
730 public void fillArc(int x, int y, int width, int height,
731 int startAngle, int arcAngle) {
732 Rectangle2D.Float rect = new Rectangle2D.Float(x, y,width, height);
733 addDrawingRect(rect);
734 mPrintMetrics.fill(this);
735
736 }
737
738 /**
739 * Draws a sequence of connected lines defined by
740 * arrays of <i>x</i> and <i>y</i> coordinates.
741 * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
742 * The figure is not closed if the first point
743 * differs from the last point.
744 * @param xPoints an array of <i>x</i> points
745 * @param yPoints an array of <i>y</i> points
746 * @param nPoints the total number of points
747 * @see java.awt.Graphics#drawPolygon(int[], int[], int)
748 * @since 1.1
749 */
750 public void drawPolyline(int xPoints[], int yPoints[],
751 int nPoints) {
752 if (nPoints > 0) {
753 int x = xPoints[0];
754 int y = yPoints[0];
755
756 for (int i = 1; i < nPoints; i++) {
757 drawLine(x, y, xPoints[i], yPoints[i]);
758 x = xPoints[i];
759 y = yPoints[i];
760 }
761 }
762
763 }
764
765 /**
766 * Draws a closed polygon defined by
767 * arrays of <i>x</i> and <i>y</i> coordinates.
768 * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
769 * <p>
770 * This method draws the polygon defined by <code>nPoint</code> line
771 * segments, where the first <code>nPoint - 1</code>
772 * line segments are line segments from
773 * <code>(xPoints[i - 1], yPoints[i - 1])</code>
774 * to <code>(xPoints[i], yPoints[i])</code>, for
775 * 1 ≤ <i>i</i> ≤ <code>nPoints</code>.
776 * The figure is automatically closed by drawing a line connecting
777 * the final point to the first point, if those points are different.
778 * @param xPoints a an array of <code>x</code> coordinates.
779 * @param yPoints a an array of <code>y</code> coordinates.
780 * @param nPoints a the total number of points.
781 * @see java.awt.Graphics#fillPolygon
782 * @see java.awt.Graphics#drawPolyline
783 * @since 1.0
784 */
785 public void drawPolygon(int xPoints[], int yPoints[],
786 int nPoints) {
787 if (nPoints > 0) {
788 drawPolyline(xPoints, yPoints, nPoints);
789 drawLine(xPoints[nPoints - 1], yPoints[nPoints - 1],
790 xPoints[0], yPoints[0]);
791 }
792
793 }
794
795 /**
796 * Fills a closed polygon defined by
797 * arrays of <i>x</i> and <i>y</i> coordinates.
798 * <p>
799 * This method draws the polygon defined by <code>nPoint</code> line
800 * segments, where the first <code>nPoint - 1</code>
801 * line segments are line segments from
802 * <code>(xPoints[i - 1], yPoints[i - 1])</code>
803 * to <code>(xPoints[i], yPoints[i])</code>, for
804 * 1 ≤ <i>i</i> ≤ <code>nPoints</code>.
805 * The figure is automatically closed by drawing a line connecting
806 * the final point to the first point, if those points are different.
807 * <p>
808 * The area inside the polygon is defined using an
809 * even-odd fill rule, also known as the alternating rule.
810 * @param xPoints a an array of <code>x</code> coordinates.
811 * @param yPoints a an array of <code>y</code> coordinates.
812 * @param nPoints a the total number of points.
813 * @see java.awt.Graphics#drawPolygon(int[], int[], int)
814 * @since 1.0
815 */
816 public void fillPolygon(int xPoints[], int yPoints[],
817 int nPoints) {
818 if (nPoints > 0) {
819 int minX = xPoints[0];
820 int minY = yPoints[0];
821 int maxX = xPoints[0];
822 int maxY = yPoints[0];
823
824 for (int i = 1; i < nPoints; i++) {
825
826 if (xPoints[i] < minX) {
827 minX = xPoints[i];
828 } else if (xPoints[i] > maxX) {
829 maxX = xPoints[i];
830 }
831
832 if (yPoints[i] < minY) {
833 minY = yPoints[i];
834 } else if (yPoints[i] > maxY) {
837 }
838
839 addDrawingRect(minX, minY, maxX - minX, maxY - minY);
840 }
841
842 mPrintMetrics.fill(this);
843
844 }
845
846
847 /**
848 * Draws the text given by the specified string, using this
849 * graphics context's current font and color. The baseline of the
850 * first character is at position (<i>x</i>, <i>y</i>) in this
851 * graphics context's coordinate system.
852 * @param str the string to be drawn.
853 * @param x the <i>x</i> coordinate.
854 * @param y the <i>y</i> coordinate.
855 * @see java.awt.Graphics#drawBytes
856 * @see java.awt.Graphics#drawChars
857 * @since 1.0
858 */
859 public void drawString(String str, int x, int y) {
860
861 drawString(str, (float)x, (float)y);
862 }
863
864 /**
865 * Draws the text given by the specified iterator, using this
866 * graphics context's current color. The iterator has to specify a font
867 * for each character. The baseline of the
868 * first character is at position (<i>x</i>, <i>y</i>) in this
869 * graphics context's coordinate system.
870 * The rendering attributes applied include the clip, transform,
871 * paint or color, and composite attributes.
872 * For characters in script systems such as Hebrew and Arabic,
873 * the glyphs may be draw from right to left, in which case the
874 * coordinate supplied is the the location of the leftmost character
875 * on the baseline.
876 * @param iterator the iterator whose text is to be drawn
877 * @param x,y the coordinates where the iterator's text should be drawn.
925 * (<i>x</i>, <i>y</i>) in this graphics context's coordinate
926 * space. Transparent pixels in the image do not affect whatever
927 * pixels are already there.
928 * <p>
929 * This method returns immediately in all cases, even if the
930 * complete image has not yet been loaded, and it has not been dithered
931 * and converted for the current output device.
932 * <p>
933 * If the image has not yet been completely loaded, then
934 * <code>drawImage</code> returns <code>false</code>. As more of
935 * the image becomes available, the process that draws the image notifies
936 * the specified image observer.
937 * @param img the specified image to be drawn.
938 * @param x the <i>x</i> coordinate.
939 * @param y the <i>y</i> coordinate.
940 * @param observer object to be notified as more of
941 * the image is converted.
942 * @see java.awt.Image
943 * @see java.awt.image.ImageObserver
944 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
945 * @since 1.0
946 */
947 public boolean drawImage(Image img, int x, int y,
948 ImageObserver observer) {
949
950 if (img == null) {
951 return true;
952 }
953
954 /* The ImageWaiter creation does not return until the
955 * image is loaded.
956 */
957 ImageWaiter dim = new ImageWaiter(img);
958
959 addDrawingRect(x, y, dim.getWidth(), dim.getHeight());
960 mPrintMetrics.drawImage(this, img);
961
962 return mGraphics.drawImage(img, x, y, observer);
963 }
964
965
978 * If the current output representation is not yet complete, then
979 * <code>drawImage</code> returns <code>false</code>. As more of
980 * the image becomes available, the process that draws the image notifies
981 * the image observer by calling its <code>imageUpdate</code> method.
982 * <p>
983 * A scaled version of an image will not necessarily be
984 * available immediately just because an unscaled version of the
985 * image has been constructed for this output device. Each size of
986 * the image may be cached separately and generated from the original
987 * data in a separate image production sequence.
988 * @param img the specified image to be drawn.
989 * @param x the <i>x</i> coordinate.
990 * @param y the <i>y</i> coordinate.
991 * @param width the width of the rectangle.
992 * @param height the height of the rectangle.
993 * @param observer object to be notified as more of
994 * the image is converted.
995 * @see java.awt.Image
996 * @see java.awt.image.ImageObserver
997 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
998 * @since 1.0
999 */
1000 public boolean drawImage(Image img, int x, int y,
1001 int width, int height,
1002 ImageObserver observer) {
1003
1004 if (img == null) {
1005 return true;
1006 }
1007 addDrawingRect(x, y, width, height);
1008 mPrintMetrics.drawImage(this, img);
1009
1010 return mGraphics.drawImage(img, x, y, width, height, observer);
1011
1012 }
1013
1014 /**
1015 * Draws as much of the specified image as is currently available.
1016 * The image is drawn with its top-left corner at
1017 * (<i>x</i>, <i>y</i>) in this graphics context's coordinate
1018 * space. Transparent pixels are drawn in the specified
1023 * drawing the image on top of it, but possibly more efficient.
1024 * <p>
1025 * This method returns immediately in all cases, even if the
1026 * complete image has not yet been loaded, and it has not been dithered
1027 * and converted for the current output device.
1028 * <p>
1029 * If the image has not yet been completely loaded, then
1030 * <code>drawImage</code> returns <code>false</code>. As more of
1031 * the image becomes available, the process that draws the image notifies
1032 * the specified image observer.
1033 * @param img the specified image to be drawn.
1034 * @param x the <i>x</i> coordinate.
1035 * @param y the <i>y</i> coordinate.
1036 * @param bgcolor the background color to paint under the
1037 * non-opaque portions of the image.
1038 * @param observer object to be notified as more of
1039 * the image is converted.
1040 * @see java.awt.Image
1041 * @see java.awt.image.ImageObserver
1042 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
1043 * @since 1.0
1044 */
1045 public boolean drawImage(Image img, int x, int y,
1046 Color bgcolor,
1047 ImageObserver observer) {
1048
1049 if (img == null) {
1050 return true;
1051 }
1052
1053 /* The ImageWaiter creation does not return until the
1054 * image is loaded.
1055 */
1056 ImageWaiter dim = new ImageWaiter(img);
1057
1058 addDrawingRect(x, y, dim.getWidth(), dim.getHeight());
1059 mPrintMetrics.drawImage(this, img);
1060
1061 return mGraphics.drawImage(img, x, y, bgcolor, observer);
1062 }
1063
1082 * the image becomes available, the process that draws the image notifies
1083 * the specified image observer.
1084 * <p>
1085 * A scaled version of an image will not necessarily be
1086 * available immediately just because an unscaled version of the
1087 * image has been constructed for this output device. Each size of
1088 * the image may be cached separately and generated from the original
1089 * data in a separate image production sequence.
1090 * @param img the specified image to be drawn.
1091 * @param x the <i>x</i> coordinate.
1092 * @param y the <i>y</i> coordinate.
1093 * @param width the width of the rectangle.
1094 * @param height the height of the rectangle.
1095 * @param bgcolor the background color to paint under the
1096 * non-opaque portions of the image.
1097 * @param observer object to be notified as more of
1098 * the image is converted.
1099 * @see java.awt.Image
1100 * @see java.awt.image.ImageObserver
1101 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
1102 * @since 1.0
1103 */
1104 public boolean drawImage(Image img, int x, int y,
1105 int width, int height,
1106 Color bgcolor,
1107 ImageObserver observer) {
1108
1109 if (img == null) {
1110 return true;
1111 }
1112
1113 addDrawingRect(x, y, width, height);
1114 mPrintMetrics.drawImage(this, img);
1115
1116 return mGraphics.drawImage(img, x, y, width, height, bgcolor, observer);
1117
1118 }
1119
1120 /**
1121 * Draws as much of the specified area of the specified image as is
1122 * currently available, scaling it on the fly to fit inside the
1145 * destination rectangle.
1146 * @param dy1 the <i>y</i> coordinate of the first corner of the
1147 * destination rectangle.
1148 * @param dx2 the <i>x</i> coordinate of the second corner of the
1149 * destination rectangle.
1150 * @param dy2 the <i>y</i> coordinate of the second corner of the
1151 * destination rectangle.
1152 * @param sx1 the <i>x</i> coordinate of the first corner of the
1153 * source rectangle.
1154 * @param sy1 the <i>y</i> coordinate of the first corner of the
1155 * source rectangle.
1156 * @param sx2 the <i>x</i> coordinate of the second corner of the
1157 * source rectangle.
1158 * @param sy2 the <i>y</i> coordinate of the second corner of the
1159 * source rectangle.
1160 * @param observer object to be notified as more of the image is
1161 * scaled and converted.
1162 * @see java.awt.Image
1163 * @see java.awt.image.ImageObserver
1164 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
1165 * @since 1.1
1166 */
1167 public boolean drawImage(Image img,
1168 int dx1, int dy1, int dx2, int dy2,
1169 int sx1, int sy1, int sx2, int sy2,
1170 ImageObserver observer) {
1171
1172 if (img == null) {
1173 return true;
1174 }
1175
1176 int width = dx2 - dx1;
1177 int height = dy2 - dy1;
1178
1179 addDrawingRect(dx1, dy1, width, height);
1180 mPrintMetrics.drawImage(this, img);
1181
1182 return mGraphics.drawImage(img, dx1, dy1, dx2, dy2,
1183 sx1, sy1, sx2, sy2, observer);
1184
1185 }
1219 * destination rectangle.
1220 * @param dx2 the <i>x</i> coordinate of the second corner of the
1221 * destination rectangle.
1222 * @param dy2 the <i>y</i> coordinate of the second corner of the
1223 * destination rectangle.
1224 * @param sx1 the <i>x</i> coordinate of the first corner of the
1225 * source rectangle.
1226 * @param sy1 the <i>y</i> coordinate of the first corner of the
1227 * source rectangle.
1228 * @param sx2 the <i>x</i> coordinate of the second corner of the
1229 * source rectangle.
1230 * @param sy2 the <i>y</i> coordinate of the second corner of the
1231 * source rectangle.
1232 * @param bgcolor the background color to paint under the
1233 * non-opaque portions of the image.
1234 * @param observer object to be notified as more of the image is
1235 * scaled and converted.
1236 * @see java.awt.Image
1237 * @see java.awt.image.ImageObserver
1238 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
1239 * @since 1.1
1240 */
1241 public boolean drawImage(Image img,
1242 int dx1, int dy1, int dx2, int dy2,
1243 int sx1, int sy1, int sx2, int sy2,
1244 Color bgcolor,
1245 ImageObserver observer) {
1246
1247 if (img == null) {
1248 return true;
1249 }
1250
1251 int width = dx2 - dx1;
1252 int height = dy2 - dy1;
1253
1254 addDrawingRect(dx1, dy1, width, height);
1255 mPrintMetrics.drawImage(this, img);
1256
1257 return mGraphics.drawImage(img, dx1, dy1, dx2, dy2,
1258 sx1, sy1, sx2, sy2, bgcolor, observer);
1259
1310 * When a Java program runs, a large number of <code>Graphics</code>
1311 * objects can be created within a short time frame.
1312 * Although the finalization process of the garbage collector
1313 * also disposes of the same system resources, it is preferable
1314 * to manually free the associated resources by calling this
1315 * method rather than to rely on a finalization process which
1316 * may not run to completion for a long period of time.
1317 * <p>
1318 * Graphics objects which are provided as arguments to the
1319 * <code>paint</code> and <code>update</code> methods
1320 * of components are automatically released by the system when
1321 * those methods return. For efficiency, programmers should
1322 * call <code>dispose</code> when finished using
1323 * a <code>Graphics</code> object only if it was created
1324 * directly from a component or another <code>Graphics</code> object.
1325 * @see java.awt.Graphics#finalize
1326 * @see java.awt.Component#paint
1327 * @see java.awt.Component#update
1328 * @see java.awt.Component#getGraphics
1329 * @see java.awt.Graphics#create
1330 * @since 1.0
1331 */
1332 public void dispose() {
1333 mGraphics.dispose();
1334 }
1335
1336 /**
1337 * Empty finalizer as no clean up needed here.
1338 */
1339 public void finalize() {
1340 }
1341
1342 /* The Delegated Graphics2D Methods */
1343
1344 /**
1345 * Strokes the outline of a Shape using the settings of the current
1346 * graphics state. The rendering attributes applied include the
1347 * clip, transform, paint or color, composite and stroke attributes.
1348 * @param s The shape to be drawn.
1349 * @see #setStroke
1350 * @see #setPaint
|