aboutsummaryrefslogtreecommitdiff
path: root/main/Main.java
blob: c1a4e1c4903b5b283522a23ac5ed5851f44b93b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import org.graphstream.graph.Edge;
import org.graphstream.graph.Graph;
import org.graphstream.graph.implementations.SingleGraph;

import structure.Grid;
import structure.Router;

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')");

		
		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;");

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