Since view is singleton, removed overhanding view as parameter.

This commit is contained in:
WickedJack99
2023-12-23 14:12:16 +01:00
parent af22e077ba
commit 781c148df7
3 changed files with 18 additions and 13 deletions

View File

@@ -20,24 +20,21 @@ import data.src.ViewToController.EmptyViewToControllerData;
import data.src.ViewToController.ViewToControllerData;
import data.src.ViewToController.ViewToControllerData.ViewEvent;
import gui.src.View;
import logger.src.MessageLogger;
import model.src.ModelRepresentation;
import model.src.ConnectionModel.ConnectionStatus;
import queues.src.ControllerToViewQueue;
import queues.src.ViewToControllerQueue;
public class ControllerThread extends Thread implements Controller {
private static final String className = "ControllerThread";
private View view;
private ModelRepresentation model;
private Client client;
public ControllerThread(View view, ModelRepresentation model) {
this.view = view;
public ControllerThread(ModelRepresentation model) {
this.model = model;
}
@@ -68,6 +65,8 @@ public class ControllerThread extends Thread implements Controller {
}
private void handleConnectToServerButtonWasPressed(ViewToControllerData viewToControllerData) {
this.model.getConnectionModel().setConnectionStatus(ConnectionStatus.Pending);
String ipAddress = ((ConnectToServerData)viewToControllerData).getIPAddress();
int port = ((ConnectToServerData)viewToControllerData).getPort();
@@ -88,6 +87,7 @@ public class ControllerThread extends Thread implements Controller {
this.client = new TLSClient();
if (this.client.createConnection(connectToServerData) == true) {
this.model.getConnectionModel().setConnectionStatus(ConnectionStatus.Connected);
ControllerToViewData controllerToViewData = new ConnectToServerSuccessful();
ControllerToViewQueue.getInstance().add(controllerToViewData);
}

View File

@@ -5,7 +5,6 @@
package gui.src;
import data.src.ControllerToView.ControllerToViewData;
import data.src.ControllerToView.ControllerToViewData.ControllerEvent;
import gui.src.frames.MainFrame;
import logger.src.MessageLogger;
@@ -14,8 +13,19 @@ import queues.src.ControllerToViewQueue;
public class ViewThread extends Thread implements View {
private static final String className = "ViewThread";
private static ViewThread instance;
private boolean isRunning = true;
private ViewThread() {}
public static ViewThread getInstance() {
if (null == instance) {
instance = new ViewThread();
}
return instance;
}
public void run() {
MainFrame.getInstance();
MessageLogger.printMessage(className, "Swing ui thread was started.");

View File

@@ -7,29 +7,24 @@ package main.src;
import controller.src.Controller;
import controller.src.ControllerThread;
import gui.src.View;
import gui.src.ViewThread;
import logger.src.MessageLogger;
import model.src.ModelRepresentation;
import queues.src.ControllerToViewQueue;
import queues.src.ViewToControllerQueue;
public final class Main {
private static final String className = "Main";
public static void main(String[] args) {
ControllerToViewQueue.getInstance();
ViewToControllerQueue.getInstance();
View view = new ViewThread();
view.start();
ViewThread.getInstance().start();
ModelRepresentation model = new ModelRepresentation();
Controller controller = new ControllerThread(view, model);
Controller controller = new ControllerThread(model);
controller.start();
}
}