package ChatProgramm; | package ChatProgramm; | ||||
//import ChatProgramm.controller.CommandController; | |||||
import ChatProgramm.controller.GrafikController; | import ChatProgramm.controller.GrafikController; | ||||
import ChatProgramm.controller.commands.CommandConnectV2; | import ChatProgramm.controller.commands.CommandConnectV2; | ||||
import ChatProgramm.controller.commands.CommandSendV2; | 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.controller.ReceiveAdapter; | |||||
import ChatProgramm.view.ChatView; | import ChatProgramm.view.ChatView; | ||||
import ChatProgramm.view.GrafikView; | import ChatProgramm.view.GrafikView; | ||||
import javax.swing.JOptionPane; | import javax.swing.JOptionPane; | ||||
CommandSendV2 cSend = new CommandSendV2(view, model); | CommandSendV2 cSend = new CommandSendV2(view, model); | ||||
cSend.registerEvents(); | cSend.registerEvents(); | ||||
ReceiveAdapter rAdapter = new ReceiveAdapter(view, model); | ReceiveAdapter rAdapter = new ReceiveAdapter(view, model); | ||||
model.addSubscription(rAdapter); | model.addSubscription(rAdapter); | ||||
// | |||||
// | |||||
// GrafikController controller = new GrafikController(zeichenflaeche, model); | |||||
// controller.registerEvents(); | |||||
// | |||||
// CommandController controller_commands = new CommandController(view, model, controller, zeichenflaeche); | |||||
// controller_commands.registerEvents(); | |||||
// controller_commands.registerCommands(); | |||||
view.setVisible(true); | view.setVisible(true); | ||||
} | } |
///* | |||||
// * 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); | |||||
// | |||||
// } | |||||
// | |||||
//} | |||||
// | |||||
// |
package ChatProgramm.controller; | package ChatProgramm.controller; | ||||
//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.ChatModel; | ||||
import ChatProgramm.model.GrafikDaten; | |||||
import ChatProgramm.util.OhmLogger; | import ChatProgramm.util.OhmLogger; | ||||
import ChatProgramm.view.ChatView; | import ChatProgramm.view.ChatView; | ||||
import ChatProgramm.view.GrafikView; | |||||
import java.awt.*; | |||||
import java.awt.event.MouseAdapter; | |||||
import java.awt.event.MouseEvent; | |||||
import java.awt.event.MouseMotionListener; | |||||
import java.util.logging.Logger; | |||||
/** | /** | ||||
* | * | ||||
private static Logger lg = OhmLogger.getLogger(); | private static Logger lg = OhmLogger.getLogger(); | ||||
private ChatView view; | private ChatView view; | ||||
private ChatModel model; | private ChatModel model; | ||||
// private CommandSend commandSend; | |||||
public GrafikController(ChatView view, ChatModel model) | public GrafikController(ChatView view, ChatModel model) | ||||
{ | { | ||||
view.getGvZeichenflaeche().addMouseListener(this); | view.getGvZeichenflaeche().addMouseListener(this); | ||||
} | } | ||||
@Override | @Override | ||||
public void mouseDragged(MouseEvent evt) | public void mouseDragged(MouseEvent evt) | ||||
{ | { | ||||
view.getGvZeichenflaeche().drawPoint(); | view.getGvZeichenflaeche().drawPoint(); | ||||
} | } | ||||
@Override | |||||
public void mouseMoved(MouseEvent e) | |||||
{ | |||||
} | |||||
@Override | @Override | ||||
public void mouseReleased(MouseEvent evt) | public void mouseReleased(MouseEvent evt) | ||||
{ | { |
* 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.model; | |||||
package ChatProgramm.controller; | |||||
import ChatProgramm.model.ChatModel; | |||||
import ChatProgramm.model.Figur; | |||||
import ChatProgramm.util.OhmLogger; | import ChatProgramm.util.OhmLogger; | ||||
import ChatProgramm.view.ChatView; | import ChatProgramm.view.ChatView; | ||||
import ChatProgramm.view.GrafikView; | import ChatProgramm.view.GrafikView; |
///* | |||||
// * 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() | |||||
// { | |||||
// } | |||||
//} |
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 java.awt.event.ActionEvent; | import java.awt.event.ActionEvent; | ||||
import java.awt.event.ActionListener; | import java.awt.event.ActionListener; | ||||
import java.io.IOException; | import java.io.IOException; |
/* | |||||
* 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; | |||||
/** | |||||
* | |||||
* @author ahren | |||||
*/ | |||||
public interface CommandInterface | |||||
{ | |||||
public void execute(); | |||||
public void undo(); | |||||
public boolean isUndoable(); | |||||
} |
/* | |||||
* 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 java.awt.Component; | |||||
import java.util.HashMap; | |||||
import java.util.Stack; | |||||
/** | |||||
* | |||||
* @author ahren | |||||
*/ | |||||
public class CommandInvoker { | |||||
private HashMap<Component, CommandInterface> commands; | |||||
private Stack <CommandInterface> undoStack; | |||||
public CommandInvoker(){ | |||||
commands = new HashMap<>(); | |||||
undoStack = new Stack(); | |||||
} | |||||
/** | |||||
* Fügt ein Kommando zur Kommando-"Datenbank" = HashMap hinzu | |||||
* @param key Quelle des Events | |||||
* @param value Referenz auf das zugehörige Kommando-Objekt | |||||
*/ | |||||
public void addCommand(Component key, CommandInterface value){ | |||||
commands.put(key, value); | |||||
} | |||||
/** | |||||
* Führt Kommando der Eventquelle "key" aus und legt die Referenz | |||||
* des Kommando in den Undo-Stack | |||||
* @param key Referenz auf die Eventquelle | |||||
*/ | |||||
public void executeCommand(Component key){ | |||||
CommandInterface command = commands.get(key); | |||||
command.execute(); | |||||
if (command.isUndoable()) | |||||
{ | |||||
undoStack.push(command); | |||||
} | |||||
} | |||||
/** | |||||
* Falls der Stack Elemente enthält, wird das oberste Element geholt | |||||
* und die Methode "undo" des Commands aufgerufen | |||||
*/ | |||||
public void undoCommand() | |||||
{ | |||||
if (!undoStack.isEmpty()) | |||||
{ | |||||
undoStack.pop().undo(); | |||||
} | |||||
} | |||||
/** | |||||
* Löscht bei Öffnen einer neuen Datei den Stack | |||||
*/ | |||||
public void deleteStack() | |||||
{ | |||||
while(!undoStack.isEmpty()) | |||||
undoStack.pop(); | |||||
} | |||||
} |
///* | |||||
// * 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"); | |||||
// } | |||||
// } | |||||
//} |
package ChatProgramm.controller.commands; | package ChatProgramm.controller.commands; | ||||
import ChatProgramm.model.ChatModel; | import ChatProgramm.model.ChatModel; | ||||
import ChatProgramm.model.Client; | |||||
import ChatProgramm.model.Server; | |||||
import ChatProgramm.util.OhmLogger; | import ChatProgramm.util.OhmLogger; | ||||
import ChatProgramm.view.ChatView; | import ChatProgramm.view.ChatView; | ||||
import java.awt.event.*; | |||||
import java.io.IOException; | |||||
import java.awt.event.MouseAdapter; | |||||
import java.awt.event.MouseEvent; | |||||
import java.awt.event.MouseMotionListener; | |||||
import java.util.logging.Logger; | import java.util.logging.Logger; | ||||
/** | /** |
*/ | */ | ||||
package ChatProgramm.model; | package ChatProgramm.model; | ||||
import ChatProgramm.controller.GrafikController; | |||||
//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 ChatProgramm.util.OhmLogger; | ||||
import java.util.concurrent.Flow; | import java.util.concurrent.Flow; |
import ChatProgramm.util.OhmLogger; | import ChatProgramm.util.OhmLogger; | ||||
import ChatProgramm.view.ChatView; | import ChatProgramm.view.ChatView; | ||||
import ChatProgramm.view.GrafikView; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.net.Socket; | import java.net.Socket; | ||||
import java.util.logging.*; | |||||
import java.util.logging.Logger; | |||||
/** | /** | ||||
* Builder Class | * Builder Class |
*/ | */ | ||||
package ChatProgramm.model; | package ChatProgramm.model; | ||||
import java.awt.Point; | |||||
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 ChatProgramm.util.OhmLogger; | |||||
import java.awt.*; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Collections; | import java.util.Collections; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.logging.Logger; | import java.util.logging.Logger; | ||||
import java.util.prefs.Preferences; | import java.util.prefs.Preferences; | ||||
import ChatProgramm.util.OhmLogger; | |||||
/** | /** | ||||
* | * |
import ChatProgramm.util.OhmLogger; | import ChatProgramm.util.OhmLogger; | ||||
import ChatProgramm.view.ChatView; | import ChatProgramm.view.ChatView; | ||||
import ChatProgramm.view.GrafikView; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.net.ServerSocket; | import java.net.ServerSocket; | ||||
import java.util.logging.*; | |||||
import java.util.logging.Logger; | |||||
/** | /** | ||||
* Builder Class | * Builder Class |
*/ | */ | ||||
package ChatProgramm.model; | package ChatProgramm.model; | ||||
import ChatProgramm.controller.ReceiveAdapter; | |||||
import ChatProgramm.util.OhmLogger; | import ChatProgramm.util.OhmLogger; | ||||
import ChatProgramm.view.ChatView; | import ChatProgramm.view.ChatView; | ||||
import ChatProgramm.view.GrafikView; | |||||
import java.io.BufferedInputStream; | |||||
import java.io.BufferedOutputStream; | |||||
import java.io.BufferedReader; | |||||
import java.io.IOException; | |||||
import java.io.InputStream; | |||||
import java.io.InputStreamReader; | |||||
import java.io.ObjectInputStream; | |||||
import java.io.ObjectOutputStream; | |||||
import java.io.OutputStream; | |||||
import java.io.OutputStreamWriter; | |||||
import java.io.PrintWriter; | |||||
import java.io.UnsupportedEncodingException; | |||||
import java.io.*; | |||||
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; | ||||
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.Level; | import java.util.logging.Level; | ||||
lg.info("Reader / Writer Initialisierung abgeschlossen"); | lg.info("Reader / Writer Initialisierung abgeschlossen"); | ||||
startempfangen(); | startempfangen(); | ||||
} catch (UnsupportedEncodingException 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); | ||||
} | } |
/* | |||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license | |||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template | |||||
*/ | |||||
package ChatProgramm.model; | |||||
/** | |||||
* | |||||
* @author ahren | |||||
*/ | |||||
public interface TransmitterInterface | |||||
{ | |||||
public void send(Figur figur); | |||||
public Figur receive(); | |||||
} |