Example usage for javafx.scene.shape Polygon setFill

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

Introduction

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

Prototype

public final void setFill(Paint value) 

Source Link

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    Circle circle = new Circle(40);
    circle.setFill(Color.RED);/*from   ww w  .j a va2 s.co  m*/
    circle.setStroke(Color.BLACK);
    circle.setStrokeWidth(2.0);

    Rectangle rect = new Rectangle(120, 75);
    rect.setFill(Color.RED);

    // Create a line
    Line line = new Line(0, 0, 150, 50);
    line.setStrokeWidth(5.0);
    line.setStroke(Color.GREEN);

    // Create a parallelogram
    Polygon parallelogram = new Polygon();
    parallelogram.getPoints().addAll(30.0, 0.0, 130.0, 0.0, 120.00, 50.0, 0.0, 50.0);
    parallelogram.setFill(Color.AZURE);
    parallelogram.setStroke(Color.BLACK);

    // Create a hexagon
    Polyline hexagon = new Polyline(100.0, 0.0, 120.0, 20.0, 110.0, 140.0, 100.0, 60.0, 80.0, 40.0, 80.0, 120.0,
            100.0, 0.0);
    hexagon.setFill(Color.WHITE);
    hexagon.setStroke(Color.BLACK);

    // A CHORD arc with no fill and a stroke
    Arc arc = new Arc(0, 0, 50, 100, 0, 90);
    arc.setFill(Color.TRANSPARENT);
    arc.setStroke(Color.BLACK);
    arc.setType(ArcType.CHORD);

    // Add all shapes to an HBox
    HBox root = new HBox(circle, rect, line, parallelogram, hexagon, arc);
    root.setSpacing(10);
    root.setStyle("-fx-padding: 10;" + "-fx-border-style: solid inside;" + "-fx-border-width: 2;"
            + "-fx-border-insets: 5;" + "-fx-border-radius: 5;" + "-fx-border-color: blue;");

    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.setTitle("2D Shapes");
    stage.show();
}

From source file:editeurpanovisu.EditeurPanovisu.java

private ScrollPane afficheLegende() {
    double positionX = 0;
    double positionY = 0;
    AnchorPane apLegende = new AnchorPane();
    ScrollPane spLegende = new ScrollPane(apLegende);
    spLegende.getStyleClass().add("legendePane");

    apLegende.setMinWidth(1000);//from   w w  w.j  a  va2s  .co  m
    apLegende.setMinHeight(150);
    apLegende.setPrefWidth(1000);
    apLegende.setPrefHeight(150);
    apLegende.setMaxWidth(1000);
    apLegende.setMaxHeight(150);
    positionY = (pano.getLayoutY() + pano.getPrefHeight() + 10);

    Circle point = new Circle(30, 20, 5);
    point.setFill(Color.YELLOW);
    point.setStroke(Color.RED);
    point.setCursor(Cursor.DEFAULT);
    Circle point2 = new Circle(30, 60, 5);
    point2.setFill(Color.BLUE);
    point2.setStroke(Color.YELLOW);
    point2.setCursor(Cursor.DEFAULT);
    Circle point3 = new Circle(30, 100, 5);
    point3.setFill(Color.GREEN);
    point3.setStroke(Color.YELLOW);
    point3.setCursor(Cursor.DEFAULT);
    Polygon polygon = new Polygon();
    polygon.getPoints().addAll(new Double[] { 15.0, 2.0, 2.0, 2.0, 2.0, 15.0, -2.0, 15.0, -2.0, 2.0, -15.0, 2.0,
            -15.0, -2.0, -2.0, -2.0, -2.0, -15.0, 2.0, -15.0, 2.0, -2.0, 15.0, -2.0 });
    polygon.setStrokeLineJoin(StrokeLineJoin.MITER);
    polygon.setFill(Color.BLUEVIOLET);
    polygon.setStroke(Color.YELLOW);
    polygon.setId("PoV");
    polygon.setLayoutX(500);
    polygon.setLayoutY(20);
    Label lblHS = new Label(rb.getString("main.legendeHS"));
    Label lblHSImage = new Label(rb.getString("main.legendeHSImage"));
    //Label lblHSHTML = new Label(rb.getString("main.legendeHSHTML"));
    Label lblPoV = new Label(rb.getString("main.legendePoV"));
    Label lblNord = new Label(rb.getString("main.legendeNord"));
    Line ligneNord = new Line(500, 45, 500, 65);
    ligneNord.setStroke(Color.RED);
    ligneNord.setStrokeWidth(3);
    lblHS.setLayoutX(50);
    lblHS.setLayoutY(10);
    lblHSImage.setLayoutX(50);
    lblHSImage.setLayoutY(50);
    //lblHSHTML.setLayoutX(50);
    //lblHSHTML.setLayoutY(90);
    lblPoV.setLayoutX(520);
    lblPoV.setLayoutY(10);
    lblNord.setLayoutX(520);
    lblNord.setLayoutY(50);
    //        apLegende.getChildren().addAll(lblHS, point, lblHSImage, point2, lblHSHTML, point3, lblPoV, polygon, lblNord, ligneNord);
    apLegende.getChildren().addAll(lblHS, point, lblHSImage, point2, lblPoV, polygon, lblNord, ligneNord);
    apLegende.setId("legende");
    apLegende.setVisible(true);
    if (largeurMax - 50 < 1004) {
        spLegende.setPrefWidth(largeurMax - 50);
        spLegende.setMaxWidth(largeurMax - 50);
        positionX = 25;
    } else {
        spLegende.setPrefWidth(1004);
        spLegende.setMaxWidth(1004);
        positionX = (largeurMax - 1004) / 2.d;
    }
    spLegende.setLayoutX(positionX);
    spLegende.setLayoutY(positionY);
    spLegende.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
    spLegende.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);

    return spLegende;
}

From source file:editeurpanovisu.EditeurPanovisu.java

private void affichePoV(double longitude, double latitude) {
    double largeur = imagePanoramique.getFitWidth();
    double X = (longitude + 180.0d) * largeur / 360.0d + imagePanoramique.getLayoutX();
    double Y = (90.0d - latitude) * largeur / 360.0d;
    Node ancPoV = (Node) pano.lookup("#PoV");
    if (ancPoV != null) {
        pano.getChildren().remove(ancPoV);
    }/*from w  ww.  ja  v a2s . c  o  m*/
    Polygon polygon = new Polygon();
    polygon.getPoints().addAll(new Double[] { 20.0, 2.0, 2.0, 2.0, 2.0, 20.0, -2.0, 20.0, -2.0, 2.0, -20.0, 2.0,
            -20.0, -2.0, -2.0, -2.0, -2.0, -20.0, 2.0, -20.0, 2.0, -2.0, 20.0, -2.0 });
    polygon.setStrokeLineJoin(StrokeLineJoin.MITER);
    polygon.setFill(Color.BLUEVIOLET);
    polygon.setStroke(Color.YELLOW);
    polygon.setId("PoV");
    polygon.setLayoutX(X);
    polygon.setLayoutY(Y);
    polygon.setCursor(Cursor.DEFAULT);
    polygon.setOnDragDetected((MouseEvent me1) -> {
        polygon.setFill(Color.YELLOW);
        polygon.setStroke(Color.BLUEVIOLET);
        dragDrop = true;
        me1.consume();

    });
    polygon.setOnMouseDragged((MouseEvent me1) -> {

        double XX = me1.getSceneX() - imagePanoramique.getLayoutX();
        if (XX < 0) {
            XX = 0;
        }
        if (XX > imagePanoramique.getFitWidth()) {
            XX = imagePanoramique.getFitWidth();
        }
        polygon.setLayoutX(XX + imagePanoramique.getLayoutX());
        double YY = me1.getSceneY() - pano.getLayoutY() - 109;
        if (YY < 0) {
            YY = 0;
        }
        if (YY > imagePanoramique.getFitHeight()) {
            YY = imagePanoramique.getFitHeight();
        }
        polygon.setLayoutY(YY);

        me1.consume();

    });
    polygon.setOnMouseReleased((MouseEvent me1) -> {
        double X1 = me1.getSceneX();
        double Y1 = me1.getSceneY();
        double mouseX1 = X1 - imagePanoramique.getLayoutX();
        if (mouseX1 < 0) {
            mouseX1 = 0;
        }
        if (mouseX1 > imagePanoramique.getFitWidth()) {
            mouseX1 = imagePanoramique.getFitWidth();
        }
        double mouseY1 = Y1 - pano.getLayoutY() - 109;
        if (mouseY1 < 0) {
            mouseY1 = 0;
        }
        if (mouseY1 > imagePanoramique.getFitHeight()) {
            mouseY1 = imagePanoramique.getFitHeight();
        }
        double regardX = 360.0f * mouseX1 / largeur - 180;
        double regardY = 90.0d - 2.0f * mouseY1 / largeur * 180.0f;
        panoramiquesProjet[panoActuel].setLookAtX(regardX);
        panoramiquesProjet[panoActuel].setLookAtY(regardY);
        polygon.setFill(Color.BLUEVIOLET);
        polygon.setStroke(Color.YELLOW);
        me1.consume();

    });

    pano.getChildren().add(polygon);
}

From source file:editeurpanovisu.EditeurPanovisu.java

/**
 *
 * @param iLargeur/*  w  w  w  . ja  va  2s . c  o  m*/
 * @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:editeurpanovisu.EditeurPanovisu.java

/**
 *
 * @param iLargeur/*from w w w .  j  a  v  a  2  s.co  m*/
 * @param iHauteur
 * @param bMasqueZones
 * @param strIdZone
 * @param mouseEvent
 */
private static void choixZone(int iLargeur, int iHauteur, boolean bMasqueZones, String strIdZone,
        MouseEvent mouseEvent) {
    ComboBox cbTouchesBarre = new ComboBox();
    cbTouchesBarre.getItems().clear();
    for (int i = 0; i < strTouchesBarre.length; i++) {
        cbTouchesBarre.getItems().add(i, strTouchesBarre[i]);
    }
    cbTouchesBarre.setLayoutX(200);
    cbTouchesBarre.setLayoutX(40);

    final int iNumeroZone = Integer.parseInt(strIdZone.split("-")[1]);
    if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) {
        if (mouseEvent.getClickCount() == 2) {
            for (int ij = iNumeroZone; ij < iNombreZones - 1; ij++) {
                zones[ij] = zones[ij + 1];
            }
            iNombreZones--;
            afficheBarrePersonnalisee(iLargeur, iHauteur, bMasqueZones);
        } else {
            afficheBarrePersonnalisee(iLargeur, iHauteur, bMasqueZones);
            apZoneBarrePersonnalisee.getChildren().clear();
            apZoneBarrePersonnalisee.getChildren().add(cbTouchesBarre);
            ZoneTelecommande zone = zones[iNumeroZone];
            int index = -1;
            for (int ij = 0; ij < strCodeBarre.length; ij++) {
                if (strCodeBarre[ij].equals(zone.getStrIdZone())) {
                    index = ij;
                }
            }
            if (index != -1) {
                cbTouchesBarre.getSelectionModel().select(index);
            }

            cbTouchesBarre.valueProperty().addListener((ov, ancienneValeur, nouvelleValeur) -> {
                if (nouvelleValeur != null) {
                    String strId = strCodeBarre[cbTouchesBarre.getSelectionModel().getSelectedIndex()];
                    zones[iNumeroZone].setStrIdZone(strId);
                }
            });

            Label lblTypeBarre = new Label(zone.getStrTypeZone());
            lblTypeBarre.setLayoutX(20);
            lblTypeBarre.setLayoutY(40);
            Label lblCoordsBarre = new Label(zone.getStrCoordonneesZone());
            lblCoordsBarre.setLayoutX(20);
            lblCoordsBarre.setLayoutY(70);
            lblCoordsBarre.setPrefWidth(260);
            lblCoordsBarre.setMaxWidth(260);
            lblCoordsBarre.setWrapText(true);
            apZoneBarrePersonnalisee.getChildren().addAll(lblTypeBarre, lblCoordsBarre);
            switch (zone.getStrTypeZone()) {
            case "poly":
                Polygon poly = (Polygon) apImgBarrePersonnalisee.lookup("#" + strIdZone);
                poly.setFill(Color.rgb(255, 0, 0, 0.5));
                poly.setStroke(Color.YELLOW);
                apImgBarrePersonnalisee.getChildren()
                        .addAll(olCreeAncresPourPolygone(iNumeroZone, poly.getPoints()));
                break;
            case "rect":
                Rectangle rect = (Rectangle) apImgBarrePersonnalisee.lookup("#" + strIdZone);
                rect.setFill(Color.rgb(255, 0, 0, 0.5));
                rect.setStroke(Color.YELLOW);
                apImgBarrePersonnalisee.getChildren().addAll(olCreeAncresPourRectangle(iNumeroZone, rect));
                break;
            case "circle":
                Circle cercle = (Circle) apImgBarrePersonnalisee.lookup("#" + strIdZone);
                cercle.setFill(Color.rgb(255, 0, 0, 0.5));
                cercle.setStroke(Color.YELLOW);
                apImgBarrePersonnalisee.getChildren().addAll(olCreeAncresPourCercle(iNumeroZone, cercle));
                break;
            }

        }
    }

}

From source file:editeurpanovisu.EditeurPanovisu.java

/**
 * Affiche la croix reprsentant le point de vue
 *
 * @param longitude longitude//from  ww w. j a v a  2s  .co m
 * @param latitude latitude
 * @param fov Champ de vision
 */
private static void affichePoV(double longitude, double latitude, double fov) {
    double largeur = ivImagePanoramique.getFitWidth();
    double X = (longitude + 180.0d) * largeur / 360.0d + ivImagePanoramique.getLayoutX();
    double Y = (90.0d - latitude) * largeur / 360.0d;
    Node nodeAncienPoV = (Node) panePanoramique.lookup("#PoV");
    if (nodeAncienPoV != null) {
        panePanoramique.getChildren().remove(nodeAncienPoV);
    }
    Polygon plgPoV = new Polygon();
    plgPoV.getPoints().addAll(new Double[] { 20.0, 2.0, 2.0, 2.0, 2.0, 20.0, -2.0, 20.0, -2.0, 2.0, -20.0, 2.0,
            -20.0, -2.0, -2.0, -2.0, -2.0, -20.0, 2.0, -20.0, 2.0, -2.0, 20.0, -2.0 });
    plgPoV.setStrokeLineJoin(StrokeLineJoin.MITER);
    plgPoV.setFill(Color.BLUEVIOLET);
    plgPoV.setStroke(Color.YELLOW);
    plgPoV.setId("PoV");
    plgPoV.setLayoutX(X);
    plgPoV.setLayoutY(Y);
    plgPoV.setCursor(Cursor.DEFAULT);
    plgPoV.setOnDragDetected((mouseEvent1) -> {
        plgPoV.setFill(Color.YELLOW);
        plgPoV.setStroke(Color.BLUEVIOLET);
        bDragDrop = true;
        mouseEvent1.consume();

    });
    plgPoV.setOnMouseDragged((mouseEvent1) -> {

        double XX = mouseEvent1.getSceneX() - ivImagePanoramique.getLayoutX();
        if (XX < 0) {
            XX = 0;
        }
        if (XX > ivImagePanoramique.getFitWidth()) {
            XX = ivImagePanoramique.getFitWidth();
        }
        plgPoV.setLayoutX(XX + ivImagePanoramique.getLayoutX());
        double YY = mouseEvent1.getSceneY() - panePanoramique.getLayoutY() - 130 - getiDecalageMac();
        if (YY < 0) {
            YY = 0;
        }
        if (YY > ivImagePanoramique.getFitHeight()) {
            YY = ivImagePanoramique.getFitHeight();
        }
        plgPoV.setLayoutY(YY);
        afficheLoupe(XX, YY);
        mouseEvent1.consume();

    });
    plgPoV.setOnMouseReleased((mouseEvent1) -> {
        double X1 = mouseEvent1.getSceneX();
        double Y1 = mouseEvent1.getSceneY();
        double mouseX1 = X1 - ivImagePanoramique.getLayoutX();
        if (mouseX1 < 0) {
            mouseX1 = 0;
        }
        if (mouseX1 > ivImagePanoramique.getFitWidth()) {
            mouseX1 = ivImagePanoramique.getFitWidth();
        }
        double mouseY1 = Y1 - panePanoramique.getLayoutY() - 130 - getiDecalageMac();
        if (mouseY1 < 0) {
            mouseY1 = 0;
        }
        if (mouseY1 > ivImagePanoramique.getFitHeight()) {
            mouseY1 = ivImagePanoramique.getFitHeight();
        }
        double regardX = 360.0f * mouseX1 / largeur - 180;
        double regardY = 90.0d - 2.0f * mouseY1 / largeur * 180.0f;
        navigateurPanoramique.setLongitude(regardX - 180);
        navigateurPanoramique.setLatitude(regardY);
        navigateurPanoramique.setFov(fov);
        navigateurPanoramique.affiche();
        getPanoramiquesProjet()[getiPanoActuel()].setRegardX(regardX);
        getPanoramiquesProjet()[getiPanoActuel()].setRegardY(regardY);
        plgPoV.setFill(Color.BLUEVIOLET);
        plgPoV.setStroke(Color.YELLOW);
        mouseEvent1.consume();

    });

    panePanoramique.getChildren().add(plgPoV);
}

From source file:editeurpanovisu.EditeurPanovisu.java

/**
 *
 * @return/*from w w  w. j  a  v  a 2 s .  c  o  m*/
 */
private static ScrollPane spAfficheLegende() {
    double positionX;
    double positionY;
    AnchorPane apLegende = new AnchorPane();
    ScrollPane spLegende = new ScrollPane(apLegende);
    spLegende.getStyleClass().add("legendePane");

    apLegende.setMinWidth(1000);
    apLegende.setMinHeight(150);
    apLegende.setPrefWidth(1000);
    apLegende.setPrefHeight(150);
    apLegende.setMaxWidth(1000);
    apLegende.setMaxHeight(150);
    positionY = (spVuePanoramique.getPrefHeight() - apLegende.getPrefHeight() - 15);

    Circle circPoint = new Circle(30, 20, 5);
    circPoint.setFill(Color.YELLOW);
    circPoint.setStroke(Color.RED);
    circPoint.setCursor(Cursor.DEFAULT);
    Circle circPoint2 = new Circle(30, 40, 5);
    circPoint2.setFill(Color.BLUE);
    circPoint2.setStroke(Color.YELLOW);
    circPoint2.setCursor(Cursor.DEFAULT);
    Circle circPoint3 = new Circle(30, 60, 5);
    circPoint3.setFill(Color.GREEN);
    circPoint3.setStroke(Color.YELLOW);
    circPoint3.setCursor(Cursor.DEFAULT);
    Polygon polygonCroix = new Polygon();
    polygonCroix.getPoints().addAll(new Double[] { 15.0, 2.0, 2.0, 2.0, 2.0, 15.0, -2.0, 15.0, -2.0, 2.0, -15.0,
            2.0, -15.0, -2.0, -2.0, -2.0, -2.0, -15.0, 2.0, -15.0, 2.0, -2.0, 15.0, -2.0 });
    polygonCroix.setStrokeLineJoin(StrokeLineJoin.MITER);
    polygonCroix.setFill(Color.BLUEVIOLET);
    polygonCroix.setStroke(Color.YELLOW);
    polygonCroix.setId("PoV");
    polygonCroix.setLayoutX(500);
    polygonCroix.setLayoutY(20);
    Label lblHS = new Label(rbLocalisation.getString("main.legendeHS"));
    Label lblHSImage = new Label(rbLocalisation.getString("main.legendeHSImage"));
    Label lblHSHTML = new Label(rbLocalisation.getString("main.legendeHSHTML"));
    Label lblPoV = new Label(rbLocalisation.getString("main.legendePoV"));
    Label lblNord = new Label(rbLocalisation.getString("main.legendeNord"));
    Line lineNord = new Line(500, 45, 500, 65);
    lineNord.setStroke(Color.RED);
    lineNord.setStrokeWidth(3);
    lblHS.setLayoutX(50);
    lblHS.setLayoutY(15);
    lblHSImage.setLayoutX(50);
    lblHSImage.setLayoutY(35);
    lblHSHTML.setLayoutX(50);
    lblHSHTML.setLayoutY(55);
    lblPoV.setLayoutX(520);
    lblPoV.setLayoutY(15);
    lblNord.setLayoutX(520);
    lblNord.setLayoutY(55);
    apLegende.getChildren().addAll(lblHS, circPoint, lblHSImage, circPoint2, lblHSHTML, circPoint3, lblPoV,
            polygonCroix, lblNord, lineNord);
    apLegende.setId("legende");
    apLegende.setVisible(true);
    if (largeurMax - 50 < 1004) {
        spLegende.setPrefWidth(largeurMax - 50);
        spLegende.setMaxWidth(largeurMax - 50);
        positionX = 25;
    } else {
        spLegende.setPrefWidth(1004);
        spLegende.setMaxWidth(1004);
        positionX = (largeurMax - 1004) / 2.d;
    }
    spLegende.setLayoutX(positionX);
    spLegende.setLayoutY(positionY);
    spLegende.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
    spLegende.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);

    return spLegende;
}

From source file:editeurpanovisu.EditeurPanovisu.java

/**
 *
 * @param iLargeur/*from   w w  w.j  av a 2s. com*/
 * @param iHauteur
 * @param bMasqueZones
 */
private static void ajouterZone(int iLargeur, int iHauteur, boolean bMasqueZones) {
    if (iNombreZones == -1) {
        iNombreZones = 0;
    }
    final ZoneTelecommande zone = new ZoneTelecommande();
    strTypeZone = "poly";
    zone.setStrTypeZone(strTypeZone);
    iNombrePointsZone = 0;
    bRecommenceZone = false;
    apZoneBarrePersonnalisee.getChildren().clear();
    Button btnAnnuler = new Button(rbLocalisation.getString("main.annuler"),
            new ImageView(new Image("file:" + getStrRepertAppli() + "/images/annule.png")));
    Button btnValider = new Button(rbLocalisation.getString("main.valider"),
            new ImageView(new Image("file:" + getStrRepertAppli() + "/images/valide.png")));
    btnValider.setLayoutX(180);
    btnValider.setLayoutY(170);
    btnAnnuler.setLayoutX(80);
    btnAnnuler.setLayoutY(170);
    ToggleGroup tgTypeZone = new ToggleGroup();
    Label lblTypeZone = new Label(rbLocalisation.getString("main.typeZone"));
    lblTypeZone.setLayoutX(20);
    lblTypeZone.setLayoutY(10);

    RadioButton rbCercleZone = new RadioButton(rbLocalisation.getString("main.cercle"));
    rbCercleZone.setLayoutX(20);
    rbCercleZone.setLayoutY(40);
    rbCercleZone.setUserData("circle");
    rbCercleZone.setToggleGroup(tgTypeZone);
    RadioButton rbRectZone = new RadioButton(rbLocalisation.getString("main.rectangle"));
    rbRectZone.setLayoutX(120);
    rbRectZone.setLayoutY(40);
    rbRectZone.setUserData("rect");
    rbRectZone.setToggleGroup(tgTypeZone);
    RadioButton rbPolyZone = new RadioButton(rbLocalisation.getString("main.polygone"));
    rbPolyZone.setLayoutX(220);
    rbPolyZone.setLayoutY(40);
    rbPolyZone.setUserData("poly");
    rbPolyZone.setToggleGroup(tgTypeZone);
    rbPolyZone.setSelected(true);
    ComboBox cbTouchesBarre = new ComboBox();
    cbTouchesBarre.getItems().clear();
    for (int i = 0; i < strTouchesBarre.length; i++) {
        cbTouchesBarre.getItems().add(i, strTouchesBarre[i]);
    }
    cbTouchesBarre.setLayoutX(50);
    cbTouchesBarre.setLayoutY(110);

    afficheBarrePersonnalisee(iLargeur, iHauteur, bMasqueZones);
    AnchorPane apCreeZone = new AnchorPane();
    apCreeZone.setStyle("-fx-background-color : rgba(0,0,0,0.1)");
    apCreeZone.setPrefWidth(imgBarrePersonnalisee.getWidth());
    apCreeZone.setPrefHeight(imgBarrePersonnalisee.getHeight());
    apCreeZone.setCursor(Cursor.CROSSHAIR);
    apImgBarrePersonnalisee.getChildren().add(apCreeZone);
    apZoneBarrePersonnalisee.getChildren().addAll(lblTypeZone, rbCercleZone, rbRectZone, rbPolyZone,
            cbTouchesBarre, btnAnnuler, btnValider);
    apCreeZone.setOnMouseClicked((t) -> {
        rbCercleZone.setDisable(true);
        rbRectZone.setDisable(true);
        rbPolyZone.setDisable(true);
        iNombrePointsZone++;
        switch (strTypeZone) {
        case "rect":
            if (iNombrePointsZone == 1) {
                apCreeZone.getChildren().clear();
                x1Zone = t.getX();
                y1Zone = t.getY();
                Circle cercle = new Circle(t.getX(), t.getY(), 4);
                cercle.setFill(Color.rgb(255, 0, 0, 0.5));
                cercle.setStroke(Color.YELLOW);
                apCreeZone.getChildren().add(cercle);
            }
            if (iNombrePointsZone == 2) {
                apCreeZone.getChildren().clear();
                Rectangle rect = new Rectangle(x1Zone, y1Zone, t.getX() - x1Zone, t.getY() - y1Zone);
                rect.setFill(Color.rgb(255, 0, 0, 0.5));
                rect.setStroke(Color.YELLOW);
                apCreeZone.getChildren().add(rect);
                String chaine = Math.round(x1Zone * 10) / 10 + "," + Math.round(y1Zone * 10) / 10 + ","
                        + Math.round(t.getX() * 10) / 10 + "," + Math.round(t.getY() * 10) / 10;
                zone.setStrCoordonneesZone(chaine);
                iNombrePointsZone = 0;
            }
            break;
        case "circle":
            if (iNombrePointsZone == 1) {
                apCreeZone.getChildren().clear();
                x1Zone = t.getX();
                y1Zone = t.getY();
                Circle cercle = new Circle(t.getX(), t.getY(), 4);
                cercle.setFill(Color.rgb(255, 0, 0, 0.5));
                cercle.setStroke(Color.YELLOW);
                apCreeZone.getChildren().add(cercle);
            }
            if (iNombrePointsZone == 2) {
                apCreeZone.getChildren().clear();
                double rayon = Math.sqrt(Math.pow(x1Zone - t.getX(), 2.d) + Math.pow(y1Zone - t.getY(), 2.d));
                Circle cercle = new Circle(x1Zone, y1Zone, rayon);
                cercle.setFill(Color.rgb(255, 0, 0, 0.5));
                cercle.setStroke(Color.YELLOW);
                apCreeZone.getChildren().add(cercle);
                String chaine = Math.round(x1Zone * 10) / 10 + "," + Math.round(y1Zone * 10) / 10 + ","
                        + Math.round(rayon * 10) / 10;
                zone.setStrCoordonneesZone(chaine);
                iNombrePointsZone = 0;
            }
            break;
        case "poly":
            if (bRecommenceZone) {
                bRecommenceZone = false;
                iNombrePointsZone = 1;
            }
            if (iNombrePointsZone == 1) {
                apCreeZone.getChildren().clear();
                x1Zone = t.getX();
                y1Zone = t.getY();
                Circle cercle = new Circle(t.getX(), t.getY(), 4);
                cercle.setFill(Color.rgb(255, 0, 0, 0.5));
                cercle.setStroke(Color.YELLOW);
                apCreeZone.getChildren().add(cercle);
                pointsPolyZone[(iNombrePointsZone - 1) * 2] = t.getX();
                pointsPolyZone[(iNombrePointsZone - 1) * 2 + 1] = t.getY();
            }
            if (iNombrePointsZone == 2) {
                apCreeZone.getChildren().clear();
                Line ligne = new Line(x1Zone, y1Zone, t.getX(), t.getY());
                ligne.setStroke(Color.YELLOW);
                apCreeZone.getChildren().add(ligne);
                pointsPolyZone[(iNombrePointsZone - 1) * 2] = t.getX();
                pointsPolyZone[(iNombrePointsZone - 1) * 2 + 1] = t.getY();
            }
            if (iNombrePointsZone > 2) {
                pointsPolyZone[(iNombrePointsZone - 1) * 2] = t.getX();
                pointsPolyZone[(iNombrePointsZone - 1) * 2 + 1] = t.getY();
                apCreeZone.getChildren().clear();
                Polygon poly = new Polygon();
                for (int i = 0; i < iNombrePointsZone; i++) {
                    poly.getPoints().addAll(pointsPolyZone[i * 2], pointsPolyZone[i * 2 + 1]);
                }
                poly.setFill(Color.rgb(255, 0, 0, 0.5));
                poly.setStroke(Color.YELLOW);
                apCreeZone.getChildren().add(poly);
            }
            if (t.getClickCount() == 2) {
                String chaine = "";
                for (int i = 0; i < iNombrePointsZone; i++) {
                    if (i != 0) {
                        chaine += ",";
                    }
                    chaine += Math.round(pointsPolyZone[i * 2] * 10) / 10 + ","
                            + Math.round(pointsPolyZone[i * 2 + 1] * 10) / 10;
                }
                zone.setStrCoordonneesZone(chaine);
                bRecommenceZone = true;
            }
            break;
        }
    });

    apCreeZone.setOnMouseMoved((t) -> {
        switch (strTypeZone) {
        case "rect":
            if (iNombrePointsZone == 1) {
                apCreeZone.getChildren().clear();
                Rectangle rect = new Rectangle(x1Zone, y1Zone, t.getX() - x1Zone, t.getY() - y1Zone);
                rect.setFill(Color.rgb(255, 0, 0, 0.5));
                rect.setStroke(Color.YELLOW);
                apCreeZone.getChildren().add(rect);
            }
            break;
        case "circle":
            if (iNombrePointsZone == 1) {
                apCreeZone.getChildren().clear();
                double rayon = Math.sqrt(Math.pow(x1Zone - t.getX(), 2.d) + Math.pow(y1Zone - t.getY(), 2.d));
                Circle cercle = new Circle(x1Zone, y1Zone, rayon);
                cercle.setFill(Color.rgb(255, 0, 0, 0.5));
                cercle.setStroke(Color.YELLOW);
                apCreeZone.getChildren().add(cercle);
            }
            break;
        case "poly":
            if (!bRecommenceZone) {
                if (iNombrePointsZone == 1) {
                    apCreeZone.getChildren().clear();
                    Line ligne = new Line(x1Zone, y1Zone, t.getX(), t.getY());
                    ligne.setStroke(Color.YELLOW);
                    apCreeZone.getChildren().add(ligne);
                }
                if (iNombrePointsZone > 1) {
                    apCreeZone.getChildren().clear();
                    Polygon poly = new Polygon();
                    for (int i = 0; i < iNombrePointsZone; i++) {
                        poly.getPoints().addAll(pointsPolyZone[i * 2], pointsPolyZone[i * 2 + 1]);
                    }
                    poly.getPoints().addAll(t.getX(), t.getY());
                    poly.setFill(Color.rgb(255, 0, 0, 0.5));
                    poly.setStroke(Color.YELLOW);
                    apCreeZone.getChildren().add(poly);
                }
            }
            break;
        }
    });

    btnValider.setOnMouseClicked((t) -> {
        if (strTypeZone.equals("poly")) {
            String strChaine = "";
            for (int i = 0; i < iNombrePointsZone; i++) {
                if (i != 0) {
                    strChaine += ",";
                }
                strChaine += Math.round(pointsPolyZone[i * 2] * 10) / 10 + ","
                        + Math.round(pointsPolyZone[i * 2 + 1] * 10) / 10;
            }
            zone.setStrCoordonneesZone(strChaine);

        }
        zones[iNombreZones] = zone;
        iNombreZones++;
        afficheBarrePersonnalisee(iLargeur, iHauteur, bMasqueZones);
        btnAjouteZone.setDisable(false);
    });

    btnAnnuler.setOnMouseClicked((t) -> {
        afficheBarrePersonnalisee(iLargeur, iHauteur, bMasqueZones);
        btnAjouteZone.setDisable(false);
    });

    cbTouchesBarre.valueProperty().addListener((ov, strAncienneValeur, strNouvelleValeur) -> {
        if (strNouvelleValeur != null) {
            String strId = strCodeBarre[cbTouchesBarre.getSelectionModel().getSelectedIndex()];
            zone.setStrIdZone(strId);
        }
    });

    tgTypeZone.selectedToggleProperty()
            .addListener((ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) -> {
                if (tgTypeZone.getSelectedToggle() != null) {
                    strTypeZone = tgTypeZone.getSelectedToggle().getUserData().toString();
                    zone.setStrTypeZone(strTypeZone);
                }
            });

}