javafx.scene.control.Alert.AlertType#ERROR源码实例Demo

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

源代码1 项目: ShootOFF   文件: TargetDistancePane.java
private boolean validateDistanceData() {
	boolean isValid = validateDistanceField(shooterDistance);
	isValid = validateDistanceField(targetDistance) && isValid;
	isValid = validateDistanceField(cameraDistance) && isValid;
	isValid = validateDistanceField(targetWidth) && isValid;
	isValid = validateDistanceField(targetHeight) && isValid;

	if (!isValid) return isValid;

	if ("0".equals(targetDistance.getText())) {
		final Alert invalidDataAlert = new Alert(AlertType.ERROR);

		final String message = "Target Distance cannot be 0, please set a value greater than 0.";

		invalidDataAlert.setTitle("Invalid Target Distance");
		invalidDataAlert.setHeaderText("Target Distance Cannot Be Zero");
		invalidDataAlert.setResizable(true);
		invalidDataAlert.setContentText(message);
		invalidDataAlert.initOwner(getScene().getWindow());
		invalidDataAlert.showAndWait();

		isValid = false;
	}

	return isValid;
}
 
源代码2 项目: JetUML   文件: EditorFrame.java
private void save() 
{
	DiagramTab diagramTab = getSelectedDiagramTab();
	Optional<File> file = diagramTab.getFile();
	if(!file.isPresent()) 
	{
		saveAs();
		return;
	}
	try 
	{
		PersistenceService.save(diagramTab.getDiagram(), file.get());
		diagramTab.diagramSaved();
	} 
	catch(IOException exception) 
	{
		Alert alert = new Alert(AlertType.ERROR, RESOURCES.getString("error.save_file"), ButtonType.OK);
		alert.initOwner(aMainStage);
		alert.showAndWait();
	}
}
 
源代码3 项目: Library-Assistant   文件: AlertMaker.java
public static void showErrorMessage(Exception ex, String title, String content) {
    Alert alert = new Alert(AlertType.ERROR);
    alert.setTitle("Error occured");
    alert.setHeaderText(title);
    alert.setContentText(content);

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    ex.printStackTrace(pw);
    String exceptionText = sw.toString();

    Label label = new Label("The exception stacktrace was:");

    TextArea textArea = new TextArea(exceptionText);
    textArea.setEditable(false);
    textArea.setWrapText(true);

    textArea.setMaxWidth(Double.MAX_VALUE);
    textArea.setMaxHeight(Double.MAX_VALUE);
    GridPane.setVgrow(textArea, Priority.ALWAYS);
    GridPane.setHgrow(textArea, Priority.ALWAYS);

    GridPane expContent = new GridPane();
    expContent.setMaxWidth(Double.MAX_VALUE);
    expContent.add(label, 0, 0);
    expContent.add(textArea, 0, 1);

    alert.getDialogPane().setExpandableContent(expContent);
    alert.showAndWait();
}
 
@FXML
public void showPreferences() {
	
	try {
		
        FXMLLoader fxmlLoader = new FXMLLoader(
                HomeScreenController.class.getResource( "Preferences.fxml" ),
                null,
                builderFactory,
                (clazz) -> injector.getInstance(clazz));

        Parent prefsScreen = fxmlLoader.load();
        
		Scene scene = new Scene(prefsScreen, 1024, 768 );

		Stage stage = new Stage();
		stage.setScene( scene );
		stage.setTitle( "Preferences" );
		stage.show();
				
	} catch(Exception exc) {
		
		logger.error( "error showing preferences", exc);
		
		Alert alert = new Alert(AlertType.ERROR);
		alert.setTitle("Preferences");
		alert.setHeaderText("Error showing Preferences");
		alert.setContentText(exc.getMessage());
		alert.showAndWait();
	}
}
 
源代码5 项目: PeerWasp   文件: DialogUtilsTest.java
@Test
public void testDecorateDialogWithIcon() {
	Alert dlg = new Alert(AlertType.ERROR);
	assertFalse(alertHasIcons(dlg));
	DialogUtils.decorateDialogWithIcon(dlg);
	assertTrue(alertHasIcons(dlg));
}
 
源代码6 项目: java-ml-projects   文件: App.java
private void showError(String title, String message) {
	Alert alert = new Alert(AlertType.ERROR);
	alert.setTitle(title);
	alert.setHeaderText(null);
	alert.setContentText(message);
	alert.showAndWait();
}
 
/**
 * Renames a node through the service and its underlying data provider.
 * If there is a problem in the call to the remote JMasar service,
 * the user is shown a suitable error dialog and the name of the node is restored.
 * @param node The node being renamed
 */
private void renameNode(TreeItem<Node> node){

    List<String> existingSiblingNodes =
            node.getParent().getChildren().stream()
                    .filter(item -> item.getValue().getNodeType().equals(node.getValue().getNodeType()))
                    .map(item -> item.getValue().getName())
                    .collect(Collectors.toList());

    TextInputDialog dialog = new TextInputDialog();
    dialog.setTitle(Messages.promptRenameNodeTitle);
    dialog.setContentText(Messages.promptRenameNodeContent);
    dialog.setHeaderText(null);
    dialog.getDialogPane().lookupButton(ButtonType.OK).setDisable(true);
    dialog.getEditor().textProperty().setValue(node.getValue().getName());


    dialog.getEditor().textProperty().addListener((observable, oldValue, newValue) -> {
        String value = newValue.trim();
        dialog.getDialogPane().lookupButton(ButtonType.OK)
                .setDisable(existingSiblingNodes.contains(value) || value.isEmpty());
    });

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

    if (result.isPresent()) {
        node.getValue().setName(result.get());
        try {
            saveAndRestoreService.updateNode(node.getValue());
        } catch (Exception e) {
            Alert alert = new Alert(AlertType.ERROR);
            alert.setTitle(Messages.errorActionFailed);
            alert.setHeaderText(e.getMessage());
            alert.showAndWait();
        }
    }
}
 
源代码8 项目: metastone   文件: DialogMediator.java
private void displayErrorMessage(String header, String message) {
	Alert alert = new Alert(AlertType.ERROR);
	alert.setTitle("Error");
	alert.setHeaderText(header);
	alert.setContentText(message);
	alert.showAndWait();
}
 
源代码9 项目: phoebus   文件: SaveAndRestoreController.java
private void createNewFolder(TreeItem<Node> parentTreeItem) {

        List<String> existingFolderNames =
                parentTreeItem.getChildren().stream()
                        .filter(item -> item.getValue().getNodeType().equals(NodeType.FOLDER))
                        .map(item -> item.getValue().getName())
                        .collect(Collectors.toList());

        TextInputDialog dialog = new TextInputDialog();
        dialog.setTitle(Messages.contextMenuNewFolder);
        dialog.setContentText(Messages.promptNewFolder);
        dialog.setHeaderText(null);
        dialog.getDialogPane().lookupButton(ButtonType.OK).setDisable(true);

        dialog.getEditor().textProperty().addListener((observable, oldValue, newValue) -> {
            String value = newValue.trim();
            dialog.getDialogPane().lookupButton(ButtonType.OK)
                    .setDisable(existingFolderNames.contains(value) || value.isEmpty());
        });

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

        if (result.isPresent()) {
            Node newFolderNode = Node.builder()
                    .name(result.get())
                    .build();
            try {
                Node newTreeNode = saveAndRestoreService
                        .createNode(parentTreeItem.getValue().getUniqueId(), newFolderNode);
                parentTreeItem.getChildren().add(createNode(newTreeNode));
                parentTreeItem.getChildren().sort((a, b) -> a.getValue().getName().compareTo(b.getValue().getName()));
                parentTreeItem.setExpanded(true);
            } catch (Exception e) {
                Alert alert = new Alert(AlertType.ERROR);
                alert.setTitle("Action failed");
                alert.setHeaderText(e.getMessage());
                alert.showAndWait();
            }
        }
    }
 
源代码10 项目: phoebus   文件: SaveAndRestoreController.java
/**
 * Renames a node through the service and its underlying data provider.
 * If there is a problem in the call to the remote JMasar service,
 * the user is shown a suitable error dialog and the name of the node is restored.
 * @param node The node being renamed
 */
private void renameNode(TreeItem<Node> node){

    List<String> existingSiblingNodes =
            node.getParent().getChildren().stream()
                    .filter(item -> item.getValue().getNodeType().equals(node.getValue().getNodeType()))
                    .map(item -> item.getValue().getName())
                    .collect(Collectors.toList());

    TextInputDialog dialog = new TextInputDialog();
    dialog.setTitle(Messages.promptRenameNodeTitle);
    dialog.setContentText(Messages.promptRenameNodeContent);
    dialog.setHeaderText(null);
    dialog.getDialogPane().lookupButton(ButtonType.OK).setDisable(true);
    dialog.getEditor().textProperty().setValue(node.getValue().getName());


    dialog.getEditor().textProperty().addListener((observable, oldValue, newValue) -> {
        String value = newValue.trim();
        dialog.getDialogPane().lookupButton(ButtonType.OK)
                .setDisable(existingSiblingNodes.contains(value) || value.isEmpty());
    });

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

    if (result.isPresent()) {
        node.getValue().setName(result.get());
        try {
            saveAndRestoreService.updateNode(node.getValue());
        } catch (Exception e) {
            Alert alert = new Alert(AlertType.ERROR);
            alert.setTitle(Messages.errorActionFailed);
            alert.setHeaderText(e.getMessage());
            alert.showAndWait();
        }
    }
}
 
源代码11 项目: CircuitSim   文件: CircuitSim.java
private void saveCircuitsInternal() {
	try {
		saveCircuits();
	} catch(Exception exc) {
		exc.printStackTrace();
		
		Alert alert = new Alert(AlertType.ERROR);
		alert.initOwner(stage);
		alert.initModality(Modality.WINDOW_MODAL);
		alert.setTitle("Error");
		alert.setHeaderText("Error saving circuit.");
		alert.setContentText("Error when saving the circuit: " + exc.getMessage());
		alert.showAndWait();
	}
}
 
源代码12 项目: Library-Assistant   文件: AlertMaker.java
public static void showErrorMessage(String title, String content) {
    Alert alert = new Alert(AlertType.ERROR);
    alert.setTitle("Error");
    alert.setHeaderText(title);
    alert.setContentText(content);
    styleAlert(alert);
    alert.showAndWait();
}
 
源代码13 项目: VocabHunter   文件: ErrorDialogue.java
public ErrorDialogue(final I18nManager i18nManager, final I18nKey titleKey, final Throwable e, final String... messages) {
    alert = new Alert(AlertType.ERROR);
    alert.setTitle(i18nManager.text(titleKey));
    alert.setHeaderText(headerText(messages));

    TextArea textArea = new TextArea(exceptionText(e));
    VBox expContent = new VBox();
    DialogPane dialoguePane = alert.getDialogPane();

    expContent.getChildren().setAll(new Label(i18nManager.text(ERROR_DETAILS)), textArea);
    dialoguePane.setExpandableContent(expContent);
    dialoguePane.expandedProperty().addListener(p -> Platform.runLater(this::resizeAlert));
    dialoguePane.setId("errorDialogue");
}
 
源代码14 项目: mzmine3   文件: DialogLoggerUtil.java
public static void showErrorDialog(String message, Exception e) {
  Alert alert = new Alert(AlertType.ERROR, message + " \n" + e.getMessage());
  alert.showAndWait();
}
 
源代码15 项目: ShootOFF   文件: Configuration.java
public Optional<Camera> registerIpCam(String cameraName, String cameraURL, Optional<String> username,
		Optional<String> password) {
	try {
		final URL url = new URL(cameraURL);
		final Camera cam = IpCamera.registerIpCamera(cameraName, url, username, password);
		ipcams.put(cameraName, url);

		if (username.isPresent() && password.isPresent()) {
			ipcamCredentials.put(cameraName, username.get() + "|" + password.get());
		}

		return Optional.of(cam);
	} catch (MalformedURLException | URISyntaxException ue) {
		final Alert ipcamURLAlert = new Alert(AlertType.ERROR);
		ipcamURLAlert.setTitle("Malformed URL");
		ipcamURLAlert.setHeaderText("IPCam URL is Malformed!");
		ipcamURLAlert.setResizable(true);
		ipcamURLAlert.setContentText("IPCam URL is not valid: \n\n" + ue.getMessage());
		ipcamURLAlert.showAndWait();
	} catch (final UnknownHostException uhe) {
		final Alert ipcamHostAlert = new Alert(AlertType.ERROR);
		ipcamHostAlert.setTitle("Unknown Host");
		ipcamHostAlert.setHeaderText("IPCam URL Unknown!");
		ipcamHostAlert.setResizable(true);
		ipcamHostAlert.setContentText("The IPCam at " + cameraURL
				+ " cannot be resolved. Ensure the URL is correct "
				+ "and that you are either connected to the internet or on the same network as the camera.");
		ipcamHostAlert.showAndWait();
	} catch (final TimeoutException te) {
		final Alert ipcamTimeoutAlert = new Alert(AlertType.ERROR);
		ipcamTimeoutAlert.setTitle("IPCam Timeout");
		ipcamTimeoutAlert.setHeaderText("Connection to IPCam Reached Timeout!");
		ipcamTimeoutAlert.setResizable(true);
		ipcamTimeoutAlert.setContentText("Could not communicate with the IP at " + cameraURL
				+ ". Please check the following:\n\n" + "-The IPCam URL is correct\n"
				+ "-You are connected to the Internet (for external cameras)\n"
				+ "-You are connected to the same network as the camera (for local cameras)");
		ipcamTimeoutAlert.showAndWait();
	}

	return Optional.empty();
}
 
@FXML
public void disconnect() {
	
	if( !connected.get() ) {
		if( logger.isWarnEnabled() ) {
			logger.warn("client not connected; skipping disconnect");
		}
		return;
	}
	
	if( logger.isDebugEnabled() ) {
		logger.debug("[DISCONNECT]");
	}
	
	Task<Void> task = new Task<Void>() {

		@Override
		protected Void call() throws Exception {
			
			updateMessage("Disconnecting");
			updateProgress(0.1d, 1.0d);
			
			channel.close().sync();					

			updateMessage("Closing group");
			updateProgress(0.5d, 1.0d);
			group.shutdownGracefully().sync();

			return null;
		}

		@Override
		protected void succeeded() {
			
			connected.set(false);
		}

		@Override
		protected void failed() {
			
			connected.set(false);

			Throwable t = getException();
			logger.error( "client disconnect error", t );
			Alert alert = new Alert(AlertType.ERROR);
			alert.setTitle("Client");
			alert.setHeaderText( t.getClass().getName() );
			alert.setContentText( t.getMessage() );
			alert.showAndWait();

		}
		
	};
	
	hboxStatus.visibleProperty().bind( task.runningProperty() );
	lblStatus.textProperty().bind( task.messageProperty() );
	piStatus.progressProperty().bind(task.progressProperty());

	new Thread(task).start();
}
 
private void handleNewSaveSet(TreeItem<Node> parentTreeItem){

        List<String> existingFolderNames =
                parentTreeItem.getChildren().stream()
                        .filter(item -> item.getValue().getNodeType().equals(NodeType.CONFIGURATION))
                        .map(item -> item.getValue().getName())
                        .collect(Collectors.toList());

        TextInputDialog dialog = new TextInputDialog();
        dialog.setTitle(Messages.promptNewSaveSetTitle);
        dialog.setContentText(Messages.promptNewSaveSetContent);
        dialog.setHeaderText(null);
        dialog.getDialogPane().lookupButton(ButtonType.OK).setDisable(true);

        dialog.getEditor().textProperty().addListener((observable, oldValue, newValue) -> {
            String value = newValue.trim();
            dialog.getDialogPane().lookupButton(ButtonType.OK)
                    .setDisable(existingFolderNames.contains(value) || value.isEmpty());
        });

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

        if (result.isPresent()) {
            Node newSateSetNode = Node.builder()
                    .nodeType(NodeType.CONFIGURATION)
                    .name(result.get())
                    .build();
            try {
                Node newTreeNode = saveAndRestoreService
                        .createNode(treeView.getSelectionModel().getSelectedItem().getValue().getUniqueId(), newSateSetNode);
                TreeItem<Node> newSaveSetNode = createNode(newTreeNode);
                parentTreeItem.getChildren().add(newSaveSetNode);
                parentTreeItem.getChildren().sort((a, b) -> a.getValue().getName().compareTo(b.getValue().getName()));
                parentTreeItem.setExpanded(true);
                nodeDoubleClicked(newSaveSetNode);
                treeView.getSelectionModel().select(treeView.getRow(newSaveSetNode));
            } catch (Exception e) {
                Alert alert = new Alert(AlertType.ERROR);
                alert.setTitle("Action failed");
                alert.setHeaderText(e.getMessage());
                alert.showAndWait();
            }
        }
    }
 
源代码18 项目: phoebus   文件: SaveAndRestoreController.java
private void handleNewSaveSet(TreeItem<Node> parentTreeItem){

        List<String> existingFolderNames =
                parentTreeItem.getChildren().stream()
                        .filter(item -> item.getValue().getNodeType().equals(NodeType.CONFIGURATION))
                        .map(item -> item.getValue().getName())
                        .collect(Collectors.toList());

        TextInputDialog dialog = new TextInputDialog();
        dialog.setTitle(Messages.promptNewSaveSetTitle);
        dialog.setContentText(Messages.promptNewSaveSetContent);
        dialog.setHeaderText(null);
        dialog.getDialogPane().lookupButton(ButtonType.OK).setDisable(true);

        dialog.getEditor().textProperty().addListener((observable, oldValue, newValue) -> {
            String value = newValue.trim();
            dialog.getDialogPane().lookupButton(ButtonType.OK)
                    .setDisable(existingFolderNames.contains(value) || value.isEmpty());
        });

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

        if (result.isPresent()) {
            Node newSateSetNode = Node.builder()
                    .nodeType(NodeType.CONFIGURATION)
                    .name(result.get())
                    .build();
            try {
                Node newTreeNode = saveAndRestoreService
                        .createNode(treeView.getSelectionModel().getSelectedItem().getValue().getUniqueId(), newSateSetNode);
                TreeItem<Node> newSaveSetNode = createNode(newTreeNode);
                parentTreeItem.getChildren().add(newSaveSetNode);
                parentTreeItem.getChildren().sort((a, b) -> a.getValue().getName().compareTo(b.getValue().getName()));
                parentTreeItem.setExpanded(true);
                nodeDoubleClicked(newSaveSetNode);
                treeView.getSelectionModel().select(treeView.getRow(newSaveSetNode));
            } catch (Exception e) {
                Alert alert = new Alert(AlertType.ERROR);
                alert.setTitle("Action failed");
                alert.setHeaderText(e.getMessage());
                alert.showAndWait();
            }
        }
    }
 
@FXML
public void send() {
	if( logger.isDebugEnabled() ) {
		logger.debug("[SEND]");
	}
	
	if( !connected.get() ) {
		if( logger.isWarnEnabled() ) {
			logger.warn("client not connected; skipping write");
		}
		return;
	}
	
	final String toSend = tfSend.getText();
	
	Task<Void> task = new Task<Void>() {

		@Override
		protected Void call() throws Exception {
			
			ChannelFuture f = channel.writeAndFlush( Unpooled.copiedBuffer(toSend, CharsetUtil.UTF_8) );
			f.sync();

			return null;
		}
		
		@Override
		protected void failed() {
			
			Throwable exc = getException();
			logger.error( "client send error", exc );
			Alert alert = new Alert(AlertType.ERROR);
			alert.setTitle("Client");
			alert.setHeaderText( exc.getClass().getName() );
			alert.setContentText( exc.getMessage() );
			alert.showAndWait();
			
			connected.set(false);
		}

	};
	
	hboxStatus.visibleProperty().bind( task.runningProperty() );
	lblStatus.textProperty().bind( task.messageProperty() );
	piStatus.progressProperty().bind(task.progressProperty());
	
	new Thread(task).start();
}
 
@FXML
public void disconnect() {
	
	if( !connected.get() ) {
		if( logger.isWarnEnabled() ) {
			logger.warn("client not connected; skipping disconnect");
		}
		return;
	}
	
	if( logger.isDebugEnabled() ) {
		logger.debug("[DISCONNECT]");
	}
	
	Task<Void> task = new Task<Void>() {

		@Override
		protected Void call() throws Exception {
			
			updateMessage("Disconnecting");
			updateProgress(0.1d, 1.0d);
			
			channel.close().sync();					

			updateMessage("Closing group");
			updateProgress(0.5d, 1.0d);
			group.shutdownGracefully().sync();

			return null;
		}

		@Override
		protected void succeeded() {
			
			connected.set(false);
		}

		@Override
		protected void failed() {
			
			connected.set(false);

			Throwable t = getException();
			logger.error( "client disconnect error", t );
			Alert alert = new Alert(AlertType.ERROR);
			alert.setTitle("Client");
			alert.setHeaderText( t.getClass().getName() );
			alert.setContentText( t.getMessage() );
			alert.showAndWait();

		}
		
	};
	
	hboxStatus.visibleProperty().bind( task.runningProperty() );
	lblStatus.textProperty().bind( task.messageProperty() );
	piStatus.progressProperty().bind(task.progressProperty());

	new Thread(task).start();
}