Example usage for javafx.scene.shape Line Line

List of usage examples for javafx.scene.shape Line Line

Introduction

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

Prototype

public Line(double startX, double startY, double endX, double endY) 

Source Link

Document

Creates a new instance of Line.

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    VBox box = new VBox();
    final Scene scene = new Scene(box, 300, 250);
    scene.setFill(null);/*  ww  w.ja  v a  2 s  .c  om*/

    Line line = new Line(0, 0, 0, 0);
    line.setStartX(0.0f);
    line.setStartY(0.0f);
    line.setEndX(100.0f);
    line.setEndY(100.0f);

    box.getChildren().add(line);

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

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

    Group root = new Group();
    Scene scene = new Scene(root, 300, 150, Color.GRAY);

    Line redLine = new Line(10, 10, 200, 10);

    redLine.setStroke(Color.RED);
    redLine.setStrokeWidth(10);//from ww  w .  ja  v  a 2  s .c  om
    redLine.setStrokeLineCap(StrokeLineCap.BUTT);

    redLine.getStrokeDashArray().addAll(15d, 5d, 15d, 15d, 20d);
    redLine.setStrokeDashOffset(10);

    root.getChildren().add(redLine);

    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {

    Group root = new Group();

    Scene scene = new Scene(root, 300, 150, Color.GRAY);

    Line redLine = new Line(10, 10, 200, 10);

    redLine.setStroke(Color.RED);
    redLine.setStrokeWidth(10);// w ww  .  j a  v  a  2s .  c  om
    redLine.setStrokeLineCap(StrokeLineCap.BUTT);

    redLine.getStrokeDashArray().addAll(10d, 5d, 15d, 5d, 20d);
    redLine.setStrokeDashOffset(0);

    root.getChildren().add(redLine);

    Text offsetText = new Text("Stroke Dash Offset: 0.0");
    offsetText.setX(10);
    offsetText.setY(80);
    offsetText.setStroke(Color.WHITE);

    root.getChildren().add(offsetText);

    Slider slider = new Slider(0, 100, 0);
    slider.setLayoutX(10);
    slider.setLayoutY(95);

    redLine.strokeDashOffsetProperty().bind(slider.valueProperty());

    slider.valueProperty().addListener(
            (ov, curVal, newVal) -> offsetText.setText("Stroke Dash Offset: " + slider.getValue()));

    root.getChildren().add(slider);

    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Circle circle = new Circle(40);
    circle.setFill(Color.RED);//from  www  . j  av a 2  s .  co m
    circle.setStroke(Color.BLACK);
    circle.setStrokeWidth(2.0);

    Rectangle rect = new Rectangle(120, 75);
    rect.setFill(Color.RED);

    // Create a line
    Line line = new Line(0, 0, 150, 50);
    line.setStrokeWidth(5.0);
    line.setStroke(Color.GREEN);

    // Create a parallelogram
    Polygon parallelogram = new Polygon();
    parallelogram.getPoints().addAll(30.0, 0.0, 130.0, 0.0, 120.00, 50.0, 0.0, 50.0);
    parallelogram.setFill(Color.AZURE);
    parallelogram.setStroke(Color.BLACK);

    // Create a hexagon
    Polyline hexagon = new Polyline(100.0, 0.0, 120.0, 20.0, 110.0, 140.0, 100.0, 60.0, 80.0, 40.0, 80.0, 120.0,
            100.0, 0.0);
    hexagon.setFill(Color.WHITE);
    hexagon.setStroke(Color.BLACK);

    // A CHORD arc with no fill and a stroke
    Arc arc = new Arc(0, 0, 50, 100, 0, 90);
    arc.setFill(Color.TRANSPARENT);
    arc.setStroke(Color.BLACK);
    arc.setType(ArcType.CHORD);

    // Add all shapes to an HBox
    HBox root = new HBox(circle, rect, line, parallelogram, hexagon, arc);
    root.setSpacing(10);
    root.setStyle("-fx-padding: 10;" + "-fx-border-style: solid inside;" + "-fx-border-width: 2;"
            + "-fx-border-insets: 5;" + "-fx-border-radius: 5;" + "-fx-border-color: blue;");

    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.setTitle("2D Shapes");
    stage.show();
}

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

public FXVisualizationViewer(INetworkViewPort port) {

    this.port = port;
    // create canvas
    this.setStyle("-fx-background-color: #213245");

    for (double divide = .25; divide < 1; divide += .25) {
        final Line line = new Line(0, 200, this.getWidth(), this.getHeight());
        line.setFill(null);//from  www.j  av a 2s.  c o m
        line.setStroke(Color.web("0x385172"));
        line.setStrokeWidth(1.3);
        line.getStrokeDashArray().addAll(5d, 10d);

        line.startYProperty().bind(this.heightProperty().multiply(divide));

        line.endXProperty().bind(this.widthProperty());
        line.endYProperty().bind(this.heightProperty().multiply(divide));

        this.getChildren().add(line);
    }

    for (double divide = .25; divide < 1; divide += .25) {
        final Line line = new Line(0, 0, this.getWidth(), this.getHeight());
        line.setFill(null);
        line.setStroke(Color.web("0x385172"));
        line.setStrokeWidth(1.3);
        line.getStrokeDashArray().addAll(5d, 10d);

        line.startXProperty().bind(this.widthProperty().multiply(divide));

        line.endXProperty().bind(this.widthProperty().multiply(divide));
        line.endYProperty().bind(this.heightProperty());

        this.getChildren().add(line);
    }

    //StackPane spane = new StackPane();
    //spane.setBackground(new Background(new BackgroundFill(Color.BEIGE, null, null)));

    Pane ghost = new Pane();
    canvas = new PannableCanvas(ghost);

    Pane parent = new Pane();
    parent.getChildren().add(ghost);
    parent.getChildren().add(canvas);

    SceneGestures sceneGestures = new SceneGestures(parent, canvas);

    addEventFilter(MouseEvent.MOUSE_PRESSED, sceneGestures.getOnMousePressedEventHandler());
    addEventFilter(MouseEvent.MOUSE_DRAGGED, sceneGestures.getOnMouseDraggedEventHandler());
    addEventFilter(ScrollEvent.ANY, sceneGestures.getOnScrollEventHandler());

    new RubberBandSelection(this);

    // TODO make canvas transparent
    //canvas.setStyle("-fx-background-color: #1d1d1d");

    // we don't want the canvas on the top/left in this example => just
    // translate it a bit
    //canvas.setTranslateX(100);
    //canvas.setTranslateY(100);

    // create sample nodes which can be dragged
    nodeGestures = new NodeGestures();
    //this.getChildren().add(spane);
    this.getChildren().add(parent);

    this.layout = port.getDelegate();

    //this.layout.getGraph().getVertices().forEach(v -> Platform.runLater(() -> this.initVertex(v)));
    //this.layout.getGraph().getEdges().forEach(e -> Platform.runLater(() -> this.initEdge(e)));

    this.layout.getObservableGraph().addGraphEventListener(e -> {

        //Platform.runLater(() -> {

        switch (e.getType()) {
        case VERTEX_ADDED:
            final INode node = ((GraphEvent.Vertex<INode, IConnection>) e).getVertex();
            Platform.runLater(() -> initVertex(node));
            break;

        case EDGE_ADDED:
            final IConnection edge = ((GraphEvent.Edge<INode, IConnection>) e).getEdge();
            Platform.runLater(() -> initEdge(edge));
            break;

        case VERTEX_CHANGED:
            break;

        case EDGE_CHANGED:
            final IConnection changedEdge = ((GraphEvent.Edge<INode, IConnection>) e).getEdge();
            Platform.runLater(() -> changedEdge.getComponent(ViewComponent.class).getRenderer().animate());
            break;
        }
        //});
    });

}

From source file:de.pixida.logtest.designer.automaton.RectangularNode.java

private Line createLineBetweenTwoPoints(final Point2D from, final Point2D to) {
    return new Line(from.getX(), from.getY(), to.getX(), to.getY());
}

From source file:com.github.vatbub.tictactoe.view.Main.java

private void addWinLineOnWin(Board.WinnerInfo winnerInfo, Paint color, Runnable onFinished) {
    Line originLine = new Line(0, 0, 0, 0);
    winLineGroup.getChildren().add(originLine);

    WinLine winLine = new WinLine(winnerInfo);
    double winLineEndX = winLine.endArc.getCenterX();
    double winLineEndY = winLine.endArc.getCenterY();
    winLine.startArc.setFill(color);/* w w  w.ja v  a2  s  . c  o  m*/
    winLine.startArc.setStrokeWidth(0);
    winLine.endArc.setFill(color);
    winLine.endArc.setStrokeWidth(0);
    winLine.rightLine.setStrokeWidth(0);
    winLine.leftLine.setStrokeWidth(0);
    winLine.centerLine.setStroke(color);

    winLine.centerLine.strokeWidthProperty().bind(winLine.startArc.radiusXProperty().multiply(2));
    winLineGroup.getChildren().addAll(winLine.getAll());

    blurNode(gamePane, 4);

    winLineGroup.setOpacity(0);
    GaussianBlur blur = new GaussianBlur(100);
    winLineGroup.setEffect(blur);
    winLineGroup.setBlendMode(BlendMode.DARKEN);
    winLineGroup.setVisible(true);

    double winLineAnimationX1 = 0.2;
    double winLineAnimationX2 = 0.5;

    KeyValue stretchKeyValue1x = new KeyValue(winLine.endArc.centerXProperty(), winLine.startArc.getCenterX());
    KeyValue stretchKeyValue1y = new KeyValue(winLine.endArc.centerYProperty(), winLine.startArc.getCenterY());
    KeyFrame stretchKeyFrame1 = new KeyFrame(Duration.millis(0), stretchKeyValue1x, stretchKeyValue1y);

    KeyValue stretchKeyValue2x = new KeyValue(winLine.endArc.centerXProperty(), winLine.startArc.getCenterX(),
            new CustomEaseBothInterpolator(winLineAnimationX1, winLineAnimationX2));
    KeyValue stretchKeyValue2y = new KeyValue(winLine.endArc.centerYProperty(), winLine.startArc.getCenterY(),
            new CustomEaseBothInterpolator(winLineAnimationX1, winLineAnimationX2));
    KeyFrame stretchKeyFrame2 = new KeyFrame(Duration.millis(100), stretchKeyValue2x, stretchKeyValue2y);

    KeyValue stretchKeyValue3x = new KeyValue(winLine.endArc.centerXProperty(), winLineEndX,
            new CustomEaseBothInterpolator(winLineAnimationX1, winLineAnimationX2));
    KeyValue stretchKeyValue3y = new KeyValue(winLine.endArc.centerYProperty(), winLineEndY,
            new CustomEaseBothInterpolator(winLineAnimationX1, winLineAnimationX2));
    KeyFrame stretchKeyFrame3 = new KeyFrame(Duration.millis(800), stretchKeyValue3x, stretchKeyValue3y);

    KeyValue opacityKeyValue1 = new KeyValue(winLineGroup.opacityProperty(), 0.8);
    KeyFrame opacityKeyFrame1 = new KeyFrame(Duration.millis(400), opacityKeyValue1);

    Timeline timeline = new Timeline();
    timeline.getKeyFrames().addAll(stretchKeyFrame1, stretchKeyFrame2, stretchKeyFrame3, opacityKeyFrame1);
    timeline.play();

    timeline.setOnFinished((event) -> onFinished.run());
}

From source file:com.github.vatbub.tictactoe.view.Main.java

private void addWinLineOnLoose(Board.WinnerInfo winnerInfo) {
    final double strokeWidth = 2;

    Line originLine = new Line(0, 0, 0, 0);
    winLineGroup.getChildren().add(originLine);

    WinLine winLine = new WinLine(winnerInfo);
    winLine.startArc.setFill(Color.TRANSPARENT);
    winLine.startArc.setStroke(Color.BLACK);
    winLine.startArc.setStrokeWidth(strokeWidth);
    winLine.endArc.setFill(Color.TRANSPARENT);
    winLine.endArc.setStroke(Color.BLACK);
    winLine.endArc.setStrokeWidth(strokeWidth);
    winLine.rightLine.setStrokeWidth(strokeWidth);
    winLine.leftLine.setStrokeWidth(strokeWidth);

    winLine.centerLine.setStrokeWidth(0);
    winLineGroup.getChildren().addAll(winLine.getAll());

    winLineGroup.setOpacity(0);/*from  w  ww  .j a va 2s  . co  m*/
    GaussianBlur blur = new GaussianBlur(7);
    winLineGroup.setEffect(blur);
    winLineGroup.setVisible(true);
    KeyValue keyValue1 = new KeyValue(winLineGroup.opacityProperty(), 0);
    KeyFrame keyFrame1 = new KeyFrame(Duration.millis(900), keyValue1);
    KeyValue keyValue2 = new KeyValue(winLineGroup.opacityProperty(), 1);
    KeyFrame keyFrame2 = new KeyFrame(Duration.millis(950), keyValue2);

    Timeline timeline = new Timeline();
    timeline.getKeyFrames().addAll(keyFrame1, keyFrame2);
    timeline.play();
}

From source file:editeurpanovisu.EditeurPanovisu.java

private ScrollPane afficheLegende() {
    double positionX = 0;
    double positionY = 0;
    AnchorPane apLegende = new AnchorPane();
    ScrollPane spLegende = new ScrollPane(apLegende);
    spLegende.getStyleClass().add("legendePane");

    apLegende.setMinWidth(1000);//from   ww w.j  a  v a  2s .  c o  m
    apLegende.setMinHeight(150);
    apLegende.setPrefWidth(1000);
    apLegende.setPrefHeight(150);
    apLegende.setMaxWidth(1000);
    apLegende.setMaxHeight(150);
    positionY = (pano.getLayoutY() + pano.getPrefHeight() + 10);

    Circle point = new Circle(30, 20, 5);
    point.setFill(Color.YELLOW);
    point.setStroke(Color.RED);
    point.setCursor(Cursor.DEFAULT);
    Circle point2 = new Circle(30, 60, 5);
    point2.setFill(Color.BLUE);
    point2.setStroke(Color.YELLOW);
    point2.setCursor(Cursor.DEFAULT);
    Circle point3 = new Circle(30, 100, 5);
    point3.setFill(Color.GREEN);
    point3.setStroke(Color.YELLOW);
    point3.setCursor(Cursor.DEFAULT);
    Polygon polygon = new Polygon();
    polygon.getPoints().addAll(new Double[] { 15.0, 2.0, 2.0, 2.0, 2.0, 15.0, -2.0, 15.0, -2.0, 2.0, -15.0, 2.0,
            -15.0, -2.0, -2.0, -2.0, -2.0, -15.0, 2.0, -15.0, 2.0, -2.0, 15.0, -2.0 });
    polygon.setStrokeLineJoin(StrokeLineJoin.MITER);
    polygon.setFill(Color.BLUEVIOLET);
    polygon.setStroke(Color.YELLOW);
    polygon.setId("PoV");
    polygon.setLayoutX(500);
    polygon.setLayoutY(20);
    Label lblHS = new Label(rb.getString("main.legendeHS"));
    Label lblHSImage = new Label(rb.getString("main.legendeHSImage"));
    //Label lblHSHTML = new Label(rb.getString("main.legendeHSHTML"));
    Label lblPoV = new Label(rb.getString("main.legendePoV"));
    Label lblNord = new Label(rb.getString("main.legendeNord"));
    Line ligneNord = new Line(500, 45, 500, 65);
    ligneNord.setStroke(Color.RED);
    ligneNord.setStrokeWidth(3);
    lblHS.setLayoutX(50);
    lblHS.setLayoutY(10);
    lblHSImage.setLayoutX(50);
    lblHSImage.setLayoutY(50);
    //lblHSHTML.setLayoutX(50);
    //lblHSHTML.setLayoutY(90);
    lblPoV.setLayoutX(520);
    lblPoV.setLayoutY(10);
    lblNord.setLayoutX(520);
    lblNord.setLayoutY(50);
    //        apLegende.getChildren().addAll(lblHS, point, lblHSImage, point2, lblHSHTML, point3, lblPoV, polygon, lblNord, ligneNord);
    apLegende.getChildren().addAll(lblHS, point, lblHSImage, point2, lblPoV, polygon, lblNord, ligneNord);
    apLegende.setId("legende");
    apLegende.setVisible(true);
    if (largeurMax - 50 < 1004) {
        spLegende.setPrefWidth(largeurMax - 50);
        spLegende.setMaxWidth(largeurMax - 50);
        positionX = 25;
    } else {
        spLegende.setPrefWidth(1004);
        spLegende.setMaxWidth(1004);
        positionX = (largeurMax - 1004) / 2.d;
    }
    spLegende.setLayoutX(positionX);
    spLegende.setLayoutY(positionY);
    spLegende.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
    spLegende.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);

    return spLegende;
}

From source file:editeurpanovisu.EditeurPanovisu.java

private void afficheNord(double longitude) {
    double largeur = imagePanoramique.getFitWidth();
    double X = (longitude + 180.0d) * largeur / 360.0d + imagePanoramique.getLayoutX();
    Node ancPoV = (Node) pano.lookup("#Nord");
    if (ancPoV != null) {
        pano.getChildren().remove(ancPoV);
    }/*from  w w w.  jav a2  s. c  o m*/
    Line ligne = new Line(0, 0, 0, imagePanoramique.getFitHeight());
    ligne.setCursor(Cursor.DEFAULT);

    ligne.setLayoutX(X);
    ligne.setStroke(Color.RED);
    ligne.setStrokeWidth(4);
    ligne.setId("Nord");
    ligne.setOnDragDetected((MouseEvent me1) -> {
        ligne.setStroke(Color.BLUEVIOLET);
        dragDrop = true;
        me1.consume();
    });
    ligne.setOnMouseDragged((MouseEvent me1) -> {

        double XX = me1.getSceneX() - imagePanoramique.getLayoutX();
        if (XX < 0) {
            XX = 0;
        }
        if (XX > imagePanoramique.getFitWidth()) {
            XX = imagePanoramique.getFitWidth();
        }
        ligne.setLayoutX(XX + imagePanoramique.getLayoutX());
        me1.consume();

    });
    ligne.setOnMouseReleased((MouseEvent me1) -> {
        double X1 = me1.getSceneX();
        double mouseX1 = X1 - imagePanoramique.getLayoutX();
        if (mouseX1 < 0) {
            mouseX1 = 0;
        }
        if (mouseX1 > imagePanoramique.getFitWidth()) {
            mouseX1 = imagePanoramique.getFitWidth();
        }
        double regardX = 360.0f * mouseX1 / largeur - 180;
        panoramiquesProjet[panoActuel].setZeroNord(regardX);
        ligne.setStroke(Color.RED);
        me1.consume();

    });

    pano.getChildren().add(ligne);
}