Model.java 3.2 KB

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