94 * drawing.
95 */
96 public void setDelegate(Graphics2D graphics) {
97 mGraphics = graphics;
98 }
99
100 public PrinterJob getPrinterJob() {
101 return mPrinterJob;
102 }
103
104 /**
105 * Returns the device configuration associated with this Graphics2D.
106 */
107 public GraphicsConfiguration getDeviceConfiguration() {
108 return ((RasterPrinterJob)mPrinterJob).getPrinterGraphicsConfig();
109 }
110
111 /* The Delegated Graphics Methods */
112
113 /**
114 * Creates a new <code>Graphics</code> object that is
115 * a copy of this <code>Graphics</code> object.
116 * @return a new graphics context that is a copy of
117 * this graphics context.
118 * @since 1.0
119 */
120 public Graphics create() {
121 return new ProxyGraphics2D((Graphics2D) mGraphics.create(),
122 mPrinterJob);
123 }
124
125 /**
126 * Translates the origin of the graphics context to the point
127 * (<i>x</i>, <i>y</i>) in the current coordinate system.
128 * Modifies this graphics context so that its new origin corresponds
129 * to the point (<i>x</i>, <i>y</i>) in this graphics context's
130 * original coordinate system. All coordinates used in subsequent
131 * rendering operations on this graphics context will be relative
132 * to this new origin.
133 * @param x the <i>x</i> coordinate.
134 * @param y the <i>y</i> coordinate.
135 * @since 1.0
363
364
365 /**
366 * Sets the current clip to the rectangle specified by the given
367 * coordinates.
368 * Rendering operations have no effect outside of the clipping area.
369 * @param x the <i>x</i> coordinate of the new clip rectangle.
370 * @param y the <i>y</i> coordinate of the new clip rectangle.
371 * @param width the width of the new clip rectangle.
372 * @param height the height of the new clip rectangle.
373 * @see java.awt.Graphics#clipRect
374 * @see java.awt.Graphics#setClip(Shape)
375 * @since 1.1
376 */
377 public void setClip(int x, int y, int width, int height) {
378 mGraphics.setClip(x, y, width, height);
379 }
380
381 /**
382 * Gets the current clipping area.
383 * @return a <code>Shape</code> object representing the
384 * current clipping area.
385 * @see java.awt.Graphics#getClipBounds
386 * @see java.awt.Graphics#clipRect
387 * @see java.awt.Graphics#setClip(int, int, int, int)
388 * @see java.awt.Graphics#setClip(Shape)
389 * @since 1.1
390 */
391 public Shape getClip() {
392 return mGraphics.getClip();
393 }
394
395
396 /**
397 * Sets the current clipping area to an arbitrary clip shape.
398 * Not all objects which implement the <code>Shape</code>
399 * interface can be used to set the clip. The only
400 * <code>Shape</code> objects which are guaranteed to be
401 * supported are <code>Shape</code> objects which are
402 * obtained via the <code>getClip</code> method and via
403 * <code>Rectangle</code> objects.
404 * @see java.awt.Graphics#getClip()
405 * @see java.awt.Graphics#clipRect
406 * @see java.awt.Graphics#setClip(int, int, int, int)
407 * @since 1.1
408 */
409 public void setClip(Shape clip) {
410 mGraphics.setClip(clip);
411 }
412
413
414 /**
415 * Copies an area of the component by a distance specified by
416 * <code>dx</code> and <code>dy</code>. From the point specified
417 * by <code>x</code> and <code>y</code>, this method
418 * copies downwards and to the right. To copy an area of the
419 * component to the left or upwards, specify a negative value for
420 * <code>dx</code> or <code>dy</code>.
421 * If a portion of the source rectangle lies outside the bounds
422 * of the component, or is obscured by another window or component,
423 * <code>copyArea</code> will be unable to copy the associated
424 * pixels. The area that is omitted can be refreshed by calling
425 * the component's <code>paint</code> method.
426 * @param x the <i>x</i> coordinate of the source rectangle.
427 * @param y the <i>y</i> coordinate of the source rectangle.
428 * @param width the width of the source rectangle.
429 * @param height the height of the source rectangle.
430 * @param dx the horizontal distance to copy the pixels.
431 * @param dy the vertical distance to copy the pixels.
432 * @since 1.0
433 */
434 public void copyArea(int x, int y, int width, int height,
435 int dx, int dy) {
436 mGraphics.copyArea(x, y, width, height, dx, dy);
437 }
438
439 /**
440 * Draws a line, using the current color, between the points
441 * <code>(x1, y1)</code> and <code>(x2, y2)</code>
442 * in this graphics context's coordinate system.
443 * @param x1 the first point's <i>x</i> coordinate.
444 * @param y1 the first point's <i>y</i> coordinate.
445 * @param x2 the second point's <i>x</i> coordinate.
446 * @param y2 the second point's <i>y</i> coordinate.
447 * @since 1.0
448 */
449 public void drawLine(int x1, int y1, int x2, int y2) {
450 mGraphics.drawLine(x1, y1, x2, y2);
451 }
452
453
454 /**
455 * Fills the specified rectangle.
456 * The left and right edges of the rectangle are at
457 * <code>x</code> and <code>x + width - 1</code>.
458 * The top and bottom edges are at
459 * <code>y</code> and <code>y + height - 1</code>.
460 * The resulting rectangle covers an area
461 * <code>width</code> pixels wide by
462 * <code>height</code> pixels tall.
463 * The rectangle is filled using the graphics context's current color.
464 * @param x the <i>x</i> coordinate
465 * of the rectangle to be filled.
466 * @param y the <i>y</i> coordinate
467 * of the rectangle to be filled.
468 * @param width the width of the rectangle to be filled.
469 * @param height the height of the rectangle to be filled.
470 * @see java.awt.Graphics#fillRect
471 * @see java.awt.Graphics#clearRect
472 * @since 1.0
473 */
474 public void fillRect(int x, int y, int width, int height) {
475 mGraphics.fillRect(x, y, width, height);
476 }
477
478 /**
479 * Clears the specified rectangle by filling it with the background
480 * color of the current drawing surface. This operation does not
481 * use the current paint mode.
482 * <p>
483 * Beginning with Java 1.1, the background color
484 * of offscreen images may be system dependent. Applications should
485 * use <code>setColor</code> followed by <code>fillRect</code> to
486 * ensure that an offscreen image is cleared to a specific color.
487 * @param x the <i>x</i> coordinate of the rectangle to clear.
488 * @param y the <i>y</i> coordinate of the rectangle to clear.
489 * @param width the width of the rectangle to clear.
490 * @param height the height of the rectangle to clear.
491 * @see java.awt.Graphics#fillRect(int, int, int, int)
492 * @see java.awt.Graphics#drawRect
493 * @see java.awt.Graphics#setColor(java.awt.Color)
494 * @see java.awt.Graphics#setPaintMode
495 * @see java.awt.Graphics#setXORMode(java.awt.Color)
496 * @since 1.0
497 */
498 public void clearRect(int x, int y, int width, int height) {
499 mGraphics.clearRect(x, y, width, height);
500 }
501
502 /**
503 * Draws an outlined round-cornered rectangle using this graphics
504 * context's current color. The left and right edges of the rectangle
505 * are at <code>x</code> and <code>x + width</code>,
506 * respectively. The top and bottom edges of the rectangle are at
507 * <code>y</code> and <code>y + height</code>.
508 * @param x the <i>x</i> coordinate of the rectangle to be drawn.
509 * @param y the <i>y</i> coordinate of the rectangle to be drawn.
510 * @param width the width of the rectangle to be drawn.
511 * @param height the height of the rectangle to be drawn.
512 * @param arcWidth the horizontal diameter of the arc
513 * at the four corners.
514 * @param arcHeight the vertical diameter of the arc
515 * at the four corners.
516 * @see java.awt.Graphics#fillRoundRect
517 * @since 1.0
518 */
519 public void drawRoundRect(int x, int y, int width, int height,
520 int arcWidth, int arcHeight) {
521 mGraphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
522 }
523
524 /**
525 * Fills the specified rounded corner rectangle with the current color.
526 * The left and right edges of the rectangle
527 * are at <code>x</code> and <code>x + width - 1</code>,
528 * respectively. The top and bottom edges of the rectangle are at
529 * <code>y</code> and <code>y + height - 1</code>.
530 * @param x the <i>x</i> coordinate of the rectangle to be filled.
531 * @param y the <i>y</i> coordinate of the rectangle to be filled.
532 * @param width the width of the rectangle to be filled.
533 * @param height the height of the rectangle to be filled.
534 * @param arcWidth the horizontal diameter
535 * of the arc at the four corners.
536 * @param arcHeight the vertical diameter
537 * of the arc at the four corners.
538 * @see java.awt.Graphics#drawRoundRect
539 * @since 1.0
540 */
541 public void fillRoundRect(int x, int y, int width, int height,
542 int arcWidth, int arcHeight) {
543 mGraphics.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
544 }
545
546 /**
547 * Draws the outline of an oval.
548 * The result is a circle or ellipse that fits within the
549 * rectangle specified by the <code>x</code>, <code>y</code>,
550 * <code>width</code>, and <code>height</code> arguments.
551 * <p>
552 * The oval covers an area that is
553 * <code>width + 1</code> pixels wide
554 * and <code>height + 1</code> pixels tall.
555 * @param x the <i>x</i> coordinate of the upper left
556 * corner of the oval to be drawn.
557 * @param y the <i>y</i> coordinate of the upper left
558 * corner of the oval to be drawn.
559 * @param width the width of the oval to be drawn.
560 * @param height the height of the oval to be drawn.
561 * @see java.awt.Graphics#fillOval
562 * @since 1.0
563 */
564 public void drawOval(int x, int y, int width, int height) {
565 mGraphics.drawOval(x, y, width, height);
566 }
567
568 /**
569 * Fills an oval bounded by the specified rectangle with the
570 * current color.
571 * @param x the <i>x</i> coordinate of the upper left corner
572 * of the oval to be filled.
573 * @param y the <i>y</i> coordinate of the upper left corner
574 * of the oval to be filled.
575 * @param width the width of the oval to be filled.
576 * @param height the height of the oval to be filled.
577 * @see java.awt.Graphics#drawOval
578 * @since 1.0
579 */
580 public void fillOval(int x, int y, int width, int height) {
581 mGraphics.fillOval(x, y, width, height);
582 }
583
584 /**
585 * Draws the outline of a circular or elliptical arc
586 * covering the specified rectangle.
587 * <p>
588 * The resulting arc begins at <code>startAngle</code> and extends
589 * for <code>arcAngle</code> degrees, using the current color.
590 * Angles are interpreted such that 0 degrees
591 * is at the 3 o'clock position.
592 * A positive value indicates a counter-clockwise rotation
593 * while a negative value indicates a clockwise rotation.
594 * <p>
595 * The center of the arc is the center of the rectangle whose origin
596 * is (<i>x</i>, <i>y</i>) and whose size is specified by the
597 * <code>width</code> and <code>height</code> arguments.
598 * <p>
599 * The resulting arc covers an area
600 * <code>width + 1</code> pixels wide
601 * by <code>height + 1</code> pixels tall.
602 * @param x the <i>x</i> coordinate of the
603 * upper-left corner of the arc to be drawn.
604 * @param y the <i>y</i> coordinate of the
605 * upper-left corner of the arc to be drawn.
606 * @param width the width of the arc to be drawn.
607 * @param height the height of the arc to be drawn.
608 * @param startAngle the beginning angle.
609 * @param arcAngle the angular extent of the arc,
610 * relative to the start angle.
611 * @see java.awt.Graphics#fillArc
612 * @since 1.0
613 */
614 public void drawArc(int x, int y, int width, int height,
615 int startAngle, int arcAngle) {
616 mGraphics.drawArc(x, y, width, height, startAngle, arcAngle);
617 }
618
619 /**
620 * Fills a circular or elliptical arc covering the specified rectangle.
621 * <p>
622 * The resulting arc begins at <code>startAngle</code> and extends
623 * for <code>arcAngle</code> degrees.
624 * Angles are interpreted such that 0 degrees
625 * is at the 3 o'clock position.
626 * A positive value indicates a counter-clockwise rotation
627 * while a negative value indicates a clockwise rotation.
628 * <p>
629 * The center of the arc is the center of the rectangle whose origin
630 * is (<i>x</i>, <i>y</i>) and whose size is specified by the
631 * <code>width</code> and <code>height</code> arguments.
632 * <p>
633 * The resulting arc covers an area
634 * <code>width + 1</code> pixels wide
635 * by <code>height + 1</code> pixels tall.
636 * @param x the <i>x</i> coordinate of the
637 * upper-left corner of the arc to be filled.
638 * @param y the <i>y</i> coordinate of the
639 * upper-left corner of the arc to be filled.
640 * @param width the width of the arc to be filled.
641 * @param height the height of the arc to be filled.
642 * @param startAngle the beginning angle.
643 * @param arcAngle the angular extent of the arc,
644 * relative to the start angle.
645 * @see java.awt.Graphics#drawArc
646 * @since 1.0
647 */
648 public void fillArc(int x, int y, int width, int height,
649 int startAngle, int arcAngle) {
650 mGraphics.fillArc(x, y, width, height, startAngle, arcAngle);
651 }
655 * arrays of <i>x</i> and <i>y</i> coordinates.
656 * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
657 * The figure is not closed if the first point
658 * differs from the last point.
659 * @param xPoints an array of <i>x</i> points
660 * @param yPoints an array of <i>y</i> points
661 * @param nPoints the total number of points
662 * @see java.awt.Graphics#drawPolygon(int[], int[], int)
663 * @since 1.1
664 */
665 public void drawPolyline(int xPoints[], int yPoints[],
666 int nPoints) {
667 mGraphics.drawPolyline(xPoints, yPoints, nPoints);
668 }
669
670 /**
671 * Draws a closed polygon defined by
672 * arrays of <i>x</i> and <i>y</i> coordinates.
673 * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
674 * <p>
675 * This method draws the polygon defined by <code>nPoint</code> line
676 * segments, where the first <code>nPoint - 1</code>
677 * line segments are line segments from
678 * <code>(xPoints[i - 1], yPoints[i - 1])</code>
679 * to <code>(xPoints[i], yPoints[i])</code>, for
680 * 1 ≤ <i>i</i> ≤ <code>nPoints</code>.
681 * The figure is automatically closed by drawing a line connecting
682 * the final point to the first point, if those points are different.
683 * @param xPoints a an array of <code>x</code> coordinates.
684 * @param yPoints a an array of <code>y</code> coordinates.
685 * @param nPoints a the total number of points.
686 * @see java.awt.Graphics#fillPolygon
687 * @see java.awt.Graphics#drawPolyline
688 * @since 1.0
689 */
690 public void drawPolygon(int xPoints[], int yPoints[],
691 int nPoints) {
692 mGraphics.drawPolygon(xPoints, yPoints, nPoints);
693 }
694
695 /**
696 * Fills a closed polygon defined by
697 * arrays of <i>x</i> and <i>y</i> coordinates.
698 * <p>
699 * This method draws the polygon defined by <code>nPoint</code> line
700 * segments, where the first <code>nPoint - 1</code>
701 * line segments are line segments from
702 * <code>(xPoints[i - 1], yPoints[i - 1])</code>
703 * to <code>(xPoints[i], yPoints[i])</code>, for
704 * 1 ≤ <i>i</i> ≤ <code>nPoints</code>.
705 * The figure is automatically closed by drawing a line connecting
706 * the final point to the first point, if those points are different.
707 * <p>
708 * The area inside the polygon is defined using an
709 * even-odd fill rule, also known as the alternating rule.
710 * @param xPoints a an array of <code>x</code> coordinates.
711 * @param yPoints a an array of <code>y</code> coordinates.
712 * @param nPoints a the total number of points.
713 * @see java.awt.Graphics#drawPolygon(int[], int[], int)
714 * @since 1.0
715 */
716 public void fillPolygon(int xPoints[], int yPoints[],
717 int nPoints) {
718 mGraphics.fillPolygon(xPoints, yPoints, nPoints);
719 }
720
721 /**
722 * Draws the text given by the specified string, using this
723 * graphics context's current font and color. The baseline of the
724 * first character is at position (<i>x</i>, <i>y</i>) in this
725 * graphics context's coordinate system.
726 * @param str the string to be drawn.
727 * @param x the <i>x</i> coordinate.
728 * @param y the <i>y</i> coordinate.
729 * @see java.awt.Graphics#drawBytes
730 * @see java.awt.Graphics#drawChars
731 * @since 1.0
779 * @see #setComposite
780 * @see #setClip
781 */
782 public void drawString(AttributedCharacterIterator iterator,
783 float x, float y) {
784 mGraphics.drawString(iterator, x, y);
785 }
786
787 /**
788 * Draws as much of the specified image as is currently available.
789 * The image is drawn with its top-left corner at
790 * (<i>x</i>, <i>y</i>) in this graphics context's coordinate
791 * space. Transparent pixels in the image do not affect whatever
792 * pixels are already there.
793 * <p>
794 * This method returns immediately in all cases, even if the
795 * complete image has not yet been loaded, and it has not been dithered
796 * and converted for the current output device.
797 * <p>
798 * If the image has not yet been completely loaded, then
799 * <code>drawImage</code> returns <code>false</code>. As more of
800 * the image becomes available, the process that draws the image notifies
801 * the specified image observer.
802 * @param img the specified image to be drawn.
803 * @param x the <i>x</i> coordinate.
804 * @param y the <i>y</i> coordinate.
805 * @param observer object to be notified as more of
806 * the image is converted.
807 * @see java.awt.Image
808 * @see java.awt.image.ImageObserver
809 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
810 * @since 1.0
811 */
812 public boolean drawImage(Image img, int x, int y,
813 ImageObserver observer) {
814
815 return mGraphics.drawImage(img, x, y, observer);
816 }
817
818 /**
819 * Draws as much of the specified image as has already been scaled
820 * to fit inside the specified rectangle.
821 * <p>
822 * The image is drawn inside the specified rectangle of this
823 * graphics context's coordinate space, and is scaled if
824 * necessary. Transparent pixels do not affect whatever pixels
825 * are already there.
826 * <p>
827 * This method returns immediately in all cases, even if the
828 * entire image has not yet been scaled, dithered, and converted
829 * for the current output device.
830 * If the current output representation is not yet complete, then
831 * <code>drawImage</code> returns <code>false</code>. As more of
832 * the image becomes available, the process that draws the image notifies
833 * the image observer by calling its <code>imageUpdate</code> method.
834 * <p>
835 * A scaled version of an image will not necessarily be
836 * available immediately just because an unscaled version of the
837 * image has been constructed for this output device. Each size of
838 * the image may be cached separately and generated from the original
839 * data in a separate image production sequence.
840 * @param img the specified image to be drawn.
841 * @param x the <i>x</i> coordinate.
842 * @param y the <i>y</i> coordinate.
843 * @param width the width of the rectangle.
844 * @param height the height of the rectangle.
845 * @param observer object to be notified as more of
846 * the image is converted.
847 * @see java.awt.Image
848 * @see java.awt.image.ImageObserver
849 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
850 * @since 1.0
851 */
852 public boolean drawImage(Image img, int x, int y,
853 int width, int height,
855
856 return mGraphics.drawImage(img, x, y, width, height, observer);
857 }
858
859 /**
860 * Draws as much of the specified image as is currently available.
861 * The image is drawn with its top-left corner at
862 * (<i>x</i>, <i>y</i>) in this graphics context's coordinate
863 * space. Transparent pixels are drawn in the specified
864 * background color.
865 * <p>
866 * This operation is equivalent to filling a rectangle of the
867 * width and height of the specified image with the given color and then
868 * drawing the image on top of it, but possibly more efficient.
869 * <p>
870 * This method returns immediately in all cases, even if the
871 * complete image has not yet been loaded, and it has not been dithered
872 * and converted for the current output device.
873 * <p>
874 * If the image has not yet been completely loaded, then
875 * <code>drawImage</code> returns <code>false</code>. As more of
876 * the image becomes available, the process that draws the image notifies
877 * the specified image observer.
878 * @param img the specified image to be drawn.
879 * @param x the <i>x</i> coordinate.
880 * @param y the <i>y</i> coordinate.
881 * @param bgcolor the background color to paint under the
882 * non-opaque portions of the image.
883 * @param observer object to be notified as more of
884 * the image is converted.
885 * @see java.awt.Image
886 * @see java.awt.image.ImageObserver
887 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
888 * @since 1.0
889 */
890 public boolean drawImage(Image img, int x, int y,
891 Color bgcolor,
892 ImageObserver observer) {
893
894 if (img == null) {
895 return true;
906
907 return result;
908 }
909
910 /**
911 * Draws as much of the specified image as has already been scaled
912 * to fit inside the specified rectangle.
913 * <p>
914 * The image is drawn inside the specified rectangle of this
915 * graphics context's coordinate space, and is scaled if
916 * necessary. Transparent pixels are drawn in the specified
917 * background color.
918 * This operation is equivalent to filling a rectangle of the
919 * width and height of the specified image with the given color and then
920 * drawing the image on top of it, but possibly more efficient.
921 * <p>
922 * This method returns immediately in all cases, even if the
923 * entire image has not yet been scaled, dithered, and converted
924 * for the current output device.
925 * If the current output representation is not yet complete then
926 * <code>drawImage</code> returns <code>false</code>. As more of
927 * the image becomes available, the process that draws the image notifies
928 * the specified image observer.
929 * <p>
930 * A scaled version of an image will not necessarily be
931 * available immediately just because an unscaled version of the
932 * image has been constructed for this output device. Each size of
933 * the image may be cached separately and generated from the original
934 * data in a separate image production sequence.
935 * @param img the specified image to be drawn.
936 * @param x the <i>x</i> coordinate.
937 * @param y the <i>y</i> coordinate.
938 * @param width the width of the rectangle.
939 * @param height the height of the rectangle.
940 * @param bgcolor the background color to paint under the
941 * non-opaque portions of the image.
942 * @param observer object to be notified as more of
943 * the image is converted.
944 * @see java.awt.Image
945 * @see java.awt.image.ImageObserver
946 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
961 BufferedImage imageCopy = getBufferedImageCopy(img, bgcolor);
962 result = mGraphics.drawImage(imageCopy, x, y, width, height, null);
963 } else {
964 result = mGraphics.drawImage(img, x, y, width, height,
965 bgcolor, observer);
966 }
967
968 return result;
969 }
970
971 /**
972 * Draws as much of the specified area of the specified image as is
973 * currently available, scaling it on the fly to fit inside the
974 * specified area of the destination drawable surface. Transparent pixels
975 * do not affect whatever pixels are already there.
976 * <p>
977 * This method returns immediately in all cases, even if the
978 * image area to be drawn has not yet been scaled, dithered, and converted
979 * for the current output device.
980 * If the current output representation is not yet complete then
981 * <code>drawImage</code> returns <code>false</code>. As more of
982 * the image becomes available, the process that draws the image notifies
983 * the specified image observer.
984 * <p>
985 * This method always uses the unscaled version of the image
986 * to render the scaled rectangle and performs the required
987 * scaling on the fly. It does not use a cached, scaled version
988 * of the image for this operation. Scaling of the image from source
989 * to destination is performed such that the first coordinate
990 * of the source rectangle is mapped to the first coordinate of
991 * the destination rectangle, and the second source coordinate is
992 * mapped to the second destination coordinate. The subimage is
993 * scaled and flipped as needed to preserve those mappings.
994 * @param img the specified image to be drawn
995 * @param dx1 the <i>x</i> coordinate of the first corner of the
996 * destination rectangle.
997 * @param dy1 the <i>y</i> coordinate of the first corner of the
998 * destination rectangle.
999 * @param dx2 the <i>x</i> coordinate of the second corner of the
1000 * destination rectangle.
1001 * @param dy2 the <i>y</i> coordinate of the second corner of the
1021 ImageObserver observer) {
1022 return mGraphics.drawImage(img, dx1, dy1, dx2, dy2,
1023 sx1, sy1, sx2, sy2,
1024 observer);
1025 }
1026
1027 /**
1028 * Draws as much of the specified area of the specified image as is
1029 * currently available, scaling it on the fly to fit inside the
1030 * specified area of the destination drawable surface.
1031 * <p>
1032 * Transparent pixels are drawn in the specified background color.
1033 * This operation is equivalent to filling a rectangle of the
1034 * width and height of the specified image with the given color and then
1035 * drawing the image on top of it, but possibly more efficient.
1036 * <p>
1037 * This method returns immediately in all cases, even if the
1038 * image area to be drawn has not yet been scaled, dithered, and converted
1039 * for the current output device.
1040 * If the current output representation is not yet complete then
1041 * <code>drawImage</code> returns <code>false</code>. As more of
1042 * the image becomes available, the process that draws the image notifies
1043 * the specified image observer.
1044 * <p>
1045 * This method always uses the unscaled version of the image
1046 * to render the scaled rectangle and performs the required
1047 * scaling on the fly. It does not use a cached, scaled version
1048 * of the image for this operation. Scaling of the image from source
1049 * to destination is performed such that the first coordinate
1050 * of the source rectangle is mapped to the first coordinate of
1051 * the destination rectangle, and the second source coordinate is
1052 * mapped to the second destination coordinate. The subimage is
1053 * scaled and flipped as needed to preserve those mappings.
1054 * @param img the specified image to be drawn
1055 * @param dx1 the <i>x</i> coordinate of the first corner of the
1056 * destination rectangle.
1057 * @param dy1 the <i>y</i> coordinate of the first corner of the
1058 * destination rectangle.
1059 * @param dx2 the <i>x</i> coordinate of the second corner of the
1060 * destination rectangle.
1061 * @param dy2 the <i>y</i> coordinate of the second corner of the
1089
1090 boolean result;
1091 if (needToCopyBgColorImage(img)) {
1092 BufferedImage imageCopy = getBufferedImageCopy(img, bgcolor);
1093 result = mGraphics.drawImage(imageCopy,
1094 dx1, dy1, dx2, dy2,
1095 sy1, sy1, sx2, sy2,
1096 null);
1097 } else {
1098 result = mGraphics.drawImage(img,
1099 dx1, dy1, dx2, dy2,
1100 sy1, sy1, sx2, sy2,
1101 bgcolor,
1102 observer);
1103 }
1104
1105 return result;
1106 }
1107
1108 /**
1109 * Return true if drawing <code>img</code> will
1110 * invoke a Java2D bug (#4258675). The bug in question
1111 * occurs when a draw image call with a background color
1112 * parameter tries to render a sheared
1113 * or rotated image. The portions of the bounding
1114 * rectangle not covered by the sheared image
1115 * are incorrectly drawn with the background color.
1116 */
1117 private boolean needToCopyBgColorImage(Image img) {
1118
1119 boolean needToCopy;
1120
1121 AffineTransform transform = getTransform();
1122
1123 return (transform.getType()
1124 & (AffineTransform.TYPE_GENERAL_ROTATION
1125 | AffineTransform.TYPE_GENERAL_TRANSFORM)) != 0;
1126 }
1127
1128 /**
1129 * Return a new <code>BufferedImage</code>
1130 * that contains a copy of the provided
1131 * <code>Image</code> where its
1132 * transparent pixels have been replaced by
1133 * <code>bgcolor</code>. If the new
1134 * <code>BufferedImage</code> can not be created,
1135 * probably because the original image has not
1136 * finished loading, then <code>null</code> is
1137 * returned.
1138 */
1139 private BufferedImage getBufferedImageCopy(Image img, Color bgcolor) {
1140
1141 BufferedImage imageCopy = null;
1142
1143 int width = img.getWidth(null);
1144 int height = img.getHeight(null);
1145
1146 if (width > 0 && height > 0) {
1147
1148 int imageType;
1149
1150 /* Try to minimize the depth of the BufferedImage
1151 * we are about to create by, if possible, making
1152 * it the same depth as the original image.
1153 */
1154 if (img instanceof BufferedImage) {
1155 BufferedImage bufImage = (BufferedImage) img;
1156 imageType = bufImage.getType();
1215 AffineTransform concatTransform = new AffineTransform(xform);
1216 concatTransform.concatenate(pipeTransform);
1217 AffineTransform reverseTransform;
1218
1219 RenderContext rc = new RenderContext(concatTransform);
1220
1221 try {
1222 reverseTransform = pipeTransform.createInverse();
1223 } catch (NoninvertibleTransformException nte) {
1224 rc = new RenderContext(pipeTransform);
1225 reverseTransform = new AffineTransform();
1226 }
1227
1228 RenderedImage rendering = img.createRendering(rc);
1229 drawRenderedImage(rendering,reverseTransform);
1230 }
1231
1232 /**
1233 * Disposes of this graphics context and releases
1234 * any system resources that it is using.
1235 * A <code>Graphics</code> object cannot be used after
1236 * <code>dispose</code>has been called.
1237 * <p>
1238 * When a Java program runs, a large number of <code>Graphics</code>
1239 * objects can be created within a short time frame.
1240 * Although the finalization process of the garbage collector
1241 * also disposes of the same system resources, it is preferable
1242 * to manually free the associated resources by calling this
1243 * method rather than to rely on a finalization process which
1244 * may not run to completion for a long period of time.
1245 * <p>
1246 * Graphics objects which are provided as arguments to the
1247 * <code>paint</code> and <code>update</code> methods
1248 * of components are automatically released by the system when
1249 * those methods return. For efficiency, programmers should
1250 * call <code>dispose</code> when finished using
1251 * a <code>Graphics</code> object only if it was created
1252 * directly from a component or another <code>Graphics</code> object.
1253 * @see java.awt.Graphics#finalize
1254 * @see java.awt.Component#paint
1255 * @see java.awt.Component#update
1256 * @see java.awt.Component#getGraphics
1257 * @see java.awt.Graphics#create
1258 * @since 1.0
1259 */
1260 public void dispose() {
1261 mGraphics.dispose();
1262 }
1263
1264 /**
1265 * Empty finalizer as no clean up needed here.
1266 */
1267 public void finalize() {
1268 }
1269
1270
1271 /* The Delegated Graphics2D Methods */
1272
|
94 * drawing.
95 */
96 public void setDelegate(Graphics2D graphics) {
97 mGraphics = graphics;
98 }
99
100 public PrinterJob getPrinterJob() {
101 return mPrinterJob;
102 }
103
104 /**
105 * Returns the device configuration associated with this Graphics2D.
106 */
107 public GraphicsConfiguration getDeviceConfiguration() {
108 return ((RasterPrinterJob)mPrinterJob).getPrinterGraphicsConfig();
109 }
110
111 /* The Delegated Graphics Methods */
112
113 /**
114 * Creates a new {@code Graphics} object that is
115 * a copy of this {@code Graphics} object.
116 * @return a new graphics context that is a copy of
117 * this graphics context.
118 * @since 1.0
119 */
120 public Graphics create() {
121 return new ProxyGraphics2D((Graphics2D) mGraphics.create(),
122 mPrinterJob);
123 }
124
125 /**
126 * Translates the origin of the graphics context to the point
127 * (<i>x</i>, <i>y</i>) in the current coordinate system.
128 * Modifies this graphics context so that its new origin corresponds
129 * to the point (<i>x</i>, <i>y</i>) in this graphics context's
130 * original coordinate system. All coordinates used in subsequent
131 * rendering operations on this graphics context will be relative
132 * to this new origin.
133 * @param x the <i>x</i> coordinate.
134 * @param y the <i>y</i> coordinate.
135 * @since 1.0
363
364
365 /**
366 * Sets the current clip to the rectangle specified by the given
367 * coordinates.
368 * Rendering operations have no effect outside of the clipping area.
369 * @param x the <i>x</i> coordinate of the new clip rectangle.
370 * @param y the <i>y</i> coordinate of the new clip rectangle.
371 * @param width the width of the new clip rectangle.
372 * @param height the height of the new clip rectangle.
373 * @see java.awt.Graphics#clipRect
374 * @see java.awt.Graphics#setClip(Shape)
375 * @since 1.1
376 */
377 public void setClip(int x, int y, int width, int height) {
378 mGraphics.setClip(x, y, width, height);
379 }
380
381 /**
382 * Gets the current clipping area.
383 * @return a {@code Shape} object representing the
384 * current clipping area.
385 * @see java.awt.Graphics#getClipBounds
386 * @see java.awt.Graphics#clipRect
387 * @see java.awt.Graphics#setClip(int, int, int, int)
388 * @see java.awt.Graphics#setClip(Shape)
389 * @since 1.1
390 */
391 public Shape getClip() {
392 return mGraphics.getClip();
393 }
394
395
396 /**
397 * Sets the current clipping area to an arbitrary clip shape.
398 * Not all objects which implement the {@code Shape}
399 * interface can be used to set the clip. The only
400 * {@code Shape} objects which are guaranteed to be
401 * supported are {@code Shape} objects which are
402 * obtained via the {@code getClip} method and via
403 * {@code Rectangle} objects.
404 * @see java.awt.Graphics#getClip()
405 * @see java.awt.Graphics#clipRect
406 * @see java.awt.Graphics#setClip(int, int, int, int)
407 * @since 1.1
408 */
409 public void setClip(Shape clip) {
410 mGraphics.setClip(clip);
411 }
412
413
414 /**
415 * Copies an area of the component by a distance specified by
416 * {@code dx} and {@code dy}. From the point specified
417 * by {@code x} and {@code y}, this method
418 * copies downwards and to the right. To copy an area of the
419 * component to the left or upwards, specify a negative value for
420 * {@code dx} or {@code dy}.
421 * If a portion of the source rectangle lies outside the bounds
422 * of the component, or is obscured by another window or component,
423 * {@code copyArea} will be unable to copy the associated
424 * pixels. The area that is omitted can be refreshed by calling
425 * the component's {@code paint} method.
426 * @param x the <i>x</i> coordinate of the source rectangle.
427 * @param y the <i>y</i> coordinate of the source rectangle.
428 * @param width the width of the source rectangle.
429 * @param height the height of the source rectangle.
430 * @param dx the horizontal distance to copy the pixels.
431 * @param dy the vertical distance to copy the pixels.
432 * @since 1.0
433 */
434 public void copyArea(int x, int y, int width, int height,
435 int dx, int dy) {
436 mGraphics.copyArea(x, y, width, height, dx, dy);
437 }
438
439 /**
440 * Draws a line, using the current color, between the points
441 * <code>(x1, y1)</code> and <code>(x2, y2)</code>
442 * in this graphics context's coordinate system.
443 * @param x1 the first point's <i>x</i> coordinate.
444 * @param y1 the first point's <i>y</i> coordinate.
445 * @param x2 the second point's <i>x</i> coordinate.
446 * @param y2 the second point's <i>y</i> coordinate.
447 * @since 1.0
448 */
449 public void drawLine(int x1, int y1, int x2, int y2) {
450 mGraphics.drawLine(x1, y1, x2, y2);
451 }
452
453
454 /**
455 * Fills the specified rectangle.
456 * The left and right edges of the rectangle are at
457 * {@code x} and <code>x + width - 1</code>.
458 * The top and bottom edges are at
459 * {@code y} and <code>y + height - 1</code>.
460 * The resulting rectangle covers an area
461 * {@code width} pixels wide by
462 * {@code height} pixels tall.
463 * The rectangle is filled using the graphics context's current color.
464 * @param x the <i>x</i> coordinate
465 * of the rectangle to be filled.
466 * @param y the <i>y</i> coordinate
467 * of the rectangle to be filled.
468 * @param width the width of the rectangle to be filled.
469 * @param height the height of the rectangle to be filled.
470 * @see java.awt.Graphics#fillRect
471 * @see java.awt.Graphics#clearRect
472 * @since 1.0
473 */
474 public void fillRect(int x, int y, int width, int height) {
475 mGraphics.fillRect(x, y, width, height);
476 }
477
478 /**
479 * Clears the specified rectangle by filling it with the background
480 * color of the current drawing surface. This operation does not
481 * use the current paint mode.
482 * <p>
483 * Beginning with Java 1.1, the background color
484 * of offscreen images may be system dependent. Applications should
485 * use {@code setColor} followed by {@code fillRect} to
486 * ensure that an offscreen image is cleared to a specific color.
487 * @param x the <i>x</i> coordinate of the rectangle to clear.
488 * @param y the <i>y</i> coordinate of the rectangle to clear.
489 * @param width the width of the rectangle to clear.
490 * @param height the height of the rectangle to clear.
491 * @see java.awt.Graphics#fillRect(int, int, int, int)
492 * @see java.awt.Graphics#drawRect
493 * @see java.awt.Graphics#setColor(java.awt.Color)
494 * @see java.awt.Graphics#setPaintMode
495 * @see java.awt.Graphics#setXORMode(java.awt.Color)
496 * @since 1.0
497 */
498 public void clearRect(int x, int y, int width, int height) {
499 mGraphics.clearRect(x, y, width, height);
500 }
501
502 /**
503 * Draws an outlined round-cornered rectangle using this graphics
504 * context's current color. The left and right edges of the rectangle
505 * are at {@code x} and <code>x + width</code>,
506 * respectively. The top and bottom edges of the rectangle are at
507 * {@code y} and <code>y + height</code>.
508 * @param x the <i>x</i> coordinate of the rectangle to be drawn.
509 * @param y the <i>y</i> coordinate of the rectangle to be drawn.
510 * @param width the width of the rectangle to be drawn.
511 * @param height the height of the rectangle to be drawn.
512 * @param arcWidth the horizontal diameter of the arc
513 * at the four corners.
514 * @param arcHeight the vertical diameter of the arc
515 * at the four corners.
516 * @see java.awt.Graphics#fillRoundRect
517 * @since 1.0
518 */
519 public void drawRoundRect(int x, int y, int width, int height,
520 int arcWidth, int arcHeight) {
521 mGraphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
522 }
523
524 /**
525 * Fills the specified rounded corner rectangle with the current color.
526 * The left and right edges of the rectangle
527 * are at {@code x} and <code>x + width - 1</code>,
528 * respectively. The top and bottom edges of the rectangle are at
529 * {@code y} and <code>y + height - 1</code>.
530 * @param x the <i>x</i> coordinate of the rectangle to be filled.
531 * @param y the <i>y</i> coordinate of the rectangle to be filled.
532 * @param width the width of the rectangle to be filled.
533 * @param height the height of the rectangle to be filled.
534 * @param arcWidth the horizontal diameter
535 * of the arc at the four corners.
536 * @param arcHeight the vertical diameter
537 * of the arc at the four corners.
538 * @see java.awt.Graphics#drawRoundRect
539 * @since 1.0
540 */
541 public void fillRoundRect(int x, int y, int width, int height,
542 int arcWidth, int arcHeight) {
543 mGraphics.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
544 }
545
546 /**
547 * Draws the outline of an oval.
548 * The result is a circle or ellipse that fits within the
549 * rectangle specified by the {@code x}, {@code y},
550 * {@code width}, and {@code height} arguments.
551 * <p>
552 * The oval covers an area that is
553 * <code>width + 1</code> pixels wide
554 * and <code>height + 1</code> pixels tall.
555 * @param x the <i>x</i> coordinate of the upper left
556 * corner of the oval to be drawn.
557 * @param y the <i>y</i> coordinate of the upper left
558 * corner of the oval to be drawn.
559 * @param width the width of the oval to be drawn.
560 * @param height the height of the oval to be drawn.
561 * @see java.awt.Graphics#fillOval
562 * @since 1.0
563 */
564 public void drawOval(int x, int y, int width, int height) {
565 mGraphics.drawOval(x, y, width, height);
566 }
567
568 /**
569 * Fills an oval bounded by the specified rectangle with the
570 * current color.
571 * @param x the <i>x</i> coordinate of the upper left corner
572 * of the oval to be filled.
573 * @param y the <i>y</i> coordinate of the upper left corner
574 * of the oval to be filled.
575 * @param width the width of the oval to be filled.
576 * @param height the height of the oval to be filled.
577 * @see java.awt.Graphics#drawOval
578 * @since 1.0
579 */
580 public void fillOval(int x, int y, int width, int height) {
581 mGraphics.fillOval(x, y, width, height);
582 }
583
584 /**
585 * Draws the outline of a circular or elliptical arc
586 * covering the specified rectangle.
587 * <p>
588 * The resulting arc begins at {@code startAngle} and extends
589 * for {@code arcAngle} degrees, using the current color.
590 * Angles are interpreted such that 0 degrees
591 * is at the 3 o'clock position.
592 * A positive value indicates a counter-clockwise rotation
593 * while a negative value indicates a clockwise rotation.
594 * <p>
595 * The center of the arc is the center of the rectangle whose origin
596 * is (<i>x</i>, <i>y</i>) and whose size is specified by the
597 * {@code width} and {@code height} arguments.
598 * <p>
599 * The resulting arc covers an area
600 * <code>width + 1</code> pixels wide
601 * by <code>height + 1</code> pixels tall.
602 * @param x the <i>x</i> coordinate of the
603 * upper-left corner of the arc to be drawn.
604 * @param y the <i>y</i> coordinate of the
605 * upper-left corner of the arc to be drawn.
606 * @param width the width of the arc to be drawn.
607 * @param height the height of the arc to be drawn.
608 * @param startAngle the beginning angle.
609 * @param arcAngle the angular extent of the arc,
610 * relative to the start angle.
611 * @see java.awt.Graphics#fillArc
612 * @since 1.0
613 */
614 public void drawArc(int x, int y, int width, int height,
615 int startAngle, int arcAngle) {
616 mGraphics.drawArc(x, y, width, height, startAngle, arcAngle);
617 }
618
619 /**
620 * Fills a circular or elliptical arc covering the specified rectangle.
621 * <p>
622 * The resulting arc begins at {@code startAngle} and extends
623 * for {@code arcAngle} degrees.
624 * Angles are interpreted such that 0 degrees
625 * is at the 3 o'clock position.
626 * A positive value indicates a counter-clockwise rotation
627 * while a negative value indicates a clockwise rotation.
628 * <p>
629 * The center of the arc is the center of the rectangle whose origin
630 * is (<i>x</i>, <i>y</i>) and whose size is specified by the
631 * {@code width} and {@code height} arguments.
632 * <p>
633 * The resulting arc covers an area
634 * <code>width + 1</code> pixels wide
635 * by <code>height + 1</code> pixels tall.
636 * @param x the <i>x</i> coordinate of the
637 * upper-left corner of the arc to be filled.
638 * @param y the <i>y</i> coordinate of the
639 * upper-left corner of the arc to be filled.
640 * @param width the width of the arc to be filled.
641 * @param height the height of the arc to be filled.
642 * @param startAngle the beginning angle.
643 * @param arcAngle the angular extent of the arc,
644 * relative to the start angle.
645 * @see java.awt.Graphics#drawArc
646 * @since 1.0
647 */
648 public void fillArc(int x, int y, int width, int height,
649 int startAngle, int arcAngle) {
650 mGraphics.fillArc(x, y, width, height, startAngle, arcAngle);
651 }
655 * arrays of <i>x</i> and <i>y</i> coordinates.
656 * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
657 * The figure is not closed if the first point
658 * differs from the last point.
659 * @param xPoints an array of <i>x</i> points
660 * @param yPoints an array of <i>y</i> points
661 * @param nPoints the total number of points
662 * @see java.awt.Graphics#drawPolygon(int[], int[], int)
663 * @since 1.1
664 */
665 public void drawPolyline(int xPoints[], int yPoints[],
666 int nPoints) {
667 mGraphics.drawPolyline(xPoints, yPoints, nPoints);
668 }
669
670 /**
671 * Draws a closed polygon defined by
672 * arrays of <i>x</i> and <i>y</i> coordinates.
673 * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
674 * <p>
675 * This method draws the polygon defined by {@code nPoint} line
676 * segments, where the first <code>nPoint - 1</code>
677 * line segments are line segments from
678 * <code>(xPoints[i - 1], yPoints[i - 1])</code>
679 * to <code>(xPoints[i], yPoints[i])</code>, for
680 * 1 ≤ <i>i</i> ≤ {@code nPoints}.
681 * The figure is automatically closed by drawing a line connecting
682 * the final point to the first point, if those points are different.
683 * @param xPoints a an array of {@code x} coordinates.
684 * @param yPoints a an array of {@code y} coordinates.
685 * @param nPoints a the total number of points.
686 * @see java.awt.Graphics#fillPolygon
687 * @see java.awt.Graphics#drawPolyline
688 * @since 1.0
689 */
690 public void drawPolygon(int xPoints[], int yPoints[],
691 int nPoints) {
692 mGraphics.drawPolygon(xPoints, yPoints, nPoints);
693 }
694
695 /**
696 * Fills a closed polygon defined by
697 * arrays of <i>x</i> and <i>y</i> coordinates.
698 * <p>
699 * This method draws the polygon defined by {@code nPoint} line
700 * segments, where the first <code>nPoint - 1</code>
701 * line segments are line segments from
702 * <code>(xPoints[i - 1], yPoints[i - 1])</code>
703 * to <code>(xPoints[i], yPoints[i])</code>, for
704 * 1 ≤ <i>i</i> ≤ {@code nPoints}.
705 * The figure is automatically closed by drawing a line connecting
706 * the final point to the first point, if those points are different.
707 * <p>
708 * The area inside the polygon is defined using an
709 * even-odd fill rule, also known as the alternating rule.
710 * @param xPoints a an array of {@code x} coordinates.
711 * @param yPoints a an array of {@code y} coordinates.
712 * @param nPoints a the total number of points.
713 * @see java.awt.Graphics#drawPolygon(int[], int[], int)
714 * @since 1.0
715 */
716 public void fillPolygon(int xPoints[], int yPoints[],
717 int nPoints) {
718 mGraphics.fillPolygon(xPoints, yPoints, nPoints);
719 }
720
721 /**
722 * Draws the text given by the specified string, using this
723 * graphics context's current font and color. The baseline of the
724 * first character is at position (<i>x</i>, <i>y</i>) in this
725 * graphics context's coordinate system.
726 * @param str the string to be drawn.
727 * @param x the <i>x</i> coordinate.
728 * @param y the <i>y</i> coordinate.
729 * @see java.awt.Graphics#drawBytes
730 * @see java.awt.Graphics#drawChars
731 * @since 1.0
779 * @see #setComposite
780 * @see #setClip
781 */
782 public void drawString(AttributedCharacterIterator iterator,
783 float x, float y) {
784 mGraphics.drawString(iterator, x, y);
785 }
786
787 /**
788 * Draws as much of the specified image as is currently available.
789 * The image is drawn with its top-left corner at
790 * (<i>x</i>, <i>y</i>) in this graphics context's coordinate
791 * space. Transparent pixels in the image do not affect whatever
792 * pixels are already there.
793 * <p>
794 * This method returns immediately in all cases, even if the
795 * complete image has not yet been loaded, and it has not been dithered
796 * and converted for the current output device.
797 * <p>
798 * If the image has not yet been completely loaded, then
799 * {@code drawImage} returns {@code false}. As more of
800 * the image becomes available, the process that draws the image notifies
801 * the specified image observer.
802 * @param img the specified image to be drawn.
803 * @param x the <i>x</i> coordinate.
804 * @param y the <i>y</i> coordinate.
805 * @param observer object to be notified as more of
806 * the image is converted.
807 * @see java.awt.Image
808 * @see java.awt.image.ImageObserver
809 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
810 * @since 1.0
811 */
812 public boolean drawImage(Image img, int x, int y,
813 ImageObserver observer) {
814
815 return mGraphics.drawImage(img, x, y, observer);
816 }
817
818 /**
819 * Draws as much of the specified image as has already been scaled
820 * to fit inside the specified rectangle.
821 * <p>
822 * The image is drawn inside the specified rectangle of this
823 * graphics context's coordinate space, and is scaled if
824 * necessary. Transparent pixels do not affect whatever pixels
825 * are already there.
826 * <p>
827 * This method returns immediately in all cases, even if the
828 * entire image has not yet been scaled, dithered, and converted
829 * for the current output device.
830 * If the current output representation is not yet complete, then
831 * {@code drawImage} returns {@code false}. As more of
832 * the image becomes available, the process that draws the image notifies
833 * the image observer by calling its {@code imageUpdate} method.
834 * <p>
835 * A scaled version of an image will not necessarily be
836 * available immediately just because an unscaled version of the
837 * image has been constructed for this output device. Each size of
838 * the image may be cached separately and generated from the original
839 * data in a separate image production sequence.
840 * @param img the specified image to be drawn.
841 * @param x the <i>x</i> coordinate.
842 * @param y the <i>y</i> coordinate.
843 * @param width the width of the rectangle.
844 * @param height the height of the rectangle.
845 * @param observer object to be notified as more of
846 * the image is converted.
847 * @see java.awt.Image
848 * @see java.awt.image.ImageObserver
849 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
850 * @since 1.0
851 */
852 public boolean drawImage(Image img, int x, int y,
853 int width, int height,
855
856 return mGraphics.drawImage(img, x, y, width, height, observer);
857 }
858
859 /**
860 * Draws as much of the specified image as is currently available.
861 * The image is drawn with its top-left corner at
862 * (<i>x</i>, <i>y</i>) in this graphics context's coordinate
863 * space. Transparent pixels are drawn in the specified
864 * background color.
865 * <p>
866 * This operation is equivalent to filling a rectangle of the
867 * width and height of the specified image with the given color and then
868 * drawing the image on top of it, but possibly more efficient.
869 * <p>
870 * This method returns immediately in all cases, even if the
871 * complete image has not yet been loaded, and it has not been dithered
872 * and converted for the current output device.
873 * <p>
874 * If the image has not yet been completely loaded, then
875 * {@code drawImage} returns {@code false}. As more of
876 * the image becomes available, the process that draws the image notifies
877 * the specified image observer.
878 * @param img the specified image to be drawn.
879 * @param x the <i>x</i> coordinate.
880 * @param y the <i>y</i> coordinate.
881 * @param bgcolor the background color to paint under the
882 * non-opaque portions of the image.
883 * @param observer object to be notified as more of
884 * the image is converted.
885 * @see java.awt.Image
886 * @see java.awt.image.ImageObserver
887 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
888 * @since 1.0
889 */
890 public boolean drawImage(Image img, int x, int y,
891 Color bgcolor,
892 ImageObserver observer) {
893
894 if (img == null) {
895 return true;
906
907 return result;
908 }
909
910 /**
911 * Draws as much of the specified image as has already been scaled
912 * to fit inside the specified rectangle.
913 * <p>
914 * The image is drawn inside the specified rectangle of this
915 * graphics context's coordinate space, and is scaled if
916 * necessary. Transparent pixels are drawn in the specified
917 * background color.
918 * This operation is equivalent to filling a rectangle of the
919 * width and height of the specified image with the given color and then
920 * drawing the image on top of it, but possibly more efficient.
921 * <p>
922 * This method returns immediately in all cases, even if the
923 * entire image has not yet been scaled, dithered, and converted
924 * for the current output device.
925 * If the current output representation is not yet complete then
926 * {@code drawImage} returns {@code false}. As more of
927 * the image becomes available, the process that draws the image notifies
928 * the specified image observer.
929 * <p>
930 * A scaled version of an image will not necessarily be
931 * available immediately just because an unscaled version of the
932 * image has been constructed for this output device. Each size of
933 * the image may be cached separately and generated from the original
934 * data in a separate image production sequence.
935 * @param img the specified image to be drawn.
936 * @param x the <i>x</i> coordinate.
937 * @param y the <i>y</i> coordinate.
938 * @param width the width of the rectangle.
939 * @param height the height of the rectangle.
940 * @param bgcolor the background color to paint under the
941 * non-opaque portions of the image.
942 * @param observer object to be notified as more of
943 * the image is converted.
944 * @see java.awt.Image
945 * @see java.awt.image.ImageObserver
946 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
961 BufferedImage imageCopy = getBufferedImageCopy(img, bgcolor);
962 result = mGraphics.drawImage(imageCopy, x, y, width, height, null);
963 } else {
964 result = mGraphics.drawImage(img, x, y, width, height,
965 bgcolor, observer);
966 }
967
968 return result;
969 }
970
971 /**
972 * Draws as much of the specified area of the specified image as is
973 * currently available, scaling it on the fly to fit inside the
974 * specified area of the destination drawable surface. Transparent pixels
975 * do not affect whatever pixels are already there.
976 * <p>
977 * This method returns immediately in all cases, even if the
978 * image area to be drawn has not yet been scaled, dithered, and converted
979 * for the current output device.
980 * If the current output representation is not yet complete then
981 * {@code drawImage} returns {@code false}. As more of
982 * the image becomes available, the process that draws the image notifies
983 * the specified image observer.
984 * <p>
985 * This method always uses the unscaled version of the image
986 * to render the scaled rectangle and performs the required
987 * scaling on the fly. It does not use a cached, scaled version
988 * of the image for this operation. Scaling of the image from source
989 * to destination is performed such that the first coordinate
990 * of the source rectangle is mapped to the first coordinate of
991 * the destination rectangle, and the second source coordinate is
992 * mapped to the second destination coordinate. The subimage is
993 * scaled and flipped as needed to preserve those mappings.
994 * @param img the specified image to be drawn
995 * @param dx1 the <i>x</i> coordinate of the first corner of the
996 * destination rectangle.
997 * @param dy1 the <i>y</i> coordinate of the first corner of the
998 * destination rectangle.
999 * @param dx2 the <i>x</i> coordinate of the second corner of the
1000 * destination rectangle.
1001 * @param dy2 the <i>y</i> coordinate of the second corner of the
1021 ImageObserver observer) {
1022 return mGraphics.drawImage(img, dx1, dy1, dx2, dy2,
1023 sx1, sy1, sx2, sy2,
1024 observer);
1025 }
1026
1027 /**
1028 * Draws as much of the specified area of the specified image as is
1029 * currently available, scaling it on the fly to fit inside the
1030 * specified area of the destination drawable surface.
1031 * <p>
1032 * Transparent pixels are drawn in the specified background color.
1033 * This operation is equivalent to filling a rectangle of the
1034 * width and height of the specified image with the given color and then
1035 * drawing the image on top of it, but possibly more efficient.
1036 * <p>
1037 * This method returns immediately in all cases, even if the
1038 * image area to be drawn has not yet been scaled, dithered, and converted
1039 * for the current output device.
1040 * If the current output representation is not yet complete then
1041 * {@code drawImage} returns {@code false}. As more of
1042 * the image becomes available, the process that draws the image notifies
1043 * the specified image observer.
1044 * <p>
1045 * This method always uses the unscaled version of the image
1046 * to render the scaled rectangle and performs the required
1047 * scaling on the fly. It does not use a cached, scaled version
1048 * of the image for this operation. Scaling of the image from source
1049 * to destination is performed such that the first coordinate
1050 * of the source rectangle is mapped to the first coordinate of
1051 * the destination rectangle, and the second source coordinate is
1052 * mapped to the second destination coordinate. The subimage is
1053 * scaled and flipped as needed to preserve those mappings.
1054 * @param img the specified image to be drawn
1055 * @param dx1 the <i>x</i> coordinate of the first corner of the
1056 * destination rectangle.
1057 * @param dy1 the <i>y</i> coordinate of the first corner of the
1058 * destination rectangle.
1059 * @param dx2 the <i>x</i> coordinate of the second corner of the
1060 * destination rectangle.
1061 * @param dy2 the <i>y</i> coordinate of the second corner of the
1089
1090 boolean result;
1091 if (needToCopyBgColorImage(img)) {
1092 BufferedImage imageCopy = getBufferedImageCopy(img, bgcolor);
1093 result = mGraphics.drawImage(imageCopy,
1094 dx1, dy1, dx2, dy2,
1095 sy1, sy1, sx2, sy2,
1096 null);
1097 } else {
1098 result = mGraphics.drawImage(img,
1099 dx1, dy1, dx2, dy2,
1100 sy1, sy1, sx2, sy2,
1101 bgcolor,
1102 observer);
1103 }
1104
1105 return result;
1106 }
1107
1108 /**
1109 * Return true if drawing {@code img} will
1110 * invoke a Java2D bug (#4258675). The bug in question
1111 * occurs when a draw image call with a background color
1112 * parameter tries to render a sheared
1113 * or rotated image. The portions of the bounding
1114 * rectangle not covered by the sheared image
1115 * are incorrectly drawn with the background color.
1116 */
1117 private boolean needToCopyBgColorImage(Image img) {
1118
1119 boolean needToCopy;
1120
1121 AffineTransform transform = getTransform();
1122
1123 return (transform.getType()
1124 & (AffineTransform.TYPE_GENERAL_ROTATION
1125 | AffineTransform.TYPE_GENERAL_TRANSFORM)) != 0;
1126 }
1127
1128 /**
1129 * Return a new {@code BufferedImage}
1130 * that contains a copy of the provided
1131 * {@code Image} where its
1132 * transparent pixels have been replaced by
1133 * {@code bgcolor}. If the new
1134 * {@code BufferedImage} can not be created,
1135 * probably because the original image has not
1136 * finished loading, then {@code null} is
1137 * returned.
1138 */
1139 private BufferedImage getBufferedImageCopy(Image img, Color bgcolor) {
1140
1141 BufferedImage imageCopy = null;
1142
1143 int width = img.getWidth(null);
1144 int height = img.getHeight(null);
1145
1146 if (width > 0 && height > 0) {
1147
1148 int imageType;
1149
1150 /* Try to minimize the depth of the BufferedImage
1151 * we are about to create by, if possible, making
1152 * it the same depth as the original image.
1153 */
1154 if (img instanceof BufferedImage) {
1155 BufferedImage bufImage = (BufferedImage) img;
1156 imageType = bufImage.getType();
1215 AffineTransform concatTransform = new AffineTransform(xform);
1216 concatTransform.concatenate(pipeTransform);
1217 AffineTransform reverseTransform;
1218
1219 RenderContext rc = new RenderContext(concatTransform);
1220
1221 try {
1222 reverseTransform = pipeTransform.createInverse();
1223 } catch (NoninvertibleTransformException nte) {
1224 rc = new RenderContext(pipeTransform);
1225 reverseTransform = new AffineTransform();
1226 }
1227
1228 RenderedImage rendering = img.createRendering(rc);
1229 drawRenderedImage(rendering,reverseTransform);
1230 }
1231
1232 /**
1233 * Disposes of this graphics context and releases
1234 * any system resources that it is using.
1235 * A {@code Graphics} object cannot be used after
1236 * {@code dispose} has been called.
1237 * <p>
1238 * When a Java program runs, a large number of {@code Graphics}
1239 * objects can be created within a short time frame.
1240 * Although the finalization process of the garbage collector
1241 * also disposes of the same system resources, it is preferable
1242 * to manually free the associated resources by calling this
1243 * method rather than to rely on a finalization process which
1244 * may not run to completion for a long period of time.
1245 * <p>
1246 * Graphics objects which are provided as arguments to the
1247 * {@code paint} and {@code update} methods
1248 * of components are automatically released by the system when
1249 * those methods return. For efficiency, programmers should
1250 * call {@code dispose} when finished using
1251 * a {@code Graphics} object only if it was created
1252 * directly from a component or another {@code Graphics} object.
1253 * @see java.awt.Graphics#finalize
1254 * @see java.awt.Component#paint
1255 * @see java.awt.Component#update
1256 * @see java.awt.Component#getGraphics
1257 * @see java.awt.Graphics#create
1258 * @since 1.0
1259 */
1260 public void dispose() {
1261 mGraphics.dispose();
1262 }
1263
1264 /**
1265 * Empty finalizer as no clean up needed here.
1266 */
1267 public void finalize() {
1268 }
1269
1270
1271 /* The Delegated Graphics2D Methods */
1272
|