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, @NamedArg("contentText") String contentText,
        @NamedArg("buttonTypes") ButtonType... buttons) 

Source Link

Document

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

Usage

From source file:jlotoprint.model.Template.java

public static Model load(File templateFile, boolean showFeedback) {
    Model modelRef = null;/*ww w  .  ja  va  2s. c  om*/
    try {
        StringWriter writer = new StringWriter();
        IOUtils.copy(new FileInputStream(templateFile), writer, "UTF-8");
        Gson g = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
        modelRef = g.fromJson(writer.toString(), Model.class);
    } catch (Exception ex) {
        //Logger.getLogger(Template.class.getName()).log(Level.SEVERE, null, ex);
        if (showFeedback) {
            Alert dialog = new Alert(Alert.AlertType.ERROR, "The template you are trying to load is invalid.",
                    ButtonType.OK);
            dialog.initModality(Modality.APPLICATION_MODAL);
            dialog.showAndWait();
        }
    }
    return modelRef;
}

From source file:spdxedit.license.FileLicenseEditor.java

public static void extractLicenseFromFile(SpdxFile file, SpdxDocumentContainer container) {

    Dialog dialog = new Dialog();
    dialog.setTitle(Main.APP_TITLE);// w  w w.j av a  2  s .c o m
    dialog.setHeaderText("Extract license");

    ((Stage) dialog.getDialogPane().getScene().getWindow()).getIcons()
            .addAll(UiUtils.ICON_IMAGE_VIEW.getImage());

    dialog.getDialogPane().getButtonTypes().addAll(ButtonType.CANCEL, ButtonType.OK);

    String licenseName = "";
    String licenseText = null;
    String licenseId = "";
    //TODO: Add support for multiple extracted licenses.
    if (file.getLicenseInfoFromFiles() != null && file.getLicenseInfoFromFiles().length > 0) {
        Optional<AnyLicenseInfo> foundExtractedLicense = Arrays.stream(file.getLicenseInfoFromFiles())
                .filter(license -> license instanceof ExtractedLicenseInfo).findFirst();
        if (foundExtractedLicense.isPresent()) {
            licenseName = ((ExtractedLicenseInfo) foundExtractedLicense.get()).getName();
            licenseText = ((ExtractedLicenseInfo) foundExtractedLicense.get()).getExtractedText();
            licenseId = ((ExtractedLicenseInfo) foundExtractedLicense.get()).getLicenseId();

        }
    }

    LicenseExtractControl licenseExtractControl = new LicenseExtractControl(licenseName, licenseText,
            licenseId);

    dialog.getDialogPane().setContent(licenseExtractControl.getUi());
    Optional<ButtonType> result = dialog.showAndWait();

    licenseName = licenseExtractControl.getLicenseName();
    licenseText = licenseExtractControl.getLicenseText();
    licenseId = licenseExtractControl.getLicenseId();

    //No selection
    if (!result.isPresent() || result.get() == ButtonType.CANCEL) {
        return;
    }
    //Omitted data
    if (StringUtils.isBlank(licenseName)) {
        new Alert(Alert.AlertType.ERROR, "License name cannot be blank. Use \"NOASSERTION\" instead",
                ButtonType.OK).showAndWait();
        return;
    }
    if (StringUtils.isBlank(licenseText)) {
        new Alert(Alert.AlertType.ERROR, "License text cannot be blank.", ButtonType.OK).showAndWait();
        return;
    }
    if (StringUtils.isBlank(licenseId)) {
        new Alert(Alert.AlertType.ERROR, "License ID cannot be blank.", ButtonType.OK).showAndWait();
        return;
    }
    //License already extracted
    if (SpdxLogic.findExtractedLicenseByNameAndText(container, licenseName, licenseText).isPresent()) {
        new Alert(Alert.AlertType.WARNING,
                "License " + licenseName + " with the same text has already been extracted.", ButtonType.OK)
                        .showAndWait();
        return;
    }
    //License with ID already exists
    if (SpdxLogic.findExtractedLicenseInfoById(container, licenseId).isPresent()) {
        new Alert(Alert.AlertType.WARNING, "License with ID " + licenseId + " already exists.", ButtonType.OK)
                .showAndWait();
        return;
    }

    SpdxLogic.addExtractedLicenseFromFile(file, container, licenseId, licenseName, licenseText);

}

From source file:topt.FXMLDocumentController.java

@FXML
private void handleButtonAddElement(ActionEvent event) {
    try {//from   w w w.  ja  v a2s  .c  o  m
        if (elementsCBox.getValue() != null && !elementsCBox.getValue().toString().isEmpty()) {
            int numberOfEl = Integer.parseInt(elementsNr.getText());
            double standardDevDouble = Double.parseDouble(standardDev.getText());
            double expectedValueDouble = Double.parseDouble(expectedValue.getText());

            data.add(data.size(), new RowData(elementsCBox.getValue().toString(), numberOfEl, standardDevDouble,
                    expectedValueDouble));

            addedElementList.setItems(data);
        } else {
            Alert alert = new Alert(Alert.AlertType.ERROR, "Wybierz element", ButtonType.YES);
            alert.showAndWait();
        }
    } catch (NumberFormatException nfe) {
        Alert alert = new Alert(Alert.AlertType.ERROR, "Niepoprawny format danych (liczb)", ButtonType.YES);
        alert.showAndWait();
    }
}

From source file:topt.FXMLDocumentController.java

@FXML
private void handleButtonCompute(ActionEvent event) {
    System.out.println("Compute!");
    double sum = 0;
    double sumInSquare = 0;
    double expectedError = 0;
    for (RowData element : addedElementList.getItems()) {
        sum += element.getExpectedValue() * element.getNrOfElements();
        sumInSquare += Math.pow(element.getStandardDev(), 2) * element.getNrOfElements();
    }//from  w  ww.  ja  va  2  s .c om

    if (!tfError.getText().isEmpty())
        expectedError = Double.parseDouble(tfError.getText()) / 100;
    else {
        Alert alert = new Alert(Alert.AlertType.ERROR, "Prosz poda warto dopuszczalnegobdu [%]",
                ButtonType.YES);
        alert.showAndWait();
        return;
    }

    double nrOfStDev = computeNrStDev(sum, Math.sqrt(sumInSquare), expectedError);
    double attenuationMax = sum + nrOfStDev * Math.sqrt(sumInSquare);
    double attenuationMin = sum - nrOfStDev * Math.sqrt(sumInSquare);
    attenuationMax = roundResult(attenuationMax);
    attenuationMin = roundResult(attenuationMin);

    result.setText("Zakres tumienia toru optycznego mieci si w zakresie od: " + attenuationMin
            + "[dB] do " + attenuationMax + "[dB]");

}

From source file:uk.ac.bris.cs.scotlandyard.ui.controller.BaseGame.java

BaseGame(ResourceManager manager, Stage stage) {
    this.resourceManager = manager;
    this.stage = stage;
    Controller.bind(this);

    // initialise all controllers
    travelLog = new TravelLog(resourceManager, config);
    ticketsCounter = new TicketsCounter(resourceManager, config);
    notifications = new Notifications(resourceManager, config);
    status = new Status(resourceManager, config);
    board = new Board(resourceManager, notifications, config);

    Rectangle clip = new Rectangle();
    clip.widthProperty().bind(gamePane.widthProperty());
    clip.heightProperty().bind(gamePane.heightProperty());
    gamePane.setClip(clip);//w w w . j  a v  a  2 s .  co  m

    // system menu
    menu.setUseSystemMenuBar(true);

    // add all views
    mapPane.getChildren().add(board.root());
    roundsPane.getChildren().add(travelLog.root());
    playersPane.getChildren().add(ticketsCounter.root());
    notificationPane.getChildren().add(notifications.root());
    statusPane.getChildren().add(status.root());

    close.setOnAction(e -> stage.close());
    debug.setOnAction(evt -> {
        try {
            Debug.showDebugger(stage);
        } catch (Exception e) {
            Utils.handleFatalException(e);
        }
    });
    about.setOnAction(e -> {
        Alert alert = new Alert(AlertType.INFORMATION,
                "ScotlandYard is part of the CW-MODEL coursework prepared for University of Bristol course COMS100001",
                ButtonType.OK);
        ImageView logo = new ImageView(resourceManager.getImage(ImageResource.UOB_LOGO));
        logo.setPreserveRatio(true);
        logo.setSmooth(true);
        logo.setFitHeight(100);
        alert.setGraphic(logo);
        alert.setTitle("About ScotlandYard");
        alert.setHeaderText("ScotlandYard v0.1");
        alert.show();
    });

    findNode.setOnAction(e -> {
        Stage s = new Stage();
        s.setTitle("Find node");
        s.setScene(new Scene(new FindNode(config, s, resourceManager).root()));
        s.show();
    });
    manual.setOnAction(e -> {
        Stage s = new Stage();
        s.setTitle("Manual");
        s.setScene(new Scene(new Manual(s).root()));
        s.show();
    });

    license.setOnAction(e -> {
        Stage s = new Stage();
        s.setTitle("License");
        s.setScene(new Scene(new License(s).root()));
        s.show();
    });

    // bind all menu values
    resetViewport.setOnAction(e -> {
        board.resetViewport();
    });

    setAndBind(travelLog.root().visibleProperty(), travelLogToggle.selectedProperty());
    setAndBind(ticketsCounter.root().visibleProperty(), ticketToggle.selectedProperty());
    setAndBind(config.scrollPanProperty(), scrollToggle.selectedProperty());
    setAndBind(config.historyProperty(), historyToggle.selectedProperty());
    setAndBind(config.focusPlayerProperty(), focusToggle.selectedProperty());

    if (SystemUtils.IS_OS_WINDOWS)
        config.scrollPanProperty().setValue(false);

}

From source file:jlotoprint.MainViewController.java

public static void showExceptionAlert(String message, String details) {
    Alert alert = new Alert(Alert.AlertType.ERROR, message, ButtonType.OK);
    alert.initModality(Modality.APPLICATION_MODAL);
    alert.initOwner(JLotoPrint.stage.getScene().getWindow());
    TextArea textArea = new TextArea(details);
    textArea.setEditable(false);/*  ww  w .  j  a  v  a2  s .c  o m*/
    textArea.setWrapText(true);

    GridPane grid = new GridPane();
    grid.setPadding(new Insets(10, 10, 0, 10));
    grid.add(textArea, 0, 0);

    //set content
    alert.getDialogPane().setExpandableContent(grid);
    alert.showAndWait();
}

From source file:spdxedit.license.LicenseEditControl.java

@FXML
void initialize() {
    assert rdoNone != null : "fx:id=\"rdoNone\" was not injected: check your FXML file 'LicenseEditControl.fxml'.";
    assert rdoNoAssert != null : "fx:id=\"rdoNoAssert\" was not injected: check your FXML file 'LicenseEditControl.fxml'.";
    assert rdoStandard != null : "fx:id=\"rdoStandard\" was not injected: check your FXML file 'LicenseEditControl.fxml'.";
    assert chcListedLicense != null : "fx:id=\"chcListedLicense\" was not injected: check your FXML file 'LicenseEditControl.fxml'.";
    assert chcExtractedLicenses != null : "fx:id=\"chcExtractedLicenses\" was not injected: check your FXML file 'LicenseEditControl.fxml'.";
    assert rdoExtracted != null : "fx:id=\"rdoExtracted\" was not injected: check your FXML file 'LicenseEditControl.fxml'.";
    assert btnNewFromFile != null : "fx:id=\"btnNewFromFile\" was not injected: check your FXML file 'LicenseEditControl.fxml'.";

    //Make radio buttons mutually exclusive

    ToggleGroup licenseTypeGroup = new ToggleGroup();
    rdoExtracted.setToggleGroup(licenseTypeGroup);
    rdoStandard.setToggleGroup(licenseTypeGroup);
    rdoNone.setToggleGroup(licenseTypeGroup);
    rdoNoAssert.setToggleGroup(licenseTypeGroup);

    //Choice boxes should disable when their respective radio buttons are untoggled.
    rdoStandard.selectedProperty()//w  w w .  j  a va  2  s  . co  m
            .addListener((observable, oldValue, newValue) -> chcListedLicense.setDisable(!newValue));
    rdoExtracted.selectedProperty()
            .addListener((observable, oldValue, newValue) -> chcExtractedLicenses.setDisable(!newValue));

    chcListedLicense.getItems()
            .addAll(Arrays.stream(ListedLicenses.getListedLicenses().getSpdxListedLicenseIds()).sorted()
                    .collect(Collectors.toList()));
    chcExtractedLicenses.setConverter(new StringConverter<ExtractedLicenseInfo>() {
        @Override
        public String toString(ExtractedLicenseInfo object) {
            return object.getName();
        }

        @Override
        public ExtractedLicenseInfo fromString(String string) {
            return Arrays.stream(documentContainer.getExtractedLicenseInfos())
                    .filter(license -> StringUtils.equals(license.getName(), string)).findAny().get();
        }
    });

    btnNewFromFile.setVisible(showExtractLicenseButton);

    //Apply the initial value
    if (this.initialValue instanceof SpdxListedLicense) {
        chcListedLicense.setValue(((SpdxListedLicense) initialValue).getLicenseId());
        chcListedLicense.setDisable(false);
        rdoStandard.selectedProperty().setValue(true);
    } else if (initialValue instanceof ExtractedLicenseInfo) {
        refreshExtractedLicenses();
        chcExtractedLicenses.setValue((ExtractedLicenseInfo) initialValue);
        chcExtractedLicenses.setDisable(false);
        rdoExtracted.selectedProperty().setValue(true);
    } else if (initialValue instanceof SpdxNoAssertionLicense) {
        rdoNoAssert.selectedProperty().setValue(true);
    } else if (initialValue instanceof SpdxNoneLicense) {
        rdoNone.selectedProperty().setValue(true);
    } else {
        new Alert(Alert.AlertType.ERROR,
                "Unsupported license type: " + initialValue.getClass().getSimpleName() + ".", ButtonType.OK);
    }

    //Listen for change events

    licenseTypeGroup.selectedToggleProperty().addListener((observable1, oldValue1, newValue1) -> {
        hanldLicenseChangeEvent();
    });
    chcExtractedLicenses.valueProperty().addListener((observable, oldValue, newValue) -> {
        hanldLicenseChangeEvent();
    });
    chcListedLicense.valueProperty().addListener((observable, oldValue, newValue) -> {
        hanldLicenseChangeEvent();
    });
}

From source file:com.exalttech.trex.util.Util.java

/**
 * Generate and return alert message window
 *
 * @param type//from w  w  w  .ja  v a2 s. c  o m
 * @return
 */
public static Alert getAlert(Alert.AlertType type) {
    Alert alert = new Alert(type, "", ButtonType.OK);
    alert.setHeaderText(null);
    alert.setX(TrexApp.getPrimaryStage().getX() + ALERT_X_POSITION);
    alert.setY(TrexApp.getPrimaryStage().getY() + ALERT_Y_POSITION);
    return alert;
}

From source file:spdxedit.license.LicenseEditControl.java

public AnyLicenseInfo getValue() {
    AnyLicenseInfo result = null;//  w ww  . ja v a2  s.c  om
    if (rdoNoAssert.isSelected()) {
        result = new SpdxNoAssertionLicense();
    } else if (rdoNone.isSelected()) {
        result = new SpdxNoneLicense();
    } else if (rdoStandard.isSelected()) {
        try {
            result = ListedLicenses.getListedLicenses().getListedLicenseById(chcListedLicense.getValue());
        } catch (InvalidSPDXAnalysisException e) {
            throw new RuntimeException(e);
        }
    } else if (rdoExtracted.isSelected()) {
        result = chcExtractedLicenses.getValue();
    }
    if (result == null) {
        new Alert(Alert.AlertType.ERROR, "Unable to extract selected license", ButtonType.OK);
    }
    return result;
}

From source file:de.perdoctus.ebikeconnect.gui.ActivitiesOverviewController.java

private void handleError(final String message, final Throwable exception) {
    logger.error(exception.getMessage(), exception);
    final Alert alert = new Alert(Alert.AlertType.ERROR, exception.getMessage(), ButtonType.OK);
    alert.setTitle(message);/* w ww .java 2  s .c o  m*/
    alert.setHeaderText(rb.getString("error-header"));
    alert.show();
}