@@ -26,7 +26,7 @@ public class Start | |||
GrafikView zeichenflaeche = view.getGvZeichenflaeche(); | |||
zeichenflaeche.setModel(model); | |||
CommandController controller_commands = new CommandController(view); | |||
CommandController controller_commands = new CommandController(view, model); | |||
controller_commands.registerEvents(); | |||
controller_commands.registerCommands(); | |||
@@ -8,6 +8,7 @@ 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 java.awt.Component; | |||
import java.awt.event.ActionEvent; | |||
@@ -20,10 +21,12 @@ import java.awt.event.ActionListener; | |||
public class CommandController implements ActionListener{ | |||
private ChatView view; | |||
private GrafikModel model; | |||
private CommandInvoker invoker; | |||
public CommandController(ChatView view){ | |||
public CommandController(ChatView view, GrafikModel model){ | |||
this.view = view; | |||
this.model = model; | |||
this.invoker = new CommandInvoker(); | |||
} | |||
@@ -34,7 +37,7 @@ public class CommandController implements ActionListener{ | |||
} | |||
public void registerCommands(){ | |||
CommandSend commandSend = new CommandSend(view.getGvZeichenflaeche()); | |||
CommandSend commandSend = new CommandSend(view.getGvZeichenflaeche(), model); | |||
invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend)); | |||
//invoker.addCommand(view.getTfNachricht(), commandSend); | |||
} |
@@ -27,7 +27,7 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene | |||
{ | |||
this.view = view; | |||
this.model = model; | |||
commandSend = new CommandSend(view); | |||
commandSend = new CommandSend(view, model); | |||
} | |||
public void registerEvents() |
@@ -6,6 +6,8 @@ | |||
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; | |||
@@ -25,6 +27,7 @@ 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; | |||
@@ -32,9 +35,10 @@ public class CommandSend implements CommandInterface | |||
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 +48,8 @@ public class CommandSend implements CommandInterface | |||
public void execute() | |||
{ | |||
lg.info("wir sind drin"); | |||
Figur aktuelleFigur = model.getFiguren().getLast(); | |||
transmitterInterface.send(aktuelleFigur); | |||
//ToDo in dieser methode muss die Figur serialisiert werden und zum | |||
//übermitteln bereitgestellt werden | |||
@@ -30,7 +30,7 @@ import java.util.logging.Logger; | |||
* | |||
* @author ahren | |||
*/ | |||
public abstract class Transmitter implements Runnable, Subscriber<String>, TransmitterInterface { | |||
public abstract class Transmitter implements Runnable, Subscriber<Figur>, TransmitterInterface { | |||
static final int timeout = 60000; | |||
private static final int PORT = 35000; | |||
@@ -73,17 +73,14 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans | |||
lg.info("Initialisiere reader und writer"); | |||
InputStream is = socket.getInputStream(); | |||
OutputStream os = socket.getOutputStream(); | |||
// Bruh im ernst mann muss zuerst den writer und dann den reader initialisieren | |||
// andersrum ist das blockierend weil die Streams von hinten nach vorne | |||
// gelesen werden | |||
writer = new ObjectOutputStream(os); | |||
writer.flush(); | |||
reader = new ObjectInputStream(is); | |||
lg.info("1"); | |||
BufferedOutputStream bos = new BufferedOutputStream(os); | |||
BufferedInputStream bis = new BufferedInputStream(is); | |||
lg.info("2"); | |||
// InputStreamReader isr = new InputStreamReader(is, "UTF-8"); | |||
// OutputStreamWriter osr = new OutputStreamWriter(os, "UTF-8"); | |||
reader = new ObjectInputStream(bis); | |||
writer = new ObjectOutputStream(bos); | |||
lg.info("Reader / Writer Initialisierung abgeschlossen"); | |||
startempfangen(); | |||
lg.info("Warte auf Nachricht"); | |||
@@ -115,6 +112,21 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans | |||
figurPublisher.submit(figur); | |||
} | |||
public Figur receive(){ | |||
Object receivedObject; | |||
try { | |||
receivedObject = reader.readObject(); | |||
if (receivedObject instanceof Figur) { | |||
Figur receivedFigur = (Figur) receivedObject; | |||
// Verarbeiten Sie die empfangene Figur | |||
} | |||
} catch (IOException ex) { | |||
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex); | |||
} catch (ClassNotFoundException ex) { | |||
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex); | |||
} | |||
try { | |||
figur = (Figur) reader.readObject(); | |||
if(!txtNachricht.isEmpty()){ | |||
@@ -162,7 +174,7 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans | |||
} | |||
@Override | |||
public void onNext(String item) { | |||
public void onNext(Figur item) { | |||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody | |||
} | |||