Zwischenstand vor Praktikum
This commit is contained in:
parent
a4a45ed5f2
commit
5117ecdb6f
@ -26,12 +26,15 @@ public class Start
|
|||||||
GrafikView zeichenflaeche = view.getGvZeichenflaeche();
|
GrafikView zeichenflaeche = view.getGvZeichenflaeche();
|
||||||
zeichenflaeche.setModel(model);
|
zeichenflaeche.setModel(model);
|
||||||
|
|
||||||
CommandController controller_commands = new CommandController(view, model);
|
GrafikController controller = new GrafikController(zeichenflaeche, model);
|
||||||
|
controller.registerEvents();
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import ChatProgramm.controller.commands.CommandInvoker;
|
|||||||
import ChatProgramm.controller.commands.CommandSend;
|
import ChatProgramm.controller.commands.CommandSend;
|
||||||
import ChatProgramm.model.GrafikModel;
|
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,12 +23,16 @@ public class CommandController implements ActionListener{
|
|||||||
|
|
||||||
private ChatView view;
|
private ChatView view;
|
||||||
private GrafikModel model;
|
private GrafikModel model;
|
||||||
|
private GrafikView gView;
|
||||||
private CommandInvoker invoker;
|
private CommandInvoker invoker;
|
||||||
|
private GrafikController controller;
|
||||||
|
|
||||||
public CommandController(ChatView view, GrafikModel model){
|
public CommandController(ChatView view, GrafikModel model, GrafikController controller, GrafikView gView){
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.model = model;
|
this.model = model;
|
||||||
|
this.gView = gView;
|
||||||
this.invoker = new CommandInvoker();
|
this.invoker = new CommandInvoker();
|
||||||
|
this.controller = controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerEvents(){
|
public void registerEvents(){
|
||||||
@ -38,8 +43,8 @@ public class CommandController implements ActionListener{
|
|||||||
|
|
||||||
public void registerCommands(){
|
public void registerCommands(){
|
||||||
CommandSend commandSend = new CommandSend(view.getGvZeichenflaeche(), model);
|
CommandSend commandSend = new CommandSend(view.getGvZeichenflaeche(), model);
|
||||||
invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend));
|
invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend, model, gView));
|
||||||
//invoker.addCommand(view.getTfNachricht(), commandSend);
|
this.controller.setCommand(commandSend);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,9 +55,7 @@ public class CommandController implements ActionListener{
|
|||||||
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,11 +23,15 @@ 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, CommandController controller_commands)
|
public GrafikController(GrafikView view, GrafikModel model)
|
||||||
{
|
{
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.model = model;
|
this.model = model;
|
||||||
commandSend = new CommandSend(view, model);
|
commandSend = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setCommand(CommandSend command){
|
||||||
|
this.commandSend = command;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerEvents()
|
public void registerEvents()
|
||||||
@ -43,7 +47,7 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
|
|||||||
{
|
{
|
||||||
Point p = evt.getPoint();
|
Point p = evt.getPoint();
|
||||||
model.addPoint(p);
|
model.addPoint(p);
|
||||||
view.drawPoint(p);
|
view.drawPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -55,10 +59,9 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
|
|||||||
public void mouseReleased(MouseEvent evt)
|
public void mouseReleased(MouseEvent evt)
|
||||||
{
|
{
|
||||||
model.endShape();
|
model.endShape();
|
||||||
commandSend.execute();
|
if(commandSend != null){
|
||||||
// if (evt.getButton() == MouseEvent.BUTTON3)
|
commandSend.execute();
|
||||||
// {
|
}
|
||||||
// view.doPrint();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,11 @@
|
|||||||
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;
|
||||||
@ -26,8 +28,10 @@ public class CommandConnect implements CommandInterface
|
|||||||
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)
|
public CommandConnect(ChatView view, CommandInterface value, GrafikModel model, GrafikView gView)
|
||||||
{
|
{
|
||||||
rBtnServer = view.getBtnServer();
|
rBtnServer = view.getBtnServer();
|
||||||
rBtnClient = view.getBtnClient();
|
rBtnClient = view.getBtnClient();
|
||||||
@ -36,6 +40,8 @@ public class CommandConnect implements CommandInterface
|
|||||||
commandSend = (CommandSend) value;
|
commandSend = (CommandSend) value;
|
||||||
|
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
this.model = model;
|
||||||
|
this.gView = gView;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -44,7 +50,8 @@ public class CommandConnect implements CommandInterface
|
|||||||
if(rBtnServer.isSelected()){
|
if(rBtnServer.isSelected()){
|
||||||
lg.info("Server ausgewählt");
|
lg.info("Server ausgewählt");
|
||||||
try {
|
try {
|
||||||
commandSend.transmitterInterface = new Server(view);
|
commandSend.setTransmitter(new Server(view, model, gView));
|
||||||
|
//commandSend.transmitterInterface = new Server(view);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
lg.info("Die Verbindung zum Server ist Fehlgeschlagen");
|
lg.info("Die Verbindung zum Server ist Fehlgeschlagen");
|
||||||
}
|
}
|
||||||
@ -53,7 +60,8 @@ public class CommandConnect implements CommandInterface
|
|||||||
if(rBtnClient.isSelected()){
|
if(rBtnClient.isSelected()){
|
||||||
lg.info("Client ausgewählt");
|
lg.info("Client ausgewählt");
|
||||||
try {
|
try {
|
||||||
commandSend.transmitterInterface = new Client(view);
|
commandSend.setTransmitter(new Client(view, model, gView));
|
||||||
|
//commandSend.transmitterInterface = new Client(view);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
lg.info("Die Verbindung zum Client ist Fehlgeschlagen");
|
lg.info("Die Verbindung zum Client ist Fehlgeschlagen");
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
package ChatProgramm.model;
|
package ChatProgramm.model;
|
||||||
|
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
|
import ChatProgramm.view.GrafikView;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
@ -21,8 +22,8 @@ public class Client extends Transmitter {
|
|||||||
private static final String IP = "127.0.0.1";
|
private static final String IP = "127.0.0.1";
|
||||||
|
|
||||||
|
|
||||||
public Client(ChatView view) throws IOException {
|
public Client(ChatView view, GrafikModel model, GrafikView gView) throws IOException {
|
||||||
super(view);
|
super(view, model, gView);
|
||||||
connect();
|
connect();
|
||||||
initIO();
|
initIO();
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,10 @@ public class GrafikModel
|
|||||||
figuren.add(aktuelleFigur);
|
figuren.add(aktuelleFigur);
|
||||||
aktuelleFigur = new Figur();
|
aktuelleFigur = new Figur();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addFigur(Figur figur){
|
||||||
|
figuren.add(figur);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bestimmt die Adresse des zuletzt besuchten Ordners
|
* Bestimmt die Adresse des zuletzt besuchten Ordners
|
||||||
|
@ -4,21 +4,32 @@
|
|||||||
*/
|
*/
|
||||||
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) {
|
public ReceiveAdapter(ChatView view, GrafikModel model, GrafikView gView) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
this.model = model;
|
||||||
|
this.gView = gView;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -27,9 +38,11 @@ public class ReceiveAdapter implements Subscriber<Figur> {
|
|||||||
this.subscription.request(1);
|
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.addFigur(item);
|
||||||
|
gView.drawPoint();
|
||||||
// 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);
|
||||||
@ -43,8 +56,4 @@ public class ReceiveAdapter implements Subscriber<Figur> {
|
|||||||
public void onComplete(){
|
public void onComplete(){
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNext(Figur item)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
package ChatProgramm.model;
|
package ChatProgramm.model;
|
||||||
|
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
|
import ChatProgramm.view.GrafikView;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
@ -35,8 +36,8 @@ public class Server extends Transmitter
|
|||||||
lg.warning("Timeout"+"("+timeout/1000+"s)");
|
lg.warning("Timeout"+"("+timeout/1000+"s)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public Server(ChatView view) throws IOException {
|
public Server(ChatView view, GrafikModel model, GrafikView gView) throws IOException {
|
||||||
super(view);
|
super(view, model, gView);
|
||||||
connect();
|
connect();
|
||||||
initIO();
|
initIO();
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
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;
|
||||||
@ -48,13 +49,14 @@ public abstract class Transmitter implements Runnable, Subscriber<Figur>, Transm
|
|||||||
private ExecutorService eService;
|
private ExecutorService eService;
|
||||||
private String receivedString;
|
private String receivedString;
|
||||||
private ChatView view;
|
private ChatView view;
|
||||||
|
private GrafikModel model;
|
||||||
private ReceiveAdapter receiveAdapter;
|
private ReceiveAdapter receiveAdapter;
|
||||||
|
|
||||||
public Transmitter(ChatView view)
|
public Transmitter(ChatView view, GrafikModel model, GrafikView gView)
|
||||||
{
|
{
|
||||||
socket = new Socket();
|
socket = new Socket();
|
||||||
eService = null;
|
eService = null;
|
||||||
receiveAdapter = new ReceiveAdapter(view);
|
receiveAdapter = new ReceiveAdapter(view, model, gView);
|
||||||
figurPublisher = new SubmissionPublisher<>();
|
figurPublisher = new SubmissionPublisher<>();
|
||||||
this.view = view;
|
this.view = view;
|
||||||
addWertSubscription(receiveAdapter);
|
addWertSubscription(receiveAdapter);
|
||||||
@ -74,11 +76,12 @@ public abstract class Transmitter implements Runnable, Subscriber<Figur>, Transm
|
|||||||
InputStream is = socket.getInputStream();
|
InputStream is = socket.getInputStream();
|
||||||
OutputStream os = socket.getOutputStream();
|
OutputStream os = socket.getOutputStream();
|
||||||
|
|
||||||
|
|
||||||
// Bruh im ernst mann muss zuerst den writer und dann den reader initialisieren
|
// Bruh im ernst mann muss zuerst den writer und dann den reader initialisieren
|
||||||
// andersrum ist das blockierend weil die Streams von hinten nach vorne
|
// andersrum ist das blockiert weil die Streams von hinten nach vorne gelesen werden
|
||||||
// gelesen werden
|
|
||||||
writer = new ObjectOutputStream(os);
|
writer = new ObjectOutputStream(os);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
|
|
||||||
reader = new ObjectInputStream(is);
|
reader = new ObjectInputStream(is);
|
||||||
|
|
||||||
lg.info("Reader / Writer Initialisierung abgeschlossen");
|
lg.info("Reader / Writer Initialisierung abgeschlossen");
|
||||||
@ -118,7 +121,8 @@ public abstract class Transmitter implements Runnable, Subscriber<Figur>, Transm
|
|||||||
receivedObject = reader.readObject();
|
receivedObject = reader.readObject();
|
||||||
|
|
||||||
if (receivedObject instanceof Figur) {
|
if (receivedObject instanceof Figur) {
|
||||||
Figur receivedFigur = (Figur) receivedObject;
|
lg.info("Figur erhalten");
|
||||||
|
figur = (Figur) receivedObject;
|
||||||
// Verarbeiten Sie die empfangene Figur
|
// Verarbeiten Sie die empfangene Figur
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
@ -126,22 +130,8 @@ public abstract class Transmitter implements Runnable, Subscriber<Figur>, Transm
|
|||||||
} catch (ClassNotFoundException ex) {
|
} catch (ClassNotFoundException ex) {
|
||||||
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
figur = (Figur) reader.readObject();
|
|
||||||
if(!txtNachricht.isEmpty()){
|
|
||||||
lg.info("Nachricht erhalten");
|
|
||||||
|
|
||||||
return figur;
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
catch (ClassNotFoundException ex)
|
|
||||||
{
|
|
||||||
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
return figur;
|
return figur;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ 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 drawPoint(Point p)
|
public void drawPoint()
|
||||||
{
|
{
|
||||||
Graphics2D g2 = (Graphics2D)this.getGraphics(); // gefährlich!
|
Graphics2D g2 = (Graphics2D)this.getGraphics(); // gefährlich!
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user