HolonSwitch.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. package classes;
  2. import java.awt.Point;
  3. import java.util.LinkedList;
  4. public class HolonSwitch extends AbstractCpsObject {
  5. /**
  6. * The class HolonSwitch represents an Object in the system, that has the
  7. * capacity of manipulate the electricity flow. The switch can be manage
  8. * automatically through a graph or direct manually.
  9. *
  10. * @author Gruppe14
  11. *
  12. */
  13. /*
  14. * manual state True, if this wire is working (capable of carrying
  15. * electricity), else false
  16. */
  17. boolean manualActive;
  18. /*
  19. * active state True, if this wire is working (capable of carrying
  20. * electricity), else false
  21. */
  22. boolean autoActive;
  23. /*
  24. * true if switch has to be used manually
  25. */
  26. boolean manualMode;
  27. /*
  28. * Energy at each point of the graph with 50 predefined points. At the
  29. * beginning, it starts with all values at energy
  30. */
  31. boolean[] activeAt = new boolean[100];
  32. // Points on the UnitGraph
  33. LinkedList<Point> graphPoints = new LinkedList<>();
  34. /**
  35. * Create a new HolonSwitch with the default name ("Switch"), a default
  36. * value of automatic handle and active status
  37. *
  38. * @param ObjName
  39. * String
  40. */
  41. public HolonSwitch(String ObjName) {
  42. super(ObjName);
  43. setManualState(true);
  44. setAutoState(true);
  45. setActiveAt(true);
  46. setManualMode(false);
  47. }
  48. /**
  49. * Create a new HolonSwitch with user-defined name, a default value of
  50. * automatic handle and active status
  51. *
  52. * @param ObjName
  53. * String
  54. * @param obj
  55. * String
  56. */
  57. public HolonSwitch(String ObjName, String obj) {
  58. super(ObjName);
  59. super.setName(obj);
  60. setManualState(true);
  61. setAutoState(true);
  62. setActiveAt(true);
  63. setManualMode(false);
  64. }
  65. /**
  66. * Create a copy of an existing HolonSwitch.
  67. *
  68. * @param obj
  69. */
  70. public HolonSwitch(AbstractCpsObject obj) {
  71. super(obj);
  72. super.setName(obj.getName());
  73. setManualState(true);
  74. setAutoState(true);
  75. setActiveAt(true);
  76. setManualMode(false);
  77. }
  78. /**
  79. * Calculates the state of the Switch
  80. */
  81. public void switchState() {
  82. if (manualMode) {
  83. if (this.manualActive == true) {
  84. setImage("/Images/switch-off.png");
  85. } else {
  86. setImage("/Images/switch-on.png");
  87. }
  88. this.manualActive = !manualActive;
  89. }
  90. }
  91. /**
  92. * Getter for the status of the Switch at a given timestep
  93. *
  94. * @param timeStep
  95. * int
  96. * @return state value
  97. */
  98. public boolean getState(int timeStep) {
  99. if (manualMode) {
  100. return this.manualActive;
  101. } else {
  102. return getActiveAt()[timeStep];
  103. }
  104. }
  105. /**
  106. * Overall status of the switch (manual or automatic mode)
  107. *
  108. * @return
  109. */
  110. public boolean getState() {
  111. if (manualMode) {
  112. return this.manualActive;
  113. } else {
  114. return this.autoActive;
  115. }
  116. }
  117. /**
  118. * Change the state of the Switch to manual
  119. *
  120. * @param state
  121. */
  122. public void setManualState(boolean state) {
  123. this.manualActive = state;
  124. setImage();
  125. }
  126. /**
  127. * Set the state of the Switch to automatic
  128. *
  129. * @param state
  130. */
  131. public void setAutoState(boolean state) {
  132. this.autoActive = state;
  133. setImage();
  134. }
  135. /**
  136. * Set Image of the Switch
  137. */
  138. private void setImage() {
  139. if (manualMode) {
  140. if (this.manualActive == false) {
  141. setImage("/Images/switch-off.png");
  142. } else {
  143. setImage("/Images/switch-on.png");
  144. }
  145. } else {
  146. if (this.autoActive == false) {
  147. setImage("/Images/switch-off.png");
  148. } else {
  149. setImage("/Images/switch-on.png");
  150. }
  151. }
  152. }
  153. /**
  154. * For automatic use only (throught the graph)
  155. *
  156. * @return the Graph Points
  157. */
  158. public LinkedList<Point> getGraphPoints() {
  159. return graphPoints;
  160. }
  161. /**
  162. * Set the values of the switch in the graph (auto. mode only)
  163. *
  164. * @param points,
  165. * the Graph points
  166. */
  167. public void setGraphPoints(LinkedList<Point> points) {
  168. this.graphPoints = points;
  169. }
  170. /**
  171. * All values of the graph for the selected Switch (only auto-Mode) get the
  172. * activeAt Array
  173. */
  174. public boolean[] getActiveAt() {
  175. return activeAt;
  176. }
  177. /**
  178. * Overall value of the Swtich (only manual-Mode)
  179. *
  180. * @return
  181. */
  182. public boolean getActiveManual() {
  183. return this.manualActive;
  184. }
  185. /**
  186. * Set the value of the Switch
  187. *
  188. * @param active,
  189. * the default value
  190. */
  191. public void setActiveAt(boolean active) {
  192. for (int i = 0; i < activeAt.length; i++) {
  193. this.activeAt[i] = active;
  194. }
  195. }
  196. /**
  197. * Set the overall value of the Switch (manual mode)
  198. *
  199. * @param mode
  200. */
  201. public void setManualMode(boolean mode) {
  202. manualMode = mode;
  203. }
  204. /**
  205. * Get the value of the switch (manual mode)
  206. *
  207. * @return
  208. */
  209. public boolean getManualMode() {
  210. return manualMode;
  211. }
  212. }