Search in sources :

Example 11 with FxGraphRenderer

use of org.graphstream.ui.javafx.FxGraphRenderer in project gs-ui-javafx by graphstream.

the class TestStars method run.

private void run() {
    MultiGraph graph = new MultiGraph("TestSprites");
    Viewer viewer = new FxViewer(graph, FxViewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
    ViewerPipe pipeIn = viewer.newViewerPipe();
    FxDefaultView view = (FxDefaultView) viewer.addView("view1", new FxGraphRenderer());
    DefaultApplication.init(view, graph);
    new Thread(() -> Application.launch(DefaultApplication.class)).start();
    pipeIn.addAttributeSink(graph);
    pipeIn.addViewerListener(this);
    pipeIn.pump();
    graph.setAttribute("ui.stylesheet", styleSheet);
    graph.setAttribute("ui.antialias");
    graph.setAttribute("ui.quality");
    Node A = graph.addNode("A");
    Node B = graph.addNode("B");
    Node C = graph.addNode("C");
    Node D = graph.addNode("D");
    Node E = graph.addNode("E");
    graph.addEdge("AB", "A", "B");
    graph.addEdge("BC", "B", "C");
    graph.addEdge("CD", "C", "D");
    graph.addEdge("DA", "D", "A");
    graph.addEdge("DE", "D", "E");
    graph.addEdge("EB", "E", "B");
    A.setAttribute("xyz", new double[] { 0, 1, 0 });
    B.setAttribute("xyz", new double[] { 1.5, 1, 0 });
    C.setAttribute("xyz", new double[] { 1, 0, 0 });
    D.setAttribute("xyz", new double[] { 0, 0, 0 });
    E.setAttribute("xyz", new double[] { 0.4, 0.6, 0 });
    SpriteManager sman = new SpriteManager(graph);
    sman.setSpriteFactory(new MySpriteFactory());
    MySprite s1 = (MySprite) sman.addSprite("S1");
    MySprite s2 = (MySprite) sman.addSprite("S2");
    MySprite s3 = (MySprite) sman.addSprite("S3");
    s1.attachToEdge("AB");
    s2.attachToEdge("CD");
    s3.attachToEdge("DA");
    while (loop) {
        pipeIn.pump();
        s1.move();
        s2.move();
        s3.move();
        sleep(10);
    }
    System.out.println("bye bye");
    System.exit(0);
}
Also used : FxViewer(org.graphstream.ui.fx_viewer.FxViewer) FxGraphRenderer(org.graphstream.ui.javafx.FxGraphRenderer) Node(org.graphstream.graph.Node) FxViewer(org.graphstream.ui.fx_viewer.FxViewer) Viewer(org.graphstream.ui.view.Viewer) FxDefaultView(org.graphstream.ui.fx_viewer.FxDefaultView) SpriteManager(org.graphstream.ui.spriteManager.SpriteManager) MultiGraph(org.graphstream.graph.implementations.MultiGraph) ViewerPipe(org.graphstream.ui.view.ViewerPipe)

Aggregations

FxViewer (org.graphstream.ui.fx_viewer.FxViewer)11 FxGraphRenderer (org.graphstream.ui.javafx.FxGraphRenderer)11 FxDefaultView (org.graphstream.ui.fx_viewer.FxDefaultView)10 MultiGraph (org.graphstream.graph.implementations.MultiGraph)9 Node (org.graphstream.graph.Node)8 ViewerPipe (org.graphstream.ui.view.ViewerPipe)8 Viewer (org.graphstream.ui.view.Viewer)7 Scene (javafx.scene.Scene)4 WindowEvent (javafx.stage.WindowEvent)3 Edge (org.graphstream.graph.Edge)3 SpriteManager (org.graphstream.ui.spriteManager.SpriteManager)3 DorogovtsevMendesGenerator (org.graphstream.algorithm.generator.DorogovtsevMendesGenerator)2 Point3 (org.graphstream.ui.geom.Point3)2 Random (java.util.Random)1 GridPane (javafx.scene.layout.GridPane)1 StackPane (javafx.scene.layout.StackPane)1 IdAlreadyInUseException (org.graphstream.graph.IdAlreadyInUseException)1 SingleGraph (org.graphstream.graph.implementations.SingleGraph)1 ThreadProxyPipe (org.graphstream.stream.thread.ThreadProxyPipe)1 FxViewPanel (org.graphstream.ui.fx_viewer.FxViewPanel)1