Model.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package ui.model;
  2. import Interfaces.CategoryListener;
  3. import Interfaces.ObjectListener;
  4. import java.util.ArrayList;
  5. import java.util.LinkedList;
  6. import java.util.List;
  7. import classes.Category;
  8. import classes.CpsObject;
  9. import ui.controller.*;
  10. public class Model {
  11. //Global Variables
  12. public static int SCALE = 50; //Picture Scale
  13. public static int SCALE_DIV2 = SCALE/2;
  14. // ID of the Selected Object
  15. private int selectedID = 0;
  16. // eventuell wenn Canvasgröße gewählt werden kann
  17. private int HEIGHT;
  18. private int WIDTH;
  19. /*
  20. * Array of all categories in the model. It is set by default with the
  21. * categories ENERGY, BUILDINGS and COMPONENTS
  22. */
  23. private ArrayList<Category> categories;
  24. /*
  25. * Array of all CpsObjects in our canvas. It is set by default as an empty
  26. * list.
  27. */
  28. private ArrayList<CpsObject> objectsOnCanvas;
  29. /*
  30. * Array for all Listeners
  31. */
  32. private List<CategoryListener> categoryListeners;
  33. private List<ObjectListener> objectListeners;
  34. /*
  35. * Constructor for the model. It initializes the categories and
  36. * objectsOnCanvas by default values. Listeners are also initialized by
  37. * default values.
  38. */
  39. public Model() {
  40. setCategories(new ArrayList<Category>());
  41. setObjectsOnCanvas(new ArrayList<CpsObject>());
  42. setCategoryListeners(new LinkedList<CategoryListener>());
  43. setObjectListeners(new LinkedList<ObjectListener>());
  44. }
  45. /**
  46. * @return the categories
  47. */
  48. public ArrayList<Category> getCategories() {
  49. return categories;
  50. }
  51. /**
  52. * @param categories
  53. * the categories to set
  54. */
  55. public void setCategories(ArrayList<Category> categories) {
  56. this.categories = categories;
  57. }
  58. /**
  59. * Transform the Arraylist of categories into a string of all objectName
  60. * with a separation (',') between each name
  61. *
  62. * @return String of all names separeted by ','
  63. */
  64. public String toStringCat() {
  65. String text = "";
  66. for (int i = 0; i < categories.size(); i++) {
  67. if (text == "") {
  68. text = categories.get(i).getName();
  69. } else {
  70. text = text + ", " + categories.get(i).getName();
  71. }
  72. }
  73. return text;
  74. }
  75. /**
  76. * @return the objectsOnCanvas
  77. */
  78. public ArrayList<CpsObject> getObjectsOnCanvas() {
  79. return objectsOnCanvas;
  80. }
  81. /**
  82. * @param objectsOnCanvas
  83. * the objectsOnCanvas to set
  84. */
  85. public void setObjectsOnCanvas(ArrayList<CpsObject> objectsOnCanvas) {
  86. this.objectsOnCanvas = objectsOnCanvas;
  87. }
  88. /**
  89. * @return the objectListeners
  90. */
  91. public List<ObjectListener> getObjectListeners() {
  92. return objectListeners;
  93. }
  94. /**
  95. * @param linkedList
  96. * the objectListeners to set
  97. */
  98. public void setObjectListeners(LinkedList<ObjectListener> linkedList) {
  99. this.objectListeners = linkedList;
  100. }
  101. /**
  102. * @return the categoryListeners
  103. */
  104. public List<CategoryListener> getCategoryListeners() {
  105. return categoryListeners;
  106. }
  107. /**
  108. * @param linkedList
  109. * the categoryListeners to set
  110. */
  111. public void setCategoryListeners(LinkedList<CategoryListener> linkedList) {
  112. this.categoryListeners = linkedList;
  113. }
  114. /**
  115. * Set the ID of the selected Object
  116. * 0 = no Object is selected
  117. *
  118. * @param ID
  119. *
  120. */
  121. public void setSelectedObjectID(int id){
  122. this.selectedID = id;
  123. }
  124. /**
  125. * Returns the ID of the selected Object
  126. * 0 = no Object is selected
  127. *
  128. * @return ID
  129. */
  130. public int getSelectedObjectID(){
  131. return selectedID;
  132. }
  133. /**
  134. * Returns SCALE
  135. *
  136. * @return SCALE
  137. */
  138. public int getScale(){
  139. return SCALE;
  140. }
  141. /**
  142. * Returns SCALE_DIV2
  143. *
  144. * @return SCALE_DIV2
  145. */
  146. public int getScaleDiv2(){
  147. return SCALE_DIV2;
  148. }
  149. public void setScale(int s){
  150. SCALE = s;
  151. SCALE_DIV2 = SCALE/2;
  152. }
  153. }