diff --git a/src/ChatProgramm/Start.java b/src/ChatProgramm/Start.java index 0f6467c..8938b96 100644 --- a/src/ChatProgramm/Start.java +++ b/src/ChatProgramm/Start.java @@ -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; @@ -29,6 +31,17 @@ public class Start zeichenflaeche.setModel(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); model.addSubscription(rAdapter); diff --git a/src/ChatProgramm/controller/CommandController.java b/src/ChatProgramm/controller/CommandController.java index 989f017..bb7198a 100644 --- a/src/ChatProgramm/controller/CommandController.java +++ b/src/ChatProgramm/controller/CommandController.java @@ -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); +// +// } +// +//} +// +// diff --git a/src/ChatProgramm/controller/GrafikController.java b/src/ChatProgramm/controller/GrafikController.java index 8e0facd..bf054fa 100644 --- a/src/ChatProgramm/controller/GrafikController.java +++ b/src/ChatProgramm/controller/GrafikController.java @@ -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(); } } diff --git a/src/ChatProgramm/controller/commands/CommandConnect.java b/src/ChatProgramm/controller/commands/CommandConnect.java index e92c545..fbbc6df 100644 --- a/src/ChatProgramm/controller/commands/CommandConnect.java +++ b/src/ChatProgramm/controller/commands/CommandConnect.java @@ -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() - { - } -} \ No newline at end of file +///* +// * 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() +// { +// } +//} \ No newline at end of file diff --git a/src/ChatProgramm/controller/commands/CommandConnectV2.java b/src/ChatProgramm/controller/commands/CommandConnectV2.java index 5c0a5af..fe31fa0 100644 --- a/src/ChatProgramm/controller/commands/CommandConnectV2.java +++ b/src/ChatProgramm/controller/commands/CommandConnectV2.java @@ -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)); diff --git a/src/ChatProgramm/controller/commands/CommandSend.java b/src/ChatProgramm/controller/commands/CommandSend.java index 895c207..d3975b9 100644 --- a/src/ChatProgramm/controller/commands/CommandSend.java +++ b/src/ChatProgramm/controller/commands/CommandSend.java @@ -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"); +// } +// } +//} diff --git a/src/ChatProgramm/controller/commands/CommandSendV2.java b/src/ChatProgramm/controller/commands/CommandSendV2.java new file mode 100644 index 0000000..4daf0a7 --- /dev/null +++ b/src/ChatProgramm/controller/commands/CommandSendV2.java @@ -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(); + } +} diff --git a/src/ChatProgramm/model/ChatModel.java b/src/ChatProgramm/model/ChatModel.java index 43f4c09..a75cc54 100644 --- a/src/ChatProgramm/model/ChatModel.java +++ b/src/ChatProgramm/model/ChatModel.java @@ -5,57 +5,61 @@ 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 { private static Logger lg = OhmLogger.getLogger(); private SubmissionPublisher 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; this.transmitter = null; - + 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 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 { 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()); + } + } diff --git a/src/ChatProgramm/model/ReceiveAdapter.java b/src/ChatProgramm/model/ReceiveAdapter.java index 86b2a61..3a7d484 100644 --- a/src/ChatProgramm/model/ReceiveAdapter.java +++ b/src/ChatProgramm/model/ReceiveAdapter.java @@ -36,10 +36,8 @@ public class ReceiveAdapter implements Subscriber { } 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); } diff --git a/src/ChatProgramm/model/Transmitter.java b/src/ChatProgramm/model/Transmitter.java index 620ebdf..a77f1f9 100644 --- a/src/ChatProgramm/model/Transmitter.java +++ b/src/ChatProgramm/model/Transmitter.java @@ -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{ +public abstract class Transmitter implements Runnable { static final int timeout = 60000; private static final int PORT = 35000; @@ -42,138 +42,109 @@ public abstract class Transmitter implements Runnable, Subscriber{ protected Socket socket; protected ObjectInputStream reader; protected ObjectOutputStream writer; - + private SubmissionPublisher figurPublisher; private ExecutorService eService; - - + private ChatView view; private ChatModel model; - + private ReceiveAdapter receiveAdapter; - - public Transmitter(ChatView view, ChatModel model) - { - socket = new Socket(); - eService = null; - - figurPublisher = new SubmissionPublisher<>(); - - this.view = view; - this.model = model; + + public Transmitter(ChatView view, ChatModel model) { + socket = new Socket(); + eService = null; + + figurPublisher = new SubmissionPublisher<>(); + + this.view = view; + this.model = model; } - - public void addSubscription(Subscriber subscriber) - { - figurPublisher.subscribe(subscriber); + + public void addSubscription(Subscriber subscriber) { + figurPublisher.subscribe(subscriber); } public abstract void connect() throws IOException; public void initIO() { - try { - lg.info("Initialisiere reader und writer"); - InputStream is = socket.getInputStream(); - OutputStream os = socket.getOutputStream(); + try { + lg.info("Initialisiere reader und writer"); + InputStream is = socket.getInputStream(); + OutputStream os = socket.getOutputStream(); - writer = new ObjectOutputStream(os); - writer.flush(); - reader = new ObjectInputStream(is); - - lg.info("Reader / Writer Initialisierung abgeschlossen"); - startempfangen(); + writer = new ObjectOutputStream(os); + writer.flush(); + reader = new ObjectInputStream(is); - } catch (UnsupportedEncodingException ex) { - Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex); - } catch (IOException ex) { - Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex); - } + lg.info("Reader / Writer Initialisierung abgeschlossen"); + startempfangen(); + + } catch (UnsupportedEncodingException ex) { + Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex); + } catch (IOException ex) { + Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex); + } } - - /** - * - * @param figur - * @throws IOException - */ - public void send(Figur figur){ - try - { - writer.writeObject(figur); - writer.flush(); - } - catch (IOException ex) - { - Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex); - } + + /** + * @param figur + * @throws IOException + */ + 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"); figurPublisher.submit(figur); } - public Figur receive(){ - + + public Figur receive() { + Object receivedObject; Figur figur = new Figur(); try { receivedObject = reader.readObject(); - - if (receivedObject instanceof Figur) { - lg.info("Figur erhalten"); - figur = (Figur) receivedObject; + + if (receivedObject instanceof 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; } - - + @Override public void run() { - while (true) { - lg.info("Warte auf Nachricht"); -// figur = receive(); -// if(!figur.getPunkte().isEmpty()){ -// figurPublisher.submit(figur); -// } - } + while (true) { + Figur figur = new Figur(); + lg.info("Warte auf Nachricht"); + 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) { + } + if (eService == null) { + eService = Executors.newSingleThreadExecutor(); + eService.execute(this); + } + lg.info("Starte Chat"); } - - @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.execute(this); - } - lg.info("Starte Chat"); - } }