CpsUpperNode.java 4.2 KB

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