bisschen aufgeräumt
This commit is contained in:
parent
e617b11f86
commit
de596fad8c
@ -18,9 +18,7 @@ public class Start
|
|||||||
{
|
{
|
||||||
public Start()
|
public Start()
|
||||||
{
|
{
|
||||||
//Transmitter transmitter = new Transmitter();
|
|
||||||
ChatView view = new ChatView();
|
ChatView view = new ChatView();
|
||||||
//CommandController controller_commands = new CommandController(view, transmitter);
|
|
||||||
CommandController controller_commands = new CommandController(view);
|
CommandController controller_commands = new CommandController(view);
|
||||||
controller_commands.registerEvents();
|
controller_commands.registerEvents();
|
||||||
controller_commands.registerCommands();
|
controller_commands.registerCommands();
|
||||||
|
@ -8,9 +8,6 @@ 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.Client;
|
|
||||||
import ChatProgramm.model.Server;
|
|
||||||
import ChatProgramm.model.Transmitter;
|
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
@ -23,15 +20,8 @@ import java.awt.event.ActionListener;
|
|||||||
public class CommandController implements ActionListener{
|
public class CommandController implements ActionListener{
|
||||||
|
|
||||||
private ChatView view;
|
private ChatView view;
|
||||||
//private Transmitter transmitter;
|
|
||||||
private CommandInvoker invoker;
|
private CommandInvoker invoker;
|
||||||
|
|
||||||
// public CommandController(ChatView view, Transmitter transmitter){
|
|
||||||
// this.view = view;
|
|
||||||
// this.transmitter = transmitter;
|
|
||||||
// this.invoker = new CommandInvoker();
|
|
||||||
// }
|
|
||||||
|
|
||||||
public CommandController(ChatView view){
|
public CommandController(ChatView view){
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.invoker = new CommandInvoker();
|
this.invoker = new CommandInvoker();
|
||||||
|
@ -10,7 +10,6 @@ import ChatProgramm.model.Server;
|
|||||||
import ChatProgramm.util.OhmLogger;
|
import ChatProgramm.util.OhmLogger;
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.logging.Level;
|
|
||||||
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;
|
||||||
|
@ -13,6 +13,5 @@ public interface CommandInterface
|
|||||||
{
|
{
|
||||||
public void execute();
|
public void execute();
|
||||||
public void undo();
|
public void undo();
|
||||||
// public void redo();
|
|
||||||
public boolean isUndoable();
|
public boolean isUndoable();
|
||||||
}
|
}
|
||||||
|
@ -11,34 +11,21 @@ package ChatProgramm.model;
|
|||||||
*/
|
*/
|
||||||
public class Nachricht
|
public class Nachricht
|
||||||
{
|
{
|
||||||
private String nachricht;
|
private String nachricht;
|
||||||
//private int id;
|
|
||||||
|
|
||||||
public Nachricht(String nachricht)
|
public Nachricht(String nachricht)
|
||||||
{
|
{
|
||||||
this.nachricht = nachricht;
|
this.nachricht = nachricht;
|
||||||
//this.id = id;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the nachricht
|
||||||
|
*/
|
||||||
|
public String getNachricht() {
|
||||||
|
return nachricht;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public void setNachricht(String nachricht) {
|
||||||
* @return the id
|
this.nachricht = nachricht;
|
||||||
*/
|
}
|
||||||
// public int getId() {
|
|
||||||
// return id;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the nachricht
|
|
||||||
*/
|
|
||||||
public String getNachricht() {
|
|
||||||
return nachricht;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNachricht(String nachricht) {
|
|
||||||
this.nachricht = nachricht;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -13,7 +13,6 @@ import java.io.OutputStream;
|
|||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.ServerSocket;
|
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
@ -64,25 +63,25 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
|||||||
public abstract void connect() throws IOException;
|
public abstract void connect() throws IOException;
|
||||||
|
|
||||||
public void initIO() {
|
public void initIO() {
|
||||||
try {
|
try {
|
||||||
lg.info("Initialisiere reader und writer");
|
lg.info("Initialisiere reader und writer");
|
||||||
InputStream is = socket.getInputStream();
|
InputStream is = socket.getInputStream();
|
||||||
OutputStream os = socket.getOutputStream();
|
OutputStream os = socket.getOutputStream();
|
||||||
|
|
||||||
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
|
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
|
||||||
OutputStreamWriter osr = new OutputStreamWriter(os, "UTF-8");
|
OutputStreamWriter osr = new OutputStreamWriter(os, "UTF-8");
|
||||||
|
|
||||||
reader = new BufferedReader(isr);
|
reader = new BufferedReader(isr);
|
||||||
writer = new PrintWriter(osr);
|
writer = new PrintWriter(osr);
|
||||||
lg.info("Reader / Writer Initialisierung abgeschlossen");
|
lg.info("Reader / Writer Initialisierung abgeschlossen");
|
||||||
startempfangen();
|
startempfangen();
|
||||||
lg.info("Warte auf Nachricht");
|
lg.info("Warte auf Nachricht");
|
||||||
|
|
||||||
} catch (UnsupportedEncodingException ex) {
|
} catch (UnsupportedEncodingException ex) {
|
||||||
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
} 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(Nachricht nachricht){
|
public void send(Nachricht nachricht){
|
||||||
@ -91,54 +90,43 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
|||||||
writer.flush();
|
writer.flush();
|
||||||
lg.info("Nachricht gesendet");
|
lg.info("Nachricht gesendet");
|
||||||
textPublisher.submit(nachricht);
|
textPublisher.submit(nachricht);
|
||||||
//
|
}
|
||||||
// String nachricht = in.readLine(); // ACHTUNG blockiert
|
public Nachricht receive(){
|
||||||
// lg.info("Client: Serverbestätigung erhalten");
|
Nachricht nachricht = new Nachricht("");
|
||||||
//
|
try {
|
||||||
// lg.info("Client: fertig");
|
String txtNachricht = reader.readLine();
|
||||||
// in.close();
|
if(!txtNachricht.isEmpty()){
|
||||||
// out.close();
|
lg.info("Nachricht erhalten");
|
||||||
// s.close();
|
nachricht.setNachricht("Er / Sie: " + txtNachricht);
|
||||||
|
return nachricht;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return nachricht;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public void disconnect (){
|
||||||
// in.close();
|
// in.close();
|
||||||
// out.close();
|
// out.close();
|
||||||
// s.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
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (true) {
|
while (true) {
|
||||||
lg.info("Warte auf Nachricht");
|
lg.info("Warte auf Nachricht");
|
||||||
if(laufend) {
|
if(laufend) {
|
||||||
Nachricht eingehendeNachricht = receive();
|
Nachricht eingehendeNachricht = receive();
|
||||||
|
if(!eingehendeNachricht.getNachricht().isEmpty()){
|
||||||
if(!eingehendeNachricht.getNachricht().isEmpty()){
|
textPublisher.submit(eingehendeNachricht);
|
||||||
textPublisher.submit(eingehendeNachricht);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -164,18 +152,13 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
|||||||
|
|
||||||
private void startempfangen()
|
private void startempfangen()
|
||||||
{
|
{
|
||||||
synchronized (this){
|
synchronized (this){
|
||||||
laufend = true;
|
laufend = true;
|
||||||
}
|
}
|
||||||
|
if (eService == null){
|
||||||
if (eService == null){
|
eService = Executors.newSingleThreadExecutor();
|
||||||
eService = Executors.newSingleThreadExecutor();
|
eService.execute(this);
|
||||||
eService.execute(this);
|
}
|
||||||
}
|
lg.info("Starte Chat");
|
||||||
|
|
||||||
lg.info("Starte Chat");
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user