1 26 package org.objectweb.util.explorer.swing.graph; 27 28 import java.awt.Dimension ; 29 import java.awt.Point ; 30 import java.util.ArrayList ; 31 import java.util.List ; 32 33 import org.jgraph.graph.AttributeMap; 34 import org.jgraph.graph.DefaultEdge; 35 import org.jgraph.graph.DefaultGraphCell; 36 import org.jgraph.graph.Edge; 37 import org.jgraph.graph.GraphConstants; 38 import org.jgraph.graph.GraphModel; 39 40 44 public class CompositeVertex 45 extends PrimitiveVertex 46 { 47 48 49 private boolean isOpen = false; 50 51 52 private ArrayList verteces; 53 54 55 private Point origin; 56 57 58 private ArrayList binding; 59 60 61 private ArrayList internalPorts; 62 63 private ArrayList internalServerPorts; 64 65 private ArrayList internalClientPorts; 66 67 private ArrayList internalControllerPorts; 68 69 70 private int numberInternalServer; 71 72 private int numberInternalClient; 73 74 private int numberInternalController; 75 76 88 public CompositeVertex(Object component, String name, Graph graph, 89 Dimension compositeSize, boolean isOpen, 90 boolean controllersDisplay, boolean isStarted, boolean isShared) { 91 super(component, name, graph, compositeSize, controllersDisplay, 92 isStarted, isShared); 93 verteces = new ArrayList (); 94 binding = new ArrayList (); 95 setSize(compositeSize); 96 this.isOpen = isOpen; 97 this.type = VertexType.COMPOSITE_VERTEX; 98 if (isOpen) { 99 verteces.add(this); 100 AttributeMap vAttributes = graph.getModel().createAttributes(); 101 internalPorts = new ArrayList (); 102 internalServerPorts = new ArrayList (); 103 internalClientPorts = new ArrayList (); 104 internalControllerPorts = new ArrayList (); 105 origin = new Point (); 106 } 107 } 108 109 113 public ArrayList getBinding() { 114 return binding; 115 } 116 117 123 public Edge addBinding(GraphModel model) { 124 Edge e = new DefaultEdge(); 125 binding.add(e); 126 AttributeMap eAttributes = model.createAttributes(); 127 attributes.put(e, eAttributes); 128 int style = GraphConstants.STYLE_ORTHOGONAL; 129 GraphConstants.setLineStyle(eAttributes, style); 130 return e; 131 } 132 133 139 public MyPort getInternalPort(String name) { 140 for (int i = 0; i < internalPorts.size(); i++) { 141 if ((((MyPort) internalPorts.get(i)).getName().equals(name)) 142 && (!((MyPort) internalPorts.get(i)).isGenerated())) 143 return (MyPort) internalPorts.get(i); 144 } 145 return null; 146 } 147 148 155 public MyPort getGeneratedPort(String name) { 156 ArrayList internalPorts = getListInternalPorts(); 157 for (int i = 0; i < internalPorts.size(); i++) { 158 if ((((MyPort) internalPorts.get(i)).getName().equals(name)) 159 && (((MyPort) internalPorts.get(i)).isGenerated())) 160 return (MyPort) internalPorts.get(i); 161 } 162 return null; 163 } 164 165 169 public ArrayList getListInternalPorts() { 170 return internalPorts; 171 } 172 173 177 public ArrayList getListInternalServerPorts() { 178 if (internalServerPorts.size() == 0) { 179 List ports = getListInternalPorts(); 180 for (int i = 0; i < ports.size(); i++) { 181 if (((MyPort) ports.get(i)).getType().equals( 182 PortType.SERVER_PORT)) 183 internalServerPorts.add(ports.get(i)); 184 } 185 } 186 return internalServerPorts; 187 } 188 189 193 public ArrayList getListInternalClientPorts() { 194 if (internalClientPorts.size() == 0) { 195 List ports = getListInternalPorts(); 196 for (int i = 0; i < ports.size(); i++) { 197 if (((MyPort) ports.get(i)).getType().equals( 198 PortType.CLIENT_PORT)) 199 internalClientPorts.add(ports.get(i)); 200 } 201 } 202 return internalClientPorts; 203 } 204 205 209 public ArrayList getListInternalControllerPorts() { 210 if (internalControllerPorts.size() == 0) { 211 List ports = getListInternalPorts(); 212 for (int i = 0; i < ports.size(); i++) { 213 if (((MyPort) ports.get(i)).getType().equals( 214 PortType.CONTROLLER_PORT)) 215 internalControllerPorts.add(ports.get(i)); 216 } 217 } 218 return internalControllerPorts; 219 } 220 221 227 public PrimitiveVertex getVertex(String name) { 228 for (int i = 0; i < verteces.size(); i++) { 229 if (((PrimitiveVertex) verteces.get(i)).getName().equals(name)) 230 return (PrimitiveVertex) verteces.get(i); 231 } 232 return null; 233 } 234 235 247 public void addVertex(Object component, String name, Graph graph, 248 String type, boolean isOpen, boolean controllersDisplay, 249 boolean isStarted, boolean isShared) { 250 PortGraphicsInterface pg = Graph.getPortGraphics(); 251 VertexGraphicsInterface vg = Graph.getVertexGraphics(); 252 DefaultGraphCell vertex; 253 if (type.equals(VertexType.PRIMITIF_VERTEX)) { 254 vertex = new PrimitiveVertex(component, name, graph, getSize(), 255 controllersDisplay, isStarted, isShared); 256 AttributeMap vAttributes = graph.getModel().createAttributes(); 257 attributes.put(vertex, vAttributes); 258 } else { 259 vertex = new CompositeVertex(component, name, graph, vg 260 .getDefaultSize(), isOpen, controllersDisplay, isStarted, 261 isShared); 262 } 263 verteces.add(vertex); 264 } 265 266 274 public void addSubComponentPort(String vertexName, Object itf, 275 String portName, String type) { 276 PrimitiveVertex v = getVertex(vertexName); 277 v.addPort(itf, portName, type); 278 } 279 280 287 public void addCompositePort(Object itf, String portName, String type) { 288 MyPort initialPort = null; 289 MyPort generatedPort = null; 290 if ((type.equals(PortType.CLIENT_PORT)) 291 || (type.equals(PortType.COLLECTION_PORT))) { 292 numberInternalClient++; 293 initialPort = new MyPort(itf, portName, type, numberInternalClient, 294 false); 295 generatedPort = new MyPort(itf, portName, PortType.SERVER_PORT, 296 numberInternalClient, true); 297 internalPorts.add(generatedPort); 298 super.add(generatedPort); 299 } else if (type.equals(PortType.SERVER_PORT)) { 300 numberInternalServer++; 301 initialPort = new MyPort(itf, portName, type, numberInternalServer, 302 false); 303 generatedPort = new MyPort(itf, portName, PortType.CLIENT_PORT, 304 numberInternalServer, true); 305 internalPorts.add(generatedPort); 306 super.add(generatedPort); 307 } else if (type.equals(PortType.CONTROLLER_PORT)) { 308 numberInternalController++; 309 initialPort = new MyPort(itf, portName, type, 310 numberInternalController, false); 311 } 312 internalPorts.add(initialPort); 313 super.add(initialPort); 314 } 315 316 319 public boolean isOpen() { 320 return isOpen; 321 } 322 323 326 public void setOpen(boolean isOpen) { 327 this.isOpen = isOpen; 328 } 329 330 334 public ArrayList getVerteces() { 335 return verteces; 336 } 337 338 342 public Point getOrigin() { 343 return origin; 344 } 345 346 349 public void setOrigin(Point p) { 350 origin.x = p.x; 351 origin.y = p.y; 352 } 353 354 } | Popular Tags |