Compare commits
8
Commits
Toni
..
0e71917727
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e71917727 | ||
|
|
dc1f783e00 | ||
|
|
2fc05ae87f | ||
|
|
5117ecdb6f | ||
|
|
a4a45ed5f2 | ||
|
|
6642dc8179 | ||
|
|
f05b0f0014 | ||
|
|
1aa5b51e78 |
No files matched your search
@@ -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, model, controller, zeichenflaeche);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,8 +58,6 @@ public CommandController(ChatView view, GrafikModel model, GrafikController cont
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -44,14 +44,14 @@ public class CommandConnect implements CommandInterface
|
|||||||
this.gView = gView;
|
this.gView = gView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute()
|
public void execute()
|
||||||
{
|
{
|
||||||
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));
|
||||||
|
//commandSend.transmitterInterface = new Server(view);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
lg.info("Die Verbindung zum Server ist Fehlgeschlagen");
|
lg.info("Die Verbindung zum Server ist Fehlgeschlagen");
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,8 @@ 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));
|
||||||
|
//commandSend.transmitterInterface = new Client(view);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
lg.info("Die Verbindung zum Client ist Fehlgeschlagen");
|
lg.info("Die Verbindung zum Client ist Fehlgeschlagen");
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,6 +32,9 @@ public class CommandSend implements CommandInterface
|
|||||||
public Server server;
|
public Server server;
|
||||||
public Client client;
|
public Client client;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public CommandSend(GrafikView view, GrafikModel model)
|
public CommandSend(GrafikView view, GrafikModel model)
|
||||||
{
|
{
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
|||||||
@@ -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.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
@@ -21,8 +22,8 @@ public class Client extends Transmitter {
|
|||||||
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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,75 +52,17 @@ public class GrafikModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 endShape() {
|
public void endShape() {
|
||||||
figuren.add(aktuelleFigur);
|
figuren.add(aktuelleFigur);
|
||||||
aktuelleFigur = new Figur();
|
aktuelleFigur = new Figur();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFigur(Figur figur){
|
public void setFigur(Figur figur){
|
||||||
aktuelleFigur = figur;
|
//aktuelleFigur = figur;
|
||||||
figuren.add(figur);
|
figuren.add(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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -11,7 +11,6 @@ import java.util.concurrent.Flow;
|
|||||||
import java.util.concurrent.Flow.Subscriber;
|
import java.util.concurrent.Flow.Subscriber;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author ahren
|
* @author ahren
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
package ChatProgramm.model;
|
package ChatProgramm.model;
|
||||||
|
|
||||||
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.*;
|
||||||
@@ -35,8 +36,8 @@ public class Server extends Transmitter
|
|||||||
lg.warning("Timeout"+"("+timeout/1000+"s)");
|
lg.warning("Timeout"+"("+timeout/1000+"s)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public Server(ChatView view) throws IOException {
|
public Server(ChatView view, GrafikModel model, GrafikView gView) throws IOException {
|
||||||
super(view);
|
super(view, model, gView);
|
||||||
connect();
|
connect();
|
||||||
initIO();
|
initIO();
|
||||||
|
|
||||||
|
|||||||
@@ -31,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;
|
||||||
@@ -49,12 +49,10 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
|||||||
private ExecutorService eService;
|
private ExecutorService eService;
|
||||||
private String receivedString;
|
private String receivedString;
|
||||||
private ChatView view;
|
private ChatView view;
|
||||||
private GrafikView gView;
|
|
||||||
private GrafikModel model;
|
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;
|
||||||
@@ -78,8 +76,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();
|
||||||
|
|
||||||
|
|
||||||
|
// Bruh im ernst mann muss zuerst den writer und dann den reader initialisieren
|
||||||
|
// andersrum ist das blockiert weil die Streams von hinten nach vorne gelesen werden
|
||||||
writer = new ObjectOutputStream(os);
|
writer = new ObjectOutputStream(os);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
|
|
||||||
reader = new ObjectInputStream(is);
|
reader = new ObjectInputStream(is);
|
||||||
|
|
||||||
lg.info("Reader / Writer Initialisierung abgeschlossen");
|
lg.info("Reader / Writer Initialisierung abgeschlossen");
|
||||||
@@ -113,21 +115,23 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
|||||||
figurPublisher.submit(figur);
|
figurPublisher.submit(figur);
|
||||||
}
|
}
|
||||||
public Figur receive(){
|
public Figur receive(){
|
||||||
|
|
||||||
Object receivedObject;
|
Object receivedObject;
|
||||||
try {
|
try {
|
||||||
receivedObject = reader.readObject();
|
receivedObject = reader.readObject();
|
||||||
if(receivedObject instanceof Figur){
|
|
||||||
|
if (receivedObject instanceof Figur) {
|
||||||
lg.info("Figur erhalten");
|
lg.info("Figur erhalten");
|
||||||
figur = (Figur) receivedObject;
|
figur = (Figur) receivedObject;
|
||||||
|
// Verarbeiten Sie die empfangene Figur
|
||||||
}
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
} catch (IOException e) {
|
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
throw new RuntimeException(e);
|
} catch (ClassNotFoundException ex) {
|
||||||
}
|
|
||||||
catch (ClassNotFoundException ex)
|
|
||||||
{
|
|
||||||
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return figur;
|
return figur;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +164,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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ public class GrafikView extends JComponent implements Printable
|
|||||||
|
|
||||||
g2.dispose(); //SEEEEHHHHRRRR WICHTIG!!!!!!!
|
g2.dispose(); //SEEEEHHHHRRRR WICHTIG!!!!!!!
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawPoint()
|
public void drawPoint()
|
||||||
{
|
{
|
||||||
Graphics2D g2 = (Graphics2D)this.getGraphics(); // gefährlich!
|
Graphics2D g2 = (Graphics2D)this.getGraphics(); // gefährlich!
|
||||||
@@ -76,7 +77,6 @@ public class GrafikView extends JComponent implements Printable
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hier werden alle Pfade aus dem model neu gezeichnet
|
* Hier werden alle Pfade aus dem model neu gezeichnet
|
||||||
* Jedes mal wenn die Maus los gelassen wird, wird dder aktuelle Pfad gespeichert
|
* Jedes mal wenn die Maus los gelassen wird, wird dder aktuelle Pfad gespeichert
|
||||||
|
|||||||
Reference in new issue
Block a user