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:spdxedit.license.FileLicenseEditor.java

public static void extractLicenseFromFile(SpdxFile file, SpdxDocumentContainer container) {

    Dialog dialog = new Dialog();
    dialog.setTitle(Main.APP_TITLE);/*w  ww  .j  a  va  2 s. co m*/
    dialog.setHeaderText("Extract license");

    ((Stage) dialog.getDialogPane().getScene().getWindow()).getIcons()
            .addAll(UiUtils.ICON_IMAGE_VIEW.getImage());

    dialog.getDialogPane().getButtonTypes().addAll(ButtonType.CANCEL, ButtonType.OK);

    String licenseName = "";
    String licenseText = null;
    String licenseId = "";
    //TODO: Add support for multiple extracted licenses.
    if (file.getLicenseInfoFromFiles() != null && file.getLicenseInfoFromFiles().length > 0) {
        Optional<AnyLicenseInfo> foundExtractedLicense = Arrays.stream(file.getLicenseInfoFromFiles())
                .filter(license -> license instanceof ExtractedLicenseInfo).findFirst();
        if (foundExtractedLicense.isPresent()) {
            licenseName = ((ExtractedLicenseInfo) foundExtractedLicense.get()).getName();
            licenseText = ((ExtractedLicenseInfo) foundExtractedLicense.get()).getExtractedText();
            licenseId = ((ExtractedLicenseInfo) foundExtractedLicense.get()).getLicenseId();

        }
    }

    LicenseExtractControl licenseExtractControl = new LicenseExtractControl(licenseName, licenseText,
            licenseId);

    dialog.getDialogPane().setContent(licenseExtractControl.getUi());
    Optional<ButtonType> result = dialog.showAndWait();

    licenseName = licenseExtractControl.getLicenseName();
    licenseText = licenseExtractControl.getLicenseText();
    licenseId = licenseExtractControl.getLicenseId();

    //No selection
    if (!result.isPresent() || result.get() == ButtonType.CANCEL) {
        return;
    }
    //Omitted data
    if (StringUtils.isBlank(licenseName)) {
        new Alert(Alert.AlertType.ERROR, "License name cannot be blank. Use \"NOASSERTION\" instead",
                ButtonType.OK).showAndWait();
        return;
    }
    if (StringUtils.isBlank(licenseText)) {
        new Alert(Alert.AlertType.ERROR, "License text cannot be blank.", ButtonType.OK).showAndWait();
        return;
    }
    if (StringUtils.isBlank(licenseId)) {
        new Alert(Alert.AlertType.ERROR, "License ID cannot be blank.", ButtonType.OK).showAndWait();
        return;
    }
    //License already extracted
    if (SpdxLogic.findExtractedLicenseByNameAndText(container, licenseName, licenseText).isPresent()) {
        new Alert(Alert.AlertType.WARNING,
                "License " + licenseName + " with the same text has already been extracted.", ButtonType.OK)
                        .showAndWait();
        return;
    }
    //License with ID already exists
    if (SpdxLogic.findExtractedLicenseInfoById(container, licenseId).isPresent()) {
        new Alert(Alert.AlertType.WARNING, "License with ID " + licenseId + " already exists.", ButtonType.OK)
                .showAndWait();
        return;
    }

    SpdxLogic.addExtractedLicenseFromFile(file, container, licenseId, licenseName, licenseText);

}

From source file:jlotoprint.MainViewController.java

public static void loadAboutWindow() {

    //setup/*from ww w . ja va  2s. c  o  m*/
    Dialog dialog = new Dialog<>();
    dialog.getDialogPane().getButtonTypes().add(ButtonType.CLOSE);
    dialog.setTitle("About JLotoPanel");
    dialog.setHeaderText("JLotoPanel v1.0");
    ImageView icon = new ImageView("file:resources/icon.png");
    icon.setSmooth(true);
    icon.setFitHeight(48.0);
    icon.setFitWidth(48.0);
    dialog.setGraphic(icon);
    dialog.initModality(Modality.APPLICATION_MODAL);
    dialog.initOwner(JLotoPrint.stage.getScene().getWindow());
    //content
    GridPane grid = new GridPane();
    grid.setPadding(new Insets(10, 10, 0, 10));

    //text
    TextArea textArea = new TextArea("For more info, please visit: https://github.com/mbppower/JLotoPanel");
    textArea.setWrapText(true);
    grid.add(textArea, 0, 0);
    dialog.getDialogPane().setContent(grid);

    dialog.showAndWait();
}

From source file:cz.lbenda.rcp.DialogHelper.java

/** Show unsaved object if aren't saved. if user want cancel the closing then return false, elserwhere return true
 * @param savableRegistry register which hold unsaved data
 * @return true if window/object can be closed */
public boolean showUnsavedObjectDialog(SavableRegistry savableRegistry) {
    Set<Savable> savables = savableRegistry.dirtySavables();
    if (savables.size() == 0) {
        return true;
    }//from  ww  w.j a  va 2 s.co m
    Dialog<?> dialog = new Dialog<>();
    dialog.setResizable(false);
    dialog.setTitle(msgNotSavedObjectsTitle);
    dialog.setHeaderText(msgNotSavedObjectsHeader);

    BorderPane pane = new BorderPane();
    pane.setPrefHeight(400);
    pane.setPrefWidth(300);
    ListView<DialogHelper.Item> listView = new ListView<>();
    listView.getItems()
            .addAll(savables.stream().map(savable -> new Item(savable, true)).collect(Collectors.toList()));
    listView.setCellFactory(CheckBoxListCell.forListView(DialogHelper.Item::onProperty));
    pane.setCenter(listView);

    dialog.getDialogPane().setContent(pane);

    ButtonType btCancel = new ButtonType(button_cancel, ButtonBar.ButtonData.CANCEL_CLOSE);
    ButtonType btSaveClose = new ButtonType(button_saveAndClose, ButtonBar.ButtonData.OK_DONE);
    ButtonType btClose = new ButtonType(button_closeWithoutSave);

    dialog.getDialogPane().getButtonTypes().addAll(btClose, btSaveClose, btCancel);

    Optional<?> result = dialog.showAndWait();
    if (result.isPresent()) {
        if (btCancel == result.get()) {
            return false;
        }
        if (btSaveClose == result.get()) {
            listView.getItems().stream().filter(Item::isOn).forEach(item -> item.getSavable().save());
        }
    } else {
        return false;
    }
    return true;
}

From source file:tachyon.view.ProjectProperties.java

public ProjectProperties(JavaProject project, Window w) {
    this.project = project;
    stage = new Stage();
    stage.initOwner(w);//  w ww.jav a2  s. c o  m
    stage.initModality(Modality.APPLICATION_MODAL);
    stage.setWidth(600);
    stage.setTitle("Project Properties - " + project.getProjectName());
    stage.getIcons().add(tachyon.Tachyon.icon);
    stage.setResizable(false);
    HBox mai, libs, one, two, thr, fou;
    ListView<String> compileList, runtimeList;
    Button compileAdd, compileRemove, preview, selectIm, runtimeAdd, runtimeRemove;
    TextField iconField;
    stage.setScene(new Scene(new VBox(5, pane = new TabPane(
            new Tab("Library Settings",
                    box1 = new VBox(15,
                            libs = new HBox(10, new Label("External Libraries"), libsView = new ListView<>(),
                                    new VBox(5, addJar = new Button("Add Jar"),
                                            removeJar = new Button("Remove Jar"))))),
            new Tab("Program Settings",
                    new ScrollPane(box2 = new VBox(15, one = new HBox(10, new Label("Main-Class"),
                            mainClass = new TextField(project.getMainClassName()),
                            select = new Button("Select")),
                            two = new HBox(10, new Label("Compile-Time Arguments"),
                                    compileList = new ListView<>(),
                                    new VBox(5, compileAdd = new Button("Add Argument"),
                                            compileRemove = new Button("Remove Argument")))))),
            new Tab("Deployment Settings",
                    box3 = new VBox(15, thr = new HBox(10, new Label("Icon File"),
                            iconField = new TextField(project.getFileIconPath()),
                            preview = new Button("Preview Image"), selectIm = new Button("Select Icon")),
                            fou = new HBox(10, new Label("Runtime Arguments"), runtimeList = new ListView<>(),
                                    new VBox(5, runtimeAdd = new Button("Add Argument"),
                                            runtimeRemove = new Button("Remove Argument")))))),
            new VBox(15, mai = new HBox(10, cancel = new Button("Cancel"), confirm = new Button("Confirm"))))));
    if (applyCss.get()) {
        stage.getScene().getStylesheets().add(css);
    }
    for (Tab b : pane.getTabs()) {
        b.setClosable(false);
    }
    mainClass.setPromptText("Main-Class");
    box1.setPadding(new Insets(5, 10, 5, 10));
    mai.setAlignment(Pos.CENTER_RIGHT);
    mai.setPadding(box1.getPadding());
    libs.setAlignment(Pos.CENTER);
    one.setAlignment(Pos.CENTER);
    two.setAlignment(Pos.CENTER);
    thr.setAlignment(Pos.CENTER);
    fou.setAlignment(Pos.CENTER);
    box1.setAlignment(Pos.CENTER);
    box2.setPadding(box1.getPadding());
    box2.setAlignment(Pos.CENTER);
    box3.setPadding(box1.getPadding());
    box3.setAlignment(Pos.CENTER);
    mainClass.setEditable(false);
    mainClass.setPrefWidth(200);
    for (JavaLibrary lib : project.getAllLibs()) {
        libsView.getItems().add(lib.getBinaryAbsolutePath());
    }
    for (String sa : project.getCompileTimeArguments().keySet()) {
        compileList.getItems().add(sa + ":" + project.getCompileTimeArguments().get(sa));
    }
    for (String sa : project.getRuntimeArguments()) {
        runtimeList.getItems().add(sa);
    }
    compileAdd.setOnAction((e) -> {
        Dialog<Pair<String, String>> dialog = new Dialog<>();
        dialog.setTitle("Compiler Argument");
        dialog.initOwner(stage);
        dialog.setHeaderText("Entry the argument");

        ButtonType loginButtonType = new ButtonType("Done", ButtonData.OK_DONE);
        dialog.getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL);

        GridPane grid = new GridPane();
        grid.setHgap(10);
        grid.setVgap(10);
        grid.setPadding(new Insets(20, 150, 10, 10));

        TextField username = new TextField();
        username.setPromptText("Key");
        TextField password = new TextField();
        password.setPromptText("Value");

        grid.add(new Label("Key:"), 0, 0);
        grid.add(username, 1, 0);
        grid.add(new Label("Value:"), 0, 1);
        grid.add(password, 1, 1);

        Node loginButton = dialog.getDialogPane().lookupButton(loginButtonType);
        loginButton.setDisable(true);

        username.textProperty().addListener((observable, oldValue, newValue) -> {
            loginButton.setDisable(newValue.trim().isEmpty());
        });

        dialog.getDialogPane().setContent(grid);

        Platform.runLater(() -> username.requestFocus());

        dialog.setResultConverter(dialogButton -> {
            if (dialogButton == loginButtonType) {
                return new Pair<>(username.getText(), password.getText());
            }
            return null;
        });

        Optional<Pair<String, String>> result = dialog.showAndWait();
        if (result.isPresent()) {
            compileList.getItems().add(result.get().getKey() + ":" + result.get().getValue());
        }
    });
    compileRemove.setOnAction((e) -> {
        if (compileList.getSelectionModel().getSelectedItem() != null) {
            compileList.getItems().remove(compileList.getSelectionModel().getSelectedItem());
        }
    });
    runtimeAdd.setOnAction((e) -> {
        TextInputDialog dia = new TextInputDialog();
        dia.setTitle("Add Runtime Argument");
        dia.setHeaderText("Enter an argument");
        dia.initOwner(stage);
        Optional<String> res = dia.showAndWait();
        if (res.isPresent()) {
            runtimeList.getItems().add(res.get());
        }
    });
    runtimeRemove.setOnAction((e) -> {
        if (runtimeList.getSelectionModel().getSelectedItem() != null) {
            runtimeList.getItems().remove(runtimeList.getSelectionModel().getSelectedItem());
        }
    });
    preview.setOnAction((e) -> {
        if (!iconField.getText().isEmpty()) {
            if (iconField.getText().endsWith(".ico")) {
                List<BufferedImage> read = new ArrayList<>();
                try {
                    read.addAll(ICODecoder.read(new File(iconField.getText())));
                } catch (IOException ex) {
                }
                if (read.size() >= 1) {
                    Image im = SwingFXUtils.toFXImage(read.get(0), null);
                    Stage st = new Stage();
                    st.initOwner(stage);
                    st.initModality(Modality.APPLICATION_MODAL);
                    st.setTitle("Icon Preview");
                    st.getIcons().add(Tachyon.icon);
                    st.setScene(new Scene(new BorderPane(new ImageView(im))));
                    if (applyCss.get()) {
                        st.getScene().getStylesheets().add(css);
                    }
                    st.showAndWait();
                }
            } else if (iconField.getText().endsWith(".icns")) {
                try {
                    BufferedImage ima = Imaging.getBufferedImage(new File(iconField.getText()));
                    if (ima != null) {
                        Image im = SwingFXUtils.toFXImage(ima, null);
                        Stage st = new Stage();
                        st.initOwner(stage);
                        st.initModality(Modality.APPLICATION_MODAL);
                        st.setTitle("Icon Preview");
                        st.getIcons().add(Tachyon.icon);
                        st.setScene(new Scene(new BorderPane(new ImageView(im))));
                        if (applyCss.get()) {
                            st.getScene().getStylesheets().add(css);
                        }
                        st.showAndWait();
                    }
                } catch (ImageReadException | IOException ex) {
                }
            } else {
                Image im = new Image(new File(iconField.getText()).toURI().toString());
                Stage st = new Stage();
                st.initOwner(stage);
                st.initModality(Modality.APPLICATION_MODAL);
                st.setTitle("Icon Preview");
                st.getIcons().add(Tachyon.icon);
                st.setScene(new Scene(new BorderPane(new ImageView(im))));
                if (applyCss.get()) {
                    st.getScene().getStylesheets().add(css);
                }
                st.showAndWait();
            }
        }
    });
    selectIm.setOnAction((e) -> {
        FileChooser fc = new FileChooser();
        fc.setTitle("Icon File");
        String OS = System.getProperty("os.name").toLowerCase();
        fc.getExtensionFilters().add(new ExtensionFilter("Icon File",
                OS.contains("win") ? getWindowsImageExtensions() : getMacImageExtensions()));
        fc.setSelectedExtensionFilter(fc.getExtensionFilters().get(0));
        File lf = fc.showOpenDialog(stage);
        if (lf != null) {
            iconField.setText(lf.getAbsolutePath());
        }
    });

    addJar.setOnAction((e) -> {
        FileChooser f = new FileChooser();
        f.setTitle("External Libraries");
        f.setSelectedExtensionFilter(new ExtensionFilter("Jar Files", "*.jar"));
        List<File> showOpenMultipleDialog = f.showOpenMultipleDialog(stage);
        if (showOpenMultipleDialog != null) {
            for (File fi : showOpenMultipleDialog) {
                if (!libsView.getItems().contains(fi.getAbsolutePath())) {
                    libsView.getItems().add(fi.getAbsolutePath());
                }
            }
        }
    });

    removeJar.setOnAction((e) -> {
        String selected = libsView.getSelectionModel().getSelectedItem();
        if (selected != null) {
            libsView.getItems().remove(selected);
        }
    });

    select.setOnAction((e) -> {
        List<String> all = getAll();
        ChoiceDialog<String> di = new ChoiceDialog<>(project.getMainClassName(), all);
        di.setTitle("Select Main Class");
        di.initOwner(stage);
        di.setHeaderText("Select A Main Class");
        Optional<String> show = di.showAndWait();
        if (show.isPresent()) {
            mainClass.setText(show.get());
        }
    });
    cancel.setOnAction((e) -> {
        stage.close();
    });
    confirm.setOnAction((e) -> {
        project.setMainClassName(mainClass.getText());
        project.setFileIconPath(iconField.getText());
        project.setRuntimeArguments(runtimeList.getItems());
        HashMap<String, String> al = new HashMap<>();
        for (String s : compileList.getItems()) {
            String[] spl = s.split(":");
            al.put(spl[0], spl[1]);
        }
        project.setCompileTimeArguments(al);
        project.setAllLibs(libsView.getItems());
        stage.close();
    });
}

From source file:net.jmhertlein.mcanalytics.console.gui.LoginPane.java

@FXML
public void onLoginButtonPressed(ActionEvent event) {
    HostEntry selected = hostList.getSelectionModel().getSelectedItem();
    if (selected == null)
        return;/*from w  w w. j a v  a2 s. c  o m*/

    try {
        SSLContext ctx = SSLUtil.buildClientContext(trust);
        SSLSocket raw = (SSLSocket) ctx.getSocketFactory().createSocket(selected.getUrl(), selected.getPort());
        raw.setWantClientAuth(true);
        try {
            System.out.println("Starting handshake...");
            raw.startHandshake();
        } catch (SSLException ssle) {
            if (ssle.getCause() instanceof UntrustedCertificateException) {
                System.out.println("Got the correct exception");
                UntrustedCertificateException uce = (UntrustedCertificateException) ssle.getCause();
                CertTrustPromptDialog dlg = new CertTrustPromptDialog(trust,
                        (X509Certificate) uce.getChain()[0]);
                dlg.showAndWait();
                System.out.println("DIALOG RETURNED");
            }
            return;
        }

        PrintWriter out = new PrintWriter(raw.getOutputStream());
        BufferedReader in = new BufferedReader(new InputStreamReader(raw.getInputStream()));
        APISocket sock = new APISocket(out, in);
        app.setAPISocket(sock);
        sock.startListener();

        //handle authentication
        boolean hasCert = false;
        FutureRequest<AuthenticationResult> login;
        if (trust.isCertificateEntry(selected.getUrl())) {
            try {
                ((X509Certificate) trust.getCertificate(selected.getUrl())).checkValidity();
                hasCert = true;
            } catch (CertificateExpiredException | CertificateNotYetValidException ex) {
                Logger.getLogger(LoginPane.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        System.out.println("Has cert: " + hasCert);
        KeyPair newPair = null;
        String username;

        if (hasCert) {
            username = SSLUtil.getCNs((X509Certificate) trust.getCertificate(selected.getUrl())).iterator()
                    .next();
            login = sock.submit(new AuthenticationRequest(username));
            System.out.println("Logging in w/ cert. CN: " + username + ", URL: " + selected.getUrl());
        } else if (rememberLoginBox.isSelected()) {
            newPair = SSLUtil.newECDSAKeyPair();
            username = usernameField.getText();
            PKCS10CertificationRequest csr = SSLUtil.newCertificateRequest(
                    SSLUtil.newX500Name(username, selected.getUrl(), "mcanalytics"), newPair);
            login = sock
                    .submit(new AuthenticationRequest(usernameField.getText(), passwordField.getText(), csr));
            System.out.println("Logging in with: " + usernameField.getText() + " + " + passwordField.getText()
                    + " and requesting a cert.");
        } else {
            username = usernameField.getText();
            login = sock.submit(new AuthenticationRequest(username, passwordField.getText()));
            System.out.println("Logging in with: " + username + " + " + passwordField.getText());
        }

        try {
            boolean success = login.get().getSuccess();
            if (success) {
                System.out.println("Login successful");
                if (login.get().hasCertificate()) {
                    trust.setCertificateEntry(selected.getUrl(), login.get().getCert());
                    trust.setKeyEntry(selected.getUrl() + "-private", newPair.getPrivate(), new char[0],
                            new Certificate[] { login.get().getCert(), login.get().getCA() });
                    System.out.println("Stored a trusted cert from server.");
                }
            } else {
                System.out.println("Login failed.");
                Dialog dlg = new Dialog();
                dlg.setTitle("Login Failed");
                dlg.setContentText("Could not login- invalid login credentials.");
                dlg.showAndWait();
                return;
            }
        } catch (InterruptedException | ExecutionException | KeyStoreException ex) {
            Logger.getLogger(LoginPane.class.getName()).log(Level.SEVERE, null, ex);
            Dialogs.showMessage("Connection Error", "Connection Error", ex.getMessage(), ex.toString());
            System.out.println("Login error.");
            return;
        }
        //auth done

        Stage window = (Stage) loginButton.getScene().getWindow();
        window.setScene(new Scene(new ChartPane(username, sock)));
        window.show();
    } catch (IOException | KeyStoreException ex) {
        Logger.getLogger(LoginPane.class.getName()).log(Level.SEVERE, null, ex);
        Dialog dlg = new Dialog();
        dlg.setTitle("Connection Error");
        dlg.setContentText(ex.getMessage());
        dlg.showAndWait();
        System.out.println("Login error.");
        return;
    }
}

From source file:cz.lbenda.rcp.DialogHelper.java

/** Open dialog with chooser when user can choose single option
 * @param question question which is show to user
 * @param items list of items which user can choose
 * @param <T> type of item//w  ww  .  j  a v a 2s  .  co  m
 * @return null if user click on cancel or don't choose anything, elsewhere choosed item */
@SuppressWarnings("unchecked")
public static <T> T chooseSingOption(String question, T... items) {
    if (items.length == 0) {
        return null;
    }
    Dialog<T> dialog = new Dialog<>();
    dialog.setResizable(false);
    dialog.setTitle(chooseSingleOption_title);
    dialog.setHeaderText(question);

    ComboBox<T> comboBox = new ComboBox<>();
    comboBox.getItems().addAll(items);
    dialog.getDialogPane().setContent(comboBox);

    ButtonType btCancel = ButtonType.CANCEL;
    ButtonType btOk = ButtonType.OK;
    dialog.getDialogPane().getButtonTypes().addAll(btCancel, btOk);

    Optional<T> result = dialog.showAndWait();
    if (result.isPresent()) {
        if (btCancel == result.get()) {
            return null;
        }
        if (btOk == result.get()) {
            return comboBox.getSelectionModel().getSelectedItem();
        }
    } else {
        return null;
    }
    return result.get();
}

From source file:cz.lbenda.rcp.DialogHelper.java

/** Create dialog with right icons */
public static <T> Dialog<T> createDialog(Object caller, String iconBaseName) {
    Dialog<T> dialog = new Dialog<>();
    Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
    if (iconBaseName == null) {
        iconBaseName = MessageFactory.getInstance().getMessage("app.icon");
    }//  w  w  w  . j a  v  a2 s. co  m
    stage.getIcons().add(IconFactory.getInstance().image(caller, iconBaseName, IconFactory.IconSize.SMALL));
    stage.getIcons().add(IconFactory.getInstance().image(caller, iconBaseName, IconFactory.IconSize.MEDIUM));
    stage.getIcons().add(IconFactory.getInstance().image(caller, iconBaseName, IconFactory.IconSize.LARGE));
    stage.getIcons().add(IconFactory.getInstance().image(caller, iconBaseName, IconFactory.IconSize.XLARGE));
    return dialog;
}

From source file:ruleprunermt2.FXMLDocumentController.java

@FXML
private void pruneRules() throws IOException {
    clickCounter++;//from w ww . j a  v  a  2s  .  com
    int decisionNumbers = Pruner.BinomialCalculation(decisionTable);

    if (!decisionTable.isEmpty() && (!validationTable.isEmpty() || !isExtendedPruningTTVSelected)
            && !rules.isEmpty() && !decisions.isEmpty() && clickCounter < 2) {
        rulesInATable.clear();
        //deleting all old rule files
        File f = new File(".");
        File[] files = f.listFiles();
        for (File file : files) {
            if (file.getName().contains(".csv")) {
                file.delete();
            }
        }

        for (int i = 0; i < rules.size(); i++) {
            String[] inputString = new String[decisionTable.get(0).length];
            for (int ii = 0; ii < inputString.length; ii++) {
                inputString[ii] = null;
            }
            for (int j = 0; j < rules.get(i).size(); j++) {

                String[] tmp = rules.get(i).get(j).split(" = ");
                //System.out.println(tmp);
                for (int tmpIterator = 0; tmpIterator < decisionTable.get(0).length; tmpIterator++) {
                    if (tmp[0].equals(decisionTable.get(0)[tmpIterator])) {
                        inputString[tmpIterator] = tmp[1];
                    }
                }
            }
            inputString[decisionTable.get(0).length - 1] = decisions.get(i);
            rulesInATable.add(inputString);
        }

        tableData.clear();

        String[] resultLength = Pruner.displayStatistics(tableData, rulesInATable, decisionTable, "Raw data");
        String[] resultCoverage = Pruner.calculateCoverage(tableData, rulesInATable, decisionTable, "");
        tableData.add(new Statistics("", "no of rules", Integer.toString(rulesInATable.size()),
                Integer.toString(rulesInATable.size()), Integer.toString(rulesInATable.size())));

        resultFileWriter.add(resultLength[0] + "," + resultLength[1] + "," + resultLength[2] + ","
                + resultCoverage[0] + "," + resultCoverage[1] + "," + resultCoverage[2] + ","
                + Integer.toString(rulesInATable.size()) + ",");

        //Remove duplicated rules
        Pruner.RemoveDuplicates(rulesInATable);

        Pruner.displayStatistics(tableData, rulesInATable, decisionTable, "Duplicates removed");
        Pruner.calculateCoverage(tableData, rulesInATable, decisionTable, "");
        tableData.add(new Statistics("", "no of rules", Integer.toString(rulesInATable.size()),
                Integer.toString(rulesInATable.size()), Integer.toString(rulesInATable.size())));

        //Cutting rules by simplification algorithm
        Pruner.CutRules(decisionTable, rulesInATable, decisions, isPSelected);

        //Remove duplicated rules
        Pruner.RemoveDuplicates(rulesInATable);

        resultLength = Pruner.displayStatistics(tableData, rulesInATable, decisionTable, "Rules cut");
        resultCoverage = Pruner.calculateCoverage(tableData, rulesInATable, decisionTable, "");
        tableData.add(new Statistics("", "no of rules", Integer.toString(rulesInATable.size()),
                Integer.toString(rulesInATable.size()), Integer.toString(rulesInATable.size())));

        resultFileWriter.add(resultLength[0] + "," + resultLength[1] + "," + resultLength[2] + ","
                + resultCoverage[0] + "," + resultCoverage[1] + "," + resultCoverage[2] + ","
                + Integer.toString(rulesInATable.size()) + ",");

        ArrayList<String[]> solution = Pruner.Prune(decisionTable, rulesInATable, decisions, decisionNumbers,
                isPSelected);

        DisplayResults.DisplayCorrect(rulesInATable, decisionTable, "PrunedRules.csv");

        String[] resultSupport = Pruner.calculateSupport(tableData, rulesInATable, decisionTable, "");

        if (!extendedPruningFlag) {
            if (isExtendedPruningTTVSelected) {
                DisplayResults.DisplayInaccurate(rulesInATable, solution, decisionTable, validationTable,
                        tableData);
            }
        } else {
            //TODO
            DecimalFormat df = new DecimalFormat("0.00000");
            Double error = Pruner.CalculateError(testTable, rulesInATable)[0];
            int misclassification = (int) Pruner.CalculateError(testTable, rulesInATable)[1];
            String tmpError1 = df.format(error);
            tmpError1 = tmpError1.replace(",", ".");
            String tmpError2 = " ";
            if (isExtendedPruningTTVSelected) {
                String[] inaccurateResult = DisplayResults.DisplayInaccurate(rulesInATable, solution,
                        decisionTable, testTable, tableData);
                if (!inaccurateResult[0].equals("")) {
                    resultFileWriter.add(inaccurateResult[0]);
                } else {
                    resultFileWriter.add(",,,,,,,");
                }
                if (inaccurateResult[1] == null) {
                    inaccurateResult[1] = tmpError1;
                }
                if (inaccurateResult[2] != null) {
                    resultFileWriter.add("," + tmpError1 + "," + inaccurateResult[1] + "," + inaccurateResult[2]
                            + "," + inaccurateResult[3] + "\n");
                } else {
                    resultFileWriter.add("," + tmpError1 + "," + inaccurateResult[1] + "," + misclassification
                            + "," + resultSupport[0] + "," + resultSupport[1] + "," + resultSupport[2] + "\n");
                }

                //protection in case of problem with number format
                try {
                    averagedResult.add(Double.parseDouble(inaccurateResult[1]));
                } catch (NumberFormatException ex) {
                    averagedResult.add(Double.parseDouble("1.0"));
                }
            } else {
                resultFileWriter.add("," + tmpError1 + "," + tmpError1 + "," + misclassification + ","
                        + resultSupport[0] + "," + resultSupport[1] + "," + resultSupport[2] + "\n");
                try {
                    averagedResult.add(Double.parseDouble(tmpError1));
                } catch (NumberFormatException ex) {
                    averagedResult.add(Double.parseDouble("1.0"));
                }
            }
        }

        if (!solution.isEmpty() && !extendedPruningFlag) {
            ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
            Dialog<String> dialog = new Dialog<>();
            dialog.getDialogPane().getButtonTypes().add(buttonOK);
            dialog.setContentText("Pruning successful!");
            dialog.showAndWait();
        } else if (resultFileWriter.isEmpty()) {
            ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
            Dialog<String> dialog = new Dialog<>();
            dialog.getDialogPane().getButtonTypes().add(buttonOK);
            dialog.setContentText("Basic pruning successful. Extended pruning failed!");
            dialog.showAndWait();
        }
    } else if (clickCounter < 2 && !extendedPruningFlag) {
        ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
        Dialog<String> dialog = new Dialog<>();
        dialog.getDialogPane().getButtonTypes().add(buttonOK);
        dialog.setContentText("Error while pruning! Please check your files");
        dialog.showAndWait();
        clickCounter--;
    } else if (!extendedPruningFlag) {
        ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
        Dialog<String> dialog = new Dialog<>();
        dialog.getDialogPane().getButtonTypes().add(buttonOK);
        dialog.setContentText("Too many clicks");
        dialog.showAndWait();
    }
}

From source file:ruleprunermt2.FXMLDocumentController.java

@FXML
private void testResults() {
    clickCounterTestValidation++;//from w  w w .j a  va2s.co m

    if (!testTable.isEmpty() && clickCounterTestValidation < 2) {
        for (int i = 0; i < rulesTest.size(); i++) {
            String[] inputString = new String[testTable.get(0).length];
            for (int ii = 0; ii < inputString.length; ii++) {
                inputString[ii] = null;
            }
            for (int j = 0; j < rulesTest.get(i).size(); j++) {

                String[] tmp = rulesTest.get(i).get(j).split(" = ");
                //System.out.println(tmp);
                for (int tmpIterator = 0; tmpIterator < testTable.get(0).length; tmpIterator++) {
                    if (tmp[0].equals(testTable.get(0)[tmpIterator])) {
                        inputString[tmpIterator] = tmp[1];
                    }
                }
            }
            inputString[testTable.get(0).length - 1] = decisionsTest.get(i);
            rulesInATableTest.add(inputString);
        }

        DecimalFormat df = new DecimalFormat("0.00000");
        Double error = Pruner.CalculateError(testTable, rulesInATableTest)[0];
        String tmpError = df.format(error);

        ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
        Dialog<String> dialog = new Dialog<>();
        dialog.getDialogPane().getButtonTypes().add(buttonOK);
        dialog.setContentText("Test error = " + tmpError.replace(",", "."));
        dialog.showAndWait();
    }

    if (testTable.isEmpty()) {
        ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
        Dialog<String> dialog = new Dialog<>();
        dialog.getDialogPane().getButtonTypes().add(buttonOK);
        dialog.setContentText("Test set empty!");
        dialog.showAndWait();
    }

}

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

private Optional<String> askUserForTextField(String text) {
    TextField textfield = new TextField();

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

    if (result.isPresent() && result.get().equals(ButtonType.OK))
        return Optional.of(textfield.getText());
    else//from  ww  w .j a v a2  s . c om
        return Optional.empty();
}