Example usage for javafx.scene.control Dialog Dialog

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

Introduction

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

Prototype

public Dialog() 

Source Link

Document

Creates a dialog without a specified owner.

Usage

From source file:com.ggvaidya.scinames.dataset.BinomialChangesSceneController.java

private Optional<String> askUserForTextArea(String label, String initialText) {
    TextArea textarea = new TextArea();
    if (initialText != null)
        textarea.setText(initialText);//from  ww  w .  j a v a 2  s . co  m

    Dialog<ButtonType> dialog = new Dialog<>();
    dialog.getDialogPane().headerTextProperty().set(label);
    dialog.getDialogPane().contentProperty().set(textarea);
    dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
    Optional<ButtonType> result = dialog.showAndWait();

    if (result.isPresent() && result.get().equals(ButtonType.OK))
        return Optional.of(textarea.getText());
    else
        return Optional.empty();
}

From source file:ruleprunermt2.FXMLDocumentController.java

@FXML
protected void divideTVT(ActionEvent event) throws IOException {
    if (!CSVdata.isEmpty() && !seedItems.isEmpty()) {
        File dir1 = new File(nameOfTheChosenFile + "/train-validation-test1");
        File dir2 = new File(nameOfTheChosenFile + "/train-validation-test2");
        if (dir1.exists()) {
            FileUtils.deleteDirectory(dir1);
        }//from ww  w . j a  va2 s  .c  o m
        dir1.mkdir();

        if (dir2.exists()) {
            FileUtils.deleteDirectory(dir2);
        }
        dir2.mkdir();

        for (int iterator = 0; iterator < seedItems.size(); iterator++) {
            long seed = Integer.parseInt(seedItems.get(iterator));
            Collections.shuffle(CSVdata, new Random(seed));

            try (FileWriter writeTrain = new FileWriter(nameOfTheChosenFile + "/train-validation-test1/"
                    + nameOfTheChosenFile + "_" + (iterator + 1) + "train.csv")) {
                writeTrain.append(label[0] + "\n");
                writeTrain.append(label[1] + "\n");
                for (int i = 0; i < Math.floor((CSVdata.size() * 3) / 10); i++) {
                    writeTrain.append(CSVdata.get(i) + "\n");
                }
                writeTrain.close();
            }

            try (FileWriter writeValidation = new FileWriter(nameOfTheChosenFile + "/train-validation-test1/"
                    + nameOfTheChosenFile + "_" + (iterator + 1) + "validation.csv")) {
                writeValidation.append(label[0] + "\n");
                writeValidation.append(label[1] + "\n");
                for (int i = (int) Math.floor((CSVdata.size() * 3) / 10); i < Math
                        .floor(CSVdata.size() / 2); i++) {
                    writeValidation.append(CSVdata.get(i) + "\n");
                }
                writeValidation.close();
            }

            try (FileWriter writeTest = new FileWriter(nameOfTheChosenFile + "/train-validation-test1/"
                    + nameOfTheChosenFile + "_" + (iterator + 1) + "test.csv")) {
                writeTest.append(label[0] + "\n");
                writeTest.append(label[1] + "\n");
                for (int i = (int) Math.floor(CSVdata.size() / 2); i < CSVdata.size(); i++) {
                    writeTest.append(CSVdata.get(i) + "\n");
                }
                writeTest.close();

            }

            //Second division
            try (FileWriter writeTrain = new FileWriter(nameOfTheChosenFile + "/train-validation-test2/"
                    + nameOfTheChosenFile + "_" + (iterator + 1) + "test.csv")) {
                writeTrain.append(label[0] + "\n");
                writeTrain.append(label[1] + "\n");
                for (int i = 0; i < Math.floor((CSVdata.size()) / 2); i++) {
                    writeTrain.append(CSVdata.get(i) + "\n");
                }
                writeTrain.close();
            }

            try (FileWriter writeValidation = new FileWriter(nameOfTheChosenFile + "/train-validation-test2/"
                    + nameOfTheChosenFile + "_" + (iterator + 1) + "train.csv")) {
                writeValidation.append(label[0] + "\n");
                writeValidation.append(label[1] + "\n");
                for (int i = (int) Math.floor((CSVdata.size()) / 2); i < Math
                        .floor((CSVdata.size() * 8) / 10); i++) {
                    writeValidation.append(CSVdata.get(i) + "\n");
                }
                writeValidation.close();
            }

            try (FileWriter writeTest = new FileWriter(nameOfTheChosenFile + "/train-validation-test2/"
                    + nameOfTheChosenFile + "_" + (iterator + 1) + "validation.csv")) {
                writeTest.append(label[0] + "\n");
                writeTest.append(label[1] + "\n");
                for (int i = (int) Math.floor((CSVdata.size() * 8) / 10); i < CSVdata.size(); i++) {
                    writeTest.append(CSVdata.get(i) + "\n");
                }
                writeTest.close();

            }
        }
        ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
        Dialog<String> dialog = new Dialog<>();
        dialog.getDialogPane().getButtonTypes().add(buttonOK);
        dialog.setContentText("Division successful");
        dialog.showAndWait();

    }
    if (CSVdata.isEmpty()) {
        fileName.setTextFill(Color.RED);
        fileName.setText("Data file is empty");
    }
    if (seedItems.isEmpty()) {
        seedName.setTextFill(Color.RED);
        seedName.setText("Seed file is empty");
    }

}

From source file:ruleprunermt2.FXMLDocumentController.java

@FXML
protected void kFoldCrossValidation(ActionEvent event) throws IOException {
    int tmp = (int) kSlider.getValue();
    if (!CSVdata.isEmpty() && !seedItems.isEmpty()) {
        //            File f = new File(fileName.getText() + "/train-validation-test/.");
        File dir = new File(nameOfTheChosenFile + "/k-fold symmetric cross validation");
        if (dir.exists()) {
            FileUtils.deleteDirectory(dir);
        }/* www .j  a  v a2 s  .  c  om*/
        dir.mkdir();

        for (int iterator = 0; iterator < seedItems.size(); iterator++) {
            long seed = Integer.parseInt(seedItems.get(iterator));
            Collections.shuffle(CSVdata, new Random(seed));

            int size = (int) Math.ceil((double) CSVdata.size() / (double) tmp);
            for (int i = 0; i < tmp; i++) {

                try (FileWriter writeFile = new FileWriter(
                        nameOfTheChosenFile + "/k-fold symmetric cross validation/" + nameOfTheChosenFile + "_"
                                + (iterator + 1) + "_" + (i + 1) + ".csv")) {
                    int limit = 0;
                    int oldLimit = 0;
                    //                        if (tmp > 2) {
                    if (i < (tmp - 1)) {
                        limit = (i + 1) * size;
                    } else {
                        limit = CSVdata.size();
                    }
                    //                        } else if (tmp == 2) { // division 70train :  30test
                    //                            if (i == 0) {
                    //                                limit = (int) Math.ceil((double) 0.7 * CSVdata.size());
                    //                            } else {
                    //                                oldLimit = (int) Math.ceil((double) 0.7 * CSVdata.size());;
                    //                                limit = CSVdata.size();
                    //                            }
                    //                        }

                    writeFile.append(label[0] + "\n");
                    writeFile.append(label[1] + "\n");
                    //                        if (tmp > 2) {
                    for (int j = i * size; j < limit; j++) {
                        writeFile.append(CSVdata.get(j) + "\n");
                    }
                    //                        } else if (tmp == 2) { // division 70train :  30test
                    //                            for (int j = oldLimit; j < limit; j++) {
                    //                                writeFile.append(CSVdata.get(j) + "\n");
                    //                            }
                    //                        }
                    writeFile.close();
                }
            }
        }
        ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
        Dialog<String> dialog = new Dialog<>();
        dialog.getDialogPane().getButtonTypes().add(buttonOK);
        dialog.setContentText("Division successful");
        dialog.showAndWait();
    }
    if (CSVdata.isEmpty()) {
        fileName.setTextFill(Color.RED);
        fileName.setText("Data file is empty");
    }
    if (seedItems.isEmpty()) {
        seedName.setTextFill(Color.RED);
        seedName.setText("Seed file is empty");
    }

}

From source file:ruleprunermt2.FXMLDocumentController.java

@FXML
private void pruneExtendedly() throws IOException {
    extendedPruningFlag = true;// ww  w  . ja va  2  s  . com
    resultFileWriter.clear();
    averagedResult.clear();

    FolderHandler.SplitFiles(isExtendedPruningTTVSelected);
    //        FolderHandler.RemoveUnwantedFiles(isExtendedPruningTTVSelected);

    File ruleDirectory = new File("rules/.");
    File[] ruleFiles = ruleDirectory.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".csv");
        }
    });

    if (ruleFiles.length < 1) {
        ButtonType emptyInput = new ButtonType("OK", ButtonBar.ButtonData.OK_DONE);
        Dialog<String> dialog = new Dialog<>();
        dialog.getDialogPane().getButtonTypes().add(emptyInput);
        dialog.setContentText("Folder \"rules\" is empty");
        dialog.showAndWait();
    }

    File trainDirectory = new File("train/.");
    File[] trainFiles = trainDirectory.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".csv");
        }
    });

    File validationDirectory = new File("validation/.");
    File[] validationFiles = validationDirectory.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".csv");
        }
    });

    File testDirectory = new File("test/.");
    File[] testFiles = testDirectory.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".csv");
        }
    });

    resultFileWriter.add(
            "rawData,,,,,,,prunedData,,,,,,,prunedDataWithAlpha,,,,,,,,testError,,additionalParameters" + "\n");
    resultFileWriter.add(
            "length,,,coverage,,,noOfRules,length,,,coverage,,,noOfRules,alpha,length,,,coverage,,,noOfRules,prunedRules,prunedRulesWithAlpha,no of misclassifications,support"
                    + "\n");
    resultFileWriter.add(
            "min,avg,max,min,avg,max,result,min,avg,max,min,avg,max,result,alpha,min,avg,max,min,avg,max,result,result,result,result,min,avg,max\n");
    if (ruleFiles.length > 0 && trainFiles.length > 0) {
        for (int i = 0; i < ruleFiles.length; i++) {

            if (ruleFiles[i].getName().contains(".csv") && trainFiles[i].getName().contains(".csv")
                    && ruleFiles[i].getName().contains(".csv")) {
                DataHandler dataHandler1 = new DataHandler("rules/" + ruleFiles[i].getName());
                dataHandler1.splitRules();
                rules.clear();
                decisions.clear();
                rules = dataHandler1.rules;
                decisions = dataHandler1.decisions;
                clickCounter = 0;

                DataHandler dataHandler2 = new DataHandler("train/" + trainFiles[i].getName());
                dataHandler2.splitTraining();
                decisionTable.clear();
                decisionTable = dataHandler2.decisionTable;
                clickCounter = 0;

                if (isExtendedPruningTTVSelected) {
                    clickCounterTestValidation = 0;
                    DataHandler dataHandlerValidation1 = new DataHandler(
                            "validation/" + validationFiles[i].getName());
                    dataHandlerValidation1.splitTraining();
                    validationTable.clear();
                    validationTable = dataHandlerValidation1.decisionTable;
                }

                clickCounterTestValidation = 0;
                DataHandler dataHandlerTest2 = new DataHandler("test/" + testFiles[i].getName());
                dataHandlerTest2.splitTraining();
                testTable.clear();
                testTable = dataHandlerTest2.decisionTable;

                pruneRules();

            }

        }
        File tmpFile = new File("results.csv");
        if (tmpFile.exists()) {
            tmpFile.delete();
        }

        DecimalFormat df = new DecimalFormat("0.00000");
        String resultFileName = "resultsAverage="
                + df.format(DataHandler.calculateAverage(averagedResult)).replace(",", ".") + "std="
                + df.format(DataHandler.calculateSTD(averagedResult)).replace(",", ".") + ".csv";

        try (FileWriter writeFile = new FileWriter(resultFileName, true)) {
            for (int i = 0; i < resultFileWriter.size(); i++) {
                writeFile.append(resultFileWriter.get(i));
            }
        }
        if (!isRemoverContext) {
            ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
            Dialog<String> dialog = new Dialog<>();
            dialog.getDialogPane().getButtonTypes().add(buttonOK);
            dialog.setContentText("Extended pruning successful!");
            dialog.showAndWait();
        }
    } else if (!isRemoverContext) {
        ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
        Dialog<String> dialog = new Dialog<>();
        dialog.getDialogPane().getButtonTypes().add(buttonOK);
        dialog.setContentText("Extended pruning failed, please check input and rule files!");
        dialog.showAndWait();
    }

    extendedPruningFlag = false;
}

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

public void actionFileMerge() {
    FileChooser chooser = new FileChooser();
    chooser.setTitle("Merge Schema");
    if (schemaFile != null)
        chooser.setInitialDirectory(schemaFile.getParentFile());

    File file = chooser.showOpenDialog(stage);
    if (file == null)
        return;/*w  w  w . ja v  a  2  s  .co m*/

    Schema addSchema = null;
    try {
        addSchema = ModelSchema.deserialise(file);
    } catch (IOException ex) {
        ex.printStackTrace();
        Util.informWarning("Merge", "Failed to parse file: is it a valid schema?");
        return;
    }

    List<String> log = new ArrayList<>();
    Schema merged = SchemaUtil.mergeSchema(stack.getSchema(), addSchema, log);
    if (log.size() == 0) {
        Util.informMessage("Merge", "The merge file is the same: no action.");
        return;
    }

    String text = String.join("\n", log);
    Dialog<Boolean> confirm = new Dialog<>();
    confirm.setTitle("Confirm Merge Modifications");

    TextArea area = new TextArea(text);
    area.setWrapText(true);
    area.setPrefWidth(700);
    area.setPrefHeight(500);
    confirm.getDialogPane().setContent(area);

    ButtonType btnApply = new ButtonType("Apply", ButtonBar.ButtonData.OK_DONE);
    confirm.getDialogPane().getButtonTypes().addAll(new ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE),
            btnApply);
    confirm.setResultConverter(buttonType -> {
        if (buttonType == btnApply)
            return true;
        return null;
    });

    Optional<Boolean> result = confirm.showAndWait();
    if (!result.isPresent() || result.get() != true)
        return;

    stack.changeSchema(merged, true);
    rebuildTree();
}

From source file:ruleprunermt2.FXMLDocumentController.java

@FXML
private void RSESprepare() throws IOException {
    try {//www.j  ava  2  s.com
        RSESpreparator.prepareRules();
        ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
        Dialog<String> dialog = new Dialog<>();
        dialog.getDialogPane().getButtonTypes().add(buttonOK);
        dialog.setContentText("Operation successful!");
        dialog.showAndWait();
    } catch (Exception e) {
        ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
        Dialog<String> dialog = new Dialog<>();
        dialog.getDialogPane().getButtonTypes().add(buttonOK);
        dialog.setContentText("Operation failed!");
        dialog.showAndWait();
    }
}

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

public void actionFileAssayStats() {
    List<String> stats = new ArrayList<>();
    SchemaUtil.gatherAssayStats(stack.peekSchema(), stats);
    String text = String.join("\n", stats);
    Dialog<Boolean> showdlg = new Dialog<>();
    showdlg.setTitle("Assay Stats");

    TextArea area = new TextArea(text);
    area.setWrapText(true);/*w w w. jav  a2 s .  c  o  m*/
    area.setPrefWidth(700);
    area.setPrefHeight(500);
    showdlg.getDialogPane().setContent(area);

    showdlg.getDialogPane().getButtonTypes().addAll(new ButtonType("OK", ButtonBar.ButtonData.OK_DONE));
    showdlg.setResultConverter(buttonType -> true);
    showdlg.showAndWait();
}

From source file:ruleprunermt2.FXMLDocumentController.java

@FXML
private void RSESconvertRules() throws IOException {
    try {/*from  www.  j  a  va2 s.c  o m*/
        RSESruleProcessor.processRules();
        ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
        Dialog<String> dialog = new Dialog<>();
        dialog.getDialogPane().getButtonTypes().add(buttonOK);
        dialog.setContentText("Operation successful!");
        dialog.showAndWait();
    } catch (Exception e) {
        ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
        Dialog<String> dialog = new Dialog<>();
        dialog.getDialogPane().getButtonTypes().add(buttonOK);
        dialog.setContentText("Operation failed!");
        dialog.showAndWait();
    }
}

From source file:ruleprunermt2.FXMLDocumentController.java

@FXML
private void removeMinSupport() throws IOException, InterruptedException {
    isRemoverContext = true;/*from   w w w  .  j a  v  a2s.c o m*/

    File directory = new File("removerResults");
    FileUtils.cleanDirectory(directory);

    int iterator = 1;
    double error = 1.0;
    while (true) {
        pruneExtendedly();
        File[] inputFiles;
        File inputDirectory = new File(".");
        inputFiles = inputDirectory.listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.toLowerCase().startsWith("resultsaverage");
            }
        });
        if (inputFiles.length > 0) {
            String fileName = inputFiles[0].getName();
            String[] splitFileName = fileName.split("resultsAverage=|std=|.csv");
            double tmpError = Double.parseDouble(splitFileName[1]);
            if (tmpError < error) {
                error = tmpError;
                File f1 = new File("removerResults/" + iterator + "_" + inputFiles[0].getName());
                inputFiles[0].renameTo(f1);
            } else {
                break;
            }
        } else {
            break;
        }
        Thread thread = new Thread(new SupportRemover());
        thread.start();
        //waiting for the thread to die
        thread.join();
        iterator++;
    }
    ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
    Dialog<String> dialog = new Dialog<>();
    dialog.getDialogPane().getButtonTypes().add(buttonOK);
    dialog.setContentText("Operation successful!");
    dialog.showAndWait();
    isRemoverContext = false;
}

From source file:ruleprunermt2.FXMLDocumentController.java

@FXML
private void removeMinCoverage() throws IOException, InterruptedException {
    isRemoverContext = true;/*from   www .j a  v a  2  s . c o m*/

    File directory = new File("removerResults");
    FileUtils.cleanDirectory(directory);

    int iterator = 1;
    double error = 1.0;
    while (true) {
        pruneExtendedly();
        File[] inputFiles;
        File inputDirectory = new File(".");
        inputFiles = inputDirectory.listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.toLowerCase().startsWith("resultsaverage");
            }
        });
        if (inputFiles.length > 0) {
            String fileName = inputFiles[0].getName();
            String[] splitFileName = fileName.split("resultsAverage=|std=|.csv");
            double tmpError = Double.parseDouble(splitFileName[1]);
            if (tmpError < error) {
                error = tmpError;
                File f1 = new File("removerResults/" + iterator + "_" + inputFiles[0].getName());
                inputFiles[0].renameTo(f1);
            } else {
                break;
            }
        } else {
            break;
        }
        Thread thread = new Thread(new CoverageRemover());
        thread.start();
        //waiting for the thread to die
        thread.join();
        iterator++;
    }
    ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
    Dialog<String> dialog = new Dialog<>();
    dialog.getDialogPane().getButtonTypes().add(buttonOK);
    dialog.setContentText("Operation successful!");
    dialog.showAndWait();
    isRemoverContext = false;
}