Java Code Examples for javafx.scene.control.ButtonType#YES
The following examples show how to use
javafx.scene.control.ButtonType#YES .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DisplayWindow.java From marathonv5 with Apache License 2.0 | 7 votes |
private boolean closeEditor(IEditor e) { if (e == null) { return true; } if (e.isDirty()) { Optional<ButtonType> result = FXUIUtils.showConfirmDialog(DisplayWindow.this, "File \"" + e.getName() + "\" Modified. Do you want to save the changes ", "File \"" + e.getName() + "\" Modified", AlertType.CONFIRMATION, ButtonType.YES, ButtonType.NO, ButtonType.CANCEL); ButtonType shouldSaveFile = result.get(); if (shouldSaveFile == ButtonType.CANCEL) { return false; } if (shouldSaveFile == ButtonType.YES) { File file = save(e); if (file == null) { return false; } EditorDockable dockable = (EditorDockable) e.getData("dockable"); dockable.updateKey(); } } return true; }
Example 2
Source File: SelectRootPathUtils.java From PeerWasp with MIT License | 6 votes |
public static boolean confirmMoveDirectoryDialog(File newPath) { boolean yes = false; Alert dlg = DialogUtils.createAlert(AlertType.CONFIRMATION); dlg.setTitle("Move Directory"); dlg.setHeaderText("Move the directory?"); dlg.setContentText(String.format("This will move the directory to a new location: %s.", newPath.toString())); dlg.getButtonTypes().clear(); dlg.getButtonTypes().addAll(ButtonType.YES, ButtonType.NO); dlg.showAndWait(); yes = dlg.getResult() == ButtonType.YES; return yes; }
Example 3
Source File: GroupResource.java From marathonv5 with Apache License 2.0 | 6 votes |
@Override public Optional<ButtonType> delete(Optional<ButtonType> option) { if (!option.isPresent() || option.get() != FXUIUtils.YES_ALL) { option = FXUIUtils.showConfirmDialog(null, "Do you want to delete `" + group.getName() + "`?", "Confirm", AlertType.CONFIRMATION, ButtonType.YES, ButtonType.NO, FXUIUtils.YES_ALL, ButtonType.CANCEL); } if (option.isPresent() && (option.get() == ButtonType.YES || option.get() == FXUIUtils.YES_ALL)) { try { Group.delete(type, group); Event.fireEvent(this, new ResourceModificationEvent(ResourceModificationEvent.DELETE, this)); getParent().getChildren().remove(this); } catch (Exception e) { e.printStackTrace(); String message = String.format("Unable to delete: %s: %s%n", group.getName(), e); FXUIUtils.showMessageDialog(null, message, "Unable to delete", AlertType.ERROR); } } return option; }
Example 4
Source File: GroupEntryResource.java From marathonv5 with Apache License 2.0 | 6 votes |
@Override public Optional<ButtonType> delete(Optional<ButtonType> option) { if (!option.isPresent() || option.get() != FXUIUtils.YES_ALL) { option = FXUIUtils.showConfirmDialog(null, "Do you want to delete the entry `" + entry.getName() + "`?", "Confirm", AlertType.CONFIRMATION, ButtonType.YES, ButtonType.NO, FXUIUtils.YES_ALL, ButtonType.CANCEL); } if (option.isPresent() && (option.get() == ButtonType.YES || option.get() == FXUIUtils.YES_ALL)) { GroupResource parent = (GroupResource) getParent(); parent.deleteEntry(this); try { Group.updateFile(parent.getSuite()); Event.fireEvent(parent, new ResourceModificationEvent(ResourceModificationEvent.UPDATE, parent)); } catch (IOException e) { e.printStackTrace(); return option; } } return option; }
Example 5
Source File: FileResource.java From marathonv5 with Apache License 2.0 | 6 votes |
@Override public Optional<ButtonType> delete(Optional<ButtonType> option) { if (!option.isPresent() || option.get() != FXUIUtils.YES_ALL) { option = FXUIUtils.showConfirmDialog(null, "Do you want to delete `" + path + "`?", "Confirm", AlertType.CONFIRMATION, ButtonType.YES, ButtonType.NO, FXUIUtils.YES_ALL, ButtonType.CANCEL); } if (option.isPresent() && (option.get() == ButtonType.YES || option.get() == FXUIUtils.YES_ALL)) { if (Files.exists(path)) { try { Files.delete(path); Event.fireEvent(this, new ResourceModificationEvent(ResourceModificationEvent.DELETE, this)); getParent().getChildren().remove(this); } catch (IOException e) { String message = String.format("Unable to delete: %s: %s%n", path, e); FXUIUtils.showMessageDialog(null, message, "Unable to delete", AlertType.ERROR); } } } return option; }
Example 6
Source File: CustomizedTreeCell.java From PeerWasp with MIT License | 6 votes |
public void handle(ActionEvent t) { if (getItem() != null) { Alert hardDelete = DialogUtils.createAlert(AlertType.WARNING); hardDelete.setTitle("Irreversibly delete file?"); hardDelete.setHeaderText("You're about to hard-delete " + getItem().getPath().getFileName()); hardDelete.setContentText("The file will be removed completely from the network and cannot be recovered." + " Proceed?"); hardDelete.getButtonTypes().clear(); hardDelete.getButtonTypes().addAll(ButtonType.YES, ButtonType.NO); hardDelete.showAndWait(); if(hardDelete.getResult() == ButtonType.YES){ fileEventManager.onLocalFileHardDelete(getItem().getPath()); Alert confirm = DialogUtils.createAlert(AlertType.INFORMATION); confirm.setTitle("Hard-delete confirmation"); confirm.setContentText(getItem().getPath() + " has been hard-deleted."); confirm.showAndWait(); } } }
Example 7
Source File: FileEditorTabPane.java From markdown-writer-fx with BSD 2-Clause "Simplified" License | 6 votes |
boolean canCloseEditor(FileEditor fileEditor) { if (!fileEditor.isModified()) return true; Alert alert = mainWindow.createAlert(AlertType.CONFIRMATION, Messages.get("FileEditorTabPane.closeAlert.title"), Messages.get("FileEditorTabPane.closeAlert.message"), fileEditor.getTab().getText()); alert.getButtonTypes().setAll(ButtonType.YES, ButtonType.NO, ButtonType.CANCEL); // register first characters of Yes and No buttons as keys to close the alert for (ButtonType buttonType : Arrays.asList(ButtonType.YES, ButtonType.NO)) { Nodes.addInputMap(alert.getDialogPane(), consume(keyPressed(KeyCode.getKeyCode(buttonType.getText().substring(0, 1).toUpperCase())), e -> { if (!e.isConsumed()) { alert.setResult(buttonType); alert.close(); } })); } ButtonType result = alert.showAndWait().get(); if (result != ButtonType.YES) return (result == ButtonType.NO); return saveEditor(fileEditor); }
Example 8
Source File: EditorFrame.java From JetUML with GNU General Public License v3.0 | 6 votes |
private void close() { DiagramTab diagramTab = getSelectedDiagramTab(); // we only want to check attempts to close a frame if( diagramTab.hasUnsavedChanges() ) { // ask user if it is ok to close Alert alert = new Alert(AlertType.CONFIRMATION, RESOURCES.getString("dialog.close.ok"), ButtonType.YES, ButtonType.NO); alert.initOwner(aMainStage); alert.setTitle(RESOURCES.getString("dialog.close.title")); alert.setHeaderText(RESOURCES.getString("dialog.close.title")); alert.showAndWait(); if (alert.getResult() == ButtonType.YES) { removeGraphFrameFromTabbedPane(diagramTab); } return; } else { removeGraphFrameFromTabbedPane(diagramTab); } }
Example 9
Source File: SaveDrawing.java From latexdraw with GNU General Public License v3.0 | 6 votes |
/** * Does save on close. */ private void saveOnClose() { if(ui.isModified()) { saveAs = true; final ButtonType type = modifiedAlert.showAndWait().orElse(ButtonType.CANCEL); if(type == ButtonType.NO) { quit(); }else { if(type == ButtonType.YES) { showDialog(fileChooser, saveAs, file, currentFolder, ui, mainstage).ifPresent(f -> { file = f; super.doCmdBody(); quit(); }); }else { ok = false; } } }else { quit(); } }
Example 10
Source File: Util.java From trex-stateless-gui with Apache License 2.0 | 5 votes |
/** * Confirm deletion message window * * @param deleteMsg * @return */ public static boolean isConfirmed(String deleteMsg) { Alert confirmMsgBox = TrexAlertBuilder.build() .setType(Alert.AlertType.CONFIRMATION) .setButtons(ButtonType.YES, ButtonType.NO) .setContent(deleteMsg) .getAlert(); Optional<ButtonType> userSelection = confirmMsgBox.showAndWait(); return userSelection.isPresent() && userSelection.get() == ButtonType.YES; }
Example 11
Source File: EditorFrame.java From JetUML with GNU General Public License v3.0 | 5 votes |
/** * Exits the program if no graphs have been modified or if the user agrees to * abandon modified graphs. */ public void exit() { final int modcount = getNumberOfUsavedDiagrams(); if (modcount > 0) { Alert alert = new Alert(AlertType.CONFIRMATION, MessageFormat.format(RESOURCES.getString("dialog.exit.ok"), new Object[] { Integer.valueOf(modcount) }), ButtonType.YES, ButtonType.NO); alert.initOwner(aMainStage); alert.setTitle(RESOURCES.getString("dialog.exit.title")); alert.setHeaderText(RESOURCES.getString("dialog.exit.title")); alert.showAndWait(); if (alert.getResult() == ButtonType.YES) { Preferences.userNodeForPackage(UMLEditor.class).put("recent", aRecentFiles.serialize()); System.exit(0); } } else { Preferences.userNodeForPackage(UMLEditor.class).put("recent", aRecentFiles.serialize()); System.exit(0); } }
Example 12
Source File: AlertDialog.java From AsciidocFX with Apache License 2.0 | 5 votes |
public AlertDialog() { super(AlertType.WARNING, null, ButtonType.YES, ButtonType.CANCEL); super.setTitle("Warning"); super.initModality(Modality.WINDOW_MODAL); setDefaultIcon(super.getDialogPane()); showAlwaysOnTop(this); }
Example 13
Source File: MultiplayerTray.java From mars-sim with GNU General Public License v3.0 | 5 votes |
public void createAlert(String text) { //Stage stage = new Stage(); stage.getIcons().add(new Image(this.getClass().getResource("/icons/lander_hab.svg").toString())); String header = null; //String text = null; if (multiplayerClient != null) { header = "Multiplayer Client Connector"; } //System.out.println("confirm dialog pop up."); Alert alert = new Alert(AlertType.CONFIRMATION); alert.initOwner(stage); alert.setTitle("Mars Simulation Project"); alert.setHeaderText(header); alert.setContentText(text); alert.initModality(Modality.APPLICATION_MODAL); Optional<ButtonType> result = alert.showAndWait(); if (result.get() == ButtonType.YES){ notificationTimer.cancel(); Platform.exit(); tray.remove(trayIcon); System.exit(0); } //else { //} }
Example 14
Source File: MultiplayerTray.java From mars-sim with GNU General Public License v3.0 | 5 votes |
public void createAlert(String text) { //Stage stage = new Stage(); stage.getIcons().add(new Image(this.getClass().getResource("/icons/lander_hab.svg").toString())); String header = null; //String text = null; header = "Multiplayer Host Server"; //System.out.println("confirm dialog pop up."); Alert alert = new Alert(AlertType.CONFIRMATION); alert.initOwner(stage); alert.setTitle("Mars Simulation Project"); alert.setHeaderText(header); alert.setContentText(text); alert.initModality(Modality.APPLICATION_MODAL); Optional<ButtonType> result = alert.showAndWait(); if (result.get() == ButtonType.YES){ if (multiplayerServer != null) { // TODO: fix the loading problem for server mode multiplayerServer.setServerStopped(true); } notificationTimer.cancel(); Platform.exit(); tray.remove(trayIcon); System.exit(0); } //else { //} }
Example 15
Source File: DockItemWithInput.java From phoebus with Eclipse Public License 1.0 | 5 votes |
/** Called when user tries to close the tab * * <p>Derived class may override. * * @return Should the tab close? Otherwise it stays open. */ protected boolean okToClose() { if (! isDirty()) return true; final String text = MessageFormat.format(Messages.DockAlertMsg, getLabel()); final Alert prompt = new Alert(AlertType.NONE, text, ButtonType.NO, ButtonType.CANCEL, ButtonType.YES); prompt.setTitle(Messages.DockAlertTitle); prompt.getDialogPane().setMinSize(300, 100); prompt.setResizable(true); DialogHelper.positionDialog(prompt, getTabPane(), -200, -100); final ButtonType result = prompt.showAndWait().orElse(ButtonType.CANCEL); // Cancel the close request if (result == ButtonType.CANCEL) return false; // Close without saving? if (result == ButtonType.NO) return true; // Save in background job ... JobManager.schedule(Messages.Save, monitor -> save(monitor)); // .. and leave the tab open, so user can then try to close again return false; }
Example 16
Source File: LoadDrawing.java From latexdraw with GNU General Public License v3.0 | 5 votes |
@Override protected void doCmdBody() { if(ui.isModified()) { final ButtonType type = modifiedAlert.showAndWait().orElse(ButtonType.CANCEL); if(type == ButtonType.NO) { load(); }else { if(type == ButtonType.YES) { saveAndLoad(); } } }else { load(); } }
Example 17
Source File: DialogLoggerUtil.java From mzmine3 with GNU General Public License v2.0 | 4 votes |
public static boolean showDialogYesNo(String title, String message) { Alert alert = new Alert(AlertType.CONFIRMATION, message, ButtonType.YES, ButtonType.NO); alert.setTitle(title); Optional<ButtonType> result = alert.showAndWait(); return (result.isPresent() && result.get() == ButtonType.YES); }
Example 18
Source File: AlertHelper.java From AsciidocFX with Apache License 2.0 | 4 votes |
public static Optional<ButtonType> showYesNoAlert(String alertMessage) { AlertDialog deleteAlert = new AlertDialog(AlertType.WARNING, null, ButtonType.YES, ButtonType.NO); deleteAlert.setHeaderText(alertMessage); return deleteAlert.showAndWait(); }
Example 19
Source File: AlertHelper.java From AsciidocFX with Apache License 2.0 | 4 votes |
static Alert buildDeleteAlertDialog(List<Path> pathsLabel) { Alert deleteAlert = new WindowModalAlert(Alert.AlertType.WARNING, null, ButtonType.YES, ButtonType.CANCEL); deleteAlert.setHeaderText("Do you want to delete selected path(s)?"); DialogPane dialogPane = deleteAlert.getDialogPane(); ObservableList<Path> paths = Optional.ofNullable(pathsLabel) .map(FXCollections::observableList) .orElse(FXCollections.emptyObservableList()); if (paths.isEmpty()) { dialogPane.setContentText("There are no files selected."); deleteAlert.getButtonTypes().clear(); deleteAlert.getButtonTypes().add(ButtonType.CANCEL); return deleteAlert; } ListView<Path> listView = new ListView<>(paths); listView.setId("listOfPaths"); GridPane gridPane = new GridPane(); gridPane.addRow(0, listView); GridPane.setHgrow(listView, Priority.ALWAYS); double minWidth = 200.0; double maxWidth = Screen.getScreens().stream() .mapToDouble(s -> s.getBounds().getWidth() / 3) .min().orElse(minWidth); double prefWidth = paths.stream() .map(String::valueOf) .mapToDouble(s -> s.length() * 7) .max() .orElse(maxWidth); double minHeight = IntStream.of(paths.size()) .map(e -> e * 70) .filter(e -> e <= 300 && e >= 70) .findFirst() .orElse(200); gridPane.setMinWidth(minWidth); gridPane.setPrefWidth(prefWidth); gridPane.setPrefHeight(minHeight); dialogPane.setContent(gridPane); return deleteAlert; }
Example 20
Source File: AlertHelper.java From AsciidocFX with Apache License 2.0 | 4 votes |
public static Optional<ButtonType> showAlert(String alertMessage) { AlertDialog deleteAlert = new AlertDialog(AlertType.WARNING, null, ButtonType.YES, ButtonType.CANCEL); deleteAlert.setHeaderText(alertMessage); return deleteAlert.showAndWait(); }