123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342 |
- 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 ArrayList<CpsObject> selectedObjects = new ArrayList<CpsObject>();
- private ArrayList<CpsObject> clipboardObjects = new ArrayList<CpsObject>();
- private int selectedID = 0;
- private int autoSaveNr = -1;
- // 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<Category> categories;
- /*
- * Array of all CpsObjects in our canvas. It is set by default as an empty
- * list.
- */
- private ArrayList<CpsObject> objectsOnCanvas;
-
- private HashMap<String, Integer> cgIdx;
- private HashMap<Integer, Integer> cvsObjIdx;
- /*
- * Array of all CpsObjects in our canvas. It is set by default as an empty
- * list.
- */
- private ArrayList<CpsEdge> edgesOnCanvas;
- /*
- * Array for all Listeners
- */
- private List<CategoryListener> categoryListeners;
- private List<ObjectListener> 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<Category>());
- setObjectsOnCanvas(new ArrayList<CpsObject>());
- setEdgesOnCanvas(new ArrayList<CpsEdge>());
- setCategoryListeners(new LinkedList<CategoryListener>());
- setObjectListeners(new LinkedList<ObjectListener>());
- setCgIdx(new HashMap<String,Integer>());
- setCvsObjIdx(new HashMap<Integer,Integer>());
- setClipboradObjects(new ArrayList<CpsObject>());
- }
- /**
- * @return the categories
- */
- public ArrayList<Category> getCategories() {
- return categories;
- }
- /**
- * @param categories
- * the categories to set
- */
- public void setCategories(ArrayList<Category> 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<CpsObject> getObjectsOnCanvas() {
- return objectsOnCanvas;
- }
- /**
- * @param objectsOnCanvas
- * the objectsOnCanvas to set
- */
- public void setObjectsOnCanvas(ArrayList<CpsObject> objectsOnCanvas) {
- this.objectsOnCanvas = objectsOnCanvas;
- }
- /**
- * @return the objectsOnCanvas
- */
- public ArrayList<CpsEdge> 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<CpsEdge> arrayList) {
- this.edgesOnCanvas = arrayList;
- }
- /**
- * @return the objectListeners
- */
- public List<ObjectListener> getObjectListeners() {
- return objectListeners;
- }
- /**
- * @param linkedList
- * the objectListeners to set
- */
- public void setObjectListeners(LinkedList<ObjectListener> linkedList) {
- this.objectListeners = linkedList;
- }
- /**
- * @return the categoryListeners
- */
- public List<CategoryListener> getCategoryListeners() {
- return categoryListeners;
- }
- /**
- * @param linkedList
- * the categoryListeners to set
- */
- public void setCategoryListeners(LinkedList<CategoryListener> 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 ArrayList<CpsObject> 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<String, Integer> getCgIdx() {
- return cgIdx;
- }
- /**
- * @param cgIdx the cgIdx to set
- */
- public void setCgIdx(HashMap<String, Integer> cgIdx) {
- this.cgIdx = cgIdx;
- }
- /**
- * @return the cvsObjIdx
- */
- public HashMap<Integer, Integer> getCvsObjIdx() {
- return cvsObjIdx;
- }
- /**
- * @param cvsObjIdx the cvsObjIdx to set
- */
- public void setCvsObjIdx(HashMap<Integer, Integer> cvsObjIdx) {
- this.cvsObjIdx = cvsObjIdx;
- }
-
- public void setAutoSaveNr(int autoSaveNr){
- this.autoSaveNr = autoSaveNr;
- }
-
- public int getAutoSaveNr(){
- return autoSaveNr;
- }
- public void setClipboradObjects(ArrayList<CpsObject> c){
- this.clipboardObjects = c;
- }
-
- public ArrayList<CpsObject> getClipboradObjects(){
- return clipboardObjects;
- }
- }
|