scheinbar kacke kopiert

This commit is contained in:
ahren
2023-12-19 12:11:40 +01:00
parent ba0f12561b
commit 75cdcf7202
9 changed files with 116 additions and 58 deletions
@@ -8,7 +8,9 @@ package ChatProgramm.controller;
import ChatProgramm.controller.commands.CommandConnect;
import ChatProgramm.controller.commands.CommandInvoker;
import ChatProgramm.controller.commands.CommandSend;
import ChatProgramm.model.GrafikModel;
import ChatProgramm.view.ChatView;
import ChatProgramm.view.GrafikView;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@@ -20,11 +22,17 @@ import java.awt.event.ActionListener;
public class CommandController implements ActionListener{
private ChatView view;
private GrafikModel model;
private GrafikView gView;
private CommandInvoker invoker;
private GrafikController controller;
public CommandController(ChatView view){
public CommandController(ChatView view, GrafikModel model, GrafikController controller, GrafikView gView){
this.view = view;
this.model = model;
this.gView = gView;
this.invoker = new CommandInvoker();
this.controller = controller;
}
public void registerEvents(){
@@ -34,9 +42,9 @@ public class CommandController implements ActionListener{
}
public void registerCommands(){
CommandSend commandSend = new CommandSend(view.getGvZeichenflaeche());
invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend));
//invoker.addCommand(view.getTfNachricht(), commandSend);
CommandSend commandSend = new CommandSend(view.getGvZeichenflaeche(), model);
invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend, model, gView));
this.controller.setCommand(commandSend);
}
/**
@@ -47,11 +55,11 @@ public class CommandController implements ActionListener{
public void actionPerformed(ActionEvent e) {
Component key = (Component)e.getSource();
invoker.executeCommand(key);
// if(key == view.getBtnOpen()|| key==view.getMiOpen())
// invoker.deleteStack();
// }
}
}
@@ -27,7 +27,11 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
{
this.view = view;
this.model = model;
commandSend = new CommandSend(view);
commandSend = null;
}
void setCommand(CommandSend command){
this.commandSend = command;
}
public void registerEvents()
@@ -43,7 +47,7 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
{
Point p = evt.getPoint();
model.addPoint(p);
view.drawPoint(p);
view.drawPoint();
}
@Override
@@ -55,10 +59,9 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
public void mouseReleased(MouseEvent evt)
{
model.endShape();
commandSend.execute();
// if (evt.getButton() == MouseEvent.BUTTON3)
// {
// view.doPrint();
// }
if(commandSend != null){
commandSend.execute();
}
}
}
@@ -6,9 +6,11 @@
package ChatProgramm.controller.commands;
import ChatProgramm.model.Client;
import ChatProgramm.model.GrafikModel;
import ChatProgramm.model.Server;
import ChatProgramm.util.OhmLogger;
import ChatProgramm.view.ChatView;
import ChatProgramm.view.GrafikView;
import java.io.IOException;
import java.util.logging.Logger;
import javax.swing.JDialog;
@@ -20,24 +22,29 @@ import javax.swing.JRadioButton;
*/
public class CommandConnect implements CommandInterface
{
private JRadioButton rBtnServer;
private JRadioButton rBtnClient;
private JDialog dialogFenster;
private static Logger lg = OhmLogger.getLogger();
private CommandSend commandSend;
private ChatView view;
private JRadioButton rBtnServer;
private JRadioButton rBtnClient;
private JDialog dialogFenster;
private static Logger lg = OhmLogger.getLogger();
private CommandSend commandSend;
private ChatView view;
private GrafikModel model;
private GrafikView gView;
public CommandConnect(ChatView view, CommandInterface value)
public CommandConnect(ChatView view, CommandInterface value, GrafikModel model, GrafikView gView)
{
rBtnServer = view.getBtnServer();
rBtnClient = view.getBtnClient();
dialogFenster = view.getjDialog1();
rBtnServer = view.getBtnServer();
rBtnClient = view.getBtnClient();
dialogFenster = view.getjDialog1();
commandSend = (CommandSend) value;
commandSend = (CommandSend) value;
this.view = view;
this.view = view;
this.model = model;
this.gView = gView;
}
@Override
public void execute()
{
@@ -6,13 +6,14 @@
package ChatProgramm.controller.commands;
import ChatProgramm.model.Client;
import ChatProgramm.model.Figur;
import ChatProgramm.model.GrafikModel;
import ChatProgramm.model.Server;
import ChatProgramm.model.TransmitterInterface;
import ChatProgramm.util.OhmLogger;
import ChatProgramm.view.ChatView;
import java.util.logging.Logger;
import javax.swing.JTextField;
import ChatProgramm.model.Nachricht;
import ChatProgramm.view.GrafikView;
/**
@@ -25,16 +26,15 @@ public class CommandSend implements CommandInterface
private JTextField eingabeFeld;
private String nachricht;
private GrafikView view;
private GrafikModel model;
public TransmitterInterface transmitterInterface;
public Server server;
public Client client;
public CommandSend(GrafikView view)
public CommandSend(GrafikView view, GrafikModel model)
{
this.view = view;
this.model = model;
//ToDo: Hier muss auch der gFrame referenziert werden
//this.eingabeFeld = view.getTfNachricht();
transmitterInterface = null;
@@ -44,6 +44,13 @@ public class CommandSend implements CommandInterface
public void execute()
{
lg.info("wir sind drin");
Figur aktuelleFigur = model.getFiguren().getLast();
if(transmitterInterface != null){
transmitterInterface.send(aktuelleFigur);
}
else{
lg.info("Der Transmitter ist immernoch null");
}
//ToDo in dieser methode muss die Figur serialisiert werden und zum
//übermitteln bereitgestellt werden
@@ -64,4 +71,15 @@ public class CommandSend implements CommandInterface
public void undo()
{
}
}
void setTransmitter(TransmitterInterface transmitter) {
lg.info("Transmitter wird gesetzt");
if(transmitter != null){
this.transmitterInterface = transmitter;
}
else{
lg.info("der transmitter kommt hier als null an");
}
}
}