Example usage for javafx.beans.binding Bindings divide

List of usage examples for javafx.beans.binding Bindings divide

Introduction

In this page you can find the example usage for javafx.beans.binding Bindings divide.

Prototype

public static NumberBinding divide(int op1, final ObservableNumberValue op2) 

Source Link

Document

Creates a new javafx.beans.binding.NumberBinding that calculates the division of a constant value and the value of a javafx.beans.value.ObservableNumberValue .

Usage

From source file:Main.java

public static void main(String[] args) {
    IntegerProperty x1 = new SimpleIntegerProperty(0);
    IntegerProperty y1 = new SimpleIntegerProperty(0);

    final NumberBinding x1y2 = Bindings.multiply(x1, y1);

    final NumberBinding sum1 = Bindings.add(x1y2, 2);
    final NumberBinding diff1 = Bindings.subtract(sum1, 1);
    final NumberBinding determinant = Bindings.subtract(diff1, 2);
    final NumberBinding area = Bindings.divide(determinant, 2.0D);

    x1.set(0);/*from w  w  w  .  j  av  a2  s .c o  m*/
    y1.set(0);

    printResult(x1, y1, area);

    x1.set(1);
    y1.set(0);

    printResult(x1, y1, area);
}

From source file:Main.java

private static Node createProgressPanel() {
    final Slider slider = new Slider();

    final ProgressIndicator progressIndicator = new ProgressIndicator(0);
    progressIndicator.progressProperty().bind(Bindings.divide(slider.valueProperty(), slider.maxProperty()));

    final HBox panel = createHBox(6, new Label("Progress:"), slider, progressIndicator);
    configureBorder(panel);/*from  w ww . j  a v  a 2 s.  co  m*/

    return panel;
}

From source file:edu.kit.trufflehog.view.jung.visualization.FXVisualizationViewer.java

synchronized private void initEdge(IConnection edge) {

    final Pair<INode> pair = this.layout.getGraph().getEndpoints(edge);

    if (pair.getSecond().getAddress().isMulticast()) {

        // TODO check or do something with this (generify the getShape command?)
        final Circle destCircle = (Circle) pair.getFirst().getComponent(ViewComponent.class).getRenderer()
                .getShape();/*from   w  w w.  j  a  v a 2s .co m*/
        final Shape shape = edge.getComponent(ViewComponent.class).getRenderer().getShape();
        shape.layoutXProperty().bind(destCircle.layoutXProperty());
        shape.layoutYProperty().bind(destCircle.layoutYProperty());
        canvas.getChildren().add(shape);
        shape.setPickOnBounds(false);
        shape.setMouseTransparent(true);
        return;
    }

    // source and destination shape
    final Shape srcShape = pair.getFirst().getComponent(ViewComponent.class).getRenderer().getShape();
    final Shape destShape = pair.getSecond().getComponent(ViewComponent.class).getRenderer().getShape();

    // the positions of the shapes
    final DoubleBinding srcX = srcShape.layoutXProperty().add(srcShape.translateXProperty());
    final DoubleBinding srcY = srcShape.layoutYProperty().add(srcShape.translateYProperty());
    final DoubleBinding destX = destShape.layoutXProperty().add(destShape.translateXProperty());
    final DoubleBinding destY = destShape.layoutYProperty().add(destShape.translateYProperty());

    // the direction vector from source to destination (deltaX, deltaY)
    final DoubleBinding deltaX = destX.subtract(srcX);
    final DoubleBinding deltaY = destY.subtract(srcY);

    // the length of the direction vector
    final DoubleBinding length = MyBindings
            .sqrt(Bindings.add(MyBindings.pow2(deltaX), MyBindings.pow2(deltaY)));

    // the normalized direction vector
    final DoubleBinding normalX = deltaX.divide(length);
    final DoubleBinding normalY = deltaY.divide(length);

    // cast the shapes to circles (because right now i know they are circles) //TODO make this for arbitrary shapes
    final Circle destCircle = (Circle) destShape;
    final Circle srcCircle = (Circle) srcShape;

    // get the real source by multiplying the normal with the radius and the scale of the shape
    final DoubleBinding realSoureX = srcX
            .add(normalX.multiply(srcCircle.radiusProperty().multiply(srcShape.scaleXProperty())));
    final DoubleBinding realSoureY = srcY
            .add(normalY.multiply(srcCircle.radiusProperty().multiply(srcShape.scaleYProperty())));

    // get the real destination by multipling the normal vector with the length minus the radius and scale of the destination shape
    final DoubleBinding realDestX = srcX.add(normalX
            .multiply(length.subtract(destCircle.radiusProperty().multiply(destShape.scaleXProperty()))));
    final DoubleBinding realDestY = srcY.add(normalY
            .multiply(length.subtract(destCircle.radiusProperty().multiply(destShape.scaleYProperty()))));

    final IEdgeRenderer edgeRenderer = (IEdgeRenderer) edge.getComponent(ViewComponent.class).getRenderer();

    edgeRenderer.getArrowShape().layoutXProperty().bind(realDestX);
    edgeRenderer.getArrowShape().layoutYProperty().bind(realDestY);

    final QuadCurve curve = edgeRenderer.getLine();
    curve.setCacheHint(CacheHint.SPEED);

    curve.addEventFilter(MouseEvent.MOUSE_PRESSED, edgeGestures.getOnMousePressedEventHandler(edge));
    curve.addEventFilter(MouseEvent.MOUSE_RELEASED, edgeGestures.getOnMouseReleasedEventHandler(edge));
    edgeRenderer.getArrowShape().addEventFilter(MouseEvent.MOUSE_PRESSED,
            edgeGestures.getOnMousePressedEventHandler(edge));
    edgeRenderer.getArrowShape().addEventFilter(MouseEvent.MOUSE_RELEASED,
            edgeGestures.getOnMouseReleasedEventHandler(edge));

    /*        // make the edge clickable
            curve.setOnMouseClicked(e -> {
            
    if (e.getButton() != MouseButton.PRIMARY) {
        return;
    }
            
    logger.debug(edge.getSrc().getComponent(NodeInfoComponent.class).toString() + " --[" + edge.getComponent(EdgeStatisticsComponent.class).getTraffic() +
            "]-->" + edge.getDest().getComponent(NodeInfoComponent.class).toString());
            
    //            edge.getComponent(ViewComponent.class).getRenderer().togglePicked();
            });
            
            edgeRenderer.getArrowShape().setOnMouseClicked(e -> {
            
    if (e.getButton() != MouseButton.PRIMARY) {
        return;
    }
            
    logger.debug(edge.getSrc().getComponent(NodeInfoComponent.class).toString() + " --[" + edge.getComponent(EdgeStatisticsComponent.class).getTraffic() +
    "]-->" + edge.getDest().getComponent(NodeInfoComponent.class).toString());
            
    //            edge.getComponent(ViewComponent.class).getRenderer().togglePicked();
            
            
            });*/

    //get the edge size binding by dividing the total traffic with the local traffic
    DoubleBinding edgeSize = MyBindings
            .divideIntToDouble(edge.getComponent(EdgeStatisticsComponent.class).getTrafficProperty(),
                    port.getMaxConnectionSizeProperty())
            .multiply(8).add(2);
    curve.strokeWidthProperty().bind(edgeSize.multiply(edgeRenderer.edgeWidthMultiplierProperty()));

    // bind the ending to the real destionaion point
    curve.endXProperty().bind(realDestX);
    curve.endYProperty().bind(realDestY);

    // bind the source to the real source point
    curve.startXProperty().bind(realSoureX);
    curve.startYProperty().bind(realSoureY);

    NumberBinding normalVectorX = Bindings.subtract(realDestY, realSoureY).negate();
    NumberBinding normalVectorY = Bindings.subtract(realDestX, realSoureX);

    NumberBinding centerPointX = Bindings.divide(Bindings.add(curve.endXProperty(), curve.startXProperty()), 2);
    NumberBinding centerPointY = Bindings.divide(Bindings.add(curve.endYProperty(), curve.startYProperty()), 2);

    NumberBinding normalLength = MyBindings
            .sqrt(Bindings.add(normalVectorX.multiply(normalVectorX), normalVectorY.multiply(normalVectorY)));

    NumberBinding normalizedNVX = normalVectorX.divide(normalLength);
    NumberBinding normalizedNVY = normalVectorY.divide(normalLength);

    NumberBinding bezierPointOffset = length.multiply(.1);

    curve.controlXProperty().bind(Bindings.add(centerPointX, normalizedNVX.multiply(bezierPointOffset)));
    curve.controlYProperty().bind(Bindings.add(centerPointY, normalizedNVY.multiply(bezierPointOffset)));

    // TODO do this in component
    curve.setFill(null);

    canvas.getChildren().add(edgeRenderer.getArrowShape());
    // add the edge to the canvas
    canvas.getChildren().add(curve);
}

From source file:edu.kit.trufflehog.view.jung.visualization.FXVisualizationViewer.java

synchronized private void initVertex(INode vertex) {

    if (vertex.getAddress().isMulticast()) {
        return;/*from ww w . j  ava 2s  .c  om*/
    }

    final IRenderer renderer = vertex.getComponent(ViewComponent.class).getRenderer();
    final Shape nodeShape = renderer.getShape();
    //nodeShape.addEventFilter( MouseEvent.MOUSE_PRESSED, nodeGestures.getOnMousePressedEventHandler());
    //nodeShape.addEventFilter( MouseEvent.MOUSE_DRAGGED, nodeGestures.getOnMouseDraggedEventHandler());

    //nodeShape.setCache(false);
    //nodeShape.setCacheHint(CacheHint.);

    final NodeStatisticsComponent nsc = vertex.getComponent(NodeStatisticsComponent.class);

    final DoubleBinding nodeSize = MyBindings
            .divideIntToDouble(nsc.getCommunicationCountProperty(), port.getMaxThroughputProperty()).add(1);

    nodeShape.scaleXProperty().bind(nodeSize);
    nodeShape.scaleYProperty().bind(nodeSize);

    nodeShape.setLayoutX(layout.transform(vertex).getX());
    nodeShape.setLayoutY(layout.transform(vertex).getY());

    ///////////
    // LABEL //
    ///////////

    Label nodeLabel = new Label();

    // cast the shapes to circles (because right now i know they are circles) //TODO make this for arbitrary shapes
    final Circle nodeCircle = (Circle) nodeShape;

    /*        final DoubleProperty labelX = new SimpleDoubleProperty();
            final DoubleProperty labelY = new SimpleDoubleProperty();*/

    //labelX.bind(nodeShape.layoutXProperty().add(nodeCircle.radiusProperty().multiply(nodeShape.scaleXProperty())));
    //labelY.bind(nodeShape.layoutYProperty().add(nodeCircle.radiusProperty().multiply(nodeShape.scaleYProperty())));

    //nodeLabel.layoutXProperty().bindBidirectionalWithOffset(labelX);
    //nodeLabel.layoutYProperty().bindBidirectionalWithOffset(labelY);

    //nodeLabel.layoutXProperty().bind(nodeShape.layoutXProperty().add(nodeCircle.radiusProperty().multiply(nodeShape.scaleXProperty())));

    nodeLabel.textFillProperty().bind(new SimpleObjectProperty<>(Color.WHITE));

    //MyBindings.bindBidirectionalWithOffset(nodeLabel.layoutXProperty(), nodeShape.layoutXProperty(), nodeCircle.radiusProperty().multiply(nodeShape.scaleXProperty()));
    //MyBindings.bindBidirectionalWithOffset(nodeLabel.layoutYProperty(), nodeShape.layoutYProperty(), nodeCircle.radiusProperty().multiply(nodeShape.scaleYProperty()));

    nodeLabel.layoutXProperty().bind(nodeShape.layoutXProperty().add(nodeShape.translateXProperty())
            .add(nodeCircle.radiusProperty().multiply(nodeShape.scaleXProperty())));
    nodeLabel.layoutYProperty().bind(nodeShape.layoutYProperty().add(nodeShape.translateYProperty())
            .add(nodeCircle.radiusProperty().multiply(nodeShape.scaleYProperty())));

    NodeInfoComponent nic = vertex.getComponent(NodeInfoComponent.class);
    if (nic != null) {
        nodeLabel.textProperty().bind(nic.toStringBinding());
    }

    nodeLabel.scaleXProperty().bind(Bindings.divide(1, canvas.scaleXProperty()));
    nodeLabel.scaleYProperty().bind(Bindings.divide(1, canvas.scaleYProperty()));

    nodeLabel.addEventFilter(MouseEvent.MOUSE_PRESSED, nodeGestures.getOnMousePressedEventHandler(vertex));
    nodeLabel.addEventFilter(MouseEvent.MOUSE_DRAGGED, nodeGestures.getOnMouseDraggedEventHandler(vertex));
    nodeLabel.addEventFilter(MouseEvent.MOUSE_RELEASED, nodeGestures.getOnMouseReleasedEventHandler(vertex));

    nodeShape.addEventFilter(MouseEvent.MOUSE_PRESSED, nodeGestures.getOnMousePressedEventHandler(vertex));
    nodeShape.addEventFilter(MouseEvent.MOUSE_DRAGGED, nodeGestures.getOnMouseDraggedEventHandler(vertex));
    nodeShape.addEventFilter(MouseEvent.MOUSE_RELEASED, nodeGestures.getOnMouseReleasedEventHandler(vertex));
    nodeShape.addEventFilter(MouseEvent.MOUSE_CLICKED, nodeGestures.getOnMouseClickedEventHandler(vertex));

    canvas.getChildren().addAll(nodeLabel, nodeShape);
}