Search in sources :

Example 6 with MultiGraph

use of org.graphstream.graph.implementations.MultiGraph in project gs-ui-javafx by graphstream.

the class TextDynColor method main.

public static void main(String[] args) {
    System.setProperty("org.graphstream.ui", "org.graphstream.ui.javafx.util.Display");
    MultiGraph g = new MultiGraph("foo");
    g.setAttribute("ui.stylesheet", "node { fill-mode: dyn-plain; stroke-mode: plain; stroke-width: 1px; } edge { fill-mode: dyn-plain; }");
    g.addNode("A");
    g.addNode("B");
    g.addNode("C");
    g.addEdge("AB", "A", "B");
    g.addEdge("BC", "B", "C");
    g.addEdge("CA", "C", "A");
    g.display();
    g.getNode("A").setAttribute("ui.color", Color.RED);
    g.getNode("B").setAttribute("ui.color", Color.GREEN);
    g.getNode("C").setAttribute("ui.color", Color.BLUE);
    g.getEdge("AB").setAttribute("ui.color", Color.YELLOW);
    g.getEdge("BC").setAttribute("ui.color", Color.MAGENTA);
    g.getEdge("CA").setAttribute("ui.color", Color.CYAN);
}
Also used : MultiGraph(org.graphstream.graph.implementations.MultiGraph)

Example 7 with MultiGraph

use of org.graphstream.graph.implementations.MultiGraph in project gs-ui-javafx by graphstream.

the class DemoAllInFx method start.

@Override
public void start(Stage primaryStage) throws Exception {
    Graph graph = new MultiGraph("mg");
    FxViewer viewer = new FxViewer(graph, FxViewer.ThreadingModel.GRAPH_IN_GUI_THREAD);
    graph.addNode("A");
    graph.addNode("B");
    graph.addNode("C");
    graph.addEdge("AB", "A", "B");
    graph.addEdge("BC", "B", "C");
    graph.addEdge("CA", "C", "A");
    graph.setAttribute("ui.antialias");
    graph.setAttribute("ui.quality");
    graph.setAttribute("ui.stylesheet", styleSheet);
    graph.getNode("A").setAttribute("xyz", -1, 0, 0);
    graph.getNode("B").setAttribute("xyz", 1, 0, 0);
    graph.getNode("C").setAttribute("xyz", 0, 1, 0);
    // On ins�re la vue principale du viewer dans la JFrame.
    FxViewPanel v = (FxViewPanel) viewer.addDefaultView(false);
    Scene scene = new Scene(v, 800, 600);
    primaryStage.setScene(scene);
    primaryStage.show();
}
Also used : FxViewer(org.graphstream.ui.fx_viewer.FxViewer) Graph(org.graphstream.graph.Graph) MultiGraph(org.graphstream.graph.implementations.MultiGraph) FxViewPanel(org.graphstream.ui.fx_viewer.FxViewPanel) Scene(javafx.scene.Scene) MultiGraph(org.graphstream.graph.implementations.MultiGraph)

Example 8 with MultiGraph

use of org.graphstream.graph.implementations.MultiGraph 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)

Example 9 with MultiGraph

use of org.graphstream.graph.implementations.MultiGraph in project gs-ui-javafx by graphstream.

the class DemoTwoGraphsInOneViewerFx method start.

@Override
public void start(Stage primaryStage) throws Exception {
    Graph graph1 = new MultiGraph("g1");
    Graph graph2 = new MultiGraph("g2");
    FxViewer viewer1 = new FxViewer(new ThreadProxyPipe(graph1));
    FxViewer viewer2 = new FxViewer(new ThreadProxyPipe(graph2));
    graph1.setAttribute("ui.stylesheet", styleSheet1);
    graph2.setAttribute("ui.stylesheet", styleSheet2);
    // View view1 =
    FxViewPanel view1 = (FxViewPanel) viewer1.addDefaultView(true);
    FxViewPanel view2 = (FxViewPanel) viewer2.addDefaultView(true);
    viewer1.enableAutoLayout();
    viewer2.enableAutoLayout();
    // view1.setBackLayerRenderer(view2);
    FileSourceDGS dgs = new FileSourceDGS();
    dgs.addSink(graph1);
    try {
        dgs.begin(getClass().getResourceAsStream(GRAPH));
        for (int i = 0; i < 100 && dgs.nextEvents(); i++) ;
        dgs.end();
    } catch (IOException e1) {
        e1.printStackTrace();
        System.exit(1);
    }
    dgs.removeSink(graph1);
    dgs.addSink(graph2);
    try {
        dgs.begin(getClass().getResourceAsStream(GRAPH));
        for (int i = 0; i < 100 && dgs.nextEvents(); i++) ;
        dgs.end();
    } catch (IOException e1) {
        e1.printStackTrace();
        System.exit(1);
    }
    dgs.removeSink(graph2);
    primaryStage.setScene(new Scene(view1));
    primaryStage.show();
    Stage secondStage = new Stage();
    secondStage.setScene(new Scene(view2));
    secondStage.show();
    primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {

        @Override
        public void handle(WindowEvent t) {
            Platform.exit();
            System.exit(0);
        }
    });
    secondStage.setOnCloseRequest(new EventHandler<WindowEvent>() {

        @Override
        public void handle(WindowEvent t) {
            Platform.exit();
            System.exit(0);
        }
    });
}
Also used : ThreadProxyPipe(org.graphstream.stream.thread.ThreadProxyPipe) FileSourceDGS(org.graphstream.stream.file.FileSourceDGS) FxViewPanel(org.graphstream.ui.fx_viewer.FxViewPanel) IOException(java.io.IOException) Scene(javafx.scene.Scene) MultiGraph(org.graphstream.graph.implementations.MultiGraph) FxViewer(org.graphstream.ui.fx_viewer.FxViewer) MultiGraph(org.graphstream.graph.implementations.MultiGraph) Graph(org.graphstream.graph.Graph) WindowEvent(javafx.stage.WindowEvent) Stage(javafx.stage.Stage)

Example 10 with MultiGraph

use of org.graphstream.graph.implementations.MultiGraph in project gs-ui-javafx by graphstream.

the class DemoViewerFxEdgeSelection method main.

public static void main(String[] args) {
    System.setProperty("org.graphstream.ui", "org.graphstream.ui.javafx.util.Display");
    Graph graph = new MultiGraph("main graph");
    viewPanel = (FxViewPanel) graph.display(true).getDefaultView();
    FxViewer view = (FxViewer) viewPanel.getViewer();
    view.getDefaultView().setMouseManager(new FxMouseManager(EnumSet.of(InteractiveElement.EDGE, InteractiveElement.NODE, InteractiveElement.SPRITE)));
    ViewerPipe pipe = view.newViewerPipe();
    // graph.setAttribute( "ui.quality" );
    graph.setAttribute("ui.antialias");
    pipe.addViewerListener(new DemoViewerFxEdgeSelection());
    for (String nodeId : new String[] { "A", "B", "C" }) {
        Node node = graph.addNode(nodeId);
        node.setAttribute("ui.label", nodeId);
    }
    graph.addEdge("AB", "A", "B", true);
    graph.addEdge("BC", "B", "C", true);
    graph.addEdge("CA", "C", "A", true);
    graph.setAttribute("ui.stylesheet", styleSheet);
    float color = 0;
    float dir = 0.01f;
    while (loop) {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        pipe.pump();
        color += dir;
        if (color > 1) {
            color = 1;
            dir = -dir;
        } else if (color < 0) {
            color = 0;
            dir = -dir;
        }
        showSelection(graph);
    }
}
Also used : FxViewer(org.graphstream.ui.fx_viewer.FxViewer) Graph(org.graphstream.graph.Graph) MultiGraph(org.graphstream.graph.implementations.MultiGraph) FxMouseManager(org.graphstream.ui.fx_viewer.util.FxMouseManager) Node(org.graphstream.graph.Node) MultiGraph(org.graphstream.graph.implementations.MultiGraph) ViewerPipe(org.graphstream.ui.view.ViewerPipe)

Aggregations

MultiGraph (org.graphstream.graph.implementations.MultiGraph)21 Node (org.graphstream.graph.Node)12 FxViewer (org.graphstream.ui.fx_viewer.FxViewer)12 ViewerPipe (org.graphstream.ui.view.ViewerPipe)10 Scene (javafx.scene.Scene)9 FxGraphRenderer (org.graphstream.ui.javafx.FxGraphRenderer)9 FxDefaultView (org.graphstream.ui.fx_viewer.FxDefaultView)8 Viewer (org.graphstream.ui.view.Viewer)8 DorogovtsevMendesGenerator (org.graphstream.algorithm.generator.DorogovtsevMendesGenerator)5 Edge (org.graphstream.graph.Edge)4 Graph (org.graphstream.graph.Graph)4 WindowEvent (javafx.stage.WindowEvent)3 FxViewPanel (org.graphstream.ui.fx_viewer.FxViewPanel)3 SpriteManager (org.graphstream.ui.spriteManager.SpriteManager)3 ThreadProxyPipe (org.graphstream.stream.thread.ThreadProxyPipe)2 IOException (java.io.IOException)1 GridPane (javafx.scene.layout.GridPane)1 StackPane (javafx.scene.layout.StackPane)1 Stage (javafx.stage.Stage)1 RandomWalk (org.graphstream.algorithm.randomWalk.RandomWalk)1