1 /*
2 * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
730 public void fillArc(int x, int y, int width, int height,
731 int startAngle, int arcAngle) {
732 Rectangle2D.Float rect = new Rectangle2D.Float(x, y,width, height);
733 addDrawingRect(rect);
734 mPrintMetrics.fill(this);
735
736 }
737
738 /**
739 * Draws a sequence of connected lines defined by
740 * arrays of <i>x</i> and <i>y</i> coordinates.
741 * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
742 * The figure is not closed if the first point
743 * differs from the last point.
744 * @param xPoints an array of <i>x</i> points
745 * @param yPoints an array of <i>y</i> points
746 * @param nPoints the total number of points
747 * @see java.awt.Graphics#drawPolygon(int[], int[], int)
748 * @since 1.1
749 */
750 public void drawPolyline(int xPoints[], int yPoints[],
751 int nPoints) {
752 if (nPoints > 0) {
753 int x = xPoints[0];
754 int y = yPoints[0];
755
756 for (int i = 1; i < nPoints; i++) {
757 drawLine(x, y, xPoints[i], yPoints[i]);
758 x = xPoints[i];
759 y = yPoints[i];
760 }
761 }
762
763 }
764
765 /**
766 * Draws a closed polygon defined by
767 * arrays of <i>x</i> and <i>y</i> coordinates.
768 * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
769 * <p>
770 * This method draws the polygon defined by {@code nPoint} 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
832 if (yPoints[i] < minY) {
833 minY = yPoints[i];
834 } else if (yPoints[i] > maxY) {
835 maxY = yPoints[i];
836 }
|
1 /*
2 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
730 public void fillArc(int x, int y, int width, int height,
731 int startAngle, int arcAngle) {
732 Rectangle2D.Float rect = new Rectangle2D.Float(x, y,width, height);
733 addDrawingRect(rect);
734 mPrintMetrics.fill(this);
735
736 }
737
738 /**
739 * Draws a sequence of connected lines defined by
740 * arrays of <i>x</i> and <i>y</i> coordinates.
741 * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
742 * The figure is not closed if the first point
743 * differs from the last point.
744 * @param xPoints an array of <i>x</i> points
745 * @param yPoints an array of <i>y</i> points
746 * @param nPoints the total number of points
747 * @see java.awt.Graphics#drawPolygon(int[], int[], int)
748 * @since 1.1
749 */
750 public void drawPolyline(int[] xPoints, int[] yPoints,
751 int nPoints) {
752 if (nPoints > 0) {
753 int x = xPoints[0];
754 int y = yPoints[0];
755
756 for (int i = 1; i < nPoints; i++) {
757 drawLine(x, y, xPoints[i], yPoints[i]);
758 x = xPoints[i];
759 y = yPoints[i];
760 }
761 }
762
763 }
764
765 /**
766 * Draws a closed polygon defined by
767 * arrays of <i>x</i> and <i>y</i> coordinates.
768 * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
769 * <p>
770 * This method draws the polygon defined by {@code nPoint} 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
832 if (yPoints[i] < minY) {
833 minY = yPoints[i];
834 } else if (yPoints[i] > maxY) {
835 maxY = yPoints[i];
836 }
|