List of usage examples for javafx.scene.control Dialog showAndWait
public final Optional<R> showAndWait()
From source file:spdxedit.license.FileLicenseEditor.java
public static void editConcludedLicense(SpdxFile file, SpdxDocumentContainer container) { LicenseEditControl control = new LicenseEditControl(container, file, true); if (file.getLicenseConcluded() != null) { control.setInitialValue(file.getLicenseConcluded()); }//from w ww. ja v a2s. c o m Dialog<Boolean> dialog = UiUtils.newDialog("Edit License", ButtonType.OK); dialog.getDialogPane().setContent(control.getUi()); dialog.setResultConverter(buttonType -> { if (buttonType == ButtonType.OK) { return true; } else { return false; } }); boolean acceptChange = dialog.showAndWait().orElse(false); if (acceptChange) { try { file.setLicenseConcluded(control.getValue()); } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); } } }
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/*from w ww .java 2 s . com*/ * @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:jlotoprint.MainViewController.java
public static void loadAboutWindow() { //setup/*from w w w . jav a2s. 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:spdxedit.license.FileLicenseEditor.java
public static void extractLicenseFromFile(SpdxFile file, SpdxDocumentContainer container) { Dialog dialog = new Dialog(); dialog.setTitle(Main.APP_TITLE);//from w ww . j av a 2 s. c om 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:ruleprunermt2.FXMLDocumentController.java
@FXML private void RSESprepare() throws IOException { try {//w ww. j a v a2 s . c o m 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:ruleprunermt2.FXMLDocumentController.java
@FXML private void RSESconvertRules() throws IOException { try {// ww w.ja v a 2s . 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:cz.lbenda.dataman.db.frm.DbConfigFrmController.java
public static DbConfig openDialog(final DbConfig sc) { Dialog<DbConfig> dialog = DialogHelper.createDialog(); dialog.setResizable(false);/* www . j a va 2s .c o m*/ final Tuple2<Parent, DbConfigFrmController> tuple = createNewInstance(); if (sc != null) { tuple.get2().loadDataFromSessionConfiguration(sc); } dialog.setTitle(msgDialogTitle); dialog.setHeaderText(msgDialogHeader); dialog.getDialogPane().setContent(tuple.get1()); ButtonType buttonTypeOk = ButtonType.OK; ButtonType buttonTypeCancel = ButtonType.CANCEL; dialog.getDialogPane().getButtonTypes().add(buttonTypeCancel); dialog.getDialogPane().getButtonTypes().add(buttonTypeOk); dialog.getDialogPane().setPadding(new Insets(0, 0, 0, 0)); dialog.setResultConverter(b -> { if (b == buttonTypeOk) { DbConfig sc1 = sc; if (sc1 == null) { sc1 = new DbConfig(); tuple.get2().storeDataToSessionConfiguration(sc1); DbConfigFactory.getConfigurations().add(sc1); } else { tuple.get2().storeDataToSessionConfiguration(sc1); if (DbConfigFactory.getConfigurations().contains(sc1)) { // The copied session isn't in list yet int idx = DbConfigFactory.getConfigurations().indexOf(sc1); DbConfigFactory.getConfigurations().remove(sc1); DbConfigFactory.getConfigurations().add(idx, sc1); } else { DbConfigFactory.getConfigurations().add(sc1); } } DbConfigFactory.saveConfiguration(); return sc1; } return null; }); Optional<DbConfig> result = dialog.showAndWait(); if (result.isPresent()) { return result.get(); } return null; }
From source file:ruleprunermt2.FXMLDocumentController.java
@FXML private void removeMinSupport() throws IOException, InterruptedException { isRemoverContext = true;// w w w.j a v a 2 s . co 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 w w w . j a v a 2s. co 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; }
From source file:ruleprunermt2.FXMLDocumentController.java
@FXML private void testResults() { clickCounterTestValidation++;/* w w w.j a v a 2 s . c om*/ 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(); } }