CpsUpperNode.java 3.9 KB

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