Example usage for javafx.scene.control Button Button

List of usage examples for javafx.scene.control Button Button

Introduction

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

Prototype

public Button(String text, Node graphic) 

Source Link

Document

Creates a button with the specified text and icon for its label.

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setTitle("Button Sample");
    stage.setWidth(300);/*ww w  .  ja  va2  s  .c  o  m*/
    stage.setHeight(190);

    VBox vbox = new VBox();
    vbox.setLayoutX(20);
    vbox.setLayoutY(20);

    Image image = new Image(getClass().getResourceAsStream("a.png"));
    Button button1 = new Button("Accept", new ImageView(image));
    button1.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            System.out.println("Accepted");
        }
    });

    vbox.getChildren().add(button1);
    vbox.setSpacing(10);
    ((Group) scene.getRoot()).getChildren().add(vbox);

    stage.setScene(scene);
    stage.show();
}

From source file:de.perdian.apps.tagtiger.fx.handlers.batchupdate.UpdateFileNamesFromTagsActionEventHandler.java

@Override
protected BatchUpdateDialog createDialog() {

    ObservableList<UpdateFileNamesFromTagsItem> items = FXCollections.observableArrayList(
            this.getOtherFiles().stream().map(UpdateFileNamesFromTagsItem::new).collect(Collectors.toList()));
    StringProperty patternFieldProperty = new SimpleStringProperty();

    List<String> patternItems = Arrays.asList("${track} ${title}");
    ComboBox<String> patternBox = new ComboBox<>(FXCollections.observableArrayList(patternItems));
    patternBox.setEditable(true);//  www .j a v  a2 s  .  co  m
    patternBox.setMaxWidth(Double.MAX_VALUE);
    Bindings.bindBidirectional(patternFieldProperty, patternBox.editorProperty().get().textProperty());
    HBox.setHgrow(patternBox, Priority.ALWAYS);

    Button executeButton = new Button(this.getLocalization().executeRename(),
            new ImageView(new Image(UpdateFileNamesFromTagsActionEventHandler.class.getClassLoader()
                    .getResourceAsStream("icons/16/save.png"))));
    executeButton.setDisable(true);
    patternFieldProperty
            .addListener((o, oldValue, newValue) -> executeButton.setDisable(newValue.length() <= 0));

    HBox patternFieldPane = new HBox(10, patternBox, executeButton);
    patternFieldPane.setPadding(new Insets(5, 5, 5, 5));

    TitledPane patternFieldTitlePane = new TitledPane(this.getLocalization().fileNamePattern(),
            patternFieldPane);
    patternFieldTitlePane.setCollapsible(false);

    TableView<?> newFileNamesPane = this.createNewFileNamesPane(items);
    newFileNamesPane.setPrefHeight(400);
    VBox.setVgrow(newFileNamesPane, Priority.ALWAYS);

    VBox actionPane = new VBox(10, patternFieldTitlePane, newFileNamesPane);

    // Create the dialog and finish
    BatchUpdateDialog dialog = new BatchUpdateDialog();
    dialog.setDialogPrefWidth(800);
    dialog.setDialogTitle(this.getLocalization().updateFileNames());
    dialog.setActionPane(actionPane);
    dialog.setLegendPane(this.createLegendPane());

    // Add listeners
    this.getOtherFiles().addListener(
            new WeakListChangeListener<>((Change<? extends TaggableFile> change) -> items.setAll(change
                    .getList().stream().map(UpdateFileNamesFromTagsItem::new).collect(Collectors.toList()))));
    patternFieldProperty.addListener((o, oldValue, newValue) -> this.computeNewFileNames(items, newValue));
    executeButton.setOnAction(event -> {
        this.updateNewFileNames(items);
        ((Stage) executeButton.getScene().getWindow()).close();
    });

    return dialog;

}

From source file:com.playonlinux.ui.impl.javafx.mainwindow.center.ViewApps.java

private void initFailure() {
    failurePanel = new VBox();
    failurePanel.getStyleClass().add("rightPane");

    failurePanel.setSpacing(10);// w ww.j av  a  2  s. c om
    failurePanel.setAlignment(Pos.CENTER);

    Label failureNotificationLbl = new Label();
    failureNotificationLbl.setText(translate(
            "Connecting to ${application.name} failed.\n" + "Please check your connection and try again."));
    failureNotificationLbl.setTextAlignment(TextAlignment.CENTER);

    ImageView retryImage = new ImageView(new Image(getClass().getResourceAsStream("refresh.png")));
    retryImage.setFitWidth(16);
    retryImage.setFitHeight(16);
    retryButton = new Button(translate("Retry"), retryImage);

    failurePanel.getChildren().addAll(failureNotificationLbl, retryButton);
}

From source file:com.advos.notehub.client.util.sandsoft.CustomHTMLEditor.java

/**
 * Creates Custom ToolBar buttons and other controls
 *//*  w w w  .j  a v a 2s  .  c o  m*/
private void createCustomButtons() {
    //add embed file button  
    ImageView graphic = new ImageView(new Image(getClass().getResourceAsStream(IMPORT_BUTTON_GENERAL)));
    mImportFileButton = new Button("Import File", graphic);
    mImportFileButton.setTooltip(new Tooltip("Import File"));
    mImportFileButton.setOnAction((event) -> onImportFileButtonAction());

    //add to top toolbar         
    mTopToolBar.getItems().add(mImportFileButton);
    mTopToolBar.getItems().add(new Separator(Orientation.VERTICAL));
}

From source file:cz.lbenda.gui.controls.TextAreaFrmController.java

/** Create button which can open text editor */
public static Button createOpenButton(String windowTitle, @Nonnull Supplier<String> oldValueSupplier,
        @Nonnull Consumer<String> newValueConsumer) {
    String title = windowTitle == null ? msgDefaultWindowTitle : windowTitle;
    Button result = new Button(null, new ImageView(BUTTON_IMAGE));
    result.setTooltip(new Tooltip(msgBtnOpenInEditor_tooltip));
    BorderPane.setAlignment(result, Pos.TOP_RIGHT);
    result.setOnAction(event -> {/* w w  w.ja va2 s  .  c o m*/
        Tuple2<Parent, TextAreaFrmController> tuple2 = TextAreaFrmController.createNewInstance();
        tuple2.get2().textProperty().setValue(oldValueSupplier.get());
        tuple2.get2().textProperty()
                .addListener((observable, oldValue, newValue) -> newValueConsumer.accept(newValue));
        Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
        DialogHelper.getInstance().openWindowInCenterOfStage(stage, tuple2.get2().getMainPane(), title);
    });
    return result;
}

From source file:com.mycompany.pfinanzaspersonales.BuscadorController.java

@FXML
private void btnBuscar(ActionEvent event) throws IOException {

    String desde_t = "", hasta_t = "";

    if (input_desde.getValue() != null) {
        desde_t = input_desde.getValue().toString();
    }/*from w  w  w  .  ja va  2  s .  com*/

    if (input_hasta.getValue() != null) {
        hasta_t = input_hasta.getValue().toString();
    }

    final String desde = desde_t;
    final String hasta = hasta_t;

    final Task<Void> tarea = new Task<Void>() {
        @Override
        protected Void call() throws Exception {

            HttpResponse response;
            List<NameValuePair> parametros = new ArrayList<NameValuePair>();

            parametros.add(new BasicNameValuePair("tipo", cbb_tipo.getValue().toString()));
            parametros.add(new BasicNameValuePair("pago", cbb_pago.getValue().toString()));
            parametros.add(new BasicNameValuePair("desde", desde));
            parametros.add(new BasicNameValuePair("hasta", hasta));

            System.out.println(desde);
            response = JSON.request(Config.URL + "usuarios/buscar.json", parametros);

            JSONObject jObject = JSON.JSON(response);
            tabla_json = new ArrayList<TablaBuscar>();

            try {

                editar.setCellValueFactory(new PropertyValueFactory<TablaBuscar, String>("editar"));
                eliminar.setCellValueFactory(new PropertyValueFactory<TablaBuscar, String>("eliminar"));
                fecha.setCellValueFactory(new PropertyValueFactory<TablaBuscar, String>("fecha"));
                categoria.setCellValueFactory(new PropertyValueFactory<TablaBuscar, String>("categoria"));
                tpago.setCellValueFactory(new PropertyValueFactory<TablaBuscar, String>("pago"));
                tmonto.setCellValueFactory(new PropertyValueFactory<TablaBuscar, String>("monto"));
                ttipo.setCellValueFactory(new PropertyValueFactory<TablaBuscar, String>("tipo"));

                tabla_json = new ArrayList<TablaBuscar>();

                if (!jObject.get("data").equals(null)) {
                    JSONArray jsonArr = jObject.getJSONArray("data");
                    for (int i = 0; i < jsonArr.length(); i++) {
                        JSONObject data_json = jsonArr.getJSONObject(i);
                        tabla_json.add(new TablaBuscar(data_json.get("idgastos").toString(),
                                data_json.get("idgastos").toString(), data_json.get("idgastos").toString(),
                                data_json.get("monto").toString(), data_json.get("fecha").toString(),
                                data_json.get("nom_mediopago").toString(),
                                data_json.get("categoria").toString(), data_json.get("tipo").toString()));
                    }
                }
                tabla_buscador.setItems(FXCollections.observableArrayList(tabla_json));

            } catch (Exception e) {
                e.printStackTrace();
            }

            return null;
        }

        @Override
        protected void succeeded() {
            super.succeeded();

            eliminar.setCellFactory(new Callback<TableColumn<String, String>, TableCell<String, String>>() {
                @Override
                public TableCell<String, String> call(TableColumn<String, String> p) {

                    return new TableCell<String, String>() {
                        @Override
                        public void updateItem(String item, boolean empty) {

                            super.updateItem(item, empty);

                            if (!isEmpty() && !empty) {

                                final VBox vbox = new VBox(5);
                                Image image = new Image(getClass().getResourceAsStream("/Imagenes/delete.png"));
                                final Button boton = new Button("", new ImageView(image));
                                boton.setOnAction(new EventHandler<ActionEvent>() {
                                    @Override
                                    public void handle(ActionEvent event) {

                                        Action response = Dialogs.create().title("Eliminar Gasto")
                                                .message("Ests seguro que desaeas eliminar el gasto?")
                                                .showConfirm();

                                        if (response == Dialog.ACTION_YES) {

                                            TablaBuscar tabla = tabla_json.get(getTableRow().getIndex());

                                            List<NameValuePair> parametros = new ArrayList<NameValuePair>();

                                            String url = "";
                                            if (tabla.getTipo() == "Gastos") {
                                                parametros
                                                        .add(new BasicNameValuePair("idgastos", tabla.getId()));
                                                url = Config.URL + "gastos/eliminar.json";
                                            } else {
                                                parametros.add(
                                                        new BasicNameValuePair("idingresos", tabla.getId()));
                                                url = Config.URL + "ingresos/eliminar.json";
                                            }

                                            HttpResponse responseJSON = JSON.request(url, parametros);
                                            JSONObject jObject = JSON.JSON(responseJSON);
                                            int code = Integer.parseInt(jObject.get("code").toString());

                                            if (code == 201) {
                                                int selectdIndex = getTableRow().getIndex();
                                                tabla_json.remove(selectdIndex);
                                                tabla_buscador.getItems().remove(selectdIndex);
                                            } else {
                                                Dialogs.create().title("Error sincronizacin").message(
                                                        "Hubo un error al intentar eliminar . ERROR: 301")
                                                        .showInformation();
                                            }

                                        }

                                    }
                                });

                                vbox.getChildren().add(boton);
                                setGraphic(vbox);
                            } else {
                                setGraphic(null);
                            }
                        }
                    };
                }
            });

            editar.setCellFactory(new Callback<TableColumn<String, String>, TableCell<String, String>>() {
                @Override
                public TableCell<String, String> call(TableColumn<String, String> p) {

                    return new TableCell<String, String>() {
                        @Override
                        public void updateItem(String item, boolean empty) {

                            super.updateItem(item, empty);

                            if (!isEmpty() && !empty) {

                                final VBox vbox = new VBox(5);
                                Image image = new Image(getClass().getResourceAsStream("/Imagenes/edit.png"));
                                final Button boton = new Button("", new ImageView(image));
                                boton.setOnAction(new EventHandler<ActionEvent>() {
                                    @Override
                                    public void handle(ActionEvent event) {

                                        TablaBuscar tabla = tabla_json.get(getTableRow().getIndex());

                                        Parent parent = null;
                                        if (tabla.getTipo() == "Gastos") {
                                            AgregarGastos AG = AgregarGastos.getInstance();

                                            AG.setID(tabla.getId());
                                            AG.setMonto(tabla.getMonto());
                                            AG.setCategoria(tabla.getCategoria());
                                            AG.setPago(tabla.getPago());
                                            AG.setActualizacion(true);

                                            try {
                                                parent = FXMLLoader.load(this.getClass()
                                                        .getResource("/fxml/AgregarGastos.fxml"));
                                            } catch (IOException ex) {
                                                Logger.getLogger(FXMLController.class.getName())
                                                        .log(Level.SEVERE, null, ex);
                                            }
                                        } else {
                                            AgregarIngresos AI = AgregarIngresos.getInstance();

                                            AI.setID(tabla.getId());
                                            AI.setMonto(tabla.getMonto());
                                            AI.setCategoria(tabla.getCategoria());
                                            AI.setPago(tabla.getPago());
                                            AI.setActualizar(true);

                                            try {
                                                parent = FXMLLoader.load(this.getClass()
                                                        .getResource("/fxml/AgregarIngresos.fxml"));
                                            } catch (IOException ex) {
                                                Logger.getLogger(FXMLController.class.getName())
                                                        .log(Level.SEVERE, null, ex);
                                            }
                                        }

                                        Stage stage = new Stage();
                                        Scene scene = new Scene(parent);
                                        stage.setScene(scene);
                                        stage.show();

                                    }
                                });

                                vbox.getChildren().add(boton);
                                setGraphic(vbox);
                            } else {
                                setGraphic(null);
                            }
                        }
                    };
                }
            });

        }
    };
    new Thread(tarea).start();
}

From source file:at.ac.tuwien.qse.sepm.gui.controller.impl.OrganizerImpl.java

private void initializeFilesTree() {
    folderTree.setOnMouseClicked(event -> handleFolderChange());
    folderTree.setCellFactory(treeView -> {
        HBox hbox = new HBox();
        hbox.setMaxWidth(200);/* ww w  .  j a  va 2 s .  c  om*/
        hbox.setPrefWidth(200);
        hbox.setSpacing(7);

        FontAwesomeIconView openFolderIcon = new FontAwesomeIconView(FontAwesomeIcon.FOLDER_OPEN_ALT);
        openFolderIcon.setTranslateY(7);
        FontAwesomeIconView closedFolderIcon = new FontAwesomeIconView(FontAwesomeIcon.FOLDER_ALT);
        closedFolderIcon.setTranslateY(7);

        Label dirName = new Label();
        dirName.setMaxWidth(150);

        FontAwesomeIconView removeIcon = new FontAwesomeIconView(FontAwesomeIcon.REMOVE);

        Tooltip deleteToolTip = new Tooltip();
        deleteToolTip.setText("Verzeichnis aus Workspace entfernen");

        Button button = new Button(null, removeIcon);
        button.setTooltip(deleteToolTip);
        button.setTranslateX(8);

        return new TreeCell<String>() {
            @Override
            public void updateItem(String item, boolean empty) {
                super.updateItem(item, empty);
                if (item == null || empty) {
                    setGraphic(null);
                    setText(null);
                } else if (getTreeItem() instanceof FilePathTreeItem) {
                    hbox.getChildren().clear();
                    dirName.setText(item);
                    if (getTreeItem().isExpanded()) {
                        hbox.getChildren().add(openFolderIcon);
                    } else {
                        hbox.getChildren().add(closedFolderIcon);
                    }
                    hbox.getChildren().add(dirName);
                    TreeItem<String> treeItem = getTreeItem();
                    TreeItem<String> parent = treeItem != null ? treeItem.getParent() : null;
                    if (parent != null && parent.equals(folderTree.getRoot())) {
                        String path = ((FilePathTreeItem) getTreeItem()).getFullPath();
                        button.setOnAction(event -> handleDeleteDirectory(Paths.get(path)));
                        hbox.getChildren().add(button);
                    }
                    setGraphic(hbox);
                }
            }
        };
    });
}

From source file:AudioPlayer3.java

private Button createPlayPauseButton() {
    URL url = getClass().getResource("resources/pause.png");
    pauseImg = new Image(url.toString());

    url = getClass().getResource("resources/play.png");
    playImg = new Image(url.toString());

    playPauseIcon = new ImageView(playImg);

    final Button playPauseButton = new Button(null, playPauseIcon);
    playPauseButton.setId("playPauseButton");
    playPauseButton.setOnAction(new EventHandler<ActionEvent>() {
        @Override/*from  w w w  .  ja v  a2 s.c o m*/
        public void handle(ActionEvent arg0) {
            final MediaPlayer mediaPlayer = songModel.getMediaPlayer();
            if (mediaPlayer.getStatus() == MediaPlayer.Status.PLAYING) {
                mediaPlayer.pause();
            } else {
                mediaPlayer.play();
            }
        }
    });
    return playPauseButton;
}

From source file:editeurpanovisu.EditeurPanovisu.java

/**
 *
 * @param iLargeur//from  w w w.j  a v a2s .c  o  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);
                }
            });

}

From source file:editeurpanovisu.EditeurPanovisu.java

/**
 *
 * @param strNomFichierBarre/*from   w ww.j ava  2 s.  c  om*/
 */
public static void creerEditerBarre(String strNomFichierBarre) {
    apCreationBarre.getChildren().clear();
    apCreationBarre.setStyle("-fx-background-color : -fx-base;" + "-fx-border-color: derive(-fx-base,10%);"
            + "-fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.5) , 8, 0.0 , 0 , 8 );"
            + "-fx-border-width: 1px;");

    AnchorPane apOutilsBarre = new AnchorPane();
    Button btnAnnulerBarre = new Button(rbLocalisation.getString("main.quitter"),
            new ImageView(new Image("file:" + getStrRepertAppli() + "/images/annule.png")));
    final Button btnSauverBarre = new Button(rbLocalisation.getString("main.sauver"), new ImageView(
            new Image("file:" + getStrRepertAppli() + "/images/sauveProjet.png", 24, 24, true, true, true)));
    Rectangle2D tailleEcran = Screen.getPrimary().getBounds();
    btnAjouteZone = new Button(rbLocalisation.getString("main.ajouteZone"), new ImageView(
            new Image("file:" + getStrRepertAppli() + "/images/btn+.png", 24, 24, true, true, true)));
    apImgBarrePersonnalisee = new AnchorPane();
    apImgBarrePersonnalisee.getChildren().clear();
    apZoneBarrePersonnalisee = new AnchorPane();
    apZoneBarrePersonnalisee.getChildren().clear();
    apZoneBarrePersonnalisee.setLayoutX(0);
    apZoneBarrePersonnalisee.setLayoutY(150);
    apZoneBarrePersonnalisee.setPrefWidth(300);
    apZoneBarrePersonnalisee.setPrefHeight(200);

    int iLargeurEcran = (int) tailleEcran.getWidth();
    int iHauteurEcran = (int) tailleEcran.getHeight() - 100;
    final int iLargeur = 1200;
    final int iHauteur = 600;
    mbarPrincipal.setDisable(true);
    bbarPrincipal.setDisable(true);
    hbBarreBouton.setDisable(true);
    tpEnvironnement.setDisable(true);
    apCreationBarre.setPrefWidth(iLargeur);
    apCreationBarre.setMinWidth(iLargeur);
    apCreationBarre.setMaxWidth(iLargeur);
    apCreationBarre.setPrefHeight(iHauteur);
    apCreationBarre.setMinHeight(iHauteur);
    apCreationBarre.setMaxHeight(iHauteur);
    apCreationBarre.setLayoutX((iLargeurEcran - iLargeur) / 2);
    apCreationBarre.setLayoutY((iHauteurEcran - iHauteur) / 2);
    apCreationBarre.setVisible(true);
    Label lblBarrePersonnalisee = new Label(rbLocalisation.getString("main.creeBarrePersonnalisee"));
    lblBarrePersonnalisee.setMinWidth(iLargeur - 10);
    lblBarrePersonnalisee.setAlignment(Pos.CENTER);
    lblBarrePersonnalisee.setStyle("-fx-background-color : #777;");
    lblBarrePersonnalisee.setTextFill(Color.WHITE);
    lblBarrePersonnalisee.setLayoutX(5);
    lblBarrePersonnalisee.setLayoutY(10);
    lblBarrePersonnalisee.setFont(Font.font(14));
    apCreationBarre.getChildren().add(lblBarrePersonnalisee);
    apOutilsBarre.setPrefWidth(300);
    apOutilsBarre.setMinWidth(300);
    apOutilsBarre.setMaxWidth(300);
    apOutilsBarre.setPrefHeight(iHauteur - 50);
    apOutilsBarre.setMinHeight(iHauteur - 50);
    apOutilsBarre.setMaxHeight(iHauteur - 50);
    apOutilsBarre.setLayoutX(iLargeur - 302);
    apOutilsBarre.setLayoutY(50);

    apOutilsBarre.setStyle(
            "-fx-background-color : -fx-background;-fx-border-width : 1px;-fx-border-color : transparent transparent transparent -fx-outer-border;");
    btnAnnulerBarre.setPrefWidth(120);
    btnAnnulerBarre.setLayoutX(30);
    btnAnnulerBarre.setLayoutY(iHauteur - 90);
    btnSauverBarre.setPrefWidth(120);
    btnSauverBarre.setLayoutX(160);
    btnSauverBarre.setLayoutY(iHauteur - 90);
    btnSauverBarre.setDisable(true);
    Label lblChargeImage = new Label(rbLocalisation.getString("main.chargeImage"));
    lblChargeImage.setLayoutX(20);
    lblChargeImage.setLayoutY(10);
    TextField tfChargeImage = new TextField("");
    tfChargeImage.setDisable(true);
    tfChargeImage.setPrefWidth(200);
    tfChargeImage.setLayoutX(50);
    tfChargeImage.setLayoutY(40);
    Button btnChargeImage = new Button("...");
    btnChargeImage.setLayoutX(260);
    btnChargeImage.setLayoutY(40);
    final CheckBox cbMasqueZones = new CheckBox(rbLocalisation.getString("main.masqueZones"));
    cbMasqueZones.setDisable(true);
    cbMasqueZones.setLayoutX(20);
    cbMasqueZones.setLayoutY(70);
    btnAjouteZone.setLayoutX(130);
    btnAjouteZone.setLayoutY(110);
    btnAjouteZone.setDisable(true);
    apOutilsBarre.getChildren().addAll(lblChargeImage, tfChargeImage, btnChargeImage, cbMasqueZones,
            btnAjouteZone, apZoneBarrePersonnalisee, btnAnnulerBarre, btnSauverBarre);

    apCreationBarre.getChildren().addAll(apImgBarrePersonnalisee, apOutilsBarre);
    if (!strNomFichierBarre.equals("")) {
        lblChargeImage.setVisible(false);
        tfChargeImage.setVisible(false);
        btnChargeImage.setVisible(false);
        String strNomFichier = strNomFichierBarre;
        strNomFichier = strNomFichier.substring(0, strNomFichier.length() - 4);
        strNomFichierShp = strNomFichier + ".shp";
        String strNomFichierPng = strNomFichier + ".png";
        File fichPng = new File(strNomFichierPng);
        if (fichPng.exists()) {
            try {
                btnAjouteZone.setDisable(false);
                imgBarrePersonnalisee = new Image("file:" + fichPng);
                iNombreZones = getGestionnaireInterface().lisFichierShp(strNomFichierShp, zones);
                btnSauverBarre.setDisable(false);
                if (iNombreZones > 0) {
                    cbMasqueZones.setDisable(false);
                }
                afficheBarrePersonnalisee(iLargeur, iHauteur, false);

            } catch (IOException ex) {
                Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }

    btnAnnulerBarre.setOnMouseClicked((t) -> {
        mbarPrincipal.setDisable(false);
        bbarPrincipal.setDisable(false);
        hbBarreBouton.setDisable(false);
        tpEnvironnement.setDisable(false);
        apCreationBarre.setVisible(false);
    });

    btnAjouteZone.setOnMouseClicked((t) -> {
        btnAjouteZone.setDisable(true);
        ajouterZone(iLargeur, iHauteur, false);
    });
    btnChargeImage.setOnMouseClicked((t) -> {
        strRepertBarrePersonnalisee = getStrRepertAppli() + "/theme/telecommandes";
        File fileRepert;
        fileRepert = new File(strRepertBarrePersonnalisee);
        FileChooser fileChooser = new FileChooser();
        FileChooser.ExtensionFilter efShpFilter = new FileChooser.ExtensionFilter(
                "Fichiers barre personnalise (SHP)", "*.shp", "*.png");

        fileChooser.setInitialDirectory(fileRepert);
        fileChooser.getExtensionFilters().addAll(efShpFilter);

        File fileFichierImage = fileChooser.showOpenDialog(null);
        if (fileFichierImage != null) {
            String strNomFichier = fileFichierImage.getAbsolutePath();
            strNomFichier = strNomFichier.substring(0, strNomFichier.length() - 4);
            strNomFichierShp = strNomFichier + ".shp";
            String strNomFichierPng = strNomFichier + ".png";
            File fileFichierPng = new File(strNomFichierPng);
            if (fileFichierPng.exists()) {
                try {
                    btnAjouteZone.setDisable(false);
                    imgBarrePersonnalisee = new Image("file:" + fileFichierPng);
                    iNombreZones = getGestionnaireInterface().lisFichierShp(strNomFichierShp, zones);
                    btnSauverBarre.setDisable(false);
                    if (iNombreZones > 0) {
                        cbMasqueZones.setDisable(false);
                    }
                    afficheBarrePersonnalisee(iLargeur, iHauteur, false);

                } catch (IOException ex) {
                    Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    });

    btnSauverBarre.setOnMouseClicked((t) -> {
        try {
            sauverBarre(strNomFichierShp);
            getGestionnaireInterface().chargeBarrePersonnalisee(strNomFichierBarre);

        } catch (IOException ex) {
            Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex);
        }
    });
    cbMasqueZones.selectedProperty()
            .addListener((ObservableValue<? extends Boolean> ov, Boolean old_val, Boolean new_val) -> {
                afficheBarrePersonnalisee(iLargeur, iHauteur, new_val);
            });

}