Java Code Examples for javafx.scene.control.ButtonBar.ButtonData#OK_DONE
The following examples show how to use
javafx.scene.control.ButtonBar.ButtonData#OK_DONE .
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: MenuControl.java From HubTurbo with GNU Lesser General Public License v3.0 | 6 votes |
/** * Deletes the board named {@boardName} * * @param boardName name of the board to delete */ public final void deleteBoard(String boardName) { Alert dlg = new Alert(AlertType.CONFIRMATION, ""); dlg.initModality(Modality.APPLICATION_MODAL); dlg.setTitle("Confirmation"); dlg.getDialogPane().setHeaderText("Delete board '" + boardName + "'?"); dlg.getDialogPane().setContentText("Are you sure you want to delete this board?"); Optional<ButtonType> response = dlg.showAndWait(); if (response.isPresent() && response.get().getButtonData() == ButtonData.OK_DONE) { prefs.removeBoard(boardName); if (prefs.getLastOpenBoard().isPresent() && prefs.getLastOpenBoard().get().equals(boardName)) { prefs.clearLastOpenBoard(); prefs.clearLastOpenBoardPanelInfos(); } ui.triggerEvent(new BoardSavedEvent()); logger.info(boardName + " was deleted"); ui.updateTitle(); } else { logger.info(boardName + " was not deleted"); } }
Example 2
Source File: PacketHex.java From trex-stateless-gui with Apache License 2.0 | 5 votes |
/** * Show dialog * * @param selectedText * @return */ private String showDialog(String selectedText) { Dialog dialog = new Dialog(); dialog.setTitle("Edit Hex"); dialog.setResizable(false); TextField text1 = new TextField(); text1.addEventFilter(KeyEvent.KEY_TYPED, hex_Validation(2)); text1.setText(selectedText); StackPane dialogPane = new StackPane(); dialogPane.setPrefSize(150, 50); dialogPane.getChildren().add(text1); dialog.getDialogPane().setContent(dialogPane); ButtonType buttonTypeOk = new ButtonType("Save", ButtonData.OK_DONE); dialog.getDialogPane().getButtonTypes().add(buttonTypeOk); dialog.setResultConverter(new Callback<ButtonType, String>() { @Override public String call(ButtonType b) { if (b == buttonTypeOk) { switch (text1.getText().length()) { case 0: return null; case 1: return "0".concat(text1.getText()); default: return text1.getText(); } } return null; } }); Optional<String> result = dialog.showAndWait(); if (result.isPresent()) { return result.get(); } return null; }
Example 3
Source File: IssuePickerDialog.java From HubTurbo with GNU Lesser General Public License v3.0 | 5 votes |
private void createButtons() { ButtonType confirmButtonType = new ButtonType("Confirm", ButtonData.OK_DONE); getDialogPane().getButtonTypes().addAll(confirmButtonType, ButtonType.CANCEL); // defines what happens when user confirms/presses enter setResultConverter(dialogButton -> { Optional<TurboIssue> selectedIssue = state.getSelectedIssue(); if (dialogButton.getButtonData() == ButtonData.OK_DONE && selectedIssue.isPresent()) { return selectedIssue.get().toString(); } return null; }); }
Example 4
Source File: ProjectDirectoryNotSpecifiedDialog.java From paintera with GNU General Public License v2.0 | 4 votes |
public Optional<String> showDialog(final String contentText) throws ProjectDirectoryNotSpecified { if (this.defaultToTempDirectory) { return Optional.of(tmpDir()); } final StringProperty projectDirectory = new SimpleStringProperty(null); final ButtonType specifyProject = new ButtonType("Specify Project", ButtonData.OTHER); final ButtonType noProject = new ButtonType("No Project", ButtonData.OK_DONE); final Dialog<String> dialog = new Dialog<>(); dialog.setResultConverter(bt -> { return ButtonType.CANCEL.equals(bt) ? null : noProject.equals(bt) ? tmpDir() : projectDirectory.get(); }); dialog.getDialogPane().getButtonTypes().setAll(specifyProject, noProject, ButtonType.CANCEL); dialog.setTitle("Paintera"); dialog.setHeaderText("Specify Project Directory"); dialog.setContentText(contentText); final Node lookupProjectButton = dialog.getDialogPane().lookupButton(specifyProject); if (lookupProjectButton instanceof Button) { ((Button) lookupProjectButton).setTooltip(new Tooltip("Look up project directory.")); } Optional .ofNullable(dialog.getDialogPane().lookupButton(noProject)) .filter(b -> b instanceof Button) .map(b -> (Button) b) .ifPresent(b -> b.setTooltip(new Tooltip("Create temporary project in /tmp."))); Optional .ofNullable(dialog.getDialogPane().lookupButton(ButtonType.CANCEL)) .filter(b -> b instanceof Button) .map(b -> (Button) b) .ifPresent(b -> b.setTooltip(new Tooltip("Do not start Paintera."))); lookupProjectButton.addEventFilter(ActionEvent.ACTION, event -> { final DirectoryChooser chooser = new DirectoryChooser(); final Optional<String> d = Optional.ofNullable(chooser.showDialog(dialog.getDialogPane().getScene() .getWindow())).map( File::getAbsolutePath); if (d.isPresent()) { projectDirectory.set(d.get()); } else { // consume on cancel, so that parent dialog does not get closed. event.consume(); } }); dialog.setResizable(true); final Optional<String> returnVal = dialog.showAndWait(); if (!returnVal.isPresent()) { throw new ProjectDirectoryNotSpecified(); } return returnVal; }
Example 5
Source File: DiffDisplayDialog.java From zest-writer with GNU General Public License v3.0 | 4 votes |
public DiffDisplayDialog(File file, String newContent, String titleContent, String titleExtract) { super(Configuration.getBundle().getString("ui.dialog.download.compare.window.title"), Configuration.getBundle().getString("ui.dialog.download.compare.window.header")); this.file = file; this.newContent = newContent; this.titleContent = titleContent; this.titleExtract = titleExtract; try { if(this.file.exists()) { this.oldContent = IOUtils.toString(new FileInputStream(this.file), "UTF-8"); } } catch (IOException e) { log.error(e.getMessage(), e); } ; // Set the button types. ButtonType validButtonType = new ButtonType(Configuration.getBundle().getString("ui.dialog.download.compare.button.confirm"), ButtonData.OK_DONE); this.getDialogPane().getButtonTypes().addAll(validButtonType, ButtonType.CANCEL); // Create the username and password labels and fields. GridPane grid = new GridPane(); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(20, 20, 10, 10)); Label l01 = new Label(Configuration.getBundle().getString("ui.dialog.download.compare.content_name") + " : "+titleContent); Label l02 = new Label(Configuration.getBundle().getString("ui.dialog.download.compare.extract_name") + " : "+titleExtract); Label l1 = new Label(Configuration.getBundle().getString("ui.dialog.download.compare.old_content")); Label l2 = new Label(Configuration.getBundle().getString("ui.dialog.download.compare.new_content")); TextArea textArea1 = new TextArea(); textArea1.setEditable(false); textArea1.setWrapText(true); textArea1.setPrefHeight(500); textArea1.setText(oldContent); ScrollPane scrollPane1 = new ScrollPane(); scrollPane1.setContent(textArea1); scrollPane1.setFitToWidth(true); TextArea textArea2 = new TextArea(); textArea2.setEditable(false); textArea2.setWrapText(true); textArea2.setPrefHeight(500); textArea2.setText(newContent); ScrollPane scrollPane2 = new ScrollPane(); scrollPane2.setContent(textArea2); scrollPane2.setFitToWidth(true); grid.add(l01, 0, 0,2, 1); grid.add(l02, 0, 1, 2, 1); grid.add(l1, 0, 2); grid.add(l2, 1, 2); grid.add(scrollPane1, 0, 3); grid.add(scrollPane2, 1, 3); // Enable/Disable login button depending on whether a username was entered. this.getDialogPane().lookupButton(validButtonType); this.getDialogPane().setContent(grid); Platform.runLater(textArea1::requestFocus); this.setResultConverter(dialogButton -> { if(dialogButton == validButtonType) { return true; } return false; }); }
Example 6
Source File: LoginDialog.java From zest-writer with GNU General Public License v3.0 | 4 votes |
public LoginDialog(Button googleButton) { super(Configuration.getBundle().getString("ui.dialog.auth.title"), Configuration.getBundle().getString("ui.dialog.auth.header")); this.config = MainApp.getConfig(); this.setGraphic(IconFactory.createLoginIcon()); // Set the button types. ButtonType loginButtonType = new ButtonType(Configuration.getBundle().getString("ui.dialog.auth.button"), ButtonData.OK_DONE); this.getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL); TextField username = new TextField(); username.setPromptText("username"); PasswordField password = new PasswordField(); password.setPromptText("password"); CheckBox keepConnection = new CheckBox(Configuration.getBundle().getString("ui.dialog.auth.stay")); getGridPane().add(googleButton, 0, 0, 1, 2); getGridPane().add(new Label(Configuration.getBundle().getString("ui.dialog.auth.username")+":"), 1, 0); getGridPane().add(username, 2, 0); getGridPane().add(new Label(Configuration.getBundle().getString("ui.dialog.auth.password")+":"), 1, 1); getGridPane().add(password, 2, 1); getGridPane().add(keepConnection, 2, 2); // Enable/Disable login button depending on whether a username was entered. Node loginButton = this.getDialogPane().lookupButton(loginButtonType); loginButton.setDisable(true); keepConnection.selectedProperty().addListener((observable, oldValue, newValue) -> { if(keepConnection.isSelected()){ Alert alert = new CustomAlert(Alert.AlertType.WARNING); alert.setTitle(Configuration.getBundle().getString("ui.dialog.warning.title")); alert.setContentText(Configuration.getBundle().getString("ui.dialog.auth.warning")); alert.showAndWait(); } }); username.textProperty().addListener((observable, oldValue, newValue) -> loginButton.setDisable(newValue.trim().isEmpty())); this.getDialogPane().setContent(getGridPane()); // Request focus on the username field by default. Platform.runLater(username::requestFocus); // Convert the result to a username-password-pair when the login button is clicked. this.setResultConverter(dialogButton -> { if (dialogButton == loginButtonType) { if(keepConnection.isSelected()){ config.setAuthentificationUsername(username.getText()); config.setAuthentificationPassword(password.getText()); config.saveConfFile(); } return new Pair<>(username.getText(), password.getText()); } return null; }); }
Example 7
Source File: MultiplayerClient.java From mars-sim with GNU General Public License v3.0 | 4 votes |
public void connectDialog() { // Create the custom dialog. Dialog<String> dialog = new Dialog<>(); // Get the Stage. Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow(); /* stage.setOnCloseRequest(e -> { boolean isExit = mainMenu.exitDialog(stage);//.getScreensSwitcher().exitDialog(stage); if (!isExit) { e.consume(); } else { Platform.exit(); } }); */ // Add corner icon. stage.getIcons().add(new Image(this.getClass().getResource("/icons/network/client48.png").toString())); // Add Stage icon dialog.setGraphic(new ImageView(this.getClass().getResource("/icons/network/network256.png").toString())); // dialog.initOwner(mainMenu.getStage()); dialog.setTitle("Mars Simulation Project"); dialog.setHeaderText("Multiplayer Client"); dialog.setContentText("Enter the host address : "); // Set the button types. ButtonType connectButtonType = new ButtonType("Connect", ButtonData.OK_DONE); // ButtonType localHostButton = new ButtonType("localhost"); // dialog.getDialogPane().getButtonTypes().addAll(localHostButton, // loginButtonType, ButtonType.CANCEL); dialog.getDialogPane().getButtonTypes().addAll(connectButtonType, ButtonType.CANCEL); // Create the username and password labels and fields. GridPane grid = new GridPane(); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(20, 150, 10, 10)); // TextField tfUser = new TextField(); // tfUser.setPromptText("Username"); TextField tfServerAddress = new TextField(); // PasswordField password = new PasswordField(); tfServerAddress.setPromptText("192.168.xxx.xxx"); tfServerAddress.setText("192.168.xxx.xxx"); Button localhostB = new Button("Use localhost"); // grid.add(new Label("Username:"), 0, 0); // grid.add(tfUser, 1, 0); grid.add(new Label("Server Address:"), 0, 1); grid.add(tfServerAddress, 1, 1); grid.add(localhostB, 2, 1); // Enable/Disable connect button depending on whether the host address // was entered. Node connectButton = dialog.getDialogPane().lookupButton(connectButtonType); connectButton.setDisable(true); // Do some validation (using the Java 8 lambda syntax). tfServerAddress.textProperty().addListener((observable, oldValue, newValue) -> { connectButton.setDisable(newValue.trim().isEmpty()); } ); dialog.getDialogPane().setContent(grid); // Request focus on the username field by default. Platform.runLater(() -> tfServerAddress.requestFocus()); // Convert the result to a username-password-pair when the login button // is clicked. dialog.setResultConverter(dialogButton -> { if (dialogButton == connectButtonType) { return tfServerAddress.getText(); } return null; } ); localhostB.setOnAction(event -> { tfServerAddress.setText("127.0.0.1"); } ); // localhostB.setPadding(new Insets(1)); // localhostB.setPrefWidth(10); Optional<String> result = dialog.showAndWait(); result.ifPresent(input -> { String serverAddressStr = tfServerAddress.getText(); this.serverAddressStr = serverAddressStr; logger.info("Connecting to server at " + serverAddressStr); loginDialog(); } ); }