Example usage for javafx.scene.layout Pane heightProperty

List of usage examples for javafx.scene.layout Pane heightProperty

Introduction

In this page you can find the example usage for javafx.scene.layout Pane heightProperty.

Prototype

public final ReadOnlyDoubleProperty heightProperty() 

Source Link

Usage

From source file:Main.java

public static void startValueSetAnimation(final Pane parent) {
    final javafx.scene.shape.Rectangle rectangle = new javafx.scene.shape.Rectangle();
    Insets margin = BorderPane.getMargin(parent);
    if (margin == null) {
        margin = new Insets(0);
    }/*from w ww. ja  va 2s .  c  om*/
    rectangle.widthProperty().bind(parent.widthProperty().subtract(margin.getLeft() + margin.getRight()));
    rectangle.heightProperty().bind(parent.heightProperty().subtract(margin.getTop() + margin.getBottom()));
    rectangle.setFill(Color.rgb(0, 150, 201));
    parent.getChildren().add(rectangle);

    BoxBlur bb = new BoxBlur();
    bb.setWidth(5);
    bb.setHeight(5);
    bb.setIterations(3);
    rectangle.setEffect(bb);

    FadeTransition ft = new FadeTransition(Duration.millis(250), rectangle);
    ft.setFromValue(0.2);
    ft.setToValue(0.8);
    ft.setCycleCount(2);
    ft.setAutoReverse(true);
    ft.play();
    ft.setOnFinished(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            parent.getChildren().remove(rectangle);
        }
    });
}

From source file:mesclasses.view.TimetableController.java

private void bindHeight(Region node, Pane parent, int divider) {
    node.minHeightProperty().bind(parent.heightProperty().divide(divider));
    node.prefHeightProperty().bind(parent.heightProperty().divide(divider));
    node.maxHeightProperty().bind(parent.heightProperty().divide(divider));
}

From source file:nl.rivm.cib.episim.model.disease.infection.MSEIRSPlot.java

@Override
public void start(final Stage stage) {
    final SIRConfig conf = ConfigFactory.create(SIRConfig.class);
    final double[] t = conf.t();
    final long[] pop = conf.population();
    final double n0 = Arrays.stream(pop).sum();
    final String[] colors = conf.colors(), colors2 = conf.colors2();

    final Pane plot = new Pane();
    plot.setPrefSize(400, 300);/*  w ww  .j  a  v  a  2 s.c o m*/
    plot.setMinSize(50, 50);

    final NumberAxis xAxis = new NumberAxis(t[0], t[1], (t[1] - t[0]) / 10);
    final NumberAxis yAxis = new NumberAxis(0, n0, n0 / 10);
    final Pane axes = new Pane();
    axes.prefHeightProperty().bind(plot.heightProperty());
    axes.prefWidthProperty().bind(plot.widthProperty());

    xAxis.setSide(Side.BOTTOM);
    xAxis.setMinorTickVisible(false);
    xAxis.setPrefWidth(axes.getPrefWidth());
    xAxis.prefWidthProperty().bind(axes.widthProperty());
    xAxis.layoutYProperty().bind(axes.heightProperty());

    yAxis.setSide(Side.LEFT);
    yAxis.setMinorTickVisible(false);
    yAxis.setPrefHeight(axes.getPrefHeight());
    yAxis.prefHeightProperty().bind(axes.heightProperty());
    yAxis.layoutXProperty().bind(Bindings.subtract(1, yAxis.widthProperty()));
    axes.getChildren().setAll(xAxis, yAxis);

    final Label lbl = new Label(String.format("R0=%.1f, recovery=%.1ft\nSIR(0)=%s", conf.reproduction(),
            conf.recovery(), Arrays.toString(pop)));
    lbl.setTextAlignment(TextAlignment.CENTER);
    lbl.setTextFill(Color.WHITE);

    final Path[] deterministic = { new Path(), new Path(), new Path() };
    IntStream.range(0, pop.length).forEach(i -> {
        final Color color = Color.valueOf(colors[i]);
        final Path path = deterministic[i];
        path.setStroke(color.deriveColor(0, 1, 1, 0.6));
        path.setStrokeWidth(2);
        path.setClip(new Rectangle(0, 0, plot.getPrefWidth(), plot.getPrefHeight()));
    });

    plot.getChildren().setAll(axes);

    // fill paths with integration estimates
    final double xl = xAxis.getLowerBound(), sx = plot.getPrefWidth() / (xAxis.getUpperBound() - xl),
            yh = plot.getPrefHeight(), sy = yh / (yAxis.getUpperBound() - yAxis.getLowerBound());
    final TreeMap<Double, Integer> iDeterministic = new TreeMap<>();

    MSEIRSTest.deterministic(conf, () -> new DormandPrince853Integrator(1.0E-8, 10, 1.0E-20, 1.0E-20))
            .subscribe(yt -> {
                iDeterministic.put(yt.getKey(), deterministic[0].getElements().size());
                final double[] y = yt.getValue();
                final double x = (yt.getKey() - xl) * sx;
                for (int i = 0; i < y.length; i++) {
                    final double yi = yh - y[i] * sy;
                    final PathElement di = deterministic[i].getElements().isEmpty() ? new MoveTo(x, yi)
                            : new LineTo(x, yi);
                    deterministic[i].getElements().add(di);
                }
            }, e -> LOG.error("Problem", e), () -> plot.getChildren().addAll(deterministic));

    final Path[] stochasticTau = { new Path(), new Path(), new Path() };
    IntStream.range(0, pop.length).forEach(i -> {
        final Color color = Color.valueOf(colors[i]);
        final Path path = stochasticTau[i];
        path.setStroke(color);
        path.setStrokeWidth(1);
        path.setClip(new Rectangle(0, 0, plot.getPrefWidth(), plot.getPrefHeight()));
    });

    final TreeMap<Double, Integer> iStochasticTau = new TreeMap<>();
    MSEIRSTest.stochasticGillespie(conf).subscribe(yt -> {
        final double x = (yt.getKey() - xl) * sx;
        iStochasticTau.put(yt.getKey(), stochasticTau[0].getElements().size());
        final long[] y = yt.getValue();
        for (int i = 0; i < y.length; i++) {
            final double yi = yh - y[i] * sy;
            final ObservableList<PathElement> path = stochasticTau[i].getElements();
            if (path.isEmpty()) {
                path.add(new MoveTo(x, yi)); // first
            } else {
                final PathElement last = path.get(path.size() - 1);
                final double y_prev = last instanceof MoveTo ? ((MoveTo) last).getY() : ((LineTo) last).getY();
                path.add(new LineTo(x, y_prev));
                path.add(new LineTo(x, yi));
            }
        }
    }, e -> LOG.error("Problem", e), () -> plot.getChildren().addAll(stochasticTau));

    final Path[] stochasticRes = { new Path(), new Path(), new Path() };
    IntStream.range(0, pop.length).forEach(i -> {
        final Color color = Color.valueOf(colors2[i]);
        final Path path = stochasticRes[i];
        path.setStroke(color);
        path.setStrokeWidth(1);
        path.setClip(new Rectangle(0, 0, plot.getPrefWidth(), plot.getPrefHeight()));
    });

    final TreeMap<Double, Integer> iStochasticRes = new TreeMap<>();
    MSEIRSTest.stochasticSellke(conf).subscribe(yt -> {
        final double x = (yt.getKey() - xl) * sx;
        iStochasticRes.put(yt.getKey(), stochasticRes[0].getElements().size());
        final long[] y = yt.getValue();
        for (int i = 0; i < y.length; i++) {
            final double yi = yh - y[i] * sy;
            final ObservableList<PathElement> path = stochasticRes[i].getElements();
            if (path.isEmpty()) {
                path.add(new MoveTo(x, yi)); // first
            } else {
                final PathElement last = path.get(path.size() - 1);
                final double y_prev = last instanceof MoveTo ? ((MoveTo) last).getY() : ((LineTo) last).getY();
                path.add(new LineTo(x, y_prev));
                path.add(new LineTo(x, yi));
            }
        }
    }, e -> LOG.error("Problem", e), () -> plot.getChildren().addAll(stochasticRes));

    // auto-scale on stage/plot resize 
    // FIXME scaling around wrong origin, use ScatterChart?
    //         xAxis.widthProperty()
    //               .addListener( (ChangeListener<Number>) ( observable,
    //                  oldValue, newValue ) ->
    //               {
    //                  final double scale = ((Double) newValue)
    //                        / plot.getPrefWidth();
    //                  plot.getChildren().filtered( n -> n instanceof Path )
    //                        .forEach( n ->
    //                        {
    //                           final Path path = (Path) n;
    //                           path.setScaleX( scale );
    //                           path.setTranslateX( (path
    //                                 .getBoundsInParent().getWidth()
    //                                 - path.getLayoutBounds().getWidth())
    //                                 / 2 );
    //                        } );
    //               } );
    //         plot.heightProperty()
    //               .addListener( (ChangeListener<Number>) ( observable,
    //                  oldValue, newValue ) ->
    //               {
    //                  final double scale = ((Double) newValue)
    //                        / plot.getPrefHeight();
    //                  plot.getChildren().filtered( n -> n instanceof Path )
    //                        .forEach( n ->
    //                        {
    //                           final Path path = (Path) n;
    //                           path.setScaleY( scale );
    //                           path.setTranslateY(
    //                                 (path.getBoundsInParent()
    //                                       .getHeight() * (scale - 1))
    //                                       / 2 );
    //                        } );
    //               } );

    final StackPane layout = new StackPane(lbl, plot);
    layout.setAlignment(Pos.TOP_CENTER);
    layout.setPadding(new Insets(50));
    layout.setStyle("-fx-background-color: rgb(35, 39, 50);");

    final Line vertiCross = new Line();
    vertiCross.setStroke(Color.SILVER);
    vertiCross.setStrokeWidth(1);
    vertiCross.setVisible(false);
    axes.getChildren().add(vertiCross);

    final Tooltip tip = new Tooltip("");
    tip.setAutoHide(false);
    tip.hide();
    axes.setOnMouseExited(ev -> tip.hide());
    axes.setOnMouseMoved(ev -> {
        final Double x = (Double) xAxis.getValueForDisplay(ev.getX());
        if (x > xAxis.getUpperBound() || x < xAxis.getLowerBound()) {
            tip.hide();
            vertiCross.setVisible(false);
            return;
        }
        final Double y = (Double) yAxis.getValueForDisplay(ev.getY());
        if (y > yAxis.getUpperBound() || y < yAxis.getLowerBound()) {
            tip.hide();
            vertiCross.setVisible(false);
            return;
        }
        final double xs = xAxis.getDisplayPosition(x);
        vertiCross.setStartX(xs);
        vertiCross.setStartY(yAxis.getDisplayPosition(0));
        vertiCross.setEndX(xs);
        vertiCross.setEndY(yAxis.getDisplayPosition(yAxis.getUpperBound()));
        vertiCross.setVisible(true);
        final int i = (iDeterministic.firstKey() > x ? iDeterministic.firstEntry()
                : iDeterministic.floorEntry(x)).getValue();
        final Object[] yi = Arrays.stream(deterministic).mapToDouble(p -> getY(p, i))
                .mapToObj(yAxis::getValueForDisplay).map(n -> DecimalUtil.toScale(n, 1)).toArray();
        final int j = (iStochasticTau.firstKey() > x ? iStochasticTau.firstEntry()
                : iStochasticTau.floorEntry(x)).getValue();
        final Object[] yj = Arrays.stream(stochasticTau).mapToDouble(p -> getY(p, j))
                .mapToObj(yAxis::getValueForDisplay).map(n -> DecimalUtil.toScale(n, 0)).toArray();
        final int k = (iStochasticRes.firstKey() > x ? iStochasticRes.firstEntry()
                : iStochasticRes.floorEntry(x)).getValue();
        final Object[] yk = Arrays.stream(stochasticRes).mapToDouble(p -> getY(p, k))
                .mapToObj(yAxis::getValueForDisplay).map(n -> DecimalUtil.toScale(n, 0)).toArray();
        final String txt = String.format("SIR(t=%.1f)\n" + "~det%s\n" + "~tau%s\n" + "~res%s", x,
                Arrays.toString(yi), Arrays.toString(yj), Arrays.toString(yk));

        tip.setText(txt);
        tip.show(axes, ev.getScreenX() - ev.getSceneX() + xs, ev.getScreenY() + 15);
    });

    try {
        stage.getIcons().add(new Image(FileUtil.toInputStream("icon.jpg")));
    } catch (final IOException e) {
        LOG.error("Problem", e);
    }
    stage.setTitle("Deterministic vs. Stochastic");
    stage.setScene(new Scene(layout, Color.rgb(35, 39, 50)));
    //         stage.setOnHidden( ev -> tip.hide() );
    stage.show();
}

From source file:org.mskcc.shenkers.view.IntervalViewNGTest.java

public void testIntervalView() throws InterruptedException {
    System.out.println("testIntervalView");
    Pane p = new Pane();

    CountDownLatch l = new CountDownLatch(1);
    System.out.println("before");
    Platform.runLater(() -> {//from  w  w w .  j  ava 2 s  .  c  o m
        System.out.println("running");
        double[][] intervals = { { .1, .2 } };
        //                    Range r = null;
        RangeSet<Double> rs = TreeRangeSet.create();
        rs.add(Range.closed(.1, .2));
        rs.add(Range.closed(.2, .3));
        rs.add(Range.closed(.32, .35));
        rs.add(Range.closed(.6, .8));

        for (Range<Double> r : rs.asRanges()) {
            System.out.println(r.lowerEndpoint() + " - " + r.upperEndpoint());
        }
        for (Range<Double> interval : rs.asRanges()) {
            Rectangle r = new Rectangle();
            r.widthProperty()
                    .bind(p.widthProperty().multiply(interval.upperEndpoint() - interval.lowerEndpoint()));
            r.heightProperty().bind(p.heightProperty());
            r.xProperty().bind(p.widthProperty().multiply(interval.lowerEndpoint()));
            p.getChildren().add(r);
        }
        //                    p.prefTileHeightProperty().bind(p.heightProperty());
        Stage stage = new Stage();
        stage.setOnHidden(e -> {
            l.countDown();
            System.out.println("count " + l.getCount());
        });
        Scene scene = new Scene(p, 300, 300, Color.GRAY);
        stage.setTitle("JavaFX Scene Graph Demo");
        stage.setScene(scene);
        stage.show();

    });
    System.out.println("after");
    l.await();
    Thread.sleep(1000);
}

From source file:org.mskcc.shenkers.view.IntervalViewNGTest.java

public Node get(RangeSet<Integer> intervals, int start, int end) {
    RangeSet<Integer> view = intervals.subRangeSet(Range.closed(start, end));
    double l = end - start + 1.;
    Pane p = new Pane();
    for (Range<Integer> interval : view.asRanges()) {
        Rectangle r = new Rectangle();
        r.widthProperty().bind(/*from   w  w  w .  j  a v  a  2s . c  o m*/
                p.widthProperty().multiply(interval.upperEndpoint() - interval.lowerEndpoint() + 1).divide(l));
        r.heightProperty().bind(p.heightProperty());
        r.xProperty().bind(p.widthProperty().multiply(interval.lowerEndpoint()).divide(l));
        //            System.out.println(r);
        p.getChildren().add(r);
    }
    return p;
}

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  ww w  . ja va2  s  . c  om*/

    //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();
    }
}

From source file:snpviewer.SnpViewer.java

public void convertSampleViewToImage(final SnpFile s, final Pane pane, final String chrom, final String path) {
    WritableImage image;//from  www .j  a v  a  2s . c  om
    try {
        image = pane.snapshot(null, null);
    } catch (IllegalStateException ex) {
        Dialogs.showErrorDialog(null, "Error while attempting to convert" + " view to image file",
                "PNG conversion failed", "SNP Viewer", ex);
        return;
    }

    final DrawPaneToPng drawToPng = new DrawPaneToPng(image);
    drawToPng.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
        @Override
        public void handle(WorkerStateEvent t) {
            File pngFile;
            if (path != null && path.length() > 0) {
                pngFile = new File(s.getOutputDirectoryName() + "/" + path + "/" + chrom + ".png");
            } else {
                pngFile = new File(s.getOutputDirectoryName() + "/" + chrom + ".png");
            }
            try {
                if (!pngFile.getParentFile().exists()) {
                    boolean madeDir = pngFile.getParentFile().mkdir();
                    if (madeDir == false) {
                        Dialogs.showErrorDialog(null, "Unable to make sub directory"
                                + " when converting dynamic view to image file. Please " + "check permissions.",
                                "PNG conversion failed", "SNP Viewer");
                        return;
                    }
                }
                Files.copy(drawToPng.getImageFile().toPath(), pngFile.toPath(), REPLACE_EXISTING);
                BufferedImage bufferedImage = ImageIO.read(pngFile);
                Image image = SwingFXUtils.toFXImage(bufferedImage, null);

                ImageView chromImage = new ImageView(image);
                // chromImage.setCache(true);
                for (Iterator it = pane.getChildren().iterator(); it.hasNext();) {
                    Object line = it.next();
                    if (line instanceof Line) {
                        /*Line l = (Line) line;
                        l.startXProperty().unbind();
                        l.endXProperty().unbind();
                        l.endYProperty().unbind();*/
                    } else if (line instanceof ImageView) {
                        ImageView l = (ImageView) line;
                        l.fitHeightProperty().unbind();
                        l.fitWidthProperty().unbind();
                    }
                }
                pane.getChildren().clear();
                pane.getChildren().add(chromImage);

                chromImage.fitWidthProperty().bind(pane.widthProperty());
                chromImage.fitHeightProperty().bind(pane.heightProperty());
            } catch (IOException ex) {
                Dialogs.showErrorDialog(null,
                        "IOException while attempting to convert" + " dynamic view to image file",
                        "PNG conversion failed", "SNP Viewer", ex);
            }
        }
    });
    drawToPng.setOnFailed(new EventHandler<WorkerStateEvent>() {
        @Override
        public void handle(WorkerStateEvent t) {
            Dialogs.showErrorDialog(null, "Error attempting to convert" + " dynamic view to image file",
                    "PNG conversion failed", "SNP Viewer");

        }
    });
    drawToPng.start();
}