Commit e1603eaa authored by Linxiao Zeng's avatar Linxiao Zeng

adapt the GUI API to be able to generate GUI parts from txt file

parent 55cacc1a
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",
......
......@@ -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;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment