Compare commits
6
Commits
master
..
a4a45ed5f2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4a45ed5f2 | ||
|
|
6642dc8179 | ||
|
|
f05b0f0014 | ||
|
|
1aa5b51e78 | ||
|
|
ba0f12561b | ||
|
|
e7034fc7a4 |
No files matched your search
@@ -25,11 +25,14 @@ public class Start
|
|||||||
ChatView view = new ChatView();
|
ChatView view = new ChatView();
|
||||||
GrafikView zeichenflaeche = view.getGvZeichenflaeche();
|
GrafikView zeichenflaeche = view.getGvZeichenflaeche();
|
||||||
zeichenflaeche.setModel(model);
|
zeichenflaeche.setModel(model);
|
||||||
GrafikController controller = new GrafikController(zeichenflaeche, model);
|
|
||||||
controller.registerEvents();
|
CommandController controller_commands = new CommandController(view, model);
|
||||||
CommandController controller_commands = new CommandController(view);
|
|
||||||
controller_commands.registerEvents();
|
controller_commands.registerEvents();
|
||||||
controller_commands.registerCommands();
|
controller_commands.registerCommands();
|
||||||
|
|
||||||
|
GrafikController controller = new GrafikController(zeichenflaeche, model, controller_commands);
|
||||||
|
controller.registerEvents();
|
||||||
|
|
||||||
view.setVisible(true);
|
view.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ package ChatProgramm.controller;
|
|||||||
import ChatProgramm.controller.commands.CommandConnect;
|
import ChatProgramm.controller.commands.CommandConnect;
|
||||||
import ChatProgramm.controller.commands.CommandInvoker;
|
import ChatProgramm.controller.commands.CommandInvoker;
|
||||||
import ChatProgramm.controller.commands.CommandSend;
|
import ChatProgramm.controller.commands.CommandSend;
|
||||||
|
import ChatProgramm.model.GrafikModel;
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
@@ -20,10 +21,12 @@ import java.awt.event.ActionListener;
|
|||||||
public class CommandController implements ActionListener{
|
public class CommandController implements ActionListener{
|
||||||
|
|
||||||
private ChatView view;
|
private ChatView view;
|
||||||
|
private GrafikModel model;
|
||||||
private CommandInvoker invoker;
|
private CommandInvoker invoker;
|
||||||
|
|
||||||
public CommandController(ChatView view){
|
public CommandController(ChatView view, GrafikModel model){
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
this.model = model;
|
||||||
this.invoker = new CommandInvoker();
|
this.invoker = new CommandInvoker();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,7 +37,7 @@ public class CommandController implements ActionListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void registerCommands(){
|
public void registerCommands(){
|
||||||
CommandSend commandSend = new CommandSend(view);
|
CommandSend commandSend = new CommandSend(view.getGvZeichenflaeche(), model);
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
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;
|
||||||
@@ -14,7 +12,6 @@ import java.awt.event.MouseEvent;
|
|||||||
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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -24,12 +21,13 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
|
|||||||
{
|
{
|
||||||
private GrafikView view;
|
private GrafikView view;
|
||||||
private GrafikModel model;
|
private GrafikModel model;
|
||||||
private CommandInvoker invoker;
|
private CommandSend commandSend;
|
||||||
|
|
||||||
public GrafikController(GrafikView view, GrafikModel model)
|
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, model);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerEvents()
|
public void registerEvents()
|
||||||
@@ -37,10 +35,7 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
|
|||||||
view.addMouseMotionListener(this);
|
view.addMouseMotionListener(this);
|
||||||
view.addMouseListener(this);
|
view.addMouseListener(this);
|
||||||
}
|
}
|
||||||
public void registerCommands(){
|
|
||||||
CommandSend commandSend = new CommandSend(view);
|
|
||||||
invoker.addCommand(view.getTfNachricht(), commandSend);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -60,8 +55,7 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
|
|||||||
public void mouseReleased(MouseEvent evt)
|
public void mouseReleased(MouseEvent evt)
|
||||||
{
|
{
|
||||||
model.endShape();
|
model.endShape();
|
||||||
Component key = (Component)evt.getSource();
|
commandSend.execute();
|
||||||
invoker.executeCommand(key);
|
|
||||||
// if (evt.getButton() == MouseEvent.BUTTON3)
|
// if (evt.getButton() == MouseEvent.BUTTON3)
|
||||||
// {
|
// {
|
||||||
// view.doPrint();
|
// view.doPrint();
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
package ChatProgramm.controller.commands;
|
package ChatProgramm.controller.commands;
|
||||||
|
|
||||||
import ChatProgramm.model.Client;
|
import ChatProgramm.model.Client;
|
||||||
|
import ChatProgramm.model.Figur;
|
||||||
|
import ChatProgramm.model.GrafikModel;
|
||||||
import ChatProgramm.model.Server;
|
import ChatProgramm.model.Server;
|
||||||
import ChatProgramm.model.TransmitterInterface;
|
import ChatProgramm.model.TransmitterInterface;
|
||||||
import ChatProgramm.util.OhmLogger;
|
import ChatProgramm.util.OhmLogger;
|
||||||
@@ -25,6 +27,7 @@ public class CommandSend implements CommandInterface
|
|||||||
private JTextField eingabeFeld;
|
private JTextField eingabeFeld;
|
||||||
private String nachricht;
|
private String nachricht;
|
||||||
private GrafikView view;
|
private GrafikView view;
|
||||||
|
private GrafikModel model;
|
||||||
public TransmitterInterface transmitterInterface;
|
public TransmitterInterface transmitterInterface;
|
||||||
public Server server;
|
public Server server;
|
||||||
public Client client;
|
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.view = view;
|
||||||
|
this.model = model;
|
||||||
//ToDo: Hier muss auch der gFrame referenziert werden
|
//ToDo: Hier muss auch der gFrame referenziert werden
|
||||||
//this.eingabeFeld = view.getTfNachricht();
|
//this.eingabeFeld = view.getTfNachricht();
|
||||||
transmitterInterface = null;
|
transmitterInterface = null;
|
||||||
@@ -43,6 +47,14 @@ public class CommandSend implements CommandInterface
|
|||||||
@Override
|
@Override
|
||||||
public void execute()
|
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
|
//ToDo in dieser methode muss die Figur serialisiert werden und zum
|
||||||
//übermitteln bereitgestellt werden
|
//übermitteln bereitgestellt werden
|
||||||
|
|
||||||
@@ -63,4 +75,15 @@ public class CommandSend implements CommandInterface
|
|||||||
public void undo()
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,7 @@ import java.util.concurrent.Flow.Subscriber;
|
|||||||
*
|
*
|
||||||
* @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;
|
||||||
@@ -27,7 +27,6 @@ public class ReceiveAdapter implements Subscriber<Nachricht> {
|
|||||||
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
|
||||||
@@ -43,4 +42,9 @@ public class ReceiveAdapter implements Subscriber<Nachricht> {
|
|||||||
@Override
|
@Override
|
||||||
public void onComplete(){
|
public void onComplete(){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNext(Figur item)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,10 +5,14 @@
|
|||||||
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;
|
||||||
@@ -26,7 +30,7 @@ import java.util.logging.Logger;
|
|||||||
*
|
*
|
||||||
* @author ahren
|
* @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;
|
static final int timeout = 60000;
|
||||||
private static final int PORT = 35000;
|
private static final int PORT = 35000;
|
||||||
@@ -34,13 +38,13 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
|||||||
private static Logger lg = Logger.getLogger("netz");
|
private static Logger lg = Logger.getLogger("netz");
|
||||||
|
|
||||||
protected Socket socket;
|
protected Socket socket;
|
||||||
protected BufferedReader reader;
|
protected ObjectInputStream reader;
|
||||||
protected PrintWriter writer;
|
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;
|
||||||
@@ -51,15 +55,15 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
|||||||
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;
|
||||||
@@ -70,11 +74,13 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
|||||||
InputStream is = socket.getInputStream();
|
InputStream is = socket.getInputStream();
|
||||||
OutputStream os = socket.getOutputStream();
|
OutputStream os = socket.getOutputStream();
|
||||||
|
|
||||||
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
|
// Bruh im ernst mann muss zuerst den writer und dann den reader initialisieren
|
||||||
OutputStreamWriter osr = new OutputStreamWriter(os, "UTF-8");
|
// andersrum ist das blockierend weil die Streams von hinten nach vorne
|
||||||
|
// gelesen werden
|
||||||
reader = new BufferedReader(isr);
|
writer = new ObjectOutputStream(os);
|
||||||
writer = new PrintWriter(osr);
|
writer.flush();
|
||||||
|
reader = new ObjectInputStream(is);
|
||||||
|
|
||||||
lg.info("Reader / Writer Initialisierung abgeschlossen");
|
lg.info("Reader / Writer Initialisierung abgeschlossen");
|
||||||
startempfangen();
|
startempfangen();
|
||||||
lg.info("Warte auf Nachricht");
|
lg.info("Warte auf Nachricht");
|
||||||
@@ -86,27 +92,57 @@ 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();
|
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);
|
figurPublisher.submit(figur);
|
||||||
textPublisher.submit(nachricht);
|
|
||||||
}
|
}
|
||||||
public Nachricht receive(){
|
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 {
|
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 (){
|
||||||
@@ -120,9 +156,9 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
|||||||
while (true) {
|
while (true) {
|
||||||
lg.info("Warte auf Nachricht");
|
lg.info("Warte auf Nachricht");
|
||||||
if(laufend) {
|
if(laufend) {
|
||||||
nachricht = receive();
|
figur = receive();
|
||||||
if(!nachricht.getNachricht().isEmpty()){
|
if(!figur.getPunkte().isEmpty()){
|
||||||
textPublisher.submit(nachricht);
|
figurPublisher.submit(figur);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
@@ -138,7 +174,7 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import ChatProgramm.model.Nachricht;
|
|||||||
*/
|
*/
|
||||||
public interface TransmitterInterface
|
public interface TransmitterInterface
|
||||||
{
|
{
|
||||||
public void send(String txtNachricht);
|
public void send(Figur figur);
|
||||||
public Nachricht receive();
|
public Figur receive();
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user