Compare commits
7
Commits
Toni
...
dc1f783e00
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc1f783e00 | ||
|
|
2fc05ae87f | ||
|
|
5117ecdb6f | ||
|
|
a4a45ed5f2 | ||
|
|
6642dc8179 | ||
|
|
f05b0f0014 | ||
|
|
1aa5b51e78 |
No files matched your search
@@ -25,11 +25,17 @@ public class Start
|
||||
ChatView view = new ChatView();
|
||||
GrafikView zeichenflaeche = view.getGvZeichenflaeche();
|
||||
zeichenflaeche.setModel(model);
|
||||
|
||||
GrafikController controller = new GrafikController(zeichenflaeche, model);
|
||||
controller.registerEvents();
|
||||
CommandController controller_commands = new CommandController(view);
|
||||
|
||||
CommandController controller_commands = new CommandController(view, model, controller, zeichenflaeche);
|
||||
controller_commands.registerEvents();
|
||||
controller_commands.registerCommands();
|
||||
|
||||
|
||||
|
||||
|
||||
view.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -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,9 +55,7 @@ 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;
|
||||
@@ -26,8 +28,10 @@ public class CommandConnect implements CommandInterface
|
||||
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();
|
||||
@@ -36,6 +40,8 @@ public class CommandConnect implements CommandInterface
|
||||
commandSend = (CommandSend) value;
|
||||
|
||||
this.view = view;
|
||||
this.model = model;
|
||||
this.gView = gView;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,7 +50,8 @@ public class CommandConnect implements CommandInterface
|
||||
if(rBtnServer.isSelected()){
|
||||
lg.info("Server ausgewählt");
|
||||
try {
|
||||
commandSend.transmitterInterface = new Server(view);
|
||||
commandSend.setTransmitter(new Server(view, model, gView));
|
||||
//commandSend.transmitterInterface = new Server(view);
|
||||
} catch (IOException ex) {
|
||||
lg.info("Die Verbindung zum Server ist Fehlgeschlagen");
|
||||
}
|
||||
@@ -53,7 +60,8 @@ public class CommandConnect implements CommandInterface
|
||||
if(rBtnClient.isSelected()){
|
||||
lg.info("Client ausgewählt");
|
||||
try {
|
||||
commandSend.transmitterInterface = new Client(view);
|
||||
commandSend.setTransmitter(new Client(view, model, gView));
|
||||
//commandSend.transmitterInterface = new Client(view);
|
||||
} catch (IOException ex) {
|
||||
lg.info("Die Verbindung zum Client ist Fehlgeschlagen");
|
||||
|
||||
|
||||
@@ -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,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 +75,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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
package ChatProgramm.model;
|
||||
|
||||
import ChatProgramm.view.ChatView;
|
||||
import ChatProgramm.view.GrafikView;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.util.logging.*;
|
||||
@@ -21,8 +22,8 @@ public class Client extends Transmitter {
|
||||
private static final String IP = "127.0.0.1";
|
||||
|
||||
|
||||
public Client(ChatView view) throws IOException {
|
||||
super(view);
|
||||
public Client(ChatView view, GrafikModel model, GrafikView gView) throws IOException {
|
||||
super(view, model, gView);
|
||||
connect();
|
||||
initIO();
|
||||
}
|
||||
|
||||
@@ -96,6 +96,11 @@ public class GrafikModel
|
||||
figuren.add(aktuelleFigur);
|
||||
aktuelleFigur = new Figur();
|
||||
}
|
||||
|
||||
public void setFigur(Figur figur){
|
||||
aktuelleFigur = figur;
|
||||
figuren.add(figur);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bestimmt die Adresse des zuletzt besuchten Ordners
|
||||
|
||||
@@ -4,21 +4,32 @@
|
||||
*/
|
||||
package ChatProgramm.model;
|
||||
|
||||
import ChatProgramm.util.OhmLogger;
|
||||
import ChatProgramm.view.ChatView;
|
||||
import ChatProgramm.view.GrafikView;
|
||||
import java.util.concurrent.Flow;
|
||||
import java.util.concurrent.Flow.Subscriber;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
public class ReceiveAdapter implements Subscriber<Figur> {
|
||||
|
||||
private static Logger lg = OhmLogger.getLogger();
|
||||
|
||||
private ChatView view;
|
||||
private GrafikModel model;
|
||||
private GrafikView gView;
|
||||
private Flow.Subscription subscription;
|
||||
|
||||
public ReceiveAdapter(ChatView view) {
|
||||
public ReceiveAdapter(ChatView view, GrafikModel model, GrafikView gView) {
|
||||
this.view = view;
|
||||
this.model = model;
|
||||
this.gView = gView;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -27,9 +38,11 @@ public class ReceiveAdapter implements Subscriber<Figur> {
|
||||
this.subscription.request(1);
|
||||
}
|
||||
|
||||
public void onNext(Nachricht item) {
|
||||
public void onNext(Figur item) {
|
||||
|
||||
//ToDo: hier muss der gFrame aufgerufen werden
|
||||
lg.info("Figur wurde dem Grafikmodel hinzugefügt");
|
||||
model.setFigur(item);
|
||||
gView.drawPoint();
|
||||
// evtl muss die Figur aber zuerst serialisiert werden
|
||||
//view.getTxtChat().append(item.getNachricht());
|
||||
this.subscription.request(1);
|
||||
@@ -43,8 +56,4 @@ public class ReceiveAdapter implements Subscriber<Figur> {
|
||||
public void onComplete(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(Figur item)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
package ChatProgramm.model;
|
||||
|
||||
import ChatProgramm.view.ChatView;
|
||||
import ChatProgramm.view.GrafikView;
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.logging.*;
|
||||
@@ -35,8 +36,8 @@ public class Server extends Transmitter
|
||||
lg.warning("Timeout"+"("+timeout/1000+"s)");
|
||||
}
|
||||
}
|
||||
public Server(ChatView view) throws IOException {
|
||||
super(view);
|
||||
public Server(ChatView view, GrafikModel model, GrafikView gView) throws IOException {
|
||||
super(view, model, gView);
|
||||
connect();
|
||||
initIO();
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
package ChatProgramm.model;
|
||||
|
||||
import ChatProgramm.view.ChatView;
|
||||
import ChatProgramm.view.GrafikView;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
@@ -30,7 +31,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;
|
||||
@@ -48,13 +49,14 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
||||
private ExecutorService eService;
|
||||
private String receivedString;
|
||||
private ChatView view;
|
||||
private GrafikModel model;
|
||||
private ReceiveAdapter receiveAdapter;
|
||||
|
||||
public Transmitter(ChatView view)
|
||||
public Transmitter(ChatView view, GrafikModel model, GrafikView gView)
|
||||
{
|
||||
socket = new Socket();
|
||||
eService = null;
|
||||
receiveAdapter = new ReceiveAdapter(view);
|
||||
receiveAdapter = new ReceiveAdapter(view, model, gView);
|
||||
figurPublisher = new SubmissionPublisher<>();
|
||||
this.view = view;
|
||||
addWertSubscription(receiveAdapter);
|
||||
@@ -73,17 +75,15 @@ 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");
|
||||
|
||||
reader = new ObjectInputStream(bis);
|
||||
writer = new ObjectOutputStream(bos);
|
||||
|
||||
// Bruh im ernst mann muss zuerst den writer und dann den reader initialisieren
|
||||
// andersrum ist das blockiert weil die Streams von hinten nach vorne gelesen werden
|
||||
writer = new ObjectOutputStream(os);
|
||||
writer.flush();
|
||||
|
||||
reader = new ObjectInputStream(is);
|
||||
|
||||
lg.info("Reader / Writer Initialisierung abgeschlossen");
|
||||
startempfangen();
|
||||
lg.info("Warte auf Nachricht");
|
||||
@@ -115,21 +115,23 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
||||
figurPublisher.submit(figur);
|
||||
}
|
||||
public Figur receive(){
|
||||
try {
|
||||
figur = (Figur) reader.readObject();
|
||||
if(!txtNachricht.isEmpty()){
|
||||
lg.info("Nachricht erhalten");
|
||||
|
||||
return figur;
|
||||
|
||||
Object receivedObject;
|
||||
try {
|
||||
receivedObject = reader.readObject();
|
||||
|
||||
if (receivedObject instanceof Figur) {
|
||||
lg.info("Figur erhalten");
|
||||
figur = (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);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
catch (ClassNotFoundException ex)
|
||||
{
|
||||
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
return figur;
|
||||
}
|
||||
|
||||
@@ -162,7 +164,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
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ public class GrafikView extends JComponent implements Printable
|
||||
* Zeichnet den aktuellen Pfad (solange die maus gedrückt gehalten wird)
|
||||
* @param p -> Der aktuelle punkt als x-y-Koordinate
|
||||
*/
|
||||
public void drawPoint(Point p)
|
||||
public void drawPoint()
|
||||
{
|
||||
Graphics2D g2 = (Graphics2D)this.getGraphics(); // gefährlich!
|
||||
|
||||
|
||||
Reference in new issue
Block a user