2 Commits
9 changed files with 64 additions and 119 deletions

No files matched your search

+6 -3
View File
@@ -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);
CommandController controller_commands = new CommandController(view, model, controller, zeichenflaeche);
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,9 +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 ChatProgramm.view.GrafikView;
import java.awt.Component; import java.awt.Component;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
@@ -22,17 +20,11 @@ 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 GrafikView gView;
private CommandInvoker invoker; private CommandInvoker invoker;
private GrafikController controller;
public CommandController(ChatView view, GrafikModel model, GrafikController controller, GrafikView gView){ public CommandController(ChatView view){
this.view = view; this.view = view;
this.model = model;
this.gView = gView;
this.invoker = new CommandInvoker(); this.invoker = new CommandInvoker();
this.controller = controller;
} }
public void registerEvents(){ public void registerEvents(){
@@ -42,9 +34,9 @@ public CommandController(ChatView view, GrafikModel model, GrafikController cont
} }
public void registerCommands(){ public void registerCommands(){
CommandSend commandSend = new CommandSend(view.getGvZeichenflaeche(), model); CommandSend commandSend = new CommandSend(view.getGvZeichenflaeche());
invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend, model, gView)); invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend));
this.controller.setCommand(commandSend); //invoker.addCommand(view.getTfNachricht(), commandSend);
} }
/** /**
@@ -55,11 +47,11 @@ public CommandController(ChatView view, GrafikModel model, GrafikController cont
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Component key = (Component)e.getSource(); Component key = (Component)e.getSource();
invoker.executeCommand(key); invoker.executeCommand(key);
// if(key == view.getBtnOpen()|| key==view.getMiOpen())
// invoker.deleteStack();
// }
} }
} }
@@ -23,15 +23,11 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
private GrafikModel model; private GrafikModel model;
private CommandSend commandSend; 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 = null; commandSend = new CommandSend(view);
}
void setCommand(CommandSend command){
this.commandSend = command;
} }
public void registerEvents() public void registerEvents()
@@ -47,7 +43,7 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
{ {
Point p = evt.getPoint(); Point p = evt.getPoint();
model.addPoint(p); model.addPoint(p);
view.drawPoint(); view.drawPoint(p);
} }
@Override @Override
@@ -59,9 +55,10 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
public void mouseReleased(MouseEvent evt) public void mouseReleased(MouseEvent evt)
{ {
model.endShape(); model.endShape();
if(commandSend != null){ commandSend.execute();
commandSend.execute(); // if (evt.getButton() == MouseEvent.BUTTON3)
} // {
// view.doPrint();
// }
} }
} }
@@ -6,11 +6,9 @@
package ChatProgramm.controller.commands; package ChatProgramm.controller.commands;
import ChatProgramm.model.Client; import ChatProgramm.model.Client;
import ChatProgramm.model.GrafikModel;
import ChatProgramm.model.Server; import ChatProgramm.model.Server;
import ChatProgramm.util.OhmLogger; import ChatProgramm.util.OhmLogger;
import ChatProgramm.view.ChatView; import ChatProgramm.view.ChatView;
import ChatProgramm.view.GrafikView;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.swing.JDialog; import javax.swing.JDialog;
@@ -22,29 +20,24 @@ import javax.swing.JRadioButton;
*/ */
public class CommandConnect implements CommandInterface public class CommandConnect implements CommandInterface
{ {
private JRadioButton rBtnServer; private JRadioButton rBtnServer;
private JRadioButton rBtnClient; private JRadioButton rBtnClient;
private JDialog dialogFenster; private JDialog dialogFenster;
private static Logger lg = OhmLogger.getLogger(); private static Logger lg = OhmLogger.getLogger();
private CommandSend commandSend; private CommandSend commandSend;
private ChatView view; private ChatView view;
private GrafikModel model;
private GrafikView gView;
public CommandConnect(ChatView view, CommandInterface value, GrafikModel model, GrafikView gView) public CommandConnect(ChatView view, CommandInterface value)
{ {
rBtnServer = view.getBtnServer(); rBtnServer = view.getBtnServer();
rBtnClient = view.getBtnClient(); rBtnClient = view.getBtnClient();
dialogFenster = view.getjDialog1(); dialogFenster = view.getjDialog1();
commandSend = (CommandSend) value; commandSend = (CommandSend) value;
this.view = view; this.view = view;
this.model = model;
this.gView = gView;
} }
@Override @Override
public void execute() public void execute()
{ {
@@ -6,14 +6,13 @@
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;
import ChatProgramm.view.ChatView; import ChatProgramm.view.ChatView;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.swing.JTextField; import javax.swing.JTextField;
import ChatProgramm.model.Nachricht;
import ChatProgramm.view.GrafikView; import ChatProgramm.view.GrafikView;
/** /**
@@ -26,15 +25,16 @@ 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;
public CommandSend(GrafikView view, GrafikModel model)
public CommandSend(GrafikView view)
{ {
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;
@@ -44,13 +44,6 @@ public class CommandSend implements CommandInterface
public void execute() public void execute()
{ {
lg.info("wir sind drin"); 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
@@ -71,15 +64,4 @@ 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");
}
}
}
-5
View File
@@ -96,11 +96,6 @@ public class GrafikModel
figuren.add(aktuelleFigur); figuren.add(aktuelleFigur);
aktuelleFigur = new Figur(); aktuelleFigur = new Figur();
} }
public void setFigur(Figur figur){
aktuelleFigur = figur;
figuren.add(figur);
}
/** /**
* Bestimmt die Adresse des zuletzt besuchten Ordners * Bestimmt die Adresse des zuletzt besuchten Ordners
+8 -18
View File
@@ -4,33 +4,21 @@
*/ */
package ChatProgramm.model; package ChatProgramm.model;
import ChatProgramm.util.OhmLogger;
import ChatProgramm.view.ChatView; import ChatProgramm.view.ChatView;
import ChatProgramm.view.GrafikView;
import java.util.concurrent.Flow; import java.util.concurrent.Flow;
import java.util.concurrent.Flow.Subscriber; import java.util.concurrent.Flow.Subscriber;
import java.util.logging.Logger;
/** /**
* *
* @author ahren * @author ahren
*/ */
public class ReceiveAdapter implements Subscriber<Figur> { public class ReceiveAdapter implements Subscriber<Figur> {
private static Logger lg = OhmLogger.getLogger();
private ChatView view; private ChatView view;
private GrafikModel model;
private GrafikView gView;
private Flow.Subscription subscription; private Flow.Subscription subscription;
public ReceiveAdapter(ChatView view, GrafikModel model, GrafikView gView) { public ReceiveAdapter(ChatView view) {
this.view = view; this.view = view;
this.model = model;
this.gView = gView;
} }
@Override @Override
@@ -39,11 +27,9 @@ public class ReceiveAdapter implements Subscriber<Figur> {
this.subscription.request(1); this.subscription.request(1);
} }
public void onNext(Figur item) { public void onNext(Nachricht item) {
lg.info("Figur wurde dem Grafikmodel hinzugefügt"); //ToDo: hier muss der gFrame aufgerufen werden
model.setFigur(item);
gView.drawFigur();
// evtl muss die Figur aber zuerst serialisiert werden // evtl muss die Figur aber zuerst serialisiert werden
//view.getTxtChat().append(item.getNachricht()); //view.getTxtChat().append(item.getNachricht());
this.subscription.request(1); this.subscription.request(1);
@@ -57,4 +43,8 @@ public class ReceiveAdapter implements Subscriber<Figur> {
public void onComplete(){ public void onComplete(){
} }
} @Override
public void onNext(Figur item)
{
}
}
+15 -13
View File
@@ -5,7 +5,6 @@
package ChatProgramm.model; package ChatProgramm.model;
import ChatProgramm.view.ChatView; import ChatProgramm.view.ChatView;
import ChatProgramm.view.GrafikView;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
@@ -49,16 +48,13 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
private ExecutorService eService; private ExecutorService eService;
private String receivedString; private String receivedString;
private ChatView view; private ChatView view;
private GrafikView gView;
private GrafikModel model;
private ReceiveAdapter receiveAdapter; private ReceiveAdapter receiveAdapter;
public Transmitter(ChatView view) public Transmitter(ChatView view)
{ {
socket = new Socket(); socket = new Socket();
eService = null; eService = null;
receiveAdapter = new ReceiveAdapter(view, model, gView); receiveAdapter = new ReceiveAdapter(view);
figurPublisher = new SubmissionPublisher<>(); figurPublisher = new SubmissionPublisher<>();
this.view = view; this.view = view;
addWertSubscription(receiveAdapter); addWertSubscription(receiveAdapter);
@@ -78,10 +74,16 @@ 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();
writer = new ObjectOutputStream(os); lg.info("1");
writer.flush(); BufferedOutputStream bos = new BufferedOutputStream(os);
reader = new ObjectInputStream(is);
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");
@@ -113,12 +115,12 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
figurPublisher.submit(figur); figurPublisher.submit(figur);
} }
public Figur receive(){ public Figur receive(){
Object receivedObject;
try { try {
receivedObject = reader.readObject(); figur = (Figur) reader.readObject();
if(receivedObject instanceof Figur){ if(!txtNachricht.isEmpty()){
lg.info("Figur erhalten"); lg.info("Nachricht erhalten");
figur = (Figur) receivedObject;
return figur;
} }
} catch (IOException e) { } catch (IOException e) {
+2 -11
View File
@@ -58,23 +58,14 @@ public class GrafikView extends JComponent implements Printable
* Zeichnet den aktuellen Pfad (solange die maus gedrückt gehalten wird) * Zeichnet den aktuellen Pfad (solange die maus gedrückt gehalten wird)
* @param p -> Der aktuelle punkt als x-y-Koordinate * @param p -> Der aktuelle punkt als x-y-Koordinate
*/ */
public void drawFigur() public void drawPoint(Point p)
{
Graphics2D g2 = (Graphics2D)this.getGraphics(); // gefährlich!
drawPath(model.getFiguren().getLast().getPunkte(),g2);
g2.dispose(); //SEEEEHHHHRRRR WICHTIG!!!!!!!
}
public void drawPoint()
{ {
Graphics2D g2 = (Graphics2D)this.getGraphics(); // gefährlich! Graphics2D g2 = (Graphics2D)this.getGraphics(); // gefährlich!
drawPath(model.getPunkte(),g2); drawPath(model.getPunkte(),g2);
g2.dispose(); //SEEEEHHHHRRRR WICHTIG!!!!!!! g2.dispose(); //SEEEEHHHHRRRR WICHTIG!!!!!!!
} }
/** /**