Example usage for javafx.stage Stage setOnCloseRequest

List of usage examples for javafx.stage Stage setOnCloseRequest

Introduction

In this page you can find the example usage for javafx.stage Stage setOnCloseRequest.

Prototype

public final void setOnCloseRequest(EventHandler<WindowEvent> value) 

Source Link

Usage

From source file:poe.trade.assist.Main.java

@Override
public void start(Stage stage) {
    //      try {
    //         fh = new FileHandler("D:\\MxDownload\\POE\\poe.trade.assist\\assist.log");
    //      } catch (IOException e) {
    //         e.printStackTrace();
    //      }/*from  w w w.j av a 2s .c  o m*/
    //      logger.addHandler(fh);
    //      SimpleFormatter formatter = new SimpleFormatter();
    //      fh.setFormatter(formatter);
    //      logger.info("Init application.");

    BorderPane root = new BorderPane();

    config = Config.load();
    config.get(Config.SEARCH_FILE).ifPresent(searchFileTextField::setText);

    searchFileTextField.setPromptText("Search CSV File URL or blank");
    searchFileTextField.setTooltip(new Tooltip(
            "Any url to a valid poe.trade.assist CSV search file. Can be googlespreadsheet URL. If left blank, will load search.csv file instead"));
    searchFileTextField.setMinWidth(330);
    HBox.setHgrow(searchFileTextField, Priority.ALWAYS);

    List<Search> searchList = loadSearchListFromFile();

    AutoSearchService autoSearchService = new AutoSearchService(
            Boolean.parseBoolean(config.get(Config.AUTO_ENABLE).get()),
            Float.parseFloat(config.get(Config.SEARCH_MINUTES).get()));
    searchPane = new SearchPane(searchList);
    resultPane = new ResultPane(searchFileTextField, this);

    autoSearchService.searchesProperty().bind(searchPane.dataProperty());

    EventHandler<ActionEvent> reloadAction = e -> {
        System.out.println("Loading search file: " + searchFileTextField.getText());
        List<Search> newList = loadSearchListFromFile();
        searchPane.dataProperty().clear();
        searchPane.dataProperty().addAll(newList);
        autoSearchService.restart();
        if (searchPane.dataProperty().size() > 0)
            searchPane.searchTable.getSelectionModel().select(0);
    };

    searchFileTextField.setOnAction(reloadAction);
    resultPane.loadButton.setOnAction(reloadAction);
    resultPane.defaultButton.setOnAction(e -> {
        searchFileTextField.setText(DEFAULT_SEARCH_CSV_FILE);
        resultPane.loadButton.fire();
    });

    resultPane.runNowButton.setOnAction(e -> autoSearchService.restart());
    //        autoSearchService.minsToSleepProperty().bind(resultPane.noOfMinsTextField.textProperty());
    setupResultPaneBinding(searchPane, resultPane, autoSearchService);
    if (searchList.size() > 0)
        searchPane.searchTable.getSelectionModel().select(0);

    stage.setOnCloseRequest(we -> {
        saveSearchList(searchPane);
        config.setProperty(Config.SEARCH_FILE, searchFileTextField.getText());
        config.setProperty(Config.SOUND_FILE, resultPane.soundButton.getUserData().toString());
        config.save();
    });

    config.get(Config.SOUND_FILE).ifPresent(resultPane.soundButton::setUserData);

    autoSearchService.restart();

    //        HBox container = new HBox(5, searchPane, resultPane);
    SplitPane container = new SplitPane(searchPane, resultPane);
    container.setDividerPositions(0.1);
    HBox.setHgrow(searchPane, Priority.ALWAYS);
    HBox.setHgrow(resultPane, Priority.ALWAYS);
    container.setMaxWidth(Double.MAX_VALUE);
    //        root.getChildren().addAll(container);
    root.setCenter(container);
    Scene scene = new Scene(root);
    stage.getIcons().add(new Image("/48px-Durian.png"));
    stage.titleProperty().bind(new SimpleStringProperty("poe.trade.assist v5 (Durian) - ")
            .concat(autoSearchService.messageProperty()));
    //        stage.setWidth(1200);
    //        stage.setHeight(550);
    stage.setMaximized(true);
    stage.setScene(scene);
    stage.show();
    searchPane.searchTable.requestFocus();
}

From source file:statos2_0.MainA.java

@Override
public void start(Stage primaryStage) throws Exception {
    primaryStage.setTitle(nameseller + "[" + storename + "]");
    primaryStage.show();//from  ww w  .j  av a 2 s.  c o m

    primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
        public void handle(WindowEvent we) {

            updsel(m, 1);
        }
    });
    GridPane grid = new GridPane();
    grid.setHgap(14);
    grid.setVgap(14);
    grid.setPadding(new Insets(5, 5, 5, 5));
    //System.out.println("****"+m);
    txg3.setVisible(false);
    // ,    1
    sp1.setValueFactory(spfd);
    spb1.setValueFactory(sfi);
    sp2.setValueFactory(sfi2);
    sp3.setValueFactory(sfi3);
    p1.setId("firstlab");
    p2.setId("firstlab");
    p3.setId("firstlab");
    kasnbn.setId("secondlab");
    kasvnbn.setId("secondlab");
    sumnbn.setId("secondlab");
    vyr.setId("vyr");
    sumvnbn.setId("secondlab");
    JSONParser jP5 = new JSONParser();
    JSONObject jsons5 = new JSONObject();
    List<NameValuePair> para5 = new ArrayList<NameValuePair>();

    para5.add(new BasicNameValuePair("idm", String.valueOf(m)));
    jsons5 = jP5.makeHttpRequest(url_cashgetm, "POST", para5);
    int success = jsons5.getInt("success");
    if (!jsons5.isNull("success")) {
        //res=true;
        // System.out.println("TRUE");

        double all = jsons5.getDouble("all");
        double dayall = Double.parseDouble(jsons5.get("dayall").toString());
        double daybn = Double.parseDouble(jsons5.get("daybn").toString());
        days = dayall + daybn;
        if (days <= 7999 & days > 0) {
            smvyr += (days / 100) * 3;
        } else if (days > 7999) {
            smvyr += (days / 100) * 4;
        }
        vyr.setText(":" + smvyr);
        sumnbn.setText(all + " .");
        sumvnbn.setText(dayall + " / " + daybn);
    }

    litg.setText(":");
    {//    
        sp1.setVisible(false);
        spb1.setVisible(false);
        lb1.setVisible(false);
        t1.setVisible(false);
        bt1.setVisible(false);
        lbb1.setVisible(false);
        cbx4.setVisible(false);
    }
    {//  , 
        sp2.setVisible(false);
        lb2.setVisible(false);
        t2.setVisible(false);
        bt2.setVisible(false);
    }
    {//   

        sp3.setVisible(false);
        lb3.setVisible(false);
        t3.setVisible(false);
        bt3.setVisible(false);

    }

    res.editableProperty().setValue(Boolean.FALSE);
    t1.editableProperty().setValue(Boolean.FALSE);
    t2.editableProperty().setValue(Boolean.FALSE);
    t3.editableProperty().setValue(Boolean.FALSE);
    titg.editableProperty().setValue(Boolean.FALSE);
    //cbx1.setItems(GetByTag(TAG_NAME, "1"));
    //cbx2.setItems(GetByTag(TAG_NAME, "2"));
    //cbx3.setItems(GetByTag(TAG_NAME, "3"));
    //cbx4.setItems(GetByTag(TAG_NAME, "4"));

    //cbx1.valueProperty().addListener(new );
    cbx1.setId("comboprod");
    cbx2.setId("comboprod");
    cbx3.setId("comboprod");

    txg3.setPrefSize(70, 80);

    sp1.setPrefSize(75, 80);
    sp2.setPrefSize(75, 80);
    sp3.setPrefSize(75, 80);
    spb1.setPrefSize(75, 80);
    lb1.setId("labl");
    lb2.setId("labl");
    lb3.setId("labl");
    lbb1.setId("labl");
    t1.setId("textost");
    t2.setId("textost");
    t3.setId("textost");
    bt1.setId("btitg");
    bt2.setId("btitg");
    bt3.setId("btitg");
    cbx4.setId("combbot");
    //lb1.setPrefSize(25, 40);
    //lb2.setPrefSize(25, 40);
    //lb3.setPrefSize(25, 40);

    //t1.setPrefSize(150, 40);
    //t2.setPrefSize(150, 40);
    //t3.setPrefSize(150, 40);

    //cbx4.setPrefSize(160,40);
    //bt2.setPrefSize(40, 40);
    //bt3.setPrefSize(40, 40);

    //spb1.setPrefSize(80, 40);

    //lbb1.setPrefSize(40,40);

    //bt1.setPrefSize(40, 40);

    titg.setPrefSize(120, 80);
    litg.setId("itgl");
    res.setPrefSize(300, 300);

    lb1.setText("");
    lb2.setText("");
    lb3.setText("");
    bt1.setText("+");
    bt2.setText("+");
    bt3.setText("+");
    lbb1.setText("");
    bres.setText("");
    bitg.setText("");
    bdlg.setText("");
    bbn.setText("/");
    //sp1.setValueFactory();
    grid.add(p1, 0, 0);
    grid.add(p2, 0, 1);
    grid.add(p3, 0, 2);

    grid.add(cbx1, 1, 0);
    grid.add(cbx2, 1, 1);
    grid.add(cbx3, 1, 2);

    grid.add(sp1, 2, 0);
    grid.add(sp2, 2, 1);
    grid.add(sp3, 2, 2);
    grid.add(txg3, 2, 2);
    grid.add(lb1, 3, 0);
    grid.add(lb2, 3, 1);
    grid.add(lb3, 3, 2);

    grid.add(t1, 4, 0);
    grid.add(t2, 4, 1);
    grid.add(t3, 4, 2);

    grid.add(cbx4, 5, 0);
    grid.add(bt2, 5, 1);
    grid.add(bt3, 5, 2);

    grid.add(spb1, 6, 0);
    grid.add(lbb1, 7, 0);
    grid.add(bt1, 8, 0);
    //grid.add(res, 1, 4, 3, 3);
    grid.add(res, 0, 3, 2, 3);
    litg.setAlignment(Pos.BASELINE_RIGHT);
    grid.add(litg, 2, 3);

    grid.add(titg, 3, 3, 2, 1);
    grid.add(bitg, 2, 4);
    grid.add(btcl, 4, 4);

    grid.add(kasnbn, 10, 0);
    grid.add(sumnbn, 10, 1);
    grid.add(kasvnbn, 10, 2);
    grid.add(sumvnbn, 10, 3);
    grid.add(vyr, 10, 4);
    grid.add(close, 10, 8);

    close.setOnAction(event -> {

        /**
             Dialog<Void> dialog = new Dialog<>();
        dialog.initModality(Modality.WINDOW_MODAL);
        dialog.initOwner(primaryStage);//stage here is the stage of your webview
        //dialog.initStyle(StageStyle.TRANSPARENT);
        Label loader = new Label("LOADING");
        //loader.setContentDisplay(ContentDisplay.DOWN);
        loader.setGraphic(new ProgressIndicator());
        dialog.getDialogPane().setGraphic(loader);
        DropShadow ds = new DropShadow();
        ds.setOffsetX(1.3); ds.setOffsetY(1.3); ds.setColor(Color.DARKGRAY);
        dialog.getDialogPane().setEffect(ds);
        //ButtonType btn = new ButtonType("OK",ButtonData.CANCEL_CLOSE);
                
        //dialog.getDialogPane().getButtonTypes().add(btn);
        dialog.show();  
            runJsons();
                    
            dialog.hide();
            dialog.close();
                 
           **/

        Alert alert = new Alert(AlertType.CONFIRMATION);
        alert.setTitle("");

        alert.setHeaderText(" ");
        alert.setContentText("    ?");
        ButtonType buttonTypeOne = new ButtonType("");

        ButtonType buttonTypeCancel = new ButtonType("", ButtonData.CANCEL_CLOSE);

        alert.getButtonTypes().setAll(buttonTypeOne, buttonTypeCancel);
        Optional<ButtonType> result2 = alert.showAndWait();
        if (result2.get() == buttonTypeOne) {
            updsel(m, 1);
            cashday(m);
            System.exit(0);
        }

    });
    btcl.setOnAction(event -> {
        jsares.clear();
        res.setText("");
        titg.setText("");
        itog = 0;
        chcount = 1;
        cbx1.getSelectionModel().clearSelection();
        cbx2.getSelectionModel().clearSelection();
        cbx3.getSelectionModel().clearSelection();
        cbx4.getSelectionModel().clearSelection();
        cbx4.setVisible(false);
        sp1.getValueFactory().setValue(0.0);
        sp2.getValueFactory().setValue(0);
        sp3.getValueFactory().setValue(0);
        spb1.getValueFactory().setValue(0);
        sp1.setVisible(false);
        sp2.setVisible(false);
        sp3.setVisible(false);
        spb1.setVisible(false);
        lb1.setVisible(false);
        lb2.setVisible(false);
        lb3.setVisible(false);
        lbb1.setVisible(false);
        t1.setVisible(false);
        t2.setVisible(false);
        t3.setVisible(false);
        bt1.setVisible(false);
        bt2.setVisible(false);
        bt3.setVisible(false);

    });
    bitg.setOnAction(event -> {
        Alert alert = new Alert(AlertType.CONFIRMATION);
        alert.setTitle("");
        alert.setHeaderText(" ");
        alert.setContentText("  ?");
        ButtonType buttonOK = new ButtonType("");
        ButtonType buttonCancel = new ButtonType("", ButtonData.CANCEL_CLOSE);
        alert.getButtonTypes().setAll(buttonOK, buttonCancel);
        Optional<ButtonType> result = alert.showAndWait();
        if (result.get() == buttonOK)

        {

            alert = new Alert(AlertType.CONFIRMATION);
            alert.setTitle("");

            alert.setHeaderText("  ");
            alert.setContentText("  ");
            ButtonType buttonTypeOne = new ButtonType("");
            ButtonType buttonTypeTwo = new ButtonType("");
            //ButtonType buttonTypeThree = new ButtonType("Three");
            ButtonType buttonTypeCancel = new ButtonType("", ButtonData.CANCEL_CLOSE);

            alert.getButtonTypes().setAll(buttonTypeOne, buttonTypeTwo, /*buttonTypeThree,*/ buttonTypeCancel);
            Optional<ButtonType> result2 = alert.showAndWait();
            if (result2.get() == buttonTypeOne) {
                // ... user chose "One"
                typepay = "";
                finishnal(titg.getText(), res.getText(), 1);

            } else if (result2.get() == buttonTypeTwo) {
                // ... user chose "Two"
                typepay = "";
                finishnal(titg.getText(), res.getText(), 2);
            } /*
                      
              else if (result2.get() == buttonTypeThree) {
                // ... user chose "Three"
              }*/ else {
                // ... user chose CANCEL or closed the dialog
            }

        } else {
            // ... user chose CANCEL or closed the dialog
        }
    });
    txg3.setOnMouseClicked(event -> {
        Dialog dialog = new Dialog();
        GridPane gr = new GridPane();
        gr.setHgap(3);
        gr.setVgap(5);
        gr.setPadding(new Insets(10, 10, 10, 10));
        Button b1 = new Button("1");
        b1.setPrefSize(50, 50);
        Button b2 = new Button("2");
        b2.setPrefSize(50, 50);
        Button b3 = new Button("3");
        b3.setPrefSize(50, 50);
        Button b4 = new Button("4");
        b4.setPrefSize(50, 50);
        Button b5 = new Button("5");
        b5.setPrefSize(50, 50);
        Button b6 = new Button("6");
        b6.setPrefSize(50, 50);
        Button b7 = new Button("7");
        b7.setPrefSize(50, 50);
        Button b8 = new Button("8");
        b8.setPrefSize(50, 50);
        Button b9 = new Button("9");
        b9.setPrefSize(50, 50);
        Button b0 = new Button("0");
        b0.setPrefSize(50, 50);
        Button bd = new Button(".");
        bd.setPrefSize(50, 50);
        Button bc = new Button("C");
        bc.setPrefSize(50, 50);
        Button bok = new Button("");
        bc.setPrefSize(50, 50);
        Button bno = new Button("");
        bc.setPrefSize(50, 50);
        gr.add(b1, 0, 0);
        gr.add(b2, 1, 0);
        gr.add(b3, 2, 0);
        gr.add(b4, 0, 1);
        gr.add(b5, 1, 1);
        gr.add(b6, 2, 1);
        gr.add(b7, 0, 2);
        gr.add(b8, 1, 2);
        gr.add(b9, 2, 2);
        gr.add(bd, 0, 3);
        gr.add(b0, 1, 3);
        gr.add(bc, 2, 3);
        //gr.add(bok, 0, 4);
        //gr.add(bno, 3, 4);

        b1.setOnAction(even -> {
            txg3.setText(txg3.getText() + "1");
        });
        b2.setOnAction(even -> {
            txg3.setText(txg3.getText() + "2");
        });
        b3.setOnAction(even -> {
            txg3.setText(txg3.getText() + "3");
        });
        b4.setOnAction(even -> {
            txg3.setText(txg3.getText() + "4");
        });
        b5.setOnAction(even -> {
            txg3.setText(txg3.getText() + "5");
        });
        b6.setOnAction(even -> {
            txg3.setText(txg3.getText() + "6");
        });
        b7.setOnAction(even -> {
            txg3.setText(txg3.getText() + "7");
        });
        b8.setOnAction(even -> {
            txg3.setText(txg3.getText() + "8");
        });
        b9.setOnAction(even -> {
            txg3.setText(txg3.getText() + "9");
        });
        bc.setOnAction(even -> {
            txg3.setText("");

        });
        bd.setOnAction(even -> {
            txg3.setText(txg3.getText() + ".");
        });
        b0.setOnAction(even -> {
            txg3.setText(txg3.getText() + "0");
        });

        ButtonType okk = new ButtonType("OK", ButtonData.OK_DONE);
        ButtonType no = new ButtonType("", ButtonData.CANCEL_CLOSE);
        //gr.add(okk, 0, 4);

        dialog.getDialogPane().setContent(gr);
        dialog.getDialogPane().getButtonTypes().addAll(no, okk);
        dialog.setX(350);
        dialog.setY(260);
        Optional res = dialog.showAndWait();
        runJsons();
        // dialog.setResult(ButtonData.CANCEL_CLOSE);

        //dialog.showAndWait();
    });
    txg3.lengthProperty().addListener(new ChangeListener<Number>() {
        @Override
        public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
            if (newValue.intValue() > oldValue.intValue()) {
                char ch = txg3.getText().charAt(oldValue.intValue());

                // Check if the new character is the number or other's
                if ((!(ch >= '0' && ch <= '9'))) {

                    // if it's not number then just setText to previous one
                    if (ch == '.') {
                    } else {
                        txg3.setText(txg3.getText().substring(0, txg3.getText().length() - 1));
                    }
                }
                double res;

                if (cbx3.getSelectionModel().getSelectedIndex() >= 0) {
                    res = Double.parseDouble(txg3.getText());
                    res = res / 1000;
                    //System.out.println("RES-"+res+"balanc"+balancech(cbx3.getSelectionModel().getSelectedItem().toString())+"BASE"+Double.parseDouble(getTwotag(cbx3.getSelectionModel().getSelectedItem().toString(),MT)));
                    if ((res + balancech(cbx3.getSelectionModel().getSelectedItem().toString(), 3)) > Double
                            .parseDouble(
                                    getTwotag(cbx3.getSelectionModel().getSelectedItem().toString(), 3, MT))) {
                        txg3.setText("");
                        Alert alert = new Alert(Alert.AlertType.ERROR);
                        alert.setTitle("!");
                        alert.setHeaderText("!");
                        alert.setContentText("   \n   !");
                        alert.showAndWait();
                    }
                }

            }
        }

    });
    cbx1.setOnMouseClicked(new EventHandler() {

        @Override
        public void handle(Event event) {
            spb1.getValueFactory().setValue(0);
            sp1.getValueFactory().setValue(0.0);
            runJsons();
            cbx1.setItems(GetByTag(TAG_NAME, "1"));
            //cbx1.getSelectionModel().clearSelection(); 
            int[] remove = new int[cbx1.getItems().size()];
            for (int i = 0; i < cbx1.getItems().size(); i++) {
                //System.out.println("****"+m);
                if (!isHave(cbx1.getItems().get(i).toString(), 1)) {
                    //

                } else {

                }
            }

            cbx1.show();

        }

    });

    sp1.setOnMouseClicked(event -> {
        if (cbx1.getSelectionModel().getSelectedItem() != null) {
            double spres = Double.parseDouble(sp1.getEditor().getText().toString().replace(",", "."));
            double salesres = balancech(cbx1.getSelectionModel().getSelectedItem().toString(), 1);
            double balancestore = Double
                    .parseDouble(getTwotag(cbx1.getSelectionModel().getSelectedItem().toString(), 1, MT));
            // System.out.println(balancestore+" "+spres+" "+salesres);
            if ((balancestore - (spres + salesres)) >= 0) {

            } else {
                Alert alert = new Alert(Alert.AlertType.ERROR);
                alert.setTitle("!");
                alert.setHeaderText("!");
                alert.setContentText("   \n   !");
                alert.showAndWait();
                sp1.getValueFactory().setValue(0.0);

            }
        }
    });
    sp2.setOnMouseClicked(event -> {
        if (cbx2.getSelectionModel().getSelectedIndex() >= 0) {
            double spres = Double.parseDouble(sp2.getEditor().getText().toString());
            double salesres = balancech(cbx2.getSelectionModel().getSelectedItem().toString(), 2);
            double balancestore = Double
                    .parseDouble(getTwotag(cbx2.getSelectionModel().getSelectedItem().toString(), 2, MT));
            if ((balancestore - (spres + salesres)) >= 0) {

            } else {

                Alert alert = new Alert(Alert.AlertType.ERROR);
                alert.setTitle("!");
                alert.setHeaderText("!");
                alert.setContentText("   \n   !");
                alert.showAndWait();
                sp2.getValueFactory().setValue(0);

            }
        }
    });
    spb1.setOnMouseClicked(event -> {
        if (cbx4.getSelectionModel().getSelectedIndex() >= 0) {
            double spres = Double.parseDouble(spb1.getEditor().getText().toString());
            double salesres = balancech(cbx4.getSelectionModel().getSelectedItem().toString(), 4);
            double balancestore = Double
                    .parseDouble(getTwotag(cbx4.getSelectionModel().getSelectedItem().toString(), 4, MT));
            if ((balancestore - (spres + salesres)) >= 0) {

            } else {

                Alert alert = new Alert(Alert.AlertType.ERROR);
                alert.setTitle("!");
                alert.setHeaderText("!");
                alert.setContentText("   \n   !");
                alert.showAndWait();
                spb1.getValueFactory().setValue(0);
            }
        }
    });
    sp3.setOnMouseClicked(event -> {
        if (cbx3.getSelectionModel().getSelectedIndex() >= 0) {
            double spres = Double.parseDouble(sp3.getEditor().getText().toString());
            double salesres = balancech(cbx3.getSelectionModel().getSelectedItem().toString(), 3);
            double balancestore = Double
                    .parseDouble(getTwotag(cbx3.getSelectionModel().getSelectedItem().toString(), 3, MT));
            if ((balancestore - (spres + salesres)) >= 0) {

            } else {

                Alert alert = new Alert(Alert.AlertType.ERROR);
                alert.setTitle("!");
                alert.setHeaderText("!");
                alert.setContentText("   \n   !");
                alert.showAndWait();
                sp3.getValueFactory().setValue(0);
            }
        }
    });
    cbx4.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {

        @Override
        public void changed(ObservableValue observable, Object oldValue, Object newValue) {
            if (observable.getValue() == null) {

            } else {
                if (!isHave(cbx4.getSelectionModel().getSelectedItem().toString(), 4)) {
                    Alert alert = new Alert(Alert.AlertType.ERROR);
                    alert.setTitle("!");
                    alert.setHeaderText("!");
                    alert.setContentText(
                            cbx4.getSelectionModel().getSelectedItem().toString() + "   !");
                    Optional<ButtonType> result = alert.showAndWait();
                    if (result.get() == ButtonType.OK) {
                        cbx4.getSelectionModel().clearSelection();
                    } else {
                        cbx4.getSelectionModel().clearSelection();
                    }
                } else {

                }
            }
        }
    });
    cbx1.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {

        @Override
        public void changed(ObservableValue observable, Object oldValue, Object newValue) {

            if (observable.getValue() == null) {

            } else {

                if (!isHave(cbx1.getSelectionModel().getSelectedItem().toString(), 1)) {
                    Alert alert = new Alert(Alert.AlertType.ERROR);

                    alert.setTitle("!");
                    alert.setHeaderText("!");
                    alert.setContentText(
                            cbx1.getSelectionModel().getSelectedItem().toString() + "   !");
                    Optional<ButtonType> result = alert.showAndWait();
                    if (result.get() == ButtonType.OK) {
                        sp1.setVisible(false);
                        sp1.getValueFactory().setValue(0.0);
                        lb1.setVisible(false);
                        t1.setVisible(false);
                        cbx4.setVisible(false);
                        spb1.setVisible(false);
                        spb1.getValueFactory().setValue(0);
                        lbb1.setVisible(false);
                        bt1.setVisible(false);
                        cbx1.getSelectionModel().clearSelection();
                    } else {
                        sp1.setVisible(false);
                        sp1.getValueFactory().setValue(0.0);
                        lb1.setVisible(false);
                        t1.setVisible(false);
                        cbx4.setVisible(false);
                        spb1.setVisible(false);
                        spb1.getValueFactory().setValue(0);
                        lbb1.setVisible(false);
                        bt1.setVisible(false);
                        cbx1.getSelectionModel().clearSelection();

                    }
                } else {

                    sp2.setVisible(false);
                    lb2.setVisible(false);
                    t2.setVisible(false);
                    bt2.setVisible(false);
                    sp2.getValueFactory().setValue(0);
                    cbx2.getSelectionModel().clearSelection();

                    txg3.setVisible(false);
                    sp3.setVisible(false);
                    lb3.setVisible(false);
                    t3.setVisible(false);
                    bt3.setVisible(false);
                    sp3.getValueFactory().setValue(0);
                    cbx3.getSelectionModel().clearSelection();
                    double curbal = Double.parseDouble(
                            getTwotag(cbx1.getSelectionModel().getSelectedItem().toString(), 1, MT))
                            - balancech(cbx1.getSelectionModel().getSelectedItem().toString(), 1);
                    t1.setText(ost + " " + curbal + " .");
                    cbx4.setItems(GetByTag(TAG_NAME, "4"));
                    sp1.setVisible(true);
                    lb1.setVisible(true);
                    t1.setVisible(true);
                    cbx4.setVisible(true);
                    spb1.setVisible(true);
                    lbb1.setVisible(true);
                    bt1.setVisible(true);

                    if (cbx1.getSelectionModel().getSelectedItem().toString().matches("")) {
                        sp1.setVisible(false);
                        t1.setVisible(false);
                        lb1.setVisible(false);
                    }
                }
            }
        }
    });
    bt1.setOnAction(event -> {
        if (cbx1.getSelectionModel().getSelectedItem().toString().matches("")) {

            if (spb1.getValueFactory().getValue() < 1) {
                Alert alert = new Alert(Alert.AlertType.ERROR);
                alert.setTitle("!");
                alert.setHeaderText("!");
                alert.setContentText("    !");
                alert.showAndWait();
            } else {

                double bottlprice = Double.parseDouble(
                        getTwotag(cbx4.getSelectionModel().getSelectedItem().toString(), 4, "price"));
                int bottlc = spb1.getValueFactory().getValue();
                double bottleitg = bottlc * bottlprice;

                res.setText(res.getText() + printCh2(cbx4.getSelectionModel().getSelectedItem().toString(),
                        "", bottlc, bottlprice) + "\n");

                itog = itog + bottleitg;
                titg.setText(String.valueOf(itog));
                jsores = new JSONObject();
                jsores.put(TIP, getTwotag(cbx4.getSelectionModel().getSelectedItem().toString(), 4, "id"));
                jsores.put(TCOUNT, bottlc);
                jsores.put(TRES, bottleitg);
                jsores.put(TM, m);
                jsores.put(TSELLER, selid);//   ID 
                SimpleDateFormat fff = new SimpleDateFormat("dd.MM.yyyy HH.mm");
                jsores.put(TDATE, fff.format(System.currentTimeMillis()));
                jsores.put(TAG_CHECK, checkcheck());
                jsares.add(jsores);
                sp1.setVisible(!true);
                lb1.setVisible(!true);
                t1.setVisible(!true);
                cbx4.setVisible(!true);
                spb1.setVisible(!true);
                lbb1.setVisible(!true);
                bt1.setVisible(!true);
                spb1.getValueFactory().setValue(0);
                sp1.getValueFactory().setValue(0.0);
                cbx1.getSelectionModel().clearSelection();
                cbx4.getSelectionModel().clearSelection();

            }
        } else {
            if (sp1.getValueFactory().getValue() < 0.5) {
                Alert alert = new Alert(Alert.AlertType.ERROR);
                alert.setTitle("!");
                alert.setHeaderText("!");
                alert.setContentText("    !");
                alert.showAndWait();
            } else if (cbx4.getSelectionModel().getSelectedItem() == null) {
                Alert alert = new Alert(Alert.AlertType.ERROR);
                alert.setTitle("!");
                alert.setHeaderText("!");
                alert.setContentText("    !");
                alert.showAndWait();

            } else if (spb1.getValueFactory().getValue() < 1) {
                Alert alert = new Alert(Alert.AlertType.ERROR);
                alert.setTitle("!");
                alert.setHeaderText("!");
                alert.setContentText("    !");
                alert.showAndWait();
            } /*else if(cbx4.getSelectionModel().getSelectedItem().toString().matches("")){
               Alert alert = new Alert(Alert.AlertType.ERROR);
              alert.setTitle("!");
              alert.setHeaderText("!");
              alert.setContentText("    !");
              alert.showAndWait();  
              }*/else {
                double liters = sp1.getValueFactory().getValue();
                double bottlc = spb1.getValueFactory().getValue();
                String sb = cbx4.getSelectionModel().getSelectedItem().toString();
                double bottlsz = 0;
                if (sb.contains("0.5") | sb.contains("0,5")) {
                    bottlsz = 0.5;
                } else if (sb.contains("1.0") | sb.contains("1,0")) {
                    bottlsz = 1.0;
                } else if (sb.contains("1.5") | sb.contains("1,5")) {
                    bottlsz = 1.5;
                } else if (sb.contains("2,0") | sb.contains("2.0") | sb.contains("2")) {
                    bottlsz = 2.0;
                } else if (sb.contains("3,0") | sb.contains("3.0") | sb.contains("3")) {
                    bottlsz = 3.0;
                } else if (sb.contains("")) {
                    bottlsz = 0.5;
                }

                if ((bottlsz * bottlc) == liters) {
                    double price = Double.parseDouble(
                            getTwotag(cbx1.getSelectionModel().getSelectedItem().toString(), 1, TAG_PRICE));
                    String prodn = cbx1.getSelectionModel().getSelectedItem().toString();
                    double itg = 0;
                    if (getTwotag(prodn, 1, "sales").matches("1")) {
                        if (liters % 3 == 0) {
                            price = ((liters * price) - ((liters / 3) * price)) / liters;
                            itg = liters * price;
                        } else {
                            itg = liters * price;
                        }
                    } else {
                        itg = liters * price;
                    }
                    double bottlprice = 0;
                    if (sp1.isVisible()
                            & !cbx4.getSelectionModel().getSelectedItem().toString().contains("")) {
                        bottlprice = Double.parseDouble(
                                getTwotag(cbx4.getSelectionModel().getSelectedItem().toString(), 4, "price"));
                    } else if (sp1.isVisible()
                            & cbx4.getSelectionModel().getSelectedItem().toString().contains("")) {
                        bottlprice = 0;
                    } else if (!sp1.isVisible()
                            & cbx4.getSelectionModel().getSelectedItem().toString().contains("")) {
                        bottlprice = 0;
                    }
                    res.setText(res.getText() + printCh2(cbx1.getSelectionModel().getSelectedItem().toString(),
                            "", liters, price) + "\n");
                    res.setText(res.getText() + printCh2(cbx4.getSelectionModel().getSelectedItem().toString(),
                            "", bottlc, bottlprice) + "\n");
                    itog += itg;

                    jsores = new JSONObject();
                    jsores.put(TIP, getTwotag(cbx1.getSelectionModel().getSelectedItem().toString(), 1, "id"));
                    jsores.put(TCOUNT, String.valueOf(liters));
                    jsores.put(TRES, itg);
                    jsores.put(TM, m);
                    jsores.put(TSELLER, selid);//   ID 
                    //jsores.put("balance", (balance1.get(cbx1.getSelectionModel().getSelectedIndex()) - coun));          
                    SimpleDateFormat ff = new SimpleDateFormat("dd.MM.yyyy HH.mm");
                    jsores.put(TDATE, ff.format(System.currentTimeMillis()));
                    //jsores.put("seltype","1");        
                    //jsores.put("dolgid","1");
                    jsores.put(TAG_CHECK, checkcheck());
                    jsares.add(jsores);
                    double bottleitg = bottlprice * bottlc;

                    itog = itog + bottleitg;
                    titg.setText(String.valueOf(itog));
                    jsores = new JSONObject();
                    jsores.put(TIP, getTwotag(cbx4.getSelectionModel().getSelectedItem().toString(), 4, "id"));
                    jsores.put(TCOUNT, bottlc);
                    jsores.put(TRES, bottleitg);
                    jsores.put(TM, m);
                    jsores.put(TSELLER, selid);//   ID 
                    //jsores.put("balance", (balanceb.get(cbx4.getSelectionModel().getSelectedIndex()) - counb));          
                    SimpleDateFormat fff = new SimpleDateFormat("dd.MM.yyyy HH.mm");
                    jsores.put(TDATE, fff.format(System.currentTimeMillis()));
                    //jsores.put("seltype",1);    !
                    //jsores.put("dolgid",1);
                    jsores.put(TAG_CHECK, checkcheck());
                    jsares.add(jsores);
                    //System.out.println(jsares);
                    sp1.setVisible(!true);
                    lb1.setVisible(!true);
                    t1.setVisible(!true);
                    cbx4.setVisible(!true);
                    spb1.setVisible(!true);
                    lbb1.setVisible(!true);
                    bt1.setVisible(!true);
                    spb1.getValueFactory().setValue(0);
                    sp1.getValueFactory().setValue(0.0);
                    cbx1.getSelectionModel().clearSelection();
                    cbx4.getSelectionModel().clearSelection();

                } else {
                    Alert alert = new Alert(Alert.AlertType.ERROR);
                    alert.setTitle("!");
                    alert.setHeaderText("!");
                    alert.setContentText("    !");
                    alert.showAndWait();

                }
            }
        }
    });

    cbx2.setOnMouseClicked(new EventHandler() {
        @Override
        public void handle(Event event) {
            runJsons();
            cbx2.setItems(GetByTag(TAG_NAME, "2"));
            cbx2.show();
        }
    });

    cbx2.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {

        @Override
        public void changed(ObservableValue observable, Object oldValue, Object newValue) {

            if (observable.getValue() == null) {

            } else {
                if (!isHave(cbx2.getSelectionModel().getSelectedItem().toString(), 2)) {
                    Alert alert = new Alert(Alert.AlertType.ERROR);
                    alert.setTitle("!");
                    alert.setHeaderText("!");
                    alert.setContentText(
                            cbx2.getSelectionModel().getSelectedItem().toString() + "   !");
                    Optional<ButtonType> result = alert.showAndWait();
                    if (result.get() == ButtonType.OK) {
                        sp2.setVisible(false);
                        sp2.getValueFactory().setValue(0);
                        lb2.setVisible(false);
                        t2.setVisible(false);
                        bt2.setVisible(false);
                        cbx2.getSelectionModel().clearSelection();
                    } else {
                        sp2.setVisible(false);
                        sp2.getValueFactory().setValue(0);
                        lb2.setVisible(false);
                        t2.setVisible(false);
                        bt2.setVisible(false);
                        cbx2.getSelectionModel().clearSelection();
                    }
                } else {
                    txg3.setVisible(false);
                    sp3.setVisible(!true);
                    lb3.setVisible(!true);
                    t3.setVisible(!true);
                    bt3.setVisible(!true);
                    sp3.getValueFactory().setValue(0);
                    cbx3.getSelectionModel().clearSelection();

                    cbx4.setVisible(!true);
                    sp1.setVisible(!true);
                    lb1.setVisible(!true);
                    t1.setVisible(!true);
                    spb1.setVisible(!true);
                    lbb1.setVisible(!true);
                    bt1.setVisible(!true);
                    sp1.getValueFactory().setValue(0.0);
                    spb1.getValueFactory().setValue(0);
                    cbx1.getSelectionModel().clearSelection();

                    sp2.setVisible(true);
                    lb2.setVisible(true);
                    t2.setVisible(true);
                    bt2.setVisible(true);
                    sp2.getValueFactory().setValue(0);
                    //System.out.println("////////"+newValue+"/////");
                    double curbal = Double.parseDouble(
                            getTwotag(cbx2.getSelectionModel().getSelectedItem().toString(), 2, MT))
                            - balancech(cbx2.getSelectionModel().getSelectedItem().toString(), 2);
                    t2.setText(ost + " " + curbal + " .");
                }
            }
        }
    });
    bt2.setOnAction(event -> {
        if (sp2.getValueFactory().getValue() < 1) {
            Alert alert = new Alert(Alert.AlertType.ERROR);
            alert.setTitle("!");
            alert.setHeaderText("!");
            alert.setContentText("    !");
            alert.showAndWait();
        } else {
            int coun = Integer.parseInt(sp2.getEditor().getText());
            double price = Double.parseDouble(
                    getTwotag(cbx2.getSelectionModel().getSelectedItem().toString(), 2, TAG_PRICE));
            double itg = coun * price;
            res.setText(res.getText()
                    + printCh2(cbx2.getSelectionModel().getSelectedItem().toString(), "", coun, price)
                    + "\n");
            itog = itog + itg;
            titg.setText(String.valueOf(itog));
            jsores = new JSONObject();
            jsores.put(TIP, getTwotag(cbx2.getSelectionModel().getSelectedItem().toString(), 2, TAG_ID));
            jsores.put(TCOUNT, String.valueOf(coun));
            jsores.put(TRES, itg);
            jsores.put(TM, m);
            jsores.put(TSELLER, selid);//   ID 
            //jsores.put("balance", (balance2.get(cbx2.getSelectionModel().getSelectedIndex()) - coun));
            SimpleDateFormat ff = new SimpleDateFormat("dd.MM.yyyy HH.mm");
            jsores.put(TDATE, ff.format(System.currentTimeMillis()));
            //jsores.put("seltype","1");     !!!!!!
            //jsores.put("dolgid","1");
            jsores.put(TAG_CHECK, checkcheck());
            jsares.add(jsores);
            sp2.setVisible(!true);
            lb2.setVisible(!true);
            t2.setVisible(!true);
            bt2.setVisible(!true);
            sp2.getValueFactory().setValue(0);
            cbx2.getSelectionModel().clearSelection();
        }
    });
    cbx3.setOnMouseClicked(new EventHandler() {
        @Override
        public void handle(Event event) {

            sp3.getValueFactory().setValue(0);
            runJsons();
            cbx3.setItems(GetByTag(TAG_NAME, "3"));
            cbx3.show();
        }
    });

    cbx3.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {

        @Override
        public void changed(ObservableValue observable, Object oldValue, Object newValue) {
            if (observable.getValue() == null) {

            } else {

                if (!isHave(cbx3.getSelectionModel().getSelectedItem().toString(), 3)) {
                    Alert alert = new Alert(Alert.AlertType.ERROR);
                    alert.setTitle("!");
                    alert.setHeaderText("!");
                    alert.setContentText(
                            cbx3.getSelectionModel().getSelectedItem().toString() + "   !");
                    Optional<ButtonType> result = alert.showAndWait();
                    if (result.get() == ButtonType.OK) {
                        sp3.setVisible(false);
                        sp3.getValueFactory().setValue(0);
                        lb3.setVisible(false);
                        t3.setVisible(false);
                        bt3.setVisible(false);
                        cbx3.getSelectionModel().clearSelection();
                    } else {
                        sp3.setVisible(false);
                        sp3.getValueFactory().setValue(0);
                        lb3.setVisible(false);
                        t3.setVisible(false);
                        bt3.setVisible(false);
                        cbx3.getSelectionModel().clearSelection();
                    }
                } else {
                    sp1.setVisible(!true);
                    lb1.setVisible(!true);
                    t1.setVisible(!true);
                    cbx4.setVisible(!true);
                    spb1.setVisible(!true);
                    lbb1.setVisible(!true);
                    bt1.setVisible(!true);
                    //spb1.getEditor().setText("0");
                    //sp1.getEditor().setText("0");
                    cbx1.getSelectionModel().clearSelection();

                    sp2.setVisible(!true);
                    lb2.setVisible(!true);
                    t2.setVisible(!true);
                    bt2.setVisible(!true);
                    sp2.getValueFactory().setValue(0);
                    cbx2.getSelectionModel().clearSelection();

                    sp3.setVisible(true);
                    lb3.setVisible(true);
                    t3.setVisible(true);
                    bt3.setVisible(true);
                    sp3.getValueFactory().setValue(0);
                    if (getTwotag(cbx3.getSelectionModel().getSelectedItem().toString(), 3, TAG_ZT)
                            .equals("2")) {

                        double curbal = Double.parseDouble(
                                getTwotag(cbx3.getSelectionModel().getSelectedItem().toString(), 3, MT))
                                - (balancech(cbx3.getSelectionModel().getSelectedItem().toString(), 3));
                        String pattern = "##0.00";
                        DecimalFormat decimalFormat = new DecimalFormat(pattern);
                        String format = decimalFormat.format(curbal);

                        t3.setText(ost + " " + format + " .");
                        lb3.setText("");

                        sp3.setVisible(false);
                        txg3.setVisible(true);
                        txg3.setText("");

                    } else {
                        double curbal = Double.parseDouble(
                                getTwotag(cbx3.getSelectionModel().getSelectedItem().toString(), 3, MT))
                                - balancech(cbx3.getSelectionModel().getSelectedItem().toString(), 3);
                        t3.setText(ost + " " + curbal + " .");
                        lb3.setText("");
                        txg3.setVisible(false);
                        sp3.setVisible(true);
                    }
                }
            }
        }
    });

    bt3.setOnAction(event -> {
        int typez = Integer.parseInt(getTwotag(cbx3.getSelectionModel().getSelectedItem().toString(), 3, "zt"));

        if (sp3.isVisible() & sp3.getValueFactory().getValue() < 1) {

            Alert alert = new Alert(Alert.AlertType.ERROR);
            alert.setTitle("!");
            alert.setHeaderText("!");
            alert.setContentText("    !");
            alert.showAndWait();
        } else if (txg3.isVisible() & txg3.getText().equals("")) {

            Alert alert = new Alert(Alert.AlertType.ERROR);
            alert.setTitle("!");
            alert.setHeaderText("!!");
            alert.setContentText("    !");
            alert.showAndWait();

        } else {

            double coun = 0;
            double price = Double.parseDouble(
                    getTwotag(cbx3.getSelectionModel().getSelectedItem().toString(), 3, TAG_PRICE));
            double itg = 0;
            double itgcoun = 0;
            if (lb3.getText().equals("")) {
                //System.out.println(lb3.getText());
                coun = sp3.getValueFactory().getValue();
                itg = coun * price;
                itgcoun = coun;
                // System.out.println("SPINNER" + coun);
                res.setText(res.getText()
                        + printCh2(cbx3.getSelectionModel().getSelectedItem().toString(), "", coun, price)
                        + "\n");

            } else if (lb3.getText().equals("")) {
                // System.out.println(lb3.getText());
                coun = Double.parseDouble(txg3.getText());

                itg = ((price * coun) / 100);
                // System.out.println("!!!???!!!"+coun+"   "+price);
                res.setText(res.getText()
                        + printCh3(cbx3.getSelectionModel().getSelectedItem().toString(), "", coun, price)
                        + "\n");
                itgcoun = (double) coun / 1000;
                //System.out.println("TEXT" + coun+"  "+itgcoun);

            }
            String pattern = "##0.0";
            DecimalFormat decimalFormat = new DecimalFormat(pattern);
            String format = decimalFormat.format(itg);
            itog = itog + itg;
            titg.setText(String.valueOf(itog));
            jsores = new JSONObject();
            jsores.put(TIP, getTwotag(cbx3.getSelectionModel().getSelectedItem().toString(), 3, TAG_ID));
            jsores.put(TCOUNT, Double.parseDouble(String.valueOf(itgcoun)));
            jsores.put(TRES, itg);
            jsores.put(TM, m);
            jsores.put(TSELLER, selid);//   ID 
            //jsores.put("balance", (balance3.get(cbx3.getSelectionModel().getSelectedIndex()) - coun));
            SimpleDateFormat ff = new SimpleDateFormat("dd.MM.yyyy HH.mm");
            jsores.put(TDATE, ff.format(System.currentTimeMillis()));
            //jsores.put("seltype","1");   !!!!!
            //jsores.put("dolgid","1");
            jsores.put(TAG_CHECK, checkcheck());
            //System.out.println(jsores);
            jsares.add(jsores);
            sp3.setVisible(!true);
            lb3.setVisible(!true);
            t3.setVisible(!true);
            bt3.setVisible(!true);
            sp3.getValueFactory().setValue(0);
            cbx3.getSelectionModel().clearSelection();
            txg3.setVisible(false);
            // }
        }
    });
    Dimension sSize = Toolkit.getDefaultToolkit().getScreenSize();
    Scene scene = new Scene(grid, sSize.width, sSize.height);
    primaryStage.setScene(scene);
    scene.getStylesheets().add(MainA.class.getResource("main.css").toExternalForm());
    primaryStage.show();

}

From source file:ubicrypt.UbiCrypt.java

@Override
public void start(final Stage stage) throws Exception {
    setUserAgentStylesheet(STYLESHEET_MODENA);
    stage.setTitle("UbiCrypt");
    anchor().setStage(stage);//from   ww w.j  ava2  s .  c o m
    try {
        final PGPKeyPair kp = encryptionKey();
        encrypt(Collections.singletonList(kp.getPublicKey()),
                new ByteArrayInputStream(StringUtils.repeat("ciao", 1).getBytes()));
    } catch (Exception e) {
        Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setTitle("Strong Encryption Required");
        alert.setHeaderText("Install JCE Unlimited Strength Jurisdiction policy files");
        alert.setContentText(
                "You can install the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files, which are required to use strong encryption.\n"
                        + "Download the files and instructions for Java 8.\n"
                        + "Locate the jre\\lib\\security directory for the Java instance that the UbiCrypt is using.\n"
                        + "For example, this location might be: C:\\Program Files\\Java\\jre8\\lib\\security.\n"
                        + "Replace these two files with the .jar files included in the JCE Unlimited Strength Jurisdiction Policy Files download.\n"
                        + "Stop and restart the UbiCrypt.\n\n\n\n\n\n");
        ButtonType icePage = new ButtonType("Go to JCE download Page");
        alert.getButtonTypes().addAll(icePage);
        Optional<ButtonType> result = alert.showAndWait();
        if (result.get() == icePage) {
            getHostServices().showDocument(
                    "http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html");
        }
        Platform.exit();
    }
    final File secFile = securityFile().toFile();
    stage.setScene(anchor().show(secFile.exists() ? "login" : "createKey", getHostServices()));
    stage.show();
    final UbiCrypt ubiCrypt = this;
    anchor().getPasswordStream().subscribeOn(Schedulers.io()).subscribe(pwd -> {
        final SpringApplication app = new SpringApplication(UbiConf.class, PathConf.class, UIConf.class);
        app.setRegisterShutdownHook(false);
        app.addInitializers(new FixPassPhraseInitializer(pwd));
        app.setLogStartupInfo(true);
        ctx = app.run();
        ctx.getAutowireCapableBeanFactory().autowireBean(ubiCrypt);
        ctx.getBeanFactory().registerSingleton("stage", stage);
        ctx.getBeanFactory().registerSingleton("hostService", getHostServices());
        ctx.getBeanFactory().registerSingleton("osUtil", new OSUtil(getHostServices()));
        ControllerFactory cfactory = new ControllerFactory(ctx);
        StackNavigator navigator = new StackNavigator(null, "main", cfactory);
        stage.setScene(new Scene(navigator.open()));
    });

    stage.setOnCloseRequest(windowEvent -> shutdown.run());
    Runtime.getRuntime().addShutdownHook(new Thread(shutdown));
}

From source file:com.cdd.bao.editor.EditSchema.java

public EditSchema(Stage stage) {
    this.stage = stage;

    if (MainApplication.icon != null)
        stage.getIcons().add(MainApplication.icon);

    menuBar = new MenuBar();
    menuBar.setUseSystemMenuBar(true);//ww w. j ava2  s. c o  m
    menuBar.getMenus().add(menuFile = new Menu("_File"));
    menuBar.getMenus().add(menuEdit = new Menu("_Edit"));
    menuBar.getMenus().add(menuValue = new Menu("_Value"));
    menuBar.getMenus().add(menuView = new Menu("Vie_w"));
    createMenuItems();

    treeRoot = new TreeItem<>(new Branch(this));
    treeView = new TreeView<>(treeRoot);
    treeView.setEditable(true);
    treeView.setCellFactory(p -> new HierarchyTreeCell());
    treeView.getSelectionModel().selectedItemProperty().addListener((observable, oldVal, newVal) -> {
        if (oldVal != null)
            pullDetail(oldVal);
        if (newVal != null)
            pushDetail(newVal);
    });
    treeView.focusedProperty()
            .addListener((val, oldValue, newValue) -> Platform.runLater(() -> maybeUpdateTree()));

    detail = new DetailPane(this);

    StackPane sp1 = new StackPane(), sp2 = new StackPane();
    sp1.getChildren().add(treeView);
    sp2.getChildren().add(detail);

    splitter = new SplitPane();
    splitter.setOrientation(Orientation.HORIZONTAL);
    splitter.getItems().addAll(sp1, sp2);
    splitter.setDividerPositions(0.4, 1.0);

    progBar = new ProgressBar();
    progBar.setMaxWidth(Double.MAX_VALUE);

    root = new BorderPane();
    root.setTop(menuBar);
    root.setCenter(splitter);
    root.setBottom(progBar);

    BorderPane.setMargin(progBar, new Insets(2, 2, 2, 2));

    Scene scene = new Scene(root, 1000, 800, Color.WHITE);

    stage.setScene(scene);

    treeView.setShowRoot(false);
    treeRoot.getChildren().add(treeTemplate = new TreeItem<>(new Branch(this, "Template")));
    treeRoot.getChildren().add(treeAssays = new TreeItem<>(new Branch(this, "Assays")));
    treeTemplate.setExpanded(true);
    treeAssays.setExpanded(true);

    rebuildTree();

    Platform.runLater(() -> treeView.getFocusModel().focus(treeView.getSelectionModel().getSelectedIndex())); // for some reason it defaults to not the first item

    stage.setOnCloseRequest(event -> {
        if (!confirmClose())
            event.consume();
    });

    updateTitle();

    // loading begins in a background thread, and is updated with a status bar
    Vocabulary.Listener listener = new Vocabulary.Listener() {
        public void vocabLoadingProgress(Vocabulary vocab, float progress) {
            Platform.runLater(() -> {
                progBar.setProgress(progress);
                if (vocab.isLoaded())
                    root.getChildren().remove(progBar);
            });
        }

        public void vocabLoadingException(Exception ex) {
            ex.printStackTrace();
        }
    };
    Vocabulary.globalInstance(listener);
}

From source file:de.mirkosertic.desktopsearch.DesktopSearch.java

@Override
public void start(Stage aStage) throws Exception {

    // This is our base directory
    File theBaseDirectory = new File(SystemUtils.getUserHome(), "FreeSearchIndexDir");
    theBaseDirectory.mkdirs();//  w  w  w . j a va2 s  .  c  om

    configurationManager = new ConfigurationManager(theBaseDirectory);

    Notifier theNotifier = new Notifier();

    stage = aStage;

    // Create the known preview processors
    PreviewProcessor thePreviewProcessor = new PreviewProcessor();

    try {
        // Boot the search backend and set it up for listening to configuration changes
        backend = new Backend(theNotifier, configurationManager.getConfiguration(), thePreviewProcessor);
        configurationManager.addChangeListener(backend);

        // Boot embedded JSP container
        embeddedWebServer = new FrontendEmbeddedWebServer(aStage, backend, thePreviewProcessor,
                configurationManager);

        embeddedWebServer.start();
    } catch (BindException | LockReleaseFailedException | LockObtainFailedException e) {
        // In this case, there is already an instance of DesktopSearch running
        // Inform the instance to bring it to front end terminate the current process.
        URL theURL = new URL(FrontendEmbeddedWebServer.getBringToFrontUrl());
        // Retrieve the content, but it can be safely ignored
        // There must only be the get request
        Object theContent = theURL.getContent();

        // Terminate the JVM. The window of the running instance is visible now.
        System.exit(0);
    }

    aStage.setTitle("Free Desktop Search");
    aStage.setWidth(800);
    aStage.setHeight(600);
    aStage.initStyle(StageStyle.TRANSPARENT);

    FXMLLoader theLoader = new FXMLLoader(getClass().getResource("/scenes/mainscreen.fxml"));
    AnchorPane theMainScene = theLoader.load();

    final DesktopSearchController theController = theLoader.getController();
    theController.configure(this, backend, FrontendEmbeddedWebServer.getSearchUrl(), stage.getOwner());

    Undecorator theUndecorator = new Undecorator(stage, theMainScene);
    theUndecorator.getStylesheets().add("/skin/undecorator.css");

    Scene theScene = new Scene(theUndecorator);

    // Hacky, but works...
    theUndecorator.setStyle("-fx-background-color: rgba(0, 0, 0, 0);");

    theScene.setFill(Color.TRANSPARENT);
    aStage.setScene(theScene);

    aStage.getIcons().add(new Image(getClass().getResourceAsStream("/fds.png")));

    if (SystemTray.isSupported()) {
        Platform.setImplicitExit(false);
        SystemTray theTray = SystemTray.getSystemTray();

        // We need to reformat the icon according to the current tray icon dimensions
        // this depends on the underlying OS
        java.awt.Image theTrayIconImage = Toolkit.getDefaultToolkit()
                .getImage(getClass().getResource("/fds_small.png"));
        int trayIconWidth = new TrayIcon(theTrayIconImage).getSize().width;
        TrayIcon theTrayIcon = new TrayIcon(
                theTrayIconImage.getScaledInstance(trayIconWidth, -1, java.awt.Image.SCALE_SMOOTH),
                "Free Desktop Search");
        theTrayIcon.setImageAutoSize(true);
        theTrayIcon.setToolTip("FXDesktopSearch");
        theTrayIcon.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 1) {
                    Platform.runLater(() -> {
                        if (stage.isIconified()) {
                            stage.setIconified(false);
                        }
                        stage.show();
                        stage.toFront();
                    });
                }
            }
        });
        theTray.add(theTrayIcon);

        aStage.setOnCloseRequest(aEvent -> stage.hide());
    } else {

        aStage.setOnCloseRequest(aEvent -> shutdown());
    }

    aStage.setMaximized(true);
    aStage.show();
}

From source file:cz.lbenda.dataman.rc.DatamanApp.java

@SuppressWarnings("unchecked")
@Override/*  ww w .j av a2  s .  c  om*/
public void start(Stage primaryStage) throws Exception {
    StatusHelper.getInstance().setStatusBar(statusBar);
    Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) -> ExceptionMessageFrmController
            .showException(MessageFactory.getInstance().getMessage("UncaughtException"), throwable));

    ribbon = new Ribbon(MessageFactory.getInstance().getMessage("app.name"),
            IconFactory.getInstance().image(this, "dataman.png", IconFactory.IconLocation.APP_ICON));

    primaryStage.getIcons().add(new Image(this.getClass().getResourceAsStream("dataman16.png")));
    primaryStage.getIcons().add(new Image(this.getClass().getResourceAsStream("dataman32.png")));
    primaryStage.getIcons().add(new Image(this.getClass().getResourceAsStream("dataman48.png")));
    primaryStage.getIcons().add(new Image(this.getClass().getResourceAsStream("dataman64.png")));
    primaryStage.getIcons().add(new Image(this.getClass().getResourceAsStream("dataman128.png")));
    primaryStage.setTitle(MessageFactory.getInstance().getMessage("app.name"));

    DbConfigFactory.reloadConfiguration();
    ObjectProperty<DbConfig> currentDbProperty = new SimpleObjectProperty<>();
    ObjectProperty<TableDesc> selectedTableDescProperty = new SimpleObjectProperty<>();

    prepareMainPane();
    ribbon.itemsProperty().addAll(new AddDatabaseHandler(), new ImportDatabaseHandler(),
            new ExportDatabaseHandler(currentDbProperty), new DbConfigMenuOptions(currentDbProperty),
            new ConnectDatabaseHandler(currentDbProperty), new EditDatabaseHandler(currentDbProperty),
            new CopyDatabaseHandler(currentDbProperty), new RemoveDatabaseHandler(currentDbProperty),
            new ReloadDatabaseHandler(currentDbProperty), new RemoveRowsHandler(tableViewObjectProperty),
            new AddRowHandler(tableViewObjectProperty), new ReloadTableHandler(tableViewObjectProperty),
            new SaveTableHandler(tableViewObjectProperty), new SaveAllTableHandler(currentDbProperty),
            new OpenConnectedTablesHandler(tableViewObjectProperty,
                    detailDescriptor -> addRemoveToDetail(detailDescriptor.getTitle(),
                            detailDescriptor.getNode(), detailDescriptor.getClosable())),
            new ExportTableHandler(sqlQueryRowsObjectProperty),
            new ExportTableWithTemplateHandler(sqlQueryRowsObjectProperty), new AboutApplicationHandler());

    Scene scene = new Scene(mainPane);
    te = new SQLEditorController(ribbon::addItem, scene, currentDbProperty, nodeShower);

    addToCenter(SQLEditorController.WINDOW_TITLE, te.getNode(), false);

    Tuple2<Parent, DbTableStructureFrmController> dbTableStructureFrmController = DbTableStructureFrmController
            .createNewInstance();
    addToCenter(DbTableStructureFrmController.WINDOW_TITLE, dbTableStructureFrmController.get1(), false);
    selectedTableDescProperty.addListener(
            (observable, oldValue, newValue) -> dbTableStructureFrmController.get2().setTableDesc(newValue));

    DbStructureFrmController dfc = new DbStructureFrmController(currentDbProperty, td -> new Thread(() -> {
        StatusHelper.getInstance().progressStart(td, DataTableFrmController.TASK_NAME, 2);
        StatusHelper.getInstance().progressNextStep(td, td.getName(), 0);
        DataTableFrmController controller = new DataTableFrmController(td);
        StatusHelper.getInstance().progressNextStep(td, td.getName(), 0);
        Platform.runLater(() -> addToCenter(controller.titleProperty(), controller.getTabView(), true));
        StatusHelper.getInstance().progressFinish(td, DataTableFrmController.STEP_FINISH);
    }).start(), selectedTableDescProperty);
    leftPane.getChildren().add(dfc.getControlledNode());

    RowEditorFrmController rowEditorFrmController = new RowEditorFrmController(tableViewObjectProperty);
    addToRight(RowEditorFrmController.WINDOW_TITLE, rowEditorFrmController.getPane());

    // Scene scene = te.createScene();
    primaryStage.setScene(scene);
    primaryStage.setOnCloseRequest(event -> {
        if (!DialogHelper.getInstance().showUnsavedObjectDialog(SavableRegistry.getInstance())) {
            event.consume();
        }
    });
    primaryStage.show();
    /*
    try {
      // AquaFx.style();
      // FlatterFX.style();
      //AeroFX.style();
    } catch (Exception e) {
      LOG.error("Problem with switch to AquaFx style", e);
    }
    */
}

From source file:editeurpanovisu.EditeurPanovisu.java

/**
 *
 * @param primaryStage/*from  w  w  w  . j a v  a2s.  com*/
 * @throws Exception
 */
@Override
public void start(Stage primaryStage) throws Exception {
    File rep = new File("");
    currentDir = rep.getAbsolutePath();
    repertAppli = rep.getAbsolutePath();
    repertConfig = new File(repertAppli + File.separator + "configPV");
    if (!repertConfig.exists()) {
        repertConfig.mkdirs();
        locale = new Locale("fr", "FR");
        setUserAgentStylesheet("file:css/clair.css");
        repertoireProjet = repertAppli;
    } else {
        lisFichierConfig();
    }
    rb = ResourceBundle.getBundle("editeurpanovisu.i18n.PanoVisu", locale);
    stPrincipal = primaryStage;
    stPrincipal.setResizable(false);
    stPrincipal.setTitle("PanoVisu v" + numVersion);
    //AquaFx.style();
    //        setUserAgentStylesheet(STYLESHEET_MODENA);
    primaryStage.setMaximized(true);
    Dimension tailleEcran = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    int hauteur = (int) tailleEcran.getHeight() - 20;
    int largeur = (int) tailleEcran.getWidth() - 20;
    largeurMax = tailleEcran.getWidth() - 450.0d;
    creeEnvironnement(primaryStage, largeur, hauteur);

    File repertTempFile = new File(repertAppli + File.separator + "temp");
    repertTemp = repertTempFile.getAbsolutePath();

    if (!repertTempFile.exists()) {
        repertTempFile.mkdirs();
    } else {
        deleteDirectory(repertTemp);
    }
    String extTemp = genereChaineAleatoire(20);
    repertTemp = repertTemp + File.separator + "temp" + extTemp;
    repertTempFile = new File(repertTemp);
    repertTempFile.mkdirs();
    installeEvenements();
    projetsNouveau();
    primaryStage.setOnCloseRequest((WindowEvent event) -> {
        Action reponse = null;
        Localization.setLocale(locale);
        if (!dejaSauve) {
            reponse = Dialogs.create().owner(null).title("Quitter l'diteur")
                    .masthead("ATTENTION ! Vous n'avez pas sauvegard votre projet")
                    .message("Voulez vous le sauver ?")
                    .actions(Dialog.Actions.YES, Dialog.Actions.NO, Dialog.Actions.CANCEL).showWarning();
        }
        if (reponse == Dialog.Actions.YES) {
            try {
                projetSauve();

            } catch (IOException ex) {
                Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        if ((reponse == Dialog.Actions.YES) || (reponse == Dialog.Actions.NO) || (reponse == null)) {
            try {
                sauveHistoFichiers();
            } catch (IOException ex) {
                Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex);
            }

            deleteDirectory(repertTemp);
            File ftemp = new File(repertTemp);
            ftemp.delete();
        } else {
            event.consume();
        }
    });
}

From source file:editeurpanovisu.EditeurPanovisu.java

/**
 *
 * @param stPrimaryStage/*from w  ww.jav a  2  s. c  o m*/
 * @throws Exception Exceptions
 */
@Override

public void start(Stage stPrimaryStage) throws Exception {
    if (isLinux()) {
        stPrimaryStage.setFullScreen(true);
    }
    File fileRep = new File("");
    setbInternet(netIsAvailable());
    setStrCurrentDir(fileRep.getAbsolutePath());
    setStrRepertAppli(fileRep.getAbsolutePath());
    fileRepertConfig = new File(getStrRepertAppli() + File.separator + "configPV");
    rbLocalisation = ResourceBundle.getBundle("editeurpanovisu.i18n.PanoVisu", getLocale());
    Package pack = Package.getPackage("editeurpanovisu");
    strNumVersion = pack.getImplementationVersion() + "-b"
            + rbLocalisation.getString("build.numero").replace(" ", "").replace("", "");
    lisPreferences();
    setStPrincipal(stPrimaryStage);
    stPrimaryStage.setResizable(false);
    getStPrincipal().setResizable(true);
    getStPrincipal().setAlwaysOnTop(false);
    getStPrincipal().setTitle("PanoVisu v" + strNumVersion.split("-")[0]);
    stPrimaryStage.setMaximized(true);
    stPrimaryStage.setAlwaysOnTop(false);
    Rectangle2D tailleEcran = Screen.getPrimary().getBounds();
    int iHauteur;
    if (isMac()) {
        iHauteur = (int) tailleEcran.getHeight() - 60;
    } else {
        iHauteur = (int) tailleEcran.getHeight() - 20;
    }
    int iLargeur = (int) tailleEcran.getWidth() - 2;
    largeurMax = tailleEcran.getWidth() - 450.0d;
    creeEnvironnement(stPrimaryStage, iLargeur, iHauteur);

    File fileRepertTempFile = new File(getStrRepertAppli() + File.separator + "temp");
    setStrRepertTemp(fileRepertTempFile.getAbsolutePath());

    if (!fileRepertTempFile.exists()) {
        fileRepertTempFile.mkdirs();
    } else {
        deleteDirectory(getStrRepertTemp());
    }
    String strExtTemp = strGenereChaineAleatoire(20);
    setStrRepertTemp(getStrRepertTemp() + File.separator + "temp" + strExtTemp);
    fileRepertTempFile = new File(getStrRepertTemp());
    fileRepertTempFile.mkdirs();
    installeEvenements();
    projetsNouveau();
    stPrimaryStage.setOnCloseRequest((WindowEvent event) -> {
        try {
            sauvePreferences();
        } catch (IOException ex) {
            Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex);
        }
        ButtonType reponse = null;
        ButtonType buttonTypeOui = new ButtonType(rbLocalisation.getString("main.oui"));
        ButtonType buttonTypeNon = new ButtonType(rbLocalisation.getString("main.non"));
        ButtonType buttonTypeAnnule = new ButtonType(rbLocalisation.getString("main.annuler"));
        if (!isbDejaSauve()) {
            Alert alert = new Alert(AlertType.CONFIRMATION);
            alert.setTitle(rbLocalisation.getString("main.dialog.quitterApplication"));
            alert.setHeaderText(null);
            alert.setContentText(rbLocalisation.getString("main.dialog.chargeProjetMessage"));
            alert.getButtonTypes().clear();
            alert.getButtonTypes().setAll(buttonTypeOui, buttonTypeNon, buttonTypeAnnule);
            Optional<ButtonType> actReponse = alert.showAndWait();
            reponse = actReponse.get();
        }
        if (reponse == buttonTypeOui) {
            try {
                projetSauve();

            } catch (IOException ex) {
                Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        if ((reponse == buttonTypeOui) || (reponse == buttonTypeNon) || (reponse == null)) {
            try {
                sauveHistoFichiers();

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

            deleteDirectory(getStrRepertTemp());
            File fileTemp = new File(getStrRepertTemp());
            fileTemp.delete();
        } else {
            event.consume();
        }
    });
}

From source file:org.simmi.GeneSetHead.java

License:asdf

public void fetchGenomes() {
    if (geneset.zippath == null) {
        newFile();//from  ww  w  .jav a2  s.com
    }

    VBox vbox = new VBox();

    Stage stage = new Stage();
    stage.setTitle("Fetch genomes");
    stage.setScene(new Scene(vbox));
    stage.initOwner(primaryStage);

    //frame.setSize(400, 600);

    try {
        Map<String, String> env = new HashMap<>();
        env.put("create", "true");
        //Path path = zipfile.toPath();
        String uristr = "jar:" + geneset.zippath.toUri();
        geneset.zipuri = URI.create(uristr /*.replace("file://", "file:")*/ );
        geneset.zipfilesystem = FileSystems.newFileSystem(geneset.zipuri, env);

        final SerifyApplet sa = new SerifyApplet(geneset.zipfilesystem);
        sa.init(frame, vbox, geneset.user);

        for (Path root : geneset.zipfilesystem.getRootDirectories()) {
            Files.list(root).filter(t -> {
                String fname = t.getFileName().toString();
                return /*fname.endsWith(".gbk") || */fname.endsWith(".fna") || fname.endsWith("fastg")
                        || fname.endsWith(".fsa") || fname.endsWith(".fa") || fname.endsWith(".fasta")
                        || fname.endsWith(".aa") || fname.endsWith(".nn") || fname.endsWith(".trna")
                        || fname.endsWith(".rrna") || fname.endsWith(".ssu") || fname.endsWith(".lsu")
                        || fname.endsWith(".tsu");
            }).forEach(t -> {
                try {
                    sa.addSequences(t.getFileName().toString(), t, null);
                } catch (URISyntaxException | IOException e) {
                    e.printStackTrace();
                }
            });
            ;
        }
    } catch (IOException e1) {
        try {
            geneset.zipfilesystem.close();
        } catch (IOException e2) {
            e2.printStackTrace();
        }
        e1.printStackTrace();
    }

    //BufferedWriter bw = Files.newBufferedWriter(nf, StandardOpenOption.CREATE);

    //InputStream is = new GZIPInputStream( new FileInputStream( fc.getSelectedFile() ) );
    //uni2symbol(new InputStreamReader(is), bw, unimap);

    //bw.close();
    //long bl = Files.copy( new ByteArrayInputStream( baos.toByteArray() ), nf, StandardCopyOption.REPLACE_EXISTING );

    /*frame.addWindowListener( new WindowListener() {
               
       @Override
       public void windowOpened(WindowEvent e) {}
               
       @Override
       public void windowIconified(WindowEvent e) {}
               
       @Override
       public void windowDeiconified(WindowEvent e) {}
               
       @Override
       public void windowDeactivated(WindowEvent e) {}
               
       @Override
       public void windowClosing(WindowEvent e) {}
               
       @Override
       public void windowClosed(WindowEvent e) {
    try {
       geneset.zipfilesystem.close();
            
       geneset.cleanUp();
       importStuff();
    } catch (IOException | UnavailableServiceException e1) {
       e1.printStackTrace();
    }
       }
               
       @Override
       public void windowActivated(WindowEvent e) {}
    });
            
    frame.setVisible( true );*/

    stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
        public void handle(WindowEvent event) {
            try {
                geneset.zipfilesystem.close();

                geneset.cleanUp();
                importStuff();
            } catch (IOException | UnavailableServiceException e1) {
                e1.printStackTrace();
            }
        }
    });
    stage.show();
}