123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- 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 ObjectController {
- public enum Type {
- CONSUMER, PRODUCER
- }
- private Model MODEL;
- private int ID;
- public ObjectController(Model model) {
- this.MODEL = model;
- this.ID = iDCounter.nextId();
- initHolonElements();
- }
-
-
- /**
- * init default Power supply of the Power Plant
- */
- public void initHolonElements(){
- addNewElementIntoCategoryObject("Energy", "Power Plant", "Power", 1, 100);
- }
- /**
- * Adds Element into a Object
- */
- public void addElement(HolonObject object, HolonElement element) {
- object.getElements().add(element);
- }
- /**
- * Adds Element into a Object on the Canvas
- *
- * @param object
- * @param element
- * @param type
- */
- public void addElementIntoCanvasObject(String object, HolonElement element) {
- addElement(searchHolonObject(object, MODEL.getObjectsOnCanvas()), element);
- }
- /**
- * 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) {
- addElementIntoCanvasObject(object, new HolonElement(eleName, energy, amount));
- }
- /**
- * Add Element into a Object in Category
- *
- * @param object
- * @param element
- * @param type
- */
- public void addElementIntoCategoryObject(String category, String object, HolonElement element) {
- Category cat = null;
- for (Category cats : MODEL.getCategories()) {
- if (cats.getName().equals(category)) {
- cat = cats;
- break;
- }
- }
- addElement(searchHolonObject(object, cat.getObjects()), element);
- }
- /**
- * 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) {
- addElementIntoCategoryObject(category, object, new HolonElement(eleName, energy, amount));
- }
-
- /**
- * deletes a Element from a given Object
- * @param obj
- * @param ele
- */
- public void deleteElement(HolonObject obj, HolonElement ele){
- obj.getElements().remove(ele);
- }
-
- public void deleteElementInCategory(Category cat, HolonObject obj, HolonElement ele){
-
- }
-
-
- /**
- * 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;
- }
- /**
- * Returns the ID of the selected Object 0 = no Object is selected
- *
- * @return ID
- */
- public void setSelectedObjectID(int id) {
- MODEL.setSelectedObjectID(id);
- }
- }
|