Add personal graph
This commit is contained in:
parent
c03d794605
commit
f453154938
3 changed files with 121 additions and 54 deletions
|
@ -8,8 +8,12 @@ import java.util.Set;
|
|||
import org.graphstream.graph.Edge;
|
||||
import org.graphstream.graph.Graph;
|
||||
import org.graphstream.graph.implementations.SingleGraph;
|
||||
import org.graphstream.ui.layout.springbox.EdgeSpring;
|
||||
import org.graphstream.ui.swingViewer.basicRenderer.EdgeRenderer;
|
||||
import org.graphstream.ui.util.EdgePoints;
|
||||
|
||||
import structure.Grid;
|
||||
import structure.MyGraph;
|
||||
import structure.Router;
|
||||
|
||||
public class Main {
|
||||
|
@ -17,52 +21,17 @@ public class Main {
|
|||
public static void main(String[] args) {
|
||||
Grid g=new Grid();
|
||||
|
||||
|
||||
System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer");
|
||||
Graph graph = new SingleGraph("Tutorial 1");
|
||||
graph.addAttribute("ui.stylesheet", "url('resources/style.css')");
|
||||
MyGraph gr=new MyGraph("Routage Oportuniste", g);
|
||||
|
||||
|
||||
ArrayList<Router> grid=g.getGrid();
|
||||
for(Router r : grid){
|
||||
graph.addNode(r.name);
|
||||
|
||||
}
|
||||
|
||||
ArrayList<Integer> bestLink=g.getLinks().get(g.getBestLinkIndex());
|
||||
for(Router r : grid){
|
||||
String current=r.name;
|
||||
HashMap<Router, Integer> relier=r.getLinks();
|
||||
Set<Router> k=relier.keySet();
|
||||
Iterator<Router> i=k.iterator();
|
||||
while(i.hasNext()){
|
||||
Router currentRouter=i.next();
|
||||
String currentRouterName=currentRouter.name;
|
||||
try{
|
||||
//graph.addEdge(current+currentRouter, current, currentRouter).addAttribute("ui.style", "fill-color: rgb(0,100,255);");
|
||||
|
||||
if(g.isEdgeOfLink(bestLink, r, currentRouter)){
|
||||
Edge toAdd=graph.addEdge(current+currentRouterName, current, currentRouterName);
|
||||
toAdd.setAttribute("ui.label", relier.get(currentRouter));
|
||||
toAdd.setAttribute("ui.style", "fill-color:red;");
|
||||
gr.display();
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}else{
|
||||
graph.addEdge(current+currentRouterName, current, currentRouterName).setAttribute("ui.label", relier.get(currentRouter));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch(Exception e){
|
||||
// System.out.println("Bug de merde.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
g.printLinkWeight();
|
||||
|
||||
graph.display();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue