javafx.scene.control.ButtonType#YES源码实例Demo

下面列出了javafx.scene.control.ButtonType#YES 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: marathonv5   文件: DisplayWindow.java
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;
}
 
源代码2 项目: PeerWasp   文件: SelectRootPathUtils.java
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;
}
 
源代码3 项目: marathonv5   文件: GroupResource.java
@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;
}
 
源代码4 项目: marathonv5   文件: GroupEntryResource.java
@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;
}
 
源代码5 项目: marathonv5   文件: FileResource.java
@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;
}
 
源代码6 项目: PeerWasp   文件: CustomizedTreeCell.java
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();
		}
	}
}
 
源代码7 项目: latexdraw   文件: SaveDrawing.java
/**
 * 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();
	}
}
 
源代码8 项目: JetUML   文件: EditorFrame.java
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);
	}
}
 
源代码9 项目: markdown-writer-fx   文件: FileEditorTabPane.java
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);
}
 
源代码10 项目: latexdraw   文件: LoadDrawing.java
@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();
	}
}
 
源代码11 项目: phoebus   文件: DockItemWithInput.java
/** 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;
}
 
源代码12 项目: trex-stateless-gui   文件: Util.java
/**
 * 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;
}
 
源代码13 项目: mars-sim   文件: MultiplayerTray.java
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 {
	//}
}
 
源代码14 项目: mars-sim   文件: MultiplayerTray.java
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 {
	//}
}
 
源代码15 项目: AsciidocFX   文件: AlertDialog.java
public AlertDialog() {
    super(AlertType.WARNING, null, ButtonType.YES, ButtonType.CANCEL);
    super.setTitle("Warning");
    super.initModality(Modality.WINDOW_MODAL);
    setDefaultIcon(super.getDialogPane());
    showAlwaysOnTop(this);
}
 
源代码16 项目: JetUML   文件: EditorFrame.java
/**
 * 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);
	}
}
 
源代码17 项目: mzmine3   文件: DialogLoggerUtil.java
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);
}
 
源代码18 项目: AsciidocFX   文件: AlertHelper.java
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;
}
 
源代码19 项目: AsciidocFX   文件: AlertHelper.java
public static Optional<ButtonType> showYesNoAlert(String alertMessage) {
    AlertDialog deleteAlert = new AlertDialog(AlertType.WARNING, null, ButtonType.YES, ButtonType.NO);
    deleteAlert.setHeaderText(alertMessage);
    return deleteAlert.showAndWait();
}
 
源代码20 项目: AsciidocFX   文件: AlertHelper.java
public static Optional<ButtonType> showAlert(String alertMessage) {
    AlertDialog deleteAlert = new AlertDialog(AlertType.WARNING, null, ButtonType.YES, ButtonType.CANCEL);
    deleteAlert.setHeaderText(alertMessage);
    return deleteAlert.showAndWait();
}