Version von Toni übernommen, stand nach der LC session
This commit is contained in:
commit
f05b0f0014
@ -34,7 +34,7 @@ public class CommandController implements ActionListener{
|
||||
}
|
||||
|
||||
public void registerCommands(){
|
||||
CommandSend commandSend = new CommandSend(view);
|
||||
CommandSend commandSend = new CommandSend(view.getGvZeichenflaeche());
|
||||
invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend));
|
||||
//invoker.addCommand(view.getTfNachricht(), commandSend);
|
||||
}
|
||||
|
@ -5,8 +5,6 @@
|
||||
|
||||
package ChatProgramm.controller;
|
||||
|
||||
import ChatProgramm.controller.commands.CommandConnect;
|
||||
import ChatProgramm.controller.commands.CommandInvoker;
|
||||
import ChatProgramm.controller.commands.CommandSend;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
@ -14,7 +12,6 @@ import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
import ChatProgramm.model.GrafikModel;
|
||||
import ChatProgramm.view.GrafikView;
|
||||
import java.awt.Component;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -24,12 +21,13 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
|
||||
{
|
||||
private GrafikView view;
|
||||
private GrafikModel model;
|
||||
private CommandControler commandController;
|
||||
private CommandSend commandSend;
|
||||
|
||||
public GrafikController(GrafikView view, GrafikModel model, CommandController controller_commands)
|
||||
{
|
||||
this.view = view;
|
||||
this.model = model;
|
||||
commandSend = new CommandSend(view);
|
||||
}
|
||||
|
||||
public void registerEvents()
|
||||
@ -57,8 +55,7 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
|
||||
public void mouseReleased(MouseEvent evt)
|
||||
{
|
||||
model.endShape();
|
||||
Component key = (Component)evt.getSource();
|
||||
invoker.executeCommand(key);
|
||||
commandSend.execute();
|
||||
// if (evt.getButton() == MouseEvent.BUTTON3)
|
||||
// {
|
||||
// view.doPrint();
|
||||
|
@ -43,6 +43,7 @@ public class CommandSend implements CommandInterface
|
||||
@Override
|
||||
public void execute()
|
||||
{
|
||||
lg.info("wir sind drin");
|
||||
//ToDo in dieser methode muss die Figur serialisiert werden und zum
|
||||
//übermitteln bereitgestellt werden
|
||||
|
||||
|
@ -12,7 +12,7 @@ import java.util.concurrent.Flow.Subscriber;
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
public class ReceiveAdapter implements Subscriber<Nachricht> {
|
||||
public class ReceiveAdapter implements Subscriber<Figur> {
|
||||
|
||||
private ChatView view;
|
||||
private Flow.Subscription subscription;
|
||||
@ -27,7 +27,6 @@ public class ReceiveAdapter implements Subscriber<Nachricht> {
|
||||
this.subscription.request(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(Nachricht item) {
|
||||
|
||||
//ToDo: hier muss der gFrame aufgerufen werden
|
||||
@ -43,4 +42,9 @@ public class ReceiveAdapter implements Subscriber<Nachricht> {
|
||||
@Override
|
||||
public void onComplete(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(Figur item)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,14 @@
|
||||
package ChatProgramm.model;
|
||||
|
||||
import ChatProgramm.view.ChatView;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
@ -34,13 +38,13 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
||||
private static Logger lg = Logger.getLogger("netz");
|
||||
|
||||
protected Socket socket;
|
||||
protected BufferedReader reader;
|
||||
protected PrintWriter writer;
|
||||
protected ObjectInputStream reader;
|
||||
protected ObjectOutputStream writer;
|
||||
|
||||
private Nachricht nachricht;
|
||||
private Figur figur;
|
||||
private String txtNachricht;
|
||||
private boolean laufend;
|
||||
private SubmissionPublisher<Nachricht> textPublisher;
|
||||
private SubmissionPublisher<Figur> figurPublisher;
|
||||
private ExecutorService eService;
|
||||
private String receivedString;
|
||||
private ChatView view;
|
||||
@ -51,15 +55,15 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
||||
socket = new Socket();
|
||||
eService = null;
|
||||
receiveAdapter = new ReceiveAdapter(view);
|
||||
textPublisher = new SubmissionPublisher<>();
|
||||
figurPublisher = new SubmissionPublisher<>();
|
||||
this.view = view;
|
||||
addWertSubscription(receiveAdapter);
|
||||
nachricht = new Nachricht("");
|
||||
figur = new Figur();
|
||||
}
|
||||
|
||||
public void addWertSubscription(Subscriber<Nachricht> subscriber)
|
||||
public void addWertSubscription(Subscriber<Figur> subscriber)
|
||||
{
|
||||
textPublisher.subscribe(subscriber);
|
||||
figurPublisher.subscribe(subscriber);
|
||||
}
|
||||
|
||||
public abstract void connect() throws IOException;
|
||||
@ -69,12 +73,17 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
||||
lg.info("Initialisiere reader und writer");
|
||||
InputStream is = socket.getInputStream();
|
||||
OutputStream os = socket.getOutputStream();
|
||||
|
||||
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");
|
||||
|
||||
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
|
||||
OutputStreamWriter osr = new OutputStreamWriter(os, "UTF-8");
|
||||
|
||||
reader = new BufferedReader(isr);
|
||||
writer = new PrintWriter(osr);
|
||||
reader = new ObjectInputStream(bis);
|
||||
writer = new ObjectOutputStream(bos);
|
||||
lg.info("Reader / Writer Initialisierung abgeschlossen");
|
||||
startempfangen();
|
||||
lg.info("Warte auf Nachricht");
|
||||
@ -86,27 +95,42 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
||||
}
|
||||
}
|
||||
|
||||
public void send(String txtNachricht){
|
||||
|
||||
writer.println(txtNachricht);
|
||||
/**
|
||||
*
|
||||
* @param figur
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public void send(Figur figur){
|
||||
try
|
||||
{
|
||||
writer.writeObject(figur);
|
||||
writer.flush();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
lg.info("Nachricht gesendet");
|
||||
nachricht.setNachricht("\nDu: " + txtNachricht);
|
||||
textPublisher.submit(nachricht);
|
||||
figurPublisher.submit(figur);
|
||||
}
|
||||
public Nachricht receive(){
|
||||
public Figur receive(){
|
||||
try {
|
||||
txtNachricht = reader.readLine();
|
||||
figur = (Figur) reader.readObject();
|
||||
if(!txtNachricht.isEmpty()){
|
||||
lg.info("Nachricht erhalten");
|
||||
nachricht.setNachricht("\nEr / Sie: " + txtNachricht);
|
||||
return nachricht;
|
||||
|
||||
return figur;
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return nachricht;
|
||||
catch (ClassNotFoundException ex)
|
||||
{
|
||||
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return figur;
|
||||
}
|
||||
|
||||
// public void disconnect (){
|
||||
@ -120,9 +144,9 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
||||
while (true) {
|
||||
lg.info("Warte auf Nachricht");
|
||||
if(laufend) {
|
||||
nachricht = receive();
|
||||
if(!nachricht.getNachricht().isEmpty()){
|
||||
textPublisher.submit(nachricht);
|
||||
figur = receive();
|
||||
if(!figur.getPunkte().isEmpty()){
|
||||
figurPublisher.submit(figur);
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
@ -11,7 +11,7 @@ import ChatProgramm.model.Nachricht;
|
||||
*/
|
||||
public interface TransmitterInterface
|
||||
{
|
||||
public void send(String txtNachricht);
|
||||
public Nachricht receive();
|
||||
public void send(Figur figur);
|
||||
public Figur receive();
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user