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());
}
}
}
}
});
});
}
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;
}
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();
}
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);
}
});
}
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);
}
}
Aggregations