Search in sources :

Example 1 with ThreadProxyPipe

use of org.graphstream.stream.thread.ThreadProxyPipe 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);
    StackPane paneView1 = new StackPane();
    // prevent UI shift issues
    paneView1.getChildren().addAll(view1);
    StackPane paneView2 = new StackPane();
    // prevent UI shift issues
    paneView2.getChildren().addAll(view2);
    GridPane gridpane = new GridPane();
    gridpane.add(paneView1, 1, 0);
    gridpane.add(paneView2, 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) StackPane(javafx.scene.layout.StackPane)

Example 2 with ThreadProxyPipe

use of org.graphstream.stream.thread.ThreadProxyPipe 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)

Aggregations

Scene (javafx.scene.Scene)2 WindowEvent (javafx.stage.WindowEvent)2 MultiGraph (org.graphstream.graph.implementations.MultiGraph)2 ThreadProxyPipe (org.graphstream.stream.thread.ThreadProxyPipe)2 FxViewer (org.graphstream.ui.fx_viewer.FxViewer)2 IOException (java.io.IOException)1 GridPane (javafx.scene.layout.GridPane)1 StackPane (javafx.scene.layout.StackPane)1 Stage (javafx.stage.Stage)1 DorogovtsevMendesGenerator (org.graphstream.algorithm.generator.DorogovtsevMendesGenerator)1 Graph (org.graphstream.graph.Graph)1 FileSourceDGS (org.graphstream.stream.file.FileSourceDGS)1 FxDefaultView (org.graphstream.ui.fx_viewer.FxDefaultView)1 FxViewPanel (org.graphstream.ui.fx_viewer.FxViewPanel)1 FxGraphRenderer (org.graphstream.ui.javafx.FxGraphRenderer)1 Viewer (org.graphstream.ui.view.Viewer)1