Search in sources :

Example 11 with FxViewer

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

the class TestStars2 method start.

public void start(Stage primaryStage) throws Exception {
    SingleGraph graph = new SingleGraph("Stars !");
    double x0 = 0.0;
    double x1 = 0.0;
    double width = 100.0;
    double height = 20.0;
    int n = 500;
    Random random = new Random();
    double minDis = 4.0;
    double sizeMx = 10.0;
    graph.setAttribute("ui.stylesheet", styleSheet);
    graph.setAttribute("ui.quality");
    graph.setAttribute("ui.antialias");
    Viewer viewer = new FxViewer(graph, FxViewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
    ViewerPipe pipeIn = viewer.newViewerPipe();
    FxDefaultView view = (FxDefaultView) viewer.addView("view1", new FxGraphRenderer());
    view.resize(1000, (int) (1200 * (height / width)));
    Scene scene = new Scene(view, 1000, 1200 * (height / width), true, SceneAntialiasing.BALANCED);
    primaryStage.setScene(scene);
    primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {

        @Override
        public void handle(WindowEvent t) {
            Platform.exit();
            System.exit(0);
        }
    });
    primaryStage.setTitle("Stars 2");
    primaryStage.show();
    for (int i = 0; i < n; i++) {
        Node node = graph.addNode(i + "");
        node.setAttribute("xyz", (random.nextDouble() * width), (random.nextDouble() * height), 0);
        node.setAttribute("ui.size", (random.nextDouble() * sizeMx));
    }
    graph.nodes().forEach(node -> {
        Point3 pos = new Point3(GraphPosLengthUtils.nodePosition(node));
        graph.nodes().forEach(otherNode -> {
            if (otherNode != node) {
                Point3 otherPos = new Point3(GraphPosLengthUtils.nodePosition(otherNode));
                double dist = otherPos.distance(pos);
                if (dist < minDis) {
                    if (!node.hasEdgeBetween(otherNode.getId())) {
                        try {
                            graph.addEdge(node.getId() + "--" + otherNode.getId(), node.getId(), otherNode.getId());
                        } catch (IdAlreadyInUseException e) {
                            graph.addEdge(node.getId() + "--" + otherNode.getId() + "-2", node.getId(), otherNode.getId());
                        }
                    }
                }
            }
        });
    });
}
Also used : 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) Scene(javafx.scene.Scene) FxViewer(org.graphstream.ui.fx_viewer.FxViewer) Point3(org.graphstream.ui.geom.Point3) IdAlreadyInUseException(org.graphstream.graph.IdAlreadyInUseException) Random(java.util.Random) WindowEvent(javafx.stage.WindowEvent) SingleGraph(org.graphstream.graph.implementations.SingleGraph) ViewerPipe(org.graphstream.ui.view.ViewerPipe)

Example 12 with FxViewer

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

the class TutorialDiagrams method diagram.

public Scene diagram(Graph graph, String style, String title, int width, int height) {
    graph.setAttribute("ui.quality");
    graph.setAttribute("ui.antialias");
    graph.setAttribute("ui.stylesheet", style);
    graph.setAttribute("ui.screenshot", title + ".png");
    Viewer viewer = new FxViewer(graph, FxViewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
    FxDefaultView view = (FxDefaultView) viewer.addDefaultView(true);
    view.resize(width, height);
    Scene scene = new Scene(view, width, height, true, SceneAntialiasing.DISABLED);
    return scene;
}
Also used : FxViewer(org.graphstream.ui.fx_viewer.FxViewer) FxViewer(org.graphstream.ui.fx_viewer.FxViewer) Viewer(org.graphstream.ui.view.Viewer) FxDefaultView(org.graphstream.ui.fx_viewer.FxDefaultView) Scene(javafx.scene.Scene)

Example 13 with FxViewer

use of org.graphstream.ui.fx_viewer.FxViewer 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 14 with FxViewer

use of org.graphstream.ui.fx_viewer.FxViewer 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 15 with FxViewer

use of org.graphstream.ui.fx_viewer.FxViewer 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

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