use of org.graphstream.ui.spriteManager.SpriteManager in project gs-ui-javafx by graphstream.
the class TestSprite method addSprites.
private void addSprites() {
sprites = new SpriteManager(graph);
sprites.setSpriteFactory(new TestSpriteFactory());
for (int i = 0; i < SPRITE_COUNT; i++) {
sprites.addSprite(i + "");
}
sprites.forEach(s -> s.attachToEdge(randomEdge(graph).getId()));
}
use of org.graphstream.ui.spriteManager.SpriteManager in project gs-ui-javafx by graphstream.
the class TestPies method run.
private void run() {
System.setProperty("org.graphstream.ui", "org.graphstream.ui.javafx.util.Display");
SingleGraph g = new SingleGraph("test");
Node A = g.addNode("A");
Node B = g.addNode("B");
g.addEdge("AB", "A", "B");
SpriteManager sm = new SpriteManager(g);
Sprite pie = sm.addSprite("pie");
g.setAttribute("ui.antialias");
pie.setAttribute("ui.style", "shape: pie-chart; fill-color: #F00, #0F0, #00F; size: 30px;");
// g.addAttribute("ui.stylesheet", "sprite { shape: pie-chart; fill-color: #F00, #0F0, #00F; size: 30px; } node {fill-color: red; }")
double[] values = new double[3];
values[0] = 0.3333;
values[1] = 0.3333;
values[2] = 0.3333;
pie.setAttribute("ui.pie-values", values);
pie.attachToEdge("AB");
pie.setPosition(0.5);
g.display();
double[] values2 = new double[3];
values2[0] = 0.1;
values2[1] = 0.3;
values2[2] = 0.6;
boolean on = true;
while (true) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (on) {
values[0] = 0.1;
values[1] = 0.3;
values[2] = 0.6;
A.setAttribute("ui.pie-values", new double[] { 1.0 });
A.setAttribute("ui.style", "shape:pie-chart; fill-color:red;");
} else {
values[0] = 0.3;
values[1] = 0.3;
values[2] = 0.3;
A.setAttribute("ui.pie-values", new double[] { 1.0 });
A.setAttribute("ui.style", "shape:pie-chart; fill-color:blue;");
}
pie.setAttribute("ui.pie-values", values);
// pie.addAttribute("ui.pie-values", if(on) values else values2)
on = !on;
}
}
use of org.graphstream.ui.spriteManager.SpriteManager in project gs-ui-javafx by graphstream.
the class TestSize method run.
private void run() {
MultiGraph graph = new MultiGraph("Test Size");
Viewer viewer = new FxViewer(graph, FxViewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
ViewerPipe pipeIn = viewer.newViewerPipe();
FxDefaultView view = (FxDefaultView) viewer.addView("view1", new FxGraphRenderer());
DefaultApplication.init(view, graph);
new Thread(() -> Application.launch(DefaultApplication.class)).start();
pipeIn.addAttributeSink(graph);
pipeIn.addViewerListener(this);
pipeIn.pump();
graph.setAttribute("ui.stylesheet", styleSheet);
graph.setAttribute("ui.antialias");
graph.setAttribute("ui.quality");
Node A = graph.addNode("A");
Node B = graph.addNode("B");
Node C = graph.addNode("C");
Node D = graph.addNode("D");
Edge AB = graph.addEdge("AB", "A", "B", true);
Edge BC = graph.addEdge("BC", "B", "C", true);
Edge CD = graph.addEdge("CD", "C", "D", true);
Edge DA = graph.addEdge("DA", "D", "A", true);
Edge BB = graph.addEdge("BB", "B", "B", true);
A.setAttribute("xyz", new double[] { 0, 1, 0 });
B.setAttribute("xyz", new double[] { 1, 1, 0 });
C.setAttribute("xyz", new double[] { 1, 0, 0 });
D.setAttribute("xyz", new double[] { 0, 0, 0 });
AB.setAttribute("ui.label", "AB");
BC.setAttribute("ui.label", "A Long label ...");
CD.setAttribute("ui.label", "CD");
BB.setAttribute("ui.label", "BB");
SpriteManager sm = new SpriteManager(graph);
Sprite S1 = sm.addSprite("S1");
S1.attachToNode("C");
S1.setPosition(StyleConstants.Units.PX, 40, 45, 0);
double size = 20f;
double sizeInc = 1f;
while (loop) {
pipeIn.pump();
sleep(40);
A.setAttribute("ui.size", size);
// A.setAttribute( "ui.size", "%spx".format( size ) )
BC.setAttribute("ui.size", size);
S1.setAttribute("ui.size", size);
size += sizeInc;
if (size > 50) {
sizeInc = -1f;
size = 50f;
} else if (size < 20) {
sizeInc = 1f;
size = 20f;
}
}
System.out.println("bye bye");
System.exit(0);
}
use of org.graphstream.ui.spriteManager.SpriteManager in project gs-ui-javafx by graphstream.
the class MovingNodeSprite method run.
private void run() {
MultiGraph graph = new MultiGraph("TestSprites");
Viewer viewer = new FxViewer(graph, FxViewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
ViewerPipe pipeIn = viewer.newViewerPipe();
FxDefaultView view = (FxDefaultView) viewer.addView("view1", new FxGraphRenderer());
DefaultApplication.init(view, graph);
new Thread(() -> Application.launch(DefaultApplication.class)).start();
pipeIn.addAttributeSink(graph);
pipeIn.addViewerListener(this);
pipeIn.pump();
graph.setAttribute("ui.stylesheet", styleSheet);
graph.setAttribute("ui.antialias");
graph.setAttribute("ui.quality");
Node A = graph.addNode("A");
Node B = graph.addNode("B");
Node C = graph.addNode("C");
Node D = graph.addNode("D");
Node E = graph.addNode("E");
C.setAttribute("ui.points", new Point3(-0.05f, -0.05f, 0f), new Point3(0f, -0.02f, 0f), new Point3(0.05f, -0.05f, 0f), new Point3(0f, 0.05f, 0f));
graph.addEdge("AB1", "A", "B", true);
graph.addEdge("AB2", "B", "A", true);
graph.addEdge("BC", "B", "C");
graph.addEdge("CD", "C", "D", true);
graph.addEdge("DA", "D", "A");
graph.addEdge("DE", "D", "E", true);
graph.addEdge("EB", "E", "B", true);
graph.addEdge("BB", "B", "B", true);
graph.getEdge("CD").setAttribute("ui.points", new Point3(1, 0, 0), new Point3(0.6f, 0.1f, 0f), new Point3(0.3f, -0.1f, 0f), new Point3(0, 0, 0));
A.setAttribute("xyz", new double[] { 0, 1, 0 });
B.setAttribute("xyz", new double[] { 1.5, 1, 0 });
C.setAttribute("xyz", new double[] { 1, 0, 0 });
D.setAttribute("xyz", new double[] { 0, 0, 0 });
E.setAttribute("xyz", new double[] { 0.4, 0.6, 0 });
A.setAttribute("label", "A");
B.setAttribute("label", "B");
C.setAttribute("label", "C");
D.setAttribute("label", "D");
E.setAttribute("label", "E");
SpriteManager sman = new SpriteManager(graph);
MovingEdgeSprite s1 = sman.addSprite("S1", MovingEdgeSprite.class);
MovingEdgeSprite s2 = sman.addSprite("S2", MovingEdgeSprite.class);
MovingEdgeSprite s3 = sman.addSprite("S3", MovingEdgeSprite.class);
MovingEdgeSprite s4 = sman.addSprite("S4", MovingEdgeSprite.class);
DataSprite s5 = sman.addSprite("S5", DataSprite.class);
MovingEdgeSprite s6 = sman.addSprite("S6", MovingEdgeSprite.class);
MovingEdgeSprite s7 = sman.addSprite("S7", MovingEdgeSprite.class);
MovingEdgeSprite s8 = sman.addSprite("S8", MovingEdgeSprite.class);
s1.attachToEdge("AB1");
s2.attachToEdge("CD");
s3.attachToEdge("DA");
s4.attachToEdge("EB");
s5.attachToNode("A");
s6.attachToNode("D");
s7.attachToEdge("AB2");
s8.attachToEdge("EB");
s2.setOffsetPx(20);
s3.setOffsetPx(15);
s4.setOffsetPx(4);
s5.setPosition(Units.PX, 0, 30, 0);
s5.setData(new float[] { 0.3f, 0.5f, 0.2f });
// s6.setOffsetPx(20);
s8.setPosition(0.5f, 0.5f, 0f);
s1.setAttribute("ui.label", "FooBar1");
s2.setAttribute("ui.label", "FooBar2");
s4.setAttribute("ui.label", "FooBar4");
s7.setAttribute("ui.label", "FooBar7");
s8.setAttribute("ui.points", new Point3(-0.02f, -0.02f, 0f), new Point3(0f, -0.01f, 0f), new Point3(0.02f, -0.02f, 0f), new Point3(0f, 0.02f, 0f));
E.setAttribute("ui.pie-values", 0.2f, 0.3f, 0.4f, 0.1f);
while (loop) {
pipeIn.pump();
s1.move();
s2.move();
s3.move();
s4.move();
s6.move();
s7.move();
s8.move();
sleep(4);
}
System.out.println("bye bye");
System.exit(0);
}
use of org.graphstream.ui.spriteManager.SpriteManager in project gs-ui-javafx by graphstream.
the class TestStars method run.
private void run() {
MultiGraph graph = new MultiGraph("TestSprites");
Viewer viewer = new FxViewer(graph, FxViewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
ViewerPipe pipeIn = viewer.newViewerPipe();
FxDefaultView view = (FxDefaultView) viewer.addView("view1", new FxGraphRenderer());
DefaultApplication.init(view, graph);
new Thread(() -> Application.launch(DefaultApplication.class)).start();
pipeIn.addAttributeSink(graph);
pipeIn.addViewerListener(this);
pipeIn.pump();
graph.setAttribute("ui.stylesheet", styleSheet);
graph.setAttribute("ui.antialias");
graph.setAttribute("ui.quality");
Node A = graph.addNode("A");
Node B = graph.addNode("B");
Node C = graph.addNode("C");
Node D = graph.addNode("D");
Node E = graph.addNode("E");
graph.addEdge("AB", "A", "B");
graph.addEdge("BC", "B", "C");
graph.addEdge("CD", "C", "D");
graph.addEdge("DA", "D", "A");
graph.addEdge("DE", "D", "E");
graph.addEdge("EB", "E", "B");
A.setAttribute("xyz", new double[] { 0, 1, 0 });
B.setAttribute("xyz", new double[] { 1.5, 1, 0 });
C.setAttribute("xyz", new double[] { 1, 0, 0 });
D.setAttribute("xyz", new double[] { 0, 0, 0 });
E.setAttribute("xyz", new double[] { 0.4, 0.6, 0 });
SpriteManager sman = new SpriteManager(graph);
sman.setSpriteFactory(new MySpriteFactory());
MySprite s1 = (MySprite) sman.addSprite("S1");
MySprite s2 = (MySprite) sman.addSprite("S2");
MySprite s3 = (MySprite) sman.addSprite("S3");
s1.attachToEdge("AB");
s2.attachToEdge("CD");
s3.attachToEdge("DA");
while (loop) {
pipeIn.pump();
s1.move();
s2.move();
s3.move();
sleep(10);
}
System.out.println("bye bye");
System.exit(0);
}
Aggregations