Compare commits
19
Commits
64a6047ca4
...
JensV2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
928e6ae1af | ||
|
|
a5b238fe4f | ||
|
|
75e458a4ac | ||
|
|
68eb43c715 | ||
|
|
541b497796 | ||
|
|
43de325d71 | ||
|
|
0e71917727 | ||
|
|
dc1f783e00 | ||
|
|
2fc05ae87f | ||
|
|
5117ecdb6f | ||
|
|
a4a45ed5f2 | ||
|
|
6642dc8179 | ||
|
|
f05b0f0014 | ||
|
|
1aa5b51e78 | ||
|
|
ba0f12561b | ||
|
|
e7034fc7a4 | ||
|
|
19fd23c638 | ||
|
|
f7a0de0041 | ||
|
|
0da0f2cc5b |
No files matched your search
@@ -0,0 +1,3 @@
|
|||||||
|
/nbproject/private/
|
||||||
|
/build/
|
||||||
|
/dist/
|
||||||
@@ -5,8 +5,14 @@
|
|||||||
|
|
||||||
package ChatProgramm;
|
package ChatProgramm;
|
||||||
|
|
||||||
import ChatProgramm.controller.CommandController;
|
import ChatProgramm.controller.GrafikController;
|
||||||
|
import ChatProgramm.controller.commands.CommandConnectV2;
|
||||||
|
import ChatProgramm.controller.commands.CommandSendV2;
|
||||||
|
import ChatProgramm.model.ChatModel;
|
||||||
|
import ChatProgramm.model.GrafikDaten;
|
||||||
|
import ChatProgramm.controller.ReceiveAdapter;
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
|
import ChatProgramm.view.GrafikView;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
|
|
||||||
@@ -18,10 +24,26 @@ public class Start
|
|||||||
{
|
{
|
||||||
public Start()
|
public Start()
|
||||||
{
|
{
|
||||||
|
GrafikDaten gDaten = new GrafikDaten();
|
||||||
ChatView view = new ChatView();
|
ChatView view = new ChatView();
|
||||||
CommandController controller_commands = new CommandController(view);
|
GrafikView zeichenflaeche = view.getGvZeichenflaeche();
|
||||||
controller_commands.registerEvents();
|
zeichenflaeche.setModel(gDaten);
|
||||||
controller_commands.registerCommands();
|
|
||||||
|
ChatModel model = new ChatModel(gDaten);
|
||||||
|
|
||||||
|
GrafikController gContoller = new GrafikController(view,model);
|
||||||
|
gContoller.registerEvents();
|
||||||
|
|
||||||
|
CommandConnectV2 cConnect = new CommandConnectV2(view,model);
|
||||||
|
cConnect.registerEvents();
|
||||||
|
|
||||||
|
CommandSendV2 cSend = new CommandSendV2(view, model);
|
||||||
|
cSend.registerEvents();
|
||||||
|
|
||||||
|
ReceiveAdapter rAdapter = new ReceiveAdapter(view, model);
|
||||||
|
model.addSubscription(rAdapter);
|
||||||
|
|
||||||
|
|
||||||
view.setVisible(true);
|
view.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,57 +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.controller;
|
|
||||||
|
|
||||||
import ChatProgramm.controller.commands.CommandConnect;
|
|
||||||
import ChatProgramm.controller.commands.CommandInvoker;
|
|
||||||
import ChatProgramm.controller.commands.CommandSend;
|
|
||||||
import ChatProgramm.view.ChatView;
|
|
||||||
import java.awt.Component;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author ahren
|
|
||||||
*/
|
|
||||||
public class CommandController implements ActionListener{
|
|
||||||
|
|
||||||
private ChatView view;
|
|
||||||
private CommandInvoker invoker;
|
|
||||||
|
|
||||||
public CommandController(ChatView view){
|
|
||||||
this.view = view;
|
|
||||||
this.invoker = new CommandInvoker();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerEvents(){
|
|
||||||
view.getBtnConnect().addActionListener(this);
|
|
||||||
//ToDo: muss auf gFrame referenzieren
|
|
||||||
//view.getTfNachricht().addActionListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerCommands(){
|
|
||||||
CommandSend commandSend = new CommandSend(view);
|
|
||||||
invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend));
|
|
||||||
//invoker.addCommand(view.getTfNachricht(), commandSend);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ausführen des jeweiligen Kommandos
|
|
||||||
* @param e Referenz auf das Event
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
Component key = (Component)e.getSource();
|
|
||||||
invoker.executeCommand(key);
|
|
||||||
// if(key == view.getBtnOpen()|| key==view.getMiOpen())
|
|
||||||
// invoker.deleteStack();
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
|
||||||
|
import ChatProgramm.model.ChatModel;
|
||||||
|
import ChatProgramm.util.OhmLogger;
|
||||||
|
import ChatProgramm.view.ChatView;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseMotionListener;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author le
|
||||||
|
*/
|
||||||
|
public class GrafikController extends MouseAdapter implements MouseMotionListener
|
||||||
|
{
|
||||||
|
private static Logger lg = OhmLogger.getLogger();
|
||||||
|
private ChatView view;
|
||||||
|
private ChatModel model;
|
||||||
|
|
||||||
|
public GrafikController(ChatView view, ChatModel model)
|
||||||
|
{
|
||||||
|
this.view = view;
|
||||||
|
this.model = model;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void registerEvents()
|
||||||
|
{
|
||||||
|
view.getGvZeichenflaeche().addMouseMotionListener(this);
|
||||||
|
view.getGvZeichenflaeche().addMouseListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseDragged(MouseEvent evt)
|
||||||
|
{
|
||||||
|
Point p = evt.getPoint();
|
||||||
|
|
||||||
|
model.getGrafikDaten().addPoint(p);
|
||||||
|
view.getGvZeichenflaeche().drawPoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent evt)
|
||||||
|
{
|
||||||
|
model.getGrafikDaten().endShape();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+17
-9
@@ -2,23 +2,33 @@
|
|||||||
* 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.controller;
|
||||||
|
|
||||||
|
import ChatProgramm.model.ChatModel;
|
||||||
|
import ChatProgramm.model.Figur;
|
||||||
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author ahren
|
* @author ahren
|
||||||
*/
|
*/
|
||||||
public class ReceiveAdapter implements Subscriber<Nachricht> {
|
public class ReceiveAdapter implements Subscriber<Figur> {
|
||||||
|
|
||||||
|
private static Logger lg = OhmLogger.getLogger();
|
||||||
|
|
||||||
private ChatView view;
|
private ChatView view;
|
||||||
|
private ChatModel model;
|
||||||
|
|
||||||
private Flow.Subscription subscription;
|
private Flow.Subscription subscription;
|
||||||
|
|
||||||
public ReceiveAdapter(ChatView view) {
|
public ReceiveAdapter(ChatView view, ChatModel model) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
this.model = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -27,12 +37,9 @@ public class ReceiveAdapter implements Subscriber<Nachricht> {
|
|||||||
this.subscription.request(1);
|
this.subscription.request(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void onNext(Figur item) {
|
||||||
public void onNext(Nachricht item) {
|
view.getGvZeichenflaeche().drawFigur();
|
||||||
|
lg.info("Figur auf die Zeichenfläche projiziert");
|
||||||
//ToDo: hier muss der gFrame aufgerufen werden
|
|
||||||
// evtl muss die Figur aber zuerst serialisiert werden
|
|
||||||
//view.getTxtChat().append(item.getNachricht());
|
|
||||||
this.subscription.request(1);
|
this.subscription.request(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,4 +50,5 @@ public class ReceiveAdapter implements Subscriber<Nachricht> {
|
|||||||
@Override
|
@Override
|
||||||
public void onComplete(){
|
public void onComplete(){
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,76 +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.controller.commands;
|
|
||||||
|
|
||||||
import ChatProgramm.model.Client;
|
|
||||||
import ChatProgramm.model.Server;
|
|
||||||
import ChatProgramm.util.OhmLogger;
|
|
||||||
import ChatProgramm.view.ChatView;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
import javax.swing.JDialog;
|
|
||||||
import javax.swing.JRadioButton;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author ahren
|
|
||||||
*/
|
|
||||||
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;
|
|
||||||
|
|
||||||
public CommandConnect(ChatView view, CommandInterface value)
|
|
||||||
{
|
|
||||||
rBtnServer = view.getBtnServer();
|
|
||||||
rBtnClient = view.getBtnClient();
|
|
||||||
dialogFenster = view.getjDialog1();
|
|
||||||
|
|
||||||
commandSend = (CommandSend) value;
|
|
||||||
|
|
||||||
this.view = view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute()
|
|
||||||
{
|
|
||||||
if(rBtnServer.isSelected()){
|
|
||||||
lg.info("Server ausgewählt");
|
|
||||||
try {
|
|
||||||
commandSend.transmitterInterface = new Server(view);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
lg.info("Die Verbindung zum Server ist Fehlgeschlagen");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(rBtnClient.isSelected()){
|
|
||||||
lg.info("Client ausgewählt");
|
|
||||||
try {
|
|
||||||
commandSend.transmitterInterface = new Client(view);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
lg.info("Die Verbindung zum Client ist Fehlgeschlagen");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dialogFenster.setVisible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isUndoable()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void undo()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* 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.getBtnServer().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.getBtnClient().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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,17 +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.controller.commands;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author ahren
|
|
||||||
*/
|
|
||||||
public interface CommandInterface
|
|
||||||
{
|
|
||||||
public void execute();
|
|
||||||
public void undo();
|
|
||||||
public boolean isUndoable();
|
|
||||||
}
|
|
||||||
@@ -1,69 +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.controller.commands;
|
|
||||||
|
|
||||||
import java.awt.Component;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Stack;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author ahren
|
|
||||||
*/
|
|
||||||
public class CommandInvoker {
|
|
||||||
|
|
||||||
private HashMap<Component, CommandInterface> commands;
|
|
||||||
private Stack <CommandInterface> undoStack;
|
|
||||||
|
|
||||||
public CommandInvoker(){
|
|
||||||
commands = new HashMap<>();
|
|
||||||
undoStack = new Stack();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fügt ein Kommando zur Kommando-"Datenbank" = HashMap hinzu
|
|
||||||
* @param key Quelle des Events
|
|
||||||
* @param value Referenz auf das zugehörige Kommando-Objekt
|
|
||||||
*/
|
|
||||||
public void addCommand(Component key, CommandInterface value){
|
|
||||||
commands.put(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Führt Kommando der Eventquelle "key" aus und legt die Referenz
|
|
||||||
* des Kommando in den Undo-Stack
|
|
||||||
* @param key Referenz auf die Eventquelle
|
|
||||||
*/
|
|
||||||
public void executeCommand(Component key){
|
|
||||||
CommandInterface command = commands.get(key);
|
|
||||||
command.execute();
|
|
||||||
if (command.isUndoable())
|
|
||||||
{
|
|
||||||
undoStack.push(command);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Falls der Stack Elemente enthält, wird das oberste Element geholt
|
|
||||||
* und die Methode "undo" des Commands aufgerufen
|
|
||||||
*/
|
|
||||||
public void undoCommand()
|
|
||||||
{
|
|
||||||
if (!undoStack.isEmpty())
|
|
||||||
{
|
|
||||||
undoStack.pop().undo();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Löscht bei Öffnen einer neuen Datei den Stack
|
|
||||||
*/
|
|
||||||
public void deleteStack()
|
|
||||||
{
|
|
||||||
while(!undoStack.isEmpty())
|
|
||||||
undoStack.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,65 +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.controller.commands;
|
|
||||||
|
|
||||||
import ChatProgramm.model.Client;
|
|
||||||
import ChatProgramm.model.Server;
|
|
||||||
import ChatProgramm.model.TransmitterInterface;
|
|
||||||
import ChatProgramm.util.OhmLogger;
|
|
||||||
import ChatProgramm.view.ChatView;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
import javax.swing.JTextField;
|
|
||||||
import ChatProgramm.model.Nachricht;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author ahren
|
|
||||||
*/
|
|
||||||
public class CommandSend implements CommandInterface
|
|
||||||
{
|
|
||||||
private static Logger lg = OhmLogger.getLogger();
|
|
||||||
private JTextField eingabeFeld;
|
|
||||||
private String nachricht;
|
|
||||||
private ChatView view;
|
|
||||||
public TransmitterInterface transmitterInterface;
|
|
||||||
public Server server;
|
|
||||||
public Client client;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public CommandSend(ChatView view)
|
|
||||||
{
|
|
||||||
this.view = view;
|
|
||||||
//ToDo: Hier muss auch der gFrame referenziert werden
|
|
||||||
//this.eingabeFeld = view.getTfNachricht();
|
|
||||||
transmitterInterface = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute()
|
|
||||||
{
|
|
||||||
//ToDo in dieser methode muss die Figur serialisiert werden und zum
|
|
||||||
//übermitteln bereitgestellt werden
|
|
||||||
|
|
||||||
// if(transmitterInterface != null && !eingabeFeld.getText().isEmpty()){
|
|
||||||
// transmitterInterface.send(eingabeFeld.getText());
|
|
||||||
// eingabeFeld.setText("");
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isUndoable()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void undo()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* 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.util.OhmLogger;
|
||||||
|
import ChatProgramm.view.ChatView;
|
||||||
|
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseMotionListener;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Js-Sc
|
||||||
|
*/
|
||||||
|
public class CommandSendV2 extends MouseAdapter implements MouseMotionListener {
|
||||||
|
|
||||||
|
private static Logger lg = OhmLogger.getLogger();
|
||||||
|
private ChatView view;
|
||||||
|
private ChatModel model;
|
||||||
|
|
||||||
|
public CommandSendV2(ChatView view, ChatModel model) {
|
||||||
|
this.view = view;
|
||||||
|
this.model = model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerEvents() {
|
||||||
|
view.getGvZeichenflaeche().addMouseListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
model.sendFigur();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* 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.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 Flow.Subscription subscription;
|
||||||
|
|
||||||
|
private Transmitter transmitter;
|
||||||
|
private GrafikDaten grafikDaten;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public ChatModel(GrafikDaten gDaten) {
|
||||||
|
this.grafikDaten = gDaten;
|
||||||
|
this.transmitter = null;
|
||||||
|
|
||||||
|
this.figurPublisher = new SubmissionPublisher<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTransmitter(Transmitter transmitter) {
|
||||||
|
this.transmitter = transmitter;
|
||||||
|
this.transmitter.addSubscription(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void addSubscription(Subscriber<Figur> subscriber) {
|
||||||
|
figurPublisher.subscribe(subscriber);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSubscribe(Flow.Subscription subscription) {
|
||||||
|
this.subscription = subscription;
|
||||||
|
this.subscription.request(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNext(Figur item) {
|
||||||
|
grafikDaten.addFigure(item);
|
||||||
|
lg.info("Figur wurde dem Grafikmodel hinzugefügt");
|
||||||
|
figurPublisher.submit(item);
|
||||||
|
this.subscription.request(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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
|
||||||
|
}
|
||||||
|
|
||||||
|
public GrafikDaten getGrafikDaten() {
|
||||||
|
return grafikDaten;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendFigur() {
|
||||||
|
lg.info("Sende aktuelle Figur");
|
||||||
|
transmitter.send(grafikDaten.getFiguren().getLast());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,10 +4,12 @@
|
|||||||
*/
|
*/
|
||||||
package ChatProgramm.model;
|
package ChatProgramm.model;
|
||||||
|
|
||||||
|
import ChatProgramm.util.OhmLogger;
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.logging.*;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder Class
|
* Builder Class
|
||||||
@@ -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, ChatModel model) throws IOException {
|
||||||
super(view);
|
super(view, model);
|
||||||
connect();
|
connect();
|
||||||
initIO();
|
initIO();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* 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.util.OhmLogger;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author le
|
||||||
|
*/
|
||||||
|
public class GrafikDaten {
|
||||||
|
|
||||||
|
private Figur aktuelleFigur;
|
||||||
|
private ArrayList<Figur> figuren;
|
||||||
|
private Preferences pref;
|
||||||
|
private static Logger lg = OhmLogger.getLogger();
|
||||||
|
|
||||||
|
public GrafikDaten() {
|
||||||
|
aktuelleFigur = new Figur();
|
||||||
|
figuren = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
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() {
|
||||||
|
figuren.add(aktuelleFigur);
|
||||||
|
aktuelleFigur = new Figur();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,121 +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;
|
|
||||||
|
|
||||||
import java.awt.Point;
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.BufferedOutputStream;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.ObjectInputStream;
|
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
import java.util.prefs.Preferences;
|
|
||||||
import ChatProgramm.util.OhmLogger;
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author le
|
|
||||||
*/
|
|
||||||
public class GrafikModel
|
|
||||||
{
|
|
||||||
private Figur aktuelleFigur;
|
|
||||||
private ArrayList<Figur> figuren;
|
|
||||||
private Preferences pref;
|
|
||||||
private static Logger lg = OhmLogger.getLogger();
|
|
||||||
|
|
||||||
public GrafikModel()
|
|
||||||
{
|
|
||||||
aktuelleFigur = new Figur();
|
|
||||||
figuren = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addPoint(Point p)
|
|
||||||
{
|
|
||||||
aktuelleFigur.addPoint(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 endShape() {
|
|
||||||
figuren.add(aktuelleFigur);
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,10 +5,12 @@
|
|||||||
|
|
||||||
package ChatProgramm.model;
|
package ChatProgramm.model;
|
||||||
|
|
||||||
|
import ChatProgramm.util.OhmLogger;
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.util.logging.*;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder Class
|
* Builder Class
|
||||||
@@ -16,10 +18,15 @@ 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, ChatModel model) throws IOException {
|
||||||
|
super(view, model);
|
||||||
|
connect();
|
||||||
|
initIO();
|
||||||
|
}
|
||||||
|
|
||||||
public void connect() throws IOException
|
public void connect() throws IOException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -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();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,163 +4,133 @@
|
|||||||
*/
|
*/
|
||||||
package ChatProgramm.model;
|
package ChatProgramm.model;
|
||||||
|
|
||||||
|
import ChatProgramm.controller.ReceiveAdapter;
|
||||||
|
import ChatProgramm.util.OhmLogger;
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
import java.io.*;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Flow;
|
|
||||||
import java.util.concurrent.Flow.Subscriber;
|
import java.util.concurrent.Flow.Subscriber;
|
||||||
import java.util.concurrent.SubmissionPublisher;
|
import java.util.concurrent.SubmissionPublisher;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author ahren
|
* @author ahren
|
||||||
*/
|
*/
|
||||||
public abstract class Transmitter implements Runnable, Subscriber<String>, TransmitterInterface {
|
public abstract class Transmitter implements Runnable {
|
||||||
|
|
||||||
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 BufferedReader reader;
|
protected ObjectInputStream reader;
|
||||||
protected PrintWriter writer;
|
protected ObjectOutputStream writer;
|
||||||
|
|
||||||
private Nachricht nachricht;
|
|
||||||
private String txtNachricht;
|
private SubmissionPublisher<Figur> figurPublisher;
|
||||||
private boolean laufend;
|
|
||||||
private SubmissionPublisher<Nachricht> textPublisher;
|
|
||||||
private ExecutorService eService;
|
private ExecutorService eService;
|
||||||
private String receivedString;
|
|
||||||
|
|
||||||
private ChatView view;
|
private ChatView view;
|
||||||
|
private ChatModel model;
|
||||||
|
|
||||||
private ReceiveAdapter receiveAdapter;
|
private ReceiveAdapter receiveAdapter;
|
||||||
|
|
||||||
public Transmitter(ChatView view)
|
public Transmitter(ChatView view, ChatModel model) {
|
||||||
{
|
socket = new Socket();
|
||||||
socket = new Socket();
|
eService = null;
|
||||||
eService = null;
|
|
||||||
receiveAdapter = new ReceiveAdapter(view);
|
figurPublisher = new SubmissionPublisher<>();
|
||||||
textPublisher = new SubmissionPublisher<>();
|
|
||||||
this.view = view;
|
this.view = view;
|
||||||
addWertSubscription(receiveAdapter);
|
this.model = model;
|
||||||
nachricht = new Nachricht("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addWertSubscription(Subscriber<Nachricht> subscriber)
|
public void addSubscription(Subscriber<Figur> subscriber) {
|
||||||
{
|
figurPublisher.subscribe(subscriber);
|
||||||
textPublisher.subscribe(subscriber);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void connect() throws IOException;
|
public abstract void connect() throws IOException;
|
||||||
|
|
||||||
public void initIO() {
|
public void initIO() {
|
||||||
try {
|
try {
|
||||||
lg.info("Initialisiere reader und writer");
|
lg.info("Initialisiere reader und writer");
|
||||||
InputStream is = socket.getInputStream();
|
InputStream is = socket.getInputStream();
|
||||||
OutputStream os = socket.getOutputStream();
|
OutputStream os = socket.getOutputStream();
|
||||||
|
|
||||||
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
|
writer = new ObjectOutputStream(os);
|
||||||
OutputStreamWriter osr = new OutputStreamWriter(os, "UTF-8");
|
writer.flush();
|
||||||
|
reader = new ObjectInputStream(is);
|
||||||
|
|
||||||
reader = new BufferedReader(isr);
|
lg.info("Reader / Writer Initialisierung abgeschlossen");
|
||||||
writer = new PrintWriter(osr);
|
startempfangen();
|
||||||
lg.info("Reader / Writer Initialisierung abgeschlossen");
|
|
||||||
startempfangen();
|
|
||||||
lg.info("Warte auf Nachricht");
|
|
||||||
|
|
||||||
} catch (UnsupportedEncodingException 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 (IOException ex) {
|
}
|
||||||
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(String txtNachricht){
|
|
||||||
|
|
||||||
writer.println(txtNachricht);
|
/**
|
||||||
writer.flush();
|
* @param figur
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void send(Figur figur) {
|
||||||
|
try {
|
||||||
|
writer.writeObject(figur);
|
||||||
|
writer.flush();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
lg.info("Nachricht gesendet");
|
lg.info("Nachricht gesendet");
|
||||||
nachricht.setNachricht("\nDu: " + txtNachricht);
|
figurPublisher.submit(figur);
|
||||||
textPublisher.submit(nachricht);
|
|
||||||
}
|
}
|
||||||
public Nachricht receive(){
|
|
||||||
try {
|
public Figur receive() {
|
||||||
txtNachricht = reader.readLine();
|
|
||||||
if(!txtNachricht.isEmpty()){
|
Object receivedObject;
|
||||||
lg.info("Nachricht erhalten");
|
Figur figur = new Figur();
|
||||||
nachricht.setNachricht("\nEr / Sie: " + txtNachricht);
|
try {
|
||||||
return nachricht;
|
receivedObject = reader.readObject();
|
||||||
|
|
||||||
|
if (receivedObject instanceof Figur) {
|
||||||
|
lg.info("Figur erhalten");
|
||||||
|
figur = (Figur) receivedObject;
|
||||||
|
}
|
||||||
|
} catch (IOException | ClassNotFoundException ex) {
|
||||||
|
lg.info(ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
return figur;
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
return nachricht;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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");
|
Figur figur = new Figur();
|
||||||
if(laufend) {
|
lg.info("Warte auf Nachricht");
|
||||||
nachricht = receive();
|
figur = receive();
|
||||||
if(!nachricht.getNachricht().isEmpty()){
|
if (!figur.getPunkte().isEmpty()) {
|
||||||
textPublisher.submit(nachricht);
|
figurPublisher.submit(figur);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
|
private void startempfangen() {
|
||||||
|
synchronized (this) {
|
||||||
}
|
}
|
||||||
}
|
if (eService == null) {
|
||||||
|
eService = Executors.newSingleThreadExecutor();
|
||||||
|
eService.execute(this);
|
||||||
|
}
|
||||||
|
lg.info("Starte Chat");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@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(String 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 void startempfangen()
|
|
||||||
{
|
|
||||||
synchronized (this){
|
|
||||||
laufend = true;
|
|
||||||
}
|
|
||||||
if (eService == null){
|
|
||||||
eService = Executors.newSingleThreadExecutor();
|
|
||||||
eService.execute(this);
|
|
||||||
}
|
|
||||||
lg.info("Starte Chat");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
/*
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
|
|
||||||
*/
|
|
||||||
package ChatProgramm.model;
|
|
||||||
|
|
||||||
import ChatProgramm.model.Nachricht;
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author ahren
|
|
||||||
*/
|
|
||||||
public interface TransmitterInterface
|
|
||||||
{
|
|
||||||
public void send(String txtNachricht);
|
|
||||||
public Nachricht receive();
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -107,24 +107,15 @@
|
|||||||
|
|
||||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
|
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
|
||||||
<SubComponents>
|
<SubComponents>
|
||||||
<Container class="javax.swing.JPanel" name="jPanel2">
|
<Container class="ChatProgramm.view.GrafikView" name="gvZeichenflaeche">
|
||||||
<Constraints>
|
<Constraints>
|
||||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||||
<BorderConstraints direction="Center"/>
|
<BorderConstraints direction="Center"/>
|
||||||
</Constraint>
|
</Constraint>
|
||||||
</Constraints>
|
</Constraints>
|
||||||
|
|
||||||
<Layout>
|
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
|
||||||
<DimensionLayout dim="0">
|
<Property name="useNullLayout" type="boolean" value="true"/>
|
||||||
<Group type="103" groupAlignment="0" attributes="0">
|
|
||||||
<EmptySpace min="0" pref="400" max="32767" attributes="0"/>
|
|
||||||
</Group>
|
|
||||||
</DimensionLayout>
|
|
||||||
<DimensionLayout dim="1">
|
|
||||||
<Group type="103" groupAlignment="0" attributes="0">
|
|
||||||
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
|
|
||||||
</Group>
|
|
||||||
</DimensionLayout>
|
|
||||||
</Layout>
|
</Layout>
|
||||||
</Container>
|
</Container>
|
||||||
</SubComponents>
|
</SubComponents>
|
||||||
|
|||||||
@@ -11,6 +11,14 @@ package ChatProgramm.view;
|
|||||||
public class ChatView extends javax.swing.JFrame
|
public class ChatView extends javax.swing.JFrame
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the gvZeichenflaeche
|
||||||
|
*/
|
||||||
|
public ChatProgramm.view.GrafikView getGvZeichenflaeche()
|
||||||
|
{
|
||||||
|
return gvZeichenflaeche;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new form ChatView
|
* Creates new form ChatView
|
||||||
*/
|
*/
|
||||||
@@ -25,91 +33,88 @@ public class ChatView extends javax.swing.JFrame
|
|||||||
* regenerated by the Form Editor.
|
* regenerated by the Form Editor.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||||
private void initComponents() {
|
private void initComponents()
|
||||||
|
{
|
||||||
|
|
||||||
dialogChooseMode = new javax.swing.JDialog();
|
dialogChooseMode = new javax.swing.JDialog();
|
||||||
lblMode = new javax.swing.JLabel();
|
lblMode = new javax.swing.JLabel();
|
||||||
BtnServer = new javax.swing.JRadioButton();
|
BtnServer = new javax.swing.JRadioButton();
|
||||||
BtnClient = new javax.swing.JRadioButton();
|
BtnClient = new javax.swing.JRadioButton();
|
||||||
jPanel1 = new javax.swing.JPanel();
|
jPanel1 = new javax.swing.JPanel();
|
||||||
BtnConnect = new javax.swing.JButton();
|
BtnConnect = new javax.swing.JButton();
|
||||||
BtnGrpMode = new javax.swing.ButtonGroup();
|
BtnGrpMode = new javax.swing.ButtonGroup();
|
||||||
jPanel2 = new javax.swing.JPanel();
|
gvZeichenflaeche = new ChatProgramm.view.GrafikView();
|
||||||
|
|
||||||
dialogChooseMode.setMinimumSize(new java.awt.Dimension(278, 208));
|
dialogChooseMode.setMinimumSize(new java.awt.Dimension(278, 208));
|
||||||
dialogChooseMode.getContentPane().setLayout(new java.awt.GridLayout(0, 1));
|
dialogChooseMode.getContentPane().setLayout(new java.awt.GridLayout(0, 1));
|
||||||
|
|
||||||
lblMode.setText(" Choose your mode:");
|
lblMode.setText(" Choose your mode:");
|
||||||
dialogChooseMode.getContentPane().add(lblMode);
|
dialogChooseMode.getContentPane().add(lblMode);
|
||||||
|
|
||||||
BtnGrpMode.add(BtnServer);
|
BtnGrpMode.add(BtnServer);
|
||||||
BtnServer.setText("Server");
|
BtnServer.setText("Server");
|
||||||
BtnServer.addActionListener(new java.awt.event.ActionListener() {
|
BtnServer.addActionListener(new java.awt.event.ActionListener()
|
||||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
{
|
||||||
BtnServerActionPerformed(evt);
|
public void actionPerformed(java.awt.event.ActionEvent evt)
|
||||||
}
|
{
|
||||||
});
|
BtnServerActionPerformed(evt);
|
||||||
dialogChooseMode.getContentPane().add(BtnServer);
|
}
|
||||||
|
});
|
||||||
|
dialogChooseMode.getContentPane().add(BtnServer);
|
||||||
|
|
||||||
BtnGrpMode.add(BtnClient);
|
BtnGrpMode.add(BtnClient);
|
||||||
BtnClient.setText("Client");
|
BtnClient.setText("Client");
|
||||||
BtnClient.addActionListener(new java.awt.event.ActionListener() {
|
BtnClient.addActionListener(new java.awt.event.ActionListener()
|
||||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
{
|
||||||
BtnClientActionPerformed(evt);
|
public void actionPerformed(java.awt.event.ActionEvent evt)
|
||||||
}
|
{
|
||||||
});
|
BtnClientActionPerformed(evt);
|
||||||
dialogChooseMode.getContentPane().add(BtnClient);
|
}
|
||||||
|
});
|
||||||
|
dialogChooseMode.getContentPane().add(BtnClient);
|
||||||
|
|
||||||
BtnConnect.setText("Connect");
|
BtnConnect.setText("Connect");
|
||||||
BtnConnect.addActionListener(new java.awt.event.ActionListener() {
|
BtnConnect.addActionListener(new java.awt.event.ActionListener()
|
||||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
{
|
||||||
BtnConnectActionPerformed(evt);
|
public void actionPerformed(java.awt.event.ActionEvent evt)
|
||||||
}
|
{
|
||||||
});
|
BtnConnectActionPerformed(evt);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
|
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
|
||||||
jPanel1.setLayout(jPanel1Layout);
|
jPanel1.setLayout(jPanel1Layout);
|
||||||
jPanel1Layout.setHorizontalGroup(
|
jPanel1Layout.setHorizontalGroup(
|
||||||
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||||
.addContainerGap(65, Short.MAX_VALUE)
|
.addContainerGap(65, Short.MAX_VALUE)
|
||||||
.addComponent(BtnConnect)
|
.addComponent(BtnConnect)
|
||||||
.addContainerGap(76, Short.MAX_VALUE))
|
.addContainerGap(76, Short.MAX_VALUE))
|
||||||
);
|
);
|
||||||
jPanel1Layout.setVerticalGroup(
|
jPanel1Layout.setVerticalGroup(
|
||||||
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||||
.addContainerGap()
|
.addContainerGap()
|
||||||
.addComponent(BtnConnect)
|
.addComponent(BtnConnect)
|
||||||
.addContainerGap(57, Short.MAX_VALUE))
|
.addContainerGap(57, Short.MAX_VALUE))
|
||||||
);
|
);
|
||||||
|
|
||||||
dialogChooseMode.getContentPane().add(jPanel1);
|
dialogChooseMode.getContentPane().add(jPanel1);
|
||||||
|
|
||||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||||
setMinimumSize(new java.awt.Dimension(568, 548));
|
setMinimumSize(new java.awt.Dimension(568, 548));
|
||||||
addWindowListener(new java.awt.event.WindowAdapter() {
|
addWindowListener(new java.awt.event.WindowAdapter()
|
||||||
public void windowOpened(java.awt.event.WindowEvent evt) {
|
{
|
||||||
formWindowOpened(evt);
|
public void windowOpened(java.awt.event.WindowEvent evt)
|
||||||
}
|
{
|
||||||
});
|
formWindowOpened(evt);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
getContentPane().add(gvZeichenflaeche, java.awt.BorderLayout.CENTER);
|
||||||
|
|
||||||
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
|
pack();
|
||||||
jPanel2.setLayout(jPanel2Layout);
|
}// </editor-fold>//GEN-END:initComponents
|
||||||
jPanel2Layout.setHorizontalGroup(
|
|
||||||
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
||||||
.addGap(0, 400, Short.MAX_VALUE)
|
|
||||||
);
|
|
||||||
jPanel2Layout.setVerticalGroup(
|
|
||||||
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
||||||
.addGap(0, 300, Short.MAX_VALUE)
|
|
||||||
);
|
|
||||||
|
|
||||||
getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
|
|
||||||
|
|
||||||
pack();
|
|
||||||
}// </editor-fold>//GEN-END:initComponents
|
|
||||||
|
|
||||||
private void BtnClientActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_BtnClientActionPerformed
|
private void BtnClientActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_BtnClientActionPerformed
|
||||||
{//GEN-HEADEREND:event_BtnClientActionPerformed
|
{//GEN-HEADEREND:event_BtnClientActionPerformed
|
||||||
@@ -180,16 +185,16 @@ public class ChatView extends javax.swing.JFrame
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
private javax.swing.JRadioButton BtnClient;
|
private javax.swing.JRadioButton BtnClient;
|
||||||
private javax.swing.JButton BtnConnect;
|
private javax.swing.JButton BtnConnect;
|
||||||
private javax.swing.ButtonGroup BtnGrpMode;
|
private javax.swing.ButtonGroup BtnGrpMode;
|
||||||
private javax.swing.JRadioButton BtnServer;
|
private javax.swing.JRadioButton BtnServer;
|
||||||
private javax.swing.JDialog dialogChooseMode;
|
private javax.swing.JDialog dialogChooseMode;
|
||||||
private javax.swing.JPanel jPanel1;
|
private ChatProgramm.view.GrafikView gvZeichenflaeche;
|
||||||
private javax.swing.JPanel jPanel2;
|
private javax.swing.JPanel jPanel1;
|
||||||
private javax.swing.JLabel lblMode;
|
private javax.swing.JLabel lblMode;
|
||||||
// End of variables declaration//GEN-END:variables
|
// End of variables declaration//GEN-END:variables
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the BtnClient
|
* @return the BtnClient
|
||||||
|
|||||||
@@ -1,89 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
|
|
||||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
|
||||||
<NonVisualComponents>
|
|
||||||
<Component class="javax.swing.JFileChooser" name="FcFileChooser">
|
|
||||||
</Component>
|
|
||||||
</NonVisualComponents>
|
|
||||||
<Properties>
|
|
||||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
|
||||||
</Properties>
|
|
||||||
<SyntheticProperties>
|
|
||||||
<SyntheticProperty name="formSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,-100,0,0,2,28"/>
|
|
||||||
<SyntheticProperty name="formSizePolicy" type="int" value="0"/>
|
|
||||||
<SyntheticProperty name="generateSize" type="boolean" value="true"/>
|
|
||||||
<SyntheticProperty name="generateCenter" type="boolean" value="true"/>
|
|
||||||
</SyntheticProperties>
|
|
||||||
<AuxValues>
|
|
||||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
|
||||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
|
||||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
|
||||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
|
||||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
|
||||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
|
||||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
|
||||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
|
||||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
|
||||||
</AuxValues>
|
|
||||||
|
|
||||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
|
|
||||||
<SubComponents>
|
|
||||||
<Container class="mvcgrafik.view.GrafikView" name="gZeichenflaeche">
|
|
||||||
<Constraints>
|
|
||||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
|
||||||
<BorderConstraints direction="Center"/>
|
|
||||||
</Constraint>
|
|
||||||
</Constraints>
|
|
||||||
|
|
||||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
|
|
||||||
<Property name="useNullLayout" type="boolean" value="true"/>
|
|
||||||
</Layout>
|
|
||||||
</Container>
|
|
||||||
<Container class="javax.swing.JToolBar" name="jToolBar1">
|
|
||||||
<Properties>
|
|
||||||
<Property name="rollover" type="boolean" value="true"/>
|
|
||||||
</Properties>
|
|
||||||
<Constraints>
|
|
||||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
|
||||||
<BorderConstraints direction="First"/>
|
|
||||||
</Constraint>
|
|
||||||
</Constraints>
|
|
||||||
|
|
||||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout"/>
|
|
||||||
<SubComponents>
|
|
||||||
<Component class="javax.swing.JButton" name="btnFileOpen">
|
|
||||||
<Properties>
|
|
||||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
|
||||||
<Image iconType="3" name="/mvcgrafik/view/Open24.gif"/>
|
|
||||||
</Property>
|
|
||||||
<Property name="toolTipText" type="java.lang.String" value="Open File"/>
|
|
||||||
<Property name="focusable" type="boolean" value="false"/>
|
|
||||||
<Property name="horizontalTextPosition" type="int" value="0"/>
|
|
||||||
<Property name="verticalTextPosition" type="int" value="3"/>
|
|
||||||
</Properties>
|
|
||||||
</Component>
|
|
||||||
<Component class="javax.swing.JButton" name="btnFileSave">
|
|
||||||
<Properties>
|
|
||||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
|
||||||
<Image iconType="3" name="/mvcgrafik/view/Save24.gif"/>
|
|
||||||
</Property>
|
|
||||||
<Property name="toolTipText" type="java.lang.String" value="Safe File"/>
|
|
||||||
<Property name="horizontalTextPosition" type="int" value="0"/>
|
|
||||||
<Property name="verticalTextPosition" type="int" value="3"/>
|
|
||||||
</Properties>
|
|
||||||
</Component>
|
|
||||||
<Component class="javax.swing.JButton" name="btnPrint">
|
|
||||||
<Properties>
|
|
||||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
|
||||||
<Image iconType="3" name="/mvcgrafik/view/Print24.gif"/>
|
|
||||||
</Property>
|
|
||||||
<Property name="toolTipText" type="java.lang.String" value="Print File"/>
|
|
||||||
<Property name="focusable" type="boolean" value="false"/>
|
|
||||||
<Property name="horizontalTextPosition" type="int" value="0"/>
|
|
||||||
<Property name="verticalTextPosition" type="int" value="3"/>
|
|
||||||
</Properties>
|
|
||||||
</Component>
|
|
||||||
</SubComponents>
|
|
||||||
</Container>
|
|
||||||
</SubComponents>
|
|
||||||
</Form>
|
|
||||||
@@ -1,165 +0,0 @@
|
|||||||
/*
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
|
|
||||||
*/
|
|
||||||
package ChatProgramm.view;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author le
|
|
||||||
*/
|
|
||||||
public class GrafikFrame extends javax.swing.JFrame
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the FcFileChooser
|
|
||||||
*/
|
|
||||||
public javax.swing.JFileChooser getFcFileChooser()
|
|
||||||
{
|
|
||||||
return FcFileChooser;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the btnFileOpen
|
|
||||||
*/
|
|
||||||
public javax.swing.JButton getBtnFileOpen()
|
|
||||||
{
|
|
||||||
return btnFileOpen;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the btnFileSave
|
|
||||||
*/
|
|
||||||
public javax.swing.JButton getBtnFileSave()
|
|
||||||
{
|
|
||||||
return btnFileSave;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @return the gZeichenflaeche
|
|
||||||
*/
|
|
||||||
public mvcgrafik.view.GrafikView getgZeichenflaeche()
|
|
||||||
{
|
|
||||||
return gZeichenflaeche;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates new form GrafikFrame
|
|
||||||
*/
|
|
||||||
public GrafikFrame()
|
|
||||||
{
|
|
||||||
initComponents();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is called from within the constructor to initialize the form.
|
|
||||||
* WARNING: Do NOT modify this code. The content of this method is always
|
|
||||||
* regenerated by the Form Editor.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
|
||||||
private void initComponents() {
|
|
||||||
|
|
||||||
FcFileChooser = new javax.swing.JFileChooser();
|
|
||||||
gZeichenflaeche = new mvcgrafik.view.GrafikView();
|
|
||||||
jToolBar1 = new javax.swing.JToolBar();
|
|
||||||
btnFileOpen = new javax.swing.JButton();
|
|
||||||
btnFileSave = new javax.swing.JButton();
|
|
||||||
btnPrint = new javax.swing.JButton();
|
|
||||||
|
|
||||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
|
||||||
getContentPane().add(gZeichenflaeche, java.awt.BorderLayout.CENTER);
|
|
||||||
|
|
||||||
jToolBar1.setRollover(true);
|
|
||||||
|
|
||||||
btnFileOpen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mvcgrafik/view/Open24.gif"))); // NOI18N
|
|
||||||
btnFileOpen.setToolTipText("Open File");
|
|
||||||
btnFileOpen.setFocusable(false);
|
|
||||||
btnFileOpen.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
|
|
||||||
btnFileOpen.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
|
|
||||||
jToolBar1.add(btnFileOpen);
|
|
||||||
|
|
||||||
btnFileSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mvcgrafik/view/Save24.gif"))); // NOI18N
|
|
||||||
btnFileSave.setToolTipText("Safe File");
|
|
||||||
btnFileSave.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
|
|
||||||
btnFileSave.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
|
|
||||||
jToolBar1.add(btnFileSave);
|
|
||||||
|
|
||||||
btnPrint.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mvcgrafik/view/Print24.gif"))); // NOI18N
|
|
||||||
btnPrint.setToolTipText("Print File");
|
|
||||||
btnPrint.setFocusable(false);
|
|
||||||
btnPrint.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
|
|
||||||
btnPrint.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
|
|
||||||
jToolBar1.add(btnPrint);
|
|
||||||
|
|
||||||
getContentPane().add(jToolBar1, java.awt.BorderLayout.PAGE_START);
|
|
||||||
|
|
||||||
setSize(new java.awt.Dimension(540, 412));
|
|
||||||
setLocationRelativeTo(null);
|
|
||||||
}// </editor-fold>//GEN-END:initComponents
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param args the command line arguments
|
|
||||||
*/
|
|
||||||
public static void main(String args[])
|
|
||||||
{
|
|
||||||
/* Set the Nimbus look and feel */
|
|
||||||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
|
||||||
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
|
|
||||||
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
|
|
||||||
*/
|
|
||||||
try
|
|
||||||
{
|
|
||||||
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
|
|
||||||
{
|
|
||||||
if ("Nimbus".equals(info.getName()))
|
|
||||||
{
|
|
||||||
javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (ClassNotFoundException ex)
|
|
||||||
{
|
|
||||||
java.util.logging.Logger.getLogger(GrafikFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
catch (InstantiationException ex)
|
|
||||||
{
|
|
||||||
java.util.logging.Logger.getLogger(GrafikFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
catch (IllegalAccessException ex)
|
|
||||||
{
|
|
||||||
java.util.logging.Logger.getLogger(GrafikFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
catch (javax.swing.UnsupportedLookAndFeelException ex)
|
|
||||||
{
|
|
||||||
java.util.logging.Logger.getLogger(GrafikFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
//</editor-fold>
|
|
||||||
//</editor-fold>
|
|
||||||
|
|
||||||
/* Create and display the form */
|
|
||||||
java.awt.EventQueue.invokeLater(new Runnable()
|
|
||||||
{
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
new GrafikFrame().setVisible(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
|
||||||
private javax.swing.JFileChooser FcFileChooser;
|
|
||||||
private javax.swing.JButton btnFileOpen;
|
|
||||||
private javax.swing.JButton btnFileSave;
|
|
||||||
private javax.swing.JButton btnPrint;
|
|
||||||
private mvcgrafik.view.GrafikView gZeichenflaeche;
|
|
||||||
private javax.swing.JToolBar jToolBar1;
|
|
||||||
// End of variables declaration//GEN-END:variables
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the btnPrint
|
|
||||||
*/
|
|
||||||
public javax.swing.JButton getBtnPrint() {
|
|
||||||
return btnPrint;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -22,7 +22,7 @@ import javax.print.attribute.HashPrintRequestAttributeSet;
|
|||||||
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;
|
||||||
|
|
||||||
|
|
||||||
@@ -30,13 +30,13 @@ 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
|
||||||
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;
|
||||||
@@ -47,7 +47,7 @@ public class GrafikView extends JComponent implements Printable
|
|||||||
line = new Line2D.Float();
|
line = new Line2D.Float();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setModel(GrafikModel model)
|
public void setModel(GrafikDaten model)
|
||||||
{
|
{
|
||||||
this.model = model;
|
this.model = model;
|
||||||
}
|
}
|
||||||
@@ -58,13 +58,22 @@ 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!
|
||||||
|
|
||||||
drawPath(model.getPunkte(),g2);
|
drawPath(model.getPunkte(),g2);
|
||||||
|
|
||||||
g2.dispose(); //SEEEEHHHHRRRR WICHTIG!!!!!!!
|
g2.dispose(); //SEEEEHHHHRRRR WICHTIG!!!!!!!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -87,7 +96,7 @@ public class GrafikView extends JComponent implements Printable
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawPath(List<Point> path, Graphics2D g2){
|
public void drawPath(List<Point> path, Graphics2D g2){
|
||||||
from = path.getFirst();
|
from = path.getFirst();
|
||||||
to = null;
|
to = null;
|
||||||
|
|
||||||
@@ -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