123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- package ui.model;
- import Interfaces.CategoryListener;
- import Interfaces.ObjectListener;
- import java.util.ArrayList;
- import java.util.LinkedList;
- import java.util.List;
- import classes.Category;
- import classes.CpsObject;
- import ui.controller.*;
- public class Model {
- //Global Variables
- public static int SCALE = 50; //Picture Scale
- public static int SCALE_DIV2 = SCALE/2;
-
- // ID of the Selected Object
- private int selectedID = 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<Category> categories;
- /*
- * Array of all CpsObjects in our canvas. It is set by default as an empty
- * list.
- */
- private ArrayList<CpsObject> objectsOnCanvas;
- /*
- * 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>());
- setCategoryListeners(new LinkedList<CategoryListener>());
- setObjectListeners(new LinkedList<ObjectListener>());
- }
- /**
- * @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 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;
- }
-
- /**
- * 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 s){
- SCALE = s;
- SCALE_DIV2 = SCALE/2;
- }
- }
|