Search in sources :

Example 1 with FxViewer

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

the class TestTwoViewersInOneFrame method start.

public void start(Stage primaryStage) throws Exception {
    MultiGraph graph1 = new MultiGraph("g1");
    MultiGraph graph2 = new MultiGraph("g2");
    ThreadProxyPipe pipe1 = new ThreadProxyPipe();
    pipe1.init(graph1);
    ThreadProxyPipe pipe2 = new ThreadProxyPipe();
    pipe2.init(graph2);
    Viewer viewer1 = new FxViewer(pipe1);
    Viewer viewer2 = new FxViewer(pipe2);
    graph1.setAttribute("ui.quality");
    graph2.setAttribute("ui.quality");
    graph1.setAttribute("ui.antialias");
    graph2.setAttribute("ui.antialias");
    graph1.setAttribute("ui.stylesheet", styleSheet1);
    graph2.setAttribute("ui.stylesheet", styleSheet2);
    FxDefaultView view1 = new FxDefaultView(viewer1, "view1", new FxGraphRenderer());
    FxDefaultView view2 = new FxDefaultView(viewer2, "view2", new FxGraphRenderer());
    viewer1.addView(view1);
    viewer2.addView(view2);
    viewer1.enableAutoLayout();
    viewer2.enableAutoLayout();
    DorogovtsevMendesGenerator gen = new DorogovtsevMendesGenerator();
    gen.addSink(graph1);
    gen.addSink(graph2);
    gen.begin();
    for (int i = 0; i < 100; i++) gen.nextEvents();
    gen.end();
    gen.removeSink(graph1);
    gen.removeSink(graph2);
    GridPane gridpane = new GridPane();
    gridpane.add(view1, 1, 0);
    gridpane.add(view2, 2, 0);
    Scene scene = new Scene(gridpane, 800, 600, true, SceneAntialiasing.BALANCED);
    primaryStage.setScene(scene);
    primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {

        @Override
        public void handle(WindowEvent t) {
            Platform.exit();
            System.exit(0);
        }
    });
    primaryStage.show();
}
Also used : ThreadProxyPipe(org.graphstream.stream.thread.ThreadProxyPipe) GridPane(javafx.scene.layout.GridPane) FxGraphRenderer(org.graphstream.ui.javafx.FxGraphRenderer) FxViewer(org.graphstream.ui.fx_viewer.FxViewer) Viewer(org.graphstream.ui.view.Viewer) DorogovtsevMendesGenerator(org.graphstream.algorithm.generator.DorogovtsevMendesGenerator) FxDefaultView(org.graphstream.ui.fx_viewer.FxDefaultView) Scene(javafx.scene.Scene) MultiGraph(org.graphstream.graph.implementations.MultiGraph) FxViewer(org.graphstream.ui.fx_viewer.FxViewer) WindowEvent(javafx.stage.WindowEvent)

Example 2 with FxViewer

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

the class TestFreePlane method run.

private void run(String[] args) {
    MultiGraph graph = new MultiGraph("g1");
    FxViewer 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 root = graph.addNode("root");
    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");
    Node F = graph.addNode("F");
    Node G = graph.addNode("G");
    Node H = graph.addNode("H");
    graph.addEdge("rA", "root", "A");
    graph.addEdge("rB", "root", "B");
    graph.addEdge("rC", "root", "C");
    graph.addEdge("rD", "root", "D");
    graph.addEdge("rE", "root", "E");
    graph.addEdge("AF", "A", "F");
    graph.addEdge("CG", "C", "G");
    graph.addEdge("DH", "D", "H");
    root.setAttribute("xyz", new double[] { 0, 0, 0 });
    A.setAttribute("xyz", new double[] { 1, 1, 0 });
    B.setAttribute("xyz", new double[] { 1, 0, 0 });
    C.setAttribute("xyz", new double[] { -1, 1, 0 });
    D.setAttribute("xyz", new double[] { -1, 0, 0 });
    E.setAttribute("xyz", new double[] { -1, -1, 0 });
    F.setAttribute("xyz", new double[] { 2, 1.2, 0 });
    G.setAttribute("xyz", new double[] { -2, 1.2, 0 });
    H.setAttribute("xyz", new double[] { -2, -.5, 0 });
    root.setAttribute("label", "Idea");
    A.setAttribute("label", "Topic1");
    B.setAttribute("label", "Topic2");
    C.setAttribute("label", "Topic3");
    D.setAttribute("label", "Topic4");
    E.setAttribute("label", "Topic5");
    F.setAttribute("label", "SubTopic1");
    G.setAttribute("label", "SubTopic2");
    H.setAttribute("label", "Very Long Sub Topic ...");
    while (loop) {
        pipeIn.pump();
        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) FxDefaultView(org.graphstream.ui.fx_viewer.FxDefaultView) MultiGraph(org.graphstream.graph.implementations.MultiGraph) ViewerPipe(org.graphstream.ui.view.ViewerPipe)

Example 3 with FxViewer

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

the class AllFxTest method start.

public void start(Stage primaryStage) throws Exception {
    MultiGraph g = new MultiGraph("mg");
    FxViewer v = new FxViewer(g, FxViewer.ThreadingModel.GRAPH_IN_GUI_THREAD);
    DorogovtsevMendesGenerator gen = new DorogovtsevMendesGenerator();
    g.setAttribute("ui.antialias");
    g.setAttribute("ui.quality");
    g.setAttribute("ui.stylesheet", styleSheet);
    v.enableAutoLayout();
    FxViewPanel panel = (FxViewPanel) v.addDefaultView(false, new FxGraphRenderer());
    gen.addSink(g);
    gen.begin();
    for (int i = 0; i < 100; i++) gen.nextEvents();
    gen.end();
    gen.removeSink(g);
    Scene scene = new Scene(panel, 800, 600);
    primaryStage.setScene(scene);
    primaryStage.show();
}
Also used : FxViewer(org.graphstream.ui.fx_viewer.FxViewer) FxViewPanel(org.graphstream.ui.fx_viewer.FxViewPanel) FxGraphRenderer(org.graphstream.ui.javafx.FxGraphRenderer) DorogovtsevMendesGenerator(org.graphstream.algorithm.generator.DorogovtsevMendesGenerator) Scene(javafx.scene.Scene) MultiGraph(org.graphstream.graph.implementations.MultiGraph)

Example 4 with FxViewer

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

the class Display method display.

@Override
public Viewer display(Graph graph, boolean autoLayout) {
    FxViewer viewer = new FxViewer(graph, FxViewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
    GraphRenderer renderer = new FxGraphRenderer();
    FxDefaultView view = (FxDefaultView) viewer.addView(FxViewer.DEFAULT_VIEW_ID, renderer);
    if (autoLayout) {
        Layout layout = Layouts.newLayoutAlgorithm();
        viewer.enableAutoLayout(layout);
    }
    if (!instanceJavaFX) {
        instanceJavaFX = true;
        DefaultApplication.init(view, graph);
        new Thread(() -> {
            try {
                Application.launch(DefaultApplication.class);
            } catch (Exception e) {
                newDisplay(view);
            }
        }).start();
    } else {
        newDisplay(view);
    }
    return viewer;
}
Also used : FxViewer(org.graphstream.ui.fx_viewer.FxViewer) FxGraphRenderer(org.graphstream.ui.javafx.FxGraphRenderer) GraphRenderer(org.graphstream.ui.view.GraphRenderer) Layout(org.graphstream.ui.layout.Layout) FxGraphRenderer(org.graphstream.ui.javafx.FxGraphRenderer) DefaultApplication(org.graphstream.ui.fx_viewer.util.DefaultApplication) FxDefaultView(org.graphstream.ui.fx_viewer.FxDefaultView)

Example 5 with FxViewer

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

the class BTest method run.

public void run() {
    try {
        MultiGraph graph = new MultiGraph("TestSize");
        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");
        Node F = graph.addNode("F");
        Edge AB = graph.addEdge("AB", "A", "B", true);
        Edge BC = graph.addEdge("BC", "B", "C", true);
        Edge CD = graph.addEdge("CD", "C", "D", true);
        Edge DA = graph.addEdge("DA", "D", "A", true);
        Edge BB = graph.addEdge("BB", "B", "B", true);
        Edge DE = graph.addEdge("DE", "D", "E", true);
        Edge DF = graph.addEdge("DF", "D", "F", true);
        Edge CF = graph.addEdge("CF", "C", "F", true);
        A.setAttribute("xyz", new double[] { 0, 1, 0 });
        B.setAttribute("xyz", new double[] { 1, 0.8, 0 });
        C.setAttribute("xyz", new double[] { 0.8, 0, 0 });
        D.setAttribute("xyz", new double[] { 0, 0, 0 });
        E.setAttribute("xyz", new double[] { 0.5, 0.5, 0 });
        F.setAttribute("xyz", new double[] { 0.5, 0.25, 0 });
        A.setAttribute("label", "A");
        B.setAttribute("label", "Long label ...");
        C.setAttribute("label", "C");
        D.setAttribute("label", "A long label ...");
        E.setAttribute("label", "Another very long label");
        F.setAttribute("label", "F");
        double size = 20f;
        double sizeInc = 1f;
        while (loop) {
            pipeIn.pump();
            sleep(40);
            A.setAttribute("ui.size", size);
            size += sizeInc;
            if (size > 50) {
                sizeInc = -1f;
                size = 50f;
            } else if (size < 20) {
                sizeInc = 1f;
                size = 20f;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    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) Edge(org.graphstream.graph.Edge) MultiGraph(org.graphstream.graph.implementations.MultiGraph) ViewerPipe(org.graphstream.ui.view.ViewerPipe)

Aggregations

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