...
 
Commits (3)
transf:transfo_1;[produit1:1];[ligne2:produit2:2];2000;.02;(200,100)
transf:transfo_1;[produit1:1];[ligne2:produit2:2];2000;.02;(300,100)
transf:entree_1;[];[ligne1:produit1:1];0;0;(100,100)
transf:sortie_1;[produit2:1];[];0;0;(300,100)
transf:sortie_1;[produit2:1];[];0;0;(500,100)
ligne:ligne1;entree_1;transfo_1;5
ligne:ligne2;transfo_1;sortie_1;1
\ No newline at end of file
package gui;
import java.awt.Dimension;
import java.util.List;
import java.util.Map;
import javax.swing.JFrame;
......@@ -27,11 +29,13 @@ public class GUI extends Agent {
System.out.println(getName());//getLocalName()
Object[] args = getArguments();
capacity = (Integer)args[0];
Map<String, Map<String, Map<String, Object>>> confDic = (Map<String, Map<String, Map<String, Object>>>) args[1];
System.out.println("Lancer Interface: " + capacity);
JFrame f = new JFrame("ma fenetre");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
p = new Painting();
// p = new Painting();
p = new Painting(confDic);
p.setPreferredSize(new Dimension(800,600));
f.add(p);
f.pack();
......
package gui;
import jade.core.Runtime;
import java.util.List;
import java.util.Map;
import java.util.Random;
import jade.core.Profile;
......@@ -14,13 +16,16 @@ public class Lanceur {
private static final Random rand = new Random();
public static void main(String[] args) throws StaleProxyException {
Map<String, Map<String, Map<String, Object>>> confDic = LoadConfiguration.loadConfig("conf.txt");
Runtime rt = Runtime.instance();
rt.setCloseVM(true);
Profile pMain = new ProfileImpl("localhost", 8888,null);
AgentContainer mc = rt.createMainContainer(pMain);
AgentController ac = mc.createNewAgent("interface", "gui.GUI",
new Object[] {5});//5 produit
new Object[] {5,confDic});//5 produit
AgentController sp = mc.createNewAgent("sp2", "gui.Sender",
......
......@@ -5,21 +5,68 @@ import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class LoadConfiguration {
public static void main(String[] args) {
loadConfig();
Map<String, Map<String, Map<String, Object>>> confDic = loadConfig("conf.txt");
System.out.println("------------------Return Conf--------------------");
System.out.println("Machines:");
Map<String,Map<String, Object>> Machines = confDic.get("Machines");
Set<Entry<String, Map<String, Object>>> entrys = Machines.entrySet();
for(Entry e:entrys) {
System.out.println("");
System.out.println(e.getKey()+":");//MachineName
Map<String, Object> machineDic = (Map<String, Object>) e.getValue();
Set<Entry<String, Object>> attributs = machineDic.entrySet();
for(Entry entry:attributs) {
System.out.println(" "+entry.getKey()+":"+entry.getValue());//attributName:attribut
}
}
System.out.println("Lignes:");
Map<String,Map<String, Object>> Lignes = confDic.get("Lignes");
Set<Entry<String, Map<String, Object>>> lignesEntrys = Lignes.entrySet();
for(Entry lignesEntry:lignesEntrys) {
System.out.println("");
System.out.println(lignesEntry.getKey()+":");//LignesName
Map<String, Object> ligneDic = (Map<String, Object>) lignesEntry.getValue();
Set<Entry<String, Object>> attributs = ligneDic.entrySet();
for(Entry entry:attributs) {
System.out.println(" "+entry.getKey()+":"+entry.getValue());//attributName:attribut
}
}
}
public static void loadConfig() {
/**
* load configuration of Machines and Lignes from .txt file
* @return a Map: {"Machines": MachinesDic, "Lignes": LignesDic}\
* MachinesDic contains Machines in the form of {name : machine}, in which machine is
* an HashMap: {"inputs":inputList,"outputs":outputList,
* "processTime":pT,"errorProb":eP,"x":x,"y":y}
* LigneList contains Ligne in the form of {name : ligne}, in which ligne is
* an HashMap: {"source":source,"target":target,"capacity":capacity}
* */
public static Map<String, Map<String, Map<String, Object>>> loadConfig(String filePath) {
// TODO Auto-generated method stub
try {
FileReader fr = new FileReader("conf.txt");
FileReader fr = new FileReader(filePath);//"conf.txt"
BufferedReader br = new BufferedReader(fr);
String ligne;
Map<String, Map<String, Map<String, Object>>> confDic = new HashMap<String, Map<String, Map<String, Object>>>();
// List<Map> MachineList = new ArrayList<Map>();
// List<Map> LigneList = new ArrayList<Map>();
Map<String,Map<String, Object>> Machines = new HashMap<String, Map<String, Object>>();
Map<String,Map<String, Object>> Lignes = new HashMap<String, Map<String, Object>>();
while ((ligne=br.readLine())!=null) {
// System.out.println("lu: "+ligne);
String [] t = ligne.split(":",2);
......@@ -35,6 +82,7 @@ public class LoadConfiguration {
System.out.println(" positionx:" + m.group(6)); //int
System.out.println(" positiony:" + m.group(7)); //int
System.out.println("");
String name = m.group(1);
// handle input List
List<InOutput> inputList = handleList(m.group(2),false);
......@@ -45,6 +93,17 @@ public class LoadConfiguration {
int positionx = Integer.parseInt(m.group(6));
int positiony = Integer.parseInt(m.group(7));
System.out.println("-------------------");
Map<String,Object> MachineDic = new HashMap<String, Object>();
// MachineDic.put("name", name);
MachineDic.put("inputs", inputList);
MachineDic.put("outputs", outputList);
MachineDic.put("processTime", processTime);
MachineDic.put("errorProb", errorProb);
MachineDic.put("x", positionx);
MachineDic.put("y", positiony);
// MachineList.add(MachineDic);
Machines.put(name, MachineDic);
}
}else if(t[0].equals("ligne")) {
// case: Type ligne
......@@ -52,9 +111,17 @@ public class LoadConfiguration {
if(params.length == 4) {
String name = params[0];
String Msource = params[1];
String Mcible = params[2];
String Mtarget = params[2];
int capacity = Integer.parseInt(params[3]);
System.out.println(name+":"+Msource+" -> "+Mcible+", capacity#"+capacity);
System.out.println(name+":"+Msource+" -> "+Mtarget+", capacity#"+capacity);
Map<String,Object> LigneDic = new HashMap<String, Object>();
// LigneDic.put("name", name);
LigneDic.put("source", Msource);
LigneDic.put("target", Mtarget);
LigneDic.put("capacity", capacity);
// LigneList.add(LigneDic);
Lignes.put(name, LigneDic);
}else {
System.out.println("file is not in correct format!");
throw new IOException("file is not in correct format, can't parse!");
......@@ -64,11 +131,15 @@ public class LoadConfiguration {
throw new IOException("unknown type, can't parse!");
}
}
confDic.put("Machines", Machines);
confDic.put("Lignes", Lignes);
return confDic;
} catch (FileNotFoundException e) {
System.err.println("lignes.txt pas trouv");
} catch (IOException e) {
System.err.println("erreur lors de la lecture du fichier");
}
return null;
}
/**
......
......@@ -3,7 +3,11 @@ package gui;
import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.swing.JPanel;
......@@ -23,12 +27,12 @@ public class Painting extends JPanel {
// private int capacityLineIn;
// private int capacityLineOut;
private List<Machine> machineList;
private Map<String,Map<String, Object>> machines;
private Map<String,Map<String, Object>> lignes;
// private Product[] productList;// list of product on the line
private List<Product> productList;
// ------------ -----------------
public Painting() {
public Painting(Map<String, Map<String, Map<String, Object>>> confDic) {
super();
this.stateInput = 0;
this.stateLineET = 0;
......@@ -36,6 +40,10 @@ public class Painting extends JPanel {
this.stateLineTS = 0;
this.stateOutput = 0;
this.productList = new ArrayList<Product>();
// load config
this.machines = confDic.get("Machines");
this.lignes = confDic.get("Lignes");
}
/*
public Painting(int stateInput, int stateLineET, int stateTransf, int stateLineTS, int stateOutput,
......@@ -52,6 +60,7 @@ public class Painting extends JPanel {
}
*/
public List<Product> getProductList(){
return productList;
}
......@@ -91,6 +100,38 @@ public class Painting extends JPanel {
g.drawRect(30+(RectWidth+LineLength)*2, 30, RectWidth, RectHight);
g.drawString("Sortie", 30+(RectWidth+LineLength)*2+RectWidth/3, 30+RectHight/2);
Set<Entry<String, Map<String, Object>>> machinesEntrys = machines.entrySet();
for(Entry<String, Map<String, Object>> machinesEntry:machinesEntrys) {
String name = machinesEntry.getKey();
Map<String, Object> machine = machinesEntry.getValue();
int x = (int) machine.get("x");
int y = (int) machine.get("y");
g.setColor(Color.GRAY);
g.fillRect(x, y, RectWidth, RectHight);
g.setColor(Color.BLACK);
g.drawRect(x, y, RectWidth, RectHight);
g.drawString(name, x+RectWidth/5, y+RectHight/2);
}
Set<Entry<String, Map<String, Object>>> lignesEntrys = lignes.entrySet();
for(Entry<String, Map<String, Object>> lignesEntry:lignesEntrys) {
String name = lignesEntry.getKey();
Map<String, Object> ligne = lignesEntry.getValue();
String sourceName = (String) ligne.get("source");
String targetName = (String) ligne.get("target");
Map<String,Integer> coord1 = getCoordinate(sourceName);
Map<String,Integer> coord2 = getCoordinate(targetName);
int x1 = coord1.get("x") + RectWidth;
int x2 = coord2.get("x");
int y1 = coord1.get("y") + RectHight/2;
int y2 = coord2.get("y") + RectHight/2;
g.drawLine(x1, y1, x2, y2);
g.drawString(name, (x1+x2)/2-(x2-x1)/5, (y1+y2)/2+RectHight/4);
}
for(Product p : productList) {
g.setColor(Color.RED);
g.fillRect(p.getPosition(), 40, 10, 10);
......@@ -98,5 +139,15 @@ public class Painting extends JPanel {
g.drawRect(p.getPosition(), 40, 10, 10);
}
}
private Map<String,Integer> getCoordinate(String machineName){
Map<String,Object> machine = machines.get(machineName);
int x = (int) machine.get("x");
int y = (int) machine.get("y");
Map<String,Integer> coordinate = new HashMap<String, Integer>();
coordinate.put("x", x);
coordinate.put("y", y);
return coordinate;
}
}