Architektur umgesetzt -> noch aufraumen
This commit is contained in:
parent
75e458a4ac
commit
a5b238fe4f
@ -5,8 +5,10 @@
|
||||
|
||||
package ChatProgramm;
|
||||
|
||||
import ChatProgramm.controller.CommandController;
|
||||
//import ChatProgramm.controller.CommandController;
|
||||
import ChatProgramm.controller.GrafikController;
|
||||
import ChatProgramm.controller.commands.CommandConnectV2;
|
||||
import ChatProgramm.controller.commands.CommandSendV2;
|
||||
import ChatProgramm.model.ChatModel;
|
||||
import ChatProgramm.model.GrafikDaten;
|
||||
import ChatProgramm.model.ReceiveAdapter;
|
||||
@ -30,6 +32,17 @@ public class Start
|
||||
|
||||
ChatModel model = new ChatModel(gDaten);
|
||||
|
||||
GrafikController gContoller = new GrafikController(view,model);
|
||||
gContoller.registerEvents();
|
||||
|
||||
CommandConnectV2 cConnect = new CommandConnectV2(view,model);
|
||||
cConnect.registerEvents();
|
||||
|
||||
CommandSendV2 cSend = new CommandSendV2(view, model);
|
||||
cSend.registerEvents();
|
||||
|
||||
|
||||
|
||||
ReceiveAdapter rAdapter = new ReceiveAdapter(view, model);
|
||||
model.addSubscription(rAdapter);
|
||||
|
||||
|
@ -1,61 +1,61 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
|
||||
package ChatProgramm.controller;
|
||||
|
||||
import ChatProgramm.controller.commands.CommandConnect;
|
||||
import ChatProgramm.controller.commands.CommandInvoker;
|
||||
import ChatProgramm.controller.commands.CommandSend;
|
||||
import ChatProgramm.model.GrafikDaten;
|
||||
import ChatProgramm.view.ChatView;
|
||||
import ChatProgramm.view.GrafikView;
|
||||
import java.awt.Component;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
public class CommandController implements ActionListener{
|
||||
|
||||
private ChatView view;
|
||||
private GrafikDaten model;
|
||||
private GrafikView gView;
|
||||
private CommandInvoker invoker;
|
||||
private GrafikController controller;
|
||||
|
||||
public CommandController(ChatView view, GrafikDaten model, GrafikController controller, GrafikView gView){
|
||||
this.view = view;
|
||||
this.model = model;
|
||||
this.gView = gView;
|
||||
this.invoker = new CommandInvoker();
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
public void registerEvents(){
|
||||
view.getBtnConnect().addActionListener(this);
|
||||
}
|
||||
|
||||
public void registerCommands(){
|
||||
CommandSend commandSend = new CommandSend(view.getGvZeichenflaeche(), model);
|
||||
invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend, model, gView));
|
||||
this.controller.setCommand(commandSend);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ausführen des jeweiligen Kommandos
|
||||
* @param e Referenz auf das Event
|
||||
*/
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Component key = (Component)e.getSource();
|
||||
invoker.executeCommand(key);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
///*
|
||||
// * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
// * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
// */
|
||||
//
|
||||
//package ChatProgramm.controller;
|
||||
//
|
||||
//import ChatProgramm.controller.commands.CommandConnect;
|
||||
//import ChatProgramm.controller.commands.CommandInvoker;
|
||||
//import ChatProgramm.controller.commands.CommandSend;
|
||||
//import ChatProgramm.model.GrafikDaten;
|
||||
//import ChatProgramm.view.ChatView;
|
||||
//import ChatProgramm.view.GrafikView;
|
||||
//import java.awt.Component;
|
||||
//import java.awt.event.ActionEvent;
|
||||
//import java.awt.event.ActionListener;
|
||||
//
|
||||
///**
|
||||
// *
|
||||
// * @author ahren
|
||||
// */
|
||||
//public class CommandController implements ActionListener{
|
||||
//
|
||||
// private ChatView view;
|
||||
// private GrafikDaten model;
|
||||
// private GrafikView gView;
|
||||
// private CommandInvoker invoker;
|
||||
// private GrafikController controller;
|
||||
//
|
||||
//public CommandController(ChatView view, GrafikDaten model, GrafikController controller, GrafikView gView){
|
||||
// this.view = view;
|
||||
// this.model = model;
|
||||
// this.gView = gView;
|
||||
// this.invoker = new CommandInvoker();
|
||||
// this.controller = controller;
|
||||
// }
|
||||
//
|
||||
// public void registerEvents(){
|
||||
// view.getBtnConnect().addActionListener(this);
|
||||
// }
|
||||
//
|
||||
// public void registerCommands(){
|
||||
// CommandSend commandSend = new CommandSend(view.getGvZeichenflaeche(), model);
|
||||
// invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend, model, gView));
|
||||
// this.controller.setCommand(commandSend);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Ausführen des jeweiligen Kommandos
|
||||
// * @param e Referenz auf das Event
|
||||
// */
|
||||
// @Override
|
||||
// public void actionPerformed(ActionEvent e) {
|
||||
// Component key = (Component)e.getSource();
|
||||
// invoker.executeCommand(key);
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
||||
//
|
||||
//
|
||||
|
@ -5,12 +5,17 @@
|
||||
|
||||
package ChatProgramm.controller;
|
||||
|
||||
import ChatProgramm.controller.commands.CommandSend;
|
||||
//import ChatProgramm.controller.commands.CommandSend;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ChatProgramm.model.ChatModel;
|
||||
import ChatProgramm.model.GrafikDaten;
|
||||
import ChatProgramm.util.OhmLogger;
|
||||
import ChatProgramm.view.ChatView;
|
||||
import ChatProgramm.view.GrafikView;
|
||||
|
||||
/**
|
||||
@ -19,25 +24,22 @@ import ChatProgramm.view.GrafikView;
|
||||
*/
|
||||
public class GrafikController extends MouseAdapter implements MouseMotionListener
|
||||
{
|
||||
private GrafikView view;
|
||||
private GrafikDaten model;
|
||||
private CommandSend commandSend;
|
||||
private static Logger lg = OhmLogger.getLogger();
|
||||
private ChatView view;
|
||||
private ChatModel model;
|
||||
// private CommandSend commandSend;
|
||||
|
||||
public GrafikController(GrafikView view, GrafikDaten model)
|
||||
public GrafikController(ChatView view, ChatModel model)
|
||||
{
|
||||
this.view = view;
|
||||
this.model = model;
|
||||
commandSend = null;
|
||||
}
|
||||
|
||||
void setCommand(CommandSend command){
|
||||
this.commandSend = command;
|
||||
}
|
||||
|
||||
public void registerEvents()
|
||||
{
|
||||
view.addMouseMotionListener(this);
|
||||
view.addMouseListener(this);
|
||||
view.getGvZeichenflaeche().addMouseMotionListener(this);
|
||||
view.getGvZeichenflaeche().addMouseListener(this);
|
||||
}
|
||||
|
||||
|
||||
@ -46,8 +48,9 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
|
||||
public void mouseDragged(MouseEvent evt)
|
||||
{
|
||||
Point p = evt.getPoint();
|
||||
model.addPoint(p);
|
||||
view.drawPoint();
|
||||
|
||||
model.getGrafikDaten().addPoint(p);
|
||||
view.getGvZeichenflaeche().drawPoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -58,10 +61,7 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent evt)
|
||||
{
|
||||
model.endShape();
|
||||
if(commandSend != null){
|
||||
commandSend.execute();
|
||||
}
|
||||
model.getGrafikDaten().endShape();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,82 +1,82 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
|
||||
package ChatProgramm.controller.commands;
|
||||
|
||||
import ChatProgramm.model.Client;
|
||||
import ChatProgramm.model.GrafikDaten;
|
||||
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;
|
||||
import javax.swing.JRadioButton;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
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 GrafikDaten model;
|
||||
private GrafikView gView;
|
||||
|
||||
public CommandConnect(ChatView view, CommandInterface value, GrafikDaten model, GrafikView gView)
|
||||
{
|
||||
rBtnServer = view.getBtnServer();
|
||||
rBtnClient = view.getBtnClient();
|
||||
dialogFenster = view.getjDialog1();
|
||||
|
||||
commandSend = (CommandSend) value;
|
||||
|
||||
this.view = view;
|
||||
this.model = model;
|
||||
this.gView = gView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute()
|
||||
{
|
||||
if(rBtnServer.isSelected()){
|
||||
lg.info("Server ausgewählt");
|
||||
try {
|
||||
commandSend.setTransmitter(new Server(view, model, gView));
|
||||
} catch (IOException ex) {
|
||||
lg.info("Die Verbindung zum Server ist Fehlgeschlagen");
|
||||
}
|
||||
}
|
||||
|
||||
if(rBtnClient.isSelected()){
|
||||
lg.info("Client ausgewählt");
|
||||
try {
|
||||
commandSend.setTransmitter(new Client(view, model, gView));
|
||||
} catch (IOException ex) {
|
||||
lg.info("Die Verbindung zum Client ist Fehlgeschlagen");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
dialogFenster.setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUndoable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo()
|
||||
{
|
||||
}
|
||||
}
|
||||
///*
|
||||
// * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
// * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
// */
|
||||
//
|
||||
//package ChatProgramm.controller.commands;
|
||||
//
|
||||
//import ChatProgramm.model.Client;
|
||||
//import ChatProgramm.model.GrafikDaten;
|
||||
//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;
|
||||
//import javax.swing.JRadioButton;
|
||||
//
|
||||
///**
|
||||
// *
|
||||
// * @author ahren
|
||||
// */
|
||||
//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 GrafikDaten model;
|
||||
// private GrafikView gView;
|
||||
//
|
||||
// public CommandConnect(ChatView view, CommandInterface value, GrafikDaten model, GrafikView gView)
|
||||
// {
|
||||
// rBtnServer = view.getBtnServer();
|
||||
// rBtnClient = view.getBtnClient();
|
||||
// dialogFenster = view.getjDialog1();
|
||||
//
|
||||
// commandSend = (CommandSend) value;
|
||||
//
|
||||
// this.view = view;
|
||||
// this.model = model;
|
||||
// this.gView = gView;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void execute()
|
||||
// {
|
||||
// if(rBtnServer.isSelected()){
|
||||
// lg.info("Server ausgewählt");
|
||||
// try {
|
||||
// commandSend.setTransmitter(new Server(view, model, gView));
|
||||
// } catch (IOException ex) {
|
||||
// lg.info("Die Verbindung zum Server ist Fehlgeschlagen");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if(rBtnClient.isSelected()){
|
||||
// lg.info("Client ausgewählt");
|
||||
// try {
|
||||
// commandSend.setTransmitter(new Client(view, model, gView));
|
||||
// } catch (IOException ex) {
|
||||
// lg.info("Die Verbindung zum Client ist Fehlgeschlagen");
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// dialogFenster.setVisible(false);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean isUndoable()
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void undo()
|
||||
// {
|
||||
// }
|
||||
//}
|
@ -35,7 +35,7 @@ public class CommandConnectV2 implements ActionListener {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (view.getBtnClient().isSelected()) {
|
||||
if (view.getBtnServer().isSelected()) {
|
||||
lg.info("Server ausgewählt");
|
||||
try {
|
||||
model.setTransmitter(new Server(view, model));
|
||||
@ -44,7 +44,7 @@ public class CommandConnectV2 implements ActionListener {
|
||||
}
|
||||
}
|
||||
|
||||
if (view.getBtnServer().isSelected()) {
|
||||
if (view.getBtnClient().isSelected()) {
|
||||
lg.info("Client ausgewählt");
|
||||
try {
|
||||
model.setTransmitter(new Client(view, model));
|
||||
|
@ -1,83 +1,80 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
|
||||
package ChatProgramm.controller.commands;
|
||||
|
||||
import ChatProgramm.model.Client;
|
||||
import ChatProgramm.model.Figur;
|
||||
import ChatProgramm.model.GrafikDaten;
|
||||
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.view.GrafikView;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
public class CommandSend implements CommandInterface
|
||||
{
|
||||
private static Logger lg = OhmLogger.getLogger();
|
||||
|
||||
private GrafikView view;
|
||||
private GrafikDaten model;
|
||||
|
||||
public TransmitterInterface transmitterInterface;
|
||||
public Server server;
|
||||
public Client client;
|
||||
|
||||
|
||||
|
||||
|
||||
public CommandSend(GrafikView view, GrafikDaten model)
|
||||
{
|
||||
this.view = view;
|
||||
this.model = model;
|
||||
//ToDo: Hier muss auch der gFrame referenziert werden
|
||||
//this.eingabeFeld = view.getTfNachricht();
|
||||
transmitterInterface = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute()
|
||||
{
|
||||
Figur aktuelleFigur = model.getFiguren().getLast();
|
||||
try
|
||||
{
|
||||
transmitterInterface.send(aktuelleFigur);
|
||||
|
||||
}
|
||||
catch(Exception NullPointerExeption)
|
||||
{
|
||||
lg.info("Der Transmitter ist null");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isUndoable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
///*
|
||||
// * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
// * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
// */
|
||||
//
|
||||
//package ChatProgramm.controller.commands;
|
||||
//
|
||||
//import ChatProgramm.model.*;
|
||||
//import ChatProgramm.util.OhmLogger;
|
||||
//import ChatProgramm.view.ChatView;
|
||||
//
|
||||
//import java.awt.event.MouseAdapter;
|
||||
//import java.awt.event.MouseMotionListener;
|
||||
//import java.util.logging.Logger;
|
||||
//import javax.swing.JTextField;
|
||||
//import ChatProgramm.view.GrafikView;
|
||||
//
|
||||
///**
|
||||
// *
|
||||
// * @author ahren
|
||||
// */
|
||||
//public class CommandSend extends MouseAdapter implements MouseMotionListener
|
||||
//{
|
||||
// private static Logger lg = OhmLogger.getLogger();
|
||||
//
|
||||
// private ChatView view;
|
||||
// private ChatModel model;
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// public CommandSend(ChatView view, ChatModel model)
|
||||
// {
|
||||
// this.view = view;
|
||||
// this.model = model;
|
||||
// //ToDo: Hier muss auch der gFrame referenziert werden
|
||||
// //this.eingabeFeld = view.getTfNachricht();
|
||||
// transmitterInterface = null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void execute()
|
||||
// {
|
||||
// Figur aktuelleFigur = model.getFiguren().getLast();
|
||||
// try
|
||||
// {
|
||||
// transmitterInterface.send(aktuelleFigur);
|
||||
//
|
||||
// }
|
||||
// catch(Exception NullPointerExeption)
|
||||
// {
|
||||
// lg.info("Der Transmitter ist null");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public boolean isUndoable()
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// 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");
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
40
src/ChatProgramm/controller/commands/CommandSendV2.java
Normal file
40
src/ChatProgramm/controller/commands/CommandSendV2.java
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package ChatProgramm.controller.commands;
|
||||
|
||||
import ChatProgramm.model.ChatModel;
|
||||
import ChatProgramm.model.Client;
|
||||
import ChatProgramm.model.Server;
|
||||
import ChatProgramm.util.OhmLogger;
|
||||
import ChatProgramm.view.ChatView;
|
||||
|
||||
import java.awt.event.*;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Js-Sc
|
||||
*/
|
||||
public class CommandSendV2 extends MouseAdapter implements MouseMotionListener {
|
||||
|
||||
private static Logger lg = OhmLogger.getLogger();
|
||||
private ChatView view;
|
||||
private ChatModel model;
|
||||
|
||||
public CommandSendV2(ChatView view, ChatModel model) {
|
||||
this.view = view;
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public void registerEvents() {
|
||||
view.getGvZeichenflaeche().addMouseListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
model.sendFigur();
|
||||
}
|
||||
}
|
@ -5,30 +5,30 @@
|
||||
package ChatProgramm.model;
|
||||
|
||||
import ChatProgramm.controller.GrafikController;
|
||||
import ChatProgramm.controller.commands.CommandConnect;
|
||||
import ChatProgramm.controller.commands.CommandSend;
|
||||
//import ChatProgramm.controller.commands.CommandConnect;
|
||||
import ChatProgramm.controller.commands.CommandConnectV2;
|
||||
//import ChatProgramm.controller.commands.CommandSend;
|
||||
import ChatProgramm.controller.commands.CommandSendV2;
|
||||
import ChatProgramm.util.OhmLogger;
|
||||
|
||||
import java.util.concurrent.Flow;
|
||||
import java.util.concurrent.Flow.Subscriber;
|
||||
import java.util.concurrent.SubmissionPublisher;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Js-Sc
|
||||
*/
|
||||
public class ChatModel implements Subscriber<Figur> {
|
||||
|
||||
private static Logger lg = OhmLogger.getLogger();
|
||||
private SubmissionPublisher<Figur> figurPublisher;
|
||||
private Flow.Subscription subscription;
|
||||
|
||||
private Transmitter transmitter;
|
||||
private GrafikDaten grafikDaten;
|
||||
|
||||
private CommandConnect cConnect;
|
||||
private CommandSend cSend;
|
||||
private ReceiveAdapter rAdapter;
|
||||
private GrafikController gController;
|
||||
|
||||
|
||||
public ChatModel(GrafikDaten gDaten) {
|
||||
this.grafikDaten = gDaten;
|
||||
@ -37,25 +37,29 @@ public class ChatModel implements Subscriber<Figur> {
|
||||
this.figurPublisher = new SubmissionPublisher<>();
|
||||
}
|
||||
|
||||
public void setTransmitter(Transmitter transmitter)
|
||||
{
|
||||
public void setTransmitter(Transmitter transmitter) {
|
||||
this.transmitter = transmitter;
|
||||
this.transmitter.addSubscription(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void addSubscription(Subscriber<Figur> subscriber) {
|
||||
figurPublisher.subscribe(subscriber);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onSubscribe(Flow.Subscription subscription) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
this.subscription = subscription;
|
||||
this.subscription.request(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(Figur item) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
grafikDaten.addFigure(item);
|
||||
lg.info("Figur wurde dem Grafikmodel hinzugefügt");
|
||||
figurPublisher.submit(item);
|
||||
this.subscription.request(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -68,4 +72,13 @@ public class ChatModel implements Subscriber<Figur> {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
public GrafikDaten getGrafikDaten() {
|
||||
return grafikDaten;
|
||||
}
|
||||
|
||||
public void sendFigur() {
|
||||
lg.info("Sende aktuelle Figur");
|
||||
transmitter.send(grafikDaten.getFiguren().getLast());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,10 +36,8 @@ public class ReceiveAdapter implements Subscriber<Figur> {
|
||||
}
|
||||
|
||||
public void onNext(Figur item) {
|
||||
// model.addFigure(item);
|
||||
// gView.drawFigur();
|
||||
|
||||
lg.info("Figur wurde dem Grafikmodel hinzugefügt");
|
||||
view.getGvZeichenflaeche().drawFigur();
|
||||
lg.info("Figur auf die Zeichenfläche projiziert");
|
||||
this.subscription.request(1);
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ package ChatProgramm.model;
|
||||
import ChatProgramm.util.OhmLogger;
|
||||
import ChatProgramm.view.ChatView;
|
||||
import ChatProgramm.view.GrafikView;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
@ -29,10 +30,9 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
public abstract class Transmitter implements Runnable, Subscriber<Figur>{
|
||||
public abstract class Transmitter implements Runnable {
|
||||
|
||||
static final int timeout = 60000;
|
||||
private static final int PORT = 35000;
|
||||
@ -48,14 +48,12 @@ public abstract class Transmitter implements Runnable, Subscriber<Figur>{
|
||||
private ExecutorService eService;
|
||||
|
||||
|
||||
|
||||
private ChatView view;
|
||||
private ChatModel model;
|
||||
|
||||
private ReceiveAdapter receiveAdapter;
|
||||
|
||||
public Transmitter(ChatView view, ChatModel model)
|
||||
{
|
||||
public Transmitter(ChatView view, ChatModel model) {
|
||||
socket = new Socket();
|
||||
eService = null;
|
||||
|
||||
@ -66,8 +64,7 @@ public abstract class Transmitter implements Runnable, Subscriber<Figur>{
|
||||
|
||||
}
|
||||
|
||||
public void addSubscription(Subscriber<Figur> subscriber)
|
||||
{
|
||||
public void addSubscription(Subscriber<Figur> subscriber) {
|
||||
figurPublisher.subscribe(subscriber);
|
||||
}
|
||||
|
||||
@ -94,24 +91,21 @@ public abstract class Transmitter implements Runnable, Subscriber<Figur>{
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param figur
|
||||
* @throws IOException
|
||||
*/
|
||||
public void send(Figur figur){
|
||||
try
|
||||
{
|
||||
public void send(Figur figur) {
|
||||
try {
|
||||
writer.writeObject(figur);
|
||||
writer.flush();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
lg.info("Nachricht gesendet");
|
||||
figurPublisher.submit(figur);
|
||||
}
|
||||
public Figur receive(){
|
||||
|
||||
public Figur receive() {
|
||||
|
||||
Object receivedObject;
|
||||
Figur figur = new Figur();
|
||||
@ -122,10 +116,8 @@ public abstract class Transmitter implements Runnable, Subscriber<Figur>{
|
||||
lg.info("Figur erhalten");
|
||||
figur = (Figur) receivedObject;
|
||||
}
|
||||
} 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 | ClassNotFoundException ex) {
|
||||
lg.info(ex.getMessage());
|
||||
}
|
||||
|
||||
return figur;
|
||||
@ -133,44 +125,23 @@ public abstract class Transmitter implements Runnable, Subscriber<Figur>{
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
Figur figur = new Figur();
|
||||
lg.info("Warte auf Nachricht");
|
||||
// figur = receive();
|
||||
// if(!figur.getPunkte().isEmpty()){
|
||||
// figurPublisher.submit(figur);
|
||||
// }
|
||||
figur = receive();
|
||||
if (!figur.getPunkte().isEmpty()) {
|
||||
figurPublisher.submit(figur);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onSubscribe(Flow.Subscription subscription) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
private void startempfangen() {
|
||||
synchronized (this) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(Figur item) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable throwable) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
private void startempfangen()
|
||||
{
|
||||
synchronized (this){
|
||||
}
|
||||
if (eService == null){
|
||||
if (eService == null) {
|
||||
eService = Executors.newSingleThreadExecutor();
|
||||
eService.execute(this);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user