1 23 24 package org.objectweb.fractal.gui.model; 25 26 import org.objectweb.fractal.gui.model.Configuration; 27 import java.util.List ; 28 import java.util.ArrayList ; 29 30 33 34 public abstract class AbstractComponent implements Component { 35 36 39 40 private Configuration owner; 41 42 46 47 protected Component parent; 48 49 53 public Component getParent () { 54 return parent; 55 } 56 57 62 63 public Configuration getConfiguration () { 64 return owner; 65 } 66 67 73 74 void setParent (final Component parent) { 75 this.parent = parent; 76 } 77 78 public Component getRootComponent () { 79 Component c = this; 80 while (c != null && c.getParent() != null) { 81 c = c.getParent(); 82 } 83 return c; 84 } 85 86 public Object [] getPath () { 87 Component c = this; 88 List pathList = new ArrayList (); 89 while (c != null) { 90 pathList.add(0, c); 91 c = c.getParent(); 92 } 93 return pathList.toArray(); 94 } 95 96 public boolean contains (final Component child) { 97 Component c = child; 98 while (c != null && c != this) { 99 c = c.getParent(); 100 } 101 return c == this; 102 } 103 104 public boolean containsSlaveOfExternalComponent (final Component c) { 105 Component master = getMasterComponent(); 106 if (master != null && !c.contains(master)) { 107 return true; 108 } 109 List subComponents = getSubComponents(); 110 for (int i = 0; i < subComponents.size(); ++i) { 111 Component subComponent = (Component)subComponents.get(i); 112 if (subComponent.containsSlaveOfExternalComponent(c)) { 113 return true; 114 } 115 } 116 return false; 117 } 118 119 public boolean containsMasterOfExternalComponent (final Component c) { 120 List slaves = getSlaveComponents(); 121 for (int i = 0; i < slaves.size(); ++i) { 122 Component slave = (Component)slaves.get(i); 123 if (!c.contains(slave)) { 124 return true; 125 } 126 } 127 List subComponents = getSubComponents(); 128 for (int i = 0; i < subComponents.size(); ++i) { 129 Component subComponent = (Component)subComponents.get(i); 130 if (subComponent.containsMasterOfExternalComponent(c)) { 131 return true; 132 } 133 } 134 return false; 135 } 136 } 137 | Popular Tags |