Browse Source

Bisschen Ordnung in die Bude reingebracht

Teh-Hai Julian Zheng 8 years ago
parent
commit
88f9c15ef5

BIN
bin/classes/CpsObject.class


BIN
bin/ui/controller/CategoryController.class


BIN
bin/ui/controller/Control.class


BIN
bin/ui/controller/ObjectControl.class


BIN
bin/ui/model/IdCounter.class


BIN
bin/ui/model/Model.class


BIN
bin/ui/model/tests.class


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


+ 3 - 3
src/classes/CpsObject.java

@@ -3,7 +3,7 @@ package classes;
 import java.util.ArrayList;
 
 import Interfaces.ComparableObject;
-import ui.model.IdCounter;
+import ui.model.iDCounter;
 
 public abstract class CpsObject implements ComparableObject {
 	/* Type of the Object */
@@ -30,7 +30,7 @@ public abstract class CpsObject implements ComparableObject {
 		this.name = objName;
 		connectedTo = new ArrayList<CpsObject>();
 		position = new Position();
-		id = IdCounter.nextId();
+		id = iDCounter.nextId();
 		image = "/Images/Dummy_House.png";
 	}
 
@@ -38,7 +38,7 @@ public abstract class CpsObject implements ComparableObject {
 		this.objName = obj.getObjName();
 		connectedTo = new ArrayList<CpsObject>();
 		position = new Position();
-		id = IdCounter.nextId();
+		id = iDCounter.nextId();
 		this.name = obj.getName();
 		this.energyIn = obj.getEnergyIn();
 		this.energyOut = obj.getEnergyOut();

+ 40 - 0
src/ui/controller/CanvasController.java

@@ -0,0 +1,40 @@
+package ui.controller;
+
+import ui.model.iDCounter;
+import Interfaces.ObjectListener;
+import classes.CpsObject;
+import ui.model.Model;
+
+public class CanvasController {
+
+	private iDCounter ID;
+	private Model MODEL;
+
+	public CanvasController(iDCounter id, Model model) {
+		this.ID = id;
+		this.MODEL = model;
+	}
+
+	/**
+	 * Add an CpsObject to the model and notify the ObjectListener for update.
+	 * 
+	 * @param object
+	 *            CpsObject to be added.
+	 */
+	public void addObject(CpsObject object) {
+		String name = object.getObjName();
+		MODEL.getObjectsOnCanvas().add(object);
+		notifyObjListeners();
+		System.out.println("Added: " + name);
+	}
+
+	/**
+	 * notifies all listeners about changes in the Canvas
+	 */
+	public void notifyObjListeners() {
+		for (ObjectListener l : MODEL.getObjectListeners()) {
+			l.onChange(MODEL.getObjectsOnCanvas());
+		}
+	}
+
+}

+ 12 - 12
src/ui/controller/CategoryController.java

@@ -18,12 +18,12 @@ import ui.view.*;
 
 public class CategoryController {
 
-	private IdCounter ID;
-	private Model M;
+	private iDCounter ID;
+	private Model MODEL;
 
-	public CategoryController(Model model, IdCounter id) {
+	public CategoryController(Model model, iDCounter id) {
 		this.ID = id;
-		this.M = model;
+		this.MODEL = model;
 		initCategories();
 	}
 
@@ -64,12 +64,12 @@ public class CategoryController {
 	public void addCategory(Category toAdd) {
 		int number = 0;
 		String name = toAdd.getName();
-		while (containsInList(M.getCategories(), toAdd)) {
+		while (containsInList(MODEL.getCategories(), toAdd)) {
 			number++;
 			toAdd.setName(name + "_" + number);
 		}
 		;
-		M.getCategories().add(toAdd);
+		MODEL.getCategories().add(toAdd);
 		notifyCatListeners();
 	}
 
@@ -91,7 +91,7 @@ public class CategoryController {
 	 * @return true if successfull, otherwise false
 	 */
 	public boolean deleteCategory(String catName) {
-		int position = getPositionInList(M.getCategories(), searchCatNode(catName));
+		int position = getPositionInList(MODEL.getCategories(), searchCatNode(catName));
 		if (position != -1) {
 			deleteCategoryAt(position);
 			return true;
@@ -104,7 +104,7 @@ public class CategoryController {
 	 * deletes a Category at given position
 	 */
 	public void deleteCategoryAt(int idx) {
-		M.getCategories().remove(idx);
+		MODEL.getCategories().remove(idx);
 		notifyCatListeners();
 	}
 
@@ -187,15 +187,15 @@ public class CategoryController {
 	 * @param catLis
 	 */
 	public void addCatListener(CategoryListener catLis) {
-		M.getCategoryListeners().add(catLis);
+		MODEL.getCategoryListeners().add(catLis);
 	}
 
 	/**
 	 * notifies all listeners about changes in the Categories
 	 */
 	public void notifyCatListeners() {
-		for (CategoryListener l : M.getCategoryListeners()) {
-			l.onChange(M.getCategories());
+		for (CategoryListener l : MODEL.getCategoryListeners()) {
+			l.onChange(MODEL.getCategories());
 		}
 	}
 
@@ -208,7 +208,7 @@ public class CategoryController {
 	public Category searchCatNode(String name) {
 		Category query = null;
 
-		for (Category cat : M.getCategories()) {
+		for (Category cat : MODEL.getCategories()) {
 			if (cat.getName().equals(name)) {
 				query = cat;
 				break;

+ 21 - 14
src/ui/controller/Control.java

@@ -1,6 +1,6 @@
 package ui.controller;
 
-import ui.model.IdCounter;
+import ui.model.iDCounter;
 
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
@@ -18,21 +18,19 @@ public class Control {
 		CATEGORY, OBJECT
 	}
 
-	private IdCounter iD;
-	private Model model;
+	private iDCounter ID;
+	private Model MODEL;
 	private ActionListener actionListener;
 	private final CategoryController categoryController;
-	private final ObjectControl objectControl;
+	private final ObjectController objectController;
+	private final CanvasController canvasController;
 
-	public Control(Model model, IdCounter id) {
-		this.model = model;
-		this.iD = id;
+	public Control(Model model, iDCounter id) {
+		this.MODEL = model;
+		this.ID = id;
 		this.categoryController = new CategoryController(model, id);
-		this.objectControl = new ObjectControl(model);
-	}
-
-	public void addObject(CpsObject object) {
-		objectControl.addObject(object);
+		this.objectController = new ObjectController(model);
+		this.canvasController = new CanvasController(id, model);
 	}
 
 	////////// Operations for Categories and Objects ///////////
@@ -68,10 +66,19 @@ public class Control {
 	public void deleteObjectInCat(String toDelete, String deleteIn) {
 		categoryController.deleteObjectInCat(toDelete, deleteIn);
 	}
+	
+	
+	///////// Operations for Canvas /////////////
+	public void addObject(CpsObject object) {
+		canvasController.addObject(object);
+	}
 
 	public void setSelectedObjectID(int id){
-		objectControl.setSelectedObjectID(id);
+		objectController.setSelectedObjectID(id);
 	}
+	
+	
+	//////// Operations for Objects and Elements //////////
 
 	////////// etc
 	/**
@@ -80,7 +87,7 @@ public class Control {
 	 * @return
 	 */
 	public Model getModel() {
-		return model;
+		return MODEL;
 	}
 
 }

+ 5 - 27
src/ui/controller/ObjectControl.java → src/ui/controller/ObjectController.java

@@ -4,14 +4,14 @@ import classes.Category;
 import classes.CpsObject;
 import classes.HolonElement;
 import classes.HolonObject;
-import ui.model.IdCounter;
+import ui.model.iDCounter;
 import ui.model.Model;
 
 import java.util.ArrayList;
 
 import Interfaces.ObjectListener;
 
-public class ObjectControl {
+public class ObjectController {
 
 	public enum Type {
 		CONSUMER, PRODUCER
@@ -20,39 +20,18 @@ public class ObjectControl {
 	private Model M;
 	private int ID;
 
-	public ObjectControl(Model model) {
+	public ObjectController(Model model) {
 		this.M = model;
-		this.ID = IdCounter.nextId();
+		this.ID = iDCounter.nextId();
 	}
 
-	/**
-	 * Add an CpsObject to the model and notify the ObjectListener for update.
-	 * 
-	 * @param object
-	 *            CpsObject to be added.
-	 */
-	public void addObject(CpsObject object) {
-		String name = object.getObjName();
-		M.getObjectsOnCanvas().add(object);
-		notifyObjListeners();
-		System.out.println("Added: " + name);
-	}
-
-	/**
-	 * notifies all listeners about changes in the Categories
-	 */
-	public void notifyObjListeners() {
-		for (ObjectListener l : M.getObjectListeners()) {
-			l.onChange(M.getObjectsOnCanvas());
-		}
-	}
+	
 
 	/**
 	 * Adds Element into a Object
 	 */
 	public void addElement(HolonObject object, HolonElement element) {
 		object.getElements().add(element);
-
 	}
 
 	/**
@@ -129,7 +108,6 @@ public class ObjectControl {
 				break;
 			}
 		}
-
 		return obj;
 	}
 

+ 3 - 0
src/ui/model/Model.java

@@ -29,6 +29,9 @@ public class Model {
 	 */
 	private ArrayList<CpsObject> objectsOnCanvas;
 
+	/*
+	 * Array for all Listeners
+	 */
 	private List<CategoryListener> categoryListeners;
 	private List<ObjectListener> objectListeners;
 

+ 1 - 1
src/ui/model/IdCounter.java → src/ui/model/iDCounter.java

@@ -1,6 +1,6 @@
 package ui.model;
 
-public class IdCounter {
+public class iDCounter {
 	private static int counter = 0;
 
 	public static synchronized int nextId() {

+ 1 - 1
src/ui/model/tests.java

@@ -8,7 +8,7 @@ import ui.controller.CategoryController;
 public class tests {
 	
 	public static void main(String[] args){
-		CategoryController cc = new CategoryController(new Model(), new IdCounter());
+		CategoryController cc = new CategoryController(new Model(), new iDCounter());
 		ArrayList<Category> cats = new ArrayList<Category>();
 		cats.add(new Category("sup"));
 		boolean value;

+ 1 - 1
src/ui/view/Main.java

@@ -25,7 +25,7 @@ public class Main {
 		EventQueue.invokeLater(new Runnable() {
 			public void run() {
 				try {
-					IdCounter ID = new IdCounter();
+					iDCounter ID = new iDCounter();
 					Model M = new Model();
 					Control C = new Control(M, ID);
 					GUI V = new GUI(C);