Search in sources :

Example 1 with Graph

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

the class FxViewer method init.

/**
 * Initialise the viewer.
 *
 * @param graph
 *            The graphic graph.
 * @param ppipe
 *            The source of events from another thread or machine (null if
 *            source != null).
 * @param source
 *            The source of events from this thread (null if ppipe != null).
 */
public void init(GraphicGraph graph, ProxyPipe ppipe, Source source) {
    super.graph = graph;
    super.pumpPipe = ppipe;
    super.sourceInSameThread = source;
    this.timeline = new Timeline(new KeyFrame(Duration.millis(delay), actionEvent -> actionPerformed()));
    assert ((ppipe != null && source == null) || (ppipe == null && source != null));
    if (pumpPipe != null)
        pumpPipe.addSink(graph);
    if (sourceInSameThread != null) {
        if (source instanceof Graph)
            replayGraph((Graph) source);
        sourceInSameThread.addSink(graph);
    }
    // timer.setCoalesce(true);
    // timer.setRepeats(true);
    // timer.start();
    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.play();
}
Also used : Timeline(javafx.animation.Timeline) Graph(org.graphstream.graph.Graph) GraphicGraph(org.graphstream.ui.graphicGraph.GraphicGraph) KeyFrame(javafx.animation.KeyFrame)

Example 2 with Graph

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

the class ATest method run.

public void run(String[] args) {
    Graph graph = new MultiGraph("g1");
    Viewer viewer = graph.display(true);
    ViewerPipe pipeIn = viewer.newViewerPipe();
    DorogovtsevMendesGenerator gen = new DorogovtsevMendesGenerator();
    pipeIn.addAttributeSink(graph);
    pipeIn.addViewerListener(this);
    pipeIn.pump();
    graph.setAttribute("ui.default.title", "Layout Test Fx");
    graph.setAttribute("ui.antialias");
    graph.setAttribute("ui.stylesheet", styleSheet);
    gen.addSink(graph);
    gen.setDirectedEdges(true, true);
    gen.begin();
    int i = 0;
    while (i < 100) {
        gen.nextEvents();
        i += 1;
    }
    gen.end();
    graph.forEach(n -> n.setAttribute("ui.label", "truc"));
    while (loop) {
        pipeIn.pump();
        sleep(10);
    }
    System.out.println("bye bye");
    System.exit(0);
}
Also used : Graph(org.graphstream.graph.Graph) MultiGraph(org.graphstream.graph.implementations.MultiGraph) Viewer(org.graphstream.ui.view.Viewer) DorogovtsevMendesGenerator(org.graphstream.algorithm.generator.DorogovtsevMendesGenerator) MultiGraph(org.graphstream.graph.implementations.MultiGraph) ViewerPipe(org.graphstream.ui.view.ViewerPipe)

Example 3 with Graph

use of org.graphstream.graph.Graph 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 4 with Graph

use of org.graphstream.graph.Graph 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 5 with Graph

use of org.graphstream.graph.Graph 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

Graph (org.graphstream.graph.Graph)5 MultiGraph (org.graphstream.graph.implementations.MultiGraph)4 FxViewer (org.graphstream.ui.fx_viewer.FxViewer)3 Scene (javafx.scene.Scene)2 FxViewPanel (org.graphstream.ui.fx_viewer.FxViewPanel)2 ViewerPipe (org.graphstream.ui.view.ViewerPipe)2 IOException (java.io.IOException)1 KeyFrame (javafx.animation.KeyFrame)1 Timeline (javafx.animation.Timeline)1 Stage (javafx.stage.Stage)1 WindowEvent (javafx.stage.WindowEvent)1 DorogovtsevMendesGenerator (org.graphstream.algorithm.generator.DorogovtsevMendesGenerator)1 Node (org.graphstream.graph.Node)1 FileSourceDGS (org.graphstream.stream.file.FileSourceDGS)1 ThreadProxyPipe (org.graphstream.stream.thread.ThreadProxyPipe)1 FxMouseManager (org.graphstream.ui.fx_viewer.util.FxMouseManager)1 GraphicGraph (org.graphstream.ui.graphicGraph.GraphicGraph)1 Viewer (org.graphstream.ui.view.Viewer)1