123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- package classes;
- import com.google.gson.annotations.Expose;
- import classes.IdCounter.CounterType;
- import java.util.ArrayList;
- import java.util.HashMap;
- public class GroupNode extends AbstractCanvasObject {
- private ArrayList<AbstractCanvasObject> nodes;
- private HashMap<Integer, Integer> nodesIdx;
-
- @Expose
- private int leftBorder; //TODO Delete leftBorder, jet is just set to 0
- @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.setConnections(new ArrayList<>());
- this.setImage("/Images/upper_node.png");
- this.setSav("CVS");
- this.setId(IdCounter.nextId(CounterType.Object));
- this.setNodes(new ArrayList<>());
- this.setNodesIdx(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) {
- nodes.addAll(((GroupNode) temp).getNodesAndGroupnodeNodes());
- }
- }
- return nodes;
- }
-
-
-
- public ArrayList<HolonObject> getNumHolonObj() {
- ArrayList<HolonObject> onlyHolonObj = new ArrayList<HolonObject>();
- for (AbstractCanvasObject temp : getNodes()) {
- if (temp instanceof HolonObject) {
- onlyHolonObj.add((HolonObject) temp);
- }
- if(temp instanceof GroupNode) {
- onlyHolonObj.addAll(((GroupNode) temp).getNumHolonObj());
- }
- }
- return onlyHolonObj;
- }
- public ArrayList<HolonSwitch> getNumSwitches() {
- ArrayList<HolonSwitch> onlySwitsches = new ArrayList<HolonSwitch>();
- for (AbstractCanvasObject temp : getNodes()) {
- if (temp instanceof HolonSwitch) {
- onlySwitsches.add((HolonSwitch) temp);
- }
- if(temp instanceof GroupNode) {
- onlySwitsches.addAll(((GroupNode) temp).getNumSwitches());
- }
- }
- return onlySwitsches;
- }
- public ArrayList<GroupNode> getNumUpperNodes() {
- ArrayList<GroupNode> onlyUpperNodes = new ArrayList<GroupNode>();
- for (AbstractCanvasObject temp : getNodes()) {
- if (temp instanceof GroupNode) {
- onlyUpperNodes.add((GroupNode) temp);
- onlyUpperNodes.addAll(((GroupNode) temp).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;
- }
- /**
- * @return the leftBorder
- */
- public int getLeftBorder() {
- return leftBorder;
- }
- /**
- * @param leftBorder the leftBorder to set
- */
- public void setLeftBorder(int leftBorder) {
- this.leftBorder = leftBorder;
- }
- @Override
- public AbstractCanvasObject makeCopy() {
- return this;
- }
- }
|