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.AbstractCpsObject; import classes.HolonElement; import ui.controller.*; import ui.view.Console; 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 AbstractCpsObject selectedCpsObject = null; private HolonElement selectedHolonElement; private CpsEdge selectedEdge; private ArrayList selectedObjects = new ArrayList(); private ArrayList clipboardObjects = new ArrayList(); private Console console; // Iteration Speed private int timerSpeed = 1000; // Simulation boolean private boolean isSimulation = false; private int selectedID = 0; // number of the current autosave private int autoSaveNr = -1; // number of max simultaneous autosaves private int numberOfSaves = 35; // 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()); setClipboradObjects(new ArrayList()); } /** * @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 AbstractCpsObject getSelectedCpsObject() { return selectedCpsObject; } public void setSelectedCpsObject(AbstractCpsObject selectedCpsObject) { this.selectedCpsObject = selectedCpsObject; } public ArrayList getSelectedCpsObjects() { return selectedObjects; } 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; } /** * @return the numberOfSaves */ public int getNumberOfSaves() { return numberOfSaves; } /** * @param numberOfSaves * the numberOfSaves to set */ public void setNumberOfSaves(int numberOfSaves) { this.numberOfSaves = numberOfSaves; } /** * @param Objects * Array of Objects */ public void setClipboradObjects(ArrayList c) { this.clipboardObjects = c; } /** * * @return Objects in the Clipboard */ public ArrayList getClipboradObjects() { return clipboardObjects; } /** * * @param console * the console */ public void setConsole(Console console) { this.console = console; } /** * * @return console the console */ public Console getConsole() { return console; } /** * @param timerSpeed * speed for the Iterations */ public void setTimerSpeed(int t) { this.timerSpeed = t; } /** * @return timerSpeed speed for the Iterations */ public int getTimerSpeed() { return this.timerSpeed; } /** * @param isSimulation * boolean for for isSimulation */ public void setIsSimulation(boolean b) { this.isSimulation = b; } /** * @return isSimulation boolean for for isSimulation */ public boolean getIsSimulation() { return this.isSimulation; } }