GroupNode.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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<HolonObject> getNumHolonObj() {
  54. ArrayList<HolonObject> onlyHolonObj = new ArrayList<HolonObject>();
  55. for (AbstractCanvasObject temp : getNodes()) {
  56. if (temp instanceof HolonObject) {
  57. onlyHolonObj.add((HolonObject) temp);
  58. }
  59. }
  60. return onlyHolonObj;
  61. }
  62. public ArrayList<HolonSwitch> getNumSwitches() {
  63. ArrayList<HolonSwitch> onlySwitsches = new ArrayList<HolonSwitch>();
  64. for (AbstractCanvasObject temp : getNodes()) {
  65. if (temp instanceof HolonSwitch) {
  66. onlySwitsches.add((HolonSwitch) temp);
  67. }
  68. }
  69. return onlySwitsches;
  70. }
  71. public ArrayList<GroupNode> getNumUpperNodes() {
  72. ArrayList<GroupNode> onlyUpperNodes = new ArrayList<GroupNode>();
  73. for (AbstractCanvasObject temp : getNodes()) {
  74. if (temp instanceof GroupNode) {
  75. onlyUpperNodes.add((GroupNode) temp);
  76. }
  77. }
  78. return onlyUpperNodes;
  79. }
  80. public AbstractCanvasObject searchObj(int ID) {
  81. AbstractCanvasObject result = null;
  82. for (AbstractCanvasObject obj : getNodes()) {
  83. if (obj.getId() == ID) {
  84. result = obj;
  85. break;
  86. }
  87. }
  88. return result;
  89. }
  90. /**
  91. * Set the Background Image;
  92. *
  93. * @param imagePath
  94. * Image Path
  95. * @param mode
  96. * Image Mode
  97. * @param width
  98. * Image custom width
  99. * @param height
  100. * Image custom height
  101. */
  102. public void setBackgroundImage(String imagePath, int mode, int width, int height) {
  103. imgPath = imagePath;
  104. backgroundMode = mode;
  105. backgroundWidth = width;
  106. backgroundHeight = height;
  107. }
  108. /**
  109. * Get the Background Image Path.
  110. *
  111. * @return imgPath Path of the Image
  112. */
  113. public String getImagePath() {
  114. return imgPath;
  115. }
  116. /**
  117. * Get the Background mode.
  118. *
  119. * @return mode the mode
  120. */
  121. public int getBackgroundMode() {
  122. return backgroundMode;
  123. }
  124. /**
  125. * Get the Background image Width.
  126. *
  127. * @return mode the width of the Image
  128. */
  129. public int getImageWidht() {
  130. return backgroundWidth;
  131. }
  132. /**
  133. * Get the Background image Height.
  134. *
  135. * @return mode the mode
  136. */
  137. public int getImageHeight() {
  138. return backgroundHeight;
  139. }
  140. /**
  141. * @return the leftBorder
  142. */
  143. public int getLeftBorder() {
  144. return leftBorder;
  145. }
  146. /**
  147. * @param leftBorder the leftBorder to set
  148. */
  149. public void setLeftBorder(int leftBorder) {
  150. this.leftBorder = leftBorder;
  151. }
  152. @Override
  153. public AbstractCanvasObject makeCopy() {
  154. return this;
  155. }
  156. }