diff --git a/src/ChatProgramm/Start.java b/src/ChatProgramm/Start.java index 1388b25..440bd8d 100644 --- a/src/ChatProgramm/Start.java +++ b/src/ChatProgramm/Start.java @@ -18,9 +18,7 @@ public class Start { public Start() { - //Transmitter transmitter = new Transmitter(); ChatView view = new ChatView(); - //CommandController controller_commands = new CommandController(view, transmitter); CommandController controller_commands = new CommandController(view); controller_commands.registerEvents(); controller_commands.registerCommands(); diff --git a/src/ChatProgramm/controller/CommandController.java b/src/ChatProgramm/controller/CommandController.java index c5f889b..94a4819 100644 --- a/src/ChatProgramm/controller/CommandController.java +++ b/src/ChatProgramm/controller/CommandController.java @@ -8,9 +8,6 @@ package ChatProgramm.controller; import ChatProgramm.controller.commands.CommandConnect; import ChatProgramm.controller.commands.CommandInvoker; import ChatProgramm.controller.commands.CommandSend; -import ChatProgramm.model.Client; -import ChatProgramm.model.Server; -import ChatProgramm.model.Transmitter; import ChatProgramm.view.ChatView; import java.awt.Component; import java.awt.event.ActionEvent; @@ -23,15 +20,8 @@ import java.awt.event.ActionListener; public class CommandController implements ActionListener{ private ChatView view; - //private Transmitter transmitter; private CommandInvoker invoker; - -// public CommandController(ChatView view, Transmitter transmitter){ -// this.view = view; -// this.transmitter = transmitter; -// this.invoker = new CommandInvoker(); -// } - + public CommandController(ChatView view){ this.view = view; this.invoker = new CommandInvoker(); diff --git a/src/ChatProgramm/controller/commands/CommandConnect.java b/src/ChatProgramm/controller/commands/CommandConnect.java index 08b5cbf..7603372 100644 --- a/src/ChatProgramm/controller/commands/CommandConnect.java +++ b/src/ChatProgramm/controller/commands/CommandConnect.java @@ -10,7 +10,6 @@ import ChatProgramm.model.Server; import ChatProgramm.util.OhmLogger; import ChatProgramm.view.ChatView; import java.io.IOException; -import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JDialog; import javax.swing.JRadioButton; diff --git a/src/ChatProgramm/controller/commands/CommandInterface.java b/src/ChatProgramm/controller/commands/CommandInterface.java index 7f34a72..77bd988 100644 --- a/src/ChatProgramm/controller/commands/CommandInterface.java +++ b/src/ChatProgramm/controller/commands/CommandInterface.java @@ -13,6 +13,5 @@ public interface CommandInterface { public void execute(); public void undo(); -// public void redo(); public boolean isUndoable(); } diff --git a/src/ChatProgramm/model/Nachricht.java b/src/ChatProgramm/model/Nachricht.java index a830515..12a7270 100644 --- a/src/ChatProgramm/model/Nachricht.java +++ b/src/ChatProgramm/model/Nachricht.java @@ -11,34 +11,21 @@ package ChatProgramm.model; */ public class Nachricht { - private String nachricht; - //private int id; + private String nachricht; public Nachricht(String nachricht) { - this.nachricht = nachricht; - //this.id = id; - + this.nachricht = nachricht; } - + /** + * @return the nachricht + */ + public String getNachricht() { + return nachricht; + } - /** - * @return the id - */ -// public int getId() { -// return id; -// } - - /** - * @return the nachricht - */ - public String getNachricht() { - return nachricht; - } - - public void setNachricht(String nachricht) { - this.nachricht = nachricht; - } - + public void setNachricht(String nachricht) { + this.nachricht = nachricht; + } } \ No newline at end of file diff --git a/src/ChatProgramm/model/Transmitter.java b/src/ChatProgramm/model/Transmitter.java index 63c2d00..92ccad9 100644 --- a/src/ChatProgramm/model/Transmitter.java +++ b/src/ChatProgramm/model/Transmitter.java @@ -13,7 +13,6 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; -import java.net.ServerSocket; import java.net.Socket; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -64,25 +63,25 @@ public abstract class Transmitter implements Runnable, Subscriber, Trans 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(); - InputStreamReader isr = new InputStreamReader(is, "UTF-8"); - OutputStreamWriter osr = new OutputStreamWriter(os, "UTF-8"); + InputStreamReader isr = new InputStreamReader(is, "UTF-8"); + OutputStreamWriter osr = new OutputStreamWriter(os, "UTF-8"); - reader = new BufferedReader(isr); - writer = new PrintWriter(osr); - lg.info("Reader / Writer Initialisierung abgeschlossen"); - startempfangen(); - lg.info("Warte auf Nachricht"); + reader = new BufferedReader(isr); + writer = new PrintWriter(osr); + lg.info("Reader / Writer Initialisierung abgeschlossen"); + startempfangen(); + lg.info("Warte auf Nachricht"); - } 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); - } + } 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); + } } public void send(Nachricht nachricht){ @@ -91,54 +90,43 @@ public abstract class Transmitter implements Runnable, Subscriber, Trans writer.flush(); lg.info("Nachricht gesendet"); textPublisher.submit(nachricht); -// -// String nachricht = in.readLine(); // ACHTUNG blockiert -// lg.info("Client: Serverbestätigung erhalten"); -// -// lg.info("Client: fertig"); -// in.close(); -// out.close(); -// s.close(); - + } + public Nachricht receive(){ + Nachricht nachricht = new Nachricht(""); + try { + String txtNachricht = reader.readLine(); + if(!txtNachricht.isEmpty()){ + lg.info("Nachricht erhalten"); + nachricht.setNachricht("Er / Sie: " + txtNachricht); + return nachricht; + } + } catch (IOException e) { + throw new RuntimeException(e); + } + return nachricht; + } + +// public void disconnect (){ // in.close(); // out.close(); // s.close(); - } - public Nachricht receive(){ - Nachricht nachricht = new Nachricht(""); - try { - String txtNachricht = reader.readLine(); - if(!txtNachricht.isEmpty()){ - lg.info("Nachricht erhalten"); - nachricht.setNachricht("Er / Sie: " + txtNachricht); - return nachricht; - } - - } catch (IOException e) { - throw new RuntimeException(e); - } - - - return nachricht; - } +// } @Override public void run() { - while (true) { - lg.info("Warte auf Nachricht"); - if(laufend) { - Nachricht eingehendeNachricht = receive(); - - if(!eingehendeNachricht.getNachricht().isEmpty()){ - textPublisher.submit(eingehendeNachricht); - } - - } - else{ - break; - } + while (true) { + lg.info("Warte auf Nachricht"); + if(laufend) { + Nachricht eingehendeNachricht = receive(); + if(!eingehendeNachricht.getNachricht().isEmpty()){ + textPublisher.submit(eingehendeNachricht); + } } + else{ + break; + } + } } @@ -164,18 +152,13 @@ public abstract class Transmitter implements Runnable, Subscriber, Trans private void startempfangen() { - synchronized (this){ - laufend = true; - } - - if (eService == null){ - eService = Executors.newSingleThreadExecutor(); - eService.execute(this); - } - - lg.info("Starte Chat"); - - + synchronized (this){ + laufend = true; + } + if (eService == null){ + eService = Executors.newSingleThreadExecutor(); + eService.execute(this); + } + lg.info("Starte Chat"); } - }