Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
75cdcf7202 | ||
|
|
ba0f12561b | ||
|
|
e7034fc7a4 |
@@ -27,7 +27,7 @@ public class Start
|
||||
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);
|
||||
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,11 +55,11 @@ 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();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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,17 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
|
||||
{
|
||||
private GrafikView view;
|
||||
private GrafikModel model;
|
||||
private CommandInvoker invoker;
|
||||
private CommandSend commandSend;
|
||||
|
||||
public GrafikController(GrafikView view, GrafikModel model)
|
||||
{
|
||||
this.view = view;
|
||||
this.model = model;
|
||||
commandSend = null;
|
||||
}
|
||||
|
||||
void setCommand(CommandSend command){
|
||||
this.commandSend = command;
|
||||
}
|
||||
|
||||
public void registerEvents()
|
||||
@@ -37,10 +39,7 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
|
||||
view.addMouseMotionListener(this);
|
||||
view.addMouseListener(this);
|
||||
}
|
||||
public void registerCommands(){
|
||||
CommandSend commandSend = new CommandSend(view);
|
||||
invoker.addCommand(view.getTfNachricht(), commandSend);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@@ -48,7 +47,7 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
|
||||
{
|
||||
Point p = evt.getPoint();
|
||||
model.addPoint(p);
|
||||
view.drawPoint(p);
|
||||
view.drawPoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,11 +59,9 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
|
||||
public void mouseReleased(MouseEvent evt)
|
||||
{
|
||||
model.endShape();
|
||||
Component key = (Component)evt.getSource();
|
||||
invoker.executeCommand(key);
|
||||
// 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;
|
||||
@@ -20,24 +22,29 @@ import javax.swing.JRadioButton;
|
||||
*/
|
||||
public class CommandConnect implements CommandInterface
|
||||
{
|
||||
private JRadioButton rBtnServer;
|
||||
private JRadioButton rBtnClient;
|
||||
private JDialog dialogFenster;
|
||||
private static Logger lg = OhmLogger.getLogger();
|
||||
private CommandSend commandSend;
|
||||
private ChatView view;
|
||||
private JRadioButton rBtnServer;
|
||||
private JRadioButton rBtnClient;
|
||||
private JDialog dialogFenster;
|
||||
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();
|
||||
dialogFenster = view.getjDialog1();
|
||||
rBtnServer = view.getBtnServer();
|
||||
rBtnClient = view.getBtnClient();
|
||||
dialogFenster = view.getjDialog1();
|
||||
|
||||
commandSend = (CommandSend) value;
|
||||
commandSend = (CommandSend) value;
|
||||
|
||||
this.view = view;
|
||||
this.view = view;
|
||||
this.model = model;
|
||||
this.gView = gView;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void execute()
|
||||
{
|
||||
|
||||
@@ -6,13 +6,14 @@
|
||||
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;
|
||||
import ChatProgramm.view.ChatView;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JTextField;
|
||||
import ChatProgramm.model.Nachricht;
|
||||
import ChatProgramm.view.GrafikView;
|
||||
|
||||
/**
|
||||
@@ -25,16 +26,15 @@ 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;
|
||||
|
||||
|
||||
|
||||
|
||||
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;
|
||||
@@ -43,6 +43,14 @@ public class CommandSend implements CommandInterface
|
||||
@Override
|
||||
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
|
||||
|
||||
@@ -63,4 +71,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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,33 @@
|
||||
*/
|
||||
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<Nachricht> {
|
||||
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,10 +39,11 @@ public class ReceiveAdapter implements Subscriber<Nachricht> {
|
||||
this.subscription.request(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
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.drawFigur();
|
||||
// evtl muss die Figur aber zuerst serialisiert werden
|
||||
//view.getTxtChat().append(item.getNachricht());
|
||||
this.subscription.request(1);
|
||||
@@ -43,4 +56,5 @@ public class ReceiveAdapter implements Subscriber<Nachricht> {
|
||||
@Override
|
||||
public void onComplete(){
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,10 +5,15 @@
|
||||
package ChatProgramm.model;
|
||||
|
||||
import ChatProgramm.view.ChatView;
|
||||
import ChatProgramm.view.GrafikView;
|
||||
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,32 +39,35 @@ 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;
|
||||
private GrafikView gView;
|
||||
private GrafikModel model;
|
||||
|
||||
private ReceiveAdapter receiveAdapter;
|
||||
|
||||
public Transmitter(ChatView view)
|
||||
{
|
||||
socket = new Socket();
|
||||
eService = null;
|
||||
receiveAdapter = new ReceiveAdapter(view);
|
||||
textPublisher = new SubmissionPublisher<>();
|
||||
receiveAdapter = new ReceiveAdapter(view, model, gView);
|
||||
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;
|
||||
@@ -70,11 +78,10 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
||||
InputStream is = socket.getInputStream();
|
||||
OutputStream os = socket.getOutputStream();
|
||||
|
||||
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
|
||||
OutputStreamWriter osr = new OutputStreamWriter(os, "UTF-8");
|
||||
writer = new ObjectOutputStream(os);
|
||||
writer.flush();
|
||||
reader = new ObjectInputStream(is);
|
||||
|
||||
reader = new BufferedReader(isr);
|
||||
writer = new PrintWriter(osr);
|
||||
lg.info("Reader / Writer Initialisierung abgeschlossen");
|
||||
startempfangen();
|
||||
lg.info("Warte auf Nachricht");
|
||||
@@ -86,27 +93,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(){
|
||||
Object receivedObject;
|
||||
try {
|
||||
txtNachricht = reader.readLine();
|
||||
if(!txtNachricht.isEmpty()){
|
||||
lg.info("Nachricht erhalten");
|
||||
nachricht.setNachricht("\nEr / Sie: " + txtNachricht);
|
||||
return nachricht;
|
||||
receivedObject = reader.readObject();
|
||||
if(receivedObject instanceof Figur){
|
||||
lg.info("Figur erhalten");
|
||||
figur = (Figur) receivedObject;
|
||||
}
|
||||
|
||||
} 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 +142,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();
|
||||
|
||||
}
|
||||
|
||||
@@ -58,7 +58,15 @@ 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 drawFigur()
|
||||
{
|
||||
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!
|
||||
|
||||
@@ -68,6 +76,7 @@ public class GrafikView extends JComponent implements Printable
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Hier werden alle Pfade aus dem model neu gezeichnet
|
||||
* Jedes mal wenn die Maus los gelassen wird, wird dder aktuelle Pfad gespeichert
|
||||
|
||||
Reference in New Issue
Block a user