From 127f000183cadc24d3b142bba9d7b065c772c6e5 Mon Sep 17 00:00:00 2001 From: MKDrwal Date: Fri, 13 Dec 2019 19:38:40 +0100 Subject: [PATCH] add close connection --- .../java/ftp/sar/controller/MainPageController.java | 3 ++- .../ftp/sar/controller/ServerPanelController.java | 11 ++++++++--- src/main/java/ftp/sar/server/Server.java | 7 +++++++ src/main/resources/server_panel.fxml | 4 ++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/ftp/sar/controller/MainPageController.java b/src/main/java/ftp/sar/controller/MainPageController.java index 2707f9e..64253b4 100644 --- a/src/main/java/ftp/sar/controller/MainPageController.java +++ b/src/main/java/ftp/sar/controller/MainPageController.java @@ -30,7 +30,8 @@ public class MainPageController { FXMLLoader fxmlLoader = new FXMLLoader(resourceLoader.getResource("server_panel.fxml")); Pane panel = fxmlLoader.load(); ServerPanelController serverPanelController = fxmlLoader.getController(); - serverPanelController.setData(server); + serverPanelController.setData(server, this); + server.setServerPanel(serverPanelController); this.serverContainer.getChildren().add(panel); } catch (IOException ex) { ex.printStackTrace(); diff --git a/src/main/java/ftp/sar/controller/ServerPanelController.java b/src/main/java/ftp/sar/controller/ServerPanelController.java index 1f2776c..5d23570 100644 --- a/src/main/java/ftp/sar/controller/ServerPanelController.java +++ b/src/main/java/ftp/sar/controller/ServerPanelController.java @@ -8,6 +8,7 @@ import javafx.fxml.Initializable; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.layout.FlowPane; +import javafx.scene.layout.Pane; import java.net.URL; import java.util.ResourceBundle; @@ -15,7 +16,10 @@ import java.util.ResourceBundle; public class ServerPanelController implements Initializable { private Server server; private FilePaneBuilder filePaneBuilder = new FilePaneBuilder(); + private MainPageController mainPageController; + @FXML + Pane serverPane; @FXML Label serverPort; @FXML @@ -32,10 +36,11 @@ public class ServerPanelController implements Initializable { @FXML public void closeConnection(Event e) { - System.out.println("Close"); + this.mainPageController.serverContainer.getChildren().remove(this.serverPane); } - public void setData(Server server) { + public void setData(Server server, MainPageController mainPageController) { + this.mainPageController = mainPageController; this.server = server; this.serverPort.setText(Integer.toString(server.getPort())); this.serverIp.setText(server.getIp()); @@ -44,7 +49,7 @@ public class ServerPanelController implements Initializable { } private void setFileList() { - for (String filename: this.server.getFileList()) { + for (String filename : this.server.getFileList()) { var pane = this.filePaneBuilder.getPane(filename); this.fileContainer.getChildren().add(pane); diff --git a/src/main/java/ftp/sar/server/Server.java b/src/main/java/ftp/sar/server/Server.java index cdd1c8b..911ec65 100644 --- a/src/main/java/ftp/sar/server/Server.java +++ b/src/main/java/ftp/sar/server/Server.java @@ -1,11 +1,14 @@ package ftp.sar.server; +import ftp.sar.controller.ServerPanelController; + import java.util.ArrayList; public class Server { private String ip; private int port; private ArrayList fileList = new ArrayList<>(); + private ServerPanelController serverPanelController; public Server (String ip, int port) { this.ip = ip; @@ -39,4 +42,8 @@ public class Server { public void addToFileList(String file) { this.fileList.add(file); } + + public void setServerPanel(ServerPanelController serverPanelController) { + this.serverPanelController = serverPanelController; + } } diff --git a/src/main/resources/server_panel.fxml b/src/main/resources/server_panel.fxml index 94b6907..8f48b96 100644 --- a/src/main/resources/server_panel.fxml +++ b/src/main/resources/server_panel.fxml @@ -5,7 +5,7 @@ - +