use of org.graphstream.graph.IdAlreadyInUseException 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());
}
}
}
}
});
});
}
Aggregations