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

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

源代码1 项目: constellation   文件: QueryListDialog.java
static String getQueryName(final Object owner, final String[] queryNames) {
    final Alert dialog = new Alert(Alert.AlertType.CONFIRMATION);

    final ObservableList<String> q = FXCollections.observableArrayList(queryNames);
    final ListView<String> nameList = new ListView<>(q);
    nameList.setCellFactory(p -> new DraggableCell<>());
    nameList.setEditable(false);
    nameList.setOnMouseClicked(event -> {
        if (event.getClickCount() > 1) {
            dialog.setResult(ButtonType.OK);
        }
    });

    dialog.setResizable(false);
    dialog.setTitle("Query names");
    dialog.setHeaderText("Select a query to load.");
    dialog.getDialogPane().setContent(nameList);
    final Optional<ButtonType> option = dialog.showAndWait();
    if (option.isPresent() && option.get() == ButtonType.OK) {
        return nameList.getSelectionModel().getSelectedItem();
    }

    return null;
}
 
public static boolean infoBox(String infoMessage, String headerText, String title){
    Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
    alert.setContentText(infoMessage);
    alert.setTitle(title);
    alert.setHeaderText(headerText);
    alert.getButtonTypes();
    
    Optional<ButtonType> result = alert.showAndWait();
    if (result.get() == ButtonType.OK){
        // ... user chose OK button
     return true;
    } else {
    // ... user chose CANCEL or closed the dialog
    return false;
    }
    
}
 
源代码3 项目: Schillsaver   文件: JobController.java
/**
 * Open a file chooser for the user to select an output directory for
 * the job.
 */
private void selectOutputFolder() {
    final JFileChooser fileChooser = new JFileChooser();
    fileChooser.setDragEnabled(false);
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    fileChooser.setDialogTitle("Directory Selection");
    fileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));

    fileChooser.setApproveButtonText("Accept");

    try {
        int returnVal = fileChooser.showOpenDialog(null);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            final JobView view = (JobView) super.getView();
            view.getTextField_outputFolder().setText(fileChooser.getSelectedFile().getPath() + "/");
        }
    } catch(final HeadlessException e) {
        final Alert alert = new Alert(Alert.AlertType.ERROR, "There was an issue selecting an output folder.\nSee the log file for more information.", ButtonType.OK);
        alert.showAndWait();

        Settings.getInstance().getLogger().log(e, LogLevel.ERROR);
    }
}
 
源代码4 项目: dctb-utfpr-2018-1   文件: PokemonHomeController.java
@FXML
private void delPokemonAction() {
    Pokemon toDelete = (Pokemon) pokemonTable.getSelectionModel().getSelectedItem();
    if(toDelete != null) {
        Alert confirmDelete = new Alert(Alert.AlertType.CONFIRMATION);
        confirmDelete.setTitle("Confirmar operação.");
        confirmDelete.setHeaderText("Confirme a operação de deletar.");
        confirmDelete.setContentText("Deletar Pokemon: "+toDelete.getName()+"?");
        Optional<ButtonType> confirm = confirmDelete.showAndWait();
        if(confirm.get() == ButtonType.OK) {
            new PokemonDAO().delete(toDelete);
            loadPokemonsInTable();
        }
    }
}
 
源代码5 项目: uip-pc2   文件: Controller.java
public void salir(ActionEvent actionEvent) {
    Alert alerta = new Alert(Alert.AlertType.CONFIRMATION);
    alerta.setTitle("Pa lante!");
    alerta.setContentText("Seguro que te quieres ir");
    alerta.setHeaderText("Intento de fuga");
    Optional<ButtonType> resultado = alerta.showAndWait();
    if (resultado.get() == ButtonType.OK) {
        Platform.exit();
    }

    int x = Integer.parseInt(campoblanco.getText());
}
 
源代码6 项目: DeskChan   文件: OverlayStage.java
private static boolean showConfirmation(String text){
	Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
	try {
		((Stage) alert.getDialogPane().getScene().getWindow()).setAlwaysOnTop(true);
	} catch (Exception e){ }
	alert.setTitle(Main.getString("default_messagebox_name"));
	alert.setContentText(Main.getString(text));
	Optional<ButtonType> result = alert.showAndWait();
	return (result.get() != ButtonType.OK);
}
 
源代码7 项目: marathonv5   文件: DisplayWindow.java
@Override
public void updated(IResourceActionSource source, Resource resource) {
    if (resource.getFilePath() != null) {
        File file = resource.getFilePath().toFile();
        EditorDockable dockable = findEditorDockable(file);
        if (dockable != null) {
            IEditor editor = dockable.getEditor();
            if (editor.isDirty() && !editor.isNewFile()) {
                Optional<ButtonType> option = FXUIUtils.showConfirmDialog(DisplayWindow.this,
                        "File `" + file + "` has been modified outside the editor. Do you want to reload it?",
                        "File being modified", AlertType.CONFIRMATION);
                if (option.isPresent() && option.get() == ButtonType.OK) {
                    Platform.runLater(() -> editor.refreshResource());
                }
            } else {
                Platform.runLater(() -> editor.refreshResource());
            }
        }
    }
    if (source != navigatorPanel) {
        navigatorPanel.updated(source, resource);
    }
    if (source != suitesPanel) {
        suitesPanel.updated(source, resource);
    }
    if (source != featuresPanel) {
        featuresPanel.updated(source, resource);
    }
    if (source != storiesPanel) {
        storiesPanel.updated(source, resource);
    }
    if (source != issuesPanel) {
        issuesPanel.updated(source, resource);
    }
}
 
源代码8 项目: 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;
}
 
源代码9 项目: PeerWasp   文件: CreateNetworkController.java
private boolean showConfirmDeleteNetworkDialog() {
	boolean yes = false;

	Window owner = txtIPAddress.getScene().getWindow();
	Alert dlg = DialogUtils.createAlert(AlertType.CONFIRMATION);
	dlg.initOwner(owner);
	dlg.setTitle("Delete Network");
	dlg.setHeaderText("Delete the network?");
	dlg.setContentText("If you go back, your peer will be shut down and your network deleted. Continue?");
	dlg.showAndWait();

	yes = dlg.getResult() == ButtonType.OK;

	return yes;
}
 
源代码10 项目: Library-Assistant   文件: BookListController.java
@FXML
private void handleBookDeleteOption(ActionEvent event) {
    //Fetch the selected row
    Book selectedForDeletion = tableView.getSelectionModel().getSelectedItem();
    if (selectedForDeletion == null) {
        AlertMaker.showErrorMessage("No book selected", "Please select a book for deletion.");
        return;
    }
    if (DatabaseHandler.getInstance().isBookAlreadyIssued(selectedForDeletion)) {
        AlertMaker.showErrorMessage("Cant be deleted", "This book is already issued and cant be deleted.");
        return;
    }
    Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
    alert.setTitle("Deleting book");
    alert.setContentText("Are you sure want to delete the book " + selectedForDeletion.getTitle() + " ?");
    Optional<ButtonType> answer = alert.showAndWait();
    if (answer.get() == ButtonType.OK) {
        Boolean result = DatabaseHandler.getInstance().deleteBook(selectedForDeletion);
        if (result) {
            AlertMaker.showSimpleAlert("Book deleted", selectedForDeletion.getTitle() + " was deleted successfully.");
            list.remove(selectedForDeletion);
        } else {
            AlertMaker.showSimpleAlert("Failed", selectedForDeletion.getTitle() + " could not be deleted");
        }
    } else {
        AlertMaker.showSimpleAlert("Deletion cancelled", "Deletion process cancelled");
    }
}
 
源代码11 项目: old-mzmine3   文件: MZmineGUI.java
public static void requestQuit() {
  Alert alert = new Alert(AlertType.CONFIRMATION);
  Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
  stage.getIcons().add(mzMineIcon);
  alert.setTitle("Confirmation");
  alert.setHeaderText("Exit MZmine");
  String s = "Are you sure you want to exit?";
  alert.setContentText(s);
  Optional<ButtonType> result = alert.showAndWait();

  if ((result.isPresent()) && (result.get() == ButtonType.OK)) {
    Platform.exit();
    System.exit(0);
  }
}
 
源代码12 项目: tcMenu   文件: CurrentProjectEditorUIImpl.java
@Override
public boolean questionYesNo(String title, String header) {
    logger.log(INFO, "Showing question for confirmation title: {0}, header: {1}", title, header);
    Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
    alert.setTitle(title);
    alert.setHeaderText(header);
    return alert.showAndWait().orElse(ButtonType.CANCEL) == ButtonType.OK;
}
 
源代码13 项目: Path-of-Leveling   文件: BuildsPanel_Controller.java
@FXML
private void deleteBuild(){
    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitle("Build delete");
    alert.setHeaderText("You are about to delete Build : "+ linker.get(activeBuildID).build.getName());
    alert.setContentText("Are you ok with this?");

    Optional<ButtonType> result = alert.showAndWait();
    if (result.get() == ButtonType.OK){
       BuildLinker bl = linker.get(activeBuildID);
        if(!bl.build.isValid){
            root.toggleFooterVisibility(true);
        }
        POELevelFx.buildsLoaded.remove(bl.build);
        sgc.reset();
        //buildsBox.getChildren().remove(bl.pec.getRoot()); // remove from the UI
        buildsBox.getItems().remove(bl.pec.getRoot()); // remove from the UI
        buildsBox.getSelectionModel().clearSelection();
        linker.remove(bl.id); //remove from data
        root.toggleActiveBuilds(false);
        if(POELevelFx.buildsLoaded.isEmpty()){
            root.toggleAllBuilds(false);
        }
    }

    // and also remove from file system?

}
 
源代码14 项目: ApkToolPlus   文件: DialogPlus.java
/**
 * 确认对话框
 *
 * @param title         标题
 * @param headerText    内容标题,可为null
 * @param contentText   提示内容
 * @param callback      回调
 */
public static void confirm(String title, String headerText, String contentText, DialogCallback callback){
    Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
    alert.setTitle(title);
    alert.setHeaderText(headerText);
    alert.setContentText(contentText);

    Optional<ButtonType> result = alert.showAndWait();
    if (result.get() == ButtonType.OK){
        callback.callback(DialogCallback.CODE_CONFIRM,null);
    } else {
        callback.callback(DialogCallback.CODE_CONCEL,null);
    }
}
 
源代码15 项目: pikatimer   文件: FXMLParticipantController.java
public void clearParticipants(ActionEvent fxevent){
    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitle("Confirm Participant Removal");
    alert.setHeaderText("This will remove all Participants from the event.");
    alert.setContentText("This action cannot be undone. Are you sure you want to do this?");

    Optional<ButtonType> result = alert.showAndWait();
    if (result.get() == ButtonType.OK){
        participantDAO.clearAll();
        resetForm(); 
    } else {
        // ... user chose CANCEL or closed the dialog
    }
    
}
 
源代码16 项目: MythRedisClient   文件: SetAction.java
/**
 * 删除值.
 *
 * @param key 数据库中的键
 */
@Override
public void delValue(String key, boolean selected) {
    Alert confirmAlert = MyAlert.getInstance(Alert.AlertType.CONFIRMATION);
    confirmAlert.setTitle("提示");
    confirmAlert.setHeaderText("");
    confirmAlert.setContentText("将随机删除一个值");
    Optional<ButtonType> opt = confirmAlert.showAndWait();
    ButtonType rtn = opt.get();
    if (rtn == ButtonType.OK) {
        // 确定
        redisSet.pop(key);
    }
}
 
源代码17 项目: Spring-generator   文件: AlertUtil.java
/**
 * 确定提示框
 * 
 * @param message
 */
public static boolean showConfirmAlert(String message) {
	Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
	alert.setContentText(message);
	Optional<ButtonType> optional = alert.showAndWait();
	if (ButtonType.OK == optional.get()) {
		return true;
	} else {
		return false;
	}
}
 
源代码18 项目: phoebus   文件: DockItemWithInput.java
/** Save the content of the item to its current 'input'
 *
 *  <p>Called by the framework when user invokes the 'Save*'
 *  menu items or when a 'dirty' tab is closed.
 *
 *  <p>Will never be called when the item remains clean,
 *  i.e. never called {@link #setDirty(true)}.
 *
 *  @param monitor {@link JobMonitor} for reporting progress
 *  @return <code>true</code> on success
 */
public final boolean save(final JobMonitor monitor)
{
    // 'final' because any save customization should be possible
    // inside the save_handler
    monitor.beginTask(MessageFormat.format(Messages.Saving , input));

    try
    {   // If there is no file (input is null or for example http:),
        // call save_as to prompt for file
        File file = ResourceParser.getFile(getInput());
        if (file == null)
            return save_as(monitor);


        if (file.exists()  &&  !file.canWrite())
        {   // Warn on UI thread that file is read-only
            final CompletableFuture<ButtonType> response = new CompletableFuture<>();
            Platform.runLater(() ->
            {
                final Alert prompt = new Alert(AlertType.CONFIRMATION);
                prompt.setTitle(Messages.SavingAlertTitle);
                prompt.setResizable(true);
                prompt.setHeaderText(MessageFormat.format(Messages.SavingAlert , file.toString()));
                DialogHelper.positionDialog(prompt, getTabPane(), -200, -200);
                response.complete(prompt.showAndWait().orElse(ButtonType.CANCEL));

            });

            // If user doesn't want to overwrite, abort the save
            if (response.get() == ButtonType.OK)
                return save_as(monitor);
            return false;
        }

        if (save_handler == null)
            throw new Exception("No save_handler provided for 'dirty' " + toString());
        save_handler.run(monitor);
    }
    catch (Exception ex)
    {
        logger.log(Level.WARNING, "Save error", ex);
        Platform.runLater(() ->
            ExceptionDetailsErrorDialog.openError(Messages.SavingHdr,
                                                  Messages.SavingErr + getLabel(), ex));
        return false;
    }

    // Successfully saved the file
    setDirty(false);
    return true;
}
 
源代码19 项目: 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;
    }
}
 
源代码20 项目: blobsaver   文件: Utils.java
static void newUnreportableError(String msg) {
    Alert alert = new Alert(Alert.AlertType.ERROR, msg, ButtonType.OK);
    alert.showAndWait();
}