Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
68eb43c715 | ||
|
|
541b497796 | ||
|
|
43de325d71 | ||
|
|
0e71917727 | ||
|
|
dc1f783e00 | ||
|
|
2fc05ae87f | ||
|
|
5117ecdb6f | ||
|
|
a4a45ed5f2 | ||
|
|
6642dc8179 | ||
|
|
f05b0f0014 | ||
|
|
1aa5b51e78 |
@@ -25,11 +25,17 @@ public class Start
|
|||||||
ChatView view = new ChatView();
|
ChatView view = new ChatView();
|
||||||
GrafikView zeichenflaeche = view.getGvZeichenflaeche();
|
GrafikView zeichenflaeche = view.getGvZeichenflaeche();
|
||||||
zeichenflaeche.setModel(model);
|
zeichenflaeche.setModel(model);
|
||||||
|
|
||||||
GrafikController controller = new GrafikController(zeichenflaeche, model);
|
GrafikController controller = new GrafikController(zeichenflaeche, model);
|
||||||
controller.registerEvents();
|
controller.registerEvents();
|
||||||
CommandController controller_commands = new CommandController(view);
|
|
||||||
|
CommandController controller_commands = new CommandController(view, model, controller, zeichenflaeche);
|
||||||
controller_commands.registerEvents();
|
controller_commands.registerEvents();
|
||||||
controller_commands.registerCommands();
|
controller_commands.registerCommands();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
view.setVisible(true);
|
view.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ 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.GrafikModel;
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
|
import ChatProgramm.view.GrafikView;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
@@ -20,23 +22,27 @@ import java.awt.event.ActionListener;
|
|||||||
public class CommandController implements ActionListener{
|
public class CommandController implements ActionListener{
|
||||||
|
|
||||||
private ChatView view;
|
private ChatView view;
|
||||||
|
private GrafikModel model;
|
||||||
|
private GrafikView gView;
|
||||||
private CommandInvoker invoker;
|
private CommandInvoker invoker;
|
||||||
|
private GrafikController controller;
|
||||||
|
|
||||||
public CommandController(ChatView view){
|
public CommandController(ChatView view, GrafikModel model, GrafikController controller, GrafikView gView){
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
this.model = model;
|
||||||
|
this.gView = gView;
|
||||||
this.invoker = new CommandInvoker();
|
this.invoker = new CommandInvoker();
|
||||||
|
this.controller = controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerEvents(){
|
public void registerEvents(){
|
||||||
view.getBtnConnect().addActionListener(this);
|
view.getBtnConnect().addActionListener(this);
|
||||||
//ToDo: muss auf gFrame referenzieren
|
|
||||||
//view.getTfNachricht().addActionListener(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerCommands(){
|
public void registerCommands(){
|
||||||
CommandSend commandSend = new CommandSend(view.getGvZeichenflaeche());
|
CommandSend commandSend = new CommandSend(view.getGvZeichenflaeche(), model);
|
||||||
invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend));
|
invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend, model, gView));
|
||||||
//invoker.addCommand(view.getTfNachricht(), commandSend);
|
this.controller.setCommand(commandSend);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,9 +53,7 @@ public class CommandController implements ActionListener{
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
Component key = (Component)e.getSource();
|
Component key = (Component)e.getSource();
|
||||||
invoker.executeCommand(key);
|
invoker.executeCommand(key);
|
||||||
// if(key == view.getBtnOpen()|| key==view.getMiOpen())
|
|
||||||
// invoker.deleteStack();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,11 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
|
|||||||
{
|
{
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.model = model;
|
this.model = model;
|
||||||
commandSend = new CommandSend(view);
|
commandSend = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setCommand(CommandSend command){
|
||||||
|
this.commandSend = command;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerEvents()
|
public void registerEvents()
|
||||||
@@ -43,7 +47,7 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
|
|||||||
{
|
{
|
||||||
Point p = evt.getPoint();
|
Point p = evt.getPoint();
|
||||||
model.addPoint(p);
|
model.addPoint(p);
|
||||||
view.drawPoint(p);
|
view.drawPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -55,10 +59,9 @@ public class GrafikController extends MouseAdapter implements MouseMotionListene
|
|||||||
public void mouseReleased(MouseEvent evt)
|
public void mouseReleased(MouseEvent evt)
|
||||||
{
|
{
|
||||||
model.endShape();
|
model.endShape();
|
||||||
commandSend.execute();
|
if(commandSend != null){
|
||||||
// if (evt.getButton() == MouseEvent.BUTTON3)
|
commandSend.execute();
|
||||||
// {
|
}
|
||||||
// view.doPrint();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,11 @@
|
|||||||
package ChatProgramm.controller.commands;
|
package ChatProgramm.controller.commands;
|
||||||
|
|
||||||
import ChatProgramm.model.Client;
|
import ChatProgramm.model.Client;
|
||||||
|
import ChatProgramm.model.GrafikModel;
|
||||||
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 ChatProgramm.view.GrafikView;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
@@ -26,8 +28,10 @@ public class CommandConnect implements CommandInterface
|
|||||||
private static Logger lg = OhmLogger.getLogger();
|
private static Logger lg = OhmLogger.getLogger();
|
||||||
private CommandSend commandSend;
|
private CommandSend commandSend;
|
||||||
private ChatView view;
|
private ChatView view;
|
||||||
|
private GrafikModel model;
|
||||||
|
private GrafikView gView;
|
||||||
|
|
||||||
public CommandConnect(ChatView view, CommandInterface value)
|
public CommandConnect(ChatView view, CommandInterface value, GrafikModel model, GrafikView gView)
|
||||||
{
|
{
|
||||||
rBtnServer = view.getBtnServer();
|
rBtnServer = view.getBtnServer();
|
||||||
rBtnClient = view.getBtnClient();
|
rBtnClient = view.getBtnClient();
|
||||||
@@ -36,6 +40,8 @@ public class CommandConnect implements CommandInterface
|
|||||||
commandSend = (CommandSend) value;
|
commandSend = (CommandSend) value;
|
||||||
|
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
this.model = model;
|
||||||
|
this.gView = gView;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -44,7 +50,7 @@ public class CommandConnect implements CommandInterface
|
|||||||
if(rBtnServer.isSelected()){
|
if(rBtnServer.isSelected()){
|
||||||
lg.info("Server ausgewählt");
|
lg.info("Server ausgewählt");
|
||||||
try {
|
try {
|
||||||
commandSend.transmitterInterface = new Server(view);
|
commandSend.setTransmitter(new Server(view, model, gView));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
lg.info("Die Verbindung zum Server ist Fehlgeschlagen");
|
lg.info("Die Verbindung zum Server ist Fehlgeschlagen");
|
||||||
}
|
}
|
||||||
@@ -53,7 +59,7 @@ public class CommandConnect implements CommandInterface
|
|||||||
if(rBtnClient.isSelected()){
|
if(rBtnClient.isSelected()){
|
||||||
lg.info("Client ausgewählt");
|
lg.info("Client ausgewählt");
|
||||||
try {
|
try {
|
||||||
commandSend.transmitterInterface = new Client(view);
|
commandSend.setTransmitter(new Client(view, model, gView));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
lg.info("Die Verbindung zum Client ist Fehlgeschlagen");
|
lg.info("Die Verbindung zum Client ist Fehlgeschlagen");
|
||||||
|
|
||||||
|
|||||||
@@ -6,13 +6,14 @@
|
|||||||
package ChatProgramm.controller.commands;
|
package ChatProgramm.controller.commands;
|
||||||
|
|
||||||
import ChatProgramm.model.Client;
|
import ChatProgramm.model.Client;
|
||||||
|
import ChatProgramm.model.Figur;
|
||||||
|
import ChatProgramm.model.GrafikModel;
|
||||||
import ChatProgramm.model.Server;
|
import ChatProgramm.model.Server;
|
||||||
import ChatProgramm.model.TransmitterInterface;
|
import ChatProgramm.model.TransmitterInterface;
|
||||||
import ChatProgramm.util.OhmLogger;
|
import ChatProgramm.util.OhmLogger;
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import ChatProgramm.model.Nachricht;
|
|
||||||
import ChatProgramm.view.GrafikView;
|
import ChatProgramm.view.GrafikView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,9 +23,10 @@ import ChatProgramm.view.GrafikView;
|
|||||||
public class CommandSend implements CommandInterface
|
public class CommandSend implements CommandInterface
|
||||||
{
|
{
|
||||||
private static Logger lg = OhmLogger.getLogger();
|
private static Logger lg = OhmLogger.getLogger();
|
||||||
private JTextField eingabeFeld;
|
|
||||||
private String nachricht;
|
|
||||||
private GrafikView view;
|
private GrafikView view;
|
||||||
|
private GrafikModel model;
|
||||||
|
|
||||||
public TransmitterInterface transmitterInterface;
|
public TransmitterInterface transmitterInterface;
|
||||||
public Server server;
|
public Server server;
|
||||||
public Client client;
|
public Client client;
|
||||||
@@ -32,9 +34,10 @@ public class CommandSend implements CommandInterface
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public CommandSend(GrafikView view)
|
public CommandSend(GrafikView view, GrafikModel model)
|
||||||
{
|
{
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
this.model = model;
|
||||||
//ToDo: Hier muss auch der gFrame referenziert werden
|
//ToDo: Hier muss auch der gFrame referenziert werden
|
||||||
//this.eingabeFeld = view.getTfNachricht();
|
//this.eingabeFeld = view.getTfNachricht();
|
||||||
transmitterInterface = null;
|
transmitterInterface = null;
|
||||||
@@ -43,14 +46,16 @@ public class CommandSend implements CommandInterface
|
|||||||
@Override
|
@Override
|
||||||
public void execute()
|
public void execute()
|
||||||
{
|
{
|
||||||
lg.info("wir sind drin");
|
Figur aktuelleFigur = model.getFiguren().getLast();
|
||||||
//ToDo in dieser methode muss die Figur serialisiert werden und zum
|
try
|
||||||
//übermitteln bereitgestellt werden
|
{
|
||||||
|
transmitterInterface.send(aktuelleFigur);
|
||||||
|
|
||||||
// if(transmitterInterface != null && !eingabeFeld.getText().isEmpty()){
|
}
|
||||||
// transmitterInterface.send(eingabeFeld.getText());
|
catch(Exception NullPointerExeption)
|
||||||
// eingabeFeld.setText("");
|
{
|
||||||
// }
|
lg.info("Der Transmitter ist null");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -64,4 +69,15 @@ public class CommandSend implements CommandInterface
|
|||||||
public void undo()
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,9 @@
|
|||||||
*/
|
*/
|
||||||
package ChatProgramm.model;
|
package ChatProgramm.model;
|
||||||
|
|
||||||
|
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.*;
|
||||||
@@ -16,13 +18,13 @@ import java.util.logging.*;
|
|||||||
*/
|
*/
|
||||||
public class Client extends Transmitter {
|
public class Client extends Transmitter {
|
||||||
|
|
||||||
private static Logger lg = Logger.getLogger("netz");
|
private static Logger lg = OhmLogger.getLogger();
|
||||||
private static final int PORT = 35000; //lt. iana port > 2¹⁵
|
private static final int PORT = 35000; //lt. iana port > 2¹⁵
|
||||||
private static final String IP = "127.0.0.1";
|
private static final String IP = "127.0.0.1";
|
||||||
|
|
||||||
|
|
||||||
public Client(ChatView view) throws IOException {
|
public Client(ChatView view, GrafikModel model, GrafikView gView) throws IOException {
|
||||||
super(view);
|
super(view, model, gView);
|
||||||
connect();
|
connect();
|
||||||
initIO();
|
initIO();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
* 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.model;
|
||||||
|
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
@@ -20,102 +19,42 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author le
|
* @author le
|
||||||
*/
|
*/
|
||||||
public class GrafikModel
|
public class GrafikModel {
|
||||||
{
|
|
||||||
private Figur aktuelleFigur;
|
|
||||||
private ArrayList<Figur> figuren;
|
|
||||||
private Preferences pref;
|
|
||||||
private static Logger lg = OhmLogger.getLogger();
|
|
||||||
|
|
||||||
public GrafikModel()
|
private Figur aktuelleFigur;
|
||||||
{
|
private ArrayList<Figur> figuren;
|
||||||
aktuelleFigur = new Figur();
|
private Preferences pref;
|
||||||
figuren = new ArrayList<>();
|
private static Logger lg = OhmLogger.getLogger();
|
||||||
}
|
|
||||||
|
|
||||||
public void addPoint(Point p)
|
public GrafikModel() {
|
||||||
{
|
aktuelleFigur = new Figur();
|
||||||
aktuelleFigur.addPoint(p);
|
figuren = new ArrayList<>();
|
||||||
}
|
|
||||||
|
|
||||||
public List<Point> getPunkte()
|
|
||||||
{
|
|
||||||
return aktuelleFigur.getPunkte();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Figur> getFiguren(){
|
|
||||||
return Collections.unmodifiableList(figuren);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Persistenz via Serialisierung
|
|
||||||
* @param dateiname
|
|
||||||
* @throws FileNotFoundException
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public void speicherePunkte(String dateiname) throws FileNotFoundException, IOException
|
|
||||||
{
|
|
||||||
// an Preferences denken!!
|
|
||||||
FileOutputStream fos = new FileOutputStream(dateiname);
|
|
||||||
//wichtig Puffer -> Performance
|
|
||||||
BufferedOutputStream bos = new BufferedOutputStream(fos);
|
|
||||||
//Serialisierung
|
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(bos);
|
|
||||||
oos.writeObject(figuren);
|
|
||||||
oos.flush(); // Puffer
|
|
||||||
oos.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void lesePunkte(String dateiname) throws FileNotFoundException, IOException, ClassNotFoundException
|
|
||||||
{
|
|
||||||
// an Preferences denken!!
|
|
||||||
FileInputStream fis = new FileInputStream(dateiname);
|
|
||||||
//wichtig Puffer -> Performance
|
|
||||||
BufferedInputStream bis = new BufferedInputStream(fis);
|
|
||||||
//Serialisierung
|
|
||||||
ObjectInputStream ois = new ObjectInputStream(bis);
|
|
||||||
Object daten = ois.readObject(); // Achtung
|
|
||||||
// if (daten instanceof ArrayList)
|
|
||||||
// {
|
|
||||||
// punkte = (ArrayList<Point>)daten;
|
|
||||||
// }
|
|
||||||
//eleganter
|
|
||||||
if (daten instanceof ArrayList liste)
|
|
||||||
{
|
|
||||||
figuren = liste;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
public void addPoint(Point p) {
|
||||||
|
aktuelleFigur.addPoint(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addFigure(Figur figur) {
|
||||||
|
figuren.add(figur);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Point> getPunkte() {
|
||||||
|
return aktuelleFigur.getPunkte();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Figur> getFiguren() {
|
||||||
|
return Collections.unmodifiableList(figuren);
|
||||||
|
}
|
||||||
|
|
||||||
public void endShape() {
|
public void endShape() {
|
||||||
figuren.add(aktuelleFigur);
|
figuren.add(aktuelleFigur);
|
||||||
aktuelleFigur = new Figur();
|
aktuelleFigur = new Figur();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Bestimmt die Adresse des zuletzt besuchten Ordners
|
|
||||||
* @return letzter Ordner
|
|
||||||
*/
|
|
||||||
public String getPref()
|
|
||||||
{
|
|
||||||
pref = Preferences.userNodeForPackage(getClass());
|
|
||||||
return pref.get("lastDirectory", null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setzt die Preferenz zu dem zuletzt besuchten Ordner
|
|
||||||
* @param lastDirectory Bezeichner "lastDirectory"
|
|
||||||
* @param lastAdress Adresse des zuletzt besuchten Ordners
|
|
||||||
*/
|
|
||||||
public void putPref(String lastDirectory, String lastAdress)
|
|
||||||
{
|
|
||||||
pref.put(lastDirectory, lastAdress);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author ahren
|
|
||||||
*/
|
|
||||||
public class Nachricht
|
|
||||||
{
|
|
||||||
private String nachricht;
|
|
||||||
|
|
||||||
public Nachricht(String nachricht)
|
|
||||||
{
|
|
||||||
this.nachricht = nachricht;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the nachricht
|
|
||||||
*/
|
|
||||||
public String getNachricht() {
|
|
||||||
return nachricht;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNachricht(String nachricht) {
|
|
||||||
this.nachricht = nachricht;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,9 +4,12 @@
|
|||||||
*/
|
*/
|
||||||
package ChatProgramm.model;
|
package ChatProgramm.model;
|
||||||
|
|
||||||
|
import ChatProgramm.util.OhmLogger;
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
|
import ChatProgramm.view.GrafikView;
|
||||||
import java.util.concurrent.Flow;
|
import java.util.concurrent.Flow;
|
||||||
import java.util.concurrent.Flow.Subscriber;
|
import java.util.concurrent.Flow.Subscriber;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -14,11 +17,19 @@ import java.util.concurrent.Flow.Subscriber;
|
|||||||
*/
|
*/
|
||||||
public class ReceiveAdapter implements Subscriber<Figur> {
|
public class ReceiveAdapter implements Subscriber<Figur> {
|
||||||
|
|
||||||
|
private static Logger lg = OhmLogger.getLogger();
|
||||||
|
|
||||||
private ChatView view;
|
private ChatView view;
|
||||||
|
private GrafikModel model;
|
||||||
|
private GrafikView gView;
|
||||||
private Flow.Subscription subscription;
|
private Flow.Subscription subscription;
|
||||||
|
|
||||||
public ReceiveAdapter(ChatView view) {
|
public ReceiveAdapter(ChatView view, GrafikModel model, GrafikView gView) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
this.model = model;
|
||||||
|
this.gView = gView;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -27,11 +38,11 @@ public class ReceiveAdapter implements Subscriber<Figur> {
|
|||||||
this.subscription.request(1);
|
this.subscription.request(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onNext(Nachricht item) {
|
public void onNext(Figur item) {
|
||||||
|
model.addFigure(item);
|
||||||
|
gView.drawFigur();
|
||||||
|
|
||||||
//ToDo: hier muss der gFrame aufgerufen werden
|
lg.info("Figur wurde dem Grafikmodel hinzugefügt");
|
||||||
// evtl muss die Figur aber zuerst serialisiert werden
|
|
||||||
//view.getTxtChat().append(item.getNachricht());
|
|
||||||
this.subscription.request(1);
|
this.subscription.request(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,8 +54,4 @@ public class ReceiveAdapter implements Subscriber<Figur> {
|
|||||||
public void onComplete(){
|
public void onComplete(){
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNext(Figur item)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,9 @@
|
|||||||
|
|
||||||
package ChatProgramm.model;
|
package ChatProgramm.model;
|
||||||
|
|
||||||
|
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.*;
|
||||||
@@ -16,9 +18,14 @@ import java.util.logging.*;
|
|||||||
*/
|
*/
|
||||||
public class Server extends Transmitter
|
public class Server extends Transmitter
|
||||||
{
|
{
|
||||||
private static Logger lg = Logger.getLogger("netz");
|
private static Logger lg = OhmLogger.getLogger();
|
||||||
private static final int PORT = 35000; //lt. iana port > 2¹⁵
|
private static final int PORT = 35000; //lt. iana port > 2¹⁵
|
||||||
|
|
||||||
|
public Server(ChatView view, GrafikModel model, GrafikView gView) throws IOException {
|
||||||
|
super(view, model, gView);
|
||||||
|
connect();
|
||||||
|
initIO();
|
||||||
|
}
|
||||||
|
|
||||||
public void connect() throws IOException
|
public void connect() throws IOException
|
||||||
{
|
{
|
||||||
@@ -34,12 +41,5 @@ public class Server extends Transmitter
|
|||||||
{
|
{
|
||||||
lg.warning("Timeout"+"("+timeout/1000+"s)");
|
lg.warning("Timeout"+"("+timeout/1000+"s)");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
public Server(ChatView view) throws IOException {
|
|
||||||
super(view);
|
|
||||||
connect();
|
|
||||||
initIO();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
package ChatProgramm.model;
|
package ChatProgramm.model;
|
||||||
|
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
|
import ChatProgramm.view.GrafikView;
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@@ -30,7 +31,7 @@ import java.util.logging.Logger;
|
|||||||
*
|
*
|
||||||
* @author ahren
|
* @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;
|
static final int timeout = 60000;
|
||||||
private static final int PORT = 35000;
|
private static final int PORT = 35000;
|
||||||
@@ -42,19 +43,18 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
|||||||
protected ObjectOutputStream writer;
|
protected ObjectOutputStream writer;
|
||||||
|
|
||||||
private Figur figur;
|
private Figur figur;
|
||||||
private String txtNachricht;
|
|
||||||
private boolean laufend;
|
|
||||||
private SubmissionPublisher<Figur> figurPublisher;
|
private SubmissionPublisher<Figur> figurPublisher;
|
||||||
private ExecutorService eService;
|
private ExecutorService eService;
|
||||||
private String receivedString;
|
private String receivedString;
|
||||||
private ChatView view;
|
private ChatView view;
|
||||||
|
private GrafikModel model;
|
||||||
private ReceiveAdapter receiveAdapter;
|
private ReceiveAdapter receiveAdapter;
|
||||||
|
|
||||||
public Transmitter(ChatView view)
|
public Transmitter(ChatView view, GrafikModel model, GrafikView gView)
|
||||||
{
|
{
|
||||||
socket = new Socket();
|
socket = new Socket();
|
||||||
eService = null;
|
eService = null;
|
||||||
receiveAdapter = new ReceiveAdapter(view);
|
receiveAdapter = new ReceiveAdapter(view, model, gView);
|
||||||
figurPublisher = new SubmissionPublisher<>();
|
figurPublisher = new SubmissionPublisher<>();
|
||||||
this.view = view;
|
this.view = view;
|
||||||
addWertSubscription(receiveAdapter);
|
addWertSubscription(receiveAdapter);
|
||||||
@@ -74,19 +74,12 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
|||||||
InputStream is = socket.getInputStream();
|
InputStream is = socket.getInputStream();
|
||||||
OutputStream os = socket.getOutputStream();
|
OutputStream os = socket.getOutputStream();
|
||||||
|
|
||||||
lg.info("1");
|
writer = new ObjectOutputStream(os);
|
||||||
BufferedOutputStream bos = new BufferedOutputStream(os);
|
writer.flush();
|
||||||
|
reader = new ObjectInputStream(is);
|
||||||
|
|
||||||
BufferedInputStream bis = new BufferedInputStream(is);
|
|
||||||
lg.info("2");
|
|
||||||
// InputStreamReader isr = new InputStreamReader(is, "UTF-8");
|
|
||||||
// OutputStreamWriter osr = new OutputStreamWriter(os, "UTF-8");
|
|
||||||
|
|
||||||
reader = new ObjectInputStream(bis);
|
|
||||||
writer = new ObjectOutputStream(bos);
|
|
||||||
lg.info("Reader / Writer Initialisierung abgeschlossen");
|
lg.info("Reader / Writer Initialisierung abgeschlossen");
|
||||||
startempfangen();
|
startempfangen();
|
||||||
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);
|
||||||
@@ -115,43 +108,35 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
|||||||
figurPublisher.submit(figur);
|
figurPublisher.submit(figur);
|
||||||
}
|
}
|
||||||
public Figur receive(){
|
public Figur receive(){
|
||||||
try {
|
|
||||||
figur = (Figur) reader.readObject();
|
|
||||||
if(!txtNachricht.isEmpty()){
|
|
||||||
lg.info("Nachricht erhalten");
|
|
||||||
|
|
||||||
return figur;
|
Object receivedObject;
|
||||||
|
try {
|
||||||
|
receivedObject = reader.readObject();
|
||||||
|
|
||||||
|
if (receivedObject instanceof Figur) {
|
||||||
|
lg.info("Figur erhalten");
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
catch (ClassNotFoundException ex)
|
|
||||||
{
|
|
||||||
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
return figur;
|
return figur;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void disconnect (){
|
|
||||||
// in.close();
|
|
||||||
// out.close();
|
|
||||||
// s.close();
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (true) {
|
while (true) {
|
||||||
lg.info("Warte auf Nachricht");
|
lg.info("Warte auf Nachricht");
|
||||||
if(laufend) {
|
figur = receive();
|
||||||
figur = receive();
|
|
||||||
if(!figur.getPunkte().isEmpty()){
|
if(!figur.getPunkte().isEmpty()){
|
||||||
figurPublisher.submit(figur);
|
figurPublisher.submit(figur);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,7 +147,7 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,7 +164,6 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
|||||||
private void startempfangen()
|
private void startempfangen()
|
||||||
{
|
{
|
||||||
synchronized (this){
|
synchronized (this){
|
||||||
laufend = true;
|
|
||||||
}
|
}
|
||||||
if (eService == null){
|
if (eService == null){
|
||||||
eService = Executors.newSingleThreadExecutor();
|
eService = Executors.newSingleThreadExecutor();
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
package ChatProgramm.model;
|
package ChatProgramm.model;
|
||||||
|
|
||||||
import ChatProgramm.model.Nachricht;
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author ahren
|
* @author ahren
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import ChatProgramm.util.OhmLogger;
|
|||||||
*
|
*
|
||||||
* @author le
|
* @author le
|
||||||
*/
|
*/
|
||||||
public class GrafikView extends JComponent implements Printable
|
public class GrafikView extends JComponent
|
||||||
{
|
{
|
||||||
private static Logger lg = OhmLogger.getLogger();
|
private static Logger lg = OhmLogger.getLogger();
|
||||||
private static Dimension EINS = new Dimension(1, 1); // Dimension ist eine Klasse die width udn height hält
|
private static Dimension EINS = new Dimension(1, 1); // Dimension ist eine Klasse die width udn height hält
|
||||||
@@ -58,7 +58,16 @@ public class GrafikView extends JComponent implements Printable
|
|||||||
* Zeichnet den aktuellen Pfad (solange die maus gedrückt gehalten wird)
|
* Zeichnet den aktuellen Pfad (solange die maus gedrückt gehalten wird)
|
||||||
* @param p -> Der aktuelle punkt als x-y-Koordinate
|
* @param p -> Der aktuelle punkt als x-y-Koordinate
|
||||||
*/
|
*/
|
||||||
public void drawPoint(Point p)
|
public void drawFigur()
|
||||||
|
{
|
||||||
|
Graphics2D g2 = (Graphics2D)this.getGraphics(); // gefährlich!
|
||||||
|
|
||||||
|
drawPath(model.getFiguren().getLast().getPunkte(),g2);
|
||||||
|
|
||||||
|
g2.dispose(); //SEEEEHHHHRRRR WICHTIG!!!!!!!
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawPoint()
|
||||||
{
|
{
|
||||||
Graphics2D g2 = (Graphics2D)this.getGraphics(); // gefährlich!
|
Graphics2D g2 = (Graphics2D)this.getGraphics(); // gefährlich!
|
||||||
|
|
||||||
@@ -100,44 +109,4 @@ public class GrafikView extends JComponent implements Printable
|
|||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void doPrint()
|
|
||||||
{
|
|
||||||
HashPrintRequestAttributeSet printSet =
|
|
||||||
new HashPrintRequestAttributeSet();
|
|
||||||
printSet.add(DialogTypeSelection.NATIVE);
|
|
||||||
PrinterJob pj = PrinterJob.getPrinterJob();
|
|
||||||
pj.setPrintable(this);
|
|
||||||
//Dialog
|
|
||||||
if (pj.printDialog(printSet))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pj.print(printSet);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
JOptionPane.showMessageDialog(this, ex.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int print(Graphics gp, PageFormat pf, int pageIndex) throws PrinterException
|
|
||||||
{
|
|
||||||
Graphics2D g2p = (Graphics2D)gp;
|
|
||||||
if (pageIndex == 0)
|
|
||||||
{
|
|
||||||
g2p.translate(pf.getImageableX(), pf.getImageableY());
|
|
||||||
g2p.scale(pf.getImageableWidth() / this.getWidth(),
|
|
||||||
pf.getImageableHeight() / this.getHeight());
|
|
||||||
super.print(g2p);
|
|
||||||
return Printable.PAGE_EXISTS;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Printable.NO_SUCH_PAGE; // wichtig sonst Papiervernichtung
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
log.level=INFO
|
log.level=INFO
|
||||||
|
|
||||||
log.directory=../Aufgabe7_bandit
|
# log.directory=../Aufgabe7_bandit
|
||||||
log.filename=ohmLog
|
# log.filename=ohmLog
|
||||||
|
|
||||||
# Beispiel f\u00fcr verschiedene Level f\u00fcr unterschiedliche Pakete
|
# Beispiel f\u00fcr verschiedene Level f\u00fcr unterschiedliche Pakete
|
||||||
# log.level.bandit.Zahlengenerator=FINE
|
# log.level.bandit.Zahlengenerator=FINE
|
||||||
|
|||||||
Reference in New Issue
Block a user