CpsUpperNode.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. package classes;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import com.google.gson.annotations.Expose;
  5. public class CpsUpperNode extends AbstractCpsObject {
  6. private ArrayList<AbstractCpsObject> nodes;
  7. private ArrayList<CpsEdge> nodeEdges;
  8. private ArrayList<CpsEdge> oldEdges;
  9. private HashMap<Integer, Integer> nodesIdx;
  10. @Expose
  11. private int leftBorder = 0;
  12. // Background Image
  13. @Expose
  14. private String imgPath = "";
  15. @Expose
  16. private int backgroundMode = 0;
  17. @Expose
  18. private int backgroundWidth = 0;
  19. @Expose
  20. private int backgroundHeight = 0;
  21. public CpsUpperNode(String nodeName) {
  22. super(nodeName);
  23. this.setConnections(new ArrayList<CpsEdge>());
  24. this.setImage("/Images/upper_node.png");
  25. this.setSav("CVS");
  26. this.setId(IdCounter.nextId());
  27. this.setNodes(new ArrayList<AbstractCpsObject>());
  28. this.setNodeEdges(new ArrayList<CpsEdge>());
  29. this.setOldEdges(new ArrayList<CpsEdge>());
  30. this.setNodesIdx(new HashMap<Integer, Integer>());
  31. // TODO Auto-generated constructor stub
  32. }
  33. /**
  34. * @return the nodes
  35. */
  36. public ArrayList<AbstractCpsObject> getNodes() {
  37. return nodes;
  38. }
  39. /**
  40. * @param nodes
  41. * the nodes to set
  42. */
  43. public void setNodes(ArrayList<AbstractCpsObject> nodes) {
  44. this.nodes = nodes;
  45. }
  46. /**
  47. * @return the nodeEdges
  48. */
  49. public ArrayList<CpsEdge> getNodeEdges() {
  50. return nodeEdges;
  51. }
  52. /**
  53. * @param nodeEdges
  54. * the nodeEdges to set
  55. */
  56. public void setNodeEdges(ArrayList<CpsEdge> nodeEdges) {
  57. this.nodeEdges = nodeEdges;
  58. }
  59. /**
  60. * @return the oldEdges
  61. */
  62. public ArrayList<CpsEdge> getOldEdges() {
  63. return oldEdges;
  64. }
  65. /**
  66. * @param oldEdges
  67. * the oldEdges to set
  68. */
  69. public void setOldEdges(ArrayList<CpsEdge> oldEdges) {
  70. this.oldEdges = oldEdges;
  71. }
  72. /**
  73. * @return the nodesIdx
  74. */
  75. public HashMap<Integer, Integer> getNodesIdx() {
  76. return nodesIdx;
  77. }
  78. /**
  79. * @param nodesIdx
  80. * the nodesIdx to set
  81. */
  82. public void setNodesIdx(HashMap<Integer, Integer> nodesIdx) {
  83. this.nodesIdx = nodesIdx;
  84. }
  85. public ArrayList<HolonObject> getNumHolonObj() {
  86. ArrayList<HolonObject> onlyHolonObj = new ArrayList<HolonObject>();
  87. for (AbstractCpsObject temp : getNodes()) {
  88. if (temp instanceof HolonObject) {
  89. onlyHolonObj.add((HolonObject) temp);
  90. }
  91. }
  92. return onlyHolonObj;
  93. }
  94. public ArrayList<HolonSwitch> getNumSwitches() {
  95. ArrayList<HolonSwitch> onlySwitsches = new ArrayList<HolonSwitch>();
  96. for (AbstractCpsObject temp : getNodes()) {
  97. if (temp instanceof HolonSwitch) {
  98. onlySwitsches.add((HolonSwitch) temp);
  99. }
  100. }
  101. return onlySwitsches;
  102. }
  103. public ArrayList<CpsUpperNode> getNumUpperNodes() {
  104. ArrayList<CpsUpperNode> onlyUpperNodes = new ArrayList<CpsUpperNode>();
  105. for (AbstractCpsObject temp : getNodes()) {
  106. if (temp instanceof CpsUpperNode) {
  107. onlyUpperNodes.add((CpsUpperNode) temp);
  108. }
  109. }
  110. return onlyUpperNodes;
  111. }
  112. public AbstractCpsObject searchObj(int ID) {
  113. AbstractCpsObject result = null;
  114. for (AbstractCpsObject obj : getNodes()) {
  115. if (obj.getId() == ID) {
  116. result = obj;
  117. break;
  118. }
  119. }
  120. return result;
  121. }
  122. /**
  123. * Set the Background Image;
  124. *
  125. * @param imagePath
  126. * Image Path
  127. * @param mode
  128. * Image Mode
  129. * @param width
  130. * Image custom width
  131. * @param height
  132. * Image custom height
  133. */
  134. public void setBackgroundImage(String imagePath, int mode, int width, int height) {
  135. imgPath = imagePath;
  136. backgroundMode = mode;
  137. backgroundWidth = width;
  138. backgroundHeight = height;
  139. }
  140. /**
  141. * Get the Background Image Path.
  142. *
  143. * @return imgPath Path of the Image
  144. */
  145. public String getImagePath() {
  146. return imgPath;
  147. }
  148. /**
  149. * Get the Background mode.
  150. *
  151. * @return mode the mode
  152. */
  153. public int getBackgroundMode() {
  154. return backgroundMode;
  155. }
  156. /**
  157. * Get the Background image Width.
  158. *
  159. * @return mode the width of the Image
  160. */
  161. public int getImageWidht() {
  162. return backgroundWidth;
  163. }
  164. /**
  165. * Get the Background image Height.
  166. *
  167. * @return mode the mode
  168. */
  169. public int getImageHeight() {
  170. return backgroundHeight;
  171. }
  172. /**
  173. * @return the leftBorder
  174. */
  175. public int getLeftBorder() {
  176. return leftBorder;
  177. }
  178. /**
  179. * @param leftBorder the leftBorder to set
  180. */
  181. public void setLeftBorder(int leftBorder) {
  182. this.leftBorder = leftBorder;
  183. }
  184. }