GroupNode.java 4.5 KB

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