1 26 package org.objectweb.util.explorer.swing.graph; 27 28 import java.awt.Dimension ; 29 import java.util.ArrayList ; 30 import java.util.List ; 31 32 import org.jgraph.graph.DefaultGraphCell; 33 34 38 public class PrimitiveVertex extends DefaultGraphCell { 39 40 41 private Object component; 42 43 44 private ArrayList ports; 45 46 47 private ArrayList clientPorts; 48 49 50 private ArrayList serverPorts; 51 52 53 private ArrayList controllerPorts; 54 55 56 private String name; 57 58 59 private Graph graph; 60 61 62 private boolean isStarted; 63 64 65 private boolean isShared; 66 67 68 private int numberServer, numberClient, numberControler, 69 numberInternalServer, numberInternalClient; 70 71 72 transient String type; 73 74 75 private Dimension size = new Dimension (); 76 77 78 private Dimension compositeSize = new Dimension (); 79 80 81 private boolean controllersDisplay; 82 83 private boolean isFirstPaint; 84 85 public PrimitiveVertex(Object component, String name, Graph graph, 86 Dimension compositeSize, boolean controllersDisplay, 87 boolean isStarted, boolean isShared) { 88 super(name); 89 this.name = name; 90 this.graph = graph; 91 this.controllersDisplay = controllersDisplay; 92 this.component = component; 93 this.type = VertexType.PRIMITIF_VERTEX; 94 this.isStarted = isStarted; 95 this.isShared = isShared; 96 ports = new ArrayList (); 97 clientPorts = new ArrayList (); 98 serverPorts = new ArrayList (); 99 controllerPorts = new ArrayList (); 100 numberServer = 0; 101 numberClient = 0; 102 numberControler = 0; 103 numberInternalServer = 0; 104 numberInternalClient = 0; 105 setCompositeSize(compositeSize); 106 isFirstPaint = true; 107 } 108 109 115 public void addPort(Object itf, String name, String type) { 116 MyPort p = null; 117 if ((type.equals(PortType.CLIENT_PORT)) 118 || (type.equals(PortType.COLLECTION_PORT))) { 119 numberClient++; 120 p = new MyPort(itf, name, type, numberClient, false); 121 } else if (type.equals(PortType.SERVER_PORT)) { 122 numberServer++; 123 p = new MyPort(itf, name, type, numberServer, false); 124 } else if (type.equals(PortType.CONTROLLER_PORT)) { 125 numberControler++; 126 p = new MyPort(itf, name, type, numberControler, false); 127 } 128 super.add(p); 129 ports.add(p); 130 } 131 132 public boolean isFirstPaint() { 133 return isFirstPaint; 134 } 135 136 public void setFirstPaint(boolean isFirstPaint) { 137 this.isFirstPaint = isFirstPaint; 138 } 139 140 public boolean isShared() { 141 return isShared; 142 } 143 144 public void setShared(boolean isShared) { 145 this.isShared = isShared; 146 } 147 148 public boolean isStarted() { 149 return isStarted; 150 } 151 152 public void setStarted(boolean isStarted) { 153 this.isStarted = isStarted; 154 } 155 156 public Object getComponent() { 157 return component; 158 } 159 160 public boolean getControllerDisplay() { 161 return controllersDisplay; 162 } 163 164 public void setControllerDisplay(boolean controllersDisplay) { 165 this.controllersDisplay = controllersDisplay; 166 } 167 168 public ArrayList getListPorts() { 169 return ports; 170 } 171 172 177 public MyPort getPort(String name) { 178 for (int i = 0; i < ports.size(); i++) { 179 if (((MyPort) ports.get(i)).getName().equals(name)) 180 return (MyPort) ports.get(i); 181 } 182 return null; 183 } 184 185 192 public MyPort getPort(String name, String type, int number) { 193 List ports; 194 if (type.equals(PortType.CLIENT_PORT)) { 195 ports = getListClientPorts(); 196 } else if (type.equals(PortType.SERVER_PORT)) { 197 ports = getListServerPorts(); 198 } else 199 ports = getListControllerPorts(); 200 201 for (int i = 0; i < ports.size(); i++) { 202 if ((((MyPort) ports.get(i)).getName().equals(name)) 203 && (((MyPort) ports.get(i)).getNumber() == number)) 204 return (MyPort) ports.get(i); 205 } 206 return null; 207 } 208 209 public String getName() { 210 return name; 211 } 212 213 public String getType() { 214 return type; 215 } 216 217 221 public int getPortLabelWidth(MyPort port) { 222 return port.getName().length() * PortGraphicsInterface.PORT_NAME_WIDTH; 223 } 224 225 232 private int getMinWidht(int line) { 233 int minWidth = 0; 234 List servers = getListServerPorts(); 235 List clients = getListClientPorts(); 236 int serversLength = servers.size(); 237 int clientsLength = clients.size(); 238 if ((serversLength > line) && (clientsLength > line)) { 239 MyPort server = (MyPort) servers.get(line); 240 MyPort client = (MyPort) clients.get(line); 241 if (getPortLabelWidth(server) > getPortLabelWidth(client)) 242 minWidth = getPortLabelWidth(server) * 2; 243 else 244 minWidth = getPortLabelWidth(client) * 2; 245 } else if (clientsLength > line) { 246 MyPort client = (MyPort) clients.get(line); 247 minWidth = getPortLabelWidth(client) * 2; 248 } else if (serversLength > line){ 249 MyPort server = (MyPort) servers.get(line); 250 minWidth = getPortLabelWidth(server) * 2; 251 } 252 return minWidth + getName().length()*VertexGraphicsInterface.PRIMITIVE_NAME_WIDTH; 253 } 254 255 260 public int getMinWidth() { 261 int minWidth = 0; 262 List servers = getListServerPorts(); 263 List clients = getListClientPorts(); 264 int serversLength = servers.size(); 265 int clientsLength = clients.size(); 266 if(serversLength>clientsLength){ 267 for(int i=0;i<serversLength;i++){ 268 if(minWidth<getMinWidht(i)) 269 minWidth=getMinWidht(i); 270 } 271 } 272 else{ 273 for(int i=0;i<clientsLength;i++){ 274 if(minWidth<getMinWidht(i)) 275 minWidth=getMinWidht(i); 276 } 277 } 278 279 return minWidth; 280 } 281 282 public ArrayList getListServerPorts() { 283 if (serverPorts.size() == 0) { 284 List ports = getListPorts(); 285 for (int i = 0; i < ports.size(); i++) { 286 if (((MyPort) ports.get(i)).getType().equals( 287 PortType.SERVER_PORT)) 288 serverPorts.add(ports.get(i)); 289 } 290 } 291 return serverPorts; 292 } 293 294 public ArrayList getListClientPorts() { 295 if (clientPorts.size() == 0) { 296 List ports = getListPorts(); 297 for (int i = 0; i < ports.size(); i++) { 298 if ((((MyPort) ports.get(i)).getType() 299 .equals(PortType.CLIENT_PORT)) 300 || (((MyPort) ports.get(i)).getType() 301 .equals(PortType.COLLECTION_PORT))) 302 clientPorts.add(ports.get(i)); 303 } 304 } 305 return clientPorts; 306 } 307 308 public ArrayList getListControllerPorts() { 309 if (controllerPorts.size() == 0) { 310 List ports = getListPorts(); 311 for (int i = 0; i < ports.size(); i++) { 312 if (((MyPort) ports.get(i)).getType().equals( 313 PortType.CONTROLLER_PORT)) 314 controllerPorts.add(ports.get(i)); 315 } 316 } 317 return controllerPorts; 318 } 319 320 324 public Dimension getSize() { 325 VertexGraphicsInterface vg = Graph.getVertexGraphics(); 326 PortGraphicsInterface pg = Graph.getPortGraphics(); 327 int portsServer = getListServerPorts().size(); 328 int portsClients = getListClientPorts().size(); 329 int portsControl = getListControllerPorts().size(); 330 if (size.height < portsServer 331 * PortGraphicsInterface.PORT_NAME_LENGHT) { 332 size.height = portsServer 333 * PortGraphicsInterface.PORT_NAME_LENGHT 334 + PortGraphicsInterface.FIRST_PORT_Y; 335 } 336 if (size.height < portsClients 337 * PortGraphicsInterface.PORT_NAME_LENGHT) { 338 size.height = portsClients 339 * PortGraphicsInterface.PORT_NAME_LENGHT 340 + PortGraphicsInterface.FIRST_PORT_Y; 341 } 342 if (size.width < portsControl 343 * PortGraphicsInterface.CONTROLLER_PORT_WIDTH) { 344 size.width = portsControl 345 * PortGraphicsInterface.CONTROLLER_PORT_WIDTH; 346 } 347 int minWidth=getMinWidth(); 348 if(minWidth>VertexGraphicsInterface.VERTEX_MAX_WIDTH) 349 minWidth=VertexGraphicsInterface.VERTEX_MAX_WIDTH; 350 if (size.width < minWidth) 351 size.width = minWidth; 352 if ((size.height == 0) 353 || (size.height < vg.getDefaultSize().height)) 354 size.height = vg.getDefaultSize().height; 355 if ((size.width == 0) || (size.width < vg.getDefaultSize().width)) 356 size.width = vg.getDefaultSize().width; 357 return size; 358 } 359 360 public void setSize(Dimension d) { 361 size.width = d.width; 362 size.height = d.height; 363 } 364 365 public Dimension getCompositeSize() { 366 return compositeSize; 367 } 368 369 public void setCompositeSize(Dimension d) { 370 compositeSize.width = d.width; 371 compositeSize.height = d.height; 372 } 373 374 } | Popular Tags |