GroupNode.java 4.4 KB

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