Model.java 3.2 KB

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