package testing;

import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.stage.Stage;
import jfxtras.labs.util.event.MouseControlUtil;
import layout.PhysLayout;
import physics.Spring;
import physics.SpringSimulation;

/**
 *
 * @author Christoph Burschka &lt;christoph@burschka.de&gt;
 */
public class Main extends Application {
    private static final int NODE_COUNT = 10;
    private static final int NODE_SIZE = 10;
    private static final int WIDTH = 1024;
    private static final int HEIGHT = 768;

    @Override
    public void start(Stage primaryStage) {
        Pane root = new Pane();
        PhysLayout layout = new PhysLayout(root);
        Scene scene = new Scene(root, WIDTH, HEIGHT);
        primaryStage.setTitle("Springs");

        Circle[] nodes = new Circle[NODE_COUNT];

        Circle anchor = new Circle();
        anchor.setFill(Color.BLACK);

        anchor.relocate(WIDTH * 0.5, HEIGHT * 0.5);
        anchor.setRadius(NODE_SIZE);
        root.getChildren().add(anchor);

        for (int i = 0; i < NODE_COUNT; i++) {
            nodes[i] = new Circle();
            nodes[i].setFill(Color.hsb(360.0 * i / NODE_COUNT, 1.0, 0.5));
            nodes[i].relocate(Math.random() * WIDTH, Math.random() * HEIGHT);
            nodes[i].setRadius(NODE_SIZE);
            root.getChildren().add(nodes[i]);
            MouseControlUtil.makeDraggable(nodes[i]);
        }
        MouseControlUtil.makeDraggable(anchor);
        double radius = Math.min(WIDTH, HEIGHT) / 3;
        Spring radial = new Spring(radius, 10);
        Spring segment = new Spring(Math.PI * radius * 2 / NODE_COUNT, 10);

        for (int i = 0; i < NODE_COUNT; i++) {
            layout.addConnection(nodes[i], nodes[(i + 1) % NODE_COUNT], segment);
            layout.addConnection(nodes[i], nodes[(NODE_COUNT + i - 1) % NODE_COUNT], segment);
            layout.addConnection(nodes[i], anchor, radial);
            layout.setMass(nodes[i], 1);
        }

        // This part stays put.
        layout.setMass(anchor, Double.POSITIVE_INFINITY);
        SpringSimulation simulation = new SpringSimulation(layout);

        primaryStage.setScene(scene);
        primaryStage.show();
        simulation.runSimulation(1e-2);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

}

@@ -1858,32 +1858,970 @@
 E_COUNT; i++) %7B%0A
+%0A            Line line = new Line();%0A            line.setFill(Color.BLACK);%0A            line.setStroke(Color.BLACK);%0A            line.startXProperty().bind(nodes%5Bi%5D.layoutXProperty());%0A            line.startYProperty().bind(nodes%5Bi%5D.layoutYProperty());%0A            line.endXProperty().bind(nodes%5B(i + 1) %25 NODE_COUNT%5D.layoutXProperty());%0A            line.endYProperty().bind(nodes%5B(i + 1) %25 NODE_COUNT%5D.layoutYProperty());%0A            root.getChildren().add(line);%0A            line.toBack();%0A%0A            line = new Line();%0A            line.setFill(Color.BLACK);%0A            line.setStroke(Color.BLACK);%0A            line.startXProperty().bind(nodes%5Bi%5D.layoutXProperty());%0A            line.startYProperty().bind(nodes%5Bi%5D.layoutYProperty());%0A            line.endXProperty().bind(anchor.layoutXProperty());%0A            line.endYProperty().bind(anchor.layoutYProperty());%0A            root.getChildren().add(line);%0A            line.toBack();%0A%0A
             layo

Add lines between connected nodes in the example.