diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index b36368b..7ba9f1f 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -1067,6 +1067,15 @@ is divided into following sections: + + + + + + + + + @@ -1738,6 +1747,15 @@ is divided into following sections: + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index fe7e424..ec30bb6 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=05f3ad23 +build.xml.data.CRC32=d624b1fd build.xml.script.CRC32=1a88b66a build.xml.stylesheet.CRC32=f85dc8f2@1.108.0.48 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=05f3ad23 -nbproject/build-impl.xml.script.CRC32=fdc076e6 +nbproject/build-impl.xml.data.CRC32=d624b1fd +nbproject/build-impl.xml.script.CRC32=476a1ac9 nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.108.0.48 diff --git a/nbproject/project.properties b/nbproject/project.properties index 0f8ee00..f163320 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -37,7 +37,8 @@ endorsed.classpath= excludes= includes=** jar.compress=false -javac.classpath= +javac.classpath=\ + ${reference.Aufgabe9_mvcGrafik.jar} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false @@ -78,6 +79,8 @@ manifest.file=manifest.mf meta.inf.dir=${src.dir}/META-INF mkdist.disabled=false platform.active=default_platform +project.Aufgabe9_mvcGrafik=../../T9_mvcGrafik/Aufgabe9_mvcGrafik +reference.Aufgabe9_mvcGrafik.jar=${project.Aufgabe9_mvcGrafik}/dist/Aufgabe9_mvcGrafik.jar run.classpath=\ ${javac.classpath}:\ ${build.classes.dir} diff --git a/nbproject/project.xml b/nbproject/project.xml index 486974f..044b1b1 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -11,5 +11,15 @@ + + + Aufgabe9_mvcGrafik + jar + + jar + clean + jar + + diff --git a/src/ChatProgramm/model/Figur.java b/src/ChatProgramm/model/Figur.java new file mode 100644 index 0000000..d8756c4 --- /dev/null +++ b/src/ChatProgramm/model/Figur.java @@ -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 punkte; + + public Figur(){ + punkte = new ArrayList<>(); + } + + public void addPoint(Point p){ + punkte.add(p); + } + + public List getPunkte() + { + return Collections.unmodifiableList(punkte); + } + + public void clear(){ + punkte.clear(); + } + +} diff --git a/src/ChatProgramm/model/GrafikModel.java b/src/ChatProgramm/model/GrafikModel.java new file mode 100644 index 0000000..d5dedc7 --- /dev/null +++ b/src/ChatProgramm/model/GrafikModel.java @@ -0,0 +1,121 @@ +/* + * 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 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 getPunkte() + { + return aktuelleFigur.getPunkte(); + } + + public List 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)daten; +// } + //eleganter + if (daten instanceof ArrayList liste) + { + figuren = liste; + } + + } + + public void endShape() { + figuren.add(aktuelleFigur); + aktuelleFigur = new Figur(); + } + + /** + * Bestimmt die Adresse des zuletzt besuchten Ordners + * @return letzter Ordner + */ + public String getPref() + { + pref = Preferences.userNodeForPackage(getClass()); + return pref.get("lastDirectory", null); + } + + /** + * Setzt die Preferenz zu dem zuletzt besuchten Ordner + * @param lastDirectory Bezeichner "lastDirectory" + * @param lastAdress Adresse des zuletzt besuchten Ordners + */ + public void putPref(String lastDirectory, String lastAdress) + { + pref.put(lastDirectory, lastAdress); + } +} + + diff --git a/src/ChatProgramm/view/ChatView.java b/src/ChatProgramm/view/ChatView.java index 08ad619..6b6f782 100644 --- a/src/ChatProgramm/view/ChatView.java +++ b/src/ChatProgramm/view/ChatView.java @@ -25,115 +25,102 @@ public class ChatView extends javax.swing.JFrame * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() - { + // //GEN-BEGIN:initComponents + private void initComponents() { - dialogChooseMode = new javax.swing.JDialog(); - lblMode = new javax.swing.JLabel(); - BtnServer = new javax.swing.JRadioButton(); - BtnClient = new javax.swing.JRadioButton(); - jPanel1 = new javax.swing.JPanel(); - BtnConnect = new javax.swing.JButton(); - BtnGrpMode = new javax.swing.ButtonGroup(); - tfNachricht = new javax.swing.JTextField(); - jScrollPane2 = new javax.swing.JScrollPane(); - txtChat = new javax.swing.JTextArea(); + dialogChooseMode = new javax.swing.JDialog(); + lblMode = new javax.swing.JLabel(); + BtnServer = new javax.swing.JRadioButton(); + BtnClient = new javax.swing.JRadioButton(); + jPanel1 = new javax.swing.JPanel(); + BtnConnect = new javax.swing.JButton(); + BtnGrpMode = new javax.swing.ButtonGroup(); + tfNachricht = new javax.swing.JTextField(); + jScrollPane2 = new javax.swing.JScrollPane(); + txtChat = new javax.swing.JTextArea(); - dialogChooseMode.setMinimumSize(new java.awt.Dimension(278, 208)); - dialogChooseMode.getContentPane().setLayout(new java.awt.GridLayout(0, 1)); + dialogChooseMode.setMinimumSize(new java.awt.Dimension(278, 208)); + dialogChooseMode.getContentPane().setLayout(new java.awt.GridLayout(0, 1)); - lblMode.setText(" Choose your mode:"); - dialogChooseMode.getContentPane().add(lblMode); + lblMode.setText(" Choose your mode:"); + dialogChooseMode.getContentPane().add(lblMode); - BtnGrpMode.add(BtnServer); - BtnServer.setText("Server"); - BtnServer.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(java.awt.event.ActionEvent evt) - { - BtnServerActionPerformed(evt); - } - }); - dialogChooseMode.getContentPane().add(BtnServer); + BtnGrpMode.add(BtnServer); + BtnServer.setText("Server"); + BtnServer.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + BtnServerActionPerformed(evt); + } + }); + dialogChooseMode.getContentPane().add(BtnServer); - BtnGrpMode.add(BtnClient); - BtnClient.setText("Client"); - BtnClient.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(java.awt.event.ActionEvent evt) - { - BtnClientActionPerformed(evt); - } - }); - dialogChooseMode.getContentPane().add(BtnClient); + BtnGrpMode.add(BtnClient); + BtnClient.setText("Client"); + BtnClient.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + BtnClientActionPerformed(evt); + } + }); + dialogChooseMode.getContentPane().add(BtnClient); - BtnConnect.setText("Connect"); - BtnConnect.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(java.awt.event.ActionEvent evt) - { - BtnConnectActionPerformed(evt); - } - }); + BtnConnect.setText("Connect"); + BtnConnect.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + BtnConnectActionPerformed(evt); + } + }); - javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); - jPanel1.setLayout(jPanel1Layout); - jPanel1Layout.setHorizontalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap(65, Short.MAX_VALUE) - .addComponent(BtnConnect) - .addContainerGap(76, Short.MAX_VALUE)) - ); - jPanel1Layout.setVerticalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addComponent(BtnConnect) - .addContainerGap(57, Short.MAX_VALUE)) - ); + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); + jPanel1.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap(65, Short.MAX_VALUE) + .addComponent(BtnConnect) + .addContainerGap(76, Short.MAX_VALUE)) + ); + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addComponent(BtnConnect) + .addContainerGap(57, Short.MAX_VALUE)) + ); - dialogChooseMode.getContentPane().add(jPanel1); + dialogChooseMode.getContentPane().add(jPanel1); - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - setMinimumSize(new java.awt.Dimension(568, 548)); - addWindowListener(new java.awt.event.WindowAdapter() - { - public void windowOpened(java.awt.event.WindowEvent evt) - { - formWindowOpened(evt); - } - }); + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setMinimumSize(new java.awt.Dimension(568, 548)); + addWindowListener(new java.awt.event.WindowAdapter() { + public void windowOpened(java.awt.event.WindowEvent evt) { + formWindowOpened(evt); + } + }); - tfNachricht.setToolTipText(""); - tfNachricht.addMouseListener(new java.awt.event.MouseAdapter() - { - public void mouseClicked(java.awt.event.MouseEvent evt) - { - tfNachrichtMouseClicked(evt); - } - }); - tfNachricht.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(java.awt.event.ActionEvent evt) - { - tfNachrichtActionPerformed(evt); - } - }); - getContentPane().add(tfNachricht, java.awt.BorderLayout.PAGE_END); + 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)); + jScrollPane2.setPreferredSize(new java.awt.Dimension(238, 150)); - txtChat.setColumns(20); - txtChat.setRows(5); - txtChat.setText("Chat:"); - jScrollPane2.setViewportView(txtChat); + txtChat.setColumns(20); + txtChat.setRows(5); + txtChat.setText("Chat:"); + jScrollPane2.setViewportView(txtChat); - getContentPane().add(jScrollPane2, java.awt.BorderLayout.CENTER); + getContentPane().add(jScrollPane2, java.awt.BorderLayout.CENTER); - pack(); - }// //GEN-END:initComponents + pack(); + }// //GEN-END:initComponents private void BtnClientActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_BtnClientActionPerformed {//GEN-HEADEREND:event_BtnClientActionPerformed @@ -214,18 +201,18 @@ public class ChatView extends javax.swing.JFrame }); } - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JRadioButton BtnClient; - private javax.swing.JButton BtnConnect; - private javax.swing.ButtonGroup BtnGrpMode; - private javax.swing.JRadioButton BtnServer; - private javax.swing.JDialog dialogChooseMode; - private javax.swing.JPanel jPanel1; - private javax.swing.JScrollPane jScrollPane2; - private javax.swing.JLabel lblMode; - private javax.swing.JTextField tfNachricht; - private javax.swing.JTextArea txtChat; - // End of variables declaration//GEN-END:variables + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JRadioButton BtnClient; + private javax.swing.JButton BtnConnect; + private javax.swing.ButtonGroup BtnGrpMode; + private javax.swing.JRadioButton BtnServer; + private javax.swing.JDialog dialogChooseMode; + private javax.swing.JPanel jPanel1; + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JLabel lblMode; + private javax.swing.JTextField tfNachricht; + private javax.swing.JTextArea txtChat; + // End of variables declaration//GEN-END:variables /** * @return the BtnClient