Added static field to ChatApp and set it to the current application in the start()
This commit is contained in:
parent
7ba20a9f62
commit
edf5c65da2
@ -62,6 +62,7 @@ public class Client {
|
|||||||
sendMsgToServer(Protocol.clientLogin + "$" + systemName);
|
sendMsgToServer(Protocol.clientLogin + "$" + systemName);
|
||||||
this.chatApp = new ChatApp(new ClientModel(systemName, this));
|
this.chatApp = new ChatApp(new ClientModel(systemName, this));
|
||||||
this.chatGUi = new GUI(this.chatApp);
|
this.chatGUi = new GUI(this.chatApp);
|
||||||
|
chatGUi.setName(systemName);
|
||||||
clientPinger = new ClientPinger(this, this.socket);
|
clientPinger = new ClientPinger(this, this.socket);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -220,8 +221,10 @@ public class Client {
|
|||||||
cP.start();
|
cP.start();
|
||||||
client.userInputListener(); //this one blocks.
|
client.userInputListener(); //this one blocks.
|
||||||
//Start the GUI
|
//Start the GUI
|
||||||
Thread guiThread = new Thread(client.chatGUi);
|
GUI gui = new GUI(client.chatApp);
|
||||||
|
Thread guiThread = new Thread(gui);
|
||||||
guiThread.start();
|
guiThread.start();
|
||||||
|
LOGGER.info("7");
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
System.out.println("Invalid host IP");
|
System.out.println("Invalid host IP");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -240,14 +243,17 @@ public class Client {
|
|||||||
Thread cP = new Thread(client.clientPinger);
|
Thread cP = new Thread(client.clientPinger);
|
||||||
cP.start();
|
cP.start();
|
||||||
client.userInputListener(); //this one blocks.
|
client.userInputListener(); //this one blocks.
|
||||||
|
LOGGER.info("7.1");
|
||||||
Thread guiThread = new Thread(client.chatGUi);
|
Thread guiThread = new Thread(client.chatGUi);
|
||||||
|
LOGGER.info("8");
|
||||||
guiThread.start();
|
guiThread.start();
|
||||||
|
LOGGER.info("9");
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
System.out.println("Invalid host IP");
|
System.out.println("Invalid host IP");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
LOGGER.info("10");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Socket getSocket() {
|
public Socket getSocket() {
|
||||||
|
|||||||
@ -1,8 +1,13 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui;
|
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui;
|
||||||
|
|
||||||
|
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.Client;
|
import ch.unibas.dmi.dbis.cs108.multiplayer.client.Client;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
public class ClientModel {
|
public class ClientModel {
|
||||||
|
public static final Logger LOGGER = LogManager.getLogger(ClientModel.class);
|
||||||
|
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||||
|
|
||||||
private String username;
|
private String username;
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|||||||
@ -1,14 +1,25 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui;
|
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui;
|
||||||
|
|
||||||
|
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatApp;
|
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatApp;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
public class GUI implements Runnable{
|
public class GUI implements Runnable{
|
||||||
|
public static final Logger LOGGER = LogManager.getLogger(GUI.class);
|
||||||
|
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||||
|
|
||||||
ChatApp chatApp;
|
ChatApp chatApp;
|
||||||
|
private String name;
|
||||||
public GUI (ChatApp chatApp) {
|
public GUI (ChatApp chatApp) {
|
||||||
this.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
|
* When an object implementing interface {@code Runnable} is used to create a thread, starting the
|
||||||
* thread causes the object's {@code run} method to be called in that separately executing
|
* thread causes the object's {@code run} method to be called in that separately executing
|
||||||
@ -18,8 +29,12 @@ public class GUI implements Runnable{
|
|||||||
*
|
*
|
||||||
* @see Thread#run()
|
* @see Thread#run()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
LOGGER.info("here");
|
||||||
|
//String name =
|
||||||
Application.launch(this.chatApp.getClass());
|
Application.launch(this.chatApp.getClass());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat;
|
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 ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -8,19 +10,40 @@ import javafx.fxml.FXMLLoader;
|
|||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
public class ChatApp extends Application {
|
public class ChatApp extends Application {
|
||||||
ClientModel clientModel;
|
public static final Logger LOGGER = LogManager.getLogger(ChatApp.class);
|
||||||
|
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||||
|
|
||||||
|
private static ClientModel clientModel;
|
||||||
private ChatController chatController;
|
private ChatController chatController;
|
||||||
|
|
||||||
public ChatApp() {
|
public ChatApp() {
|
||||||
super();
|
super();
|
||||||
|
LOGGER.info("Empty ChatApp constructor got called: ");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChatApp(ClientModel clientModel) {
|
public ChatApp(ClientModel clientModel) {
|
||||||
this.clientModel = clientModel;
|
this.clientModel = clientModel;
|
||||||
this.chatController = new ChatController(clientModel);
|
this.chatController = new ChatController(clientModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setChatController(
|
||||||
|
ChatController chatController) {
|
||||||
|
this.chatController = chatController;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setClientModel(ClientModel clientM) {
|
||||||
|
clientModel = clientM;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ClientModel getClientModel() {
|
||||||
|
return clientModel;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main entry point for all JavaFX applications. The start method is called after the init
|
* 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.
|
* method has returned, and after the system is ready for the application to begin running.
|
||||||
@ -36,8 +59,11 @@ public class ChatApp extends Application {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws Exception {
|
public void start(Stage primaryStage) throws Exception {
|
||||||
|
LOGGER.info("made it here");
|
||||||
|
this.setClientModel(clientModel);
|
||||||
URL resource = ChatApp.class.getResource(
|
URL resource = ChatApp.class.getResource(
|
||||||
"splitPaneChatView.fxml");
|
"splitPaneChatView.fxml");
|
||||||
|
LOGGER.info("1");
|
||||||
if (resource == null) {
|
if (resource == null) {
|
||||||
System.out.println("File wasnt found");
|
System.out.println("File wasnt found");
|
||||||
}
|
}
|
||||||
@ -46,16 +72,23 @@ public class ChatApp extends Application {
|
|||||||
Parent root = FXMLLoader.load(
|
Parent root = FXMLLoader.load(
|
||||||
Objects.requireNonNull(ChatApp.class.getResource(
|
Objects.requireNonNull(ChatApp.class.getResource(
|
||||||
"splitPaneChatView.fxml")));
|
"splitPaneChatView.fxml")));
|
||||||
|
LOGGER.info("2");
|
||||||
// TODO bin chatController.getChatPaneRoot() border to root border for rezising
|
// TODO bin chatController.getChatPaneRoot() border to root border for rezising
|
||||||
Scene scene = new Scene(root);
|
Scene scene = new Scene(root);
|
||||||
|
LOGGER.info("3");
|
||||||
scene.setRoot(root);
|
scene.setRoot(root);
|
||||||
|
LOGGER.info("4");
|
||||||
primaryStage.setScene(scene);
|
primaryStage.setScene(scene);
|
||||||
|
LOGGER.info("5");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
primaryStage.setResizable(true);
|
primaryStage.setResizable(true);
|
||||||
|
LOGGER.info("6");
|
||||||
primaryStage.setTitle("Chat");
|
primaryStage.setTitle("Chat");
|
||||||
|
LOGGER.info("7");
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
|
LOGGER.info("8");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -68,7 +68,7 @@ public class ChatController implements Initializable {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
|
setClient(ChatApp.getClientModel());
|
||||||
vBoxChatMessages.getChildren().addListener(new ListChangeListener<Node>() {
|
vBoxChatMessages.getChildren().addListener(new ListChangeListener<Node>() {
|
||||||
@Override
|
@Override
|
||||||
public void onChanged(Change<? extends Node> c) {
|
public void onChanged(Change<? extends Node> c) {
|
||||||
|
|||||||
Reference in New Issue
Block a user