Example usage for javafx.concurrent Task titleProperty

List of usage examples for javafx.concurrent Task titleProperty

Introduction

In this page you can find the example usage for javafx.concurrent Task titleProperty.

Prototype

@Override
    public final ReadOnlyStringProperty titleProperty() 

Source Link

Usage

From source file:snpviewer.SnpViewer.java

public void saveRegion(final String chromosome, final double startCoordinate, final double endCoordinate) {
    final Task<RegionSummary> saveSelectionTask = new Task<RegionSummary>() {
        @Override/*from  ww  w. java  2 s . co m*/
        protected RegionSummary call() throws Exception {
            try {
                updateProgress(-1, -1);
                updateTitle("Finding flanking SNPs");
                updateMessage("Searching for nearest SNP in all files...");

                /* read SnpFiles to find closest SNPs - use binary search
                 * to find nearby SNP and refine to closest
                 */
                List<SnpFile.SnpLine> startAndEndSnps = searchCoordinate(chromosome, (int) startCoordinate,
                        (int) endCoordinate);
                if (startAndEndSnps == null) {
                    System.out.println("Start and End SNPS ARE NULL!");
                    //DISPLAY ERROR HERE?
                    return null;
                }
                RegionSummary region = new RegionSummary(chromosome, startAndEndSnps.get(0).getPosition(),
                        startAndEndSnps.get(1).getPosition(), 0, 0, startAndEndSnps.get(0).getId(),
                        startAndEndSnps.get(1).getId());
                return region;

            } catch (NumberFormatException ex) {
                Dialogs.showErrorDialog(null,
                        "Can't display flanking SNP IDs"
                                + " - missing required componant!\n\nPlease report this error.",
                        "Error!", "SNP Viewer", ex);
            }
            return null;
        }
    };
    setProgressMode(true);
    progressBar.progressProperty().bind(saveSelectionTask.progressProperty());
    progressMessage.textProperty().unbind();
    progressMessage.textProperty().bind(saveSelectionTask.messageProperty());
    progressTitle.textProperty().unbind();
    progressTitle.textProperty().bind(saveSelectionTask.titleProperty());
    saveSelectionTask.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
        @Override
        public void handle(WorkerStateEvent e) {
            setProgressMode(false);
            RegionSummary result = (RegionSummary) e.getSource().getValue();
            savedRegions.add(result);
            RegionSummary sorter = new RegionSummary();
            sorter.mergeRegionsByPosition(savedRegions);
            saveProject();
            clearDragSelectRectangle();
            savedRegionsDisplay.clear();
            savedRegionsReference.clear();
            drawSavedRegions(
                    (String) chromosomeBoxList[chromosomeSelector.getSelectionModel().getSelectedIndex()]);
            progressBar.progressProperty().unbind();
            progressBar.progressProperty().set(0);
            progressTitle.textProperty().unbind();
            progressMessage.textProperty().unbind();
            progressTitle.setText("");
            progressMessage.setText("");
        }

    });
    saveSelectionTask.setOnFailed(new EventHandler<WorkerStateEvent>() {
        @Override
        public void handle(WorkerStateEvent e) {
            setProgressMode(false);
            progressBar.progressProperty().unbind();
            progressBar.progressProperty().set(0);
            progressTitle.textProperty().unbind();
            progressMessage.textProperty().unbind();
            progressTitle.setText("");
            progressMessage.setText("");
            Dialogs.showErrorDialog(null, "Error finding flanking SNPs\n", "Save Region error", "SNP Viewer",
                    saveSelectionTask.getException());

        }

    });
    saveSelectionTask.setOnCancelled(new EventHandler<WorkerStateEvent>() {
        @Override
        public void handle(WorkerStateEvent e) {
            progressMessage.setText("Region write cancelled");
            setProgressMode(false);
            progressBar.progressProperty().unbind();
            progressBar.progressProperty().set(0);
            progressTitle.textProperty().unbind();
            progressMessage.textProperty().unbind();
            progressTitle.setText("");
            progressMessage.setText("");
            Dialogs.showErrorDialog(null, "User cancelled region save.", "Save Region", "SNP Viewer",
                    saveSelectionTask.getException());
        }

    });
    cancelButton.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent actionEvent) {
            saveSelectionTask.cancel();

        }
    });
    new Thread(saveSelectionTask).start();
}

From source file:snpviewer.SnpViewer.java

public void displayFlankingSnpIDs(final String chrom, final double start, final double end) {
    final Task<List<String>> displayTask = new Task<List<String>>() {
        @Override/*w  w  w.j  a va2  s. c om*/
        protected List<String> call() {
            updateProgress(-1, -1);
            updateTitle("Finding flanking SNPs");
            updateMessage("Searching for nearest SNP in all files...");
            //work out coordinates based on chromosome and pane sizes
            /* read SnpFiles to find closest SNPs - use binary search
            * to find nearby SNP and refine to closest
            */
            List<SnpFile.SnpLine> startAndEndSnps = searchCoordinate(chrom, (int) start, (int) end);
            if (startAndEndSnps == null) {
                //DISPLAY ERROR HERE?
                return null;
            }
            String coordResult = "chr" + chrom + ":" + nf.format(startAndEndSnps.get(0).getPosition()) + "-"
                    + nf.format(startAndEndSnps.get(1).getPosition());
            String idResult = startAndEndSnps.get(0).getId() + ";" + startAndEndSnps.get(1).getId();
            List<String> result = new ArrayList();
            result.add(coordResult);
            result.add(idResult);
            return result;
        }
    };

    setProgressMode(true);
    progressBar.progressProperty().bind(displayTask.progressProperty());
    progressMessage.textProperty().unbind();
    progressMessage.textProperty().bind(displayTask.messageProperty());
    progressTitle.textProperty().unbind();
    progressTitle.textProperty().bind(displayTask.titleProperty());
    displayTask.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
        @Override
        public void handle(WorkerStateEvent e) {
            setProgressMode(false);
            progressBar.progressProperty().unbind();
            progressBar.progressProperty().set(0);
            progressTitle.textProperty().unbind();
            progressMessage.textProperty().unbind();
            progressTitle.setText("");
            progressMessage.setText("");
        }

    });
    displayTask.setOnFailed(new EventHandler<WorkerStateEvent>() {
        @Override
        public void handle(WorkerStateEvent e) {
            setProgressMode(false);
            progressBar.progressProperty().unbind();
            progressBar.progressProperty().set(0);
            progressTitle.textProperty().unbind();
            progressMessage.textProperty().unbind();
            progressTitle.setText("");
            progressMessage.setText("");
            Dialogs.showErrorDialog(null, "Error displaying flanking SNPs\n", "Display error", "SNP Viewer",
                    displayTask.getException());

        }

    });
    displayTask.setOnCancelled(new EventHandler<WorkerStateEvent>() {
        @Override
        public void handle(WorkerStateEvent e) {
            progressMessage.setText("Display flanking SNPs cancelled");
            setProgressMode(false);
            progressBar.progressProperty().unbind();
            progressBar.progressProperty().set(0);
            progressTitle.textProperty().unbind();
            progressMessage.textProperty().unbind();
            progressTitle.setText("");
            progressMessage.setText("");
            Dialogs.showErrorDialog(null, "User cancelled display.", "Display error", "SNP Viewer",
                    displayTask.getException());
        }

    });
    cancelButton.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent actionEvent) {
            displayTask.cancel();

        }
    });
    new Thread(displayTask).start();
    try {
        List<String> result = displayTask.get();
        FXMLLoader loader = new FXMLLoader(getClass().getResource("RegionReporter.fxml"));
        Stage stage = new Stage();
        Pane page = (Pane) loader.load();
        Scene scene = new Scene(page);
        stage.setScene(scene);
        stage.setTitle("SNP Viewer Region Summary");
        stage.getIcons().add(new Image(this.getClass().getResourceAsStream("icon.png")));
        RegionReporterController regionReporter = loader.<RegionReporterController>getController();
        if (result == null) {
            regionReporter.setCoordinates("Error!");
            regionReporter.setIds("Error!");
        } else {
            regionReporter.setCoordinates(result.get(0));
            regionReporter.setIds(result.get(1));
        }
        scene.getStylesheets().add(SnpViewer.class.getResource("SnpViewerStyleSheet.css").toExternalForm());
        stage.setResizable(false);
        stage.initModality(Modality.NONE);

        stage.show();
    } catch (InterruptedException | ExecutionException | IOException ex) {
        Dialogs.showErrorDialog(null,
                "Can't display flanking SNP IDs" + " - exception caught!\n\nPlease report this error.",
                "Error!", "SNP Viewer", ex);
    }

}