Example usage for javafx.scene.shape Circle radiusProperty

List of usage examples for javafx.scene.shape Circle radiusProperty

Introduction

In this page you can find the example usage for javafx.scene.shape Circle radiusProperty.

Prototype

public final DoubleProperty radiusProperty() 

Source Link

Usage

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("Title");

    final Circle circ = new Circle(40, Color.RED);

    System.out.println(circ.radiusProperty().doubleValue());

    final Group root = new Group(circ);
    final Scene scene = new Scene(root, 400, 300);

    primaryStage.setScene(scene);//from w w w .j  av a  2  s.  co m
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Circle c = new Circle();
    Group root = new Group(c);
    Scene scene = new Scene(root, 100, 100);

    c.centerXProperty().bind(scene.widthProperty().divide(2));
    c.centerYProperty().bind(scene.heightProperty().divide(2));
    c.radiusProperty().bind(Bindings.min(scene.widthProperty(), scene.heightProperty()).divide(2));

    stage.setTitle("A Centered Circle");
    stage.setScene(scene);/* w w  w .  j a  v a  2s  .  co m*/
    stage.sizeToScene();
    stage.show();
}

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();/*w  ww.  j a v a 2  s  . c  o 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:com.github.vatbub.tictactoe.view.Main.java

private void showLooser(Board.WinnerInfo winnerInfo) {
    String looserName = board.getOpponent(winnerInfo.winningPlayer).getName();
    guiAnimationQueue.submitWaitForUnlock(() -> {
        ShakeTransition anim = new ShakeTransition(gamePane, null);
        anim.playFromStart();/*  ww w  .  j a v a2 s .  c o  m*/

        Timeline timeline = new Timeline();

        Circle c1 = new Circle((452 / 600.0) * looserPane.getWidth(), (323 / 640.0) * looserPane.getHeight(),
                0);
        GaussianBlur circleBlur = new GaussianBlur(30);
        c1.setEffect(circleBlur);
        looseImage.setClip(c1);
        addWinLineOnLoose(winnerInfo);

        KeyValue keyValue1 = new KeyValue(c1.radiusProperty(), 0);
        KeyFrame keyFrame1 = new KeyFrame(Duration.millis(800), keyValue1);
        KeyValue keyValue2 = new KeyValue(c1.radiusProperty(), (500 / 640.0) * looserPane.getHeight());
        KeyFrame keyFrame2 = new KeyFrame(Duration.millis(900), keyValue2);

        timeline.getKeyFrames().addAll(keyFrame1, keyFrame2);

        looseMessage.setOpacity(0);
        looserText.setText(looserName + " lost :(");
        looserPane.setVisible(true);
        looserPane.setOpacity(1);

        timeline.setOnFinished((event) -> {
            looseImage.setClip(null);
            winLineGroup.setClip(null);
            blurGamePane();
            PauseTransition wait = new PauseTransition();
            wait.setDuration(Duration.seconds(1));
            wait.setOnFinished((event2) -> {
                FadeTransition looseMessageTransition = new FadeTransition();
                looseMessageTransition.setNode(looseMessage);
                looseMessageTransition.setFromValue(0);
                looseMessageTransition.setToValue(1);
                looseMessageTransition.setDuration(Duration.millis(500));
                looseMessageTransition.setAutoReverse(false);
                looseMessageTransition.play();
            });

            wait.play();
        });

        timeline.play();
    });

}

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 . java 2  s.  c o m*/
    }

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