Example usage for javafx.scene.control Alert Alert

List of usage examples for javafx.scene.control Alert Alert

Introduction

In this page you can find the example usage for javafx.scene.control Alert Alert.

Prototype

public Alert(@NamedArg("alertType") AlertType alertType) 

Source Link

Document

Creates an alert with the given AlertType (refer to the AlertType documentation for clarification over which one is most appropriate).

Usage

From source file:be.makercafe.apps.makerbench.editors.GCodeEditor.java

private void handleExportAsPngFile(ActionEvent e) {

    if (csgObject == null) {
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Oeps an error occured");
        alert.setHeaderText("Cannot export PNG. There is no geometry !");
        alert.setContentText("Please verify that your code generates a valid CSG object.");
        alert.showAndWait();/*w  w w. j a v a2  s . co m*/
        return;
    }

    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export PNG File");
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Image files (*.png)", "*.png"));

    File f = fileChooser.showSaveDialog(null);

    if (f == null) {
        return;
    }

    String fName = f.getAbsolutePath();

    if (!fName.toLowerCase().endsWith(".png")) {
        fName += ".png";
    }

    int snWidth = 1024;
    int snHeight = 1024;

    double realWidth = viewGroup.getBoundsInLocal().getWidth();
    double realHeight = viewGroup.getBoundsInLocal().getHeight();

    double scaleX = snWidth / realWidth;
    double scaleY = snHeight / realHeight;

    double scale = Math.min(scaleX, scaleY);

    PerspectiveCamera snCam = new PerspectiveCamera(false);
    snCam.setTranslateZ(-200);

    SnapshotParameters snapshotParameters = new SnapshotParameters();
    snapshotParameters.setTransform(new Scale(scale, scale));
    snapshotParameters.setCamera(snCam);
    snapshotParameters.setDepthBuffer(true);
    snapshotParameters.setFill(Color.TRANSPARENT);

    WritableImage snapshot = new WritableImage(snWidth, (int) (realHeight * scale));

    viewGroup.snapshot(snapshotParameters, snapshot);

    try {
        ImageIO.write(SwingFXUtils.fromFXImage(snapshot, null), "png", new File(fName));
    } catch (IOException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Oeps an error occured");
        alert.setHeaderText("Cannot export PNG. There went something wrong writing the file.");
        alert.setContentText(
                "Please verify that your file is not read only, is not locked by other user or program, you have enough diskspace.");
        alert.showAndWait();
    }
}

From source file:Pages.LandingPage.java

public void validateLogin(Stage theStage) {
    if (shouldTrainBayes) {
        trainBayes();/*from  w  w w. j a  v a 2 s.com*/
    }

    if (shouldTestBayes) {
        testBayes();
    }

    if (shouldLoadBooks) {
        loadBooks(theStage);
    }

    if (user.getText().length() > 3 & pass.getText().length() > 4) {
        CUser uss = connection.consultUser(user.getText());
        if (uss != null && pass.getText().equals(uss.getUser_password())) { //Entering here means that the user was succesfully logged
            // try {
            CStaticInfo.loggedUser = uss;
            //ANN a = new ANN();
            //a.getRecommendations(2);
            EditProfile mainPage = new EditProfile();
            Stage loginStage = mainPage.getStage();
            loginStage.show();
            thisStage.close();
            //} catch (SQLException ex) {
            //  Logger.getLogger(BookNext.class.getName()).log(Level.SEVERE, null, ex);
            //}
        } else {
            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            alert.setTitle("Error");
            alert.setHeaderText("Incorrect Password or UserName");
            alert.setContentText("Please enter a existing user name with correct password");
            alert.showAndWait();
        }
    } else {
        if (user.getText().length() < 4) {
            user.validate();
        } else {
            if (pass.getText().length() < 4) {
                pass.validate();
            } else {

                Alert alert = new Alert(Alert.AlertType.INFORMATION);

                alert.setTitle("Error");
                alert.setHeaderText("User form not complete");
                alert.setContentText("Please complete user form");
                alert.showAndWait();
            }
        }
    }
}

From source file:ExcelFx.FXMLDocumentController.java

@Override
public void initialize(URL url, ResourceBundle rb) {

    this.Print.setDisable(true);

    footer.setItems(names);//  w w w .  j  a va  2 s . com
    JsonWrite jsw = new JsonWrite();
    File universityFile = new File("university.json");
    File collegeFile = new File("college.json");
    //File codesFile = new File("codes.json");

    if ((universityFile.exists()) && (collegeFile.exists()) /*&& (codesFile.exists())*/) {
        try {
            this.universityJson.jsonRead("university.json");
            this.collegeJson.jsonRead("college.json");
            //this.codesJson.jsonRead("codes.json");
            this.jsonXLSXData.setAll(universityJson, collegeJson/*, codesJson*/);
        } catch (IOException | ParseException ex) {
            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            alert.setTitle("");
            alert.setHeaderText(" ? ? ");
            alert.setContentText(ex.toString());
            alert.showAndWait();
            Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
        }

    } else {
        try {
            FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("FileOpenFXML.fxml"));
            this.fileOpenParent = (Parent) fxmlLoader.load();
            Stage stage = new Stage();
            stage.initModality(Modality.APPLICATION_MODAL);
            stage.initStyle(StageStyle.DECORATED);
            stage.setTitle(" ");
            stage.setScene(new Scene(this.fileOpenParent));

            stage.showAndWait();
        } catch (Exception e) {
            System.err.println(e);

        }

        this.jsonXLSXData.setAll(universityJson, collegeJson/*, codesJson*/);
    }

}

From source file:org.cirdles.ambapo.userInterface.AmbapoUIController.java

@FXML
private void openConvertedFileClicked(MouseEvent event) {
    try {/*  www. ja v  a 2 s.c o  m*/
        // TODO add your handling code here:
        Desktop.getDesktop().open(convertedFile);
    } catch (IOException ex) {
        Logger.getLogger(AmbapoUIController.class.getName()).log(Level.SEVERE, null, ex);

        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Error");
        alert.setHeaderText("Unable to open file.");
        alert.setContentText("Check if you have a valid file name.");
        alert.showAndWait();
    }
}

From source file:se.trixon.filebydate.ui.MainApp.java

private void profileRemove(Profile profile) {
    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.initOwner(mStage);/*ww w . j ava2  s.c o m*/
    alert.setTitle(Dict.Dialog.TITLE_PROFILE_REMOVE.toString() + "?");
    String message = String.format(Dict.Dialog.MESSAGE_PROFILE_REMOVE.toString(), profile.getName());
    alert.setHeaderText(message);

    ButtonType removeButtonType = new ButtonType(Dict.REMOVE.toString(), ButtonData.OK_DONE);
    ButtonType cancelButtonType = new ButtonType(Dict.CANCEL.toString(), ButtonData.CANCEL_CLOSE);
    alert.getButtonTypes().setAll(removeButtonType, cancelButtonType);

    Optional<ButtonType> result = FxHelper.showAndWait(alert, mStage);
    if (result.get() == removeButtonType) {
        mProfiles.remove(profile);
        profilesSave();
        populateProfiles(null);
        mLogAction.setDisabled(mItems.isEmpty() || mLastRunProfile == null);
    }
}

From source file:com.helegris.szorengeteg.ui.forms.TopicFormView.java

private void alertMissingData() {
    Alert alert = new Alert(Alert.AlertType.WARNING);
    alert.setTitle(Messages.msg("alert.missing_data"));
    alert.setHeaderText(Messages.msg("alert.missing_word_or_description"));
    alert.initModality(Modality.APPLICATION_MODAL);

    alert.showAndWait();/* ww  w  .  jav  a  2  s  .  c om*/
}

From source file:be.makercafe.apps.makerbench.Main.java

/**
 * Creates the menubar//  www .j  ava2  s . c  om
 *
 * @return
 */
private MenuBar createMenuBar() {
    MenuBar bar = new MenuBar();
    Menu projectMenu = new Menu("Project");
    MenuItem openProject = new MenuItem("Open...");
    openProject.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            directoryChooser.setTitle("Please choose a project folder");
            File file = directoryChooser.showDialog(stage);

            viewer.setRoot(setRootFolder(file));

        }
    });
    Menu newProject = new Menu("New");

    MenuItem newFolder = new MenuItem("Folder...");
    newFolder.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            TextInputDialog dialog = new TextInputDialog("my_project_folder");
            dialog.setTitle("New folder");
            dialog.setHeaderText("Create a new folder");
            dialog.setContentText("Folder name:");
            Optional<String> result = dialog.showAndWait();
            if (result.isPresent()) {
                String homeDir = System.getProperty("user.home");

                System.out.println("Folder name: " + result.get());
                System.out.println("User home: " + homeDir);
            }
        }
    });
    newProject.getItems().add(newFolder);

    MenuItem importProject = new MenuItem("Import");
    importProject.setAccelerator(new KeyCodeCombination(KeyCode.I, KeyCombination.CONTROL_DOWN));
    importProject.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            System.out.println("Import");

        }
    });
    MenuItem deleteProject = new MenuItem("Delete");
    deleteProject.setAccelerator(new KeyCodeCombination(KeyCode.D, KeyCombination.CONTROL_DOWN));
    deleteProject.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            System.out.println("Delete");

        }
    });
    projectMenu.getItems().addAll(openProject, newProject, importProject, deleteProject);

    Menu helpMenu = new Menu("Help");

    MenuItem aboutItem = new MenuItem("About");
    aboutItem.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            Alert alert = new Alert(AlertType.INFORMATION);
            alert.setTitle("Information Dialog");
            alert.setHeaderText("About makerbench");
            alert.setContentText(
                    "Makerbench is an open source IDE for designing and manufacturing objects and code.\nWritten by Luc De pauw\n\nUses opensource libraries from the next projects:\n-RichtextFX by Tomas Mikula\n-JCSG by Michael Hoffer\n-ControlsFX by FXexperience.com");
            alert.showAndWait();
        }
    });

    helpMenu.getItems().add(aboutItem);
    bar.getMenus().addAll(projectMenu, helpMenu);
    return bar;
}

From source file:Pages.LandingPage.java

public void validateNewUser(Stage theStage) throws SQLException {

    if (new_user.getText().length() > 3 & new_pass.getText().length() > 5 & new_name.getText().length() > 4
            & country.getLength() > 4) {
        CUser uss = connection.consultUser(new_user.getText());

        if (uss != null) { //If uss !=null means that the username is already registered

            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            alert.setTitle("Error");
            alert.setHeaderText("User Already Exist");
            alert.setContentText("Please select another user");
            alert.showAndWait();/*ww w  .java2s.  c  o  m*/

        } else {
            String strDate = dateToString(date.getValue());
            uss = new CUser(new_user.getText(), new_name.getText(), new_pass.getText(), strDate, imageURL,
                    country.getText());
            boolean validate = connection.addNewUser(uss.gerUsername(), uss.getUser_fullName(),
                    uss.getUser_birthday(), uss.getUser_password(), uss.getUser_image(), uss.getUser_country());
            validate = true;
            if (validate = true) //if this is true, means that all the fields are correct.
            {
                CStaticInfo.loggedUser = uss;
                CStaticInfo.usersBooks = new ArrayList(); //New user, empty book list 
                bookSelection book = new bookSelection();
                Stage loginStage = book.getStage();
                loginStage.show();
                theStage.getScene().getWindow().hide();

            } else {
                if (new_user.getText().length() < 4) {
                    new_user.validate();
                } else {
                    if (new_pass.getText().length() < 4) {
                        new_pass.validate();
                    } else {
                        Alert alert = new Alert(Alert.AlertType.INFORMATION);
                        alert.setTitle("Error");
                        alert.setHeaderText("User form not complete");
                        alert.setContentText("Please complete user form");
                        alert.showAndWait();
                    }
                }
            }
        }
    }
}

From source file:se.trixon.filebydate.ui.MainApp.java

private void profileRun(Profile profile) {
    String title = String.format(Dict.Dialog.TITLE_PROFILE_RUN.toString(), profile.getName());
    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.initOwner(mStage);//from  w  w w  .  j  a v a  2 s.c  o m

    alert.setTitle(title);
    alert.setGraphic(null);
    alert.setHeaderText(null);

    PreviewPanel previewPanel = new PreviewPanel();
    previewPanel.load(profile);
    final DialogPane dialogPane = alert.getDialogPane();
    dialogPane.setContent(previewPanel);

    ButtonType runButtonType = new ButtonType(Dict.RUN.toString());
    ButtonType dryRunButtonType = new ButtonType(Dict.DRY_RUN.toString(), ButtonData.OK_DONE);
    ButtonType cancelButtonType = new ButtonType(Dict.CANCEL.toString(), ButtonData.CANCEL_CLOSE);

    alert.getButtonTypes().setAll(runButtonType, dryRunButtonType, cancelButtonType);
    Optional<ButtonType> result = alert.showAndWait();
    if (result.get() != cancelButtonType) {
        boolean dryRun = result.get() == dryRunButtonType;
        profile.setDryRun(dryRun);
        mProgressPanel.clear();
        mRoot.setCenter(mProgressPanel);
        mIndicator.setProfile(profile);

        if (profile.isValid()) {
            mLastRunProfile = profile;
            mOperationThread = new Thread(() -> {
                Operation operation = new Operation(mOperationListener, profile);
                operation.start();
            });
            mOperationThread.setName("Operation");
            mOperationThread.start();
        } else {
            mProgressPanel.out(profile.toDebugString());
            mProgressPanel.out(profile.getValidationError());
            mProgressPanel.out(Dict.ABORTING.toString());
        }
    }
}

From source file:ui.main.MainViewController.java

private void sendFile() {
    if (!contactsManager.getAvailabilityforSharing(currentChat.getParticipant())) {
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle("Attention!");
        alert.setHeaderText("The user is not available!");
        alert.setContentText("The file receiving user should be available online to receive the file.");
        alert.showAndWait();/*from   w  w w. j  av a 2s .com*/
        return;
    }
    ItemType type = contactsManager.getUserType(currentChat.getParticipant());

    if (type.equals(ItemType.none)) {
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle("Attention!");
        alert.setHeaderText("This user is not available for you!");
        alert.setContentText(
                "The user has not accepted the Friend Request." + " The user is not available for you.");
        alert.showAndWait();
        return;
    } else if (type.equals(ItemType.from)) {
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle("Attention!");
        alert.setHeaderText("An unaccepted user!");
        alert.setContentText("You have not accepted the Friend Request."
                + " You can not send any messages until you accept the friend request.");
        alert.showAndWait();
        return;
    } else if (type.equals(ItemType.to)) {
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle("Attention!");
        alert.setHeaderText("The user has not accepted!");
        alert.setContentText("The user has not accepted the Friend Request."
                + " You can not send any messages until the user accepts the friend request.");
        alert.showAndWait();
        return;
    }
    if (!contactsManager.getAvailabilityforSharing(currentChat.getParticipant())) {
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle("Attention!");
        alert.setHeaderText("The user is not available!");
        alert.setContentText("The file receiving user should be available online to receive the file.");
        alert.showAndWait();
        return;
    }
    FileChooser fc = new FileChooser();
    File file = fc.showOpenDialog(presence.getScene().getWindow());
    if (file == null) {
        return;
    }
    Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                fileManager.sendFile(file, currentChat.getParticipant());
                if (history.isSelected()) {
                    Timestamp time = new Timestamp(System.currentTimeMillis());
                    DBSingleChat.saveFileMessage(currentChat.getParticipant(), false, file.getPath(), time);
                }

                paintSentFile(currentChat, file.getAbsolutePath(), dtfT.print(DateTime.now()));
                Task tt = new Task() {
                    @Override
                    protected Object call() throws Exception {
                        Thread.sleep(500);
                        return new Object();
                    }
                };

                tt.setOnSucceeded(value -> scrollPane.setVvalue(scrollPane.getHmax()));

                Thread thread1 = new Thread(tt);
                thread1.start();
            } catch (FileNotFoundException ex) {
                Alert alert = new Alert(Alert.AlertType.ERROR);
                alert.setTitle("IMP");
                alert.setHeaderText("File is not Found!");
                alert.setContentText("File you selected does not exist.");
                alert.showAndWait();
                return;
            }
        }
    });
    t.start();
}