123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- package holeg.model;
- import com.google.gson.annotations.Expose;
- import java.util.ArrayList;
- import java.util.HashMap;
- public class GroupNode extends AbstractCanvasObject {
- private ArrayList<AbstractCanvasObject> nodes = new ArrayList<>();
- private HashMap<Integer, Integer> nodesIdx = new HashMap<>();
-
- @Expose
- private String imgPath = "";
- @Expose
- private int backgroundMode = 0;
- @Expose
- private int backgroundWidth = 0;
- @Expose
- private int backgroundHeight = 0;
- public GroupNode(String nodeName) {
- super(nodeName);
- this.setImage("/Images/upper_node.png");
- this.setSav("CVS");
- }
- @Override
- public void initForReflection() {
- super.initForReflection();
- nodes = new ArrayList<>();
- nodesIdx = new HashMap<>();
- }
-
-
-
-
- /**
- * @return the nodes
- */
- public ArrayList<AbstractCanvasObject> getNodes() {
- return nodes;
- }
- /**
- * @param nodes
- * the nodes to set
- */
- public void setNodes(ArrayList<AbstractCanvasObject> nodes) {
- this.nodes = nodes;
- }
- /**
- * @return the nodesIdx
- */
- public HashMap<Integer, Integer> getNodesIdx() {
- return nodesIdx;
- }
- /**
- * @param nodesIdx
- * the nodesIdx to set
- */
- public void setNodesIdx(HashMap<Integer, Integer> nodesIdx) {
- this.nodesIdx = nodesIdx;
- }
- public ArrayList<AbstractCanvasObject> getNodesAndGroupnodeNodes(){
- ArrayList<AbstractCanvasObject> nodes = new ArrayList<AbstractCanvasObject>();
- nodes.addAll(getNodes());
- for (AbstractCanvasObject temp : getNodes()) {
- if(temp instanceof GroupNode groupnode) {
- nodes.addAll(groupnode.getNodesAndGroupnodeNodes());
- }
- }
- return nodes;
- }
-
-
-
- public ArrayList<HolonObject> getNumHolonObj() {
- ArrayList<HolonObject> onlyHolonObj = new ArrayList<HolonObject>();
- for (AbstractCanvasObject temp : getNodes()) {
- if (temp instanceof HolonObject hO) {
- onlyHolonObj.add(hO);
- }
- if(temp instanceof GroupNode groupnode) {
- onlyHolonObj.addAll(groupnode.getNumHolonObj());
- }
- }
- return onlyHolonObj;
- }
- public ArrayList<HolonSwitch> getNumSwitches() {
- ArrayList<HolonSwitch> onlySwitsches = new ArrayList<HolonSwitch>();
- for (AbstractCanvasObject temp : getNodes()) {
- if (temp instanceof HolonSwitch sw) {
- onlySwitsches.add(sw);
- }
- if(temp instanceof GroupNode groupnode) {
- onlySwitsches.addAll(groupnode.getNumSwitches());
- }
- }
- return onlySwitsches;
- }
- public ArrayList<GroupNode> getNumUpperNodes() {
- ArrayList<GroupNode> onlyUpperNodes = new ArrayList<GroupNode>();
- for (AbstractCanvasObject temp : getNodes()) {
- if (temp instanceof GroupNode groupnode) {
- onlyUpperNodes.add(groupnode);
- onlyUpperNodes.addAll(groupnode.getNumUpperNodes());
- }
- }
- return onlyUpperNodes;
- }
- public AbstractCanvasObject searchObj(int ID) {
- AbstractCanvasObject result = null;
- for (AbstractCanvasObject obj : getNodes()) {
- if (obj.getId() == ID) {
- result = obj;
- break;
- }
- }
- return result;
- }
- /**
- * Set the Background Image;
- *
- * @param imagePath
- * Image Path
- * @param mode
- * Image Mode
- * @param width
- * Image custom width
- * @param height
- * Image custom height
- */
- public void setBackgroundImage(String imagePath, int mode, int width, int height) {
- imgPath = imagePath;
- backgroundMode = mode;
- backgroundWidth = width;
- backgroundHeight = height;
- }
- /**
- * Get the Background Image Path.
- *
- * @return imgPath Path of the Image
- */
- public String getImagePath() {
- return imgPath;
- }
- /**
- * Get the Background mode.
- *
- * @return mode the mode
- */
- public int getBackgroundMode() {
- return backgroundMode;
- }
- /**
- * Get the Background image Width.
- *
- * @return mode the width of the Image
- */
- public int getImageWidht() {
- return backgroundWidth;
- }
- /**
- * Get the Background image Height.
- *
- * @return mode the mode
- */
- public int getImageHeight() {
- return backgroundHeight;
- }
- }
|