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