Search in sources :

Example 11 with ViewerPipe

use of org.graphstream.ui.view.ViewerPipe 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

ViewerPipe (org.graphstream.ui.view.ViewerPipe)11 MultiGraph (org.graphstream.graph.implementations.MultiGraph)10 Node (org.graphstream.graph.Node)9 FxViewer (org.graphstream.ui.fx_viewer.FxViewer)9 FxDefaultView (org.graphstream.ui.fx_viewer.FxDefaultView)8 FxGraphRenderer (org.graphstream.ui.javafx.FxGraphRenderer)8 Viewer (org.graphstream.ui.view.Viewer)8 Edge (org.graphstream.graph.Edge)3 SpriteManager (org.graphstream.ui.spriteManager.SpriteManager)3 Scene (javafx.scene.Scene)2 WindowEvent (javafx.stage.WindowEvent)2 DorogovtsevMendesGenerator (org.graphstream.algorithm.generator.DorogovtsevMendesGenerator)2 Graph (org.graphstream.graph.Graph)2 Point3 (org.graphstream.ui.geom.Point3)2 Random (java.util.Random)1 IdAlreadyInUseException (org.graphstream.graph.IdAlreadyInUseException)1 SingleGraph (org.graphstream.graph.implementations.SingleGraph)1 FxMouseManager (org.graphstream.ui.fx_viewer.util.FxMouseManager)1 ImageCache (org.graphstream.ui.javafx.util.ImageCache)1 Sprite (org.graphstream.ui.spriteManager.Sprite)1