HolonSwitch.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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() {
  60. if (manualMode) {
  61. return this.manualActive;
  62. } else {
  63. return this.autoActive;
  64. }
  65. }
  66. public void setManualState(boolean state) {
  67. this.manualActive = state;
  68. setImage();
  69. }
  70. public void setAutoState(boolean state) {
  71. this.autoActive = state;
  72. setImage();
  73. }
  74. private void setImage() {
  75. if (manualMode) {
  76. if (this.manualActive == false) {
  77. setImage("/Images/switch-off.png");
  78. } else {
  79. setImage("/Images/switch-on.png");
  80. }
  81. } else {
  82. if (this.autoActive == false) {
  83. setImage("/Images/switch-off.png");
  84. } else {
  85. setImage("/Images/switch-on.png");
  86. }
  87. }
  88. }
  89. /**
  90. * @return the Graph Points
  91. */
  92. public LinkedList<Point> getGraphPoints() {
  93. return graphPoints;
  94. }
  95. /**
  96. * @param points,
  97. * the Graph points
  98. */
  99. public void setGraphPoints(LinkedList<Point> points) {
  100. this.graphPoints = points;
  101. }
  102. /**
  103. * get the activeAt Array
  104. */
  105. public boolean[] getActiveAt() {
  106. return activeAt;
  107. }
  108. public boolean getActiveManual() {
  109. return this.manualActive;
  110. }
  111. /**
  112. * @param active,
  113. * the default value
  114. */
  115. public void setActiveAt(boolean active) {
  116. for (int i = 0; i < activeAt.length; i++) {
  117. this.activeAt[i] = active;
  118. }
  119. }
  120. public void setManualMode(boolean mode) {
  121. manualMode = mode;
  122. }
  123. public boolean getManualMode() {
  124. return manualMode;
  125. }
  126. }