From b71a6cf6b2c37f9b293073ee16591cad6ab0b898 Mon Sep 17 00:00:00 2001 From: BakeOrDie Date: Wed, 23 Dec 2020 11:47:08 +0100 Subject: [PATCH] Merge origin/master Conflicts: src/wuerfelthreads/Start.java src/wuerfelthreads/view/WuerfelView.form src/wuerfelthreads/view/WuerfelView.java --- src/graphicChat/controller/CommandSend.java | 3 +- .../controller/ReceiveAdapter.java | 2 +- src/graphicChat/model/ChatModel.java | 53 ++++++------------- src/graphicChat/model/Figure.java | 3 +- src/graphicChat/model/GraphicData.java | 40 +++++++++----- 5 files changed, 49 insertions(+), 52 deletions(-) diff --git a/src/graphicChat/controller/CommandSend.java b/src/graphicChat/controller/CommandSend.java index b09df3b..9971c1c 100644 --- a/src/graphicChat/controller/CommandSend.java +++ b/src/graphicChat/controller/CommandSend.java @@ -47,8 +47,9 @@ public class CommandSend implements ActionListener if(src == view.getBtnSend()){ /* view get figures*/ - msg = model.getFigures(); + msg = model.getSendFigures(); model.sendMessage(msg); + model.saveFigures(msg); view.getLblStatus().setText("Nachricht gesendet"); } } diff --git a/src/graphicChat/controller/ReceiveAdapter.java b/src/graphicChat/controller/ReceiveAdapter.java index e4ec9bc..1ff15f6 100644 --- a/src/graphicChat/controller/ReceiveAdapter.java +++ b/src/graphicChat/controller/ReceiveAdapter.java @@ -49,7 +49,7 @@ public class ReceiveAdapter implements Flow.Subscriber> public void onNext(List
msg) { view.getLblStatus().setText("Nachricht empfangen"); - model.addList(msg); + view.repaint(); subscription.request(1); } diff --git a/src/graphicChat/model/ChatModel.java b/src/graphicChat/model/ChatModel.java index b6ce7a0..45dd28d 100644 --- a/src/graphicChat/model/ChatModel.java +++ b/src/graphicChat/model/ChatModel.java @@ -27,6 +27,7 @@ import java.util.logging.Logger; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.util.ArrayList; import java.util.List; /** @@ -80,14 +81,13 @@ public class ChatModel implements Runnable try { try { - lg.info("test"); - msg = (List
)objectInput.readObject(); + msg = (List
)objectInput.readObject(); + lg.info("Nachricht empfangen" + String.valueOf(msg.size())); } catch (ClassNotFoundException ex) { lg.log(Level.SEVERE, null, ex); } - lg.info("Nachricht empfangen: "); addList(msg); iPublisher.submit(msg);//wenn neue Nachricht } catch (IOException ex) { @@ -151,15 +151,16 @@ public class ChatModel implements Runnable public void sendMessage(List
msg) { if(laufend){ - lg.log(Level.INFO, "Sende Nachricht: "); + lg.log(Level.INFO, "Sende Nachricht: " + String.valueOf(msg.size())); try { - objectOutput.writeObject(msg); - //objectOutput.flush(); + List
cloned_list = new ArrayList
(msg); + objectOutput.writeObject(cloned_list); + objectOutput.flush(); } catch (IOException ex) { - Logger.getLogger(ChatModel.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(ChatModel.class.getName()).log(Level.SEVERE, null, ex); } } else{ @@ -176,38 +177,18 @@ public class ChatModel implements Runnable { return gdata.getFigures(); } + public List
getSendFigures() + { + return gdata.getSendFigures(); + } + public void addList(List
list) { gdata.addList(list); } - -// public void speichereDatei(String dateiname) throws FileNotFoundException, IOException -// { -// FileOutputStream fos = new FileOutputStream(dateiname); -// BufferedOutputStream buffout = new BufferedOutputStream(fos); -// ObjectOutputStream oos = new ObjectOutputStream(buffout); -// oos.writeObject(figures); -// oos.flush(); -// oos.close(); -// -// } -// -// public void ladeDatei(String dateiname) throws FileNotFoundException, IOException, ClassNotFoundException -// { -// FileInputStream fis = new FileInputStream(dateiname); -// BufferedInputStream buffin = new BufferedInputStream(fis); -// ObjectInputStream ois = new ObjectInputStream(buffin); -// Object obj = ois.readObject(); -//// if (obj instanceof ArrayList) -//// { -//// punkte = (ArrayList) obj; -//// } -//// else -//// { -//// Fehler .... -//// } -// figures = (ArrayList
) ois.readObject(); -// ois.close(); -// } + public void saveFigures(List
list) + { + gdata.saveFigures(list); + } } \ No newline at end of file diff --git a/src/graphicChat/model/Figure.java b/src/graphicChat/model/Figure.java index 2d619dd..3c6ff48 100644 --- a/src/graphicChat/model/Figure.java +++ b/src/graphicChat/model/Figure.java @@ -7,6 +7,7 @@ package graphicChat.model; import java.awt.Point; +import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -15,7 +16,7 @@ import java.util.List; * * @author chris, hd */ -public class Figure +public class Figure implements Serializable { private ArrayList punkte; diff --git a/src/graphicChat/model/GraphicData.java b/src/graphicChat/model/GraphicData.java index 12ecf5d..b90753e 100644 --- a/src/graphicChat/model/GraphicData.java +++ b/src/graphicChat/model/GraphicData.java @@ -6,17 +6,11 @@ package graphicChat.model; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; +import graphicChat.logger.OhmLogger; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.logging.Logger; /** * @@ -25,24 +19,44 @@ import java.util.List; public class GraphicData { private ArrayList
figures; + private ArrayList
send_figures; + private static final Logger lg = OhmLogger.getLogger(); public GraphicData() { figures = new ArrayList<>(); - + send_figures = new ArrayList<>(); } public void addList(List
list) { - figures.addAll(list); + figures.addAll(list); } - public Figure addFigure() + public void saveFigures(List
list) { - figures.add(new Figure()); - return figures.get(figures.size() - 1); + figures.addAll(list); + send_figures.clear(); } + +// public Figure addFigure() +// { +// figures.add(new Figure()); +// return figures.get(figures.size() - 1); +// +// } + public Figure addFigure() + { + send_figures.add(new Figure()); + return send_figures.get(send_figures.size() - 1); + + } + public List
getFigures() { return Collections.unmodifiableList(figures); } + public List
getSendFigures() + { + return Collections.unmodifiableList(send_figures); + } } \ No newline at end of file