Browse Source

Neue Architektur nach Lehner UML aufgesetzt .> draft

JensV2
Jens Schuhmann 1 year ago
parent
commit
75e458a4ac

+ 19
- 8
src/ChatProgramm/Start.java View File

@@ -7,7 +7,9 @@ package ChatProgramm;

import ChatProgramm.controller.CommandController;
import ChatProgramm.controller.GrafikController;
import ChatProgramm.model.GrafikModel;
import ChatProgramm.model.ChatModel;
import ChatProgramm.model.GrafikDaten;
import ChatProgramm.model.ReceiveAdapter;
import ChatProgramm.view.ChatView;
import ChatProgramm.view.GrafikView;
import javax.swing.JOptionPane;
@@ -21,17 +23,26 @@ public class Start
{
public Start()
{
GrafikModel model = new GrafikModel();
GrafikDaten gDaten = new GrafikDaten();
ChatView view = new ChatView();
GrafikView zeichenflaeche = view.getGvZeichenflaeche();
zeichenflaeche.setModel(model);
zeichenflaeche.setModel(gDaten);
GrafikController controller = new GrafikController(zeichenflaeche, model);
controller.registerEvents();
ChatModel model = new ChatModel(gDaten);
CommandController controller_commands = new CommandController(view, model, controller, zeichenflaeche);
controller_commands.registerEvents();
controller_commands.registerCommands();
ReceiveAdapter rAdapter = new ReceiveAdapter(view, model);
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();

+ 3
- 3
src/ChatProgramm/controller/CommandController.java View File

@@ -8,7 +8,7 @@ package ChatProgramm.controller;
import ChatProgramm.controller.commands.CommandConnect;
import ChatProgramm.controller.commands.CommandInvoker;
import ChatProgramm.controller.commands.CommandSend;
import ChatProgramm.model.GrafikModel;
import ChatProgramm.model.GrafikDaten;
import ChatProgramm.view.ChatView;
import ChatProgramm.view.GrafikView;
import java.awt.Component;
@@ -22,12 +22,12 @@ import java.awt.event.ActionListener;
public class CommandController implements ActionListener{
private ChatView view;
private GrafikModel model;
private GrafikDaten model;
private GrafikView gView;
private CommandInvoker invoker;
private GrafikController controller;
public CommandController(ChatView view, GrafikModel model, GrafikController controller, GrafikView gView){
public CommandController(ChatView view, GrafikDaten model, GrafikController controller, GrafikView gView){
this.view = view;
this.model = model;
this.gView = gView;

+ 3
- 3
src/ChatProgramm/controller/GrafikController.java View File

@@ -10,7 +10,7 @@ import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import ChatProgramm.model.GrafikModel;
import ChatProgramm.model.GrafikDaten;
import ChatProgramm.view.GrafikView;

/**
@@ -20,10 +20,10 @@ import ChatProgramm.view.GrafikView;
public class GrafikController extends MouseAdapter implements MouseMotionListener
{
private GrafikView view;
private GrafikModel model;
private GrafikDaten model;
private CommandSend commandSend;
public GrafikController(GrafikView view, GrafikModel model)
public GrafikController(GrafikView view, GrafikDaten model)
{
this.view = view;
this.model = model;

+ 3
- 3
src/ChatProgramm/controller/commands/CommandConnect.java View File

@@ -6,7 +6,7 @@
package ChatProgramm.controller.commands;

import ChatProgramm.model.Client;
import ChatProgramm.model.GrafikModel;
import ChatProgramm.model.GrafikDaten;
import ChatProgramm.model.Server;
import ChatProgramm.util.OhmLogger;
import ChatProgramm.view.ChatView;
@@ -28,10 +28,10 @@ public class CommandConnect implements CommandInterface
private static Logger lg = OhmLogger.getLogger();
private CommandSend commandSend;
private ChatView view;
private GrafikModel model;
private GrafikDaten model;
private GrafikView gView;
public CommandConnect(ChatView view, CommandInterface value, GrafikModel model, GrafikView gView)
public CommandConnect(ChatView view, CommandInterface value, GrafikDaten model, GrafikView gView)
{
rBtnServer = view.getBtnServer();
rBtnClient = view.getBtnClient();

+ 60
- 0
src/ChatProgramm/controller/commands/CommandConnectV2.java View File

@@ -0,0 +1,60 @@
/*
* 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.ChatModel;
import ChatProgramm.model.Client;
import ChatProgramm.model.Server;
import ChatProgramm.util.OhmLogger;
import ChatProgramm.view.ChatView;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.logging.Logger;

/**
*
* @author Js-Sc
*/
public class CommandConnectV2 implements ActionListener {

private static Logger lg = OhmLogger.getLogger();
private ChatView view;
private ChatModel model;

public CommandConnectV2(ChatView view, ChatModel model) {
this.view = view;
this.model = model;
}

public void registerEvents() {
view.getBtnConnect().addActionListener(this);
}

@Override
public void actionPerformed(ActionEvent e) {
if (view.getBtnClient().isSelected()) {
lg.info("Server ausgewählt");
try {
model.setTransmitter(new Server(view, model));
} catch (IOException ex) {
lg.info("Die Verbindung zum Server ist Fehlgeschlagen");
}
}

if (view.getBtnServer().isSelected()) {
lg.info("Client ausgewählt");
try {
model.setTransmitter(new Client(view, model));
} catch (IOException ex) {
lg.info("Die Verbindung zum Client ist Fehlgeschlagen");

}
}

view.getjDialog1().setVisible(false);
}

}

+ 3
- 3
src/ChatProgramm/controller/commands/CommandSend.java View File

@@ -7,7 +7,7 @@ package ChatProgramm.controller.commands;

import ChatProgramm.model.Client;
import ChatProgramm.model.Figur;
import ChatProgramm.model.GrafikModel;
import ChatProgramm.model.GrafikDaten;
import ChatProgramm.model.Server;
import ChatProgramm.model.TransmitterInterface;
import ChatProgramm.util.OhmLogger;
@@ -25,7 +25,7 @@ public class CommandSend implements CommandInterface
private static Logger lg = OhmLogger.getLogger();
private GrafikView view;
private GrafikModel model;
private GrafikDaten model;
public TransmitterInterface transmitterInterface;
public Server server;
@@ -34,7 +34,7 @@ public class CommandSend implements CommandInterface

public CommandSend(GrafikView view, GrafikModel model)
public CommandSend(GrafikView view, GrafikDaten model)
{
this.view = view;
this.model = model;

+ 71
- 0
src/ChatProgramm/model/ChatModel.java View File

@@ -0,0 +1,71 @@
/*
* 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.model;

import ChatProgramm.controller.GrafikController;
import ChatProgramm.controller.commands.CommandConnect;
import ChatProgramm.controller.commands.CommandSend;
import ChatProgramm.util.OhmLogger;
import java.util.concurrent.Flow;
import java.util.concurrent.Flow.Subscriber;
import java.util.concurrent.SubmissionPublisher;
import java.util.logging.Logger;

/**
*
* @author Js-Sc
*/
public class ChatModel implements Subscriber<Figur> {

private static Logger lg = OhmLogger.getLogger();
private SubmissionPublisher<Figur> figurPublisher;

private Transmitter transmitter;
private GrafikDaten grafikDaten;
private CommandConnect cConnect;
private CommandSend cSend;
private ReceiveAdapter rAdapter;
private GrafikController gController;
public ChatModel(GrafikDaten gDaten) {
this.grafikDaten = gDaten;
this.transmitter = null;
this.figurPublisher = new SubmissionPublisher<>();
}
public void setTransmitter(Transmitter transmitter)
{
this.transmitter = transmitter;
}


public void addSubscription(Subscriber<Figur> subscriber) {
figurPublisher.subscribe(subscriber);
}

@Override
public void onSubscribe(Flow.Subscription subscription) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public void onNext(Figur item) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public void onError(Throwable throwable) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public void onComplete() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

}

+ 2
- 2
src/ChatProgramm/model/Client.java View File

@@ -23,8 +23,8 @@ public class Client extends Transmitter {
private static final String IP = "127.0.0.1";

public Client(ChatView view, GrafikModel model, GrafikView gView) throws IOException {
super(view, model, gView);
public Client(ChatView view, ChatModel model) throws IOException {
super(view, model);
connect();
initIO();
}

src/ChatProgramm/model/GrafikModel.java → src/ChatProgramm/model/GrafikDaten.java View File

@@ -24,14 +24,14 @@ import ChatProgramm.util.OhmLogger;
*
* @author le
*/
public class GrafikModel {
public class GrafikDaten {

private Figur aktuelleFigur;
private ArrayList<Figur> figuren;
private Preferences pref;
private static Logger lg = OhmLogger.getLogger();

public GrafikModel() {
public GrafikDaten() {
aktuelleFigur = new Figur();
figuren = new ArrayList<>();
}

+ 6
- 9
src/ChatProgramm/model/ReceiveAdapter.java View File

@@ -20,16 +20,13 @@ public class ReceiveAdapter implements Subscriber<Figur> {
private static Logger lg = OhmLogger.getLogger();

private ChatView view;
private GrafikModel model;
private GrafikView gView;
private ChatModel model;
private Flow.Subscription subscription;

public ReceiveAdapter(ChatView view, GrafikModel model, GrafikView gView) {
public ReceiveAdapter(ChatView view, ChatModel model) {
this.view = view;
this.model = model;
this.gView = gView;
this.model = model;
}

@Override
@@ -39,8 +36,8 @@ public class ReceiveAdapter implements Subscriber<Figur> {
}

public void onNext(Figur item) {
model.addFigure(item);
gView.drawFigur();
// model.addFigure(item);
// gView.drawFigur();
lg.info("Figur wurde dem Grafikmodel hinzugefügt");
this.subscription.request(1);

+ 2
- 2
src/ChatProgramm/model/Server.java View File

@@ -21,8 +21,8 @@ public class Server extends Transmitter
private static Logger lg = OhmLogger.getLogger();
private static final int PORT = 35000; //lt. iana port > 2¹⁵
public Server(ChatView view, GrafikModel model, GrafikView gView) throws IOException {
super(view, model, gView);
public Server(ChatView view, ChatModel model) throws IOException {
super(view, model);
connect();
initIO();
}

+ 23
- 18
src/ChatProgramm/model/Transmitter.java View File

@@ -4,6 +4,7 @@
*/
package ChatProgramm.model;

import ChatProgramm.util.OhmLogger;
import ChatProgramm.view.ChatView;
import ChatProgramm.view.GrafikView;
import java.io.BufferedInputStream;
@@ -31,37 +32,41 @@ import java.util.logging.Logger;
*
* @author ahren
*/
public abstract class Transmitter implements Runnable, Subscriber<Figur>, TransmitterInterface {
public abstract class Transmitter implements Runnable, Subscriber<Figur>{

static final int timeout = 60000;
private static final int PORT = 35000;

private static Logger lg = Logger.getLogger("netz");
private static Logger lg = OhmLogger.getLogger();

protected Socket socket;
protected ObjectInputStream reader;
protected ObjectOutputStream writer;
private Figur figur;
private SubmissionPublisher<Figur> figurPublisher;
private ExecutorService eService;
private String receivedString;

private ChatView view;
private GrafikModel model;
private ChatModel model;
private ReceiveAdapter receiveAdapter;
public Transmitter(ChatView view, GrafikModel model, GrafikView gView)
public Transmitter(ChatView view, ChatModel model)
{
socket = new Socket();
eService = null;
receiveAdapter = new ReceiveAdapter(view, model, gView);
figurPublisher = new SubmissionPublisher<>();
this.view = view;
addWertSubscription(receiveAdapter);
figur = new Figur();
this.model = model;
}
public void addWertSubscription(Subscriber<Figur> subscriber)
public void addSubscription(Subscriber<Figur> subscriber)
{
figurPublisher.subscribe(subscriber);
}
@@ -93,7 +98,6 @@ public abstract class Transmitter implements Runnable, Subscriber<Figur>, Transm
* @param figur
* @throws IOException
*/
@Override
public void send(Figur figur){
try
{
@@ -110,21 +114,22 @@ public abstract class Transmitter implements Runnable, Subscriber<Figur>, Transm
public Figur receive(){
Object receivedObject;
Figur figur = new Figur();
try {
receivedObject = reader.readObject();
if (receivedObject instanceof Figur) {
lg.info("Figur erhalten");
figur = (Figur) receivedObject;
figur = (Figur) receivedObject;
}
} 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);
}
return figur;


return figur;
}

@@ -133,10 +138,10 @@ public abstract class Transmitter implements Runnable, Subscriber<Figur>, Transm
public void run() {
while (true) {
lg.info("Warte auf Nachricht");
figur = receive();
if(!figur.getPunkte().isEmpty()){
figurPublisher.submit(figur);
}
// figur = receive();
// if(!figur.getPunkte().isEmpty()){
// figurPublisher.submit(figur);
// }
}
}


+ 3
- 3
src/ChatProgramm/view/GrafikView.java View File

@@ -22,7 +22,7 @@ import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.standard.DialogTypeSelection;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import ChatProgramm.model.GrafikModel;
import ChatProgramm.model.GrafikDaten;
import ChatProgramm.util.OhmLogger;


@@ -36,7 +36,7 @@ public class GrafikView extends JComponent
private static Dimension EINS = new Dimension(1, 1); // Dimension ist eine Klasse die width udn height hält
private Rectangle2D.Float pixel;
private Line2D.Float line;
private GrafikModel model;
private GrafikDaten model;
private Point from = null;
private Point to = null;
@@ -47,7 +47,7 @@ public class GrafikView extends JComponent
line = new Line2D.Float();
}

public void setModel(GrafikModel model)
public void setModel(GrafikDaten model)
{
this.model = model;
}

Loading…
Cancel
Save