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

下面列出了javafx.scene.control.ButtonType#CANCEL 实例代码,或者点击链接到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 项目: marathonv5   文件: Group.java
public static Group createGroup(GroupType type, Path path, String name) {
    List<Group> groups = getGroups(type);
    for (Group g : groups) {
        if (g.getName().equals(name)) {
            Optional<ButtonType> option = FXUIUtils.showConfirmDialog(null,
                    type.fileType() + " `" + g.getName() + "` name is already used.", "Duplicate " + type.fileType() + " Name",
                    AlertType.CONFIRMATION);
            if (!option.isPresent() || option.get() == ButtonType.CANCEL) {
                return null;
            }
        }
    }
    Group group = new Group(name);
    try {
        Files.write(path, (type.fileCommentHeader() + group.toJSONString()).getBytes());
        return new Group(path.toFile());
    } catch (IOException e) {
        return null;
    }
}
 
源代码3 项目: mcaselector   文件: ConfirmationDialog.java
public ConfirmationDialog(Stage primaryStage, Translation title, Translation headerText, String cssPrefix) {
	super(
			AlertType.WARNING,
			"",
			ButtonType.OK,
			ButtonType.CANCEL
	);
	initStyle(StageStyle.UTILITY);
	getDialogPane().getStyleClass().add(cssPrefix + "-confirmation-dialog-pane");
	getDialogPane().getStylesheets().addAll(primaryStage.getScene().getStylesheets());
	titleProperty().bind(title.getProperty());
	headerTextProperty().bind(headerText.getProperty());
	contentTextProperty().bind(Translation.DIALOG_CONFIRMATION_QUESTION.getProperty());
}
 
源代码4 项目: marathonv5   文件: ResourceView.java
private void delete(ObservableList<TreeItem<Resource>> selectedItems) {
    Optional<ButtonType> option = Optional.empty();
    ArrayList<TreeItem<Resource>> items = new ArrayList<>(selectedItems);
    for (TreeItem<Resource> treeItem : items) {
        option = treeItem.getValue().delete(option);
        if (option.isPresent() && option.get() == ButtonType.CANCEL) {
            break;
        }
    }
}
 
源代码5 项目: marathonv5   文件: FileHandler.java
@Override
public File saveAs(String script, Window parent, String filename) throws IOException {
    boolean saved = false;
    while (!saved) {
        File file = askForFile(parent, filename);
        if (file == null) {
            return null;
        }
        ButtonType option = ButtonType.YES;
        if (file.exists()) {
            if (nameValidateChecker != null && !nameValidateChecker.okToOverwrite(file)) {
                return null;
            }
            Optional<ButtonType> result = FXUIUtils.showConfirmDialog(parent,
                    "File " + file.getName() + " already exists. Do you want to overwrite?", "File exists",
                    AlertType.CONFIRMATION, ButtonType.YES, ButtonType.NO);
            option = result.get();
        }
        if (option == ButtonType.YES) {
            setCurrentFile(file);
            saveToFile(currentFile, script);
            return file;
        }
        if (option == ButtonType.CANCEL) {
            return null;
        }
    }
    return null;
}
 
源代码6 项目: 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;
}
 
源代码7 项目: CircuitSim   文件: CircuitSim.java
private boolean checkUnsavedChanges() {
	clearSelection();
	
	if(editHistory.editStackSize() != savedEditStackSize) {
		Alert alert = new Alert(AlertType.CONFIRMATION);
		alert.initOwner(stage);
		alert.initModality(Modality.WINDOW_MODAL);
		alert.setTitle("Unsaved changes");
		alert.setHeaderText("Unsaved changes");
		alert.setContentText("There are unsaved changes, do you want to save them?");
		
		ButtonType discard = new ButtonType("Discard", ButtonData.NO);
		alert.getButtonTypes().add(discard);
		
		Optional<ButtonType> result = alert.showAndWait();
		if(result.isPresent()) {
			if(result.get() == ButtonType.OK) {
				saveCircuitsInternal();
				return saveFile == null;
			} else {
				return result.get() == ButtonType.CANCEL;
			}
		}
	}
	
	return false;
}
 
源代码8 项目: 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);
}
 
源代码9 项目: sis   文件: CRSChooser.java
/**
 * Show a modal dialog to select a {@link CoordinateReferenceSystem}.
 *
 * @param parent parent frame of widget.
 * @param crs {@link CoordinateReferenceSystem} to edit.
 * @return modified {@link CoordinateReferenceSystem}.
 */
public static CoordinateReferenceSystem showDialog(Object parent, CoordinateReferenceSystem crs) {
    final CRSChooser chooser = new CRSChooser();
    chooser.crsProperty.set(crs);
    final Alert alert = new Alert(Alert.AlertType.NONE);
    final DialogPane pane = alert.getDialogPane();
    pane.setContent(chooser);
    alert.getButtonTypes().setAll(ButtonType.OK,ButtonType.CANCEL);
    alert.setResizable(true);
    final ButtonType res = alert.showAndWait().orElse(ButtonType.CANCEL);
    return res == ButtonType.CANCEL ? null : chooser.crsProperty.get();
}
 
源代码10 项目: blobsaver   文件: Utils.java
static void newReportableError(String msg) {
    Alert alert = new Alert(Alert.AlertType.ERROR, msg + "\n\nPlease create a new issue on Github or PM me on Reddit.", githubIssue, redditPM, ButtonType.CANCEL);
    alert.showAndWait();
    reportError(alert);
}
 
源代码11 项目: blobsaver   文件: Utils.java
static void newReportableError(String msg, String toCopy) {
    Alert alert = new Alert(Alert.AlertType.ERROR, msg + "\n\nPlease create a new issue on Github or PM me on Reddit. The log has been copied to your clipboard.", githubIssue, redditPM, ButtonType.CANCEL);
    alert.showAndWait();
    reportError(alert, toCopy);
}
 
源代码12 项目: kafka-message-tool   文件: AddTopicDialog.java
private void closeThisDialogWithCancelStatus() {
    returnButtonType = ButtonType.CANCEL;
    stage.close();
}
 
源代码13 项目: kafka-message-tool   文件: AlterTopicDialog.java
private void closeThisDialogWithCancelStatus() {
    returnButtonType = ButtonType.CANCEL;
    stage.close();
}
 
源代码14 项目: marathonv5   文件: Blurb.java
private void onCancel() {
    selection = ButtonType.CANCEL;
    dispose();
}
 
源代码15 项目: phoebus   文件: UpdateApplication.java
private void promptForUpdate(final Node node, final Instant new_version)
{
    final File install_location = Locations.install();
    // Want to  update install_location, but that's locked on Windows,
    // and replacing the jars of a running application might be bad.
    // So download into a stage area.
    // The start script needs to be aware of this stage area
    // and move it to the install location on startup.
    final File stage_area = new File(install_location, "update");
    final StringBuilder buf = new StringBuilder();
    buf.append("You are running version  ")
       .append(TimestampFormats.DATETIME_FORMAT.format(Update.current_version))
       .append("\n")
       .append("The new version is dated ")
       .append(TimestampFormats.DATETIME_FORMAT.format(new_version))
       .append("\n\n")
       .append("The update will replace the installation in\n")
       .append(install_location)
       .append("\n(").append(stage_area).append(")")
       .append("\nwith the content of ")
       .append(Update.update_url)
       .append("\n\n")
       .append("Do you want to update?\n");

    final Alert prompt = new Alert(AlertType.INFORMATION,
                                   buf.toString(),
                                   ButtonType.OK, ButtonType.CANCEL);
    prompt.setTitle(NAME);
    prompt.setHeaderText("A new version of this software is available");
    prompt.setResizable(true);
    DialogHelper.positionDialog(prompt, node, -600, -350);
    prompt.getDialogPane().setPrefSize(600, 300);
    if (prompt.showAndWait().orElse(ButtonType.CANCEL) == ButtonType.OK)
    {
        // Show job manager to display progress
        ApplicationService.findApplication(JobViewerApplication.NAME).create();
        // Perform update
        JobManager.schedule(NAME, monitor ->
        {
            Update.downloadAndUpdate(monitor, stage_area);
            Update.adjustCurrentVersion();
            if (! monitor.isCanceled())
                Platform.runLater(() -> restart(node));
        });
    }
    else
    {
        // Remove the update button
        StatusBar.getInstance().removeItem(start_update);
        start_update = null;
    }
}
 
源代码16 项目: 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;
}
 
源代码17 项目: 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();
}
 
源代码18 项目: AsciidocFX   文件: MyTab.java
private synchronized void save() {

        FileTime latestModifiedTime = IOHelper.getLastModifiedTime(getPath());

        if (Objects.nonNull(latestModifiedTime) && Objects.nonNull(getLastModifiedTime())) {
            if (latestModifiedTime.compareTo(getLastModifiedTime()) > 0) {

                this.select();
                ButtonType buttonType = AlertHelper.conflictAlert(getPath()).orElse(ButtonType.CANCEL);

                if (buttonType == ButtonType.CANCEL) {
                    return;
                }

                if (buttonType == AlertHelper.LOAD_FILE_SYSTEM_CHANGES) {
                    load();
                }
            } else {
                if (!isNew() && !isChanged()) {
                    return;
                }
            }
        }

        if (Objects.isNull(getPath())) {
            final FileChooser fileChooser = directoryService.newFileChooser(String.format("Save file"));
            fileChooser.getExtensionFilters().addAll(ExtensionFilters.ASCIIDOC);
            fileChooser.getExtensionFilters().addAll(ExtensionFilters.MARKDOWN);
            fileChooser.getExtensionFilters().addAll(ExtensionFilters.ALL);
            File file = fileChooser.showSaveDialog(null);

            if (Objects.isNull(file))
                return;

            setPath(file.toPath());
            setTabText(file.toPath().getFileName().toString());
        }

        String editorValue = editorPane.getEditorValue();

        IOHelper.createDirectories(getPath().getParent());

        Optional<Exception> exception =
                IOHelper.writeToFile(getPath(), editorValue, TRUNCATE_EXISTING, CREATE, SYNC);

        if (exception.isPresent()) {
            return;
        }

        setLastModifiedTime(IOHelper.getLastModifiedTime(getPath()));

        setChangedProperty(false);

        ObservableList<Item> recentFiles = storedConfigBean.getRecentFiles();
        recentFiles.remove(new Item(getPath()));
        recentFiles.add(0, new Item(getPath()));

        directoryService.setInitialDirectory(Optional.ofNullable(getPath().toFile()));
    }