Example usage for javafx.scene.shape Polygon Polygon

List of usage examples for javafx.scene.shape Polygon Polygon

Introduction

In this page you can find the example usage for javafx.scene.shape Polygon Polygon.

Prototype

public Polygon(double... points) 

Source Link

Document

Creates a new instance of Polygon.

Usage

From source file:editeurpanovisu.EditeurPanovisu.java

/**
 *
 * @param iLargeur//from  w w  w.  j a va  2s.c  om
 * @param iHauteur
 * @param bMasqueZones
 */
private static void afficheBarrePersonnalisee(int iLargeur, int iHauteur, boolean bMasqueZones) {
    apImgBarrePersonnalisee.getChildren().clear();
    apZoneBarrePersonnalisee.getChildren().clear();
    ImageView ivBarrePersonnalisee = new ImageView(imgBarrePersonnalisee);
    apImgBarrePersonnalisee.getChildren().add(ivBarrePersonnalisee);
    apImgBarrePersonnalisee.setPrefWidth(imgBarrePersonnalisee.getWidth());
    apImgBarrePersonnalisee.setPrefHeight(imgBarrePersonnalisee.getHeight());
    apImgBarrePersonnalisee.setCursor(Cursor.CROSSHAIR);
    apImgBarrePersonnalisee.setLayoutX((iLargeur - 300 - apImgBarrePersonnalisee.getPrefWidth()) / 2.d);
    apImgBarrePersonnalisee.setLayoutY((iHauteur - apImgBarrePersonnalisee.getPrefHeight()) / 2.d);
    if ((iNombreZones > 0) && !bMasqueZones) {
        for (int i = 0; i < iNombreZones; i++) {
            ZoneTelecommande zone = zones[i];
            String[] strPoints = zone.getStrCoordonneesZone().split(",");
            double[] points = new double[strPoints.length];
            for (int ij = 0; ij < strPoints.length; ij++) {
                points[ij] = Double.parseDouble(strPoints[ij]);
            }
            final String strIdZone = zone.getStrTypeZone() + "-" + i;

            switch (zone.getStrTypeZone()) {
            case "circle":
                Circle cercle = new Circle(points[0], points[1], points[2]);
                cercle.setFill(Color.rgb(255, 255, 0, 0.5));
                cercle.setStroke(Color.FORESTGREEN);
                cercle.setCursor(Cursor.DEFAULT);
                apImgBarrePersonnalisee.getChildren().add(cercle);
                cercle.setId(strIdZone);
                cercle.setOnMouseClicked((t) -> {
                    choixZone(iLargeur, iHauteur, bMasqueZones, strIdZone, t);
                    t.consume();
                });
                break;
            case "rect":
                double largRect = points[2] - points[0];
                double hautRect = points[3] - points[1];
                Rectangle rect = new Rectangle(points[0], points[1], largRect, hautRect);
                rect.setFill(Color.rgb(255, 255, 0, 0.5));
                rect.setStroke(Color.FORESTGREEN);
                rect.setCursor(Cursor.DEFAULT);
                apImgBarrePersonnalisee.getChildren().add(rect);
                rect.setId(strIdZone);
                rect.setOnMouseClicked((t) -> {
                    choixZone(iLargeur, iHauteur, bMasqueZones, strIdZone, t);
                    t.consume();
                });
                break;
            case "poly":
                Polygon poly = new Polygon(points);
                poly.setFill(Color.rgb(255, 255, 0, 0.5));
                poly.setStroke(Color.FORESTGREEN);
                poly.setStrokeWidth(3);
                poly.setCursor(Cursor.DEFAULT);
                poly.setStrokeLineCap(StrokeLineCap.ROUND);
                poly.setId(strIdZone);
                apImgBarrePersonnalisee.getChildren().add(poly);
                poly.setOnMouseClicked((t) -> {
                    choixZone(iLargeur, iHauteur, bMasqueZones, strIdZone, t);
                    t.consume();
                });
                break;
            }
        }
    }
}

From source file:org.mskcc.shenkers.control.alignment.AlignmentPolygon.java

public Polygon getPolygon() {
    Stack<Double> ends = new Stack<>();
    Stack<Double> heights = new Stack<>();

    List<Double> points = new ArrayList<>();
    for (int i = 0; i < span.size(); i++) {
        GenomeSpan s = span.get(i);//from  w  w w. j  a v  a 2  s . co  m
        GenomeSpan d = displayedSpans.get(i);
        double displayedSpanWidth = d.length() + 0.;
        double relativeWidth = s.length() / displayedSpanWidth;
        int distanceFromStart = d.isNegativeStrand() ? d.getEnd() - s.getEnd() : s.getStart() - d.getStart();
        //            int distanceFromStart = d.isNegativeStrand() ? d.getEnd() : d.getStart();
        double relativeStart = (distanceFromStart) / displayedSpanWidth;
        double relativeHeight = weight.get(i);

        points.add(relativeStart);
        points.add(relativeHeight);

        ends.push(relativeStart + relativeWidth);
        heights.push(relativeHeight);
    }

    while (ends.size() > 0) {
        points.add(ends.pop());
        points.add(heights.pop());
    }

    logger.info(points);

    return new Polygon(ArrayUtils.toPrimitive(points.toArray(new Double[0])));
}