145 }
146
147 /**
148 * Return a Spans instance describing the parts of the page in
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;
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
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);
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
914 NullPointerException("AttributedCharacterIterator is null");
915 }
916
917 TextLayout layout = new TextLayout(iterator, getFontRenderContext());
918 layout.draw(this, x, y);
919 }
920
921
922 /**
923 * Draws as much of the specified image as is currently available.
924 * The image is drawn with its top-left corner at
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
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
966 /**
967 * Draws as much of the specified image as has already been scaled
968 * to fit inside the specified rectangle.
969 * <p>
970 * The image is drawn inside the specified rectangle of this
971 * graphics context's coordinate space, and is scaled if
972 * necessary. Transparent pixels do not affect whatever pixels
973 * are already there.
974 * <p>
975 * This method returns immediately in all cases, even if the
976 * entire image has not yet been scaled, dithered, and converted
977 * for the current output device.
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,
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
1019 * background color.
1020 * <p>
1021 * This operation is equivalent to filling a rectangle of the
1022 * width and height of the specified image with the given color and then
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;
1061 return mGraphics.drawImage(img, x, y, bgcolor, observer);
1062 }
1063
1064
1065 /**
1066 * Draws as much of the specified image as has already been scaled
1067 * to fit inside the specified rectangle.
1068 * <p>
1069 * The image is drawn inside the specified rectangle of this
1070 * graphics context's coordinate space, and is scaled if
1071 * necessary. Transparent pixels are drawn in the specified
1072 * background color.
1073 * This operation is equivalent to filling a rectangle of the
1074 * width and height of the specified image with the given color and then
1075 * drawing the image on top of it, but possibly more efficient.
1076 * <p>
1077 * This method returns immediately in all cases, even if the
1078 * entire image has not yet been scaled, dithered, and converted
1079 * for the current output device.
1080 * If the current output representation is not yet complete then
1081 * <code>drawImage</code> returns <code>false</code>. As more of
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)
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
1123 * specified area of the destination drawable surface. Transparent pixels
1124 * do not affect whatever pixels are already there.
1125 * <p>
1126 * This method returns immediately in all cases, even if the
1127 * image area to be drawn has not yet been scaled, dithered, and converted
1128 * for the current output device.
1129 * If the current output representation is not yet complete then
1130 * <code>drawImage</code> returns <code>false</code>. As more of
1131 * the image becomes available, the process that draws the image notifies
1132 * the specified image observer.
1133 * <p>
1134 * This method always uses the unscaled version of the image
1135 * to render the scaled rectangle and performs the required
1136 * scaling on the fly. It does not use a cached, scaled version
1137 * of the image for this operation. Scaling of the image from source
1138 * to destination is performed such that the first coordinate
1139 * of the source rectangle is mapped to the first coordinate of
1140 * the destination rectangle, and the second source coordinate is
1141 * mapped to the second destination coordinate. The subimage is
1142 * scaled and flipped as needed to preserve those mappings.
1143 * @param img the specified image to be drawn
1144 * @param dx1 the <i>x</i> coordinate of the first corner of 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
1182 return mGraphics.drawImage(img, dx1, dy1, dx2, dy2,
1183 sx1, sy1, sx2, sy2, observer);
1184
1185 }
1186
1187
1188 /**
1189 * Draws as much of the specified area of the specified image as is
1190 * currently available, scaling it on the fly to fit inside the
1191 * specified area of the destination drawable surface.
1192 * <p>
1193 * Transparent pixels are drawn in the specified background color.
1194 * This operation is equivalent to filling a rectangle of the
1195 * width and height of the specified image with the given color and then
1196 * drawing the image on top of it, but possibly more efficient.
1197 * <p>
1198 * This method returns immediately in all cases, even if the
1199 * image area to be drawn has not yet been scaled, dithered, and converted
1200 * for the current output device.
1201 * If the current output representation is not yet complete then
1202 * <code>drawImage</code> returns <code>false</code>. As more of
1203 * the image becomes available, the process that draws the image notifies
1204 * the specified image observer.
1205 * <p>
1206 * This method always uses the unscaled version of the image
1207 * to render the scaled rectangle and performs the required
1208 * scaling on the fly. It does not use a cached, scaled version
1209 * of the image for this operation. Scaling of the image from source
1210 * to destination is performed such that the first coordinate
1211 * of the source rectangle is mapped to the first coordinate of
1212 * the destination rectangle, and the second source coordinate is
1213 * mapped to the second destination coordinate. The subimage is
1214 * scaled and flipped as needed to preserve those mappings.
1215 * @param img the specified image to be drawn
1216 * @param dx1 the <i>x</i> coordinate of the first corner of the
1217 * destination rectangle.
1218 * @param dy1 the <i>y</i> coordinate of the first corner of the
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
1287
1288 mPrintMetrics.drawImage(this, img);
1289 mDrawingArea.addInfinite();
1290 }
1291
1292
1293 public void drawRenderableImage(RenderableImage img,
1294 AffineTransform xform) {
1295
1296 if (img == null) {
1297 return;
1298 }
1299
1300 mPrintMetrics.drawImage(this, img);
1301 mDrawingArea.addInfinite();
1302 }
1303
1304 /**
1305 * Disposes of this graphics context and releases
1306 * any system resources that it is using.
1307 * A <code>Graphics</code> object cannot be used after
1308 * <code>dispose</code>has been called.
1309 * <p>
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 /**
1718 * @see #setStroke
1719 */
1720 public Stroke getStroke() {
1721 return mGraphics.getStroke();
1722 }
1723
1724 /**
1725 * Intersects the current clip with the interior of the specified Shape
1726 * and sets the current clip to the resulting intersection.
1727 * The indicated shape is transformed with the current transform in the
1728 * Graphics2D state before being intersected with the current clip.
1729 * This method is used to make the current clip smaller.
1730 * To make the clip larger, use any setClip method.
1731 * @param s The Shape to be intersected with the current clip.
1732 */
1733 public void clip(Shape s) {
1734 mGraphics.clip(s);
1735 }
1736
1737 /**
1738 * Return true if the Rectangle <code>rect</code>
1739 * intersects the area into which the application
1740 * has drawn.
1741 */
1742 public boolean hitsDrawingArea(Rectangle rect) {
1743
1744 return mDrawingArea.intersects((float) rect.getMinY(),
1745 (float) rect.getMaxY());
1746 }
1747
1748 /**
1749 * Return the object holding the summary of the
1750 * drawing done by the printing application.
1751 */
1752 public PeekMetrics getMetrics() {
1753 return mPrintMetrics;
1754 }
1755
1756 /* Support Routines for Calculating the Drawing Area */
1757
1758 /**
|
145 }
146
147 /**
148 * Return a Spans instance describing the parts of the page in
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} object that is
166 * a copy of this {@code Graphics} 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;
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} 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}
463 * interface can be used to set the clip. The only
464 * {@code Shape} objects which are guaranteed to be
465 * supported are {@code Shape} objects which are
466 * obtained via the {@code getClip} method and via
467 * {@code Rectangle} 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} and {@code dy}. From the point specified
481 * by {@code x} and {@code y}, 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} or {@code dy}.
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} 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} 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} and <code>x + width - 1</code>.
524 * The top and bottom edges are at
525 * {@code y} and <code>y + height - 1</code>.
526 * The resulting rectangle covers an area
527 * {@code width} pixels wide by
528 * {@code height} 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} followed by {@code fillRect} 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} and <code>x + width</code>,
577 * respectively. The top and bottom edges of the rectangle are at
578 * {@code y} 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} and <code>x + width - 1</code>,
601 * respectively. The top and bottom edges of the rectangle are at
602 * {@code y} 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 y},
625 * {@code width}, and {@code height} 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
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} and extends
669 * for {@code arcAngle} 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} and {@code height} 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} and extends
705 * for {@code arcAngle} 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} and {@code height} 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);
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} 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}.
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} coordinates.
779 * @param yPoints a an array of {@code y} 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} 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}.
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} coordinates.
811 * @param yPoints a an array of {@code y} 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
914 NullPointerException("AttributedCharacterIterator is null");
915 }
916
917 TextLayout layout = new TextLayout(iterator, getFontRenderContext());
918 layout.draw(this, x, y);
919 }
920
921
922 /**
923 * Draws as much of the specified image as is currently available.
924 * The image is drawn with its top-left corner at
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} returns {@code false}. 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
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
966 /**
967 * Draws as much of the specified image as has already been scaled
968 * to fit inside the specified rectangle.
969 * <p>
970 * The image is drawn inside the specified rectangle of this
971 * graphics context's coordinate space, and is scaled if
972 * necessary. Transparent pixels do not affect whatever pixels
973 * are already there.
974 * <p>
975 * This method returns immediately in all cases, even if the
976 * entire image has not yet been scaled, dithered, and converted
977 * for the current output device.
978 * If the current output representation is not yet complete, then
979 * {@code drawImage} returns {@code false}. As more of
980 * the image becomes available, the process that draws the image notifies
981 * the image observer by calling its {@code imageUpdate} 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,
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
1019 * background color.
1020 * <p>
1021 * This operation is equivalent to filling a rectangle of the
1022 * width and height of the specified image with the given color and then
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} returns {@code false}. 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;
1061 return mGraphics.drawImage(img, x, y, bgcolor, observer);
1062 }
1063
1064
1065 /**
1066 * Draws as much of the specified image as has already been scaled
1067 * to fit inside the specified rectangle.
1068 * <p>
1069 * The image is drawn inside the specified rectangle of this
1070 * graphics context's coordinate space, and is scaled if
1071 * necessary. Transparent pixels are drawn in the specified
1072 * background color.
1073 * This operation is equivalent to filling a rectangle of the
1074 * width and height of the specified image with the given color and then
1075 * drawing the image on top of it, but possibly more efficient.
1076 * <p>
1077 * This method returns immediately in all cases, even if the
1078 * entire image has not yet been scaled, dithered, and converted
1079 * for the current output device.
1080 * If the current output representation is not yet complete then
1081 * {@code drawImage} returns {@code false}. As more of
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)
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
1123 * specified area of the destination drawable surface. Transparent pixels
1124 * do not affect whatever pixels are already there.
1125 * <p>
1126 * This method returns immediately in all cases, even if the
1127 * image area to be drawn has not yet been scaled, dithered, and converted
1128 * for the current output device.
1129 * If the current output representation is not yet complete then
1130 * {@code drawImage} returns {@code false}. As more of
1131 * the image becomes available, the process that draws the image notifies
1132 * the specified image observer.
1133 * <p>
1134 * This method always uses the unscaled version of the image
1135 * to render the scaled rectangle and performs the required
1136 * scaling on the fly. It does not use a cached, scaled version
1137 * of the image for this operation. Scaling of the image from source
1138 * to destination is performed such that the first coordinate
1139 * of the source rectangle is mapped to the first coordinate of
1140 * the destination rectangle, and the second source coordinate is
1141 * mapped to the second destination coordinate. The subimage is
1142 * scaled and flipped as needed to preserve those mappings.
1143 * @param img the specified image to be drawn
1144 * @param dx1 the <i>x</i> coordinate of the first corner of 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
1182 return mGraphics.drawImage(img, dx1, dy1, dx2, dy2,
1183 sx1, sy1, sx2, sy2, observer);
1184
1185 }
1186
1187
1188 /**
1189 * Draws as much of the specified area of the specified image as is
1190 * currently available, scaling it on the fly to fit inside the
1191 * specified area of the destination drawable surface.
1192 * <p>
1193 * Transparent pixels are drawn in the specified background color.
1194 * This operation is equivalent to filling a rectangle of the
1195 * width and height of the specified image with the given color and then
1196 * drawing the image on top of it, but possibly more efficient.
1197 * <p>
1198 * This method returns immediately in all cases, even if the
1199 * image area to be drawn has not yet been scaled, dithered, and converted
1200 * for the current output device.
1201 * If the current output representation is not yet complete then
1202 * {@code drawImage} returns {@code false}. As more of
1203 * the image becomes available, the process that draws the image notifies
1204 * the specified image observer.
1205 * <p>
1206 * This method always uses the unscaled version of the image
1207 * to render the scaled rectangle and performs the required
1208 * scaling on the fly. It does not use a cached, scaled version
1209 * of the image for this operation. Scaling of the image from source
1210 * to destination is performed such that the first coordinate
1211 * of the source rectangle is mapped to the first coordinate of
1212 * the destination rectangle, and the second source coordinate is
1213 * mapped to the second destination coordinate. The subimage is
1214 * scaled and flipped as needed to preserve those mappings.
1215 * @param img the specified image to be drawn
1216 * @param dx1 the <i>x</i> coordinate of the first corner of the
1217 * destination rectangle.
1218 * @param dy1 the <i>y</i> coordinate of the first corner of the
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
1287
1288 mPrintMetrics.drawImage(this, img);
1289 mDrawingArea.addInfinite();
1290 }
1291
1292
1293 public void drawRenderableImage(RenderableImage img,
1294 AffineTransform xform) {
1295
1296 if (img == null) {
1297 return;
1298 }
1299
1300 mPrintMetrics.drawImage(this, img);
1301 mDrawingArea.addInfinite();
1302 }
1303
1304 /**
1305 * Disposes of this graphics context and releases
1306 * any system resources that it is using.
1307 * A {@code Graphics} object cannot be used after
1308 * {@code dispose} has been called.
1309 * <p>
1310 * When a Java program runs, a large number of {@code Graphics}
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} and {@code update} methods
1320 * of components are automatically released by the system when
1321 * those methods return. For efficiency, programmers should
1322 * call {@code dispose} when finished using
1323 * a {@code Graphics} object only if it was created
1324 * directly from a component or another {@code Graphics} 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 /**
1718 * @see #setStroke
1719 */
1720 public Stroke getStroke() {
1721 return mGraphics.getStroke();
1722 }
1723
1724 /**
1725 * Intersects the current clip with the interior of the specified Shape
1726 * and sets the current clip to the resulting intersection.
1727 * The indicated shape is transformed with the current transform in the
1728 * Graphics2D state before being intersected with the current clip.
1729 * This method is used to make the current clip smaller.
1730 * To make the clip larger, use any setClip method.
1731 * @param s The Shape to be intersected with the current clip.
1732 */
1733 public void clip(Shape s) {
1734 mGraphics.clip(s);
1735 }
1736
1737 /**
1738 * Return true if the Rectangle {@code rect}
1739 * intersects the area into which the application
1740 * has drawn.
1741 */
1742 public boolean hitsDrawingArea(Rectangle rect) {
1743
1744 return mDrawingArea.intersects((float) rect.getMinY(),
1745 (float) rect.getMaxY());
1746 }
1747
1748 /**
1749 * Return the object holding the summary of the
1750 * drawing done by the printing application.
1751 */
1752 public PeekMetrics getMetrics() {
1753 return mPrintMetrics;
1754 }
1755
1756 /* Support Routines for Calculating the Drawing Area */
1757
1758 /**
|