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