package ui.model; import Interfaces.CategoryListener; import Interfaces.ObjectListener; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import classes.Category; import classes.CpsEdge; import classes.CpsObject; import classes.HolonElement; import ui.controller.*; public class Model { // Global Variables private static int SCALE = 50; // Picture Scale private static int SCALE_DIV2 = SCALE / 2; private static final int ITERATIONS = 100; private int CUR_ITERATION = 0; // ID of the Selected Object private CpsObject selectedCpsObject = null; private HolonElement selectedHolonElement; private CpsEdge selectedEdge; private int selectedID = 0; private int autoSaveNr = 0; // eventuell wenn Canvasgröße gewählt werden kann private int HEIGHT; private int WIDTH; /* * Array of all categories in the model. It is set by default with the * categories ENERGY, BUILDINGS and COMPONENTS */ private ArrayList categories; /* * Array of all CpsObjects in our canvas. It is set by default as an empty * list. */ private ArrayList objectsOnCanvas; private HashMap cgIdx; private HashMap cvsObjIdx; /* * Array of all CpsObjects in our canvas. It is set by default as an empty * list. */ private ArrayList edgesOnCanvas; /* * Array for all Listeners */ private List categoryListeners; private List objectListeners; /* * Constructor for the model. It initializes the categories and * objectsOnCanvas by default values. Listeners are also initialized by * default values. */ public Model() { setCategories(new ArrayList()); setObjectsOnCanvas(new ArrayList()); setEdgesOnCanvas(new ArrayList()); setCategoryListeners(new LinkedList()); setObjectListeners(new LinkedList()); setCgIdx(new HashMap()); setCvsObjIdx(new HashMap()); } /** * @return the categories */ public ArrayList getCategories() { return categories; } /** * @param categories * the categories to set */ public void setCategories(ArrayList categories) { this.categories = categories; } /** * Transform the Arraylist of categories into a string of all objectName * with a separation (',') between each name * * @return String of all names separeted by ',' */ public String toStringCat() { String text = ""; for (int i = 0; i < categories.size(); i++) { if (text == "") { text = categories.get(i).getName(); } else { text = text + ", " + categories.get(i).getName(); } } return text; } /** * @return the objectsOnCanvas */ public ArrayList getObjectsOnCanvas() { return objectsOnCanvas; } /** * @param objectsOnCanvas * the objectsOnCanvas to set */ public void setObjectsOnCanvas(ArrayList objectsOnCanvas) { this.objectsOnCanvas = objectsOnCanvas; } /** * @return the objectsOnCanvas */ public ArrayList getEdgesOnCanvas() { return edgesOnCanvas; } /** * @param objectsOnCanvas * the objectsOnCanvas to set */ public void addEdgeOnCanvas(CpsEdge edge) { this.edgesOnCanvas.add(edge); } /** * @param edgesOnCanvas * the edge to remove */ public void removeEdgesOnCanvas(CpsEdge edge) { this.edgesOnCanvas.remove(edge); } /** * @param EdgesOnCanvas * the edgesOnCanvas to set */ public void setEdgesOnCanvas(ArrayList arrayList) { this.edgesOnCanvas = arrayList; } /** * @return the objectListeners */ public List getObjectListeners() { return objectListeners; } /** * @param linkedList * the objectListeners to set */ public void setObjectListeners(LinkedList linkedList) { this.objectListeners = linkedList; } /** * @return the categoryListeners */ public List getCategoryListeners() { return categoryListeners; } /** * @param linkedList * the categoryListeners to set */ public void setCategoryListeners(LinkedList linkedList) { this.categoryListeners = linkedList; } /** * Set the ID of the selected Object 0 = no Object is selected * * @param ID * */ public void setSelectedObjectID(int id) { this.selectedID = id; } /** * Returns the ID of the selected Object 0 = no Object is selected * * @return ID */ public int getSelectedObjectID() { return selectedID; } public CpsObject getSelectedCpsObject() { return selectedCpsObject; } public void setSelectedCpsObject(CpsObject selectedCpsObject) { this.selectedCpsObject = selectedCpsObject; } public HolonElement getSelectedHolonElement() { return selectedHolonElement; } public void setSelectedHolonElement(HolonElement selectedHolonElement) { this.selectedHolonElement = selectedHolonElement; } /** * Returns SCALE * * @return SCALE */ public int getScale() { return SCALE; } /** * Returns SCALE_DIV2 * * @return SCALE_DIV2 */ public int getScaleDiv2() { return SCALE_DIV2; } public void setScale(int scale) { SCALE = scale; SCALE_DIV2 = SCALE / 2; } /** * Returns ITERATIONS * * @return ITERATIONS */ public int getIterations() { return ITERATIONS; } /** * sets the current Iteration * * @param cur_it, the current Iteration */ public void setCurIteration(int cur_it) { this.CUR_ITERATION = cur_it; } /** * Returns CUR_ITERATIONS * * @return CUR_ITERATIONS */ public int getCurIteration() { return CUR_ITERATION; } /** * Set the selected Edge * * @param edge * */ public void setSelectedEdge(CpsEdge edge) { this.selectedEdge = edge; } /** * Returns the selected Edge * * @return selectedEdge */ public CpsEdge getSelectedEdge(){ return selectedEdge; } /** * @return the cgIdx */ public HashMap getCgIdx() { return cgIdx; } /** * @param cgIdx the cgIdx to set */ public void setCgIdx(HashMap cgIdx) { this.cgIdx = cgIdx; } /** * @return the cvsObjIdx */ public HashMap getCvsObjIdx() { return cvsObjIdx; } /** * @param cvsObjIdx the cvsObjIdx to set */ public void setCvsObjIdx(HashMap cvsObjIdx) { this.cvsObjIdx = cvsObjIdx; } public void setAutoSAveNr(int autoSaveNr){ this.autoSaveNr = autoSaveNr; } public int getAutoSaveNr(){ return autoSaveNr; } }