4 Commits
9 changed files with 75 additions and 93 deletions

No files matched your search

+6 -3
View File
@@ -25,11 +25,14 @@ public class Start
ChatView view = new ChatView();
GrafikView zeichenflaeche = view.getGvZeichenflaeche();
zeichenflaeche.setModel(model);
GrafikController controller = new GrafikController(zeichenflaeche, model);
controller.registerEvents();
CommandController controller_commands = new CommandController(view, model, controller, zeichenflaeche);
CommandController controller_commands = new CommandController(view, model);
controller_commands.registerEvents();
controller_commands.registerCommands();
GrafikController controller = new GrafikController(zeichenflaeche, model, controller_commands);
controller.registerEvents();
view.setVisible(true);
}
@@ -10,7 +10,6 @@ import ChatProgramm.controller.commands.CommandInvoker;
import ChatProgramm.controller.commands.CommandSend;
import ChatProgramm.model.GrafikModel;
import ChatProgramm.view.ChatView;
import ChatProgramm.view.GrafikView;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@@ -23,16 +22,12 @@ public class CommandController implements ActionListener{
private ChatView view;
private GrafikModel model;
private GrafikView gView;
private CommandInvoker invoker;
private GrafikController controller;
public CommandController(ChatView view, GrafikModel model, GrafikController controller, GrafikView gView){
public CommandController(ChatView view, GrafikModel model){
this.view = view;
this.model = model;
this.gView = gView;
this.invoker = new CommandInvoker();
this.controller = controller;
}
public void registerEvents(){
@@ -43,8 +38,8 @@ public CommandController(ChatView view, GrafikModel model, GrafikController cont
public void registerCommands(){
CommandSend commandSend = new CommandSend(view.getGvZeichenflaeche(), model);
invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend, model, gView));
this.controller.setCommand(commandSend);
invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend));
//invoker.addCommand(view.getTfNachricht(), commandSend);
}
/**
@@ -55,11 +50,11 @@ public CommandController(ChatView view, GrafikModel model, GrafikController cont
public void actionPerformed(ActionEvent e) {
Component key = (Component)e.getSource();
invoker.executeCommand(key);
// if(key == view.getBtnOpen()|| key==view.getMiOpen())
// invoker.deleteStack();
// }
}
}
@@ -23,15 +23,11 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
private GrafikModel model;
private CommandSend commandSend;
public GrafikController(GrafikView view, GrafikModel model)
public GrafikController(GrafikView view, GrafikModel model, CommandController controller_commands)
{
this.view = view;
this.model = model;
commandSend = null;
}
void setCommand(CommandSend command){
this.commandSend = command;
commandSend = new CommandSend(view, model);
}
public void registerEvents()
@@ -47,7 +43,7 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
{
Point p = evt.getPoint();
model.addPoint(p);
view.drawPoint();
view.drawPoint(p);
}
@Override
@@ -59,9 +55,10 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
public void mouseReleased(MouseEvent evt)
{
model.endShape();
if(commandSend != null){
commandSend.execute();
}
commandSend.execute();
// if (evt.getButton() == MouseEvent.BUTTON3)
// {
// view.doPrint();
// }
}
}
@@ -6,11 +6,9 @@
package ChatProgramm.controller.commands;
import ChatProgramm.model.Client;
import ChatProgramm.model.GrafikModel;
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;
@@ -22,29 +20,24 @@ import javax.swing.JRadioButton;
*/
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 GrafikModel model;
private GrafikView gView;
private JRadioButton rBtnServer;
private JRadioButton rBtnClient;
private JDialog dialogFenster;
private static Logger lg = OhmLogger.getLogger();
private CommandSend commandSend;
private ChatView view;
public CommandConnect(ChatView view, CommandInterface value, GrafikModel model, GrafikView gView)
public CommandConnect(ChatView view, CommandInterface value)
{
rBtnServer = view.getBtnServer();
rBtnClient = view.getBtnClient();
dialogFenster = view.getjDialog1();
rBtnServer = view.getBtnServer();
rBtnClient = view.getBtnClient();
dialogFenster = view.getjDialog1();
commandSend = (CommandSend) value;
commandSend = (CommandSend) value;
this.view = view;
this.model = model;
this.gView = gView;
this.view = view;
}
@Override
public void execute()
{
@@ -14,6 +14,7 @@ import ChatProgramm.util.OhmLogger;
import ChatProgramm.view.ChatView;
import java.util.logging.Logger;
import javax.swing.JTextField;
import ChatProgramm.model.Nachricht;
import ChatProgramm.view.GrafikView;
/**
@@ -31,6 +32,9 @@ public class CommandSend implements CommandInterface
public Server server;
public Client client;
public CommandSend(GrafikView view, GrafikModel model)
{
this.view = view;
@@ -82,4 +86,4 @@ public class CommandSend implements CommandInterface
lg.info("der transmitter kommt hier als null an");
}
}
}
}
-5
View File
@@ -96,11 +96,6 @@ public class GrafikModel
figuren.add(aktuelleFigur);
aktuelleFigur = new Figur();
}
public void setFigur(Figur figur){
aktuelleFigur = figur;
figuren.add(figur);
}
/**
* Bestimmt die Adresse des zuletzt besuchten Ordners
+8 -18
View File
@@ -4,33 +4,21 @@
*/
package ChatProgramm.model;
import ChatProgramm.util.OhmLogger;
import ChatProgramm.view.ChatView;
import ChatProgramm.view.GrafikView;
import java.util.concurrent.Flow;
import java.util.concurrent.Flow.Subscriber;
import java.util.logging.Logger;
/**
*
* @author ahren
*/
public class ReceiveAdapter implements Subscriber<Figur> {
private static Logger lg = OhmLogger.getLogger();
private ChatView view;
private GrafikModel model;
private GrafikView gView;
private Flow.Subscription subscription;
public ReceiveAdapter(ChatView view, GrafikModel model, GrafikView gView) {
public ReceiveAdapter(ChatView view) {
this.view = view;
this.model = model;
this.gView = gView;
}
@Override
@@ -39,11 +27,9 @@ public class ReceiveAdapter implements Subscriber<Figur> {
this.subscription.request(1);
}
public void onNext(Figur item) {
public void onNext(Nachricht item) {
lg.info("Figur wurde dem Grafikmodel hinzugefügt");
model.setFigur(item);
gView.drawFigur();
//ToDo: hier muss der gFrame aufgerufen werden
// evtl muss die Figur aber zuerst serialisiert werden
//view.getTxtChat().append(item.getNachricht());
this.subscription.request(1);
@@ -57,4 +43,8 @@ public class ReceiveAdapter implements Subscriber<Figur> {
public void onComplete(){
}
}
@Override
public void onNext(Figur item)
{
}
}
+28 -14
View File
@@ -5,7 +5,6 @@
package ChatProgramm.model;
import ChatProgramm.view.ChatView;
import ChatProgramm.view.GrafikView;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
@@ -31,7 +30,7 @@ import java.util.logging.Logger;
*
* @author ahren
*/
public abstract class Transmitter implements Runnable, Subscriber<String>, TransmitterInterface {
public abstract class Transmitter implements Runnable, Subscriber<Figur>, TransmitterInterface {
static final int timeout = 60000;
private static final int PORT = 35000;
@@ -49,16 +48,13 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
private ExecutorService eService;
private String receivedString;
private ChatView view;
private GrafikView gView;
private GrafikModel model;
private ReceiveAdapter receiveAdapter;
public Transmitter(ChatView view)
{
socket = new Socket();
eService = null;
receiveAdapter = new ReceiveAdapter(view, model, gView);
receiveAdapter = new ReceiveAdapter(view);
figurPublisher = new SubmissionPublisher<>();
this.view = view;
addWertSubscription(receiveAdapter);
@@ -77,11 +73,14 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
lg.info("Initialisiere reader und writer");
InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream();
// Bruh im ernst mann muss zuerst den writer und dann den reader initialisieren
// andersrum ist das blockierend weil die Streams von hinten nach vorne
// gelesen werden
writer = new ObjectOutputStream(os);
writer.flush();
reader = new ObjectInputStream(is);
lg.info("Reader / Writer Initialisierung abgeschlossen");
startempfangen();
lg.info("Warte auf Nachricht");
@@ -113,12 +112,27 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
figurPublisher.submit(figur);
}
public Figur receive(){
Object receivedObject;
Object receivedObject;
try {
receivedObject = reader.readObject();
if (receivedObject instanceof Figur) {
Figur receivedFigur = (Figur) receivedObject;
// Verarbeiten Sie die empfangene Figur
}
} 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);
}
try {
receivedObject = reader.readObject();
if(receivedObject instanceof Figur){
lg.info("Figur erhalten");
figur = (Figur) receivedObject;
figur = (Figur) reader.readObject();
if(!txtNachricht.isEmpty()){
lg.info("Nachricht erhalten");
return figur;
}
} catch (IOException e) {
@@ -160,7 +174,7 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
}
@Override
public void onNext(String item) {
public void onNext(Figur item) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
+2 -11
View File
@@ -58,23 +58,14 @@ public class GrafikView extends JComponent implements Printable
* Zeichnet den aktuellen Pfad (solange die maus gedrückt gehalten wird)
* @param p -> Der aktuelle punkt als x-y-Koordinate
*/
public void drawFigur()
{
Graphics2D g2 = (Graphics2D)this.getGraphics(); // gefährlich!
drawPath(model.getFiguren().getLast().getPunkte(),g2);
g2.dispose(); //SEEEEHHHHRRRR WICHTIG!!!!!!!
}
public void drawPoint()
public void drawPoint(Point p)
{
Graphics2D g2 = (Graphics2D)this.getGraphics(); // gefährlich!
drawPath(model.getPunkte(),g2);
g2.dispose(); //SEEEEHHHHRRRR WICHTIG!!!!!!!
g2.dispose(); //SEEEEHHHHRRRR WICHTIG!!!!!!!
}
/**