/* * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javafx.scene.shape; import com.sun.javafx.collections.TrackableObservableList; import com.sun.javafx.geom.BaseBounds; import com.sun.javafx.geom.Path2D; import com.sun.javafx.geom.transform.BaseTransform; import com.sun.javafx.scene.DirtyBits; import com.sun.javafx.scene.NodeHelper; import com.sun.javafx.scene.shape.PolygonHelper; import com.sun.javafx.scene.shape.ShapeHelper; import com.sun.javafx.sg.prism.NGNode; import com.sun.javafx.sg.prism.NGPolygon; import com.sun.javafx.sg.prism.NGShape; import javafx.collections.ListChangeListener.Change; import javafx.collections.ObservableList; import javafx.scene.Node; import javafx.scene.paint.Paint; /** * Creates a polygon, defined by an array of x,y coordinates. The Polygon * class is similar to the Polyline class, except that the Polyline class * is not automatically closed. *
import javafx.scene.shape.*; Polygon polygon = new Polygon(); polygon.getPoints().addAll(new Double[]{ 0.0, 0.0, 20.0, 10.0, 10.0, 20.0 });* @since JavaFX 2.0 */ public class Polygon extends Shape { static { PolygonHelper.setPolygonAccessor(new PolygonHelper.PolygonAccessor() { @Override public NGNode doCreatePeer(Node node) { return ((Polygon) node).doCreatePeer(); } @Override public void doUpdatePeer(Node node) { ((Polygon) node).doUpdatePeer(); } @Override public BaseBounds doComputeGeomBounds(Node node, BaseBounds bounds, BaseTransform tx) { return ((Polygon) node).doComputeGeomBounds(bounds, tx); } @Override public com.sun.javafx.geom.Shape doConfigShape(Shape shape) { return ((Polygon) shape).doConfigShape(); } }); } private final Path2D shape = new Path2D(); { // To initialize the class helper at the begining each constructor of this class PolygonHelper.initHelper(this); } /** * Creates an empty instance of Polygon. */ public Polygon() { } /** * Creates a new instance of Polygon. * @param points the coordinates of the polygon vertices */ public Polygon(double... points) { if (points != null) { for (double p : points) { this.getPoints().add(p); } } } /** * Defines the coordinates of the polygon vertices. * * @defaultValue empty */ private final ObservableList