public static void draw(Pane canvas, ContextMenu contextMenu) { System.out.println("Number of Vm's Present " + application.Data.vmMap.keySet().size()); System.out.println("Number of Hub's Present " + application.Data.hubMap.keySet().size()); // the pane should be cleared each time canvas.getChildren().clear(); // if(!Data.vmMap.isEmpty() && !Data.hubMap.isEmpty()) { // if(!(Data.hubMap.size() == 0)) { canvas.getChildren().add(createVlanNode("V2", canvas, contextMenu)); // } // we don't actually want to change the value of Data.hubStartPosY // instead we initially set our tempPosY to the startPos and alter that int tempPosX = Data.hubStartPosX; int tempPosY = Data.hubStartPosY; // Draw a Blue rectangle for each hub for (Map.Entry<String, HUB> hubEntry : application.Data.hubMap.entrySet()) { String currentHubName = hubEntry.getKey(); HUB currentHub = application.Data.hubMap.get(currentHubName); currentHub.setPosX(tempPosX); currentHub.setPosY(tempPosY); canvas.getChildren().add(application.Graphics.createHUBNode(currentHub, canvas, contextMenu)); // cashe wither the hub has connections // if it don't then theres no need to draw the lines boolean haveConnections = !currentHub.getInfs().isEmpty(); // ----- Draws a horizontal line from the hub to the middle of the space // between hubs and vms if (haveConnections) { drawLine(canvas, tempPosX + 100, tempPosY + 50, tempPosX + 150, tempPosY + 50); } // Draw a Red rectangle for each vm tempPosX += 200; for (Map.Entry<String, VM> vmEntry : application.Data.vmMap.entrySet()) { String currentVMName = vmEntry.getKey(); VM currentVM = application.Data.vmMap.get(currentVMName); for (Map.Entry<String, String> vmInterface : currentVM.getInterfaces().entrySet()) { // If the the first three octals of the vm's interface match // the first three octals of the hub's subnet // Draw the vm to the left of the hub as they are connected int ipClass = Data.getIPClass(application.Data.hubMap.get(currentHubName).getNetmask()); String replaceRegex = "\\.\\d{1," + String.valueOf(ipClass) + "}\\z"; if (vmInterface .getValue() .replaceAll(replaceRegex, "") .equals( application.Data.hubMap .get(currentHubName) .getSubnet() .replaceAll(replaceRegex, ""))) { application.Data.hubMap .get(currentHubName) .addInf(currentVM.getName() + "." + vmInterface.getKey()); currentVM.setPosX(tempPosX); currentVM.setPosY(tempPosY); canvas .getChildren() .add(application.Graphics.createVMNode(currentVM, canvas, contextMenu)); // draws a horizontal line from each vm to the middle of // the space between hubs and vms if (haveConnections) { drawLine(canvas, tempPosX, tempPosY + 50, tempPosX - 50, tempPosY + 50); } tempPosY += 150; } } } if (!haveConnections) { tempPosY += 150; } // draw vertical in the middle of the space between hubs and vms if (haveConnections) { drawLine(canvas, tempPosX - 50, currentHub.getPosY() + 50, tempPosX - 50, tempPosY - 100); } // draw horizontal line from the vlan to the hub drawLine( canvas, Data.vlanstartPosX + 100, currentHub.getPosY() + 50, currentHub.getPosX(), currentHub.getPosY() + 50); tempPosX += 200; // tempPosY += 150; } }