javafx.scene.control.ButtonBar.ButtonData Java Examples

The following examples show how to use javafx.scene.control.ButtonBar.ButtonData. 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 vote down vote up
/**
 * 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: DownloadDialog.java    From Animu-Downloaderu with MIT License 6 votes vote down vote up
public DownloadDialog(int count) {
	var buttonType = new ButtonType("Yes", ButtonData.YES);
	var dialogPane = getDialogPane();
	setTitle("Confirm Download");
	dialogPane.getStylesheets().add(getClass().getResource("/css/combo.css").toExternalForm());

	String question;
	if (count == 0) {
		question = "Please select at least one video";
		dialogPane.getButtonTypes().addAll(ButtonType.CLOSE);
	} else {
		question = String.format("Do you want to download %d episode(s)?", count);
		dialogPane.getButtonTypes().addAll(buttonType, ButtonType.NO);
	}

	var label = new Label(question);
	dialogPane.setContent(label);
	setResultConverter(dialogButton -> dialogButton == buttonType);
}
 
Example #3
Source File: FXMLTimingController.java    From pikatimer with GNU General Public License v3.0 6 votes vote down vote up
public void clearAllOverrides(ActionEvent fxevent){
    //TODO: Prompt and then remove all times associated with that timing location 
    // _or_ all timing locations
    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitle("Clear Overrides...");
    alert.setHeaderText("Delete Overrides:");
    alert.setContentText("Do you want to delete all overrides?");

    //ButtonType allButtonType = new ButtonType("All");
    
    ButtonType deleteButtonType = new ButtonType("Delete",ButtonData.YES);
    ButtonType cancelButtonType = new ButtonType("Cancel", ButtonData.CANCEL_CLOSE);

    alert.getButtonTypes().setAll(cancelButtonType, deleteButtonType );

    Optional<ButtonType> result = alert.showAndWait();
    if (result.get() == deleteButtonType) {
        // delete all
        timingDAO.clearAllOverrides(); 
    }
 
}
 
Example #4
Source File: MenuController.java    From zest-writer with GNU General Public License v3.0 6 votes vote down vote up
private void displayIndex(Map<String, Double> resultIndex, String title, String header) {
    BaseDialog dialog = new BaseDialog(title, header);
    dialog.getDialogPane().setPrefSize(800, 600);
    dialog.getDialogPane().getButtonTypes().addAll(new ButtonType(Configuration.getBundle().getString("ui.actions.stats.close"), ButtonBar.ButtonData.CANCEL_CLOSE));

    // draw
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();
    final LineChart<String,Number> lineChart = new LineChart<>(xAxis, yAxis);
    lineChart.setTitle(title);
    lineChart.setLegendVisible(false);

    xAxis.setLabel(Configuration.getBundle().getString("ui.actions.stats.xaxis"));
    yAxis.setLabel(Configuration.getBundle().getString("ui.actions.readable.yaxis"));

    XYChart.Series<String, Number> series = new XYChart.Series();
    for(Map.Entry<String, Double> st:resultIndex.entrySet()) {
        series.getData().add(new XYChart.Data(st.getKey(), st.getValue()));
    }
    lineChart.getData().addAll(series);
    dialog.getDialogPane().setContent(lineChart);
    dialog.setResizable(true);
    dialog.showAndWait();
}
 
Example #5
Source File: PacketHex.java    From trex-stateless-gui with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #6
Source File: IssuePickerDialog.java    From HubTurbo with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 #7
Source File: ParameterSetupDialog.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
private void setupHelpButton(URL helpURL) {

    // Add a Help button
    ButtonType helpButtonType = new ButtonType("Help", ButtonData.HELP);
    getDialogPane().getButtonTypes().add(helpButtonType);
    Button helpButton = (Button) getDialogPane().lookupButton(helpButtonType);

    // If there is no help file, disable the Help button
    if (helpURL == null) {
      helpButton.setDisable(true);
      return;
    }

    // Prevent closing this dialog by the Help button by adding an event
    // filter
    helpButton.addEventFilter(ActionEvent.ACTION, event -> {
      if ((helpWindow != null) && (!helpWindow.isShowing())) {
        helpWindow = null;
      }

      if (helpWindow != null) {
        helpWindow.toFront();
      } else {
        helpWindow = new HelpWindow(helpURL.toString());
        helpWindow.show();
      }
      event.consume();
    });

    // Close the help window when we close this dialog
    setOnHidden(e -> {
      if ((helpWindow != null) && (helpWindow.isShowing())) {
        helpWindow.close();
      }
    });

  }
 
Example #8
Source File: CircuitSim.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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;
}
 
Example #9
Source File: FXMLTimingController.java    From pikatimer with GNU General Public License v3.0 5 votes vote down vote up
public void clearAllTimes(ActionEvent fxevent){
    //TODO: Prompt and then remove all times associated with that timing location 
    // _or_ all timing locations
    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitle("Clear Timing Data...");
    alert.setHeaderText("Clear Timing Data:");
    alert.setContentText("Do you want to clear the times for all locations or just the " + selectedTimingLocation.getLocationName()+ " location?");

    ButtonType allButtonType = new ButtonType("All Times");
    
    ButtonType currentButtonType = new ButtonType(selectedTimingLocation.getLocationName() + " Times",ButtonData.YES);
    ButtonType cancelButtonType = new ButtonType("Cancel", ButtonData.CANCEL_CLOSE);

    alert.getButtonTypes().setAll(cancelButtonType, allButtonType,  currentButtonType );

    Optional<ButtonType> result = alert.showAndWait();
    if (result.get() == allButtonType){
        // ... user chose All
        timingDAO.clearAllTimes();
        // itterate over all of the timing locations
        timingLocationList.stream().forEach(tl -> {tl.getInputs().stream().forEach(tli -> {tli.clearLocalReads();});});
    } else if (result.get() == currentButtonType) {
        // ... user chose "Two"
        selectedTimingLocation.getInputs().stream().forEach(tli -> {tli.clearReads();});
    } else {
        // ... user chose CANCEL or closed the dialog
    }
 
}
 
Example #10
Source File: OpenLabelerController.java    From OpenLabeler with Apache License 2.0 5 votes vote down vote up
public boolean canClose() {
    if (miSave.isDisable()) {
        return true;
    }
    ButtonType saveAndClose = new ButtonType(bundle.getString("label.saveAndClose"), ButtonData.OTHER);
    Alert alert = AppUtils.createAlert(CONFIRMATION, bundle.getString("label.alert"), bundle.getString("msg.confirmClose"));
    alert.getButtonTypes().clear();
    alert.getButtonTypes().addAll(saveAndClose, ButtonType.YES, ButtonType.NO);
    Optional<ButtonType> result = alert.showAndWait();
    if (result.get() == saveAndClose) {
        save(true);
    }

    return result.get() != ButtonType.NO;
}
 
Example #11
Source File: ProxySettingDialog.java    From cute-proxy with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ProxySettingDialog() throws IOException {
    FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/proxy_setting.fxml"));
    loader.setRoot(this);
    loader.setController(this);
    loader.load();

    getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
    setResultConverter((dialogButton) -> {
        ButtonData data = dialogButton == null ? null : dialogButton.getButtonData();
        return data == ButtonData.OK_DONE ? getModel() : null;
    });

    proxySetting.addListener((o, old, n) -> setModel(n));

}
 
Example #12
Source File: MainSettingDialog.java    From cute-proxy with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public MainSettingDialog() throws IOException {
    FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/main_setting.fxml"));
    loader.setRoot(this);
    loader.setController(this);
    loader.load();

    setResultConverter((dialogButton) -> {
        ButtonData data = dialogButton == null ? null : dialogButton.getButtonData();
        return data == ButtonData.OK_DONE ? getModel() : null;
    });

    mainSetting.addListener((o, old, n) -> setModel(n));

}
 
Example #13
Source File: KeyStoreSettingDialog.java    From cute-proxy with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public KeyStoreSettingDialog() throws IOException {
    FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/key_store_setting.fxml"));
    loader.setRoot(this);
    loader.setController(this);
    loader.load();

    setResultConverter((dialogButton) -> {
        ButtonData data = dialogButton == null ? null : dialogButton.getButtonData();
        return data == ButtonData.OK_DONE ? getModel() : null;
    });

    keyStoreSetting.addListener((o, old, n) -> setModel(n));

}
 
Example #14
Source File: PasswordDialog.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** @param title Title, message
 *  @param correct_password Password to check
 */
public PasswordDialog(final String title, final String correct_password)
{
    this.correct_password = correct_password;
    final DialogPane pane = getDialogPane();

    pass_entry.setPromptText(Messages.Password_Prompt);
    pass_entry.setMaxWidth(Double.MAX_VALUE);

    HBox.setHgrow(pass_entry, Priority.ALWAYS);

    pane.setContent(new HBox(6, pass_caption, pass_entry));

    pane.setMinSize(300, 150);
    setResizable(true);

    setTitle(Messages.Password);
    setHeaderText(title);
    pane.getStyleClass().add("text-input-dialog");
    pane.getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);

    // Check password in dialog?
    if (correct_password != null  &&  correct_password.length() > 0)
    {
        final Button okButton = (Button) pane.lookupButton(ButtonType.OK);
        okButton.addEventFilter(ActionEvent.ACTION, event ->
        {
            if (! checkPassword())
                event.consume();
        });
    }

    setResultConverter((button) ->
    {
        return button.getButtonData() == ButtonData.OK_DONE ? pass_entry.getText() : null;
    });

    Platform.runLater(() -> pass_entry.requestFocus());
}
 
Example #15
Source File: DonateDialog.java    From Animu-Downloaderu with MIT License 5 votes vote down vote up
public DonateDialog() {
	var buttonType = new ButtonType("Yes", ButtonData.YES);
	var dialogPane = getDialogPane();

	setTitle("Donate :3");
	dialogPane.getStylesheets().add(getClass().getResource("/css/combo.css").toExternalForm());

	var gridPane = new GridPane();

	gridPane.setVgap(10);
	String question = "Thank you for clicking the donate button!! <3\n\n"
			+ "You can donate via liberapay, paypal, or help me by subscribing to my patreon!\n\n";

	Label librapay = new Label("Liberapay");
	Label paypal = new Label("Paypal");
	Label patrion = new Label("Patreon");
	HBox donateButtons = new HBox(15);
	donateButtons.setAlignment(Pos.CENTER);
	librapay.setCursor(Cursor.HAND);
	paypal.setCursor(Cursor.HAND);
	patrion.setCursor(Cursor.HAND);
	librapay.setId("link");
	paypal.setId("link");
	patrion.setId("link");

	librapay.setOnMouseClicked(e -> handleClick("https://liberapay.com/codingotaku/donate"));
	paypal.setOnMouseClicked(e -> handleClick("https://paypal.me/codingotaku"));
	patrion.setOnMouseClicked(e -> handleClick("https://www.patreon.com/bePatron?u=13678963"));
	donateButtons.getChildren().addAll(librapay, paypal, patrion);

	dialogPane.getButtonTypes().addAll(ButtonType.CLOSE);

	var label = new Label(question);
	GridPane.setConstraints(label, 1, 2);
	GridPane.setConstraints(donateButtons, 1, 3, 2, 1);
	gridPane.getChildren().addAll(label, donateButtons);
	dialogPane.setContent(gridPane);
	setResultConverter(dialogButton -> dialogButton == buttonType);
}
 
Example #16
Source File: LoginDialog.java    From zest-writer with GNU General Public License v3.0 4 votes vote down vote up
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 #17
Source File: DiffDisplayDialog.java    From zest-writer with GNU General Public License v3.0 4 votes vote down vote up
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 #18
Source File: CommitWidget.java    From BowlerStudio with GNU General Public License v3.0 4 votes vote down vote up
public static void commit(File currentFile, String code){
	if(code.length()<1){
		Log.error("COmmit failed with no code to commit");
		return;
	}
	Platform.runLater(() ->{
		// Create the custom dialog.
		Dialog<Pair<String, String>> dialog = new Dialog<>();
		dialog.setTitle("Commit message Dialog");
		dialog.setHeaderText("Enter a commit message to publish changes");


		// Set the button types.
		ButtonType loginButtonType = new ButtonType("Publish", ButtonData.OK_DONE);
		dialog.getDialogPane().getButtonTypes().addAll(loginButtonType, 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 username = new TextField();
		username.setPromptText("60 character description");
		TextArea password = new TextArea();
		password.setPrefRowCount(5);
		password.setPrefColumnCount(40);
		password.setPromptText("Full Sentences describing explanation");

		grid.add(new Label("What did you change?"), 0, 0);
		grid.add(username, 1, 0);
		grid.add(new Label("Why did you change it?"), 0, 1);
		grid.add(password, 1, 1);

		// Enable/Disable login button depending on whether a username was entered.
		Node loginButton = dialog.getDialogPane().lookupButton(loginButtonType);
		loginButton.setDisable(true);

		// Do some validation (using the Java 8 lambda syntax).
		username.textProperty().addListener((observable, oldValue, newValue) -> {
		    loginButton.setDisable(newValue.trim().length()<5);
		});

		dialog.getDialogPane().setContent(grid);

		// 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.
		dialog.setResultConverter(dialogButton -> {
		    if (dialogButton == loginButtonType) {
		        return new Pair<>(username.getText(), password.getText());
		    }
		    return null;
		});

		
		Optional<Pair<String, String>> result = dialog.showAndWait();

		result.ifPresent(commitBody -> {
		    new Thread(){
		    	public void run(){
					Thread.currentThread().setUncaughtExceptionHandler(new IssueReportingExceptionHandler());

				    String message = commitBody.getKey()+"\n\n"+commitBody.getValue();
				    
				    Git git;
					try {
						git = ScriptingEngine.locateGit(currentFile);
						String remote= git.getRepository().getConfig().getString("remote", "origin", "url");
						String relativePath = ScriptingEngine.findLocalPath(currentFile,git);
					    ScriptingEngine.pushCodeToGit(remote,ScriptingEngine.getFullBranch(remote), relativePath, code, message);
					    git.close();
					} catch (Exception e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
		    	}
		    }.start();
		});
	});
}
 
Example #19
Source File: DebugUtil.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void logException(String message, Throwable throwable) {
	System.err.println(message);
	throwable.printStackTrace();
	
	if(simulatorWindow.isWindowOpen()) {
		Platform.runLater(() -> {
			synchronized(DebugUtil.this) {
				if(showingError) return;
				showingError = true;
			}
			
			try {
				ByteArrayOutputStream stream = new ByteArrayOutputStream();
				throwable.printStackTrace(new PrintStream(stream));
				String errorMessage = stream.toString();
				
				Alert alert = new Alert(AlertType.ERROR);
				alert.initOwner(simulatorWindow.getStage());
				alert.initModality(Modality.WINDOW_MODAL);
				alert.setTitle("Internal error");
				alert.setHeaderText("Internal error: " + message);
				TextArea textArea = new TextArea(errorMessage);
				textArea.setMinWidth(600);
				textArea.setMinHeight(400);
				alert.getDialogPane().setContent(textArea);
				
				alert.getButtonTypes().clear();
				alert.getButtonTypes().add(new ButtonType("Save and Exit", ButtonData.APPLY));
				alert.getButtonTypes().add(new ButtonType("Send Error Report", ButtonData.YES));
				alert.getButtonTypes().add(new ButtonType("Cancel", ButtonData.CANCEL_CLOSE));
				Optional<ButtonType> buttonType = alert.showAndWait();
				
				if(buttonType.isPresent()) {
					if(buttonType.get().getButtonData() == ButtonData.YES) {
						sendErrorReport(message + "\n" + errorMessage);
					} else if(buttonType.get().getButtonData() == ButtonData.APPLY) {
						try {
							simulatorWindow.saveCircuits();
						} catch(Exception exc) {
							exc.printStackTrace();
						}
						
						simulatorWindow.closeWindow();
					}
				}
			} finally {
				showingError = false;
			}
		});
	}
}
 
Example #20
Source File: MultiplayerClient.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
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();
		} );

	}
 
Example #21
Source File: OptionsDialog.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public OptionsDialog(Window owner) {
	setTitle(Messages.get("OptionsDialog.title"));
	initOwner(owner);

	initComponents();

	tabPane.getStyleClass().add(TabPane.STYLE_CLASS_FLOATING);

	// add "Store in project" checkbox to buttonbar
	boolean oldStoreInProject = Options.isStoreInProject();
	ButtonType storeInProjectButtonType = new ButtonType(Messages.get("OptionsDialog.storeInProject.text"), ButtonData.LEFT);
	setDialogPane(new DialogPane() {
		@Override
		protected Node createButton(ButtonType buttonType) {
			if (buttonType == storeInProjectButtonType) {
				CheckBox storeInProjectButton = new CheckBox(buttonType.getText());
				ButtonBar.setButtonData(storeInProjectButton, buttonType.getButtonData());
				storeInProjectButton.setSelected(oldStoreInProject);
				storeInProjectButton.setDisable(ProjectManager.getActiveProject() == null);
				return storeInProjectButton;
			}
			return super.createButton(buttonType);
		}
	});

	DialogPane dialogPane = getDialogPane();
	dialogPane.setContent(tabPane);
	dialogPane.getButtonTypes().addAll(storeInProjectButtonType, ButtonType.OK, ButtonType.CANCEL);

	// save options on OK clicked
	dialogPane.lookupButton(ButtonType.OK).addEventHandler(ActionEvent.ACTION, e -> {
		boolean newStoreInProject = ((CheckBox)dialogPane.lookupButton(storeInProjectButtonType)).isSelected();
		if (newStoreInProject != oldStoreInProject)
			Options.storeInProject(newStoreInProject);

		save();
		e.consume();
	});

	Utils.fixSpaceAfterDeadKey(dialogPane.getScene());

	// load options
	load();

	// select last tab
	int tabIndex = MarkdownWriterFXApp.getState().getInt("lastOptionsTab", -1);
	if (tabIndex > 0 && tabIndex < tabPane.getTabs().size())
		tabPane.getSelectionModel().select(tabIndex);

	// remember last selected tab
	setOnHidden(e -> {
		MarkdownWriterFXApp.getState().putInt("lastOptionsTab", tabPane.getSelectionModel().getSelectedIndex());
	});
}
 
Example #22
Source File: ProjectDirectoryNotSpecifiedDialog.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
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;

}