Example usage for javafx.scene.shape Line getStrokeDashArray

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

Introduction

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

Prototype

public final ObservableList<Double> getStrokeDashArray() 

Source Link

Document

Defines the array representing the lengths of the dash segments.

Usage

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 .j  a  va2 s .c o m
    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);/*from   w w  w .  jav a2s.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

private Line connect(Circle c1, Circle c2) {
    Line line = new Line();

    line.startXProperty().bind(c1.centerXProperty());
    line.startYProperty().bind(c1.centerYProperty());

    line.endXProperty().bind(c2.centerXProperty());
    line.endYProperty().bind(c2.centerYProperty());

    line.setStrokeWidth(1);/* w  w  w  .j a v  a 2 s.co m*/
    line.setStrokeLineCap(StrokeLineCap.BUTT);
    line.getStrokeDashArray().setAll(1.0, 4.0);

    return line;
}

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  w  w  w  .ja  va2 s  .  co  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;
        }
        //});
    });

}