HolonSwitch.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package classes;
  2. import java.awt.Point;
  3. import java.util.LinkedList;
  4. public class HolonSwitch extends CpsObject {
  5. /*
  6. * manual state True, if this wire is working (capable of carrying
  7. * electricity), else false
  8. */
  9. boolean manualActive;
  10. /*
  11. * active state True, if this wire is working (capable of carrying
  12. * electricity), else false
  13. */
  14. boolean autoActive;
  15. /*
  16. * true if switch has to be used manually
  17. */
  18. boolean manualMode;
  19. /*
  20. * Energy at each point of the graph with 50 predefined points. At the
  21. * beginning, it starts with all values at energy
  22. */
  23. boolean[] activeAt = new boolean[100];
  24. // Points on the UnitGraph
  25. LinkedList<Point> graphPoints = new LinkedList<>();
  26. public HolonSwitch(String ObjName) {
  27. super(ObjName);
  28. setManualState(true);
  29. setAutoState(true);
  30. setActiveAt(true);
  31. setManualMode(false);
  32. }
  33. public HolonSwitch(String ObjName, String obj) {
  34. super(ObjName);
  35. super.setName(obj);
  36. setManualState(true);
  37. setAutoState(true);
  38. setActiveAt(true);
  39. setManualMode(false);
  40. }
  41. public HolonSwitch(CpsObject obj) {
  42. super(obj);
  43. super.setName(obj.getName());
  44. setManualState(true);
  45. setAutoState(true);
  46. setActiveAt(true);
  47. setManualMode(false);
  48. }
  49. public void switchState() {
  50. if (manualMode) {
  51. if (this.manualActive == true) {
  52. setImage("/Images/switch-off.png");
  53. } else {
  54. setImage("/Images/switch-on.png");
  55. }
  56. this.manualActive = !manualActive;
  57. }
  58. }
  59. public boolean getState(int timeStep){
  60. if(manualMode){
  61. return this.manualActive;
  62. } else {
  63. return getActiveAt()[timeStep];
  64. }
  65. }
  66. public boolean getState() {
  67. if (manualMode) {
  68. return this.manualActive;
  69. } else {
  70. return this.autoActive;
  71. }
  72. }
  73. public void setManualState(boolean state) {
  74. this.manualActive = state;
  75. setImage();
  76. }
  77. public void setAutoState(boolean state) {
  78. this.autoActive = state;
  79. setImage();
  80. }
  81. private void setImage() {
  82. if (manualMode) {
  83. if (this.manualActive == false) {
  84. setImage("/Images/switch-off.png");
  85. } else {
  86. setImage("/Images/switch-on.png");
  87. }
  88. } else {
  89. if (this.autoActive == false) {
  90. setImage("/Images/switch-off.png");
  91. } else {
  92. setImage("/Images/switch-on.png");
  93. }
  94. }
  95. }
  96. /**
  97. * @return the Graph Points
  98. */
  99. public LinkedList<Point> getGraphPoints() {
  100. return graphPoints;
  101. }
  102. /**
  103. * @param points,
  104. * the Graph points
  105. */
  106. public void setGraphPoints(LinkedList<Point> points) {
  107. this.graphPoints = points;
  108. }
  109. /**
  110. * get the activeAt Array
  111. */
  112. public boolean[] getActiveAt() {
  113. return activeAt;
  114. }
  115. public boolean getActiveManual() {
  116. return this.manualActive;
  117. }
  118. /**
  119. * @param active,
  120. * the default value
  121. */
  122. public void setActiveAt(boolean active) {
  123. for (int i = 0; i < activeAt.length; i++) {
  124. this.activeAt[i] = active;
  125. }
  126. }
  127. public void setManualMode(boolean mode) {
  128. manualMode = mode;
  129. }
  130. public boolean getManualMode() {
  131. return manualMode;
  132. }
  133. }