diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..1c24f9a --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/src/netKnow/Class/IP.java b/src/netKnow/Class/IP.java index 43a2830..83984af 100644 --- a/src/netKnow/Class/IP.java +++ b/src/netKnow/Class/IP.java @@ -1,6 +1,6 @@ package netKnow.Class; -public class IP { +public class IP implements Comparable { private int [] ipArray; private int [] maskArray; private String fullIPAdress []; @@ -15,15 +15,18 @@ public IP(String [] fullIPAdress){ ipArray = new int[4]; maskArray = new int[4]; this.fullIPAdress = fullIPAdress; + convertStringToIPAdress(fullIPAdress); + convertStringToMask(); } + private void convertStringToIPAdress(String [] fullIPAdress){ for(int i = 0; i < 4; i++) { ipArray[i] = Integer.parseInt(fullIPAdress[i]); } } - private void convertStringToMask(String mask){ + private void convertStringToMask(){ int n = Integer.parseInt(fullIPAdress[4]); for(int i = 0; i < n; i++){ maskArray[i/8] |= (128 >> (i%8)); @@ -31,8 +34,6 @@ private void convertStringToMask(String mask){ } public void computeData(){ - convertStringToIPAdress(fullIPAdress); - convertStringToMask(fullIPAdress[4]); network = computeNetwork(); broadcast = computeBroadcast(); numberOfHosts = Integer.toString(numberOfHosts()); @@ -77,6 +78,22 @@ private String maxHost() return (tmp1[0] + "." + tmp1[1] + "." + tmp1[2] + "." + tmp2); } + public int compareTo(IP ip){ + if(this.ipArray[0] == ip.ipArray[0] && this.ipArray[1] == ip.ipArray[1] && this.ipArray[2] == ip.ipArray[2] + && this.ipArray[3] == ip.ipArray[3]){ + return 0; + } + else if((this.ipArray[0] > ip.ipArray[0]) || (this.ipArray[0] == ip.ipArray[0] && this.ipArray[1] > ip.ipArray[1]) || + (this.ipArray[0] == ip.ipArray[0] && this.ipArray[1] == ip.ipArray[1] && this.ipArray[2] > ip.ipArray[2]) || + (this.ipArray[0] == ip.ipArray[0] && this.ipArray[1] == ip.ipArray[1] && this.ipArray[2] == ip.ipArray[2] + && this.ipArray[3] > ip.ipArray[3])){ + return 1; + } + else{ + return -1; + } + } + public String getNetwork() { return network; } @@ -96,4 +113,17 @@ public String getMinHost() { public String getNumberOfHosts() { return numberOfHosts; } + + public String getIP(){ + return (ipArray[0]+ "." + ipArray[1]+ "." + ipArray[2]+ "." + ipArray[3] + "/" + fullIPAdress[4]); + } + + public int[] getIPAsInt(){ return ipArray; } + + public int getMaskAsInt(){return Integer.parseInt(fullIPAdress[4]);} + + public void setMask(int k){ + fullIPAdress[4] = Integer.toString(k); + convertStringToMask(); + }; } diff --git a/src/netKnow/Class/routing/CiscoConfigurationCodeGenerator.java b/src/netKnow/Class/routing/CiscoConfigurationCodeGenerator.java new file mode 100644 index 0000000..285a7f5 --- /dev/null +++ b/src/netKnow/Class/routing/CiscoConfigurationCodeGenerator.java @@ -0,0 +1,132 @@ +package netKnow.Class.routing; + +import java.util.List; + +/** + * Created by MQ on 2017-06-06. + */ +public class CiscoConfigurationCodeGenerator { + List routersList; + List nodes; + + public CiscoConfigurationCodeGenerator(List routersList, List nodes){ + this.routersList = routersList; + this.nodes = nodes; + } + + public String getConfiguration(){ + String out = ""; + for(int i=0; i 0){ + NodeLinkData data = connectedToInterfaceNode.nodeLinks.get(i).nodeLinkData; + for(int j=0; j mLinkIds = new ArrayList(); + public List nodeLinks = new ArrayList<>(); + public List nodePCLink = new ArrayList<>(); + public List pcList = new ArrayList<>(); private EventHandler mContextDragOver; private EventHandler mContextDragDropped; - private EventHandler mLinkHandleDragDetected; // wykrycie przeciagania - private EventHandler mLinkHandleDragDropped; // wykrycie konca przeciagania - private EventHandler mContextLinkDragOver; // wykrycie przeciagania z drugim obiektem - private EventHandler mContextLinkDragDropped; // wykrycie konca przeciagania z drugim obiektem + public EventHandler mLinkHandleDragDetected; // wykrycie przeciagania + public EventHandler mLinkHandleDragDropped; // wykrycie konca przeciagania + public EventHandler mContextLinkDragOver; // wykrycie przeciagania z drugim obiektem + public EventHandler mContextLinkDragDropped; // wykrycie konca przeciagania z drugim obiektem private NodeLink mDragLink; private AnchorPane rightPane; @@ -47,6 +54,7 @@ public class DraggableNode extends AnchorPane{ private DragIconType mType = null; private Point2D mDragOffset = new Point2D(0.0, 0.0); public DraggableNodeData draggableNodeData; + public RIPInfo ripInfo; public DraggableNode() { self = this; @@ -66,6 +74,11 @@ public DraggableNode() { setId(UUID.randomUUID().toString()); } + public DraggableNode(String id){ + self = this; + setId(id); + } + public void setTitleBar(String titleBarText) { titleBar.setText(titleBarText); } @@ -274,13 +287,20 @@ public void setType(DragIconType type) { case switchIco: nodeBody.getStyleClass().add("icon-switch"); break; - case labelIco: - nodeBody.getStyleClass().add("icon-label"); - break; - default: break; } } + public void setHostLabels(String host){ + rightHostLabel.setText(host); + leftHostLabel.setText(host); + topHostLabel.setText(host); + bottomHostLabel.setText(host); + } + + public void setIpTop(String ip){ + topHostLabel.setText(ip); + } + } \ No newline at end of file diff --git a/src/netKnow/Class/routing/DraggableNodeData.java b/src/netKnow/Class/routing/DraggableNodeData.java index db2c07f..91dd8cb 100644 --- a/src/netKnow/Class/routing/DraggableNodeData.java +++ b/src/netKnow/Class/routing/DraggableNodeData.java @@ -7,10 +7,17 @@ public class DraggableNodeData { private String name; private String host; + private String ip; - public DraggableNodeData(String name, String host){ + public DraggableNodeData(String name, String x){ this.name = name; - this.host = host; + if(x.length() > 3){ + this.ip = x; + System.out.println("IP: " + this.ip); + }else{ + this.host = x; + System.out.println("host: " + this.host); + } } public String getName(){ @@ -20,4 +27,23 @@ public String getName(){ public String getHost(){ return host; } + + public String getIp() { + return ip; + } + + public String getIpWithoutMask(){ + String [] pp = ip.split("/"); + return pp[0]; + } + + public String getMask(){ + System.out.println("MY IP IS: " + ip); + String [] pp = ip.split("/"); + int cidrMask = Integer.parseInt(pp[1]); + long bits = 0; + bits = 0xffffffff ^ (1 << 32 - cidrMask) - 1; + String mask = String.format("%d.%d.%d.%d", (bits & 0x0000000000ff000000L) >> 24, (bits & 0x0000000000ff0000) >> 16, (bits & 0x0000000000ff00) >> 8, bits & 0xff); + return mask; + } } diff --git a/src/netKnow/Class/routing/JuniperConfigurationCodeGenerator.java b/src/netKnow/Class/routing/JuniperConfigurationCodeGenerator.java new file mode 100644 index 0000000..b788562 --- /dev/null +++ b/src/netKnow/Class/routing/JuniperConfigurationCodeGenerator.java @@ -0,0 +1,134 @@ +package netKnow.Class.routing; + +import java.util.List; + +/** + * Created by MQ on 2017-06-06. + */ +public class JuniperConfigurationCodeGenerator { + + List routersList; + List nodes; + + public JuniperConfigurationCodeGenerator(List routersList, List nodes){ + this.routersList = routersList; + this.nodes = nodes; + } + + public String getConfiguration(){ + String out = ""; + for(int i=0; i 0){ + NodeLinkData data = connectedToInterfaceNode.nodeLinks.get(i).nodeLinkData; + for(int j=0; j x2 && y1 > y2)){ // source lub target prawy gorny rog degree = 90 - degree; } + if( y1 == y2 ){ + degree = 0; + } return degree; } } diff --git a/src/netKnow/Class/routing/NodeLinkData.java b/src/netKnow/Class/routing/NodeLinkData.java index b443806..4e788f8 100644 --- a/src/netKnow/Class/routing/NodeLinkData.java +++ b/src/netKnow/Class/routing/NodeLinkData.java @@ -20,11 +20,38 @@ public NodeLinkData(String octetFirst, String octetSecond, String octetThird, St this.typeOfConnection = typeOfConnection; } + public NodeLinkData(String ip){ + String [] ipAndMask = ip.split("/"); + String [] ipAddress = ipAndMask[0].split("\\."); + this.mask = ipAndMask[1]; + this.octetFirst = ipAddress[0]; + this.octetSecond = ipAddress[1]; + this.octetThird = ipAddress[2]; + this.octetFourth = ipAddress[3]; + this.typeOfConnection = "Kabel lan"; + } + public String getAddress(){ return octetFirst + "." + octetSecond + "." + octetThird + "." + octetFourth + "/" + mask; } + public String getAddressToInterface(){ + return octetFirst + "." + octetSecond + "." + octetThird + "."; + } + + public String getMask() { + return mask; + } + public String getTypeOfConnection(){ return typeOfConnection; } + + public String getMaskCisco(){ + int cidrMask = Integer.parseInt(mask); + long bits = 0; + bits = 0xffffffff ^ (1 << 32 - cidrMask) - 1; + String mask = String.format("%d.%d.%d.%d", (bits & 0x0000000000ff000000L) >> 24, (bits & 0x0000000000ff0000) >> 16, (bits & 0x0000000000ff00) >> 8, bits & 0xff); + return mask; + } } diff --git a/src/netKnow/Class/routing/RIPInfo.java b/src/netKnow/Class/routing/RIPInfo.java new file mode 100644 index 0000000..b7eadc9 --- /dev/null +++ b/src/netKnow/Class/routing/RIPInfo.java @@ -0,0 +1,72 @@ +package netKnow.Class.routing; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by MQ on 2017-06-05. + */ +public class RIPInfo { + + private DraggableNode routerFrom; + public List ripWayList; + private DraggableNode[] prev; + private List orderedRouters; + + public RIPInfo(DraggableNode[] prev, List orderedRouters){ + routerFrom = orderedRouters.get(0); + this.prev = prev; + this.orderedRouters = orderedRouters; + ripWayList = new ArrayList<>(); + fillWayList(); + showWayList(); + } + + public void showWayList(){ + System.out.println("Way for: " + routerFrom.titleBar.getText()); + for(int i=0; i way; + + public RIPWay(DraggableNode dest){ + destination = dest; + way = new ArrayList<>(); + } + + public void addToEnd(DraggableNode x){ + way.add(x); + } + + public void addToStart(DraggableNode x){ + way.add(0, x); + } + + public DraggableNode getDestination() { + return destination; + } + + public void setDestination(DraggableNode destination) { + this.destination = destination; + } + + public List getWay() { + return way; + } +} diff --git a/src/netKnow/Code/NetworkAggregation.java b/src/netKnow/Code/NetworkAggregation.java new file mode 100644 index 0000000..ddf07b6 --- /dev/null +++ b/src/netKnow/Code/NetworkAggregation.java @@ -0,0 +1,70 @@ +package netKnow.Code; + +import netKnow.Class.IP; + +import java.util.Arrays; + + +/** + * Created by Kuba on 16.05.2017. + */ +public class NetworkAggregation { + private IP[] IPArray; + + public NetworkAggregation(IP[] Array) { + this.IPArray = Array; + } + + private int search(IP search){ + int key = -1; + int i = 0; + while(i < this.IPArray.length){ + if(this.IPArray[i].getIP().equals(search.getIP())){ + key = i; + } + i++; + } + return key; + } + + public IP[] aggregateNetwork() { + int [][] tmp = new int[IPArray.length][4]; + IP [] result = new IP[IPArray.length]; + for (int i = 0; i < IPArray.length; i++) { + tmp[i] = IPArray[i].getIPAsInt(); + } + int k = 0; + Arrays.sort(IPArray); + for(int i = 0; i < IPArray.length; i++){ + int [] tmp2 = tmp[i]; + int [] tmp3 = IPArray[i].getIPAsInt(); + int j = IPArray[i].getMaskAsInt() - 1; + int mask = j+1; + int mask1 = mask; + if(j < 7){ + return null; + } + String [] tmpString1 = {Integer.toString(tmp3[0]), Integer.toString(tmp3[1]), Integer.toString(tmp3[2]), + Integer.toString(tmp3[3]), Integer.toString(mask)}; + result[k] = new IP(tmpString1); + while((tmp3[j / 8] & (128 >> j%8)) == 0) { + tmp2[j / 8] |= 128 >> j % 8; + String[] tmpString = {Integer.toString(tmp2[0]), Integer.toString(tmp2[1]), Integer.toString(tmp2[2]), + Integer.toString(tmp2[3]), Integer.toString(mask1)}; + IP newIP = new IP(tmpString); + int key = search(newIP); + if (key > 0) { + i = key; + mask = j; + } + result[k].setMask(mask); + j--; + } + k++; + } + if(k > 1){ + return null; + } + return result; + } +} \ No newline at end of file diff --git a/src/netKnow/DatabaseConnection.java b/src/netKnow/DatabaseConnection.java index 4a121cd..6cc169e 100644 --- a/src/netKnow/DatabaseConnection.java +++ b/src/netKnow/DatabaseConnection.java @@ -5,7 +5,7 @@ import java.sql.SQLException; public class DatabaseConnection { - private final static String DBURL = "jdbc:mysql://sql.slowiak.nazwa.pl:3306/slowiak"; + private final static String DBURL = "jdbc:mysql://sql.slowiak.nazwa.pl:3306/slowiak?serverTimezone=UTC"; private final static String DBURL2 = "jdbc:mysql://127.0.0.1:3306/slowiak?serverTimezone=UTC"; private final static String DBUSER = "slowiak"; private final static String DBUSER2 = "root"; @@ -14,8 +14,8 @@ public class DatabaseConnection { public static Connection getConenction(){ try { - //connection = DriverManager.getConnection(DBURL, DBUSER, DBPASS); - connection = DriverManager.getConnection(DBURL2, DBUSER2, DBPASS); + connection = DriverManager.getConnection(DBURL, DBUSER, DBPASS); + //connection = DriverManager.getConnection(DBURL2, DBUSER2, DBPASS); if(connection != null){ System.out.println("Connected to the datebase :D"); return connection; diff --git a/src/netKnow/Main.java b/src/netKnow/Main.java index d36e14c..a0a3bd1 100644 --- a/src/netKnow/Main.java +++ b/src/netKnow/Main.java @@ -1,32 +1,38 @@ package netKnow; +import com.mysql.cj.core.conf.IntegerPropertyDefinition; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.VBox; import javafx.stage.Stage; import netKnow.scene.LoginScene; +import netKnow.scene.MainOptionsScene; import netKnow.scene.RoutingScene; +import netKnow.Class.IP; +import netKnow.Code.NetworkAggregation; public class Main extends Application { private Stage window; + + @Override public void start(Stage primaryStage) throws Exception{ window = primaryStage; window.setTitle("netKnow - aplication that will change your life"); - Scene scene = new Scene(new VBox(), 1000, 800); + Scene scene = new Scene(new VBox(), 1400, 1000); window.setScene(scene); - //new LoginScene(scene); - new RoutingScene(scene); + new LoginScene(scene); + //new RoutingScene(scene); window.show(); //window.setFullScreen(true); } public static void main(String[] args) { - launch(args); + launch(args); } } diff --git a/src/netKnow/TODOfile b/src/netKnow/TODOfile new file mode 100644 index 0000000..fb26516 --- /dev/null +++ b/src/netKnow/TODOfile @@ -0,0 +1,9 @@ +/// Klasy do zrobienia + +-> Router(PC) +-> Switch +-> Siec + + +-> przy robieniu linkNode nie ma resetowania wartosci w textfieldach +-> wywalic do pliku hasla \ No newline at end of file diff --git a/src/netKnow/controller/AggregationController.java b/src/netKnow/controller/AggregationController.java new file mode 100644 index 0000000..e68d31d --- /dev/null +++ b/src/netKnow/controller/AggregationController.java @@ -0,0 +1,111 @@ +package netKnow.controller; + +import javafx.fxml.FXML; +import javafx.geometry.Pos; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.ScrollPane; +import javafx.scene.control.TextField; +import javafx.scene.input.KeyCode; +import javafx.scene.layout.HBox; +import javafx.scene.layout.VBox; +import javafx.scene.paint.Color; +import netKnow.Class.IP; +import netKnow.Code.NetworkAggregation; +import netKnow.scene.AggregationPopUp; +import netKnow.scene.MainOptionsScene; +import netKnow.scene.SingleIP; + +import java.util.ArrayList; +import java.util.List; + +public class +AggregationController { + private Scene scene; + + @FXML + private TextField amountNetwork; + @FXML + private Button okButton; + @FXML + private VBox networkListVbox; + @FXML + private Button backButton; + @FXML + private Button aggregateButton; + @FXML + private Label errorLabel; + + List arrayListSingleIp; + int amount=0; + boolean clickedAggregation = false; + + public IP[] aggregatedNetwork; + + @FXML + void initialize(){ + amountNetwork.setOnKeyPressed(event -> { + if(event.getCode() == KeyCode.ENTER ){ + okButton.fire(); + } + }); + okButton.setOnAction(event -> { + + amount = Integer.parseInt(amountNetwork.getText()); + + networkListVbox.getChildren().clear(); + if(amount > 10){ + errorLabel.setText("Liczba sieci do agregacji nie może być > 10"); + }else if(amount < 1){ + errorLabel.setText("Liczba nie może być <= 0"); + }else{ + arrayListSingleIp = new ArrayList<>(); + for (int i=0; i { + + if( clickedAggregation ){ + + IP [] IPArray = new IP[amount]; + for (int i=0; i { + new MainOptionsScene(scene); + + }); + + } + + public void setScene(Scene scene){ + this.scene = scene; + } + +} diff --git a/src/netKnow/controller/CodeGeneratorController.java b/src/netKnow/controller/CodeGeneratorController.java new file mode 100644 index 0000000..3a862c0 --- /dev/null +++ b/src/netKnow/controller/CodeGeneratorController.java @@ -0,0 +1,49 @@ +package netKnow.controller; + +/** + * Created by MQ on 2017-06-06. + */ +import javafx.fxml.FXML; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.TextArea; +import javafx.scene.layout.GridPane; +import netKnow.Class.routing.CiscoConfigurationCodeGenerator; +import netKnow.Class.routing.DraggableNode; +import netKnow.Class.routing.JuniperConfigurationCodeGenerator; +import netKnow.scene.MainOptionsScene; + +import java.util.List; + +public class CodeGeneratorController { + + private Scene scene; + @FXML + private TextArea textAreaField; + @FXML + private GridPane buttons; + @FXML + private Button menuButton; + @FXML + private Button jakisButton; + List routersList; + List nodeList; + String code; + String typeOfDevice; + + + @FXML + void initialize(){ + menuButton.setOnAction(e-> new MainOptionsScene(scene)); + } + + public void setScene(Scene scene){ + this.scene = scene; + } + + public void setDevicesLists(String code, List routersList, List nodeList){ + this.routersList = routersList; + this.nodeList = nodeList; + textAreaField.setText(code); + } +} diff --git a/src/netKnow/controller/MainOptionsController.java b/src/netKnow/controller/MainOptionsController.java index a287714..eb7370e 100644 --- a/src/netKnow/controller/MainOptionsController.java +++ b/src/netKnow/controller/MainOptionsController.java @@ -3,6 +3,7 @@ import javafx.fxml.FXML; import javafx.scene.Scene; import javafx.scene.control.Button; +import netKnow.scene.AggregationScene; import netKnow.scene.IPCalculatorScene; import netKnow.scene.RoutingScene; @@ -14,11 +15,14 @@ public class MainOptionsController { private Button calculatorIPButton; @FXML private Button routingButton; + @FXML + private Button aggregationButton; @FXML void initialize(){ calculatorIPButton.setOnAction(e -> new IPCalculatorScene(scene)); routingButton.setOnAction(e -> new RoutingScene(scene)); + aggregationButton.setOnAction(event -> new AggregationScene(scene)); } public void setScene(Scene scene){ diff --git a/src/netKnow/controller/RegistrationController.java b/src/netKnow/controller/RegistrationController.java index c42bcad..d2869a8 100644 --- a/src/netKnow/controller/RegistrationController.java +++ b/src/netKnow/controller/RegistrationController.java @@ -10,6 +10,7 @@ import netKnow.MailSender; import netKnow.PasswordEncrypter; import netKnow.scene.LoginScene; +import netKnow.scene.SuccessfulRegistrationScene; import javax.mail.MessagingException; import java.security.MessageDigest; @@ -85,6 +86,7 @@ void initialize(){ } catch (MessagingException e1) { e1.printStackTrace(); } + new SuccessfulRegistrationScene(scene); }else{ registrationErrorLabel.setText("Hasła nie pasują do siebie"); } diff --git a/src/netKnow/controller/RoutingController.java b/src/netKnow/controller/RoutingController.java index adc933d..3dc2699 100644 --- a/src/netKnow/controller/RoutingController.java +++ b/src/netKnow/controller/RoutingController.java @@ -1,26 +1,35 @@ package netKnow.controller; +import javafx.embed.swing.SwingFXUtils; import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.geometry.Point2D; import javafx.scene.Node; import javafx.scene.Scene; +import javafx.scene.SnapshotParameters; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.SplitPane; +import javafx.scene.image.WritableImage; import javafx.scene.input.ClipboardContent; import javafx.scene.input.DragEvent; import javafx.scene.input.TransferMode; import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.GridPane; import javafx.scene.layout.VBox; +import javafx.scene.paint.Color; +import javafx.scene.paint.Paint; +import javafx.scene.shape.Circle; import javafx.scene.text.Font; import netKnow.Class.routing.NodeLinkData; import netKnow.Class.routing.*; -import netKnow.scene.DraggableNodePopUp; -import netKnow.scene.MainOptionsScene; -import netKnow.scene.NodeLinkPopUp; -import netKnow.scene.RoutingTypeScene; +import netKnow.scene.*; +import javax.imageio.ImageIO; +import java.io.File; +import java.io.IOException; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; @@ -31,6 +40,8 @@ public class RoutingController { private Scene scene; + @FXML + private GridPane gridPane; @FXML SplitPane base_pane; @FXML @@ -44,6 +55,8 @@ public class RoutingController { Button goBackButton; @FXML Button routingTypeButton; + @FXML + Button screenshotButton; private DragIcon mDragOverIcon = null; @@ -57,28 +70,57 @@ private void initialize() { goBackButton.setOnAction(e -> new MainOptionsScene(scene)); routingTypeButton.setOnAction(e -> { + // sciaganie nodow do listy nodow List nodes = new ArrayList<>(); for(int i=0; i{ + WritableImage image = right_pane.snapshot(new SnapshotParameters(), null); + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); + LocalDate localDate = LocalDate.now(); + String nameOfFile = dtf.format(localDate); + nameOfFile = nameOfFile.replace(" ", "_"); + nameOfFile = nameOfFile.replace("/", ""); + nameOfFile = nameOfFile.replace(":", ""); + File file = new File("D:\\netKnowApp\\"+ nameOfFile + ".png"); + try { + ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file); + } catch (IOException e1) { + e1.printStackTrace(); + } }); //Add one icon that will be used for the drag-drop process //This is added as a child to the root anchorpane so it can be visible //on both sides of the split pane. mDragOverIcon = new DragIcon(); - mDragOverIcon.setVisible(false); mDragOverIcon.setOpacity(0.65); root_pane.getChildren().add(mDragOverIcon); - String [] labels = {"Komputer", "Router", "Switch", "Chodar"}; + String [] labels = {"Komputer", "Router", "Switch"}; //populate left pane with multiple colored icons for testing - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 3; i++) { DragIcon icn = new DragIcon(); Label descriptionLabel = new Label(labels[i]); @@ -154,8 +196,6 @@ private void buildDragHandlers() { }; mIconDragDropped = event -> { - System.out.println("drag dropped"); - DragContainer container = (DragContainer) event.getDragboard().getContent(DragContainer.AddNode); container.addData("scene_coords", new Point2D(event.getSceneX(), event.getSceneY())); @@ -179,12 +219,27 @@ private void buildDragHandlers() { if (container != null) { if (container.getValue("scene_coords") != null) { DraggableNode droppedIcon = new DraggableNode(); - DraggableNodeData draggableNodeData = DraggableNodePopUp.display(); + DragIconType dragIconType = DragIconType.valueOf(container.getValue("type")); + DraggableNodeData draggableNodeData; + + if(dragIconType.equals(DragIconType.routerIco)){ + draggableNodeData = DraggableNodeRouterPopUp.display(); + }else if(dragIconType.equals(DragIconType.pcIco)){ + draggableNodeData = DraggableNodePCPopUp.display(); + }else{ + draggableNodeData = DraggableNodeSwitchPopUp.display(); + } if(draggableNodeData != null) { droppedIcon.draggableNodeData = draggableNodeData; - droppedIcon.setTitleBar(draggableNodeData.getName() + " (" + draggableNodeData.getHost() + ")"); - droppedIcon.setType(DragIconType.valueOf(container.getValue("type"))); + if(dragIconType.equals(DragIconType.routerIco)){ + droppedIcon.setHostLabels("."+draggableNodeData.getHost()); + }else if(dragIconType.equals(DragIconType.pcIco)){ + droppedIcon.setIpTop(draggableNodeData.getIp()); + } + + droppedIcon.setTitleBar(draggableNodeData.getName()); + droppedIcon.setType(dragIconType); right_pane.getChildren().add(droppedIcon); Point2D cursorPoint = container.getValue("scene_coords"); @@ -236,8 +291,16 @@ private void buildDragHandlers() { if (source != null && target != null){ link.setStartAndEnd(sourceId, targetId); link.bindEnds(source, target); + NodeLinkData ipAddress; + + if(source.getType().equals(DragIconType.switchIco)){ + ipAddress = new NodeLinkData(source.draggableNodeData.getIp()); + }else if(target.getType().equals(DragIconType.switchIco)){ + ipAddress = new NodeLinkData(target.draggableNodeData.getIp()); + }else{ + ipAddress = NodeLinkPopUp.display(); + } - NodeLinkData ipAddress = NodeLinkPopUp.display(); if(ipAddress != null){ link.infoLabel.setText(ipAddress.getAddress()); link.relocateLabelCoords(right_pane); @@ -255,4 +318,5 @@ private void buildDragHandlers() { public void setScene(Scene scene){ this.scene = scene; } + } diff --git a/src/netKnow/controller/RoutingTypeController.java b/src/netKnow/controller/RoutingTypeController.java index fcb79ba..dd81415 100644 --- a/src/netKnow/controller/RoutingTypeController.java +++ b/src/netKnow/controller/RoutingTypeController.java @@ -1,12 +1,22 @@ package netKnow.controller; +import com.sun.org.apache.xpath.internal.SourceTree; import javafx.collections.FXCollections; import javafx.fxml.FXML; +import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.CheckBox; import javafx.scene.control.ChoiceBox; import javafx.scene.control.ComboBox; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.GridPane; +import netKnow.Class.routing.*; +import netKnow.scene.CodeGeneratorScene; +import netKnow.scene.SimulationScene; + +import java.util.ArrayList; +import java.util.List; /** * Created by MQ on 2017-05-19. @@ -14,40 +24,191 @@ public class RoutingTypeController { private Scene scene; + private GridPane scheme; @FXML private ComboBox typeOfDeviceChoiceBox; @FXML - private ComboBox typeOfRoutingChoiceBox; - @FXML private Button generateCodeButton; @FXML private Button simulationButton; - + private List nodeList; + private List routersList; + private List routersAndSwitchesList; + private AnchorPane context; @FXML void initialize(){ generateCodeButton.setOnAction(e ->{ - System.out.println("Tu bedzie generowanie kodu!"); + String typeOfConnection = typeOfDeviceChoiceBox.getValue(); + new CodeGeneratorScene(scene, typeOfConnection, routersList, nodeList); }); simulationButton.setOnAction(e -> { + for(int i=0; i nodeList){ + this.nodeList = nodeList; + setRoutersList(); + setNodePCLink(); + setPCConnectedToRouters(); + } + + private void setRoutersList(){ + routersList = new ArrayList<>(); + routersAndSwitchesList = new ArrayList<>(); + for(int i=0; i(); + System.out.println("Aktualny size to: "+routersList.size()); + routersList.add(new DraggableNode("R1")); // 0 + routersList.add(new DraggableNode("R2")); // 1 + routersList.add(new DraggableNode("R3")); // 2 + routersList.add(new DraggableNode("R4")); // 3 + routersList.add(new DraggableNode("R5")); // 4 + routersList.get(0).nodeLinks.add(new NodeLink("r1-connect1", "R1", "R2")); + routersList.get(0).nodeLinks.add(new NodeLink("r1-connect2", "R1", "R3")); + routersList.get(0).nodeLinks.add(new NodeLink("r1-connect3", "R1", "R4")); + routersList.get(1).nodeLinks.add(new NodeLink("r2-connect1", "R2", "R1")); + routersList.get(1).nodeLinks.add(new NodeLink("r2-connect2", "R2", "R4")); + routersList.get(2).nodeLinks.add(new NodeLink("r3-connect1", "R3", "R1")); + routersList.get(2).nodeLinks.add(new NodeLink("r3-connect2", "R3", "R4")); + routersList.get(3).nodeLinks.add(new NodeLink("r4-connect1", "R4", "R1")); + routersList.get(3).nodeLinks.add(new NodeLink("r4-connect2", "R4", "R2")); + routersList.get(3).nodeLinks.add(new NodeLink("r4-connect3", "R4", "R3")); + routersList.get(3).nodeLinks.add(new NodeLink("r4-connect4", "R4", "R5")); + routersList.get(4).nodeLinks.add(new NodeLink("r5-connect1", "R5", "R4")); + + } + + private DraggableNode[] countRIPPaths(int v){ + //setMyOwnRoutersAndLinkers(); + + int [] distance = new int[routersAndSwitchesList.size()]; + DraggableNode [] previous = new DraggableNode[routersAndSwitchesList.size()]; + + for(int i=0; i distance[l] + weight){ + distance[index] = distance[l] + weight; + previous[index] = routersAndSwitchesList.get(l); + } + } + } + } + + /*for(int i=0; i{ + new LoginScene(scene); + }); + } + + public void setScene(Scene scene){ + this.scene = scene; + } +} diff --git a/src/netKnow/fxml/code_generator_scene.fxml b/src/netKnow/fxml/code_generator_scene.fxml new file mode 100644 index 0000000..643f666 --- /dev/null +++ b/src/netKnow/fxml/code_generator_scene.fxml @@ -0,0 +1,38 @@ + + + + + + + + +
+ +
+ + + + + + + + + + + + - + + + + + + + + diff --git a/src/netKnow/fxml/routing_layout.fxml b/src/netKnow/fxml/routing_layout.fxml index de97aab..eff0d30 100644 --- a/src/netKnow/fxml/routing_layout.fxml +++ b/src/netKnow/fxml/routing_layout.fxml @@ -10,7 +10,7 @@ - + @@ -39,7 +39,7 @@ - + @@ -48,6 +48,7 @@