|
@@ -1,12 +1,22 @@
|
|
|
package ui.controller;
|
|
|
|
|
|
+import classes.Category;
|
|
|
import classes.CpsObject;
|
|
|
+import classes.HolonElement;
|
|
|
+import classes.HolonObject;
|
|
|
import ui.model.IdCounter;
|
|
|
import ui.model.Model;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+
|
|
|
import Interfaces.ObjectListener;
|
|
|
|
|
|
public class ObjectControl {
|
|
|
|
|
|
+ public enum Type {
|
|
|
+ CONSUMER, PRODUCER
|
|
|
+ }
|
|
|
+
|
|
|
private Model M;
|
|
|
private int ID;
|
|
|
|
|
@@ -37,4 +47,94 @@ public class ObjectControl {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Adds Element into a Object
|
|
|
+ */
|
|
|
+ public void addElement(HolonObject object, HolonElement element, Type type) {
|
|
|
+
|
|
|
+ if (type.equals(Type.CONSUMER))
|
|
|
+ object.getConsumers().add(element);
|
|
|
+ else
|
|
|
+ object.getProducers().add(element);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Adds Element into a Object on the Canvas
|
|
|
+ *
|
|
|
+ * @param object
|
|
|
+ * @param element
|
|
|
+ * @param type
|
|
|
+ */
|
|
|
+ public void addElementIntoCanvasObject(HolonObject object, HolonElement element, Type type) {
|
|
|
+ addElement(object, element, type);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Add a new Element into a Object on the Canvas
|
|
|
+ *
|
|
|
+ * @param object
|
|
|
+ * @param eleName
|
|
|
+ * @param amount
|
|
|
+ * @param energy
|
|
|
+ * @param type
|
|
|
+ */
|
|
|
+ public void addNewElementIntoCanvasObject(String object, String eleName, int amount, float energy, Type type) {
|
|
|
+ addElementIntoCanvasObject(searchHolonObject(object, M.getObjectsOnCanvas()),
|
|
|
+ new HolonElement(eleName, amount, energy), type);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Add Element into a Object in Category
|
|
|
+ *
|
|
|
+ * @param object
|
|
|
+ * @param element
|
|
|
+ * @param type
|
|
|
+ */
|
|
|
+ public void addElementIntoCategoryObject(HolonObject object, HolonElement element, Type type) {
|
|
|
+ addElement(object, element, type);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Add a new Element into a Object in Category
|
|
|
+ *
|
|
|
+ * @param category
|
|
|
+ * @param object
|
|
|
+ * @param eleName
|
|
|
+ * @param amount
|
|
|
+ * @param energy
|
|
|
+ * @param type
|
|
|
+ */
|
|
|
+ public void addNewElementIntoCategoryObject(String category, String object, String eleName, int amount,
|
|
|
+ float energy, Type type) {
|
|
|
+ Category cat = null;
|
|
|
+
|
|
|
+ for (Category cats : M.getCategories()) {
|
|
|
+ if (cats.getName().equals(category)) {
|
|
|
+ cat = cats;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ addElementIntoCategoryObject(searchHolonObject(object, cat.getObjects()),
|
|
|
+ new HolonElement(eleName, amount, energy), type);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Search for Object
|
|
|
+ *
|
|
|
+ * @param object
|
|
|
+ * @param list
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public HolonObject searchHolonObject(String object, ArrayList<CpsObject> list) {
|
|
|
+ HolonObject obj = null;
|
|
|
+
|
|
|
+ for (CpsObject objects : list) {
|
|
|
+ if (objects.getObjName().equals(object)) {
|
|
|
+ obj = (HolonObject) objects;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return obj;
|
|
|
+ }
|
|
|
}
|