Example usage for javafx.scene.control SplitPane getScene

List of usage examples for javafx.scene.control SplitPane getScene

Introduction

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

Prototype

public final Scene getScene() 

Source Link

Usage

From source file:snpviewer.SnpViewer.java

public void drawCoordinatesWithIterator(final SnpFile sfile, final Pane pane, final String pngPath,
        final Iterator<SnpFile> sIter, final Iterator<Pane> pIter, final int currentFile, final int totalFiles,
        final String chrom, final Double start, final Double end, final boolean forceRedraw,
        final SplitPane splitPane) {
    Stage stage = (Stage) splitPane.getScene().getWindow();
    fixStageSize(stage, true);//from   w  w w . java  2s .co m

    //stage.setResizable(false);//we have to disable this when using windows due to a bug (in javafx?)
    File pngFile = new File(sfile.getOutputDirectoryName() + "/" + chrom + ".png");
    if (pngPath != null && pngPath.length() > 0) {
        pngFile = new File(sfile.getOutputDirectoryName() + "/" + pngPath + "/" + chrom + ".png");
    }
    if (!forceRedraw && pngFile.exists()) {
        try {
            progressBar.progressProperty().unbind();
            progressBar.setProgress((double) currentFile / (double) totalFiles);
            BufferedImage bufferedImage = ImageIO.read(pngFile);
            Image image = SwingFXUtils.toFXImage(bufferedImage, null);
            ImageView chromImage = new ImageView(image);
            //chromImage.setCache(true);
            pane.getChildren().clear();
            pane.getChildren().add(chromImage);
            //pane.setCache(true);
            chromImage.fitWidthProperty().bind(pane.widthProperty());
            chromImage.fitHeightProperty().bind(pane.heightProperty());
            pane.minHeightProperty().bind(splitPane.heightProperty().divide(totalFiles));
            pane.minWidthProperty().bind(splitPane.widthProperty());

            if (sIter.hasNext()) {
                SnpFile nextFile = sIter.next();
                Pane nextPane = pIter.next();
                drawCoordinatesWithIterator(nextFile, nextPane, pngPath, sIter, pIter, currentFile + 1,
                        totalFiles, chrom, start, end, forceRedraw, splitPane);
            } else {
                progressBar.progressProperty().unbind();
                progressBar.setProgress(0);
                setProgressMode(false);
                fixStageSize(stage, false);//for windows only
                stage.setResizable(true);
            }
        } catch (IOException ex) {
            Dialogs.showErrorDialog(null, "IO error reading cached image", "Error displaying chromosome image",
                    "SnpViewer", ex);
            return;
        }

    } else {

        final DrawSnpsToPane draw = new DrawSnpsToPane(pane, sfile, chrom, Colors.aa.value, Colors.bb.value,
                Colors.ab.value, start, end);

        progressBar.progressProperty().unbind();
        //progressBar.setProgress(0);
        //progressBar.progressProperty().bind(draw.progressProperty());
        progressTitle.setText("Drawing " + currentFile + " of " + totalFiles);
        progressMessage.textProperty().bind(draw.messageProperty());
        cancelButton.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                draw.cancel();
            }
        });

        draw.setOnCancelled(new EventHandler<WorkerStateEvent>() {
            @Override
            public void handle(WorkerStateEvent t) {

                progressBar.progressProperty().unbind();
                progressBar.setProgress(0);
                progressTitle.setText("Drawing Cancelled");
                progressMessage.textProperty().unbind();
                progressMessage.setText("Drawing Cancelled");
                setProgressMode(false);
                selectionOverlayPane.getChildren().clear();
                selectionOverlayPane.getChildren().add(dragSelectRectangle);
                Stage stage = (Stage) splitPane.getScene().getWindow();
                stage.setResizable(true);
                fixStageSize(stage, false);//for windows only
            }
        });
        draw.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
            @Override
            public void handle(WorkerStateEvent t) {
                ArrayList<HashMap<String, Double>> result = (ArrayList<HashMap<String, Double>>) t.getSource()
                        .getValue();
                progressBar.progressProperty().unbind();
                progressBar.setProgress((double) currentFile / (2 * (double) totalFiles));
                progressTitle.setText("");
                progressMessage.textProperty().unbind();
                progressMessage.setText("");
                /*if (pane.getMinHeight() < 200){
                pane.setMinHeight(200);
                }
                if (pane.getMinWidth() < 800){
                    pane.setMinWidth(800);
                }*/
                if (result != null) {
                    List<Line> lines = drawLinesToPane(pane, result);
                    pane.getChildren().addAll(lines);
                    pane.setVisible(true);
                    convertSampleViewToImage(sfile, pane, chrom, pngPath);
                    /*for (Line l: lines){
                        l.startXProperty().unbind();
                        l.startYProperty().unbind();
                        l.endXProperty().unbind();
                        l.endYProperty().unbind();
                    }*/
                    lines.clear();
                }
                progressBar.setProgress((double) currentFile / (double) totalFiles);
                pane.minWidthProperty().bind(splitPane.widthProperty());
                pane.minHeightProperty().bind(splitPane.heightProperty().divide(totalFiles));
                // pane.setCache(true);
                if (sIter.hasNext()) {
                    SnpFile nextFile = sIter.next();
                    Pane nextPane = pIter.next();
                    drawCoordinatesWithIterator(nextFile, nextPane, pngPath, sIter, pIter, currentFile + 1,
                            totalFiles, chrom, start, end, forceRedraw, splitPane);
                } else {
                    setProgressMode(false);
                    progressBar.progressProperty().unbind();
                    progressBar.setProgress(0);

                    Stage stage = (Stage) splitPane.getScene().getWindow();
                    stage.setResizable(true);
                    fixStageSize(stage, false);//for windows only
                }
            }
        });
        draw.setOnFailed(new EventHandler<WorkerStateEvent>() {
            @Override
            public void handle(WorkerStateEvent t) {
                draw.reset();
                progressBar.progressProperty().unbind();
                progressBar.setProgress(0);
                progressTitle.setText("ERROR!");
                progressMessage.textProperty().unbind();
                progressMessage.setText("Drawing failed!");
                setProgressMode(false);
                selectionOverlayPane.getChildren().clear();
                selectionOverlayPane.getChildren().add(dragSelectRectangle);
                //     Stage stage = (Stage) chromSplitPane.getScene().getWindow();
                //     stage.setResizable(true);
            }

        });
        draw.start();
    }
}