Browse Source

Version von Toni übernommen, stand nach der LC session

Jens
Jens Schuhmann 1 year ago
parent
commit
f05b0f0014

+ 1
- 1
src/ChatProgramm/controller/CommandController.java View File

} }
public void registerCommands(){ 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.getBtnConnect(), new CommandConnect(view, commandSend));
//invoker.addCommand(view.getTfNachricht(), commandSend); //invoker.addCommand(view.getTfNachricht(), commandSend);
} }

+ 3
- 6
src/ChatProgramm/controller/GrafikController.java View File



package ChatProgramm.controller; package ChatProgramm.controller;


import ChatProgramm.controller.commands.CommandConnect;
import ChatProgramm.controller.commands.CommandInvoker;
import ChatProgramm.controller.commands.CommandSend; import ChatProgramm.controller.commands.CommandSend;
import java.awt.Point; import java.awt.Point;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseMotionListener; import java.awt.event.MouseMotionListener;
import ChatProgramm.model.GrafikModel; import ChatProgramm.model.GrafikModel;
import ChatProgramm.view.GrafikView; import ChatProgramm.view.GrafikView;
import java.awt.Component;


/** /**
* *
{ {
private GrafikView view; private GrafikView view;
private GrafikModel model; private GrafikModel model;
private CommandControler commandController;
private CommandSend commandSend;
public GrafikController(GrafikView view, GrafikModel model, CommandController controller_commands) public GrafikController(GrafikView view, GrafikModel model, CommandController controller_commands)
{ {
this.view = view; this.view = view;
this.model = model; this.model = model;
commandSend = new CommandSend(view);
} }
public void registerEvents() public void registerEvents()
public void mouseReleased(MouseEvent evt) public void mouseReleased(MouseEvent evt)
{ {
model.endShape(); model.endShape();
Component key = (Component)evt.getSource();
invoker.executeCommand(key);
commandSend.execute();
// if (evt.getButton() == MouseEvent.BUTTON3) // if (evt.getButton() == MouseEvent.BUTTON3)
// { // {
// view.doPrint(); // view.doPrint();

+ 1
- 0
src/ChatProgramm/controller/commands/CommandSend.java View File

@Override @Override
public void execute() public void execute()
{ {
lg.info("wir sind drin");
//ToDo in dieser methode muss die Figur serialisiert werden und zum //ToDo in dieser methode muss die Figur serialisiert werden und zum
//übermitteln bereitgestellt werden //übermitteln bereitgestellt werden

+ 6
- 2
src/ChatProgramm/model/ReceiveAdapter.java View File

* *
* @author ahren * @author ahren
*/ */
public class ReceiveAdapter implements Subscriber<Nachricht> {
public class ReceiveAdapter implements Subscriber<Figur> {


private ChatView view; private ChatView view;
private Flow.Subscription subscription; private Flow.Subscription subscription;
this.subscription.request(1); this.subscription.request(1);
} }


@Override
public void onNext(Nachricht item) { public void onNext(Nachricht item) {
//ToDo: hier muss der gFrame aufgerufen werden //ToDo: hier muss der gFrame aufgerufen werden
@Override @Override
public void onComplete(){ public void onComplete(){
} }

@Override
public void onNext(Figur item)
{
}
} }

+ 51
- 27
src/ChatProgramm/model/Transmitter.java View File

package ChatProgramm.model; package ChatProgramm.model;


import ChatProgramm.view.ChatView; import ChatProgramm.view.ChatView;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
private static Logger lg = Logger.getLogger("netz"); private static Logger lg = Logger.getLogger("netz");


protected Socket socket; 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 String txtNachricht;
private boolean laufend; private boolean laufend;
private SubmissionPublisher<Nachricht> textPublisher;
private SubmissionPublisher<Figur> figurPublisher;
private ExecutorService eService; private ExecutorService eService;
private String receivedString; private String receivedString;
private ChatView view; private ChatView view;
socket = new Socket(); socket = new Socket();
eService = null; eService = null;
receiveAdapter = new ReceiveAdapter(view); receiveAdapter = new ReceiveAdapter(view);
textPublisher = new SubmissionPublisher<>();
figurPublisher = new SubmissionPublisher<>();
this.view = view; this.view = view;
addWertSubscription(receiveAdapter); 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; public abstract void connect() throws IOException;
lg.info("Initialisiere reader und writer"); lg.info("Initialisiere reader und writer");
InputStream is = socket.getInputStream(); InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream(); OutputStream os = socket.getOutputStream();

InputStreamReader isr = new InputStreamReader(is, "UTF-8");
OutputStreamWriter osr = new OutputStreamWriter(os, "UTF-8");

reader = new BufferedReader(isr);
writer = new PrintWriter(osr);
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"); lg.info("Reader / Writer Initialisierung abgeschlossen");
startempfangen(); startempfangen();
lg.info("Warte auf Nachricht"); lg.info("Warte auf Nachricht");
} }
} }
public void send(String txtNachricht){

writer.println(txtNachricht);
/**
*
* @param figur
* @throws IOException
*/
@Override
public void send(Figur figur){
try
{
writer.writeObject(figur);
writer.flush(); writer.flush();
}
catch (IOException ex)
{
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
}
lg.info("Nachricht gesendet"); lg.info("Nachricht gesendet");
nachricht.setNachricht("\nDu: " + txtNachricht);
textPublisher.submit(nachricht);
figurPublisher.submit(figur);
} }
public Nachricht receive(){
public Figur receive(){
try { try {
txtNachricht = reader.readLine();
figur = (Figur) reader.readObject();
if(!txtNachricht.isEmpty()){ if(!txtNachricht.isEmpty()){
lg.info("Nachricht erhalten"); lg.info("Nachricht erhalten");
nachricht.setNachricht("\nEr / Sie: " + txtNachricht);
return nachricht;
return figur;
} }


} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(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 (){ // public void disconnect (){
while (true) { while (true) {
lg.info("Warte auf Nachricht"); lg.info("Warte auf Nachricht");
if(laufend) { if(laufend) {
nachricht = receive();
if(!nachricht.getNachricht().isEmpty()){
textPublisher.submit(nachricht);
figur = receive();
if(!figur.getPunkte().isEmpty()){
figurPublisher.submit(figur);
} }
} }
else{ else{

+ 2
- 2
src/ChatProgramm/model/TransmitterInterface.java View File

*/ */
public interface TransmitterInterface public interface TransmitterInterface
{ {
public void send(String txtNachricht);
public Nachricht receive();
public void send(Figur figur);
public Figur receive();


} }

Loading…
Cancel
Save