Teh-Hai Julian Zheng 8 роки тому
батько
коміт
826b0261bf

BIN
bin/ui/controller/Control.class


BIN
bin/ui/view/GUI$1.class


BIN
bin/ui/view/GUI$2.class


BIN
bin/ui/view/GUI$3.class


BIN
bin/ui/view/GUI$4.class


BIN
bin/ui/view/GUI$5.class


BIN
bin/ui/view/GUI$6.class


BIN
bin/ui/view/GUI.class


BIN
bin/ui/view/Main$1.class


BIN
bin/ui/view/Main.class


+ 2 - 2
src/ui/controller/CanvasController.java

@@ -10,7 +10,7 @@ public class CanvasController {
 	private iDCounter ID;
 	private Model MODEL;
 
-	public CanvasController(iDCounter id, Model model) {
+	public CanvasController(Model model, iDCounter id) {
 		this.ID = id;
 		this.MODEL = model;
 	}
@@ -21,7 +21,7 @@ public class CanvasController {
 	 * @param object
 	 *            CpsObject to be added.
 	 */
-	public void addObject(CpsObject object) {
+	public void addObjectIntoCanvas(CpsObject object) {
 		String name = object.getObjName();
 		MODEL.getObjectsOnCanvas().add(object);
 		notifyObjListeners();

+ 18 - 10
src/ui/controller/Control.java

@@ -20,7 +20,9 @@ public class Control {
 
 	private iDCounter ID;
 	private Model MODEL;
+	
 	private ActionListener actionListener;
+	
 	private final CategoryController categoryController;
 	private final ObjectController objectController;
 	private final CanvasController canvasController;
@@ -30,10 +32,10 @@ public class Control {
 		this.ID = id;
 		this.categoryController = new CategoryController(model, id);
 		this.objectController = new ObjectController(model);
-		this.canvasController = new CanvasController(id, model);
+		this.canvasController = new CanvasController(model, id);
 	}
 
-	////////// Operations for Categories and Objects ///////////
+	/* Operations for Categories and Objects */
 	public void addNewCategory(String catName) {
 		categoryController.addNewCategory(catName);
 	}
@@ -66,19 +68,25 @@ public class Control {
 	public void deleteObjectInCat(String toDelete, String deleteIn) {
 		categoryController.deleteObjectInCat(toDelete, deleteIn);
 	}
-	
-	
-	///////// Operations for Canvas /////////////
+
+	/* Operations for Canvas */
 	public void addObject(CpsObject object) {
-		canvasController.addObject(object);
+		canvasController.addObjectIntoCanvas(object);
 	}
 
-	public void setSelectedObjectID(int id){
+	public void setSelectedObjectID(int id) {
 		objectController.setSelectedObjectID(id);
 	}
-	
-	
-	//////// Operations for Objects and Elements //////////
+
+	/* Operations for Objects and Elements */
+	public void addNewElementIntoCanvasObjects(String objName, String eleName, int amount, float energy) {
+		objectController.addNewElementIntoCanvasObject(objName, eleName, amount, energy);
+	}
+
+	public void addNewElementIntoCategoryObject(String catName, String objName, String eleName, int amount,
+			float energy) {
+		objectController.addNewElementIntoCategoryObject(catName, objName, eleName, amount, energy);
+	}
 
 	////////// etc
 	/**

+ 13 - 5
src/ui/controller/ObjectController.java

@@ -17,12 +17,20 @@ public class ObjectController {
 		CONSUMER, PRODUCER
 	}
 
-	private Model M;
+	private Model MODEL;
 	private int ID;
 
 	public ObjectController(Model model) {
-		this.M = model;
+		this.MODEL = model;
 		this.ID = iDCounter.nextId();
+		initElements();
+	}
+	
+	/**
+	 * init default Power supply of the Power Plant
+	 */
+	public void initElements(){
+		addNewElementIntoCategoryObject("Energy", "Power Plant", "Power", 1, 100);
 	}
 
 	
@@ -42,7 +50,7 @@ public class ObjectController {
 	 * @param type
 	 */
 	public void addElementIntoCanvasObject(String object, HolonElement element) {
-		addElement(searchHolonObject(object, M.getObjectsOnCanvas()), element);
+		addElement(searchHolonObject(object, MODEL.getObjectsOnCanvas()), element);
 	}
 
 	/**
@@ -68,7 +76,7 @@ public class ObjectController {
 	public void addElementIntoCategoryObject(String category, String object, HolonElement element) {
 		Category cat = null;
 
-		for (Category cats : M.getCategories()) {
+		for (Category cats : MODEL.getCategories()) {
 			if (cats.getName().equals(category)) {
 				cat = cats;
 				break;
@@ -117,6 +125,6 @@ public class ObjectController {
 	 * @return ID
 	 */
 	public void setSelectedObjectID(int id) {
-		M.setSelectedObjectID(id);
+		MODEL.setSelectedObjectID(id);
 	}
 }

+ 1 - 0
src/ui/view/GUI.java

@@ -108,6 +108,7 @@ public class GUI implements CategoryListener {
 		this.canvas = new MyCanvas(model, control);
 		control.initListener(this);
 		initialize();
+		updateCategories(model.getCategories());
 	}
 
 	/**

+ 4 - 5
src/ui/view/Main.java

@@ -26,12 +26,11 @@ public class Main {
 			public void run() {
 				try {
 					iDCounter ID = new iDCounter();
-					Model M = new Model();
-					Control C = new Control(M, ID);
-					GUI V = new GUI(C);
+					Model MODEL = new Model();
+					Control CONTROL = new Control(MODEL, ID);
+					GUI VIEW = new GUI(CONTROL);
 
-					V.updateCategories(M.getCategories());
-					V.getFrmCyberPhysical().setVisible(true);
+					VIEW.getFrmCyberPhysical().setVisible(true);
 
 				} catch (Exception e) {
 					e.printStackTrace();