add close connection

This commit is contained in:
MKDrwal 2019-12-13 19:38:40 +01:00
parent 0e815cb905
commit 127f000183
4 changed files with 19 additions and 6 deletions

View File

@ -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();

View File

@ -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);

View File

@ -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<String> 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;
}
}

View File

@ -5,7 +5,7 @@
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.Pane?>
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefWidth="780.0" style="border: black;" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ftp.sar.controller.ServerPanelController">
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" fx:id="serverPane" prefWidth="780.0" style="border: black;" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ftp.sar.controller.ServerPanelController">
<children>
<Label layoutX="22.0" layoutY="-1.0" prefHeight="30.0" text="IP Addres: " />
<Label fx:id="serverIp" layoutX="88.0" layoutY="5.0" text="xxx.xxx.xxx.xxx" />
@ -13,6 +13,6 @@
<Label fx:id="serverPort" layoutX="236.0" layoutY="6.0" text="xxxx" />
<FlowPane fx:id="fileContainer" layoutY="30.0" maxWidth="1.7976931348623157E308" minWidth="-Infinity" prefWidth="780.0" />
<!-- <Button fx:id="refreshButton" layoutX="640.0" layoutY="0" mnemonicParsing="false" onAction="#refreshList" text="Refresh" />-->
<!-- <Button fx:id="closeButton" layoutX="720.0" layoutY="0" mnemonicParsing="false" onAction="#closeConnection" text="Close" />-->
<Button fx:id="closeButton" layoutX="720.0" layoutY="0" mnemonicParsing="false" onAction="#closeConnection" text="Close" />
</children>
</Pane>