went over all classes and added docs where is appropriate and needed

This commit is contained in:
Seraina
2022-04-18 21:57:33 +02:00
parent d25b6c405d
commit 55147ce1cf
21 changed files with 66 additions and 64 deletions

View File

@@ -62,7 +62,6 @@ public class Client {
sendMsgToServer(Protocol.clientLogin + "$" + systemName);
this.chatApp = new ChatApp(new ClientModel(systemName, this));
this.chatGui = new GUI(this.chatApp);
chatGui.setName(systemName);
clientPinger = new ClientPinger(this, this.socket);
} catch (IOException e) {
e.printStackTrace();
@@ -205,6 +204,10 @@ public class Client {
}
}
/**
* The main Method used for testing in IDE
* @param args not used in this main
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String hostname;
@@ -239,6 +242,12 @@ public class Client {
}
/**
* The main-method used for the jar build of this project
* @param address the IP address of the Server (can be localhost)
* @param port the port for the connection
* @param username the username of this client
*/
public static void main(InetAddress address, int port, String username) {
Scanner sc = new Scanner(System.in);
Socket socket;

View File

@@ -31,7 +31,6 @@ public class JClientProtocolParser {
}
switch (header) {
case Protocol.pingFromServer:
c.sendMsgToServer(Protocol.pingBack);
break;
case Protocol.pingBack:

View File

@@ -11,16 +11,13 @@ public class GUI implements Runnable {
public static final Logger LOGGER = LogManager.getLogger(GUI.class);
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
ChatApp chatApp;
private String name;
private ChatApp chatApp;
public GUI(ChatApp chatApp) {
this.chatApp = chatApp;
}
public void setName(String name) {
this.name = name;
}
/**
* When an object implementing interface {@code Runnable} is used to create a thread, starting the
@@ -32,11 +29,9 @@ public class GUI implements Runnable {
* @see Thread#run()
*/
@Override
public void run() {
LOGGER.info("here");
//String name =
Application.launch(this.chatApp.getClass());
}
}

View File

@@ -1,7 +1,6 @@
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.Client;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
import java.net.URL;
import java.util.Objects;
@@ -25,19 +24,28 @@ public class ChatApp extends Application {
public ChatApp() {
super();
LOGGER.info("Empty ChatApp constructor got called: ");
}
public ChatApp(ClientModel clientModel) {
this.clientModel = clientModel;
this.chatController = new ChatController(clientModel);
public ChatApp(ClientModel clientM) {
clientModel = clientM;
chatController = new ChatController(clientM);
}
public static void setChatController(
ChatController chatC) {
/**
* Sets the ChatController for the Application, needs to be static, but only one application can
* be launched per programm
*
* @param chatC the ChatController to be linked to this chatApp
*/
public static void setChatController(ChatController chatC) {
chatController = chatC;
}
/**
* Sets the non-static ClientModel field of this class
*
* @param cModel the non static ClientModel to be added
*/
public void setcModel(ClientModel cModel) {
this.cModel = cModel;
}
@@ -54,6 +62,11 @@ public class ChatApp extends Application {
return clientModel;
}
public ChatController getChatController() {
return chatController;
}
/**
* The main entry point for all JavaFX applications. The start method is called after the init
* method has returned, and after the system is ready for the application to begin running.
@@ -69,11 +82,9 @@ public class ChatApp extends Application {
*/
@Override
public void start(Stage primaryStage) throws Exception {
LOGGER.info("made it here");
this.setcModel(clientModel);
URL resource = ChatApp.class.getResource(
"splitPaneChatView.fxml");
LOGGER.info("1");
if (resource == null) {
System.out.println("File wasnt found");
}
@@ -82,23 +93,16 @@ public class ChatApp extends Application {
Parent root = FXMLLoader.load(
Objects.requireNonNull(ChatApp.class.getResource(
"splitPaneChatView.fxml")));
LOGGER.info("2");
// TODO bin chatController.getChatPaneRoot() border to root border for rezising
Scene scene = new Scene(root);
LOGGER.info("3");
scene.setRoot(root);
LOGGER.info("4");
primaryStage.setScene(scene);
LOGGER.info("5");
} catch (Exception e) {
e.printStackTrace();
}
primaryStage.setResizable(true);
LOGGER.info("6");
primaryStage.setTitle("Chat");
LOGGER.info("7");
primaryStage.show();
LOGGER.info("8");
}
@@ -107,7 +111,4 @@ public class ChatApp extends Application {
launch(args);
}
public ChatController getChatController() {
return chatController;
}
}

View File

@@ -22,7 +22,6 @@ import javafx.scene.control.SplitPane;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import org.apache.logging.log4j.LogManager;
@@ -53,7 +52,10 @@ public class ChatController implements Initializable {
private static final String chatToAll = Protocol.chatMsgToAll;
private static final String chatToLobby = Protocol.chatMsgToLobby;
public ChatController() { //TODO: why does this get called
/**
* Needs to stay, because it gets called in initialisation
*/
public ChatController() {
super();
whisperTargetChosen = new SimpleBooleanProperty();
cmd = Protocol.chatMsgToLobby + "$";
@@ -154,13 +156,15 @@ public class ChatController implements Initializable {
}
/**
* @return the client who's chat controller this is
* @return the ClientModel whose chat controller this is
*/
public static ClientModel getClient() {
return client;
}
/**
* Sets the ClientModel of this ChatController
*
* @param client who's gui controller this should be
*/
public void setClient(ClientModel client) {
@@ -172,7 +176,7 @@ public class ChatController implements Initializable {
}
/**
* The client calls this method to foreward a chat message to the chat gui
* The client calls this method to forward a chat message to the chat gui
*
* @param msg the message to be displayed
*/

View File

@@ -3,7 +3,6 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.helpers;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler;
import java.io.BufferedWriter;
import java.io.IOException;
import java.net.Socket;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

View File

@@ -2,11 +2,6 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.server;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.gamelogic.ClientVoteData;
import ch.unibas.dmi.dbis.cs108.gamelogic.Game;
import ch.unibas.dmi.dbis.cs108.gamelogic.GameState;
import ch.unibas.dmi.dbis.cs108.gamelogic.TrainOverflow;
import ch.unibas.dmi.dbis.cs108.gamelogic.VoteHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;

View File

@@ -43,6 +43,9 @@ public class Server {
}
}
/**
* closes the Server socket of this server
*/
public void closeServerSocket() {
try {
if (serverSocket != null) {
@@ -53,6 +56,10 @@ public class Server {
}
}
/**
* The main method used for testing
* @param args not used in this method
*/
public static void main(String[] args) {
ServerSocket serverSocket = null;
gamePort = 1873;
@@ -65,6 +72,10 @@ public class Server {
server.startServer();
}
/**
* The main method of the Server that is used for the jar build of this project
* @param port the port the server will open on
*/
public static void main(int port) {
gamePort = port;
ServerSocket serverSocket = null;