Example usage for javafx.scene.control RadioButton setLayoutX

List of usage examples for javafx.scene.control RadioButton setLayoutX

Introduction

In this page you can find the example usage for javafx.scene.control RadioButton setLayoutX.

Prototype

public final void setLayoutX(double value) 

Source Link

Usage

From source file:editeurpanovisu.EditeurPanovisu.java

/**
 *
 * @param iLargeur//from   www  .  j  a  v  a 2  s .  co  m
 * @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);
                }
            });

}