import ChatProgramm.controller.CommandController; | import ChatProgramm.controller.CommandController; | ||||
import ChatProgramm.controller.GrafikController; | 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.ChatView; | ||||
import ChatProgramm.view.GrafikView; | import ChatProgramm.view.GrafikView; | ||||
import javax.swing.JOptionPane; | import javax.swing.JOptionPane; | ||||
{ | { | ||||
public Start() | public Start() | ||||
{ | { | ||||
GrafikModel model = new GrafikModel(); | |||||
GrafikDaten gDaten = new GrafikDaten(); | |||||
ChatView view = new ChatView(); | ChatView view = new ChatView(); | ||||
GrafikView zeichenflaeche = view.getGvZeichenflaeche(); | 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(); | |||||
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.model.GrafikDaten; | |||||
import ChatProgramm.view.ChatView; | import ChatProgramm.view.ChatView; | ||||
import ChatProgramm.view.GrafikView; | import ChatProgramm.view.GrafikView; | ||||
import java.awt.Component; | import java.awt.Component; | ||||
public class CommandController implements ActionListener{ | public class CommandController implements ActionListener{ | ||||
private ChatView view; | private ChatView view; | ||||
private GrafikModel model; | |||||
private GrafikDaten model; | |||||
private GrafikView gView; | private GrafikView gView; | ||||
private CommandInvoker invoker; | private CommandInvoker invoker; | ||||
private GrafikController controller; | 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.view = view; | ||||
this.model = model; | this.model = model; | ||||
this.gView = gView; | this.gView = gView; |
import java.awt.event.MouseAdapter; | import java.awt.event.MouseAdapter; | ||||
import java.awt.event.MouseEvent; | import java.awt.event.MouseEvent; | ||||
import java.awt.event.MouseMotionListener; | import java.awt.event.MouseMotionListener; | ||||
import ChatProgramm.model.GrafikModel; | |||||
import ChatProgramm.model.GrafikDaten; | |||||
import ChatProgramm.view.GrafikView; | import ChatProgramm.view.GrafikView; | ||||
/** | /** | ||||
public class GrafikController extends MouseAdapter implements MouseMotionListener | public class GrafikController extends MouseAdapter implements MouseMotionListener | ||||
{ | { | ||||
private GrafikView view; | private GrafikView view; | ||||
private GrafikModel model; | |||||
private GrafikDaten model; | |||||
private CommandSend commandSend; | private CommandSend commandSend; | ||||
public GrafikController(GrafikView view, GrafikModel model) | |||||
public GrafikController(GrafikView view, GrafikDaten model) | |||||
{ | { | ||||
this.view = view; | this.view = view; | ||||
this.model = model; | this.model = model; |
package ChatProgramm.controller.commands; | package ChatProgramm.controller.commands; | ||||
import ChatProgramm.model.Client; | import ChatProgramm.model.Client; | ||||
import ChatProgramm.model.GrafikModel; | |||||
import ChatProgramm.model.GrafikDaten; | |||||
import ChatProgramm.model.Server; | import ChatProgramm.model.Server; | ||||
import ChatProgramm.util.OhmLogger; | import ChatProgramm.util.OhmLogger; | ||||
import ChatProgramm.view.ChatView; | import ChatProgramm.view.ChatView; | ||||
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 GrafikDaten model; | |||||
private GrafikView gView; | 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(); | rBtnServer = view.getBtnServer(); | ||||
rBtnClient = view.getBtnClient(); | rBtnClient = view.getBtnClient(); |
/* | |||||
* 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); | |||||
} | |||||
} |
import ChatProgramm.model.Client; | import ChatProgramm.model.Client; | ||||
import ChatProgramm.model.Figur; | import ChatProgramm.model.Figur; | ||||
import ChatProgramm.model.GrafikModel; | |||||
import ChatProgramm.model.GrafikDaten; | |||||
import ChatProgramm.model.Server; | import ChatProgramm.model.Server; | ||||
import ChatProgramm.model.TransmitterInterface; | import ChatProgramm.model.TransmitterInterface; | ||||
import ChatProgramm.util.OhmLogger; | import ChatProgramm.util.OhmLogger; | ||||
private static Logger lg = OhmLogger.getLogger(); | private static Logger lg = OhmLogger.getLogger(); | ||||
private GrafikView view; | private GrafikView view; | ||||
private GrafikModel model; | |||||
private GrafikDaten model; | |||||
public TransmitterInterface transmitterInterface; | public TransmitterInterface transmitterInterface; | ||||
public Server server; | public Server server; | ||||
public CommandSend(GrafikView view, GrafikModel model) | |||||
public CommandSend(GrafikView view, GrafikDaten model) | |||||
{ | { | ||||
this.view = view; | this.view = view; | ||||
this.model = model; | this.model = model; |
/* | |||||
* 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 | |||||
} | |||||
} |
private static final String IP = "127.0.0.1"; | 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(); | connect(); | ||||
initIO(); | initIO(); | ||||
} | } |
* | * | ||||
* @author le | * @author le | ||||
*/ | */ | ||||
public class GrafikModel { | |||||
public class GrafikDaten { | |||||
private Figur aktuelleFigur; | private Figur aktuelleFigur; | ||||
private ArrayList<Figur> figuren; | private ArrayList<Figur> figuren; | ||||
private Preferences pref; | private Preferences pref; | ||||
private static Logger lg = OhmLogger.getLogger(); | private static Logger lg = OhmLogger.getLogger(); | ||||
public GrafikModel() { | |||||
public GrafikDaten() { | |||||
aktuelleFigur = new Figur(); | aktuelleFigur = new Figur(); | ||||
figuren = new ArrayList<>(); | figuren = new ArrayList<>(); | ||||
} | } |
private static Logger lg = OhmLogger.getLogger(); | private static Logger lg = OhmLogger.getLogger(); | ||||
private ChatView view; | private ChatView view; | ||||
private GrafikModel model; | |||||
private GrafikView gView; | |||||
private ChatModel model; | |||||
private Flow.Subscription subscription; | private Flow.Subscription subscription; | ||||
public ReceiveAdapter(ChatView view, GrafikModel model, GrafikView gView) { | |||||
public ReceiveAdapter(ChatView view, ChatModel model) { | |||||
this.view = view; | this.view = view; | ||||
this.model = model; | |||||
this.gView = gView; | |||||
this.model = model; | |||||
} | } | ||||
@Override | @Override | ||||
} | } | ||||
public void onNext(Figur item) { | public void onNext(Figur item) { | ||||
model.addFigure(item); | |||||
gView.drawFigur(); | |||||
// model.addFigure(item); | |||||
// gView.drawFigur(); | |||||
lg.info("Figur wurde dem Grafikmodel hinzugefügt"); | lg.info("Figur wurde dem Grafikmodel hinzugefügt"); | ||||
this.subscription.request(1); | this.subscription.request(1); |
private static Logger lg = OhmLogger.getLogger(); | 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); | |||||
public Server(ChatView view, ChatModel model) throws IOException { | |||||
super(view, model); | |||||
connect(); | connect(); | ||||
initIO(); | initIO(); | ||||
} | } |
*/ | */ | ||||
package ChatProgramm.model; | package ChatProgramm.model; | ||||
import ChatProgramm.util.OhmLogger; | |||||
import ChatProgramm.view.ChatView; | import ChatProgramm.view.ChatView; | ||||
import ChatProgramm.view.GrafikView; | import ChatProgramm.view.GrafikView; | ||||
import java.io.BufferedInputStream; | import java.io.BufferedInputStream; | ||||
* | * | ||||
* @author ahren | * @author ahren | ||||
*/ | */ | ||||
public abstract class Transmitter implements Runnable, Subscriber<Figur>, TransmitterInterface { | |||||
public abstract class Transmitter implements Runnable, Subscriber<Figur>{ | |||||
static final int timeout = 60000; | static final int timeout = 60000; | ||||
private static final int PORT = 35000; | private static final int PORT = 35000; | ||||
private static Logger lg = Logger.getLogger("netz"); | |||||
private static Logger lg = OhmLogger.getLogger(); | |||||
protected Socket socket; | protected Socket socket; | ||||
protected ObjectInputStream reader; | protected ObjectInputStream reader; | ||||
protected ObjectOutputStream writer; | protected ObjectOutputStream writer; | ||||
private Figur figur; | |||||
private SubmissionPublisher<Figur> figurPublisher; | private SubmissionPublisher<Figur> figurPublisher; | ||||
private ExecutorService eService; | private ExecutorService eService; | ||||
private String receivedString; | |||||
private ChatView view; | private ChatView view; | ||||
private GrafikModel model; | |||||
private ChatModel model; | |||||
private ReceiveAdapter receiveAdapter; | private ReceiveAdapter receiveAdapter; | ||||
public Transmitter(ChatView view, GrafikModel model, GrafikView gView) | |||||
public Transmitter(ChatView view, ChatModel model) | |||||
{ | { | ||||
socket = new Socket(); | socket = new Socket(); | ||||
eService = null; | eService = null; | ||||
receiveAdapter = new ReceiveAdapter(view, model, gView); | |||||
figurPublisher = new SubmissionPublisher<>(); | figurPublisher = new SubmissionPublisher<>(); | ||||
this.view = view; | 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); | figurPublisher.subscribe(subscriber); | ||||
} | } | ||||
* @param figur | * @param figur | ||||
* @throws IOException | * @throws IOException | ||||
*/ | */ | ||||
@Override | |||||
public void send(Figur figur){ | public void send(Figur figur){ | ||||
try | try | ||||
{ | { | ||||
public Figur receive(){ | public Figur receive(){ | ||||
Object receivedObject; | Object receivedObject; | ||||
Figur figur = new Figur(); | |||||
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; | |||||
} | } | ||||
} 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); | ||||
} 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; | |||||
} | } | ||||
public void run() { | public void run() { | ||||
while (true) { | while (true) { | ||||
lg.info("Warte auf Nachricht"); | lg.info("Warte auf Nachricht"); | ||||
figur = receive(); | |||||
if(!figur.getPunkte().isEmpty()){ | |||||
figurPublisher.submit(figur); | |||||
} | |||||
// figur = receive(); | |||||
// if(!figur.getPunkte().isEmpty()){ | |||||
// figurPublisher.submit(figur); | |||||
// } | |||||
} | } | ||||
} | } | ||||
import javax.print.attribute.standard.DialogTypeSelection; | import javax.print.attribute.standard.DialogTypeSelection; | ||||
import javax.swing.JComponent; | import javax.swing.JComponent; | ||||
import javax.swing.JOptionPane; | import javax.swing.JOptionPane; | ||||
import ChatProgramm.model.GrafikModel; | |||||
import ChatProgramm.model.GrafikDaten; | |||||
import ChatProgramm.util.OhmLogger; | import ChatProgramm.util.OhmLogger; | ||||
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 | ||||
private Rectangle2D.Float pixel; | private Rectangle2D.Float pixel; | ||||
private Line2D.Float line; | private Line2D.Float line; | ||||
private GrafikModel model; | |||||
private GrafikDaten model; | |||||
private Point from = null; | private Point from = null; | ||||
private Point to = null; | private Point to = null; | ||||
line = new Line2D.Float(); | line = new Line2D.Float(); | ||||
} | } | ||||
public void setModel(GrafikModel model) | |||||
public void setModel(GrafikDaten model) | |||||
{ | { | ||||
this.model = model; | this.model = model; | ||||
} | } |