diff --git a/src/kommunikation/Start.java b/src/kommunikation/Start.java new file mode 100644 index 0000000..d59512f --- /dev/null +++ b/src/kommunikation/Start.java @@ -0,0 +1,68 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package kommunikation; + +import javax.swing.JOptionPane; +import kommunikation.controller.ConnectController; +import kommunikation.controller.GrafikController; +import kommunikation.controller.ReceiveAdapter; +import kommunikation.controller.SendController; +import kommunikation.transmitter.BilderKom; +import kommunikation.view.ViewChat; + + +/** + * Builder Class + * @author Alexander_Christoph + */ +public class Start +{ + public Start() + { + Object[] options = {"Client","Server"}; + int selected = JOptionPane.showOptionDialog(null,"Wollen Sie Client oder Server sein","Konfiguration",JOptionPane.DEFAULT_OPTION,JOptionPane.QUESTION_MESSAGE,null, options, options[0]); + + if(selected < 0) + { + JOptionPane.showMessageDialog(null, "Sie müssen entweder Client oder Server sein. Bitte starten Sie das Programm erneut und wählen eine Option","Fehler", JOptionPane.ERROR_MESSAGE); + } + else + { + ViewChat view = new ViewChat(); + BilderKom model = new BilderKom(selected); + model.registerEvents(); + + if(selected == 1) + { + view.setTitle("Server"); + } + + view.getGrafikViewChat().setModel(model.getModel()); + GrafikController gcontrol= new GrafikController(view.getGrafikViewChat(),model); + gcontrol.registerEvents(); + + ConnectController control = new ConnectController(view,model); + control.registerEvents(); + + SendController send = new SendController(view,model); + send.registerEvents(); + + ReceiveAdapter adapter = new ReceiveAdapter(view,model); + adapter.registerEvents(); + + view.setVisible(true); + } + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) + { + new Start(); + } +} diff --git a/src/kommunikation/controller/ConnectController.java b/src/kommunikation/controller/ConnectController.java new file mode 100644 index 0000000..c72ec89 --- /dev/null +++ b/src/kommunikation/controller/ConnectController.java @@ -0,0 +1,53 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package kommunikation.controller; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JOptionPane; +import kommunikation.transmitter.BilderKom; +import kommunikation.transmitter.Transmitter; +import kommunikation.view.ViewChat; + +/** + * + * @author Alexander_Christoph + */ +public class ConnectController implements ActionListener +{ + ViewChat view; + BilderKom model; + + + public ConnectController(ViewChat view, BilderKom model) + { + this.view = view; + this.model = model; + } + + public void registerEvents() + { + view.getBtnConnect().addActionListener(this); + } + + @Override + public void actionPerformed(ActionEvent arg0) + { + try + { + String ip = view.getTfIp().getText(); + int port = Integer.parseInt(view.getTfPort().getText()); + model.setIpPort(ip, port); + } + catch(NumberFormatException ex) + { + JOptionPane.showMessageDialog(null, "Bitte geben sie eine Zahl ein","Fehler", JOptionPane.ERROR_MESSAGE); + } + view.getTaChat().append("Verbinde\n"); + model.start(); + } +} diff --git a/src/kommunikation/controller/GrafikController.java b/src/kommunikation/controller/GrafikController.java new file mode 100644 index 0000000..1310cb3 --- /dev/null +++ b/src/kommunikation/controller/GrafikController.java @@ -0,0 +1,104 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package kommunikation.controller; + +import java.awt.Point; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import kommunikation.transmitter.BilderKom; +import kommunikation.transmitter.Figur; +import kommunikation.view.GrafikView; + + +/** + * + * @author le + */ +public class GrafikController implements MouseMotionListener, MouseListener +{ + private GrafikView view; + private BilderKom model; + private Figur f; + private Boolean neu; + private Boolean ersterPunkt; + private Point zwischenSpeicher; + + public GrafikController(GrafikView view, BilderKom model) + { + this.view = view; + this.model = model; + neu = true; + zwischenSpeicher = new Point(); + ersterPunkt = true; + } + + public void registerEvents() + { + view.addMouseMotionListener(this); + view.addMouseListener(this); + } + + @Override + public void mouseDragged(MouseEvent evt) + { + Point p = evt.getPoint(); + view.drawPoint(p); + f.addPoint(p); + if(!ersterPunkt) + { + view.line(zwischenSpeicher, p); + } + zwischenSpeicher = p; + ersterPunkt = false; + } + + @Override + public void mouseMoved(MouseEvent e) + { + } + + @Override + public void mouseClicked(MouseEvent e) + { + + } + + @Override + public void mousePressed(MouseEvent e) + { + if(neu) + { + f = new Figur(); + neu = false; + } + } + + @Override + public void mouseReleased(MouseEvent evt) + { + if (evt.getButton() == MouseEvent.BUTTON3) + { + view.doPrint(); + } + + model.addFigur(f); + model.senden(f); + neu = true; + ersterPunkt = true; + } + + @Override + public void mouseEntered(MouseEvent e) + { + } + + @Override + public void mouseExited(MouseEvent e) + { + } +} diff --git a/src/kommunikation/controller/ReceiveAdapter.java b/src/kommunikation/controller/ReceiveAdapter.java new file mode 100644 index 0000000..fe90422 --- /dev/null +++ b/src/kommunikation/controller/ReceiveAdapter.java @@ -0,0 +1,58 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package kommunikation.controller; + +import java.util.Observable; +import java.util.Observer; +import java.util.logging.Logger; +import kommunikation.transmitter.BilderKom; +import kommunikation.transmitter.Figur; +import kommunikation.view.ViewChat; + +/** + * + * @author Alexander_Christoph + */ +public class ReceiveAdapter implements Observer +{ + ViewChat view; + BilderKom model; + Logger lg =Logger.getLogger("observer"); + + public ReceiveAdapter(ViewChat view, BilderKom model) + { + this.view = view; + this.model = model; + } + + public void registerEvents() + { + model.addObserver(this); + } + + @Override + public void update(Observable arg0, Object arg1) + { + lg.info("in update"); + Object obj; + obj = model.getNachricht(); + if(obj instanceof String) + { + + String text = obj.toString() + "\n"; + view.getTaChat().append("Freund: " + text); + } + if(obj instanceof Figur) + { + model.addFigurFremd((Figur)obj); //muss eventuell noch gezeichnet werden nachdem es hinzugefügt wurde !!! + view.repaint(); + } + } + +} + + diff --git a/src/kommunikation/controller/SendController.java b/src/kommunikation/controller/SendController.java new file mode 100644 index 0000000..b20cf05 --- /dev/null +++ b/src/kommunikation/controller/SendController.java @@ -0,0 +1,43 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package kommunikation.controller; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import kommunikation.transmitter.BilderKom; +import kommunikation.view.ViewChat; + +/** + * + * @author Alexander_Christoph + */ +public class SendController implements ActionListener +{ + ViewChat view; + BilderKom model; + + public SendController(ViewChat view, BilderKom model) + { + this.view = view; + this.model = model; + } + + public void registerEvents() + { + view.getTfMessage().addActionListener(this); + } + + @Override + public void actionPerformed(ActionEvent arg0) + { + String text = view.getTfMessage().getText(); + view.getTaChat().append("Ich: "+ text+"\n"); + model.senden(text); + view.getTfMessage().setText(""); + } + +} diff --git a/src/kommunikation/logger/MyFormatter.java b/src/kommunikation/logger/MyFormatter.java new file mode 100644 index 0000000..30357ea --- /dev/null +++ b/src/kommunikation/logger/MyFormatter.java @@ -0,0 +1,30 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package kommunikation.logger; + +import java.util.logging.LogRecord; +import java.util.logging.SimpleFormatter; + +/** + * + * @author nobody + */ +public class MyFormatter extends SimpleFormatter +{ + public MyFormatter() + { + + } + + @Override + public String format(LogRecord record) + { + String str = "| " + record.getMillis() + " | " + record.getLevel()+ " | " + record.getSourceClassName() + " | " + record.getMessage() + " |\n"; + + return str; + } +} diff --git a/src/kommunikation/logger/OhmLogger.java b/src/kommunikation/logger/OhmLogger.java new file mode 100644 index 0000000..6a60b12 --- /dev/null +++ b/src/kommunikation/logger/OhmLogger.java @@ -0,0 +1,58 @@ +package kommunikation.logger; +/** + * + * @author nobody + */ + +import java.io.File; +import java.io.IOException; +import java.util.logging.ConsoleHandler; +import java.util.logging.FileHandler; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class OhmLogger +{ + private static Logger lg = null; + + public static Logger getLogger() + { + if (lg == null) + { + lg = Logger.getLogger("OhmLogger"); + initLogger(); + } + + return lg; + } + + private static void initLogger() + { + try + { + // Besser: Die Log-Datei über eine Properties-Dateieinstellbar machen + // Hier wird in das temporäre Verzeichnis desBetriebssytems geloggt. + + String datei = System.getProperty("java.io.tmpdir") + File.separator + "log.txt"; + FileHandler fh = new FileHandler(datei); + ConsoleHandler ch = new ConsoleHandler(); + lg.setUseParentHandlers(false); + + // Text-Ausgabe --> SimpleFormatter + // Standard = Default: XMLFormatter --> xml-Format + //fh.setFormatter(new SimpleFormatter()); + lg.addHandler(fh); + + // besser eigener Formatter: + ch.setFormatter(new MyFormatter()); + + lg.addHandler(ch); + + lg.setLevel(Level.ALL); + } + catch (IOException ioex) + { + System.err.println(ioex); + } + } +} diff --git a/src/kommunikation/transmitter/BilderKom.java b/src/kommunikation/transmitter/BilderKom.java new file mode 100644 index 0000000..fed45e7 --- /dev/null +++ b/src/kommunikation/transmitter/BilderKom.java @@ -0,0 +1,112 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package kommunikation.transmitter; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Observable; +import java.util.Observer; +import java.util.function.Supplier; +import java.util.logging.Level; +import java.util.logging.Logger; +import kommunikation.logger.OhmLogger; + +/** + * + * @author nobody + */ +public class BilderKom extends Observable implements Observer +{ + protected static final Logger lg = OhmLogger.getLogger(); + private GrafikModel grafik; + private Transmitter trans; + + public BilderKom(int modus ) + { + trans = new Transmitter(modus); + grafik = new GrafikModel(); + } + + public void registerEvents() + { + trans.addObserver(this); + } + + public GrafikModel getModel() + { + return grafik; + } + + public void start() + { + trans.start(); + } + + public void setIpPort(String ip,int port) + { + trans.setIpPort(ip, port); + } + + public void senden(Object nachricht) + { + trans.senden(nachricht); + } + + public Object getNachricht() + { + return trans.getNachricht(); + } + + public void addFigur(Figur f) + { + grafik.addFigur(f); + } + + public void addFigurFremd(Figur f) + { + grafik.addFigurFremd(f); + } + + public List getFigur() + { + return grafik.getFigur(); + } + + public void speichereFiguren(File datei) + { + try + { + grafik.speichereFiguren(datei); + } + catch (IOException ex) + { + Logger.getLogger(BilderKom.class.getName()).log(Level.SEVERE, null, ex); + } + } + + @SuppressWarnings("unchecked") + public void ladeFiguren(File dateiname) + { + try + { + grafik.ladeFiguren(dateiname); + } + catch (IOException | ClassNotFoundException ex) + { + lg.severe((Supplier) ex); + } + } + + @Override + public void update(Observable o, Object arg) + { + this.setChanged(); + this.notifyObservers(); + } + +} diff --git a/src/kommunikation/transmitter/Client.java b/src/kommunikation/transmitter/Client.java new file mode 100644 index 0000000..768bf33 --- /dev/null +++ b/src/kommunikation/transmitter/Client.java @@ -0,0 +1,45 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package kommunikation.transmitter; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.net.Socket; + + +/** + * + * @author Alexander_Christoph + */ +public class Client extends Kommunikationspartner +{ + + public Client() + { + this.ip = "127.0.0.0"; + lg.info("Client erstellt"); + } + + + @Override + public void verbinde() + { + try + { + Socket s = new Socket(ip, port); // Achtung: blockiert! + lg.info("Client: socket erstellt"); + out = new ObjectOutputStream(s.getOutputStream()); + in = new ObjectInputStream(s.getInputStream()); + lg.info("Client: Stream initialisiert"); + } + catch (IOException ex) + { + lg.severe(ex.toString()); + } + } +} diff --git a/src/kommunikation/transmitter/Figur.java b/src/kommunikation/transmitter/Figur.java new file mode 100644 index 0000000..fc22cdf --- /dev/null +++ b/src/kommunikation/transmitter/Figur.java @@ -0,0 +1,38 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package kommunikation.transmitter; + +import java.awt.Point; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * + * @author nobody + */ +public class Figur implements Serializable +{ + private ArrayList punkte; + + public Figur() + { + punkte = new ArrayList<>(); + } + + public void addPoint(Point p) + { + punkte.add(p); + } + + public List getPunkte() + { + return Collections.unmodifiableList(punkte); + } + +} diff --git a/src/kommunikation/transmitter/GrafikModel.java b/src/kommunikation/transmitter/GrafikModel.java new file mode 100644 index 0000000..40e6c9b --- /dev/null +++ b/src/kommunikation/transmitter/GrafikModel.java @@ -0,0 +1,83 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package kommunikation.transmitter; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +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.Observable; +import java.util.logging.Logger; +import kommunikation.logger.OhmLogger; + +/** + * + * @author le + */ +public class GrafikModel extends Observable +{ + private ArrayList figuren; + private ArrayList figurenFremd; + private static final Logger lg = OhmLogger.getLogger(); + + public GrafikModel() + { + figuren = new ArrayList<>(); + figurenFremd = new ArrayList<>(); + } + + public void addFigurFremd(Figur f) + { + figurenFremd.add(f); + lg.info("fremde Figur wurde hinzugefügt"); + } + + + public void addFigur(Figur f) + { + figuren.add(f); + lg.info("Figur wurde hinzugefügt"); + } + + public List getFigur() + { + return Collections.unmodifiableList(figuren); + } + + public List getFigurFremd() + { + return Collections.unmodifiableList(figurenFremd); + } + + public void speichereFiguren(File datei) throws FileNotFoundException, IOException + { + FileOutputStream fos = new FileOutputStream(datei); + BufferedOutputStream bos = new BufferedOutputStream(fos); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(figuren); + oos.flush(); + oos.close(); + } + + public void ladeFiguren(File dateiname) throws FileNotFoundException, IOException, ClassNotFoundException + { + FileInputStream fis = new FileInputStream(dateiname); + BufferedInputStream buffin = new BufferedInputStream(fis); + ObjectInputStream ois = new ObjectInputStream(buffin); + figuren = (ArrayList) ois.readObject(); + ois.close(); + } + +} diff --git a/src/kommunikation/transmitter/Kommunikationspartner.java b/src/kommunikation/transmitter/Kommunikationspartner.java new file mode 100644 index 0000000..16efe4c --- /dev/null +++ b/src/kommunikation/transmitter/Kommunikationspartner.java @@ -0,0 +1,86 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package kommunikation.transmitter; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.logging.Logger; +import kommunikation.logger.OhmLogger; + + + +/** + * + * @author Alexander_Christoph + */ +public abstract class Kommunikationspartner +{ + protected static final Logger lg = OhmLogger.getLogger(); + protected int port; + protected String ip; + protected Object nachricht; + protected Figur figur; + protected ObjectInputStream in; + protected ObjectOutputStream out; + + public Kommunikationspartner() + { + port = 35000; + ip = ""; + } + + public abstract void verbinde(); + + public void senden(Object nachricht) + { + try + { + out.writeObject(nachricht); + } + catch (IOException ex) + { + lg.severe(ex.toString()); + } + + lg.info("Grafik versendet"); + } + + public void empfangen() + { + try + { + lg.info("Warte auf Nachricht ..."); + + nachricht = in.readObject(); + + lg.info("Nachricht empfangen"); + } + catch (IOException | ClassNotFoundException ex) + { + lg.severe(ex.toString()); + } + + } + + public Object getNachricht() + { + return nachricht; + } + + public void setPort(int port) + { + this.port = port; + lg.info("Port auf " + port + " gesetzt" ); + } + + public void setIp(String ip) + { + this.ip = ip; + lg.info("Ip auf " + ip + " gesetzt" ); + } +} diff --git a/src/kommunikation/transmitter/Server.java b/src/kommunikation/transmitter/Server.java new file mode 100644 index 0000000..f0a10da --- /dev/null +++ b/src/kommunikation/transmitter/Server.java @@ -0,0 +1,49 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package kommunikation.transmitter; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.net.ServerSocket; +import java.net.Socket; +import static kommunikation.transmitter.Kommunikationspartner.lg; + +/** + * + * @author Alexander_Christoph + */ +public class Server extends Kommunikationspartner +{ + + public Server() + { + lg.info("Server erstellt"); + } + + @Override + public void verbinde() + { + try + { + ServerSocket sSocket = new ServerSocket(port); + lg.info("Server: Warte auf Verbindung ..."); + Socket s = sSocket.accept(); + lg.info("Server: Verbindung akzeptiert"); + + out = new ObjectOutputStream(s.getOutputStream()); + in = new ObjectInputStream(s.getInputStream()); + + } + catch (IOException ex) + { + lg.severe(ex.toString()); + } + } +} diff --git a/src/kommunikation/transmitter/Transmitter.java b/src/kommunikation/transmitter/Transmitter.java new file mode 100644 index 0000000..6acddb4 --- /dev/null +++ b/src/kommunikation/transmitter/Transmitter.java @@ -0,0 +1,93 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package kommunikation.transmitter; + +import java.util.Observable; +import java.util.logging.Logger; +import javax.swing.JOptionPane; +import kommunikation.logger.OhmLogger; + +/** + * + * @author Alexander_Christoph + */ +public class Transmitter extends Observable implements Runnable +{ + protected static final Logger lg = OhmLogger.getLogger(); + private Kommunikationspartner kom; + private Boolean verbindung; + private Thread thd; + + public Transmitter(int modus) + { + if (modus == 0) + { + kom = new Client(); + } + + if (modus == 1) + { + kom = new Server(); + } + + verbindung = false; + thd = null; + } + + public void start() + { + if (thd == null) + { + thd = new Thread(this); + thd.start(); + } + + } + + @Override + public void run() + { + while (true) + { + if (!verbindung) + { + kom.verbinde(); + verbindung = true; + } + synchronized (this) + { + kom.empfangen(); + } + lg.info("empfangen"); + this.setChanged(); + this.notifyObservers(); + } + } + + public void setIpPort(String ip, int port) + { + kom.setPort(port); + kom.setIp(ip); + } + + public void senden(Object nachricht) + { + if (verbindung) + { + kom.senden(nachricht); + } + else + { + JOptionPane.showMessageDialog(null, "Bauen Sie zuerst eine Verbindung auf", "Keine Verbindung", JOptionPane.INFORMATION_MESSAGE); + } + } + + public Object getNachricht() + { + return kom.getNachricht(); + } + +} diff --git a/src/kommunikation/view/GrafikView.java b/src/kommunikation/view/GrafikView.java new file mode 100644 index 0000000..7122840 --- /dev/null +++ b/src/kommunikation/view/GrafikView.java @@ -0,0 +1,160 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package kommunikation.view; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.geom.Line2D; +import java.awt.geom.Rectangle2D; +import java.awt.print.PageFormat; +import java.awt.print.Printable; +import java.awt.print.PrinterException; +import java.awt.print.PrinterJob; +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 kommunikation.transmitter.Figur; +import kommunikation.transmitter.GrafikModel; + + +/** + * + * @author le + */ +public class GrafikView extends JComponent implements Printable +{ + private final static Dimension EINS = new Dimension(1, 1); + private final static Logger lg = Logger.getLogger("mvcGrafik"); + private Rectangle2D.Float pixel; + private Line2D.Float linie; + private GrafikModel model; + + public GrafikView() + { + pixel = new Rectangle2D.Float(); + linie = new Line2D.Float(); + this.setBackground(Color.WHITE); + } + + public void setModel(GrafikModel model) + { + this.model = model; + } + + public void drawPoint(Point p) + { + Graphics2D g2 = (Graphics2D) this.getGraphics(); + pixel.setFrame(p, EINS); + g2.draw(pixel); + g2.dispose(); // VERY, VERY WICHTIG + } + + @Override + public void paintComponent(Graphics g) + { + if (model == null) + { + lg.severe("keine Referenz auf Model vorhanden"); + return; + } + super.paintComponent(g); + Graphics2D g2 = (Graphics2D) g; + + Point zwischenSpeicher = new Point(); + for (Figur f : model.getFigur()) + { + g2.setColor(Color.BLACK); + Boolean first = true; + for (Point p : f.getPunkte()) + { + pixel.setFrame(p, EINS); + g2.draw(pixel); + if(!first) + { + linie.setLine(zwischenSpeicher, p); + g2.draw(linie); + } + zwischenSpeicher = p; + first = false; + } + } + for (Figur f : model.getFigurFremd()) + { + Boolean first = true; + g2.setColor(Color.RED); + for (Point p : f.getPunkte()) + { + pixel.setFrame(p, EINS); + g2.draw(pixel); + if(!first) + { + linie.setLine(zwischenSpeicher, p); + g2.draw(linie); + } + zwischenSpeicher = p; + first = false; + } + } + } + + public void line(Point p1, Point p2) + { + Graphics2D g2 = (Graphics2D) this.getGraphics(); + Line2D.Float lin = new Line2D.Float(p1, p2); + g2.draw(lin); + g2.dispose(); + } + + public void doPrint() + { + HashPrintRequestAttributeSet printSet = + new HashPrintRequestAttributeSet(); + printSet.add(DialogTypeSelection.NATIVE); + PrinterJob pj = PrinterJob.getPrinterJob(); + pj.setPrintable(this); + // Druckdialog + 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; + Logger lg = Logger.getLogger("mvcGrafik"); + lg.info("pgIndex: " + Integer.toString(pageIndex)); + if (pageIndex == 0) + { + g2p.translate(pf.getImageableX(), pf.getImageableY()); + g2p.scale(pf.getImageableWidth()/this.getWidth(), + pf.getImageableHeight() / this.getHeight()); + super.print(g2p); + + lg.info("Druck ist möglich"); + return Printable.PAGE_EXISTS; + } + else + { + lg.info("Druck ist unmöglich"); + return Printable.NO_SUCH_PAGE; + } + } + +} diff --git a/src/kommunikation/view/ViewChat.form b/src/kommunikation/view/ViewChat.form new file mode 100644 index 0000000..8614f3a --- /dev/null +++ b/src/kommunikation/view/ViewChat.form @@ -0,0 +1,113 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/kommunikation/view/ViewChat.java b/src/kommunikation/view/ViewChat.java new file mode 100644 index 0000000..f8e1553 --- /dev/null +++ b/src/kommunikation/view/ViewChat.java @@ -0,0 +1,197 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package kommunikation.view; + +/** + * + * @author Alexander_Christoph + */ +public class ViewChat extends javax.swing.JFrame +{ + /** + * @return the grafikViewChat + */ + public kommunikation.view.GrafikView getGrafikViewChat() + { + return grafikViewChat; + } + /** + * @return the btnConnect + */ + public javax.swing.JButton getBtnConnect() + { + return btnConnect; + } + + /** + * @return the taChat + */ + public javax.swing.JTextArea getTaChat() + { + return taChat; + } + + /** + * @return the tfIp + */ + public javax.swing.JTextField getTfIp() + { + return tfIp; + } + + /** + * @return the tfMessage + */ + public javax.swing.JTextField getTfMessage() + { + return tfMessage; + } + + /** + * @return the tfPort + */ + public javax.swing.JTextField getTfPort() + { + return tfPort; + } + + /** + * Creates new form ViewServer + */ + public ViewChat() + { + initComponents(); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() + { + + tfMessage = new javax.swing.JTextField(); + pnlConnect = new javax.swing.JPanel(); + lblPort = new javax.swing.JLabel(); + tfPort = new javax.swing.JTextField(); + lblIp = new javax.swing.JLabel(); + tfIp = new javax.swing.JTextField(); + btnConnect = new javax.swing.JButton(); + pnlChat = new javax.swing.JPanel(); + jScrollPane2 = new javax.swing.JScrollPane(); + taChat = new javax.swing.JTextArea(); + grafikViewChat = new kommunikation.view.GrafikView(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("Client"); + + tfMessage.setText("Nachricht"); + tfMessage.setToolTipText(""); + getContentPane().add(tfMessage, java.awt.BorderLayout.PAGE_END); + + lblPort.setText("PORT"); + pnlConnect.add(lblPort); + + tfPort.setColumns(6); + tfPort.setText("port"); + pnlConnect.add(tfPort); + + lblIp.setText("IP_ADRESSE"); + pnlConnect.add(lblIp); + + tfIp.setColumns(15); + tfIp.setText("ip-Adresse"); + pnlConnect.add(tfIp); + + btnConnect.setText("Connect"); + pnlConnect.add(btnConnect); + + getContentPane().add(pnlConnect, java.awt.BorderLayout.PAGE_START); + + pnlChat.setLayout(new java.awt.GridLayout(0, 2)); + + taChat.setColumns(20); + taChat.setRows(5); + jScrollPane2.setViewportView(taChat); + + pnlChat.add(jScrollPane2); + pnlChat.add(grafikViewChat); + + getContentPane().add(pnlChat, java.awt.BorderLayout.CENTER); + + setSize(new java.awt.Dimension(805, 631)); + setLocationRelativeTo(null); + }// //GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) + { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try + { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) + { + if ("Nimbus".equals(info.getName())) + { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } + catch (ClassNotFoundException ex) + { + java.util.logging.Logger.getLogger(ViewChat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + catch (InstantiationException ex) + { + java.util.logging.Logger.getLogger(ViewChat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + catch (IllegalAccessException ex) + { + java.util.logging.Logger.getLogger(ViewChat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + catch (javax.swing.UnsupportedLookAndFeelException ex) + { + java.util.logging.Logger.getLogger(ViewChat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + // + // + // + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() + { + public void run() + { + new ViewChat().setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton btnConnect; + private kommunikation.view.GrafikView grafikViewChat; + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JLabel lblIp; + private javax.swing.JLabel lblPort; + private javax.swing.JPanel pnlChat; + private javax.swing.JPanel pnlConnect; + private javax.swing.JTextArea taChat; + private javax.swing.JTextField tfIp; + private javax.swing.JTextField tfMessage; + private javax.swing.JTextField tfPort; + // End of variables declaration//GEN-END:variables +}