1 Commits
Author SHA1 Message Date
BakeOrDie 0b7127cebd Merge origin/master
Conflicts:
	src/wuerfelthreads/Start.java
	src/wuerfelthreads/view/WuerfelView.form
	src/wuerfelthreads/view/WuerfelView.java
2020-12-16 11:23:52 +01:00
16 changed files with 412 additions and 773 deletions
-69
View File
@@ -1,69 +0,0 @@
/*
* 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 graphicChat;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
import graphicChat.controller.CommandConnect;
import graphicChat.controller.CommandSend;
import graphicChat.controller.GraphicsController;
import graphicChat.controller.ReceiveAdapter;
import graphicChat.view.ChatView;
import graphicChat.model.ChatModel;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
/**
* Builder Class
* @author le
*/
public class Start
{
public Start()
{
JFrame frm = new JFrame();
frm.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
ChatView view = new ChatView();
ChatModel model = new ChatModel();
view.getGrafikView1().setModel(model);
GraphicsController controller = new GraphicsController(view.getGrafikView1(), model);
controller.registerEvents();
CommandConnect cmdConnect = new CommandConnect(view, model);
cmdConnect.registerEvents();
CommandSend cmdSend = new CommandSend(view, model);
cmdSend.registerEvents();
ReceiveAdapter recAdapter = new ReceiveAdapter(view, model);
recAdapter.subscribe();
view.setTitle("Chat");
view.setSize(800, 600);
view.setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception ex)
{
JOptionPane.showMessageDialog(null, ex.toString());
}
new Start();
new Start();
}
}
@@ -1,73 +0,0 @@
/*
* 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 graphicChat.controller;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.logging.Logger;
import graphicChat.logger.OhmLogger;
import graphicChat.model.ChatModel;
import graphicChat.view.ChatView;
/**
*
* @author hd, chris
*/
public class CommandConnect implements ActionListener
{
private static Logger lg = OhmLogger.getLogger();
ChatView view;
ChatModel model;
private static final int PORT = 35000;
private static final String IP_ADRESSE = "127.0.0.1";
public CommandConnect(ChatView view, ChatModel model)
{
this.view = view;
this.model = model;
}
public void registerEvents(){
view.getBtnServer().addActionListener(this);
view.getBtnClient().addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
Object src = e.getSource();
// connect to server
if(src == view.getBtnServer()){
synchronized (this){
try {
view.getLblType().setText("Server");
model.setServer(PORT);
} catch (IOException ex) {
lg.severe(ex.toString());
}
}
}
// connect to client
if(src == view.getBtnClient()){
synchronized (this){
try {
view.getLblType().setText("Client");
model.setClient(PORT, IP_ADRESSE);
} catch (IOException ex) {
lg.severe(ex.toString());
}
}
}
}
}
@@ -1,56 +0,0 @@
/*
* 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 graphicChat.controller;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Logger;
import graphicChat.logger.OhmLogger;
import graphicChat.model.ChatModel;
import graphicChat.model.Figure;
import graphicChat.view.ChatView;
import java.util.List;
import java.util.function.Supplier;
/**
*
* @author hd, christ
*/
public class CommandSend implements ActionListener
{
private static Logger lg = OhmLogger.getLogger();
ChatView view;
ChatModel model;
private List<Figure> msg;
public CommandSend(ChatView view, ChatModel model)
{
this.view = view;
this.model = model;
}
public void registerEvents(){
view.getBtnSend().addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e)
{
Object src = e.getSource();
if(src == view.getBtnSend()){
/* view get figures*/
msg = model.getSendFigures();
model.sendMessage(msg);
model.saveFigures(msg);
view.getLblStatus().setText("Nachricht gesendet");
}
}
}
@@ -1,67 +0,0 @@
/*
* 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 graphicChat.controller;
import java.util.concurrent.Flow;
import java.util.logging.Logger;
import graphicChat.logger.OhmLogger;
import graphicChat.model.ChatModel;
import graphicChat.model.Figure;
import graphicChat.view.ChatView;
import java.util.List;
/**
*
* @author hd, chris
*/
public class ReceiveAdapter implements Flow.Subscriber<List<Figure>>
{
private static Logger lg = OhmLogger.getLogger();
private ChatView view;
private ChatModel model;
private Flow.Subscription subscription;
public ReceiveAdapter(ChatView view, ChatModel model)
{
this.view = view;
this.model = model;
}
public void subscribe()
{
model.addSubscription(this);
}
@Override
public void onSubscribe(Flow.Subscription subscription)
{
this.subscription = subscription;
subscription.request(1);
}
@Override
public void onNext(List<Figure> msg)
{
view.getLblStatus().setText("Nachricht empfangen");
view.repaint();
subscription.request(1);
}
@Override
public void onError(Throwable throwable)
{
}
@Override
public void onComplete()
{
}
}
-26
View File
@@ -1,26 +0,0 @@
/*
* 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 graphicChat.logger;
import java.util.Date;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
/**
*
* @author chris
*/
public class MyFormatter extends Formatter {
@Override
public String format(LogRecord lr) {
String date = String.format("%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS %1$Tp", new Date(lr.getMillis()));
String s = ("| ")+lr.getMillis()+(" | ")+date+(" | ")+lr.getLevel().toString()+(" | ")+lr.getSourceClassName()+(" | ")+lr.getMessage()+(" | ")+"\n";
return s;
}
}
-54
View File
@@ -1,54 +0,0 @@
/*
* 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 graphicChat.logger;
import graphicChat.logger.MyFormatter;
import java.io.File;
import java.io.IOException;
import java.util.logging.*;
/**
*
* @author chris, hd
*/
public class OhmLogger
{
public 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{
String datei = System.getProperty("java.io.tmpdir") + File.separator + "log.txt";
FileHandler fh = new FileHandler(datei);
ConsoleHandler ch = new ConsoleHandler();
lg.addHandler(fh);
ch.setFormatter(new MyFormatter());
lg.setUseParentHandlers(false);
lg.addHandler(ch);
lg.setLevel(Level.ALL);
}
catch(IOException ioex)
{
System.err.println(ioex);
}
}
}
-194
View File
@@ -1,194 +0,0 @@
/*
* 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 graphicChat.model;
import graphicChat.logger.OhmLogger;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Flow;
import java.util.concurrent.SubmissionPublisher;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author hd, chris
*/
public class ChatModel implements Runnable
{
private static final Logger lg = OhmLogger.getLogger();
private final ExecutorService eService;
private final SubmissionPublisher<List<Figure>> iPublisher;
private volatile boolean laufend;
private final GraphicData gdata;
List<Figure> msg;
// BufferedReader in;
// PrintWriter out;
ObjectOutputStream objectOutput;
ObjectInputStream objectInput;
private Socket socket;
public ChatModel()
{
laufend = false;
iPublisher = new SubmissionPublisher<>();
eService = Executors.newSingleThreadExecutor();
gdata = new GraphicData();
}
public void addSubscription(Flow.Subscriber<List<Figure>> subscriber)
{
iPublisher.subscribe(subscriber);
}
public synchronized void start(){
laufend = true;
eService.submit(this);
this.notifyAll();//muss sync
lg.info("startet");
}
@Override
public void run()
{
while(true){
try {
try
{
msg = (List<Figure>)objectInput.readObject();
lg.info("Nachricht empfangen: " + String.valueOf(msg.size()));
}
catch (ClassNotFoundException ex)
{
lg.log(Level.SEVERE, null, ex);
}
addList(msg);
iPublisher.submit(msg);//wenn neue Nachricht
} catch (IOException ex) {
lg.log(Level.SEVERE, ex.toString());
}
}
}
public void setSocket(Socket s) throws IOException
{
InputStream iStream = s.getInputStream();
OutputStream oStream = s.getOutputStream();
objectOutput = new ObjectOutputStream(oStream);
// objectOutput.writeObject(msg);
objectInput = new ObjectInputStream(iStream);
start();
}
public void setClient(int PORT, String IP_ADRESSE) throws IOException
{
Thread connectThread = new Thread(new Runnable() {
@Override
public void run() {
try {
lg.info("Client: verbinde ...");
Socket s = new Socket(IP_ADRESSE, PORT); // Achtung: blockiert!
setSocket(s);
lg.info("Client: Verbindung hergestellt");
} catch (Exception e) {
// e.printStackTrace();
lg.info("Client: Verbindung fehlgeschlagen: " + e);
}
}
});
connectThread.start();
}
public void setServer(int PORT) throws IOException
{
Thread connectThread;
connectThread = new Thread(new Runnable() {
@Override
public void run() {
try {
ServerSocket sSocket = new ServerSocket(PORT);
lg.info("Server: Warte auf Verbindung ...");
Socket s = sSocket.accept(); // Achtung: blockiert!
setSocket(s);
lg.info("Server: Verbindung akzeptiert");
} catch (IOException e) {
// e.printStackTrace();
lg.info("Server: Verbindung fehlgeschlagen: " + e);
}
}
});
connectThread.start();
}
public void sendMessage(List<Figure> msg)
{
if(laufend){
lg.log(Level.INFO, "Sende Nachricht: " + String.valueOf(msg.size()));
try
{
List<Figure> cloned_list = new ArrayList<Figure>(msg);
objectOutput.writeObject(cloned_list);
objectOutput.flush();
}
catch (IOException ex)
{
Logger.getLogger(ChatModel.class.getName()).log(Level.SEVERE, null, ex);
}
}
else{
lg.log(Level.INFO, "Keine Verbindung!");
}
}
public Figure addFigure()
{
return gdata.addFigure();
}
public List<Figure> getFigures()
{
return gdata.getFigures();
}
public List<Figure> getSendFigures()
{
return gdata.getSendFigures();
}
public void addList(List<Figure> list)
{
gdata.addList(list);
}
public void saveFigures(List<Figure> list)
{
gdata.saveFigures(list);
}
}
-62
View File
@@ -1,62 +0,0 @@
/*
* 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 graphicChat.model;
import graphicChat.logger.OhmLogger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;
/**
*
* @author hd, chris
*/
public class GraphicData
{
private ArrayList<Figure> figures;
private ArrayList<Figure> send_figures;
private static final Logger lg = OhmLogger.getLogger();
public GraphicData()
{
figures = new ArrayList<>();
send_figures = new ArrayList<>();
}
public void addList(List<Figure> list)
{
figures.addAll(list);
}
public void saveFigures(List<Figure> list)
{
figures.addAll(list);
send_figures.clear();
}
// public Figure addFigure()
// {
// figures.add(new Figure());
// return figures.get(figures.size() - 1);
//
// }
public Figure addFigure()
{
send_figures.add(new Figure());
return send_figures.get(send_figures.size() - 1);
}
public List<Figure> getFigures()
{
return Collections.unmodifiableList(figures);
}
public List<Figure> getSendFigures()
{
return Collections.unmodifiableList(send_figures);
}
}
+51
View File
@@ -0,0 +1,51 @@
/*
* 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 mvcgrafik;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import mvcgrafik.controller.BtnController;
import mvcgrafik.controller.GrafikController;
import mvcgrafik.model.GrafikModel;
import mvcgrafik.view.GrafikMenuView;
import mvcgrafik.view.GrafikView;
//import mvcgrafik.ohmLogger;
/**
* Builder Class
* @author le
*/
public class Start
{
public Start()
{
JFrame frm = new JFrame();
frm.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
GrafikMenuView view = new GrafikMenuView();
GrafikModel model = new GrafikModel();
view.getGrafikView1().setModel(model);
GrafikController controller = new GrafikController(view.getGrafikView1(), model);
BtnController btncontroller = new BtnController(view, model);
controller.registerEvents();
btncontroller.registerEvents();
view.setSize(800, 600);
view.setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
new Start();
}
}
+109
View File
@@ -0,0 +1,109 @@
/*
* 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 mvcgrafik.controller;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.Preferences;
import javax.swing.JFileChooser;
import mvcgrafik.model.Figure;
import mvcgrafik.model.GrafikModel;
import mvcgrafik.view.GrafikMenuView;
import ohmlogger.OhmLogger;
/**
*
* @author le
*/
public class BtnController implements ActionListener
{
private GrafikMenuView view;
//private GrafikMenuView menuview;
private GrafikModel model;
private Figure figure;
private Point p_old;
private static Logger lg = OhmLogger.getLogger();
public BtnController(GrafikMenuView view, GrafikModel model)
{
this.view = view;
this.model = model;
}
public void registerEvents()
{
view.getBtnOpen().addActionListener(this);
view.getBtnSafe().addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource() == view.getBtnSafe())
{
Preferences pref = Preferences.userNodeForPackage(this.getClass());
String path = pref.get("DEFAULT_PATH", "");
view.getjFileChooser1().setCurrentDirectory(new File(path));
int choice = view.getjFileChooser1().showSaveDialog(view);
if (choice == JFileChooser.APPROVE_OPTION)
{
File selectedFile = view.getjFileChooser1().getSelectedFile();
pref.put("DEFAULT_PATH", selectedFile.getAbsolutePath());
try
{
//model.datenSpeichern(selectedFile);
model.speichereDatei("TEST");
}
catch (UnsupportedEncodingException ex)
{
Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex);
}
catch (IOException ex)
{
Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
if(ae.getSource() == view.getBtnOpen())
{
Preferences pref = Preferences.userNodeForPackage(this.getClass());
String path = pref.get("DEFAULT_PATH", "");
view.getjFileChooser1().setCurrentDirectory(new File(path));
int choice = view.getjFileChooser1().showOpenDialog(view);
if (choice == JFileChooser.APPROVE_OPTION)
{
File selectedFile = view.getjFileChooser1().getSelectedFile();
pref.put("DEFAULT_PATH", selectedFile.getAbsolutePath());
try
{
//model.datenLesen(selectedFile);
model.ladeDatei("TEST");
}
catch (UnsupportedEncodingException ex)
{
Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex);
}
catch (IOException | ClassNotFoundException ex)
{
Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
}
@@ -4,32 +4,32 @@
* and open the template in the editor. * and open the template in the editor.
*/ */
package graphicChat.controller; package mvcgrafik.controller;
import java.awt.Point; import java.awt.Point;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener; import java.awt.event.MouseMotionListener;
import java.util.logging.Logger; import java.util.logging.Logger;
import graphicChat.model.Figure; import mvcgrafik.model.Figure;
import graphicChat.model.ChatModel; import mvcgrafik.model.GrafikModel;
import graphicChat.logger.OhmLogger; import ohmlogger.OhmLogger;
import graphicChat.view.Surface; import mvcgrafik.view.GrafikView;
/** /**
* *
* @author le * @author le
*/ */
public class GraphicsController implements MouseMotionListener, MouseListener public class GrafikController implements MouseMotionListener, MouseListener
{ {
private Surface view; private GrafikView view;
private ChatModel model; private GrafikModel model;
private Figure figure; private Figure figure;
private Point p_old; private Point p_old;
private static Logger lg = OhmLogger.getLogger(); private static Logger lg = OhmLogger.getLogger();
public GraphicsController(Surface view, ChatModel model) public GrafikController(GrafikView view, GrafikModel model)
{ {
this.view = view; this.view = view;
this.model = model; this.model = model;
@@ -51,6 +51,7 @@ public class GraphicsController implements MouseMotionListener, MouseListener
} }
Point p = evt.getPoint(); Point p = evt.getPoint();
if(p_old != null){ if(p_old != null){
// view.drawLine(p, p_old);
view.drawLine(p, p_old); view.drawLine(p, p_old);
} }
p_old = p; p_old = p;
@@ -82,6 +83,11 @@ public class GraphicsController implements MouseMotionListener, MouseListener
p_old = null; p_old = null;
figure = null; figure = null;
lg.info("Figure finished"); lg.info("Figure finished");
if (evt.getButton() == MouseEvent.BUTTON3)
{
// view.doPrint();
view.doPrint();
}
} }
@Override @Override
@@ -4,10 +4,9 @@
* and open the template in the editor. * and open the template in the editor.
*/ */
package graphicChat.model; package mvcgrafik.model;
import java.awt.Point; import java.awt.Point;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@@ -16,7 +15,7 @@ import java.util.List;
* *
* @author chris, hd * @author chris, hd
*/ */
public class Figure implements Serializable public class Figure
{ {
private ArrayList<Point> punkte; private ArrayList<Point> punkte;
+74
View File
@@ -0,0 +1,74 @@
/*
* 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 mvcgrafik.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;
/**
*
* @author le
*/
public class GrafikModel
{
private ArrayList<Figure> figures;
public GrafikModel()
{
figures = new ArrayList<>();
}
public Figure addFigure()
{
figures.add(new Figure());
return figures.get(figures.size() - 1);
}
public List<Figure> getFigures()
{
return Collections.unmodifiableList(figures);
}
public void speichereDatei(String dateiname) throws FileNotFoundException, IOException
{
FileOutputStream fos = new FileOutputStream(dateiname);
BufferedOutputStream buffout = new BufferedOutputStream(fos);
ObjectOutputStream oos = new ObjectOutputStream(buffout);
oos.writeObject(figures);
oos.flush();
oos.close();
}
public void ladeDatei(String dateiname) throws FileNotFoundException, IOException, ClassNotFoundException
{
FileInputStream fis = new FileInputStream(dateiname);
BufferedInputStream buffin = new BufferedInputStream(fis);
ObjectInputStream ois = new ObjectInputStream(buffin);
Object obj = ois.readObject();
// if (obj instanceof ArrayList)
// {
// punkte = (ArrayList<Point>) obj;
// }
// else
// {
// Fehler ....
// }
figures = (ArrayList<Figure>) ois.readObject();
ois.close();
}
}
@@ -1,11 +1,48 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> <Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<NonVisualComponents>
<Component class="javax.swing.JFileChooser" name="jFileChooser1">
</Component>
<Menu class="javax.swing.JMenuBar" name="jMenuBar1">
<SubComponents>
<Menu class="javax.swing.JMenu" name="jMenu1">
<Properties>
<Property name="text" type="java.lang.String" value="File"/>
</Properties>
<SubComponents>
<MenuItem class="javax.swing.JMenuItem" name="btnOpen">
<Properties>
<Property name="text" type="java.lang.String" value="Open"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnOpenActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="btnSafe">
<Properties>
<Property name="text" type="java.lang.String" value="Safe"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnSafeActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Menu>
<Menu class="javax.swing.JMenu" name="jMenu2">
<Properties>
<Property name="text" type="java.lang.String" value="Edit"/>
</Properties>
</Menu>
</SubComponents>
</Menu>
</NonVisualComponents>
<Properties> <Properties>
<Property name="defaultCloseOperation" type="int" value="3"/> <Property name="defaultCloseOperation" type="int" value="3"/>
<Property name="title" type="java.lang.String" value="Zeichentool"/> <Property name="title" type="java.lang.String" value="Zeichentool"/>
</Properties> </Properties>
<SyntheticProperties> <SyntheticProperties>
<SyntheticProperty name="menuBar" type="java.lang.String" value="jMenuBar1"/>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/> <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/> <SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties> </SyntheticProperties>
@@ -19,7 +56,7 @@
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,48,0,0,1,-52"/> <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
</AuxValues> </AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
@@ -34,7 +71,7 @@
<Layout> <Layout>
<DimensionLayout dim="0"> <DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Component id="grafikView1" alignment="0" max="32767" attributes="0"/> <Component id="grafikView1" alignment="0" pref="400" max="32767" attributes="0"/>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
<DimensionLayout dim="1"> <DimensionLayout dim="1">
@@ -44,7 +81,7 @@
</DimensionLayout> </DimensionLayout>
</Layout> </Layout>
<SubComponents> <SubComponents>
<Container class="graphicChat.view.Surface" name="grafikView1"> <Container class="mvcgrafik.view.GrafikView" name="grafikView1">
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout"> <Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
<Property name="useNullLayout" type="boolean" value="true"/> <Property name="useNullLayout" type="boolean" value="true"/>
@@ -52,57 +89,5 @@
</Container> </Container>
</SubComponents> </SubComponents>
</Container> </Container>
<Container class="javax.swing.JPanel" name="jPanel2">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
<BorderConstraints direction="First"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridLayout">
<Property name="columns" type="int" value="0"/>
<Property name="rows" type="int" value="1"/>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="lblType">
</Component>
<Component class="javax.swing.JButton" name="btnClient">
<Properties>
<Property name="text" type="java.lang.String" value="Client"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnClientActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnServer">
<Properties>
<Property name="text" type="java.lang.String" value="Server"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnServerActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JButton" name="btnSend">
<Properties>
<Property name="text" type="java.lang.String" value="Send"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnSendActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
<BorderConstraints direction="After"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="lblStatus">
<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>
</SubComponents> </SubComponents>
</Form> </Form>
@@ -3,55 +3,15 @@
* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
package graphicChat.view; package mvcgrafik.view;
/** /**
* *
* @author hd * @author hd
*/ */
public class ChatView extends javax.swing.JFrame public class GrafikMenuView extends javax.swing.JFrame
{ {
/**
* @return the btnClient
*/
public javax.swing.JButton getBtnClient()
{
return btnClient;
}
/**
* @return the btnSend
*/
public javax.swing.JButton getBtnSend()
{
return btnSend;
}
/**
* @return the btnServer
*/
public javax.swing.JButton getBtnServer()
{
return btnServer;
}
/**
* @return the lblStatus
*/
public javax.swing.JLabel getLblStatus()
{
return lblStatus;
}
/**
* @return the lblType
*/
public javax.swing.JLabel getLblType()
{
return lblType;
}
/** /**
* @return the jPanel1 * @return the jPanel1
*/ */
@@ -63,7 +23,7 @@ public class ChatView extends javax.swing.JFrame
/** /**
* Creates new form GrafikMenuView * Creates new form GrafikMenuView
*/ */
public ChatView() public GrafikMenuView()
{ {
initComponents(); initComponents();
} }
@@ -80,14 +40,14 @@ public class ChatView extends javax.swing.JFrame
private void initComponents() private void initComponents()
{ {
jFileChooser1 = new javax.swing.JFileChooser();
jPanel1 = new javax.swing.JPanel(); jPanel1 = new javax.swing.JPanel();
grafikView1 = new graphicChat.view.Surface(); grafikView1 = new mvcgrafik.view.GrafikView();
jPanel2 = new javax.swing.JPanel(); jMenuBar1 = new javax.swing.JMenuBar();
lblType = new javax.swing.JLabel(); jMenu1 = new javax.swing.JMenu();
btnClient = new javax.swing.JButton(); btnOpen = new javax.swing.JMenuItem();
btnServer = new javax.swing.JButton(); btnSafe = new javax.swing.JMenuItem();
btnSend = new javax.swing.JButton(); jMenu2 = new javax.swing.JMenu();
lblStatus = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Zeichentool"); setTitle("Zeichentool");
@@ -96,7 +56,7 @@ public class ChatView extends javax.swing.JFrame
jPanel1.setLayout(jPanel1Layout); jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup( jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(grafikView1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(grafikView1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
); );
jPanel1Layout.setVerticalGroup( jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@@ -105,59 +65,47 @@ public class ChatView extends javax.swing.JFrame
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER); getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
jPanel2.setLayout(new java.awt.GridLayout(1, 0)); jMenu1.setText("File");
jPanel2.add(lblType);
btnClient.setText("Client"); btnOpen.setText("Open");
btnClient.addActionListener(new java.awt.event.ActionListener() btnOpen.addActionListener(new java.awt.event.ActionListener()
{ {
public void actionPerformed(java.awt.event.ActionEvent evt) public void actionPerformed(java.awt.event.ActionEvent evt)
{ {
btnClientActionPerformed(evt); btnOpenActionPerformed(evt);
} }
}); });
jPanel2.add(btnClient); jMenu1.add(btnOpen);
btnServer.setText("Server"); btnSafe.setText("Safe");
btnServer.addActionListener(new java.awt.event.ActionListener() btnSafe.addActionListener(new java.awt.event.ActionListener()
{ {
public void actionPerformed(java.awt.event.ActionEvent evt) public void actionPerformed(java.awt.event.ActionEvent evt)
{ {
btnServerActionPerformed(evt); btnSafeActionPerformed(evt);
} }
}); });
jPanel2.add(btnServer); jMenu1.add(btnSafe);
getContentPane().add(jPanel2, java.awt.BorderLayout.PAGE_START); jMenuBar1.add(jMenu1);
btnSend.setText("Send"); jMenu2.setText("Edit");
btnSend.addActionListener(new java.awt.event.ActionListener() jMenuBar1.add(jMenu2);
{
public void actionPerformed(java.awt.event.ActionEvent evt) setJMenuBar(jMenuBar1);
{
btnSendActionPerformed(evt);
}
});
getContentPane().add(btnSend, java.awt.BorderLayout.LINE_END);
getContentPane().add(lblStatus, java.awt.BorderLayout.PAGE_END);
pack(); pack();
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
private void btnClientActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnClientActionPerformed private void btnOpenActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnOpenActionPerformed
{//GEN-HEADEREND:event_btnClientActionPerformed {//GEN-HEADEREND:event_btnOpenActionPerformed
// TODO add your handling code here: // TODO add your handling code here:
}//GEN-LAST:event_btnClientActionPerformed }//GEN-LAST:event_btnOpenActionPerformed
private void btnServerActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnServerActionPerformed private void btnSafeActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnSafeActionPerformed
{//GEN-HEADEREND:event_btnServerActionPerformed {//GEN-HEADEREND:event_btnSafeActionPerformed
// TODO add your handling code here: // TODO add your handling code here:
}//GEN-LAST:event_btnServerActionPerformed }//GEN-LAST:event_btnSafeActionPerformed
private void btnSendActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnSendActionPerformed
{//GEN-HEADEREND:event_btnSendActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_btnSendActionPerformed
/** /**
* @param args the command line arguments * @param args the command line arguments
@@ -182,50 +130,72 @@ public class ChatView extends javax.swing.JFrame
} }
catch (ClassNotFoundException ex) catch (ClassNotFoundException ex)
{ {
java.util.logging.Logger.getLogger(ChatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(GrafikMenuView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} }
catch (InstantiationException ex) catch (InstantiationException ex)
{ {
java.util.logging.Logger.getLogger(ChatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(GrafikMenuView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} }
catch (IllegalAccessException ex) catch (IllegalAccessException ex)
{ {
java.util.logging.Logger.getLogger(ChatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(GrafikMenuView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} }
catch (javax.swing.UnsupportedLookAndFeelException ex) catch (javax.swing.UnsupportedLookAndFeelException ex)
{ {
java.util.logging.Logger.getLogger(ChatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(GrafikMenuView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} }
//</editor-fold> //</editor-fold>
//</editor-fold>
/* Create and display the form */ /* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() java.awt.EventQueue.invokeLater(new Runnable()
{ {
public void run() public void run()
{ {
new ChatView().setVisible(true); new GrafikMenuView().setVisible(true);
} }
}); });
} }
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnClient; private javax.swing.JMenuItem btnOpen;
private javax.swing.JButton btnSend; private javax.swing.JMenuItem btnSafe;
private javax.swing.JButton btnServer; private mvcgrafik.view.GrafikView grafikView1;
private graphicChat.view.Surface grafikView1; private javax.swing.JFileChooser jFileChooser1;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JLabel lblStatus;
private javax.swing.JLabel lblType;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
/** /**
* @return the grafikView1 * @return the grafikView1
*/ */
public graphicChat.view.Surface getGrafikView1() public mvcgrafik.view.GrafikView getGrafikView1()
{ {
return grafikView1; return grafikView1;
} }
/**
* @return the jFileChooser1
*/
public javax.swing.JFileChooser getjFileChooser1()
{
return jFileChooser1;
}
/**
* @return the btnOpen
*/
public javax.swing.JMenuItem getBtnOpen()
{
return btnOpen;
}
/**
* @return the btnSafe
*/
public javax.swing.JMenuItem getBtnSafe()
{
return btnSafe;
}
} }
@@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
package graphicChat.view; package mvcgrafik.view;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
@@ -12,30 +12,37 @@ import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
import java.awt.geom.Line2D; import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D; 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 java.util.logging.Logger;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.standard.DialogTypeSelection;
import javax.swing.JComponent; import javax.swing.JComponent;
import graphicChat.logger.OhmLogger; import javax.swing.JOptionPane;
import graphicChat.model.ChatModel; import mvcgrafik.model.GrafikModel;
import ohmlogger.OhmLogger;
/** /**
* *
* @author hd, chris * @author hd, chris
*/ */
public class Surface extends JComponent public class GrafikView extends JComponent implements Printable
{ {
private final static Dimension EINS = new Dimension(1, 1); private final static Dimension EINS = new Dimension(1, 1);
private static Logger lg = OhmLogger.getLogger(); private static Logger lg = OhmLogger.getLogger();
private Rectangle2D.Float pixel; private Rectangle2D.Float pixel;
private ChatModel model; private GrafikModel model;
private Point old_punkt = null; private Point old_punkt = null;
public Surface() public GrafikView()
{ {
pixel = new Rectangle2D.Float(); pixel = new Rectangle2D.Float();
this.setBackground(Color.WHITE); this.setBackground(Color.WHITE);
} }
public void setModel(ChatModel model) public void setModel(GrafikModel model)
{ {
this.model = model; this.model = model;
} }
@@ -45,7 +52,7 @@ public class Surface extends JComponent
Graphics2D g2 = (Graphics2D) this.getGraphics(); Graphics2D g2 = (Graphics2D) this.getGraphics();
Line2D.Double line = new Line2D.Double(p.getX(),p.getY(),p_old.getX(),p_old.getY()); Line2D.Double line = new Line2D.Double(p.getX(),p.getY(),p_old.getX(),p_old.getY());
g2.draw(line); g2.draw(line);
g2.dispose(); // VERY, VERY IMPORTANT g2.dispose(); // VERY, VERY WICHTIG
} }
public void drawLineG2(Point p, Point p_old, Graphics2D g2) public void drawLineG2(Point p, Point p_old, Graphics2D g2)
{ {
@@ -77,5 +84,44 @@ public class Surface extends JComponent
}); });
}); });
} }
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;
if (pageIndex == 1)
{
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;
}
}
} }