Compare commits
21
Commits
22efa7c18f
...
JensV2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
928e6ae1af | ||
|
|
a5b238fe4f | ||
|
|
75e458a4ac | ||
|
|
68eb43c715 | ||
|
|
541b497796 | ||
|
|
43de325d71 | ||
|
|
0e71917727 | ||
|
|
dc1f783e00 | ||
|
|
2fc05ae87f | ||
|
|
5117ecdb6f | ||
|
|
a4a45ed5f2 | ||
|
|
6642dc8179 | ||
|
|
f05b0f0014 | ||
|
|
1aa5b51e78 | ||
|
|
ba0f12561b | ||
|
|
e7034fc7a4 | ||
|
|
19fd23c638 | ||
|
|
f7a0de0041 | ||
|
|
0da0f2cc5b | ||
|
|
64a6047ca4 | ||
|
|
78c5d8eedf |
No files matched your search
@@ -0,0 +1,3 @@
|
||||
/nbproject/private/
|
||||
/build/
|
||||
/dist/
|
||||
@@ -1067,6 +1067,15 @@ is divided into following sections:
|
||||
<propertyfile file="${built-jar.properties}">
|
||||
<entry key="${basedir}" value=""/>
|
||||
</propertyfile>
|
||||
<antcall target="-maybe-call-dep">
|
||||
<param name="call.built.properties" value="${built-jar.properties}"/>
|
||||
<param location="${project.Aufgabe9_mvcGrafik}" name="call.subproject"/>
|
||||
<param location="${project.Aufgabe9_mvcGrafik}/build.xml" name="call.script"/>
|
||||
<param name="call.target" value="jar"/>
|
||||
<param name="transfer.built-jar.properties" value="${built-jar.properties}"/>
|
||||
<param name="transfer.not.archive.disabled" value="true"/>
|
||||
<param name="transfer.do.jlink" value="false"/>
|
||||
</antcall>
|
||||
</target>
|
||||
<target depends="init,-check-automatic-build,-clean-after-automatic-build" name="-verify-automatic-build"/>
|
||||
<target depends="init" name="-check-automatic-build">
|
||||
@@ -1738,6 +1747,15 @@ is divided into following sections:
|
||||
<propertyfile file="${built-clean.properties}">
|
||||
<entry key="${basedir}" value=""/>
|
||||
</propertyfile>
|
||||
<antcall target="-maybe-call-dep">
|
||||
<param name="call.built.properties" value="${built-clean.properties}"/>
|
||||
<param location="${project.Aufgabe9_mvcGrafik}" name="call.subproject"/>
|
||||
<param location="${project.Aufgabe9_mvcGrafik}/build.xml" name="call.script"/>
|
||||
<param name="call.target" value="clean"/>
|
||||
<param name="transfer.built-clean.properties" value="${built-clean.properties}"/>
|
||||
<param name="transfer.not.archive.disabled" value="true"/>
|
||||
<param name="transfer.do.jlink" value="false"/>
|
||||
</antcall>
|
||||
</target>
|
||||
<target depends="init" name="-do-clean">
|
||||
<delete dir="${build.dir}"/>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
build.xml.data.CRC32=05f3ad23
|
||||
build.xml.data.CRC32=d624b1fd
|
||||
build.xml.script.CRC32=1a88b66a
|
||||
build.xml.stylesheet.CRC32=f85dc8f2@1.108.0.48
|
||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||
nbproject/build-impl.xml.data.CRC32=05f3ad23
|
||||
nbproject/build-impl.xml.script.CRC32=fdc076e6
|
||||
nbproject/build-impl.xml.data.CRC32=d624b1fd
|
||||
nbproject/build-impl.xml.script.CRC32=476a1ac9
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.108.0.48
|
||||
@@ -37,7 +37,8 @@ endorsed.classpath=
|
||||
excludes=
|
||||
includes=**
|
||||
jar.compress=false
|
||||
javac.classpath=
|
||||
javac.classpath=\
|
||||
${reference.Aufgabe9_mvcGrafik.jar}
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=
|
||||
javac.deprecation=false
|
||||
@@ -78,6 +79,8 @@ manifest.file=manifest.mf
|
||||
meta.inf.dir=${src.dir}/META-INF
|
||||
mkdist.disabled=false
|
||||
platform.active=default_platform
|
||||
project.Aufgabe9_mvcGrafik=../../T9_mvcGrafik/Aufgabe9_mvcGrafik
|
||||
reference.Aufgabe9_mvcGrafik.jar=${project.Aufgabe9_mvcGrafik}/dist/Aufgabe9_mvcGrafik.jar
|
||||
run.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
|
||||
@@ -11,5 +11,15 @@
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
<references xmlns="http://www.netbeans.org/ns/ant-project-references/1">
|
||||
<reference>
|
||||
<foreign-project>Aufgabe9_mvcGrafik</foreign-project>
|
||||
<artifact-type>jar</artifact-type>
|
||||
<script>build.xml</script>
|
||||
<target>jar</target>
|
||||
<clean-target>clean</clean-target>
|
||||
<id>jar</id>
|
||||
</reference>
|
||||
</references>
|
||||
</configuration>
|
||||
</project>
|
||||
@@ -5,8 +5,14 @@
|
||||
|
||||
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.GrafikView;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
@@ -18,10 +24,26 @@ public class Start
|
||||
{
|
||||
public Start()
|
||||
{
|
||||
GrafikDaten gDaten = new GrafikDaten();
|
||||
ChatView view = new ChatView();
|
||||
CommandController controller_commands = new CommandController(view);
|
||||
controller_commands.registerEvents();
|
||||
controller_commands.registerCommands();
|
||||
GrafikView zeichenflaeche = view.getGvZeichenflaeche();
|
||||
zeichenflaeche.setModel(gDaten);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,56 +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);
|
||||
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
-7
@@ -2,23 +2,33 @@
|
||||
* 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;
|
||||
package ChatProgramm.controller;
|
||||
|
||||
import ChatProgramm.model.ChatModel;
|
||||
import ChatProgramm.model.Figur;
|
||||
import ChatProgramm.util.OhmLogger;
|
||||
import ChatProgramm.view.ChatView;
|
||||
import ChatProgramm.view.GrafikView;
|
||||
import java.util.concurrent.Flow;
|
||||
import java.util.concurrent.Flow.Subscriber;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
public class ReceiveAdapter implements Subscriber<Nachricht> {
|
||||
public class ReceiveAdapter implements Subscriber<Figur> {
|
||||
|
||||
private static Logger lg = OhmLogger.getLogger();
|
||||
|
||||
private ChatView view;
|
||||
private ChatModel model;
|
||||
|
||||
private Flow.Subscription subscription;
|
||||
|
||||
public ReceiveAdapter(ChatView view) {
|
||||
public ReceiveAdapter(ChatView view, ChatModel model) {
|
||||
this.view = view;
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -27,10 +37,9 @@ public class ReceiveAdapter implements Subscriber<Nachricht> {
|
||||
this.subscription.request(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(Nachricht item) {
|
||||
|
||||
view.getTxtChat().append(item.getNachricht());
|
||||
public void onNext(Figur item) {
|
||||
view.getGvZeichenflaeche().drawFigur();
|
||||
lg.info("Figur auf die Zeichenfläche projiziert");
|
||||
this.subscription.request(1);
|
||||
}
|
||||
|
||||
@@ -41,4 +50,5 @@ public class ReceiveAdapter implements Subscriber<Nachricht> {
|
||||
@Override
|
||||
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,61 +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;
|
||||
this.eingabeFeld = view.getTfNachricht();
|
||||
transmitterInterface = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute()
|
||||
{
|
||||
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;
|
||||
|
||||
import ChatProgramm.util.OhmLogger;
|
||||
import ChatProgramm.view.ChatView;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.util.logging.*;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Builder Class
|
||||
@@ -16,13 +18,13 @@ import java.util.logging.*;
|
||||
*/
|
||||
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 String IP = "127.0.0.1";
|
||||
|
||||
|
||||
public Client(ChatView view) throws IOException {
|
||||
super(view);
|
||||
public Client(ChatView view, ChatModel model) throws IOException {
|
||||
super(view, model);
|
||||
connect();
|
||||
initIO();
|
||||
}
|
||||
|
||||
@@ -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.model;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
public class Figur implements Serializable
|
||||
{
|
||||
private ArrayList<Point> punkte;
|
||||
|
||||
public Figur(){
|
||||
punkte = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addPoint(Point p){
|
||||
punkte.add(p);
|
||||
}
|
||||
|
||||
public List<Point> getPunkte()
|
||||
{
|
||||
return Collections.unmodifiableList(punkte);
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
punkte.clear();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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,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;
|
||||
|
||||
import ChatProgramm.util.OhmLogger;
|
||||
import ChatProgramm.view.ChatView;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.logging.*;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Builder Class
|
||||
@@ -16,10 +18,15 @@ import java.util.logging.*;
|
||||
*/
|
||||
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¹⁵
|
||||
|
||||
|
||||
public Server(ChatView view, ChatModel model) throws IOException {
|
||||
super(view, model);
|
||||
connect();
|
||||
initIO();
|
||||
}
|
||||
|
||||
public void connect() throws IOException
|
||||
{
|
||||
try
|
||||
@@ -34,12 +41,5 @@ public class Server extends Transmitter
|
||||
{
|
||||
lg.warning("Timeout"+"("+timeout/1000+"s)");
|
||||
}
|
||||
}
|
||||
public Server(ChatView view) throws IOException {
|
||||
super(view);
|
||||
connect();
|
||||
initIO();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,163 +4,133 @@
|
||||
*/
|
||||
package ChatProgramm.model;
|
||||
|
||||
import ChatProgramm.controller.ReceiveAdapter;
|
||||
import ChatProgramm.util.OhmLogger;
|
||||
import ChatProgramm.view.ChatView;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
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.io.*;
|
||||
import java.net.Socket;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Flow;
|
||||
import java.util.concurrent.Flow.Subscriber;
|
||||
import java.util.concurrent.SubmissionPublisher;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
public abstract class Transmitter implements Runnable, Subscriber<String>, TransmitterInterface {
|
||||
public abstract class Transmitter implements Runnable {
|
||||
|
||||
static final int timeout = 60000;
|
||||
private static final int PORT = 35000;
|
||||
|
||||
private static Logger lg = Logger.getLogger("netz");
|
||||
private static Logger lg = OhmLogger.getLogger();
|
||||
|
||||
protected Socket socket;
|
||||
protected BufferedReader reader;
|
||||
protected PrintWriter writer;
|
||||
|
||||
private Nachricht nachricht;
|
||||
private String txtNachricht;
|
||||
private boolean laufend;
|
||||
private SubmissionPublisher<Nachricht> textPublisher;
|
||||
protected ObjectInputStream reader;
|
||||
protected ObjectOutputStream writer;
|
||||
|
||||
|
||||
private SubmissionPublisher<Figur> figurPublisher;
|
||||
private ExecutorService eService;
|
||||
private String receivedString;
|
||||
|
||||
|
||||
private ChatView view;
|
||||
private ChatModel model;
|
||||
|
||||
private ReceiveAdapter receiveAdapter;
|
||||
|
||||
public Transmitter(ChatView view)
|
||||
{
|
||||
socket = new Socket();
|
||||
eService = null;
|
||||
receiveAdapter = new ReceiveAdapter(view);
|
||||
textPublisher = new SubmissionPublisher<>();
|
||||
this.view = view;
|
||||
addWertSubscription(receiveAdapter);
|
||||
nachricht = new Nachricht("");
|
||||
|
||||
public Transmitter(ChatView view, ChatModel model) {
|
||||
socket = new Socket();
|
||||
eService = null;
|
||||
|
||||
figurPublisher = new SubmissionPublisher<>();
|
||||
|
||||
this.view = view;
|
||||
this.model = model;
|
||||
|
||||
}
|
||||
|
||||
public void addWertSubscription(Subscriber<Nachricht> subscriber)
|
||||
{
|
||||
textPublisher.subscribe(subscriber);
|
||||
|
||||
public void addSubscription(Subscriber<Figur> subscriber) {
|
||||
figurPublisher.subscribe(subscriber);
|
||||
}
|
||||
|
||||
public abstract void connect() throws IOException;
|
||||
|
||||
public void initIO() {
|
||||
try {
|
||||
lg.info("Initialisiere reader und writer");
|
||||
InputStream is = socket.getInputStream();
|
||||
OutputStream os = socket.getOutputStream();
|
||||
try {
|
||||
lg.info("Initialisiere reader und writer");
|
||||
InputStream is = socket.getInputStream();
|
||||
OutputStream os = socket.getOutputStream();
|
||||
|
||||
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
|
||||
OutputStreamWriter osr = new OutputStreamWriter(os, "UTF-8");
|
||||
writer = new ObjectOutputStream(os);
|
||||
writer.flush();
|
||||
reader = new ObjectInputStream(is);
|
||||
|
||||
reader = new BufferedReader(isr);
|
||||
writer = new PrintWriter(osr);
|
||||
lg.info("Reader / Writer Initialisierung abgeschlossen");
|
||||
startempfangen();
|
||||
lg.info("Warte auf Nachricht");
|
||||
lg.info("Reader / Writer Initialisierung abgeschlossen");
|
||||
startempfangen();
|
||||
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (IOException 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");
|
||||
nachricht.setNachricht("\nDu: " + txtNachricht);
|
||||
textPublisher.submit(nachricht);
|
||||
figurPublisher.submit(figur);
|
||||
}
|
||||
public Nachricht receive(){
|
||||
try {
|
||||
txtNachricht = reader.readLine();
|
||||
if(!txtNachricht.isEmpty()){
|
||||
lg.info("Nachricht erhalten");
|
||||
nachricht.setNachricht("\nEr / Sie: " + txtNachricht);
|
||||
return nachricht;
|
||||
|
||||
public Figur receive() {
|
||||
|
||||
Object receivedObject;
|
||||
Figur figur = new Figur();
|
||||
try {
|
||||
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) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return nachricht;
|
||||
return figur;
|
||||
|
||||
}
|
||||
|
||||
// public void disconnect (){
|
||||
// in.close();
|
||||
// out.close();
|
||||
// s.close();
|
||||
// }
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
lg.info("Warte auf Nachricht");
|
||||
if(laufend) {
|
||||
nachricht = receive();
|
||||
if(!nachricht.getNachricht().isEmpty()){
|
||||
textPublisher.submit(nachricht);
|
||||
}
|
||||
while (true) {
|
||||
Figur figur = new Figur();
|
||||
lg.info("Warte auf Nachricht");
|
||||
figur = receive();
|
||||
if (!figur.getPunkte().isEmpty()) {
|
||||
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,45 +107,16 @@
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JTextField" name="tfNachricht">
|
||||
<Properties>
|
||||
<Property name="toolTipText" type="java.lang.String" value=""/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="tfNachrichtMouseClicked"/>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="tfNachrichtActionPerformed"/>
|
||||
</Events>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
<BorderConstraints direction="Last"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
<Container class="javax.swing.JScrollPane" name="jScrollPane2">
|
||||
<Properties>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[238, 150]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
|
||||
</AuxValues>
|
||||
<Container class="ChatProgramm.view.GrafikView" name="gvZeichenflaeche">
|
||||
<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.support.JScrollPaneSupportLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JTextArea" name="txtChat">
|
||||
<Properties>
|
||||
<Property name="columns" type="int" value="20"/>
|
||||
<Property name="rows" type="int" value="5"/>
|
||||
<Property name="text" type="java.lang.String" value="Chat:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
|
||||
<Property name="useNullLayout" type="boolean" value="true"/>
|
||||
</Layout>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
@@ -11,6 +11,14 @@ package ChatProgramm.view;
|
||||
public class ChatView extends javax.swing.JFrame
|
||||
{
|
||||
|
||||
/**
|
||||
* @return the gvZeichenflaeche
|
||||
*/
|
||||
public ChatProgramm.view.GrafikView getGvZeichenflaeche()
|
||||
{
|
||||
return gvZeichenflaeche;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new form ChatView
|
||||
*/
|
||||
@@ -36,9 +44,7 @@ public class ChatView extends javax.swing.JFrame
|
||||
jPanel1 = new javax.swing.JPanel();
|
||||
BtnConnect = new javax.swing.JButton();
|
||||
BtnGrpMode = new javax.swing.ButtonGroup();
|
||||
tfNachricht = new javax.swing.JTextField();
|
||||
jScrollPane2 = new javax.swing.JScrollPane();
|
||||
txtChat = new javax.swing.JTextArea();
|
||||
gvZeichenflaeche = new ChatProgramm.view.GrafikView();
|
||||
|
||||
dialogChooseMode.setMinimumSize(new java.awt.Dimension(278, 208));
|
||||
dialogChooseMode.getContentPane().setLayout(new java.awt.GridLayout(0, 1));
|
||||
@@ -105,32 +111,7 @@ public class ChatView extends javax.swing.JFrame
|
||||
formWindowOpened(evt);
|
||||
}
|
||||
});
|
||||
|
||||
tfNachricht.setToolTipText("");
|
||||
tfNachricht.addMouseListener(new java.awt.event.MouseAdapter()
|
||||
{
|
||||
public void mouseClicked(java.awt.event.MouseEvent evt)
|
||||
{
|
||||
tfNachrichtMouseClicked(evt);
|
||||
}
|
||||
});
|
||||
tfNachricht.addActionListener(new java.awt.event.ActionListener()
|
||||
{
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt)
|
||||
{
|
||||
tfNachrichtActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
getContentPane().add(tfNachricht, java.awt.BorderLayout.PAGE_END);
|
||||
|
||||
jScrollPane2.setPreferredSize(new java.awt.Dimension(238, 150));
|
||||
|
||||
txtChat.setColumns(20);
|
||||
txtChat.setRows(5);
|
||||
txtChat.setText("Chat:");
|
||||
jScrollPane2.setViewportView(txtChat);
|
||||
|
||||
getContentPane().add(jScrollPane2, java.awt.BorderLayout.CENTER);
|
||||
getContentPane().add(gvZeichenflaeche, java.awt.BorderLayout.CENTER);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
@@ -145,21 +126,11 @@ public class ChatView extends javax.swing.JFrame
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_BtnServerActionPerformed
|
||||
|
||||
private void tfNachrichtActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_tfNachrichtActionPerformed
|
||||
{//GEN-HEADEREND:event_tfNachrichtActionPerformed
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_tfNachrichtActionPerformed
|
||||
|
||||
private void formWindowOpened(java.awt.event.WindowEvent evt)//GEN-FIRST:event_formWindowOpened
|
||||
{//GEN-HEADEREND:event_formWindowOpened
|
||||
dialogChooseMode.show();
|
||||
}//GEN-LAST:event_formWindowOpened
|
||||
|
||||
private void tfNachrichtMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_tfNachrichtMouseClicked
|
||||
{//GEN-HEADEREND:event_tfNachrichtMouseClicked
|
||||
|
||||
}//GEN-LAST:event_tfNachrichtMouseClicked
|
||||
|
||||
private void BtnConnectActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_BtnConnectActionPerformed
|
||||
{//GEN-HEADEREND:event_BtnConnectActionPerformed
|
||||
// TODO add your handling code here:
|
||||
@@ -220,11 +191,9 @@ public class ChatView extends javax.swing.JFrame
|
||||
private javax.swing.ButtonGroup BtnGrpMode;
|
||||
private javax.swing.JRadioButton BtnServer;
|
||||
private javax.swing.JDialog dialogChooseMode;
|
||||
private ChatProgramm.view.GrafikView gvZeichenflaeche;
|
||||
private javax.swing.JPanel jPanel1;
|
||||
private javax.swing.JScrollPane jScrollPane2;
|
||||
private javax.swing.JLabel lblMode;
|
||||
private javax.swing.JTextField tfNachricht;
|
||||
private javax.swing.JTextArea txtChat;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
/**
|
||||
@@ -267,19 +236,19 @@ public class ChatView extends javax.swing.JFrame
|
||||
return dialogChooseMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tfNachricht
|
||||
*/
|
||||
public javax.swing.JTextField getTfNachricht()
|
||||
{
|
||||
return tfNachricht;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the txtChat
|
||||
*/
|
||||
public javax.swing.JTextArea getTxtChat()
|
||||
{
|
||||
return txtChat;
|
||||
}
|
||||
// /**
|
||||
// * @return the tfNachricht
|
||||
// */
|
||||
// public javax.swing.JTextField getTfNachricht()
|
||||
// {
|
||||
// return tfNachricht;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @return the txtChat
|
||||
// */
|
||||
// public javax.swing.JTextArea getTxtChat()
|
||||
// {
|
||||
// return txtChat;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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.view;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.print.PageFormat;
|
||||
import java.awt.print.Printable;
|
||||
import java.awt.print.PrinterException;
|
||||
import java.awt.print.PrinterJob;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
import javax.print.attribute.HashPrintRequestAttributeSet;
|
||||
import javax.print.attribute.standard.DialogTypeSelection;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JOptionPane;
|
||||
import ChatProgramm.model.GrafikDaten;
|
||||
import ChatProgramm.util.OhmLogger;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author le
|
||||
*/
|
||||
public class GrafikView extends JComponent
|
||||
{
|
||||
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 Rectangle2D.Float pixel;
|
||||
private Line2D.Float line;
|
||||
private GrafikDaten model;
|
||||
|
||||
private Point from = null;
|
||||
private Point to = null;
|
||||
|
||||
public GrafikView()
|
||||
{
|
||||
pixel = new Rectangle2D.Float();
|
||||
line = new Line2D.Float();
|
||||
}
|
||||
|
||||
public void setModel(GrafikDaten model)
|
||||
{
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Zeichnet den aktuellen Pfad (solange die maus gedrückt gehalten wird)
|
||||
* @param p -> Der aktuelle punkt als x-y-Koordinate
|
||||
*/
|
||||
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!
|
||||
|
||||
drawPath(model.getPunkte(),g2);
|
||||
|
||||
g2.dispose(); //SEEEEHHHHRRRR WICHTIG!!!!!!!
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Hier werden alle Pfade aus dem model neu gezeichnet
|
||||
* Jedes mal wenn die Maus los gelassen wird, wird dder aktuelle Pfad gespeichert
|
||||
* @param g
|
||||
*/
|
||||
@Override
|
||||
public void paintComponent(Graphics g)
|
||||
{
|
||||
if (model == null) return;
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2 = (Graphics2D)g;
|
||||
|
||||
|
||||
model.getFiguren().forEach(figuren->
|
||||
{
|
||||
drawPath(figuren.getPunkte(),g2);
|
||||
});
|
||||
}
|
||||
|
||||
public void drawPath(List<Point> path, Graphics2D g2){
|
||||
from = path.getFirst();
|
||||
to = null;
|
||||
|
||||
path.forEach(point->
|
||||
{
|
||||
to = point;
|
||||
line.setLine(from,to);
|
||||
g2.draw(line);
|
||||
from = to;
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
log.level=INFO
|
||||
|
||||
log.directory=../Aufgabe7_bandit
|
||||
log.filename=ohmLog
|
||||
# log.directory=../Aufgabe7_bandit
|
||||
# log.filename=ohmLog
|
||||
|
||||
# Beispiel f\u00fcr verschiedene Level f\u00fcr unterschiedliche Pakete
|
||||
# log.level.bandit.Zahlengenerator=FINE
|
||||
|
||||
Reference in new issue
Block a user