Compare commits
8
Commits
22efa7c18f
...
Toni
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
75cdcf7202 | ||
|
|
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}">
|
<propertyfile file="${built-jar.properties}">
|
||||||
<entry key="${basedir}" value=""/>
|
<entry key="${basedir}" value=""/>
|
||||||
</propertyfile>
|
</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>
|
||||||
<target depends="init,-check-automatic-build,-clean-after-automatic-build" name="-verify-automatic-build"/>
|
<target depends="init,-check-automatic-build,-clean-after-automatic-build" name="-verify-automatic-build"/>
|
||||||
<target depends="init" name="-check-automatic-build">
|
<target depends="init" name="-check-automatic-build">
|
||||||
@@ -1738,6 +1747,15 @@ is divided into following sections:
|
|||||||
<propertyfile file="${built-clean.properties}">
|
<propertyfile file="${built-clean.properties}">
|
||||||
<entry key="${basedir}" value=""/>
|
<entry key="${basedir}" value=""/>
|
||||||
</propertyfile>
|
</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>
|
||||||
<target depends="init" name="-do-clean">
|
<target depends="init" name="-do-clean">
|
||||||
<delete dir="${build.dir}"/>
|
<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.script.CRC32=1a88b66a
|
||||||
build.xml.stylesheet.CRC32=f85dc8f2@1.108.0.48
|
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.
|
# 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.
|
# 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.data.CRC32=d624b1fd
|
||||||
nbproject/build-impl.xml.script.CRC32=fdc076e6
|
nbproject/build-impl.xml.script.CRC32=476a1ac9
|
||||||
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.108.0.48
|
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.108.0.48
|
||||||
@@ -37,7 +37,8 @@ endorsed.classpath=
|
|||||||
excludes=
|
excludes=
|
||||||
includes=**
|
includes=**
|
||||||
jar.compress=false
|
jar.compress=false
|
||||||
javac.classpath=
|
javac.classpath=\
|
||||||
|
${reference.Aufgabe9_mvcGrafik.jar}
|
||||||
# Space-separated list of extra javac options
|
# Space-separated list of extra javac options
|
||||||
javac.compilerargs=
|
javac.compilerargs=
|
||||||
javac.deprecation=false
|
javac.deprecation=false
|
||||||
@@ -78,6 +79,8 @@ manifest.file=manifest.mf
|
|||||||
meta.inf.dir=${src.dir}/META-INF
|
meta.inf.dir=${src.dir}/META-INF
|
||||||
mkdist.disabled=false
|
mkdist.disabled=false
|
||||||
platform.active=default_platform
|
platform.active=default_platform
|
||||||
|
project.Aufgabe9_mvcGrafik=../../T9_mvcGrafik/Aufgabe9_mvcGrafik
|
||||||
|
reference.Aufgabe9_mvcGrafik.jar=${project.Aufgabe9_mvcGrafik}/dist/Aufgabe9_mvcGrafik.jar
|
||||||
run.classpath=\
|
run.classpath=\
|
||||||
${javac.classpath}:\
|
${javac.classpath}:\
|
||||||
${build.classes.dir}
|
${build.classes.dir}
|
||||||
|
|||||||
@@ -11,5 +11,15 @@
|
|||||||
<root id="test.src.dir"/>
|
<root id="test.src.dir"/>
|
||||||
</test-roots>
|
</test-roots>
|
||||||
</data>
|
</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>
|
</configuration>
|
||||||
</project>
|
</project>
|
||||||
@@ -6,7 +6,10 @@
|
|||||||
package ChatProgramm;
|
package ChatProgramm;
|
||||||
|
|
||||||
import ChatProgramm.controller.CommandController;
|
import ChatProgramm.controller.CommandController;
|
||||||
|
import ChatProgramm.controller.GrafikController;
|
||||||
|
import ChatProgramm.model.GrafikModel;
|
||||||
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,8 +21,13 @@ public class Start
|
|||||||
{
|
{
|
||||||
public Start()
|
public Start()
|
||||||
{
|
{
|
||||||
|
GrafikModel model = new GrafikModel();
|
||||||
ChatView view = new ChatView();
|
ChatView view = new ChatView();
|
||||||
CommandController controller_commands = new CommandController(view);
|
GrafikView zeichenflaeche = view.getGvZeichenflaeche();
|
||||||
|
zeichenflaeche.setModel(model);
|
||||||
|
GrafikController controller = new GrafikController(zeichenflaeche, model);
|
||||||
|
controller.registerEvents();
|
||||||
|
CommandController controller_commands = new CommandController(view, model, controller, zeichenflaeche);
|
||||||
controller_commands.registerEvents();
|
controller_commands.registerEvents();
|
||||||
controller_commands.registerCommands();
|
controller_commands.registerCommands();
|
||||||
view.setVisible(true);
|
view.setVisible(true);
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ package ChatProgramm.controller;
|
|||||||
import ChatProgramm.controller.commands.CommandConnect;
|
import ChatProgramm.controller.commands.CommandConnect;
|
||||||
import ChatProgramm.controller.commands.CommandInvoker;
|
import ChatProgramm.controller.commands.CommandInvoker;
|
||||||
import ChatProgramm.controller.commands.CommandSend;
|
import ChatProgramm.controller.commands.CommandSend;
|
||||||
|
import ChatProgramm.model.GrafikModel;
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
|
import ChatProgramm.view.GrafikView;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
@@ -20,22 +22,29 @@ import java.awt.event.ActionListener;
|
|||||||
public class CommandController implements ActionListener{
|
public class CommandController implements ActionListener{
|
||||||
|
|
||||||
private ChatView view;
|
private ChatView view;
|
||||||
|
private GrafikModel model;
|
||||||
|
private GrafikView gView;
|
||||||
private CommandInvoker invoker;
|
private CommandInvoker invoker;
|
||||||
|
private GrafikController controller;
|
||||||
|
|
||||||
public CommandController(ChatView view){
|
public CommandController(ChatView view, GrafikModel model, GrafikController controller, GrafikView gView){
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
this.model = model;
|
||||||
|
this.gView = gView;
|
||||||
this.invoker = new CommandInvoker();
|
this.invoker = new CommandInvoker();
|
||||||
|
this.controller = controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerEvents(){
|
public void registerEvents(){
|
||||||
view.getBtnConnect().addActionListener(this);
|
view.getBtnConnect().addActionListener(this);
|
||||||
view.getTfNachricht().addActionListener(this);
|
//ToDo: muss auf gFrame referenzieren
|
||||||
|
//view.getTfNachricht().addActionListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerCommands(){
|
public void registerCommands(){
|
||||||
CommandSend commandSend = new CommandSend(view);
|
CommandSend commandSend = new CommandSend(view.getGvZeichenflaeche(), model);
|
||||||
invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend));
|
invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend, model, gView));
|
||||||
invoker.addCommand(view.getTfNachricht(), commandSend);
|
this.controller.setCommand(commandSend);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,10 +55,10 @@ public class CommandController implements ActionListener{
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
Component key = (Component)e.getSource();
|
Component key = (Component)e.getSource();
|
||||||
invoker.executeCommand(key);
|
invoker.executeCommand(key);
|
||||||
// if(key == view.getBtnOpen()|| key==view.getMiOpen())
|
|
||||||
// invoker.deleteStack();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* 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.CommandSend;
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseMotionListener;
|
||||||
|
import ChatProgramm.model.GrafikModel;
|
||||||
|
import ChatProgramm.view.GrafikView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author le
|
||||||
|
*/
|
||||||
|
public class GrafikController extends MouseAdapter implements MouseMotionListener
|
||||||
|
{
|
||||||
|
private GrafikView view;
|
||||||
|
private GrafikModel model;
|
||||||
|
private CommandSend commandSend;
|
||||||
|
|
||||||
|
public GrafikController(GrafikView view, GrafikModel model)
|
||||||
|
{
|
||||||
|
this.view = view;
|
||||||
|
this.model = model;
|
||||||
|
commandSend = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setCommand(CommandSend command){
|
||||||
|
this.commandSend = command;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerEvents()
|
||||||
|
{
|
||||||
|
view.addMouseMotionListener(this);
|
||||||
|
view.addMouseListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseDragged(MouseEvent evt)
|
||||||
|
{
|
||||||
|
Point p = evt.getPoint();
|
||||||
|
model.addPoint(p);
|
||||||
|
view.drawPoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseMoved(MouseEvent e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent evt)
|
||||||
|
{
|
||||||
|
model.endShape();
|
||||||
|
if(commandSend != null){
|
||||||
|
commandSend.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,9 +6,11 @@
|
|||||||
package ChatProgramm.controller.commands;
|
package ChatProgramm.controller.commands;
|
||||||
|
|
||||||
import ChatProgramm.model.Client;
|
import ChatProgramm.model.Client;
|
||||||
|
import ChatProgramm.model.GrafikModel;
|
||||||
import ChatProgramm.model.Server;
|
import ChatProgramm.model.Server;
|
||||||
import ChatProgramm.util.OhmLogger;
|
import ChatProgramm.util.OhmLogger;
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
|
import ChatProgramm.view.GrafikView;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
@@ -26,8 +28,10 @@ public class CommandConnect implements CommandInterface
|
|||||||
private static Logger lg = OhmLogger.getLogger();
|
private static Logger lg = OhmLogger.getLogger();
|
||||||
private CommandSend commandSend;
|
private CommandSend commandSend;
|
||||||
private ChatView view;
|
private ChatView view;
|
||||||
|
private GrafikModel model;
|
||||||
|
private GrafikView gView;
|
||||||
|
|
||||||
public CommandConnect(ChatView view, CommandInterface value)
|
public CommandConnect(ChatView view, CommandInterface value, GrafikModel model, GrafikView gView)
|
||||||
{
|
{
|
||||||
rBtnServer = view.getBtnServer();
|
rBtnServer = view.getBtnServer();
|
||||||
rBtnClient = view.getBtnClient();
|
rBtnClient = view.getBtnClient();
|
||||||
@@ -36,8 +40,11 @@ public class CommandConnect implements CommandInterface
|
|||||||
commandSend = (CommandSend) value;
|
commandSend = (CommandSend) value;
|
||||||
|
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
this.model = model;
|
||||||
|
this.gView = gView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute()
|
public void execute()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,13 +6,15 @@
|
|||||||
package ChatProgramm.controller.commands;
|
package ChatProgramm.controller.commands;
|
||||||
|
|
||||||
import ChatProgramm.model.Client;
|
import ChatProgramm.model.Client;
|
||||||
|
import ChatProgramm.model.Figur;
|
||||||
|
import ChatProgramm.model.GrafikModel;
|
||||||
import ChatProgramm.model.Server;
|
import ChatProgramm.model.Server;
|
||||||
import ChatProgramm.model.TransmitterInterface;
|
import ChatProgramm.model.TransmitterInterface;
|
||||||
import ChatProgramm.util.OhmLogger;
|
import ChatProgramm.util.OhmLogger;
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import ChatProgramm.model.Nachricht;
|
import ChatProgramm.view.GrafikView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -23,28 +25,39 @@ public class CommandSend implements CommandInterface
|
|||||||
private static Logger lg = OhmLogger.getLogger();
|
private static Logger lg = OhmLogger.getLogger();
|
||||||
private JTextField eingabeFeld;
|
private JTextField eingabeFeld;
|
||||||
private String nachricht;
|
private String nachricht;
|
||||||
private ChatView view;
|
private GrafikView view;
|
||||||
|
private GrafikModel model;
|
||||||
public TransmitterInterface transmitterInterface;
|
public TransmitterInterface transmitterInterface;
|
||||||
public Server server;
|
public Server server;
|
||||||
public Client client;
|
public Client client;
|
||||||
|
|
||||||
|
public CommandSend(GrafikView view, GrafikModel model)
|
||||||
|
|
||||||
|
|
||||||
public CommandSend(ChatView view)
|
|
||||||
{
|
{
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.eingabeFeld = view.getTfNachricht();
|
this.model = model;
|
||||||
|
//ToDo: Hier muss auch der gFrame referenziert werden
|
||||||
|
//this.eingabeFeld = view.getTfNachricht();
|
||||||
transmitterInterface = null;
|
transmitterInterface = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute()
|
public void execute()
|
||||||
{
|
{
|
||||||
if(transmitterInterface != null && !eingabeFeld.getText().isEmpty()){
|
lg.info("wir sind drin");
|
||||||
transmitterInterface.send(eingabeFeld.getText());
|
Figur aktuelleFigur = model.getFiguren().getLast();
|
||||||
eingabeFeld.setText("");
|
if(transmitterInterface != null){
|
||||||
|
transmitterInterface.send(aktuelleFigur);
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
lg.info("Der Transmitter ist immernoch null");
|
||||||
|
}
|
||||||
|
//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("");
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -58,4 +71,15 @@ public class CommandSend implements CommandInterface
|
|||||||
public void undo()
|
public void undo()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setTransmitter(TransmitterInterface transmitter) {
|
||||||
|
lg.info("Transmitter wird gesetzt");
|
||||||
|
if(transmitter != null){
|
||||||
|
this.transmitterInterface = transmitter;
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
lg.info("der transmitter kommt hier als null an");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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,126 @@
|
|||||||
|
/*
|
||||||
|
* 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();
|
||||||
|
}
|
||||||
|
public void setFigur(Figur figur){
|
||||||
|
aktuelleFigur = figur;
|
||||||
|
figuren.add(figur);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bestimmt die Adresse des zuletzt besuchten Ordners
|
||||||
|
* @return letzter Ordner
|
||||||
|
*/
|
||||||
|
public String getPref()
|
||||||
|
{
|
||||||
|
pref = Preferences.userNodeForPackage(getClass());
|
||||||
|
return pref.get("lastDirectory", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setzt die Preferenz zu dem zuletzt besuchten Ordner
|
||||||
|
* @param lastDirectory Bezeichner "lastDirectory"
|
||||||
|
* @param lastAdress Adresse des zuletzt besuchten Ordners
|
||||||
|
*/
|
||||||
|
public void putPref(String lastDirectory, String lastAdress)
|
||||||
|
{
|
||||||
|
pref.put(lastDirectory, lastAdress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -4,21 +4,33 @@
|
|||||||
*/
|
*/
|
||||||
package ChatProgramm.model;
|
package ChatProgramm.model;
|
||||||
|
|
||||||
|
import ChatProgramm.util.OhmLogger;
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
|
import ChatProgramm.view.GrafikView;
|
||||||
import java.util.concurrent.Flow;
|
import java.util.concurrent.Flow;
|
||||||
import java.util.concurrent.Flow.Subscriber;
|
import java.util.concurrent.Flow.Subscriber;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @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 GrafikModel model;
|
||||||
|
private GrafikView gView;
|
||||||
private Flow.Subscription subscription;
|
private Flow.Subscription subscription;
|
||||||
|
|
||||||
public ReceiveAdapter(ChatView view) {
|
public ReceiveAdapter(ChatView view, GrafikModel model, GrafikView gView) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
this.model = model;
|
||||||
|
this.gView = gView;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -27,10 +39,13 @@ 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.getTxtChat().append(item.getNachricht());
|
lg.info("Figur wurde dem Grafikmodel hinzugefügt");
|
||||||
|
model.setFigur(item);
|
||||||
|
gView.drawFigur();
|
||||||
|
// evtl muss die Figur aber zuerst serialisiert werden
|
||||||
|
//view.getTxtChat().append(item.getNachricht());
|
||||||
this.subscription.request(1);
|
this.subscription.request(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,4 +56,5 @@ public class ReceiveAdapter implements Subscriber<Nachricht> {
|
|||||||
@Override
|
@Override
|
||||||
public void onComplete(){
|
public void onComplete(){
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5,10 +5,15 @@
|
|||||||
package ChatProgramm.model;
|
package ChatProgramm.model;
|
||||||
|
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
|
import ChatProgramm.view.GrafikView;
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
@@ -34,32 +39,35 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
|||||||
private static Logger lg = Logger.getLogger("netz");
|
private static Logger lg = Logger.getLogger("netz");
|
||||||
|
|
||||||
protected Socket socket;
|
protected Socket socket;
|
||||||
protected BufferedReader reader;
|
protected ObjectInputStream reader;
|
||||||
protected PrintWriter writer;
|
protected ObjectOutputStream writer;
|
||||||
|
|
||||||
private Nachricht nachricht;
|
private Figur figur;
|
||||||
private String txtNachricht;
|
private String txtNachricht;
|
||||||
private boolean laufend;
|
private boolean laufend;
|
||||||
private SubmissionPublisher<Nachricht> textPublisher;
|
private SubmissionPublisher<Figur> figurPublisher;
|
||||||
private ExecutorService eService;
|
private ExecutorService eService;
|
||||||
private String receivedString;
|
private String receivedString;
|
||||||
private ChatView view;
|
private ChatView view;
|
||||||
|
private GrafikView gView;
|
||||||
|
private GrafikModel model;
|
||||||
|
|
||||||
private ReceiveAdapter receiveAdapter;
|
private ReceiveAdapter receiveAdapter;
|
||||||
|
|
||||||
public Transmitter(ChatView view)
|
public Transmitter(ChatView view)
|
||||||
{
|
{
|
||||||
socket = new Socket();
|
socket = new Socket();
|
||||||
eService = null;
|
eService = null;
|
||||||
receiveAdapter = new ReceiveAdapter(view);
|
receiveAdapter = new ReceiveAdapter(view, model, gView);
|
||||||
textPublisher = new SubmissionPublisher<>();
|
figurPublisher = new SubmissionPublisher<>();
|
||||||
this.view = view;
|
this.view = view;
|
||||||
addWertSubscription(receiveAdapter);
|
addWertSubscription(receiveAdapter);
|
||||||
nachricht = new Nachricht("");
|
figur = new Figur();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addWertSubscription(Subscriber<Nachricht> subscriber)
|
public void addWertSubscription(Subscriber<Figur> subscriber)
|
||||||
{
|
{
|
||||||
textPublisher.subscribe(subscriber);
|
figurPublisher.subscribe(subscriber);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void connect() throws IOException;
|
public abstract void connect() throws IOException;
|
||||||
@@ -70,11 +78,10 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
|||||||
InputStream is = socket.getInputStream();
|
InputStream is = socket.getInputStream();
|
||||||
OutputStream os = socket.getOutputStream();
|
OutputStream os = socket.getOutputStream();
|
||||||
|
|
||||||
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);
|
|
||||||
writer = new PrintWriter(osr);
|
|
||||||
lg.info("Reader / Writer Initialisierung abgeschlossen");
|
lg.info("Reader / Writer Initialisierung abgeschlossen");
|
||||||
startempfangen();
|
startempfangen();
|
||||||
lg.info("Warte auf Nachricht");
|
lg.info("Warte auf Nachricht");
|
||||||
@@ -86,27 +93,42 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(String txtNachricht){
|
/**
|
||||||
|
*
|
||||||
writer.println(txtNachricht);
|
* @param figur
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void send(Figur figur){
|
||||||
|
try
|
||||||
|
{
|
||||||
|
writer.writeObject(figur);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
lg.info("Nachricht gesendet");
|
|
||||||
nachricht.setNachricht("\nDu: " + txtNachricht);
|
|
||||||
textPublisher.submit(nachricht);
|
|
||||||
}
|
}
|
||||||
public Nachricht receive(){
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
lg.info("Nachricht gesendet");
|
||||||
|
figurPublisher.submit(figur);
|
||||||
|
}
|
||||||
|
public Figur receive(){
|
||||||
|
Object receivedObject;
|
||||||
try {
|
try {
|
||||||
txtNachricht = reader.readLine();
|
receivedObject = reader.readObject();
|
||||||
if(!txtNachricht.isEmpty()){
|
if(receivedObject instanceof Figur){
|
||||||
lg.info("Nachricht erhalten");
|
lg.info("Figur erhalten");
|
||||||
nachricht.setNachricht("\nEr / Sie: " + txtNachricht);
|
figur = (Figur) receivedObject;
|
||||||
return nachricht;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
return nachricht;
|
catch (ClassNotFoundException ex)
|
||||||
|
{
|
||||||
|
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
return figur;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void disconnect (){
|
// public void disconnect (){
|
||||||
@@ -120,9 +142,9 @@ public abstract class Transmitter implements Runnable, Subscriber<String>, Trans
|
|||||||
while (true) {
|
while (true) {
|
||||||
lg.info("Warte auf Nachricht");
|
lg.info("Warte auf Nachricht");
|
||||||
if(laufend) {
|
if(laufend) {
|
||||||
nachricht = receive();
|
figur = receive();
|
||||||
if(!nachricht.getNachricht().isEmpty()){
|
if(!figur.getPunkte().isEmpty()){
|
||||||
textPublisher.submit(nachricht);
|
figurPublisher.submit(figur);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import ChatProgramm.model.Nachricht;
|
|||||||
*/
|
*/
|
||||||
public interface TransmitterInterface
|
public interface TransmitterInterface
|
||||||
{
|
{
|
||||||
public void send(String txtNachricht);
|
public void send(Figur figur);
|
||||||
public Nachricht receive();
|
public Figur receive();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -107,45 +107,16 @@
|
|||||||
|
|
||||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
|
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
|
||||||
<SubComponents>
|
<SubComponents>
|
||||||
<Component class="javax.swing.JTextField" name="tfNachricht">
|
<Container class="ChatProgramm.view.GrafikView" name="gvZeichenflaeche">
|
||||||
<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>
|
|
||||||
<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 class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
|
||||||
<SubComponents>
|
<Property name="useNullLayout" type="boolean" value="true"/>
|
||||||
<Component class="javax.swing.JTextArea" name="txtChat">
|
</Layout>
|
||||||
<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>
|
|
||||||
</Container>
|
</Container>
|
||||||
</SubComponents>
|
</SubComponents>
|
||||||
</Form>
|
</Form>
|
||||||
@@ -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
|
||||||
*/
|
*/
|
||||||
@@ -36,9 +44,7 @@ public class ChatView extends javax.swing.JFrame
|
|||||||
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();
|
||||||
tfNachricht = new javax.swing.JTextField();
|
gvZeichenflaeche = new ChatProgramm.view.GrafikView();
|
||||||
jScrollPane2 = new javax.swing.JScrollPane();
|
|
||||||
txtChat = new javax.swing.JTextArea();
|
|
||||||
|
|
||||||
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));
|
||||||
@@ -105,32 +111,7 @@ public class ChatView extends javax.swing.JFrame
|
|||||||
formWindowOpened(evt);
|
formWindowOpened(evt);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
getContentPane().add(gvZeichenflaeche, java.awt.BorderLayout.CENTER);
|
||||||
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);
|
|
||||||
|
|
||||||
pack();
|
pack();
|
||||||
}// </editor-fold>//GEN-END:initComponents
|
}// </editor-fold>//GEN-END:initComponents
|
||||||
@@ -145,21 +126,11 @@ public class ChatView extends javax.swing.JFrame
|
|||||||
// TODO add your handling code here:
|
// TODO add your handling code here:
|
||||||
}//GEN-LAST:event_BtnServerActionPerformed
|
}//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
|
private void formWindowOpened(java.awt.event.WindowEvent evt)//GEN-FIRST:event_formWindowOpened
|
||||||
{//GEN-HEADEREND:event_formWindowOpened
|
{//GEN-HEADEREND:event_formWindowOpened
|
||||||
dialogChooseMode.show();
|
dialogChooseMode.show();
|
||||||
}//GEN-LAST:event_formWindowOpened
|
}//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
|
private void BtnConnectActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_BtnConnectActionPerformed
|
||||||
{//GEN-HEADEREND:event_BtnConnectActionPerformed
|
{//GEN-HEADEREND:event_BtnConnectActionPerformed
|
||||||
// TODO add your handling code here:
|
// 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.ButtonGroup BtnGrpMode;
|
||||||
private javax.swing.JRadioButton BtnServer;
|
private javax.swing.JRadioButton BtnServer;
|
||||||
private javax.swing.JDialog dialogChooseMode;
|
private javax.swing.JDialog dialogChooseMode;
|
||||||
|
private ChatProgramm.view.GrafikView gvZeichenflaeche;
|
||||||
private javax.swing.JPanel jPanel1;
|
private javax.swing.JPanel jPanel1;
|
||||||
private javax.swing.JScrollPane jScrollPane2;
|
|
||||||
private javax.swing.JLabel lblMode;
|
private javax.swing.JLabel lblMode;
|
||||||
private javax.swing.JTextField tfNachricht;
|
|
||||||
private javax.swing.JTextArea txtChat;
|
|
||||||
// End of variables declaration//GEN-END:variables
|
// End of variables declaration//GEN-END:variables
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -267,19 +236,19 @@ public class ChatView extends javax.swing.JFrame
|
|||||||
return dialogChooseMode;
|
return dialogChooseMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* @return the tfNachricht
|
// * @return the tfNachricht
|
||||||
*/
|
// */
|
||||||
public javax.swing.JTextField getTfNachricht()
|
// public javax.swing.JTextField getTfNachricht()
|
||||||
{
|
// {
|
||||||
return tfNachricht;
|
// return tfNachricht;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* @return the txtChat
|
// * @return the txtChat
|
||||||
*/
|
// */
|
||||||
public javax.swing.JTextArea getTxtChat()
|
// public javax.swing.JTextArea getTxtChat()
|
||||||
{
|
// {
|
||||||
return txtChat;
|
// return txtChat;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
/*
|
||||||
|
* 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.GrafikModel;
|
||||||
|
import ChatProgramm.util.OhmLogger;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author le
|
||||||
|
*/
|
||||||
|
public class GrafikView extends JComponent implements Printable
|
||||||
|
{
|
||||||
|
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 GrafikModel model;
|
||||||
|
|
||||||
|
private Point from = null;
|
||||||
|
private Point to = null;
|
||||||
|
|
||||||
|
public GrafikView()
|
||||||
|
{
|
||||||
|
pixel = new Rectangle2D.Float();
|
||||||
|
line = new Line2D.Float();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModel(GrafikModel 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;
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user