From ec1e01acbfb3a5f319026c1c7775b091d954a162 Mon Sep 17 00:00:00 2001 From: BobCaSUaL Date: Thu, 18 Sep 2014 13:15:42 +0200 Subject: [PATCH 01/45] Separazione Casi d'Uso --- nbproject/project.properties | 2 +- src/{view/Login.form => GUI/Main.form} | 0 src/{view/Login.java => GUI/Main.java} | 29 ++++---- src/{view => GUI/user}/LeggiMessaggi.form | 0 src/{view => GUI/user}/LeggiMessaggi.java | 2 +- src/{view => GUI/user}/NuoveProposte.form | 0 src/{view => GUI/user}/NuoveProposte.java | 6 +- src/{view => GUI/user}/NuovoMessaggio.form | 0 src/{view => GUI/user}/NuovoMessaggio.java | 3 +- .../user}/PropostaSistemaDiCifratura.form | 0 .../user}/PropostaSistemaDiCifratura.java | 6 +- src/{view => GUI/user}/Registrazione.form | 0 src/{view => GUI/user}/Registrazione.java | 2 +- .../user}/Utente_Regolamentare.form | 0 .../user}/Utente_Regolamentare.java | 4 +- src/controller/CommunicationController.java | 6 +- src/controller/Controller.java | 6 +- src/db/DbManager.java | 4 +- src/db/DbManager0.java | 4 +- src/model/Messaggio.java | 2 + src/model/spia/Ipotesi.java | 33 ++++++++++ src/model/spia/Sessione.java | 66 +++++++++++++++++++ src/model/spia/SistemaDiSupporto.java | 19 ++++++ src/model/spia/Spia.java | 15 +++++ src/model/{ => user}/CalcolatoreCesare.java | 2 +- .../{ => user}/CalcolatoreMappatura.java | 2 +- .../{ => user}/CalcolatoreParolaChiave.java | 2 +- .../{ => user}/CalcolatorePseudocasuale.java | 2 +- src/model/{ => user}/Cifratore.java | 2 +- src/model/{ => user}/Mappatura.java | 2 +- src/model/{ => user}/Proposta.java | 3 +- src/model/{ => user}/PropostaConfermata.java | 4 +- src/model/{ => user}/SistemaCifratura.java | 5 +- src/progetto_sas/Progetto_SAS.java | 28 -------- 34 files changed, 184 insertions(+), 77 deletions(-) rename src/{view/Login.form => GUI/Main.form} (100%) rename src/{view/Login.java => GUI/Main.java} (93%) rename src/{view => GUI/user}/LeggiMessaggi.form (100%) rename src/{view => GUI/user}/LeggiMessaggi.java (99%) rename src/{view => GUI/user}/NuoveProposte.form (100%) rename src/{view => GUI/user}/NuoveProposte.java (98%) rename src/{view => GUI/user}/NuovoMessaggio.form (100%) rename src/{view => GUI/user}/NuovoMessaggio.java (99%) rename src/{view => GUI/user}/PropostaSistemaDiCifratura.form (100%) rename src/{view => GUI/user}/PropostaSistemaDiCifratura.java (99%) rename src/{view => GUI/user}/Registrazione.form (100%) rename src/{view => GUI/user}/Registrazione.java (97%) rename src/{view => GUI/user}/Utente_Regolamentare.form (100%) rename src/{view => GUI/user}/Utente_Regolamentare.java (99%) create mode 100644 src/model/spia/Ipotesi.java create mode 100644 src/model/spia/Sessione.java create mode 100644 src/model/spia/SistemaDiSupporto.java create mode 100644 src/model/spia/Spia.java rename src/model/{ => user}/CalcolatoreCesare.java (92%) rename src/model/{ => user}/CalcolatoreMappatura.java (90%) rename src/model/{ => user}/CalcolatoreParolaChiave.java (91%) rename src/model/{ => user}/CalcolatorePseudocasuale.java (91%) rename src/model/{ => user}/Cifratore.java (94%) rename src/model/{ => user}/Mappatura.java (94%) rename src/model/{ => user}/Proposta.java (95%) rename src/model/{ => user}/PropostaConfermata.java (90%) rename src/model/{ => user}/SistemaCifratura.java (95%) delete mode 100644 src/progetto_sas/Progetto_SAS.java diff --git a/nbproject/project.properties b/nbproject/project.properties index 0825295..b007f4a 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -56,7 +56,7 @@ javadoc.splitindex=true javadoc.use=true javadoc.version=false javadoc.windowtitle= -main.class=progetto_sas.Progetto_SAS +main.class=GUI.Main manifest.file=manifest.mf meta.inf.dir=${src.dir}/META-INF mkdist.disabled=false diff --git a/src/view/Login.form b/src/GUI/Main.form similarity index 100% rename from src/view/Login.form rename to src/GUI/Main.form diff --git a/src/view/Login.java b/src/GUI/Main.java similarity index 93% rename from src/view/Login.java rename to src/GUI/Main.java index f801757..2e03030 100644 --- a/src/view/Login.java +++ b/src/GUI/Main.java @@ -1,28 +1,21 @@ -/* - * 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 view; +package GUI; -import model.Session; -/*import Clmodeltudente; -import ClasmodelrInfo;*/ -import controller.Controller; +import GUI.user.Registrazione; +import GUI.user.Utente_Regolamentare; import java.util.Vector; +import model.Session; import model.Studente; /** * * @author MASTER */ -public class Login extends javax.swing.JFrame { +public class Main extends javax.swing.JFrame { /** * Creates new form Login */ - public Login() { + public Main() { initComponents(); } @@ -231,20 +224,20 @@ public static void main(String args[]) { } } } catch (ClassNotFoundException ex) { - java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(Main.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 Login().setVisible(true); + new Main().setVisible(true); } }); } diff --git a/src/view/LeggiMessaggi.form b/src/GUI/user/LeggiMessaggi.form similarity index 100% rename from src/view/LeggiMessaggi.form rename to src/GUI/user/LeggiMessaggi.form diff --git a/src/view/LeggiMessaggi.java b/src/GUI/user/LeggiMessaggi.java similarity index 99% rename from src/view/LeggiMessaggi.java rename to src/GUI/user/LeggiMessaggi.java index d2d7b97..cf03770 100644 --- a/src/view/LeggiMessaggi.java +++ b/src/GUI/user/LeggiMessaggi.java @@ -4,7 +4,7 @@ * and open the template in the editor. */ -package view; +package GUI.user; import model.Messaggio; import model.MessaggioDestinatario; diff --git a/src/view/NuoveProposte.form b/src/GUI/user/NuoveProposte.form similarity index 100% rename from src/view/NuoveProposte.form rename to src/GUI/user/NuoveProposte.form diff --git a/src/view/NuoveProposte.java b/src/GUI/user/NuoveProposte.java similarity index 98% rename from src/view/NuoveProposte.java rename to src/GUI/user/NuoveProposte.java index 2090899..5186fda 100644 --- a/src/view/NuoveProposte.java +++ b/src/GUI/user/NuoveProposte.java @@ -4,9 +4,9 @@ * and open the template in the editor. */ -package view; +package GUI.user; -import model.Proposta; +import model.user.Proposta; /*import Clmodelession; import ClasmodelrInfo;*/ import controller.CommunicationController; @@ -72,7 +72,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 624, Short.MAX_VALUE) + .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 624, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1) diff --git a/src/view/NuovoMessaggio.form b/src/GUI/user/NuovoMessaggio.form similarity index 100% rename from src/view/NuovoMessaggio.form rename to src/GUI/user/NuovoMessaggio.form diff --git a/src/view/NuovoMessaggio.java b/src/GUI/user/NuovoMessaggio.java similarity index 99% rename from src/view/NuovoMessaggio.java rename to src/GUI/user/NuovoMessaggio.java index c0ddc1d..40b163e 100644 --- a/src/view/NuovoMessaggio.java +++ b/src/GUI/user/NuovoMessaggio.java @@ -4,8 +4,9 @@ * and open the template in the editor. */ -package view; +package GUI.user; +import model.user.PropostaConfermata; import controller.CommunicationController; import model.*; import controller.Controller; diff --git a/src/view/PropostaSistemaDiCifratura.form b/src/GUI/user/PropostaSistemaDiCifratura.form similarity index 100% rename from src/view/PropostaSistemaDiCifratura.form rename to src/GUI/user/PropostaSistemaDiCifratura.form diff --git a/src/view/PropostaSistemaDiCifratura.java b/src/GUI/user/PropostaSistemaDiCifratura.java similarity index 99% rename from src/view/PropostaSistemaDiCifratura.java rename to src/GUI/user/PropostaSistemaDiCifratura.java index bf86d1f..fb07a01 100644 --- a/src/view/PropostaSistemaDiCifratura.java +++ b/src/GUI/user/PropostaSistemaDiCifratura.java @@ -4,7 +4,7 @@ * and open the template in the editor. */ -package view; +package GUI.user; import model.Session; //import ClmodelserInfo; @@ -14,8 +14,8 @@ //import Controviewoller; import java.util.Vector; import javax.swing.ListModel; -import model.Proposta; -import model.SistemaCifratura; +import model.user.Proposta; +import model.user.SistemaCifratura; import model.Studente; /** diff --git a/src/view/Registrazione.form b/src/GUI/user/Registrazione.form similarity index 100% rename from src/view/Registrazione.form rename to src/GUI/user/Registrazione.form diff --git a/src/view/Registrazione.java b/src/GUI/user/Registrazione.java similarity index 97% rename from src/view/Registrazione.java rename to src/GUI/user/Registrazione.java index f371146..ac8ac12 100644 --- a/src/view/Registrazione.java +++ b/src/GUI/user/Registrazione.java @@ -4,7 +4,7 @@ * and open the template in the editor. */ -package view; +package GUI.user; import controller.Controller; import model.Studente; diff --git a/src/view/Utente_Regolamentare.form b/src/GUI/user/Utente_Regolamentare.form similarity index 100% rename from src/view/Utente_Regolamentare.form rename to src/GUI/user/Utente_Regolamentare.form diff --git a/src/view/Utente_Regolamentare.java b/src/GUI/user/Utente_Regolamentare.java similarity index 99% rename from src/view/Utente_Regolamentare.java rename to src/GUI/user/Utente_Regolamentare.java index 0ff252f..9a61905 100644 --- a/src/view/Utente_Regolamentare.java +++ b/src/GUI/user/Utente_Regolamentare.java @@ -4,9 +4,9 @@ * and open the template in the editor. */ -package view; +package GUI.user; -import model.Proposta; +import model.user.Proposta; /*import Clmodelession; import ClasmodelrInfo;*/ import controller.CommunicationController; diff --git a/src/controller/CommunicationController.java b/src/controller/CommunicationController.java index f01ba26..c15631e 100644 --- a/src/controller/CommunicationController.java +++ b/src/controller/CommunicationController.java @@ -15,9 +15,9 @@ import java.util.List; import java.util.Vector; import model.Messaggio; -import model.Proposta; -import model.PropostaConfermata; -import model.SistemaCifratura; +import model.user.Proposta; +import model.user.PropostaConfermata; +import model.user.SistemaCifratura; import model.Studente; import model.UserInfo; diff --git a/src/controller/Controller.java b/src/controller/Controller.java index 13af619..6d4f4f0 100644 --- a/src/controller/Controller.java +++ b/src/controller/Controller.java @@ -5,7 +5,7 @@ */ package controller; -import model.Proposta; +import model.user.Proposta; //import Clmodelession; //import Clasmodeldente; //import Classemodelnfo; @@ -16,9 +16,9 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Vector; -import model.PropostaConfermata; +import model.user.PropostaConfermata; import model.Session; -import model.SistemaCifratura; +import model.user.SistemaCifratura; import model.Studente; import model.UserInfo; /** diff --git a/src/db/DbManager.java b/src/db/DbManager.java index b236d0b..3c800f2 100644 --- a/src/db/DbManager.java +++ b/src/db/DbManager.java @@ -20,8 +20,8 @@ public class DbManager { private String nomeDB = "cryptohelper"; // Nome del Database a cui connettersi - private String nomeUtente = "root"; // Nome utente utilizzato per la connessione al Database - private String pwdUtente = "root"; // Password usata per la connessione al Database + private String nomeUtente = "cryptohelper"; // Nome utente utilizzato per la connessione al Database + private String pwdUtente = "cryptohelper"; // Password usata per la connessione al Database private String errore; // Raccoglie informazioni riguardo l'ultima eccezione sollevata private Connection db; // La connessione col Database private boolean connesso; // Flag che indica se la connessione è attiva o meno diff --git a/src/db/DbManager0.java b/src/db/DbManager0.java index 1c84b15..d11f3db 100644 --- a/src/db/DbManager0.java +++ b/src/db/DbManager0.java @@ -36,8 +36,8 @@ public static synchronized DbManager0 getInstance() throws SQLException { /******* object definition *******/ private String schema = "cryptohelper"; // Nome del Database a cui connettersi - private String uname = "root"; // Nome utente utilizzato per la connessione al Database - private String passw = "root"; // Password usata per la connessione al Database + private String uname = "cryptohelper"; // Nome utente utilizzato per la connessione al Database + private String passw = "cryptohelper"; // Password usata per la connessione al Database private Connection engine; // La connessione col Database diff --git a/src/model/Messaggio.java b/src/model/Messaggio.java index 4e813b9..d8765f1 100644 --- a/src/model/Messaggio.java +++ b/src/model/Messaggio.java @@ -6,6 +6,8 @@ package model; +import model.user.Cifratore; +import model.user.SistemaCifratura; import static controller.Controller.*; import db.DbManager; import db.DbManager0; diff --git a/src/model/spia/Ipotesi.java b/src/model/spia/Ipotesi.java new file mode 100644 index 0000000..a040a77 --- /dev/null +++ b/src/model/spia/Ipotesi.java @@ -0,0 +1,33 @@ +package model.spia; + + +import java.util.Enumeration; +import javax.swing.tree.TreeNode; + +/* + * 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. + */ + +/** + * + * @author user + */ +public class Ipotesi extends javax.swing.tree.DefaultMutableTreeNode { + + private char cifrata; + private char inChiaro; + + private String messaggioParzialmenteDecifrato; + + + public void add( Ipotesi p ) { + super.add( p ); + } + + public void remove( Ipotesi p ) { + super.remove( p ); + } + +} diff --git a/src/model/spia/Sessione.java b/src/model/spia/Sessione.java new file mode 100644 index 0000000..a7a3418 --- /dev/null +++ b/src/model/spia/Sessione.java @@ -0,0 +1,66 @@ +package model.spia; + + +import model.Messaggio; +import model.Messaggio; + + + +/* + * 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. + */ + +/** + * + * @author user + */ +public class Sessione { + + public static class Properties extends java.util.Hashtable {} + + public static Sessione startNewSessione() { + //DO CODE + return new Sessione( (Properties)null ); + } + public static Sessione restoreSessione() { + //DO CODE + return new Sessione( (Properties)null ); + } + public static void deleteSessione( Sessione sessione ) { + //DO CODE + } + + public static void saveSession( Sessione sessione ) { + //DO CODE + } + + + private Ipotesi root; + private Ipotesi ipCorrente; + + private Properties properties; + + public Sessione( Properties p ) { + this.properties = p; + } + public Sessione( Messaggio m ) { + this( new Properties() ); + this.properties.put("messaggio", m); + } + + public Ipotesi getIpotesiRadice() { + return root; + } + public Ipotesi getIpotesiCorrente() { + return ipCorrente; + } + public Properties getProperties() { + return properties; + } + + public void start() { + //DO CODE + } +} diff --git a/src/model/spia/SistemaDiSupporto.java b/src/model/spia/SistemaDiSupporto.java new file mode 100644 index 0000000..9c70579 --- /dev/null +++ b/src/model/spia/SistemaDiSupporto.java @@ -0,0 +1,19 @@ +package model.spia; + + +import model.Messaggio; +import model.Messaggio; + +/* + * 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. + */ + +/** + * + * @author user + */ +public interface SistemaDiSupporto { + public Ipotesi start(Ipotesi ipCorrente, Messaggio messaggio); +} diff --git a/src/model/spia/Spia.java b/src/model/spia/Spia.java new file mode 100644 index 0000000..908d118 --- /dev/null +++ b/src/model/spia/Spia.java @@ -0,0 +1,15 @@ +package model.spia; + +/* + * 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. + */ + +/** + * + * @author user + */ +public interface Spia { + +} diff --git a/src/model/CalcolatoreCesare.java b/src/model/user/CalcolatoreCesare.java similarity index 92% rename from src/model/CalcolatoreCesare.java rename to src/model/user/CalcolatoreCesare.java index f4b4bf0..dd3fe5f 100644 --- a/src/model/CalcolatoreCesare.java +++ b/src/model/user/CalcolatoreCesare.java @@ -4,7 +4,7 @@ * and open the template in the editor. */ -package model; +package model.user; /** * diff --git a/src/model/CalcolatoreMappatura.java b/src/model/user/CalcolatoreMappatura.java similarity index 90% rename from src/model/CalcolatoreMappatura.java rename to src/model/user/CalcolatoreMappatura.java index 5b175a0..4743378 100644 --- a/src/model/CalcolatoreMappatura.java +++ b/src/model/user/CalcolatoreMappatura.java @@ -4,7 +4,7 @@ * and open the template in the editor. */ -package model; +package model.user; /** * diff --git a/src/model/CalcolatoreParolaChiave.java b/src/model/user/CalcolatoreParolaChiave.java similarity index 91% rename from src/model/CalcolatoreParolaChiave.java rename to src/model/user/CalcolatoreParolaChiave.java index 8c74c35..e98c410 100644 --- a/src/model/CalcolatoreParolaChiave.java +++ b/src/model/user/CalcolatoreParolaChiave.java @@ -4,7 +4,7 @@ * and open the template in the editor. */ -package model; +package model.user; /** * diff --git a/src/model/CalcolatorePseudocasuale.java b/src/model/user/CalcolatorePseudocasuale.java similarity index 91% rename from src/model/CalcolatorePseudocasuale.java rename to src/model/user/CalcolatorePseudocasuale.java index 8772b3e..3ed51e2 100644 --- a/src/model/CalcolatorePseudocasuale.java +++ b/src/model/user/CalcolatorePseudocasuale.java @@ -4,7 +4,7 @@ * and open the template in the editor. */ -package model; +package model.user; /** * diff --git a/src/model/Cifratore.java b/src/model/user/Cifratore.java similarity index 94% rename from src/model/Cifratore.java rename to src/model/user/Cifratore.java index 4105899..c1f2e2e 100644 --- a/src/model/Cifratore.java +++ b/src/model/user/Cifratore.java @@ -4,7 +4,7 @@ * and open the template in the editor. */ -package model; +package model.user; /** * diff --git a/src/model/Mappatura.java b/src/model/user/Mappatura.java similarity index 94% rename from src/model/Mappatura.java rename to src/model/user/Mappatura.java index 303cc72..50dacaa 100644 --- a/src/model/Mappatura.java +++ b/src/model/user/Mappatura.java @@ -4,7 +4,7 @@ * and open the template in the editor. */ -package model; +package model.user; /** * diff --git a/src/model/Proposta.java b/src/model/user/Proposta.java similarity index 95% rename from src/model/Proposta.java rename to src/model/user/Proposta.java index a19fc54..892aadf 100644 --- a/src/model/Proposta.java +++ b/src/model/user/Proposta.java @@ -4,7 +4,7 @@ * and open the template in the editor. */ -package model; +package model.user; import controller.Controller; //import static controller.Controller.connect; @@ -13,6 +13,7 @@ import db.Query; import db.QueryResult; import java.sql.SQLException; +import model.UserInfo; /** * diff --git a/src/model/PropostaConfermata.java b/src/model/user/PropostaConfermata.java similarity index 90% rename from src/model/PropostaConfermata.java rename to src/model/user/PropostaConfermata.java index fb44e26..7812eb1 100644 --- a/src/model/PropostaConfermata.java +++ b/src/model/user/PropostaConfermata.java @@ -4,7 +4,9 @@ * and open the template in the editor. */ -package model; +package model.user; + +import model.UserInfo; /** * diff --git a/src/model/SistemaCifratura.java b/src/model/user/SistemaCifratura.java similarity index 95% rename from src/model/SistemaCifratura.java rename to src/model/user/SistemaCifratura.java index 070d64f..51b9897 100644 --- a/src/model/SistemaCifratura.java +++ b/src/model/user/SistemaCifratura.java @@ -4,7 +4,7 @@ * and open the template in the editor. */ -package model; +package model.user; //import static controller.Controller.connect; import db.DbManager; @@ -13,6 +13,9 @@ import db.QueryResult; import java.sql.SQLException; import java.util.Vector; +import model.Session; +import model.Studente; +import model.UserInfo; /** * diff --git a/src/progetto_sas/Progetto_SAS.java b/src/progetto_sas/Progetto_SAS.java deleted file mode 100644 index d014b98..0000000 --- a/src/progetto_sas/Progetto_SAS.java +++ /dev/null @@ -1,28 +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 progetto_sas; - -import view.Login; -//import jrogetto_sas.GUI.*; -import java.util.Vector; -import javax.swing.JFrame; - -/** - * - * @author MASTER - */ -public class Progetto_SAS { - - /** - * @param args the command line arguments - */ - public static void main(String[] args) { - Login l = new Login(); - l.setVisible(true); - l.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - } - -} From fba829de218522dae9cd58eb3ed3f200e303c5e1 Mon Sep 17 00:00:00 2001 From: BobCaSUaL Date: Thu, 18 Sep 2014 19:15:32 +0200 Subject: [PATCH 02/45] Ulteriore separazione Casi d'Uso e separazione GUI. ->MultiThreaded component GUI spia! --- src/GUI/Main.java | 25 +-- src/GUI/spia/GestisciSessioneDiLavoro.form | 77 +++++++ src/GUI/spia/GestisciSessioneDiLavoro.java | 142 ++++++++++++ src/GUI/spia/ListaMessaggiCifrati.form | 80 +++++++ src/GUI/spia/ListaMessaggiCifrati.java | 188 ++++++++++++++++ src/GUI/user/NuovoMessaggio.java | 2 +- src/controller/CommunicationController.java | 9 +- src/controller/Controller.java | 8 +- src/db/DbManager.java | 204 +++++------------- src/db/DbManager0.java | 83 ------- src/model/Messaggio.java | 64 ++++-- src/model/Studente.java | 8 +- src/model/UserInfo.java | 4 +- src/model/spia/Ipotesi.java | 3 + src/model/spia/Sessione.java | 4 +- src/model/spia/Spia.java | 8 +- .../spia/supportTools/AnalisiFrequenze.java | 23 ++ .../analisiFrequenze/AnalisiFrequenze.java | 46 ++++ .../analisiFrequenze/Replacer.java | 19 ++ src/model/user/Proposta.java | 4 +- src/model/user/SistemaCifratura.java | 13 +- .../supportTools/TesterAnalisiFrequenze.java | 33 +++ 22 files changed, 764 insertions(+), 283 deletions(-) create mode 100644 src/GUI/spia/GestisciSessioneDiLavoro.form create mode 100644 src/GUI/spia/GestisciSessioneDiLavoro.java create mode 100644 src/GUI/spia/ListaMessaggiCifrati.form create mode 100644 src/GUI/spia/ListaMessaggiCifrati.java delete mode 100644 src/db/DbManager0.java create mode 100644 src/model/spia/supportTools/AnalisiFrequenze.java create mode 100644 src/model/spia/supportTools/analisiFrequenze/AnalisiFrequenze.java create mode 100644 src/model/spia/supportTools/analisiFrequenze/Replacer.java create mode 100644 src/test/model/spia/supportTools/TesterAnalisiFrequenze.java diff --git a/src/GUI/Main.java b/src/GUI/Main.java index 2e03030..b825f26 100644 --- a/src/GUI/Main.java +++ b/src/GUI/Main.java @@ -176,26 +176,21 @@ private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS }//GEN-LAST:event_jButton3ActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - // TODO add your handling code here: - Vector v; - if(jTextField1.getText().equals("")) + + if (jTextField1.getText().equals("")) { jLabel4.setText("Inserisci username"); - if(jPasswordField1.getPassword().equals("")) + } + if (jPasswordField1.getPassword().equals("")) { jLabel4.setText("Inserisci Password"); - else{ - Studente s = new Studente(jTextField1.getText(), ""+jPasswordField1.getText(), true); + } else { + Studente s = new Studente(jTextField1.getText(), "" + jPasswordField1.getText(), true); boolean conferma = s.login(); - if(!conferma) + if (!conferma) { jLabel4.setText("Username e/o password non corretti: riprova"); - else{ - //jLabel4.setText("Ok sei loggato"); - Session g = new Session(s.getId(), s.toString()); - Utente_Regolamentare m = new Utente_Regolamentare(); - m.setVisible(true); + } else { + new Utente_Regolamentare().setVisible(true); } - - - + } }//GEN-LAST:event_jButton1ActionPerformed diff --git a/src/GUI/spia/GestisciSessioneDiLavoro.form b/src/GUI/spia/GestisciSessioneDiLavoro.form new file mode 100644 index 0000000..9fdbff1 --- /dev/null +++ b/src/GUI/spia/GestisciSessioneDiLavoro.form @@ -0,0 +1,77 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/spia/GestisciSessioneDiLavoro.java b/src/GUI/spia/GestisciSessioneDiLavoro.java new file mode 100644 index 0000000..3c4e4a5 --- /dev/null +++ b/src/GUI/spia/GestisciSessioneDiLavoro.java @@ -0,0 +1,142 @@ +/* + * 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 GUI.spia; + +import model.spia.Sessione; + +/** + * + * @author user + */ +public class GestisciSessioneDiLavoro extends javax.swing.JFrame { + + /** + * Creates new form GestisciSessioneDiLavoro + */ + public GestisciSessioneDiLavoro() { + 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() { + + jButton1 = new javax.swing.JButton(); + jButton2 = new javax.swing.JButton(); + jButton3 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jButton1.setText("Nuova Sesione"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jButton2.setText("Ripristina Sessione"); + jButton2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton2ActionPerformed(evt); + } + }); + + jButton3.setText("Elimina Sessione"); + jButton3.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton3ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(25, 25, 25) + .addComponent(jButton1) + .addGap(33, 33, 33) + .addComponent(jButton2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE) + .addComponent(jButton3) + .addGap(34, 34, 34)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(59, 59, 59) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton1) + .addComponent(jButton2) + .addComponent(jButton3)) + .addContainerGap(212, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + // TODO add your handling code here: + Sessione s = Sessione.startNewSessione(); + }//GEN-LAST:event_jButton1ActionPerformed + + private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed + // TODO add your handling code here: + Sessione s = Sessione.restoreSessione(); + }//GEN-LAST:event_jButton2ActionPerformed + + private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed + // TODO add your handling code here: + Sessione.deleteSessione(null); + }//GEN-LAST:event_jButton3ActionPerformed + + /** + * @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(GestisciSessioneDiLavoro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(GestisciSessioneDiLavoro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(GestisciSessioneDiLavoro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(GestisciSessioneDiLavoro.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 GestisciSessioneDiLavoro().setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + private javax.swing.JButton jButton3; + // End of variables declaration//GEN-END:variables +} diff --git a/src/GUI/spia/ListaMessaggiCifrati.form b/src/GUI/spia/ListaMessaggiCifrati.form new file mode 100644 index 0000000..230d58d --- /dev/null +++ b/src/GUI/spia/ListaMessaggiCifrati.form @@ -0,0 +1,80 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/spia/ListaMessaggiCifrati.java b/src/GUI/spia/ListaMessaggiCifrati.java new file mode 100644 index 0000000..4be3733 --- /dev/null +++ b/src/GUI/spia/ListaMessaggiCifrati.java @@ -0,0 +1,188 @@ +/* + * 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 GUI.spia; + +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import model.Messaggio; + +/** + * + * @author user + */ +public class ListaMessaggiCifrati extends javax.swing.JFrame { + + public static Messaggio getMessaggio() { + final SynchronizedBuffer buff = new SynchronizedBuffer<>(); + + new Thread( new Runnable() { + public void run() { + ListaMessaggiCifrati listaMessaggiCifrati = new ListaMessaggiCifrati(buff); + listaMessaggiCifrati.setVisible(true); + } + } ).start(); + + return buff.get(); + } + public static class SynchronizedBuffer { + private T contents; + private boolean available = false; + + public synchronized T get() { + while (available == false) { + try { + wait(); + } catch (InterruptedException e) { } + } + available = false; + notifyAll(); + return contents; + } + + public synchronized void put(T value) { + while (available == true) { + try { + wait(); + } catch (InterruptedException e) { } + } + contents = value; + available = true; + notifyAll(); + } + } + + SynchronizedBuffer syncBuffer; + public ListaMessaggiCifrati( SynchronizedBuffer c ) { + this(); + this.syncBuffer = c; + } + /** + * Creates new form NuovaSessione + */ + public ListaMessaggiCifrati () { + initComponents(); + List list = Messaggio.getMessaggi(); + Messaggio[] arr = list.toArray( new Messaggio[list.size()] ); + for( Messaggio m: arr) { + m.setToStringF("%lingua%, %testoCif%"); + } + jList1.setListData(arr); + + } + + /** + * 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() { + + jScrollPane1 = new javax.swing.JScrollPane(); + jList1 = new javax.swing.JList(); + jButton1 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jList1.setModel(new javax.swing.AbstractListModel() { + String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; + public int getSize() { return strings.length; } + public Object getElementAt(int i) { return strings[i]; } + }); + jScrollPane1.setViewportView(jList1); + + jButton1.setText("Scegli"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jButton1) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 335, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(53, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(23, 23, 23) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(44, 44, 44) + .addComponent(jButton1) + .addContainerGap(64, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + // TODO add your handling code here: + Messaggio m = (Messaggio)jList1.getSelectedValue(); + this.syncBuffer.put(m); + this.dispose(); + }//GEN-LAST:event_jButton1ActionPerformed + + /** + * @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(ListaMessaggiCifrati.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(ListaMessaggiCifrati.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(ListaMessaggiCifrati.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(ListaMessaggiCifrati.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + + + final SynchronizedBuffer b = new SynchronizedBuffer(); + + new Thread( new Runnable() { + public void run() { + ListaMessaggiCifrati listaMessaggiCifrati = new ListaMessaggiCifrati(b); + listaMessaggiCifrati.setVisible(true); + } + } ).start(); + + + System.out.println( b.get() ); + } + + + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JList jList1; + private javax.swing.JScrollPane jScrollPane1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/GUI/user/NuovoMessaggio.java b/src/GUI/user/NuovoMessaggio.java index 40b163e..b2fa7a2 100644 --- a/src/GUI/user/NuovoMessaggio.java +++ b/src/GUI/user/NuovoMessaggio.java @@ -18,7 +18,7 @@ public class NuovoMessaggio extends javax.swing.JFrame { private PropostaConfermata[] a = CommunicationController.getProposteAccettate(Session.getIdLoggedUser()); private int index; - private Messaggio m = new Messaggio(); + private Messaggio m = null; /** * Creates new form NuovoMessaggio */ diff --git a/src/controller/CommunicationController.java b/src/controller/CommunicationController.java index c15631e..6d67019 100644 --- a/src/controller/CommunicationController.java +++ b/src/controller/CommunicationController.java @@ -7,13 +7,10 @@ package controller; import db.DbManager; -import db.DbManager0; import db.Query; import db.QueryResult; import java.sql.SQLException; import java.util.ArrayList; -import java.util.List; -import java.util.Vector; import model.Messaggio; import model.user.Proposta; import model.user.PropostaConfermata; @@ -36,7 +33,7 @@ public static Proposta[] getProposte(String id_user) { //proposte pendenti ArrayList result = new ArrayList<>(); try { - DbManager0 db = DbManager0.getInstance(); + DbManager db = DbManager.getInstance(); Query q = db.createQuery("SELECT * FROM `cryptohelper`.`proposta` WHERE id_destinatario = " + id_user + " && stato = 'in attesa'"); QueryResult rs = db.execute( q ); @@ -70,7 +67,7 @@ public static PropostaConfermata[] getProposteAccettate(String id_user){ //propo ArrayList result = new ArrayList<>(); try { - DbManager0 db = DbManager0.getInstance(); + DbManager db = DbManager.getInstance(); Query q = db.createQuery("SELECT * FROM `cryptohelper`.`proposta` WHERE id_mittente = " + id_user + " && stato = 'accettata'"); QueryResult rs = db.execute( q ); @@ -111,7 +108,7 @@ public static boolean send(Messaggio m){ } public Messaggio apriMessaggioRicevuto(int id){ - return new Messaggio(); + return null; } } diff --git a/src/controller/Controller.java b/src/controller/Controller.java index 6d4f4f0..a946c9b 100644 --- a/src/controller/Controller.java +++ b/src/controller/Controller.java @@ -10,7 +10,7 @@ //import Clasmodeldente; //import Classemodelnfo; import db.DbManager; -import db.DbManager0; +import db.DbManager; import db.Query; import db.QueryResult; import java.sql.SQLException; @@ -53,7 +53,7 @@ public class Controller { public static boolean accettaProposta(Proposta p){ //DbManager db = connect(); try{ - DbManager0 db = DbManager0.getInstance(); + DbManager db = DbManager.getInstance(); Query q = db.createQuery("UPDATE `cryptohelper`.`proposta` SET `stato` = 'accettata' WHERE `proposta`.`id` = " + p.getId()); q.executeUpdate(); } @@ -70,7 +70,7 @@ public static boolean accettaProposta(Proposta p){ public static boolean rifiutaProposta(Proposta p){ try{ - DbManager0 db = DbManager0.getInstance(); + DbManager db = DbManager.getInstance(); Query q = db.createQuery("UPDATE `cryptohelper`.`proposta` SET `stato` = 'rifiutata' WHERE `proposta`.`id` = " + p.getId()); q.executeUpdate(); } @@ -102,7 +102,7 @@ public static boolean rifiutaProposta(Proposta p){ public static Studente[] recuperaUtenti(){ ArrayList result = new ArrayList<>(); try{ - DbManager0 db = DbManager0.getInstance(); + DbManager db = DbManager.getInstance(); Query q = db.createQuery("SELECT * FROM user where username <> '" + Session.getLoggedUser() + "'"); QueryResult rs = db.execute( q ); while( rs.next() ) { diff --git a/src/db/DbManager.java b/src/db/DbManager.java index 3c800f2..3f44eae 100644 --- a/src/db/DbManager.java +++ b/src/db/DbManager.java @@ -3,161 +3,75 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ + package db; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + /** * - * @author MASTER - */ -/* - * Classe dedicata alla gestione del Database. - * Gestisce l'apertura e la chiusura della connessione col Database - * Fornisce i metodi per l'esecuzione delle query sul Database + * @author BobCaSUaL */ -import java.sql.*; -import java.util.Vector; - public class DbManager { - private String nomeDB = "cryptohelper"; // Nome del Database a cui connettersi - private String nomeUtente = "cryptohelper"; // Nome utente utilizzato per la connessione al Database - private String pwdUtente = "cryptohelper"; // Password usata per la connessione al Database - private String errore; // Raccoglie informazioni riguardo l'ultima eccezione sollevata - private Connection db; // La connessione col Database - private boolean connesso; // Flag che indica se la connessione è attiva o meno - - public DbManager(String nomeDB) { - this(nomeDB, "", ""); + /********** static part *********/ + private static DbManager instance = null; + + public static synchronized DbManager getInstance() throws SQLException { + if( null == instance ) { + instance = new DbManager(); } - - public DbManager(String nomeDB, String nomeUtente, String pwdUtente) { - this.nomeDB = nomeDB; - this.nomeUtente = nomeUtente; - this.pwdUtente = pwdUtente; - connesso = false; - errore = ""; + return instance; + } + + + /******* object definition *******/ + + private String schema = "cryptohelper"; // Nome del Database a cui connettersi + private String uname = "cryptohelper"; // Nome utente utilizzato per la connessione al Database + private String passw = "cryptohelper"; // Password usata per la connessione al Database + + private Connection engine; // La connessione col Database + + + /******* internal classes *******/ + + public class QueryImpl extends QueryAbstract { + String sql; + public QueryImpl( String sql ) throws SQLException { + super( engine.prepareStatement(sql), sql ); } + } + public class QueryResultImpl extends QueryResultAbstract { -// Apre la connessione con il Database - public boolean connetti() { - connesso = false; - try { - -// Carico il driver JDBC per la connessione con il database MySQL - Class.forName("com.mysql.jdbc.Driver"); - -// Controllo che il nome del Database non sia nulla - if (!nomeDB.equals("")) { - -// Controllo se il nome utente va usato o meno per la connessione - if (nomeUtente.equals("")) { - -// La connessione non richiede nome utente e password - db = DriverManager.getConnection("jdbc:mysql://localhost/" + nomeDB); - } else { - -// La connessione richiede nome utente, controllo se necessita anche della password - if (pwdUtente.equals("")) { - -// La connessione non necessita di password - db = DriverManager.getConnection("jdbc:mysql://localhost/" + nomeDB + "?user=" + nomeUtente); - } else { - -// La connessione necessita della password - db = DriverManager.getConnection("jdbc:mysql://localhost/" + nomeDB + "?user=" + nomeUtente + "&password=" + pwdUtente); - } - } - -// La connessione è avvenuta con successo - connesso = true; - } else { - System.out.println("Manca il nome del database!!"); - System.out.println("Scrivere il nome del database da utilizzare all'interno del file \"config.xml\""); - System.exit(0); - } - } catch (Exception e) { - errore = e.getMessage(); - e.printStackTrace(); - } - return connesso; + public QueryResultImpl(Query q) throws SQLException { + super(q.executeQuery(), q); } + } + + /*public class QueryResultImpl2 extends QueryResultAbstract { -// Esegue una query di selezione dati sul Database -// query: una stringa che rappresenta un'istruzione SQL di tipo SELECT da eseguire -// colonne: il numero di colonne di cui sarà composta la tupla del risultato -// ritorna un Vector contenente tutte le tuple del risultato - public Vector eseguiQuery(String query) { - Vector v = null; - String[] record; - int colonne = 0; - try { - Statement stmt = db.createStatement(); // Creo lo Statement per l'esecuzione della query - ResultSet rs = stmt.executeQuery(query); // Ottengo il ResultSet dell'esecuzione della query - v = new Vector(); - ResultSetMetaData rsmd = rs.getMetaData(); - colonne = rsmd.getColumnCount(); - - while (rs.next()) { // Creo il vettore risultato scorrendo tutto il ResultSet - record = new String[colonne]; - for (int i = 0; i < colonne; i++) { - record[i] = rs.getString(i + 1); - } - v.add((String[]) record.clone()); - } - rs.close(); // Chiudo il ResultSet - stmt.close(); // Chiudo lo Statement - } catch (Exception e) { - e.printStackTrace(); - errore = e.getMessage(); - } - - return v; + public QueryResultImpl2(Query q) throws SQLException { + super(q.executeUpdate(), q); } - -// Esegue una query di aggiornamento sul Database -// query: una stringa che rappresenta un'istuzione SQL di tipo UPDATE da eseguire -// ritorna TRUE se l'esecuzione è adata a buon fine, FALSE se c'è stata un'eccezione - public boolean eseguiAggiornamento(String query) { - int n = 0; - boolean risultato = false; - try { - Statement stmt = db.createStatement(); - n = stmt.executeUpdate(query); - risultato = true; - stmt.close(); - } catch (Exception e) { - e.printStackTrace(); - errore = e.getMessage(); - risultato = false; - } - return risultato; - } - - /*public boolean inserisciNuovovalore(String query){ //query di insert - int n = 0; - try{ - Statement stmt = db.createStatement(); - n = stmt. - } - - return true; - }*/ - -// Chiude la connessione con il Database - public void disconnetti() { - try { - db.close(); - connesso = false; - } catch (Exception e) { - e.printStackTrace(); - } - } - - public boolean isConnesso() { - return connesso; - } // Ritorna TRUE se la connessione con il Database è attiva - - public String getErrore() { - return errore; - } // Ritorna il messaggio d'errore dell'ultima eccezione sollevata -} \ No newline at end of file + }*/ + + private DbManager() throws SQLException { + DriverManager.registerDriver( new com.mysql.jdbc.Driver() ); + engine = DriverManager.getConnection("jdbc:mysql://localhost/" + schema, uname, passw); + } + + public Query createQuery( String sql ) throws SQLException { + return new QueryImpl( sql ); + } + public QueryResult execute( Query q ) throws SQLException { + return new QueryResultImpl( q ); + } + + /*public QueryResult executeUpdate( Query q ) throws SQLException { + return new QueryResultImpl( q ); + }*/ + +} diff --git a/src/db/DbManager0.java b/src/db/DbManager0.java deleted file mode 100644 index d11f3db..0000000 --- a/src/db/DbManager0.java +++ /dev/null @@ -1,83 +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 db; - -import com.mysql.jdbc.Field; -import com.mysql.jdbc.MySQLConnection; -import com.mysql.jdbc.RowData; -import com.mysql.jdbc.StatementImpl; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -/** - * - * @author BobCaSUaL - */ -public class DbManager0 { - - /********** static part *********/ - private static DbManager0 instance = null; - - public static synchronized DbManager0 getInstance() throws SQLException { - if( null == instance ) { - instance = new DbManager0(); - } - return instance; - } - - - /******* object definition *******/ - - private String schema = "cryptohelper"; // Nome del Database a cui connettersi - private String uname = "cryptohelper"; // Nome utente utilizzato per la connessione al Database - private String passw = "cryptohelper"; // Password usata per la connessione al Database - - private Connection engine; // La connessione col Database - - - /******* internal classes *******/ - - public class QueryImpl extends QueryAbstract { - String sql; - public QueryImpl( String sql ) throws SQLException { - super( engine.prepareStatement(sql), sql ); - } - } - public class QueryResultImpl extends QueryResultAbstract { - - public QueryResultImpl(Query q) throws SQLException { - super(q.executeQuery(), q); - } - } - - /*public class QueryResultImpl2 extends QueryResultAbstract { - - public QueryResultImpl2(Query q) throws SQLException { - super(q.executeUpdate(), q); - } - }*/ - - private DbManager0() throws SQLException { - DriverManager.registerDriver( new com.mysql.jdbc.Driver() ); - engine = DriverManager.getConnection("jdbc:mysql://localhost/" + schema, uname, passw); - } - - public Query createQuery( String sql ) throws SQLException { - return new QueryImpl( sql ); - } - public QueryResult execute( Query q ) throws SQLException { - return new QueryResultImpl( q ); - } - - /*public QueryResult executeUpdate( Query q ) throws SQLException { - return new QueryResultImpl( q ); - }*/ - -} diff --git a/src/model/Messaggio.java b/src/model/Messaggio.java index d8765f1..624aa4f 100644 --- a/src/model/Messaggio.java +++ b/src/model/Messaggio.java @@ -8,15 +8,12 @@ import model.user.Cifratore; import model.user.SistemaCifratura; -import static controller.Controller.*; import db.DbManager; -import db.DbManager0; import db.Query; import db.QueryResult; -import java.awt.List; import java.sql.SQLException; +import java.util.List; import java.util.ArrayList; -import java.util.Vector; /** * @@ -29,8 +26,20 @@ public class Messaggio implements MessaggioMittente, MessaggioDestinatario{ private String testo, testoCifrato, lingua, titolo; private boolean bozza, letto; - public Messaggio(){ - /*QUERY RESULT*/ + public Messaggio(QueryResult rs) throws SQLException { + this.id = rs.getInt(1); + this.mittente = new UserInfo(rs.getString(2)); + this.destinatario = new UserInfo(rs.getString(3)); + this.testo = rs.getString(4); + this.lingua = rs.getString(6); + this.testoCifrato = rs.getString(5); + this.sdc = SistemaCifratura.load( rs.getString("idsistemacifratura") ); + this.bozza = rs.getBoolean(8); + this.letto = rs.getBoolean(9); + + + + } public Messaggio(String testo, String lingua, UserInfo mittente, UserInfo destinatario){ @@ -86,18 +95,35 @@ public void setSdc(SistemaCifratura s){ } }//carica il messaggio*/ - public static List caricaIniviati(Studente s){ - return new List(); + public static List caricaIniviati(Studente s){ + return null; } - public static List caricaBozze(Studente s){ - return new List(); + public static List caricaBozze(Studente s){ + return null; + } + + public static List getMessaggi(){ + ArrayList result = new ArrayList<>(); + try{ + DbManager db = DbManager.getInstance(); + Query q = db.createQuery("SELECT * FROM `cryptohelper`.`messaggio`"); + QueryResult rs = db.execute(q); + while( rs.next() ){ + + result.add( new Messaggio(rs) ); + } + } + catch (SQLException ex){ + throw new RuntimeException( ex.getMessage(), ex ); + } + return result; } public static MessaggioDestinatario[] caricaRicevuti(){ ArrayList result = new ArrayList<>(); try{ - DbManager0 db = DbManager0.getInstance(); + DbManager db = DbManager.getInstance(); Query q = db.createQuery("SELECT * FROM `cryptohelper`.`messaggio` WHERE id_destinatario = " + Session.getIdLoggedUser()); QueryResult rs = db.execute(q); while( rs.next() ){ @@ -153,7 +179,7 @@ public boolean save(){ System.out.println("sgsgf"); return true;*/ try{ - DbManager0 db = DbManager0.getInstance(); + DbManager db = DbManager.getInstance(); Query q = db.createQuery("INSERT INTO `cryptohelper`.`messaggio` (`id`, `id_mittente`, `id_destinatario`, `testo`, `testoCifrato`, `lingua`, `titolo`, `bozza`, `letto`) VALUES (NULL, '" +this.mittente.getId()+"', '"+this.destinatario.getId()+"', '" + this.testo + "', '" + this.testoCifrato + "' , '" + this.lingua + "', 'titoloDiProva', " + this.bozza + ", false);"); q.executeUpdate(); } @@ -167,8 +193,20 @@ public boolean isLetto(){ return true; } + private String toStringF = "Messaggio in lingua: %lingua% inviato da utente con id %mittenteID% ad utente con id %destinatario% e testo: %testo%"; + public String setToStringF( String f ) { + String result = toStringF; + this.toStringF = f; + return result; + } public String toString(){ - return "Messaggio in lingua:" + lingua + "inviato da utente con id " + this.mittente.getId() + " ad utente con id " + this.destinatario.getId() + " e testo: " + this.testo; + String result = toStringF; + result = result.replaceAll("%lingua%", lingua); + result = result.replaceAll("%mittenteID%", mittente.getId()); + result = result.replaceAll("%destinatarioID%", destinatario.getId()); + result = result.replaceAll("%testo%", testo); + result = result.replaceAll("%testoCif", testoCifrato); + return result; } public boolean send(){ diff --git a/src/model/Studente.java b/src/model/Studente.java index aadec76..58e1d33 100644 --- a/src/model/Studente.java +++ b/src/model/Studente.java @@ -8,11 +8,9 @@ //import static controller.Controller.connect; import db.DbManager; -import db.DbManager0; import db.Query; import db.QueryResult; import java.sql.SQLException; -import java.util.Vector; /** * @@ -24,7 +22,7 @@ public class Studente { private String id; private String login; private String pwd; - private DbManager0 DbManager0; + private DbManager DbManager0; public Studente(String user){ this.login = user; @@ -57,7 +55,7 @@ public boolean login(){ this.id = s; return true;*/ try{ - DbManager0 db = DbManager0.getInstance(); + DbManager db = DbManager0.getInstance(); Query q = db.createQuery("SELECT * FROM user WHERE username = '"+this.login+"' and password = '"+this.pwd+"';"); QueryResult rs = db.execute(q); rs.next(); @@ -81,7 +79,7 @@ public boolean registra(){ // Ora chiudo la connessione col Database: db.disconnetti();*/ try{ - DbManager0 db = DbManager0.getInstance(); + DbManager db = DbManager0.getInstance(); Query q = db.createQuery("INSERT INTO `cryptohelper`.`user` (`username`, `password`, `nome`, `cognome`) VALUES ('" +this.login+"', '"+this.pwd+"', NULL, NULL);"); q.executeUpdate(); } diff --git a/src/model/UserInfo.java b/src/model/UserInfo.java index 8f3bbbb..84f5cc7 100644 --- a/src/model/UserInfo.java +++ b/src/model/UserInfo.java @@ -8,7 +8,7 @@ //import static controller.Controller.connect; import db.DbManager; -import db.DbManager0; +import db.DbManager; import db.Query; import db.QueryResult; import java.sql.SQLException; @@ -31,7 +31,7 @@ public UserInfo(String id){ this.cognome = ((String[]) v.elementAt(0))[4];*/ this.id = id; try{ - DbManager0 db = DbManager0.getInstance(); + DbManager db = DbManager.getInstance(); Query q = db.createQuery("SELECT * FROM `cryptohelper`.`user` WHERE id = '" + id + "'"); QueryResult rs = db.execute(q); rs.next(); diff --git a/src/model/spia/Ipotesi.java b/src/model/spia/Ipotesi.java index a040a77..903ce62 100644 --- a/src/model/spia/Ipotesi.java +++ b/src/model/spia/Ipotesi.java @@ -21,6 +21,9 @@ public class Ipotesi extends javax.swing.tree.DefaultMutableTreeNode { private String messaggioParzialmenteDecifrato; + public String getMessaggioParzialmenteDecifrato() { + return this.messaggioParzialmenteDecifrato; + } public void add( Ipotesi p ) { super.add( p ); diff --git a/src/model/spia/Sessione.java b/src/model/spia/Sessione.java index a7a3418..7fc8ff6 100644 --- a/src/model/spia/Sessione.java +++ b/src/model/spia/Sessione.java @@ -1,7 +1,7 @@ package model.spia; -import model.Messaggio; +import GUI.spia.ListaMessaggiCifrati; import model.Messaggio; @@ -21,6 +21,8 @@ public class Sessione { public static class Properties extends java.util.Hashtable {} public static Sessione startNewSessione() { + Messaggio m = ListaMessaggiCifrati.getMessaggio(); + //DO CODE return new Sessione( (Properties)null ); } diff --git a/src/model/spia/Spia.java b/src/model/spia/Spia.java index 908d118..e43b32e 100644 --- a/src/model/spia/Spia.java +++ b/src/model/spia/Spia.java @@ -6,10 +6,16 @@ * and open the template in the editor. */ +import model.*; + /** * * @author user */ -public interface Spia { +public class Spia extends Studente { + + public Spia(String user) { + super(user); + } } diff --git a/src/model/spia/supportTools/AnalisiFrequenze.java b/src/model/spia/supportTools/AnalisiFrequenze.java new file mode 100644 index 0000000..1e6d037 --- /dev/null +++ b/src/model/spia/supportTools/AnalisiFrequenze.java @@ -0,0 +1,23 @@ +/* + * 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 model.spia.supportTools; + +import model.spia.*; +import model.Messaggio; + +/** + * + * @author user + */ +public class AnalisiFrequenze implements SistemaDiSupporto { + + @Override + public Ipotesi start(Ipotesi ipCorrente, Messaggio messaggio) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + +} diff --git a/src/model/spia/supportTools/analisiFrequenze/AnalisiFrequenze.java b/src/model/spia/supportTools/analisiFrequenze/AnalisiFrequenze.java new file mode 100644 index 0000000..d69ed45 --- /dev/null +++ b/src/model/spia/supportTools/analisiFrequenze/AnalisiFrequenze.java @@ -0,0 +1,46 @@ +/* + * 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 model.spia.supportTools.analisiFrequenze; +import java.util.HashMap; +/** + * + * @author davide + */ +public class AnalisiFrequenze { + private HashMap table; + private int msgLength; + public void start (String msg){ + table = new HashMap(); +// msg = msg.toLowerCase(); + msg = msg.replaceAll("\\s", ""); /*rimuove gli spazi*/ + this. msgLength = msg.length(); + System.out.println(msg); + for(int i = 0; i < msg.length(); i++){ + Character c = msg.charAt(i); + if (table.containsKey(c)){ + Integer occorrenze = (Integer)table.get(c)+1; + table.put(c, occorrenze); + } + else{ + table.put(c, new Integer(1)); + } + } + System.out.println(/*table + " size " + */this.toString()); + } + public String toString() { + String frequencyTable = "Numero lettere nel messaggio " + this.getMsgLength()+"\n"; + for(Character currentKey : table.keySet()){ + Integer occurence =table.get(currentKey); + frequencyTable += currentKey + " numero occorrenze " + occurence + " percentuale " + (double)occurence/this.getMsgLength()*100+"\n"; + } + return frequencyTable; + //return table.size()+" numero lettere "+this.getMsgLength(); + } + public int getMsgLength(){ + return this.msgLength; + } + +} diff --git a/src/model/spia/supportTools/analisiFrequenze/Replacer.java b/src/model/spia/supportTools/analisiFrequenze/Replacer.java new file mode 100644 index 0000000..716e1cb --- /dev/null +++ b/src/model/spia/supportTools/analisiFrequenze/Replacer.java @@ -0,0 +1,19 @@ +/* + * 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 model.spia.supportTools.analisiFrequenze; + +/** + * + * @author davide + */ +public class Replacer { + public String start(String msg, char from, char to){ + to = Character.toUpperCase(to); + msg = msg.replace(from, to); + return msg; + } +} diff --git a/src/model/user/Proposta.java b/src/model/user/Proposta.java index 892aadf..54d4caa 100644 --- a/src/model/user/Proposta.java +++ b/src/model/user/Proposta.java @@ -9,7 +9,7 @@ import controller.Controller; //import static controller.Controller.connect; import db.DbManager; -import db.DbManager0; +import db.DbManager; import db.Query; import db.QueryResult; import java.sql.SQLException; @@ -56,7 +56,7 @@ public boolean save(){ System.out.println("sgsgf"); return true;*/ try{ - DbManager0 db = DbManager0.getInstance(); + DbManager db = DbManager.getInstance(); Query q = db.createQuery("INSERT INTO `cryptohelper`.`proposta` (`id`, `id_mittente`, `id_destinatario`, `idsistemacifratura`, `stato`, `notificata`) VALUES (NULL, '" +this.proponente.getId()+"', '"+this.partner.getId()+"', '" + Integer.parseInt(this.s.getId()) + "', 'in attesa', NULL);"); q.executeUpdate(); } diff --git a/src/model/user/SistemaCifratura.java b/src/model/user/SistemaCifratura.java index 51b9897..9008552 100644 --- a/src/model/user/SistemaCifratura.java +++ b/src/model/user/SistemaCifratura.java @@ -8,7 +8,7 @@ //import static controller.Controller.connect; import db.DbManager; -import db.DbManager0; +import db.DbManager; import db.Query; import db.QueryResult; import java.sql.SQLException; @@ -51,11 +51,14 @@ public static SistemaCifratura load(String id){ Vector v = db.eseguiQuery("SELECT * FROM `cryptohelper`.`sistemacifratura` WHERE id = '" + id + "'"); return new SistemaCifratura(((String[])v.elementAt(0))[0], ((String[])v.elementAt(0))[1], ((String[])v.elementAt(0))[2], new UserInfo(((String[])v.elementAt(0))[3]));*/ try{ - DbManager0 db = DbManager0.getInstance(); + DbManager db = DbManager.getInstance(); Query q = db.createQuery("SELECT * FROM `cryptohelper`.`sistemacifratura` WHERE id = '" + id + "'"); QueryResult rs = db.execute(q); - rs.next(); - return new SistemaCifratura(rs.getString(1), rs.getString(2), rs.getString(3), new UserInfo(rs.getString(4))); + if( rs.next() ) { + return new SistemaCifratura(rs.getString(1), rs.getString(2), rs.getString(3), new UserInfo(rs.getString(4))); + } else { + return null; + } } catch(SQLException ex){ throw new RuntimeException( ex.getMessage(), ex ); @@ -87,7 +90,7 @@ public SistemaCifratura(String chiave, String metodo){ this.metodo = metodo; this.creatore = new UserInfo(Session.getIdLoggedUser()); try{ - DbManager0 db = DbManager0.getInstance(); + DbManager db = DbManager.getInstance(); Query q = db.createQuery("INSERT INTO `cryptohelper`.`sistemacifratura` (`id`, `chiave`, `metodo`, `idcreatore`) VALUES (NULL, '" +chiave+"', '"+metodo+"', '" + Session.getIdLoggedUser() + "')"); q.executeUpdate(); q = db.createQuery("SELECT * FROM `cryptohelper`.`sistemacifratura` ORDER BY id DESC"); diff --git a/src/test/model/spia/supportTools/TesterAnalisiFrequenze.java b/src/test/model/spia/supportTools/TesterAnalisiFrequenze.java new file mode 100644 index 0000000..ed4d185 --- /dev/null +++ b/src/test/model/spia/supportTools/TesterAnalisiFrequenze.java @@ -0,0 +1,33 @@ +/* + * 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 test.model.spia.supportTools; + +import model.spia.supportTools.analisiFrequenze.AnalisiFrequenze; +import model.spia.supportTools.analisiFrequenze.Replacer; + +/** + * + * @author davide + */ +public class TesterAnalisiFrequenze { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + AnalisiFrequenze tool = new AnalisiFrequenze(); + String msg = "hello analisi frequenze"; + tool.start(msg); + Replacer tool1 = new Replacer(); + String edit = msg; + edit = tool1.start(edit, 'e', 'F'); + System.out.println(msg + "\nSostituzione e con F \n" + edit); + tool.start(edit); + // TODO code application logic here + } + +} From a32607bcaa1b6719687d2ab794e9ea407e632c2b Mon Sep 17 00:00:00 2001 From: BobCaSUaL Date: Thu, 18 Sep 2014 19:21:17 +0200 Subject: [PATCH 03/45] .gitignore aggiunto da nettobenso --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..838458f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/dist/ \ No newline at end of file From 34c3d66d248a83ce6f67f7bf10175f7dd47c278b Mon Sep 17 00:00:00 2001 From: BobCaSUaL Date: Thu, 18 Sep 2014 22:26:56 +0200 Subject: [PATCH 04/45] Created the GenericSelector --- ...saggiCifrati.form => GenericSelector.form} | 0 src/GUI/spia/GenericSelector.java | 183 ++++++++++++++++++ src/GUI/spia/MessaggiSelector.form | 80 ++++++++ ...aggiCifrati.java => MessaggiSelector.java} | 18 +- src/model/spia/Sessione.java | 14 +- src/test/model/spia/SessioneTest.java | 20 ++ 6 files changed, 301 insertions(+), 14 deletions(-) rename src/GUI/spia/{ListaMessaggiCifrati.form => GenericSelector.form} (100%) create mode 100644 src/GUI/spia/GenericSelector.java create mode 100644 src/GUI/spia/MessaggiSelector.form rename src/GUI/spia/{ListaMessaggiCifrati.java => MessaggiSelector.java} (87%) create mode 100644 src/test/model/spia/SessioneTest.java diff --git a/src/GUI/spia/ListaMessaggiCifrati.form b/src/GUI/spia/GenericSelector.form similarity index 100% rename from src/GUI/spia/ListaMessaggiCifrati.form rename to src/GUI/spia/GenericSelector.form diff --git a/src/GUI/spia/GenericSelector.java b/src/GUI/spia/GenericSelector.java new file mode 100644 index 0000000..f7da4b9 --- /dev/null +++ b/src/GUI/spia/GenericSelector.java @@ -0,0 +1,183 @@ +/* + * 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 GUI.spia; + +import java.util.List; + +/** + * + * @author user + * @param + */ +public class GenericSelector extends javax.swing.JFrame { + + public static K selectOptions( List list ) { + + final SynchronizedBuffer buff = new SynchronizedBuffer<>(); + final List fList = list; + + new Thread( new Runnable() { + @Override + public void run() { + GenericSelector selector = new GenericSelector<>(buff); + selector.setOptionList( fList ); + selector.setVisible(true); + } + } ).start(); + + return buff.get(); + } + + + SynchronizedBuffer syncBuffer; + + public GenericSelector( SynchronizedBuffer c ) { + this(); + this.syncBuffer = c; + } + /** + * Creates new form NuovaSessione + */ + public GenericSelector () { + initComponents(); + } + + public void setOptionList( List list ) { + T[] arr = (T[]) list.toArray( new Object[list.size()] ); + jList1.setListData(arr); + } + + public static class SynchronizedBuffer { + private T contents; + private boolean available = false; + + public synchronized T get() { + while (available == false) { + try { + wait(); + } catch (InterruptedException e) { } + } + available = false; + notifyAll(); + return contents; + } + + public synchronized void put(T value) { + while (available == true) { + try { + wait(); + } catch (InterruptedException e) { } + } + contents = value; + available = true; + notifyAll(); + } + } + + /** + * 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() { + + jScrollPane1 = new javax.swing.JScrollPane(); + jList1 = new javax.swing.JList(); + jButton1 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jList1.setModel(new javax.swing.AbstractListModel() { + String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; + public int getSize() { return strings.length; } + public Object getElementAt(int i) { return strings[i]; } + }); + jScrollPane1.setViewportView(jList1); + + jButton1.setText("Scegli"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jButton1) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 335, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(53, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(23, 23, 23) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(44, 44, 44) + .addComponent(jButton1) + .addContainerGap(64, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + // TODO add your handling code here: + T selected = (T)jList1.getSelectedValue(); + this.syncBuffer.put(selected); + this.dispose(); + }//GEN-LAST:event_jButton1ActionPerformed + + /** + * @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(GenericSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(GenericSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(GenericSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(GenericSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + List list = new java.util.ArrayList<>(); + list.add("A"); + list.add("B"); + list.add("C"); + list.add("D"); + + + System.out.println( GenericSelector.selectOptions(list) ); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JList jList1; + private javax.swing.JScrollPane jScrollPane1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/GUI/spia/MessaggiSelector.form b/src/GUI/spia/MessaggiSelector.form new file mode 100644 index 0000000..230d58d --- /dev/null +++ b/src/GUI/spia/MessaggiSelector.form @@ -0,0 +1,80 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/spia/ListaMessaggiCifrati.java b/src/GUI/spia/MessaggiSelector.java similarity index 87% rename from src/GUI/spia/ListaMessaggiCifrati.java rename to src/GUI/spia/MessaggiSelector.java index 4be3733..8f4ad7b 100644 --- a/src/GUI/spia/ListaMessaggiCifrati.java +++ b/src/GUI/spia/MessaggiSelector.java @@ -15,14 +15,14 @@ * * @author user */ -public class ListaMessaggiCifrati extends javax.swing.JFrame { +public class MessaggiSelector extends javax.swing.JFrame { public static Messaggio getMessaggio() { final SynchronizedBuffer buff = new SynchronizedBuffer<>(); new Thread( new Runnable() { public void run() { - ListaMessaggiCifrati listaMessaggiCifrati = new ListaMessaggiCifrati(buff); + MessaggiSelector listaMessaggiCifrati = new MessaggiSelector(buff); listaMessaggiCifrati.setVisible(true); } } ).start(); @@ -57,14 +57,14 @@ public synchronized void put(T value) { } SynchronizedBuffer syncBuffer; - public ListaMessaggiCifrati( SynchronizedBuffer c ) { + public MessaggiSelector( SynchronizedBuffer c ) { this(); this.syncBuffer = c; } /** * Creates new form NuovaSessione */ - public ListaMessaggiCifrati () { + public MessaggiSelector () { initComponents(); List list = Messaggio.getMessaggi(); Messaggio[] arr = list.toArray( new Messaggio[list.size()] ); @@ -152,13 +152,13 @@ public static void main(String args[]) { } } } catch (ClassNotFoundException ex) { - java.util.logging.Logger.getLogger(ListaMessaggiCifrati.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(MessaggiSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(ListaMessaggiCifrati.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(MessaggiSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(ListaMessaggiCifrati.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(MessaggiSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(ListaMessaggiCifrati.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(MessaggiSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } // @@ -168,7 +168,7 @@ public static void main(String args[]) { new Thread( new Runnable() { public void run() { - ListaMessaggiCifrati listaMessaggiCifrati = new ListaMessaggiCifrati(b); + MessaggiSelector listaMessaggiCifrati = new MessaggiSelector(b); listaMessaggiCifrati.setVisible(true); } } ).start(); diff --git a/src/model/spia/Sessione.java b/src/model/spia/Sessione.java index 7fc8ff6..f61afb1 100644 --- a/src/model/spia/Sessione.java +++ b/src/model/spia/Sessione.java @@ -1,7 +1,9 @@ package model.spia; -import GUI.spia.ListaMessaggiCifrati; +import GUI.spia.GenericSelector; +import GUI.spia.MessaggiSelector; +import java.util.List; import model.Messaggio; @@ -21,11 +23,13 @@ public class Sessione { public static class Properties extends java.util.Hashtable {} public static Sessione startNewSessione() { - Messaggio m = ListaMessaggiCifrati.getMessaggio(); - - //DO CODE - return new Sessione( (Properties)null ); + List options = Messaggio.getMessaggi(); + for( Messaggio m: options ) { + m.setToStringF("%lingua%, %testoCif%"); + } + return new Sessione( GenericSelector.selectOptions( options ) ); } + public static Sessione restoreSessione() { //DO CODE return new Sessione( (Properties)null ); diff --git a/src/test/model/spia/SessioneTest.java b/src/test/model/spia/SessioneTest.java new file mode 100644 index 0000000..1137453 --- /dev/null +++ b/src/test/model/spia/SessioneTest.java @@ -0,0 +1,20 @@ +/* + * 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 test.model.spia; + +import model.spia.Sessione; + +/** + * + * @author user + */ +public class SessioneTest { + public static void main( String[] args ) { + Sessione s = Sessione.startNewSessione(); + System.out.println(s); + } +} From a7a54c201ad207e15276c89ee53a4d8530e416f6 Mon Sep 17 00:00:00 2001 From: BobCaSUaL Date: Thu, 18 Sep 2014 22:41:38 +0200 Subject: [PATCH 05/45] package revision --- src/GUI/{spia => }/GenericSelector.form | 0 src/GUI/{spia => }/GenericSelector.java | 2 +- src/GUI/spia/MessaggiSelector.form | 80 ---------- src/GUI/spia/MessaggiSelector.java | 188 ------------------------ src/model/spia/Sessione.java | 3 +- 5 files changed, 2 insertions(+), 271 deletions(-) rename src/GUI/{spia => }/GenericSelector.form (100%) rename src/GUI/{spia => }/GenericSelector.java (99%) delete mode 100644 src/GUI/spia/MessaggiSelector.form delete mode 100644 src/GUI/spia/MessaggiSelector.java diff --git a/src/GUI/spia/GenericSelector.form b/src/GUI/GenericSelector.form similarity index 100% rename from src/GUI/spia/GenericSelector.form rename to src/GUI/GenericSelector.form diff --git a/src/GUI/spia/GenericSelector.java b/src/GUI/GenericSelector.java similarity index 99% rename from src/GUI/spia/GenericSelector.java rename to src/GUI/GenericSelector.java index f7da4b9..992dcfc 100644 --- a/src/GUI/spia/GenericSelector.java +++ b/src/GUI/GenericSelector.java @@ -4,7 +4,7 @@ * and open the template in the editor. */ -package GUI.spia; +package GUI; import java.util.List; diff --git a/src/GUI/spia/MessaggiSelector.form b/src/GUI/spia/MessaggiSelector.form deleted file mode 100644 index 230d58d..0000000 --- a/src/GUI/spia/MessaggiSelector.form +++ /dev/null @@ -1,80 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/src/GUI/spia/MessaggiSelector.java b/src/GUI/spia/MessaggiSelector.java deleted file mode 100644 index 8f4ad7b..0000000 --- a/src/GUI/spia/MessaggiSelector.java +++ /dev/null @@ -1,188 +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 GUI.spia; - -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import model.Messaggio; - -/** - * - * @author user - */ -public class MessaggiSelector extends javax.swing.JFrame { - - public static Messaggio getMessaggio() { - final SynchronizedBuffer buff = new SynchronizedBuffer<>(); - - new Thread( new Runnable() { - public void run() { - MessaggiSelector listaMessaggiCifrati = new MessaggiSelector(buff); - listaMessaggiCifrati.setVisible(true); - } - } ).start(); - - return buff.get(); - } - public static class SynchronizedBuffer { - private T contents; - private boolean available = false; - - public synchronized T get() { - while (available == false) { - try { - wait(); - } catch (InterruptedException e) { } - } - available = false; - notifyAll(); - return contents; - } - - public synchronized void put(T value) { - while (available == true) { - try { - wait(); - } catch (InterruptedException e) { } - } - contents = value; - available = true; - notifyAll(); - } - } - - SynchronizedBuffer syncBuffer; - public MessaggiSelector( SynchronizedBuffer c ) { - this(); - this.syncBuffer = c; - } - /** - * Creates new form NuovaSessione - */ - public MessaggiSelector () { - initComponents(); - List list = Messaggio.getMessaggi(); - Messaggio[] arr = list.toArray( new Messaggio[list.size()] ); - for( Messaggio m: arr) { - m.setToStringF("%lingua%, %testoCif%"); - } - jList1.setListData(arr); - - } - - /** - * 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() { - - jScrollPane1 = new javax.swing.JScrollPane(); - jList1 = new javax.swing.JList(); - jButton1 = new javax.swing.JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jList1.setModel(new javax.swing.AbstractListModel() { - String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; - public int getSize() { return strings.length; } - public Object getElementAt(int i) { return strings[i]; } - }); - jScrollPane1.setViewportView(jList1); - - jButton1.setText("Scegli"); - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(jButton1) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 335, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap(53, Short.MAX_VALUE)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(23, 23, 23) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(44, 44, 44) - .addComponent(jButton1) - .addContainerGap(64, Short.MAX_VALUE)) - ); - - pack(); - }// //GEN-END:initComponents - - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - // TODO add your handling code here: - Messaggio m = (Messaggio)jList1.getSelectedValue(); - this.syncBuffer.put(m); - this.dispose(); - }//GEN-LAST:event_jButton1ActionPerformed - - /** - * @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(MessaggiSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(MessaggiSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(MessaggiSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(MessaggiSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } - // - - - - final SynchronizedBuffer b = new SynchronizedBuffer(); - - new Thread( new Runnable() { - public void run() { - MessaggiSelector listaMessaggiCifrati = new MessaggiSelector(b); - listaMessaggiCifrati.setVisible(true); - } - } ).start(); - - - System.out.println( b.get() ); - } - - - - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton1; - private javax.swing.JList jList1; - private javax.swing.JScrollPane jScrollPane1; - // End of variables declaration//GEN-END:variables -} diff --git a/src/model/spia/Sessione.java b/src/model/spia/Sessione.java index f61afb1..9544cc8 100644 --- a/src/model/spia/Sessione.java +++ b/src/model/spia/Sessione.java @@ -1,8 +1,7 @@ package model.spia; -import GUI.spia.GenericSelector; -import GUI.spia.MessaggiSelector; +import GUI.GenericSelector; import java.util.List; import model.Messaggio; From 613a4a1de430761f51cb97f3a5310eaabe69c33f Mon Sep 17 00:00:00 2001 From: BobCaSUaL Date: Fri, 19 Sep 2014 00:05:49 +0200 Subject: [PATCH 06/45] Sessione first coding --- src/DatabaseDUMPS/Sessione.sql | 13 +++ src/DatabaseDUMPS/cryptohelper.sql | 159 +++++++++++++++++++++++++++++ src/model/Studente.java | 7 ++ src/model/spia/Sessione.java | 67 +++++++++++- 4 files changed, 241 insertions(+), 5 deletions(-) create mode 100644 src/DatabaseDUMPS/Sessione.sql create mode 100644 src/DatabaseDUMPS/cryptohelper.sql diff --git a/src/DatabaseDUMPS/Sessione.sql b/src/DatabaseDUMPS/Sessione.sql new file mode 100644 index 0000000..aacc734 --- /dev/null +++ b/src/DatabaseDUMPS/Sessione.sql @@ -0,0 +1,13 @@ + +-- +-- Struttura della tabella `Sessione` +-- + +CREATE TABLE IF NOT EXISTS `Sessione` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique ID', + `userId` int(11) NOT NULL COMMENT 'user ID', + `key` varchar(255) NOT NULL COMMENT 'Human Readable key', + `sessione` blob NOT NULL COMMENT 'The serialized Session object', + PRIMARY KEY (`id`), + UNIQUE KEY `userId` (`userId`,`key`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; \ No newline at end of file diff --git a/src/DatabaseDUMPS/cryptohelper.sql b/src/DatabaseDUMPS/cryptohelper.sql new file mode 100644 index 0000000..39faa69 --- /dev/null +++ b/src/DatabaseDUMPS/cryptohelper.sql @@ -0,0 +1,159 @@ +-- phpMyAdmin SQL Dump +-- version 4.0.10deb1 +-- http://www.phpmyadmin.net +-- +-- Host: localhost +-- Generato il: Set 18, 2014 alle 22:57 +-- Versione del server: 5.5.38-0ubuntu0.14.04.1 +-- Versione PHP: 5.5.9-1ubuntu4.3 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; + +-- +-- Database: `cryptohelper` +-- + +-- -------------------------------------------------------- + +-- +-- Struttura della tabella `messaggio` +-- + +CREATE TABLE IF NOT EXISTS `messaggio` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `id_mittente` int(11) NOT NULL, + `id_destinatario` int(11) NOT NULL, + `testo` varchar(120) NOT NULL, + `testoCifrato` varchar(120) NOT NULL, + `lingua` varchar(120) NOT NULL, + `titolo` varchar(120) NOT NULL, + `bozza` tinyint(1) NOT NULL, + `letto` tinyint(1) NOT NULL, + `idsistemacifratura` int(11) NOT NULL, + PRIMARY KEY (`id`), + KEY `id_mittente` (`id_mittente`), + KEY `id_destinatario` (`id_destinatario`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=22 ; + +-- +-- Dump dei dati per la tabella `messaggio` +-- + +INSERT INTO `messaggio` (`id`, `id_mittente`, `id_destinatario`, `testo`, `testoCifrato`, `lingua`, `titolo`, `bozza`, `letto`, `idsistemacifratura`) VALUES +(19, 1, 3, 'bellaaaaaaaaaaaaa!!!!', 'bellaaaaaaaaaaaaa', 'Italiano', 'titoloDiProva', 0, 0, 0), +(20, 1, 2, 'ciao bob qui tutto a posto', 'rxp~ q~q ??x ????~ p ~??~', 'null', 'titoloDiProva', 0, 0, 0), +(21, 1, 2, 'ciao', 'rxp~', 'Italiano', 'titoloDiProva', 0, 0, 0); + +-- -------------------------------------------------------- + +-- +-- Struttura della tabella `proposta` +-- + +CREATE TABLE IF NOT EXISTS `proposta` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `id_mittente` varchar(120) NOT NULL, + `id_destinatario` varchar(120) NOT NULL, + `idsistemacifratura` int(11) NOT NULL, + `stato` varchar(120) NOT NULL, + `notificata` datetime DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `user_mittente` (`id_mittente`), + KEY `user_destinatario` (`id_destinatario`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ; + +-- +-- Dump dei dati per la tabella `proposta` +-- + +INSERT INTO `proposta` (`id`, `id_mittente`, `id_destinatario`, `idsistemacifratura`, `stato`, `notificata`) VALUES +(7, '1', '2', 5, 'accettata', NULL), +(8, '1', '3', 6, 'accettata', NULL), +(9, '1', '2', 7, 'accettata', NULL), +(10, '2', '3', 8, 'rifiutata', NULL); + +-- -------------------------------------------------------- + +-- +-- Struttura della tabella `Sessione` +-- + +CREATE TABLE IF NOT EXISTS `Sessione` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique ID', + `userId` int(11) NOT NULL COMMENT 'user ID', + `key` varchar(255) NOT NULL COMMENT 'Human Readable key', + `session` blob NOT NULL COMMENT 'The serialized Session object', + PRIMARY KEY (`id`), + UNIQUE KEY `userId` (`userId`,`key`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; + +-- -------------------------------------------------------- + +-- +-- Struttura della tabella `sistemacifratura` +-- + +CREATE TABLE IF NOT EXISTS `sistemacifratura` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `chiave` varchar(120) NOT NULL, + `metodo` varchar(120) NOT NULL, + `idcreatore` int(11) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ; + +-- +-- Dump dei dati per la tabella `sistemacifratura` +-- + +INSERT INTO `sistemacifratura` (`id`, `chiave`, `metodo`, `idcreatore`) VALUES +(5, '15', 'Sistema di cesare', 1), +(6, '0', 'Sistema di cesare', 1), +(7, 'ciaao', 'Parola chiave', 1), +(8, '30', 'Sistema di cesare', 2); + +-- -------------------------------------------------------- + +-- +-- Struttura della tabella `user` +-- + +CREATE TABLE IF NOT EXISTS `user` ( + `id` int(120) NOT NULL AUTO_INCREMENT, + `username` varchar(120) NOT NULL, + `password` varchar(120) NOT NULL, + `nome` varchar(120) DEFAULT NULL, + `cognome` varchar(120) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `username` (`username`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; + +-- +-- Dump dei dati per la tabella `user` +-- + +INSERT INTO `user` (`id`, `username`, `password`, `nome`, `cognome`) VALUES +(1, 'roberto', 'root', NULL, NULL), +(2, 'bob', 'root', NULL, NULL), +(3, 'davide', 'prova', NULL, NULL); + +-- +-- Limiti per le tabelle scaricate +-- + +-- +-- Limiti per la tabella `messaggio` +-- +ALTER TABLE `messaggio` + ADD CONSTRAINT `messaggio_ibfk_1` FOREIGN KEY (`id_mittente`) REFERENCES `user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + ADD CONSTRAINT `messaggio_ibfk_2` FOREIGN KEY (`id_destinatario`) REFERENCES `user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/src/model/Studente.java b/src/model/Studente.java index 58e1d33..8a1e9da 100644 --- a/src/model/Studente.java +++ b/src/model/Studente.java @@ -17,6 +17,13 @@ * @author MASTER */ public class Studente { + + private static Studente loggato = null; + + public static Studente getLoggato() { + return loggato; + } + private String nome; private String cognome; private String id; diff --git a/src/model/spia/Sessione.java b/src/model/spia/Sessione.java index 9544cc8..17260ce 100644 --- a/src/model/spia/Sessione.java +++ b/src/model/spia/Sessione.java @@ -2,8 +2,17 @@ import GUI.GenericSelector; +import db.DbManager; +import db.Query; +import db.QueryResult; +import java.io.Serializable; +import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; import model.Messaggio; +import model.Studente; @@ -17,7 +26,7 @@ * * @author user */ -public class Sessione { +public class Sessione implements Serializable { public static class Properties extends java.util.Hashtable {} @@ -30,17 +39,64 @@ public static Sessione startNewSessione() { } public static Sessione restoreSessione() { - //DO CODE - return new Sessione( (Properties)null ); + Sessione result = null; + ArrayList optionList = new ArrayList<>(); + try{ + //seleziona la key di una sessione salvata + DbManager db = DbManager.getInstance(); + Query q = db.createQuery("SELECT `key` FROM `Sessione` WHERE `userId` = ?"); + q.setString ( 1, Studente.getLoggato().getId() ); + QueryResult rs = db.execute(q); + while( rs.next() ){ + optionList.add( rs.getString("key") ); + } + String key = GenericSelector.selectOptions( optionList ); + + //In base alla key scelta deserializza la Sessione dal database + Query u = db.createQuery("SELECT `sessione` FROM `Sessione` WHERE `userId` = ? AND `key` = ? LIMIT 1"); + u.setString ( 1, Studente.getLoggato().getId() ); + u.setString ( 2, key ); + QueryResult qr = db.execute(u); + + if( qr.next() ) { + result = qr.getObject("sessione", Sessione.class); + } + } + catch (SQLException ex){ + throw new RuntimeException( ex.getMessage(), ex ); + } + return result; } + public static void deleteSessione( Sessione sessione ) { - //DO CODE + try { + DbManager db = DbManager.getInstance(); + Query q = db.createQuery("DELETE FROM `Sessione` WHERE `id` = ? AND `userId` = ?"); + q.setString ( 1, Studente.getLoggato().getId() ); + q.setInt ( 2, sessione.id ); + QueryResult rs = db.execute(q); + + } catch (SQLException ex) { + throw new RuntimeException( ex.getMessage(), ex ); + } } public static void saveSession( Sessione sessione ) { - //DO CODE + try { + DbManager db = DbManager.getInstance(); + Query q = db.createQuery("INSERT INTO `Sessione`(`userId`,`key`,`session`) VALUES( ?, ?, ? )"); + q.setString ( 1, Studente.getLoggato().getId() ); + q.setString ( 2, sessione.key ); + q.setObject ( 3, sessione ); + QueryResult rs = db.execute(q); + + } catch (SQLException ex) { + throw new RuntimeException( ex.getMessage(), ex ); + } } + private int id; + private String key; private Ipotesi root; private Ipotesi ipCorrente; @@ -49,6 +105,7 @@ public static void saveSession( Sessione sessione ) { public Sessione( Properties p ) { this.properties = p; + this.key = new java.sql.Timestamp( new java.util.Date().getTime() ).toString(); } public Sessione( Messaggio m ) { this( new Properties() ); From ed1f357c98b7c885c9466294f06c21de135a6e22 Mon Sep 17 00:00:00 2001 From: BobCaSUaL Date: Fri, 19 Sep 2014 16:55:51 +0200 Subject: [PATCH 07/45] CicloDiAnalisi coding: per ciclo di analisi s'intede il metodo Sessione.start() --- src/GUI/Main.java | 143 ++++++++------ src/GUI/spia/GestisciSessioneDiLavoro.form | 4 +- src/GUI/spia/GestisciSessioneDiLavoro.java | 192 +++++++++---------- src/GUI/user/PropostaSistemaDiCifratura.java | 3 +- src/GUI/user/Registrazione.java | 2 +- src/controller/Controller.java | 17 +- src/model/Studente.java | 68 +++++-- src/model/spia/Sessione.java | 71 ++++--- src/model/spia/Spia.java | 34 ++++ 9 files changed, 311 insertions(+), 223 deletions(-) diff --git a/src/GUI/Main.java b/src/GUI/Main.java index b825f26..4da4fbe 100644 --- a/src/GUI/Main.java +++ b/src/GUI/Main.java @@ -1,10 +1,17 @@ package GUI; +import GUI.spia.GestisciSessioneDiLavoro; import GUI.user.Registrazione; import GUI.user.Utente_Regolamentare; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.util.Vector; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.JFrame; import model.Session; import model.Studente; +import model.spia.Spia; /** * @@ -12,19 +19,19 @@ */ public class Main extends javax.swing.JFrame { - /** - * Creates new form Login - */ - public Main() { - initComponents(); - } + /** + * Creates new form Login + */ + public Main() { + 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") + /** + * 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() { @@ -167,76 +174,94 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { }// //GEN-END:initComponents private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_jTextField1ActionPerformed private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed - Registrazione r = new Registrazione(); - r.setVisible(true); + Registrazione r = new Registrazione(); + r.setVisible(true); }//GEN-LAST:event_jButton3ActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - - if (jTextField1.getText().equals("")) { - jLabel4.setText("Inserisci username"); + + if (jTextField1.getText().equals("")) { + jLabel4.setText("Inserisci username"); + } + if (jPasswordField1.getPassword().equals("")) { + jLabel4.setText("Inserisci Password"); + } else { + + if (jRadioButton1.isSelected()) { + final Spia s = new Spia(jTextField1.getText(), "" + jPasswordField1.getText()); + boolean conferma = s.login(); + if (!conferma) { + jLabel4.setText("Username e/o password non corretti: riprova"); + } else { + new Thread( new Runnable() { + public void run() { + new GestisciSessioneDiLavoro(s).setVisible(true); + } + }).start(); + } } - if (jPasswordField1.getPassword().equals("")) { - jLabel4.setText("Inserisci Password"); - } else { - Studente s = new Studente(jTextField1.getText(), "" + jPasswordField1.getText(), true); - boolean conferma = s.login(); - if (!conferma) { - jLabel4.setText("Username e/o password non corretti: riprova"); - } else { + if (jRadioButton2.isSelected()) { + final Studente s = new Studente(jTextField1.getText(), "" + jPasswordField1.getText()); + boolean conferma = s.login(); + if (!conferma) { + jLabel4.setText("Username e/o password non corretti: riprova"); + } else { + new Thread( new Runnable() { + public void run() { new Utente_Regolamentare().setVisible(true); - } - + } + }).start(); + } } + } + }//GEN-LAST:event_jButton1ActionPerformed private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_jRadioButton1ActionPerformed private void jPasswordField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPasswordField1ActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_jPasswordField1ActionPerformed - /** - * @param args the command line arguments - */ - public static void main(String args[]) { - /* Set the Nimbus look and feel */ + /** + * @param args the command line arguments + */ + public static synchronized 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(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + * 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(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(Main.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 Main().setVisible(true); - } - }); - } + new Main().setVisible(true); + + } + private static Object lock = new Object(); + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.ButtonGroup buttonGroup1; private javax.swing.ButtonGroup buttonGroup2; diff --git a/src/GUI/spia/GestisciSessioneDiLavoro.form b/src/GUI/spia/GestisciSessioneDiLavoro.form index 9fdbff1..95327f1 100644 --- a/src/GUI/spia/GestisciSessioneDiLavoro.form +++ b/src/GUI/spia/GestisciSessioneDiLavoro.form @@ -24,9 +24,9 @@ - + - + diff --git a/src/GUI/spia/GestisciSessioneDiLavoro.java b/src/GUI/spia/GestisciSessioneDiLavoro.java index 3c4e4a5..6810674 100644 --- a/src/GUI/spia/GestisciSessioneDiLavoro.java +++ b/src/GUI/spia/GestisciSessioneDiLavoro.java @@ -6,7 +6,9 @@ package GUI.spia; +import javax.swing.JFrame; import model.spia.Sessione; +import model.spia.Spia; /** * @@ -17,7 +19,8 @@ public class GestisciSessioneDiLavoro extends javax.swing.JFrame { /** * Creates new form GestisciSessioneDiLavoro */ - public GestisciSessioneDiLavoro() { + public GestisciSessioneDiLavoro( Spia s ) { + this.spia = s; initComponents(); } @@ -27,116 +30,99 @@ public GestisciSessioneDiLavoro() { * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - jButton1 = new javax.swing.JButton(); - jButton2 = new javax.swing.JButton(); - jButton3 = new javax.swing.JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jButton1.setText("Nuova Sesione"); - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - - jButton2.setText("Ripristina Sessione"); - jButton2.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton2ActionPerformed(evt); - } - }); - - jButton3.setText("Elimina Sessione"); - jButton3.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton3ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(25, 25, 25) - .addComponent(jButton1) - .addGap(33, 33, 33) - .addComponent(jButton2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE) - .addComponent(jButton3) - .addGap(34, 34, 34)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(59, 59, 59) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jButton1) - .addComponent(jButton2) - .addComponent(jButton3)) - .addContainerGap(212, Short.MAX_VALUE)) - ); - - pack(); - }// //GEN-END:initComponents + // //GEN-BEGIN:initComponents + private void initComponents() { + + jButton1 = new javax.swing.JButton(); + jButton2 = new javax.swing.JButton(); + jButton3 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jButton1.setText("Nuova Sesione"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jButton2.setText("Ripristina Sessione"); + jButton2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton2ActionPerformed(evt); + } + }); + + jButton3.setText("Elimina Sessione"); + jButton3.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton3ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(32, 32, 32) + .addComponent(jButton1) + .addGap(26, 26, 26) + .addComponent(jButton2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE) + .addComponent(jButton3) + .addGap(34, 34, 34)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(59, 59, 59) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton1) + .addComponent(jButton2) + .addComponent(jButton3)) + .addContainerGap(212, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - // TODO add your handling code here: - Sessione s = Sessione.startNewSessione(); + final Spia s = this.spia; + final JFrame self = this; + new Thread( new Runnable() { + public void run() { + self.setVisible(false); + s.startNewSessione(); + self.setVisible(true); + } + }).start(); }//GEN-LAST:event_jButton1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed - // TODO add your handling code here: - Sessione s = Sessione.restoreSessione(); + final Spia s = this.spia; + new Thread( new Runnable() { + public void run() { + s.restoreSessione(); + } + }).start(); }//GEN-LAST:event_jButton2ActionPerformed private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed - // TODO add your handling code here: - Sessione.deleteSessione(null); + final Spia s = this.spia; + new Thread( new Runnable() { + public void run() { + s.deleteSessione(); + } + }).start(); }//GEN-LAST:event_jButton3ActionPerformed - /** - * @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(GestisciSessioneDiLavoro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(GestisciSessioneDiLavoro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(GestisciSessioneDiLavoro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(GestisciSessioneDiLavoro.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 GestisciSessioneDiLavoro().setVisible(true); - } - }); - } - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton1; - private javax.swing.JButton jButton2; - private javax.swing.JButton jButton3; - // End of variables declaration//GEN-END:variables + + private Spia spia; + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + private javax.swing.JButton jButton3; + // End of variables declaration//GEN-END:variables } diff --git a/src/GUI/user/PropostaSistemaDiCifratura.java b/src/GUI/user/PropostaSistemaDiCifratura.java index fb07a01..ed2fe79 100644 --- a/src/GUI/user/PropostaSistemaDiCifratura.java +++ b/src/GUI/user/PropostaSistemaDiCifratura.java @@ -17,6 +17,7 @@ import model.user.Proposta; import model.user.SistemaCifratura; import model.Studente; +import model.UserInfo; /** * @@ -29,7 +30,7 @@ public class PropostaSistemaDiCifratura extends javax.swing.JFrame { */ public PropostaSistemaDiCifratura() { initComponents(); - Studente[] s = Controller.recuperaUtenti(); + UserInfo[] s = Controller.recuperaUtenti(); jList2.setListData(s); } diff --git a/src/GUI/user/Registrazione.java b/src/GUI/user/Registrazione.java index ac8ac12..a45a750 100644 --- a/src/GUI/user/Registrazione.java +++ b/src/GUI/user/Registrazione.java @@ -129,7 +129,7 @@ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS System.out.println(jTextField1.getText()); System.out.println(jTextField2.getText()); /*mancano controlli sulla password*/ - new Studente(jTextField1.getText(), jTextField2.getText(), true).registra(); + Studente.registra(jTextField1.getText(), jTextField2.getText()); }//GEN-LAST:event_jButton1ActionPerformed private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed diff --git a/src/controller/Controller.java b/src/controller/Controller.java index a946c9b..99ad83c 100644 --- a/src/controller/Controller.java +++ b/src/controller/Controller.java @@ -5,22 +5,15 @@ */ package controller; -import model.user.Proposta; -//import Clmodelession; -//import Clasmodeldente; -//import Classemodelnfo; -import db.DbManager; import db.DbManager; import db.Query; import db.QueryResult; import java.sql.SQLException; import java.util.ArrayList; -import java.util.Vector; -import model.user.PropostaConfermata; import model.Session; -import model.user.SistemaCifratura; import model.Studente; import model.UserInfo; +import model.user.Proposta; /** * * @author MASTER @@ -99,8 +92,8 @@ public static boolean rifiutaProposta(Proposta p){ - public static Studente[] recuperaUtenti(){ - ArrayList result = new ArrayList<>(); + public static UserInfo[] recuperaUtenti(){ + ArrayList result = new ArrayList<>(); try{ DbManager db = DbManager.getInstance(); Query q = db.createQuery("SELECT * FROM user where username <> '" + Session.getLoggedUser() + "'"); @@ -108,12 +101,12 @@ public static Studente[] recuperaUtenti(){ while( rs.next() ) { String id = rs.getString(1); String user = rs.getString(2); - result.add( new Studente( id, user ) ); + result.add( new UserInfo( id, user ) ); } } catch(SQLException ex){ throw new RuntimeException( ex.getMessage(), ex ); } - return result.toArray( new Studente[result.size()] ); + return result.toArray( new UserInfo[result.size()] ); } } diff --git a/src/model/Studente.java b/src/model/Studente.java index 8a1e9da..6389669 100644 --- a/src/model/Studente.java +++ b/src/model/Studente.java @@ -20,6 +20,9 @@ public class Studente { private static Studente loggato = null; + public static void setLoggato( Studente s ) { + loggato = s; + } public static Studente getLoggato() { return loggato; } @@ -35,11 +38,6 @@ public Studente(String user){ this.login = user; } - public Studente(String id, String user){ - this.id = id; - this.login = user; - } - public Studente(String nome, String cognome, String id, String user, String password){ this.login = user; this.pwd = password; @@ -48,7 +46,7 @@ public Studente(String nome, String cognome, String id, String user, String pass this.id = id; } - public Studente(String user, String password, boolean b){ + public Studente(String user, String password){ this.login = user; this.pwd = password; } @@ -62,20 +60,25 @@ public boolean login(){ this.id = s; return true;*/ try{ - DbManager db = DbManager0.getInstance(); - Query q = db.createQuery("SELECT * FROM user WHERE username = '"+this.login+"' and password = '"+this.pwd+"';"); + DbManager db = DbManager.getInstance(); + Query q = db.createQuery("SELECT * FROM user WHERE username = ? and password = ?"); + q.setString(1, this.getLogin()); + q.setString(2, this.getPwd()); + QueryResult rs = db.execute(q); - rs.next(); - if(rs.wasNull()) return false; - this.id = rs.getInt("id")+""; + if( rs.next() ) { + this.id = rs.getString("id"); return true; + } else { + return false; + } } catch(SQLException ex){ throw new RuntimeException( ex.getMessage(), ex ); } } - public boolean registra(){ + public static boolean registra(String nome, String password){ /*DbManager db = connect(); if (!db.eseguiAggiornamento("INSERT INTO `cryptohelper`.`user` (`username`, `password`, `nome`, `cognome`) VALUES ('" +this.login+"', '"+this.pwd+"', NULL, NULL);")) { @@ -86,8 +89,8 @@ public boolean registra(){ // Ora chiudo la connessione col Database: db.disconnetti();*/ try{ - DbManager db = DbManager0.getInstance(); - Query q = db.createQuery("INSERT INTO `cryptohelper`.`user` (`username`, `password`, `nome`, `cognome`) VALUES ('" +this.login+"', '"+this.pwd+"', NULL, NULL);"); + DbManager db = DbManager.getInstance(); + Query q = db.createQuery("INSERT INTO `cryptohelper`.`user` (`username`, `password`, `nome`, `cognome`) VALUES ('" +nome+"', '"+password+"', NULL, NULL);"); q.executeUpdate(); } catch (SQLException ex){ @@ -101,6 +104,41 @@ public String getId(){ } public String toString(){ - return this.login; + return this.getLogin(); } + + /** + * @return the nome + */ + public String getNome() { + return nome; + } + + /** + * @return the cognome + */ + public String getCognome() { + return cognome; + } + + /** + * @return the login + */ + public String getLogin() { + return login; + } + + /** + * @return the pwd + */ + public String getPwd() { + return pwd; + } + + /** + * @return the DbManager0 + */ + public DbManager getDbManager0() { + return DbManager0; + } } diff --git a/src/model/spia/Sessione.java b/src/model/spia/Sessione.java index 17260ce..03cbbe0 100644 --- a/src/model/spia/Sessione.java +++ b/src/model/spia/Sessione.java @@ -30,42 +30,46 @@ public class Sessione implements Serializable { public static class Properties extends java.util.Hashtable {} + public static Sessione recuperaSessione( Studente s ) throws SQLException { + Sessione result = null; + ArrayList optionList = new ArrayList<>(); + + //seleziona la key di una sessione salvata + DbManager db = DbManager.getInstance(); + Query q = db.createQuery("SELECT `key` FROM `Sessione` WHERE `userId` = ?"); + q.setString ( 1, s.getId() ); + QueryResult rs = db.execute(q); + while( rs.next() ){ + optionList.add( rs.getString("key") ); + } + String key = GenericSelector.selectOptions( optionList ); + + //In base alla key scelta deserializza la Sessione dal database + Query u = db.createQuery("SELECT `sessione` FROM `Sessione` WHERE `userId` = ? AND `key` = ? LIMIT 1"); + u.setString ( 1, s.getId() ); + u.setString ( 2, key ); + QueryResult qr = db.execute(u); + + if( qr.next() ) { + result = qr.getObject("sessione", Sessione.class); + } + return result; + } + public static Sessione startNewSessione() { List options = Messaggio.getMessaggi(); for( Messaggio m: options ) { m.setToStringF("%lingua%, %testoCif%"); } - return new Sessione( GenericSelector.selectOptions( options ) ); + Messaggio selectedMsg = GenericSelector.selectOptions( options ); + Sessione s = new Sessione( selectedMsg ); + s.start(); + return s; } - public static Sessione restoreSessione() { - Sessione result = null; - ArrayList optionList = new ArrayList<>(); - try{ - //seleziona la key di una sessione salvata - DbManager db = DbManager.getInstance(); - Query q = db.createQuery("SELECT `key` FROM `Sessione` WHERE `userId` = ?"); - q.setString ( 1, Studente.getLoggato().getId() ); - QueryResult rs = db.execute(q); - while( rs.next() ){ - optionList.add( rs.getString("key") ); - } - String key = GenericSelector.selectOptions( optionList ); - - //In base alla key scelta deserializza la Sessione dal database - Query u = db.createQuery("SELECT `sessione` FROM `Sessione` WHERE `userId` = ? AND `key` = ? LIMIT 1"); - u.setString ( 1, Studente.getLoggato().getId() ); - u.setString ( 2, key ); - QueryResult qr = db.execute(u); - - if( qr.next() ) { - result = qr.getObject("sessione", Sessione.class); - } - } - catch (SQLException ex){ - throw new RuntimeException( ex.getMessage(), ex ); - } - return result; + public static Sessione restoreSessione( Sessione s ) { + s.start(); + return s; } public static void deleteSessione( Sessione sessione ) { @@ -123,6 +127,13 @@ public Properties getProperties() { } public void start() { - //DO CODE + ArrayList nomiStrumenti = new ArrayList<>(); + nomiStrumenti.add("RipristinaSessione"); + nomiStrumenti.add("AnalisiDelleFrequenze"); + nomiStrumenti.add("BruteForce"); + + String nomeStrumentoScelto = GenericSelector.selectOptions(nomiStrumenti); + + System.out.println( "Hai scelto lo strumento "+nomeStrumentoScelto); } } diff --git a/src/model/spia/Spia.java b/src/model/spia/Spia.java index e43b32e..c3b22a3 100644 --- a/src/model/spia/Spia.java +++ b/src/model/spia/Spia.java @@ -6,6 +6,9 @@ * and open the template in the editor. */ +import java.sql.SQLException; +import java.util.logging.Level; +import java.util.logging.Logger; import model.*; /** @@ -17,5 +20,36 @@ public class Spia extends Studente { public Spia(String user) { super(user); } + public Spia( String user, String password ){ + super( user, password ); + } + public Spia(String nome, String cognome, String id, String user, String password){ + super( nome, cognome, id, user, password ); + } + + public Sessione startNewSessione() { + Sessione s = Sessione.startNewSessione(); + return s; + } + + public Sessione restoreSessione() { + try { + Sessione recuperata = Sessione.recuperaSessione(this); + Sessione s = Sessione.restoreSessione( recuperata ); + return s; + } catch (SQLException ex) { + throw new RuntimeException( ex.getMessage(), ex ); + } + } + + public Sessione deleteSessione() { + try { + Sessione s = Sessione.recuperaSessione( this ); + Sessione.deleteSessione( s ); + return s; + } catch (SQLException ex) { + throw new RuntimeException( ex.getMessage(), ex ); + } + } } From 9f25ab0d1af42bf006c2cee4d7e6353ca4234501 Mon Sep 17 00:00:00 2001 From: davide Date: Sat, 20 Sep 2014 00:35:03 +0200 Subject: [PATCH 08/45] Aggiunta dei form per il ciclo di analisi e la gestione delle sessioni --- src/GUI/spia/CicloDiAnalisi.form | 105 ++++++++++++++++++++ src/GUI/spia/CicloDiAnalisi.java | 148 +++++++++++++++++++++++++++++ src/GUI/spia/GestisciSessioni.form | 103 ++++++++++++++++++++ src/GUI/spia/GestisciSessioni.java | 130 +++++++++++++++++++++++++ 4 files changed, 486 insertions(+) create mode 100644 src/GUI/spia/CicloDiAnalisi.form create mode 100644 src/GUI/spia/CicloDiAnalisi.java create mode 100644 src/GUI/spia/GestisciSessioni.form create mode 100644 src/GUI/spia/GestisciSessioni.java diff --git a/src/GUI/spia/CicloDiAnalisi.form b/src/GUI/spia/CicloDiAnalisi.form new file mode 100644 index 0000000..d326b7c --- /dev/null +++ b/src/GUI/spia/CicloDiAnalisi.form @@ -0,0 +1,105 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/spia/CicloDiAnalisi.java b/src/GUI/spia/CicloDiAnalisi.java new file mode 100644 index 0000000..aa07140 --- /dev/null +++ b/src/GUI/spia/CicloDiAnalisi.java @@ -0,0 +1,148 @@ +/* + * 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 GUI.spia; + +/** + * + * @author davide + */ +public class CicloDiAnalisi extends javax.swing.JFrame { + + /** + * Creates new form CicloDiAnalisi + */ + public CicloDiAnalisi() { + 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() { + + jLabel2 = new javax.swing.JLabel(); + jButton1 = new javax.swing.JButton(); + jButton2 = new javax.swing.JButton(); + jScrollPane1 = new javax.swing.JScrollPane(); + jTextArea1 = new javax.swing.JTextArea(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jLabel2.setText("Ciclo di Analisi"); + + jButton1.setLabel("Esegui analisi frequenze"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jButton2.setLabel("Sostituisci una lettera"); + jButton2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton2ActionPerformed(evt); + } + }); + + jTextArea1.setEditable(false); + jTextArea1.setColumns(20); + jTextArea1.setRows(5); + jTextArea1.setText("Testo parzialmente decifrato"); + jScrollPane1.setViewportView(jTextArea1); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(74, 74, 74) + .addComponent(jLabel2) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1)) + .addGroup(layout.createSequentialGroup() + .addGap(57, 57, 57) + .addComponent(jButton2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE) + .addComponent(jButton1))) + .addGap(52, 52, 52)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel2) + .addGap(38, 38, 38) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton1) + .addComponent(jButton2)) + .addGap(35, 35, 35)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jButton1ActionPerformed + + private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jButton2ActionPerformed + + /** + * @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(CicloDiAnalisi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(CicloDiAnalisi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(CicloDiAnalisi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(CicloDiAnalisi.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 CicloDiAnalisi().setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + private javax.swing.JLabel jLabel2; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextArea jTextArea1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/GUI/spia/GestisciSessioni.form b/src/GUI/spia/GestisciSessioni.form new file mode 100644 index 0000000..dfc9091 --- /dev/null +++ b/src/GUI/spia/GestisciSessioni.form @@ -0,0 +1,103 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/spia/GestisciSessioni.java b/src/GUI/spia/GestisciSessioni.java new file mode 100644 index 0000000..0113631 --- /dev/null +++ b/src/GUI/spia/GestisciSessioni.java @@ -0,0 +1,130 @@ +/* + * 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 GUI.spia; + +/** + * + * @author davide + */ +public class GestisciSessioni extends javax.swing.JFrame { + + /** + * Creates new form GestisciSessioni + */ + public GestisciSessioni() { + 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() { + + jLabel1 = new javax.swing.JLabel(); + jScrollPane1 = new javax.swing.JScrollPane(); + jList1 = new javax.swing.JList(); + jButton1 = new javax.swing.JButton(); + jButton2 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jLabel1.setText("Elenco sessioni di lavoro iniziate in passato"); + + jList1.setModel(new javax.swing.AbstractListModel() { + String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; + public int getSize() { return strings.length; } + public Object getElementAt(int i) { return strings[i]; } + }); + jScrollPane1.setViewportView(jList1); + + jButton1.setText("Riprendi sessione"); + + jButton2.setText("Cancella sessione"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(98, 98, 98) + .addComponent(jLabel1)) + .addGroup(layout.createSequentialGroup() + .addGap(20, 20, 20) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 352, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addGap(46, 46, 46) + .addComponent(jButton1) + .addGap(61, 61, 61) + .addComponent(jButton2))) + .addContainerGap(28, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel1) + .addGap(30, 30, 30) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton1) + .addComponent(jButton2)) + .addContainerGap()) + ); + + pack(); + }// //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(GestisciSessioni.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(GestisciSessioni.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(GestisciSessioni.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(GestisciSessioni.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 GestisciSessioni().setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + private javax.swing.JLabel jLabel1; + private javax.swing.JList jList1; + private javax.swing.JScrollPane jScrollPane1; + // End of variables declaration//GEN-END:variables +} From 32c66307059cc7539355e04f063cab20fdbe01ef Mon Sep 17 00:00:00 2001 From: davide Date: Sat, 20 Sep 2014 00:42:33 +0200 Subject: [PATCH 09/45] Aggiunta dei form per il ciclo di analisi e la gestione delle sessioni --- src/GUI/spia/CicloDiAnalisi.java | 6 +- src/GUI/spia/SostituzioneLettera.form | 116 ++++++++++++++++++++ src/GUI/spia/SostituzioneLettera.java | 152 ++++++++++++++++++++++++++ 3 files changed, 273 insertions(+), 1 deletion(-) create mode 100644 src/GUI/spia/SostituzioneLettera.form create mode 100644 src/GUI/spia/SostituzioneLettera.java diff --git a/src/GUI/spia/CicloDiAnalisi.java b/src/GUI/spia/CicloDiAnalisi.java index aa07140..e073bf8 100644 --- a/src/GUI/spia/CicloDiAnalisi.java +++ b/src/GUI/spia/CicloDiAnalisi.java @@ -100,7 +100,11 @@ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS }//GEN-LAST:event_jButton1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed - // TODO add your handling code here: + new Thread( new Runnable() { + public void run() { + new SostituzioneLettera().setVisible(true); + } + }).start(); }//GEN-LAST:event_jButton2ActionPerformed /** diff --git a/src/GUI/spia/SostituzioneLettera.form b/src/GUI/spia/SostituzioneLettera.form new file mode 100644 index 0000000..d2648d4 --- /dev/null +++ b/src/GUI/spia/SostituzioneLettera.form @@ -0,0 +1,116 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/spia/SostituzioneLettera.java b/src/GUI/spia/SostituzioneLettera.java new file mode 100644 index 0000000..0682fc4 --- /dev/null +++ b/src/GUI/spia/SostituzioneLettera.java @@ -0,0 +1,152 @@ +/* + * 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 GUI.spia; + +/** + * + * @author davide + */ +public class SostituzioneLettera extends javax.swing.JFrame { + + /** + * Creates new form SostituzioneLettera + */ + public SostituzioneLettera() { + 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() { + + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + jLabel3 = new javax.swing.JLabel(); + jTextField1 = new javax.swing.JTextField(); + jTextField2 = new javax.swing.JTextField(); + jButton1 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jLabel1.setText("Sostituisci la lettera:"); + + jLabel2.setText("Trasforma la lettera: "); + + jLabel3.setText("In:"); + + jTextField1.setText("jTextField1"); + + jTextField2.setText("jTextField2"); + + jButton1.setText("Sostituisci"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(144, 144, 144) + .addComponent(jLabel1)) + .addGroup(layout.createSequentialGroup() + .addGap(47, 47, 47) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel3) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel2) + .addGap(55, 55, 55) + .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))) + .addContainerGap(137, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(jButton1) + .addGap(46, 46, 46)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(21, 21, 21) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel1) + .addGap(37, 37, 37) + .addComponent(jLabel2)) + .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(39, 39, 39) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel3) + .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 82, Short.MAX_VALUE) + .addComponent(jButton1) + .addGap(50, 50, 50)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jButton1ActionPerformed + + /** + * @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(SostituzioneLettera.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(SostituzioneLettera.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(SostituzioneLettera.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(SostituzioneLettera.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 SostituzioneLettera().setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JTextField jTextField1; + private javax.swing.JTextField jTextField2; + // End of variables declaration//GEN-END:variables +} From ec1232d02275119791d463b29f08fd8a68ddbbac Mon Sep 17 00:00:00 2001 From: user Date: Sat, 20 Sep 2014 15:30:43 +0200 Subject: [PATCH 10/45] CHECK --- src/model/spia/Sessione.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/model/spia/Sessione.java b/src/model/spia/Sessione.java index 03cbbe0..44e96b4 100644 --- a/src/model/spia/Sessione.java +++ b/src/model/spia/Sessione.java @@ -133,7 +133,7 @@ public void start() { nomiStrumenti.add("BruteForce"); String nomeStrumentoScelto = GenericSelector.selectOptions(nomiStrumenti); - + //CHECK System.out.println( "Hai scelto lo strumento "+nomeStrumentoScelto); } } From c5ddedccd13e856672e54b8c59fab832832cb84e Mon Sep 17 00:00:00 2001 From: BobCaSUaL Date: Sat, 20 Sep 2014 15:42:45 +0200 Subject: [PATCH 11/45] CicloDiAnalisi linked --- src/GUI/spia/CicloDiAnalisi.java | 193 +++++++++++++------------------ src/model/spia/Sessione.java | 8 +- 2 files changed, 84 insertions(+), 117 deletions(-) diff --git a/src/GUI/spia/CicloDiAnalisi.java b/src/GUI/spia/CicloDiAnalisi.java index e073bf8..fab8200 100644 --- a/src/GUI/spia/CicloDiAnalisi.java +++ b/src/GUI/spia/CicloDiAnalisi.java @@ -6,6 +6,8 @@ package GUI.spia; +import model.spia.Sessione; + /** * * @author davide @@ -15,7 +17,8 @@ public class CicloDiAnalisi extends javax.swing.JFrame { /** * Creates new form CicloDiAnalisi */ - public CicloDiAnalisi() { + public CicloDiAnalisi( Sessione s ) { + this.sessione = s; initComponents(); } @@ -25,75 +28,75 @@ public CicloDiAnalisi() { * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - jLabel2 = new javax.swing.JLabel(); - jButton1 = new javax.swing.JButton(); - jButton2 = new javax.swing.JButton(); - jScrollPane1 = new javax.swing.JScrollPane(); - jTextArea1 = new javax.swing.JTextArea(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jLabel2.setText("Ciclo di Analisi"); - - jButton1.setLabel("Esegui analisi frequenze"); - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - - jButton2.setLabel("Sostituisci una lettera"); - jButton2.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton2ActionPerformed(evt); - } - }); - - jTextArea1.setEditable(false); - jTextArea1.setColumns(20); - jTextArea1.setRows(5); - jTextArea1.setText("Testo parzialmente decifrato"); - jScrollPane1.setViewportView(jTextArea1); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(74, 74, 74) - .addComponent(jLabel2) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(jScrollPane1)) - .addGroup(layout.createSequentialGroup() - .addGap(57, 57, 57) - .addComponent(jButton2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE) - .addComponent(jButton1))) - .addGap(52, 52, 52)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(jLabel2) - .addGap(38, 38, 38) - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jButton1) - .addComponent(jButton2)) - .addGap(35, 35, 35)) - ); - - pack(); - }// //GEN-END:initComponents + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel2 = new javax.swing.JLabel(); + jButton1 = new javax.swing.JButton(); + jButton2 = new javax.swing.JButton(); + jScrollPane1 = new javax.swing.JScrollPane(); + jTextArea1 = new javax.swing.JTextArea(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jLabel2.setText("Ciclo di Analisi"); + + jButton1.setLabel("Esegui analisi frequenze"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jButton2.setLabel("Sostituisci una lettera"); + jButton2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton2ActionPerformed(evt); + } + }); + + jTextArea1.setEditable(false); + jTextArea1.setColumns(20); + jTextArea1.setRows(5); + jTextArea1.setText("Testo parzialmente decifrato"); + jScrollPane1.setViewportView(jTextArea1); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(74, 74, 74) + .addComponent(jLabel2) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1)) + .addGroup(layout.createSequentialGroup() + .addGap(57, 57, 57) + .addComponent(jButton2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE) + .addComponent(jButton1))) + .addGap(52, 52, 52)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel2) + .addGap(38, 38, 38) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton1) + .addComponent(jButton2)) + .addGap(35, 35, 35)) + ); + + pack(); + }// //GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: @@ -107,46 +110,14 @@ public void run() { }).start(); }//GEN-LAST:event_jButton2ActionPerformed - /** - * @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(CicloDiAnalisi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(CicloDiAnalisi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(CicloDiAnalisi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(CicloDiAnalisi.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 CicloDiAnalisi().setVisible(true); - } - }); - } - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton1; - private javax.swing.JButton jButton2; - private javax.swing.JLabel jLabel2; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JTextArea jTextArea1; - // End of variables declaration//GEN-END:variables + private Sessione sessione; + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + private javax.swing.JLabel jLabel2; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextArea jTextArea1; + // End of variables declaration//GEN-END:variables } diff --git a/src/model/spia/Sessione.java b/src/model/spia/Sessione.java index 44e96b4..cdada8c 100644 --- a/src/model/spia/Sessione.java +++ b/src/model/spia/Sessione.java @@ -2,6 +2,7 @@ import GUI.GenericSelector; +import GUI.spia.CicloDiAnalisi; import db.DbManager; import db.Query; import db.QueryResult; @@ -128,12 +129,7 @@ public Properties getProperties() { public void start() { ArrayList nomiStrumenti = new ArrayList<>(); - nomiStrumenti.add("RipristinaSessione"); - nomiStrumenti.add("AnalisiDelleFrequenze"); - nomiStrumenti.add("BruteForce"); - String nomeStrumentoScelto = GenericSelector.selectOptions(nomiStrumenti); - //CHECK - System.out.println( "Hai scelto lo strumento "+nomeStrumentoScelto); + new CicloDiAnalisi( this ).setVisible(true); } } From bf0dbff502766592cd8b149a211b727a5497f32d Mon Sep 17 00:00:00 2001 From: BobCaSUaL Date: Sat, 20 Sep 2014 15:47:30 +0200 Subject: [PATCH 12/45] edit Sessione --- src/model/spia/Sessione.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/model/spia/Sessione.java b/src/model/spia/Sessione.java index cdada8c..4e43cd4 100644 --- a/src/model/spia/Sessione.java +++ b/src/model/spia/Sessione.java @@ -10,8 +10,6 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; import model.Messaggio; import model.Studente; @@ -106,15 +104,12 @@ public static void saveSession( Sessione sessione ) { private Ipotesi root; private Ipotesi ipCorrente; - private Properties properties; + private Messaggio messaggio; + - public Sessione( Properties p ) { - this.properties = p; - this.key = new java.sql.Timestamp( new java.util.Date().getTime() ).toString(); - } public Sessione( Messaggio m ) { - this( new Properties() ); - this.properties.put("messaggio", m); + this.messaggio = m; + this.key = new java.sql.Timestamp( new java.util.Date().getTime() ).toString(); } public Ipotesi getIpotesiRadice() { @@ -123,8 +118,8 @@ public Ipotesi getIpotesiRadice() { public Ipotesi getIpotesiCorrente() { return ipCorrente; } - public Properties getProperties() { - return properties; + public Messaggio getMessaggio() { + return this.messaggio; } public void start() { From 36d80eea84b13423bf233f2e1e00610390442515 Mon Sep 17 00:00:00 2001 From: user Date: Sat, 20 Sep 2014 15:57:27 +0200 Subject: [PATCH 13/45] edit Sessione --- src/model/spia/Sessione.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/model/spia/Sessione.java b/src/model/spia/Sessione.java index 4e43cd4..d0278c7 100644 --- a/src/model/spia/Sessione.java +++ b/src/model/spia/Sessione.java @@ -124,7 +124,6 @@ public Messaggio getMessaggio() { public void start() { ArrayList nomiStrumenti = new ArrayList<>(); - new CicloDiAnalisi( this ).setVisible(true); } } From 10737cbe9e1f9321f8f8e165aec10637b4c4496a Mon Sep 17 00:00:00 2001 From: davide Date: Sat, 20 Sep 2014 15:58:15 +0200 Subject: [PATCH 14/45] Compilazione casella di testo messaggio parzialmente decifrato stronzi --- src/GUI/spia/CicloDiAnalisi.java | 8 ++++ src/model/Messaggio.java | 76 +++++++++++++++++++++++++++----- 2 files changed, 74 insertions(+), 10 deletions(-) diff --git a/src/GUI/spia/CicloDiAnalisi.java b/src/GUI/spia/CicloDiAnalisi.java index fab8200..31fc3c4 100644 --- a/src/GUI/spia/CicloDiAnalisi.java +++ b/src/GUI/spia/CicloDiAnalisi.java @@ -6,6 +6,7 @@ package GUI.spia; +import model.spia.Ipotesi; import model.spia.Sessione; /** @@ -19,6 +20,13 @@ public class CicloDiAnalisi extends javax.swing.JFrame { */ public CicloDiAnalisi( Sessione s ) { this.sessione = s; + String str; + Ipotesi ip; + if ((ip =this.sessione.getIpotesiCorrente())== null){ + str = s.getMessaggio().getTestoCifrato(); + jTextArea1.setText(str); + } + else jTextArea1.setText(ip.getMessaggioParzialmenteDecifrato()); initComponents(); } diff --git a/src/model/Messaggio.java b/src/model/Messaggio.java index 624aa4f..0dfbb48 100644 --- a/src/model/Messaggio.java +++ b/src/model/Messaggio.java @@ -161,8 +161,8 @@ public void setBozza(boolean b){ public void cifra(){ //SistemaCifratura.load(this.mittente, this.destinatario); - this.sdc.calcolaMappatura(); //sdc ha ora un oggetto mappatura - this.testoCifrato = Cifratore.cifra(this.testo, this.sdc.getMappatura()); + this.getSdc().calcolaMappatura(); //sdc ha ora un oggetto mappatura + this.testoCifrato = Cifratore.cifra(this.getTesto(), this.getSdc().getMappatura()); } public boolean isBozza(){ @@ -180,7 +180,7 @@ public boolean save(){ return true;*/ try{ DbManager db = DbManager.getInstance(); - Query q = db.createQuery("INSERT INTO `cryptohelper`.`messaggio` (`id`, `id_mittente`, `id_destinatario`, `testo`, `testoCifrato`, `lingua`, `titolo`, `bozza`, `letto`) VALUES (NULL, '" +this.mittente.getId()+"', '"+this.destinatario.getId()+"', '" + this.testo + "', '" + this.testoCifrato + "' , '" + this.lingua + "', 'titoloDiProva', " + this.bozza + ", false);"); + Query q = db.createQuery("INSERT INTO `cryptohelper`.`messaggio` (`id`, `id_mittente`, `id_destinatario`, `testo`, `testoCifrato`, `lingua`, `titolo`, `bozza`, `letto`) VALUES (NULL, '" +this.getMittente().getId()+"', '"+this.getDestinatario().getId()+"', '" + this.getTesto() + "', '" + this.getTestoCifrato() + "' , '" + this.getLingua() + "', 'titoloDiProva', " + this.isBozza() + ", false);"); q.executeUpdate(); } catch (SQLException ex){ @@ -195,17 +195,17 @@ public boolean isLetto(){ private String toStringF = "Messaggio in lingua: %lingua% inviato da utente con id %mittenteID% ad utente con id %destinatario% e testo: %testo%"; public String setToStringF( String f ) { - String result = toStringF; + String result = getToStringF(); this.toStringF = f; return result; } public String toString(){ - String result = toStringF; - result = result.replaceAll("%lingua%", lingua); - result = result.replaceAll("%mittenteID%", mittente.getId()); - result = result.replaceAll("%destinatarioID%", destinatario.getId()); - result = result.replaceAll("%testo%", testo); - result = result.replaceAll("%testoCif", testoCifrato); + String result = getToStringF(); + result = result.replaceAll("%lingua%", getLingua()); + result = result.replaceAll("%mittenteID%", getMittente().getId()); + result = result.replaceAll("%destinatarioID%", getDestinatario().getId()); + result = result.replaceAll("%testo%", getTesto()); + result = result.replaceAll("%testoCif", getTestoCifrato()); return result; } @@ -214,5 +214,61 @@ public boolean send(){ this.save(); return true; } + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @return the mittente + */ + public UserInfo getMittente() { + return mittente; + } + + /** + * @return the destinatario + */ + public UserInfo getDestinatario() { + return destinatario; + } + + /** + * @return the testo + */ + public String getTesto() { + return testo; + } + + /** + * @return the testoCifrato + */ + public String getTestoCifrato() { + return testoCifrato; + } + + /** + * @return the lingua + */ + public String getLingua() { + return lingua; + } + + /** + * @return the titolo + */ + public String getTitolo() { + return titolo; + } + + /** + * @return the toStringF + */ + public String getToStringF() { + return toStringF; + } } From 53b74656bc8934e592ad75f48270637a078af7bc Mon Sep 17 00:00:00 2001 From: BobCaSUaL Date: Sat, 20 Sep 2014 16:01:09 +0200 Subject: [PATCH 15/45] sync --- src/GUI/spia/CicloDiAnalisi.java | 61 +++++++++++++++++--------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/src/GUI/spia/CicloDiAnalisi.java b/src/GUI/spia/CicloDiAnalisi.java index 31fc3c4..bb7454b 100644 --- a/src/GUI/spia/CicloDiAnalisi.java +++ b/src/GUI/spia/CicloDiAnalisi.java @@ -3,7 +3,6 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ - package GUI.spia; import model.spia.Ipotesi; @@ -15,27 +14,32 @@ */ public class CicloDiAnalisi extends javax.swing.JFrame { - /** - * Creates new form CicloDiAnalisi - */ - public CicloDiAnalisi( Sessione s ) { - this.sessione = s; - String str; - Ipotesi ip; - if ((ip =this.sessione.getIpotesiCorrente())== null){ - str = s.getMessaggio().getTestoCifrato(); - jTextArea1.setText(str); - } - else jTextArea1.setText(ip.getMessaggioParzialmenteDecifrato()); - initComponents(); + public CicloDiAnalisi() { + initComponents(); + } + + /** + * Creates new form CicloDiAnalisi + */ + public CicloDiAnalisi(Sessione s) { + this(); + this.sessione = s; + String str; + Ipotesi ip; + if ((ip = this.sessione.getIpotesiCorrente()) == null) { + str = s.getMessaggio().getTestoCifrato(); + jTextArea1.setText(str); + } else { + jTextArea1.setText(ip.getMessaggioParzialmenteDecifrato()); } - - /** - * 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") + } + + /** + * 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() { @@ -107,20 +111,19 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { }// //GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - // TODO add your handling code here: + // TODO add your handling code here: }//GEN-LAST:event_jButton1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed - new Thread( new Runnable() { - public void run() { - new SostituzioneLettera().setVisible(true); - } - }).start(); + new Thread(new Runnable() { + public void run() { + new SostituzioneLettera().setVisible(true); + } + }).start(); }//GEN-LAST:event_jButton2ActionPerformed + private Sessione sessione; - private Sessione sessione; - // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; From 55528160a7cdf41235e1790b0d84540a72bbfd8e Mon Sep 17 00:00:00 2001 From: BobCaSUaL Date: Sat, 20 Sep 2014 16:12:39 +0200 Subject: [PATCH 16/45] sync --- src/GUI/spia/CicloDiAnalisi.form | 31 ++++++++++++++++++++++------- src/GUI/spia/CicloDiAnalisi.java | 34 ++++++++++++++++++++++++++------ src/model/spia/Sessione.java | 18 +++++++++++++++-- 3 files changed, 68 insertions(+), 15 deletions(-) diff --git a/src/GUI/spia/CicloDiAnalisi.form b/src/GUI/spia/CicloDiAnalisi.form index d326b7c..a1c718d 100644 --- a/src/GUI/spia/CicloDiAnalisi.form +++ b/src/GUI/spia/CicloDiAnalisi.form @@ -23,13 +23,14 @@ - - - - - + + + + + + @@ -49,8 +50,16 @@ - - + + + + + + + + + + @@ -101,5 +110,13 @@ + + + + + + + + diff --git a/src/GUI/spia/CicloDiAnalisi.java b/src/GUI/spia/CicloDiAnalisi.java index bb7454b..e9bb79b 100644 --- a/src/GUI/spia/CicloDiAnalisi.java +++ b/src/GUI/spia/CicloDiAnalisi.java @@ -48,6 +48,7 @@ private void initComponents() { jButton2 = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); + jButton3 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); @@ -73,16 +74,24 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { jTextArea1.setText("Testo parzialmente decifrato"); jScrollPane1.setViewportView(jTextArea1); + jButton3.setText("TerminaCicloDiAnalisi"); + jButton3.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton3ActionPerformed(evt); + } + }); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(74, 74, 74) - .addComponent(jLabel2) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(layout.createSequentialGroup() + .addGap(74, 74, 74) + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jButton3)) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1)) @@ -97,8 +106,13 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() - .addComponent(jLabel2) - .addGap(38, 38, 38) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel2) + .addGap(38, 38, 38)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(jButton3) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED))) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) @@ -122,11 +136,19 @@ public void run() { }).start(); }//GEN-LAST:event_jButton2ActionPerformed + private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed + this.dispose(); + synchronized( this.sessione ) { + this.sessione.notify(); + } + }//GEN-LAST:event_jButton3ActionPerformed + private Sessione sessione; // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; + private javax.swing.JButton jButton3; private javax.swing.JLabel jLabel2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextArea jTextArea1; diff --git a/src/model/spia/Sessione.java b/src/model/spia/Sessione.java index d0278c7..dba2772 100644 --- a/src/model/spia/Sessione.java +++ b/src/model/spia/Sessione.java @@ -10,6 +10,8 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; import model.Messaggio; import model.Studente; @@ -122,8 +124,20 @@ public Messaggio getMessaggio() { return this.messaggio; } - public void start() { + public synchronized void start() { ArrayList nomiStrumenti = new ArrayList<>(); - new CicloDiAnalisi( this ).setVisible(true); + final Sessione self = this; + + new Thread( new Runnable() { + public void run() { + new CicloDiAnalisi( self ).setVisible(true); + } + }).start(); + try { + wait(); + } catch (InterruptedException ex) { + throw new RuntimeException( ex.getMessage(), ex ); + } + System.out.println("SALVARE SESSIONE"); } } From 6d17d5625b41cfcb495c8f2a2caf66bdb9d1807f Mon Sep 17 00:00:00 2001 From: user Date: Sat, 20 Sep 2014 16:27:23 +0200 Subject: [PATCH 17/45] sync --- src/model/spia/Ipotesi.java | 15 ++- src/model/spia/Sessione.java | 214 +++++++++++++++++------------------ 2 files changed, 118 insertions(+), 111 deletions(-) diff --git a/src/model/spia/Ipotesi.java b/src/model/spia/Ipotesi.java index 903ce62..6ed52ed 100644 --- a/src/model/spia/Ipotesi.java +++ b/src/model/spia/Ipotesi.java @@ -15,12 +15,15 @@ * @author user */ public class Ipotesi extends javax.swing.tree.DefaultMutableTreeNode { - - private char cifrata; - private char inChiaro; - + + private String key; private String messaggioParzialmenteDecifrato; + public Ipotesi( String key, String messaggioParzialmenteDecifrato ) { + this.key = key; + this.messaggioParzialmenteDecifrato = messaggioParzialmenteDecifrato; + } + public String getMessaggioParzialmenteDecifrato() { return this.messaggioParzialmenteDecifrato; } @@ -33,4 +36,8 @@ public void remove( Ipotesi p ) { super.remove( p ); } + public String toString() { + return this.key; + } + } diff --git a/src/model/spia/Sessione.java b/src/model/spia/Sessione.java index dba2772..457395b 100644 --- a/src/model/spia/Sessione.java +++ b/src/model/spia/Sessione.java @@ -1,6 +1,5 @@ package model.spia; - import GUI.GenericSelector; import GUI.spia.CicloDiAnalisi; import db.DbManager; @@ -15,129 +14,130 @@ import model.Messaggio; import model.Studente; - - /* * 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. */ - /** * * @author user */ public class Sessione implements Serializable { - - public static class Properties extends java.util.Hashtable {} - - public static Sessione recuperaSessione( Studente s ) throws SQLException { - Sessione result = null; - ArrayList optionList = new ArrayList<>(); - - //seleziona la key di una sessione salvata - DbManager db = DbManager.getInstance(); - Query q = db.createQuery("SELECT `key` FROM `Sessione` WHERE `userId` = ?"); - q.setString ( 1, s.getId() ); - QueryResult rs = db.execute(q); - while( rs.next() ){ - optionList.add( rs.getString("key") ); - } - String key = GenericSelector.selectOptions( optionList ); - //In base alla key scelta deserializza la Sessione dal database - Query u = db.createQuery("SELECT `sessione` FROM `Sessione` WHERE `userId` = ? AND `key` = ? LIMIT 1"); - u.setString ( 1, s.getId() ); - u.setString ( 2, key ); - QueryResult qr = db.execute(u); + public static class Properties extends java.util.Hashtable { + } - if( qr.next() ) { - result = qr.getObject("sessione", Sessione.class); - } - return result; - } - - public static Sessione startNewSessione() { - List options = Messaggio.getMessaggi(); - for( Messaggio m: options ) { - m.setToStringF("%lingua%, %testoCif%"); - } - Messaggio selectedMsg = GenericSelector.selectOptions( options ); - Sessione s = new Sessione( selectedMsg ); - s.start(); - return s; - } - - public static Sessione restoreSessione( Sessione s ) { - s.start(); - return s; - } - - public static void deleteSessione( Sessione sessione ) { - try { - DbManager db = DbManager.getInstance(); - Query q = db.createQuery("DELETE FROM `Sessione` WHERE `id` = ? AND `userId` = ?"); - q.setString ( 1, Studente.getLoggato().getId() ); - q.setInt ( 2, sessione.id ); - QueryResult rs = db.execute(q); - - } catch (SQLException ex) { - throw new RuntimeException( ex.getMessage(), ex ); - } - } - - public static void saveSession( Sessione sessione ) { - try { - DbManager db = DbManager.getInstance(); - Query q = db.createQuery("INSERT INTO `Sessione`(`userId`,`key`,`session`) VALUES( ?, ?, ? )"); - q.setString ( 1, Studente.getLoggato().getId() ); - q.setString ( 2, sessione.key ); - q.setObject ( 3, sessione ); - QueryResult rs = db.execute(q); - - } catch (SQLException ex) { - throw new RuntimeException( ex.getMessage(), ex ); - } + public static Sessione recuperaSessione(Studente s) throws SQLException { + Sessione result = null; + ArrayList optionList = new ArrayList<>(); + + //seleziona la key di una sessione salvata + DbManager db = DbManager.getInstance(); + Query q = db.createQuery("SELECT `key` FROM `Sessione` WHERE `userId` = ?"); + q.setString(1, s.getId()); + QueryResult rs = db.execute(q); + while (rs.next()) { + optionList.add(rs.getString("key")); } - - private int id; - private String key; - - private Ipotesi root; - private Ipotesi ipCorrente; - - private Messaggio messaggio; - - - public Sessione( Messaggio m ) { - this.messaggio = m; - this.key = new java.sql.Timestamp( new java.util.Date().getTime() ).toString(); + String key = GenericSelector.selectOptions(optionList); + + //In base alla key scelta deserializza la Sessione dal database + Query u = db.createQuery("SELECT `sessione` FROM `Sessione` WHERE `userId` = ? AND `key` = ? LIMIT 1"); + u.setString(1, s.getId()); + u.setString(2, key); + QueryResult qr = db.execute(u); + + if (qr.next()) { + result = qr.getObject("sessione", Sessione.class); } - - public Ipotesi getIpotesiRadice() { - return root; + return result; + } + + public static Sessione startNewSessione() { + List options = Messaggio.getMessaggi(); + for (Messaggio m : options) { + m.setToStringF("%lingua%, %testoCif%"); } - public Ipotesi getIpotesiCorrente() { - return ipCorrente; + Messaggio selectedMsg = GenericSelector.selectOptions(options); + Sessione s = new Sessione(selectedMsg); + s.start(); + return s; + } + + public static Sessione restoreSessione(Sessione s) { + s.start(); + return s; + } + + public static void deleteSessione(Sessione sessione) { + try { + DbManager db = DbManager.getInstance(); + Query q = db.createQuery("DELETE FROM `Sessione` WHERE `id` = ? AND `userId` = ?"); + q.setString(1, Studente.getLoggato().getId()); + q.setInt(2, sessione.id); + QueryResult rs = db.execute(q); + + } catch (SQLException ex) { + throw new RuntimeException(ex.getMessage(), ex); } - public Messaggio getMessaggio() { - return this.messaggio; + } + + public static void saveSession(Sessione sessione) { + try { + DbManager db = DbManager.getInstance(); + Query q = db.createQuery("INSERT INTO `Sessione`(`userId`,`key`,`session`) VALUES( ?, ?, ? )"); + q.setString(1, Studente.getLoggato().getId()); + q.setString(2, sessione.key); + q.setObject(3, sessione); + QueryResult rs = db.execute(q); + + } catch (SQLException ex) { + throw new RuntimeException(ex.getMessage(), ex); } - - public synchronized void start() { - ArrayList nomiStrumenti = new ArrayList<>(); - final Sessione self = this; - - new Thread( new Runnable() { - public void run() { - new CicloDiAnalisi( self ).setVisible(true); - } - }).start(); - try { - wait(); - } catch (InterruptedException ex) { - throw new RuntimeException( ex.getMessage(), ex ); + } + + private int id; + private String key; + + private Ipotesi root; + private Ipotesi ipCorrente; + + private Messaggio messaggio; + + public Sessione(Messaggio m) { + this.messaggio = m; + this.key = new java.sql.Timestamp(new java.util.Date().getTime()).toString(); + } + + public Ipotesi getIpotesiRadice() { + return root; + } + + public Ipotesi getIpotesiCorrente() { + return ipCorrente; + } + + public Messaggio getMessaggio() { + return this.messaggio; + } + + public synchronized void start() { + + this.root = new Ipotesi("nessuna_sostituzione", this.messaggio.getTestoCifrato()); + this.ipCorrente = this.root; + + final Sessione self = this; + new Thread(new Runnable() { + public void run() { + new CicloDiAnalisi(self).setVisible(true); } - System.out.println("SALVARE SESSIONE"); + }).start(); + try { + wait(); + } catch (InterruptedException ex) { + throw new RuntimeException(ex.getMessage(), ex); } + System.out.println("SALVARE SESSIONE"); + } } From 684f6f00abcc4f475324a32572336cd8971a85c2 Mon Sep 17 00:00:00 2001 From: BobCaSUaL Date: Sat, 20 Sep 2014 18:43:58 +0200 Subject: [PATCH 18/45] Working update --- src/GUI/PopUpViewer.form | 76 +++++++ src/GUI/PopUpViewer.java | 123 +++++++++++ src/GUI/spia/CicloDiAnalisi.form | 65 ++++-- src/GUI/spia/CicloDiAnalisi.java | 100 ++++++--- src/GUI/spia/SostituzioneLettera.form | 71 +++--- src/GUI/spia/SostituzioneLettera.java | 202 ++++++++++-------- src/model/spia/Sessione.java | 16 +- .../spia/supportTools/AnalisiFrequenze.java | 23 -- .../analisiFrequenze/AnalisiFrequenze.java | 2 +- 9 files changed, 482 insertions(+), 196 deletions(-) create mode 100644 src/GUI/PopUpViewer.form create mode 100644 src/GUI/PopUpViewer.java delete mode 100644 src/model/spia/supportTools/AnalisiFrequenze.java diff --git a/src/GUI/PopUpViewer.form b/src/GUI/PopUpViewer.form new file mode 100644 index 0000000..b6af39d --- /dev/null +++ b/src/GUI/PopUpViewer.form @@ -0,0 +1,76 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/PopUpViewer.java b/src/GUI/PopUpViewer.java new file mode 100644 index 0000000..8e6a9d9 --- /dev/null +++ b/src/GUI/PopUpViewer.java @@ -0,0 +1,123 @@ +/* + * 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 GUI; + +/** + * + * @author user + */ +public class PopUpViewer extends javax.swing.JFrame { + + /** + * Creates new form PopUpViewer + */ + public PopUpViewer() { + initComponents(); + } + + public PopUpViewer(String toString) { + this(); + jTextArea1.setText(toString); + } + + /** + * 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() { + + jScrollPane1 = new javax.swing.JScrollPane(); + jTextArea1 = new javax.swing.JTextArea(); + jButton1 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jTextArea1.setColumns(20); + jTextArea1.setRows(5); + jScrollPane1.setViewportView(jTextArea1); + + jButton1.setText("Ok"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 432, Short.MAX_VALUE) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(jButton1))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 294, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButton1) + .addContainerGap(34, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + this.dispose(); + }//GEN-LAST:event_jButton1ActionPerformed + + /** + * @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(PopUpViewer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(PopUpViewer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(PopUpViewer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(PopUpViewer.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 PopUpViewer().setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextArea jTextArea1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/GUI/spia/CicloDiAnalisi.form b/src/GUI/spia/CicloDiAnalisi.form index a1c718d..28a0d65 100644 --- a/src/GUI/spia/CicloDiAnalisi.form +++ b/src/GUI/spia/CicloDiAnalisi.form @@ -24,25 +24,27 @@ - - + + + + + + + + - + - - - - - - - + - + + + @@ -52,21 +54,29 @@ - - + + - - + + + + + + + + + + + + + + + + + - - - - - - -
@@ -118,5 +128,16 @@
+ + + + + + + + + + + diff --git a/src/GUI/spia/CicloDiAnalisi.java b/src/GUI/spia/CicloDiAnalisi.java index e9bb79b..efb670a 100644 --- a/src/GUI/spia/CicloDiAnalisi.java +++ b/src/GUI/spia/CicloDiAnalisi.java @@ -5,14 +5,20 @@ */ package GUI.spia; +import GUI.PopUpViewer; +import java.util.Observable; +import java.util.Observer; +import javax.swing.JFrame; +import javax.swing.tree.DefaultTreeModel; import model.spia.Ipotesi; import model.spia.Sessione; +import model.spia.supportTools.analisiFrequenze.AnalisiFrequenze; /** * * @author davide */ -public class CicloDiAnalisi extends javax.swing.JFrame { +public class CicloDiAnalisi extends javax.swing.JFrame implements Observer { public CicloDiAnalisi() { initComponents(); @@ -24,14 +30,10 @@ public CicloDiAnalisi() { public CicloDiAnalisi(Sessione s) { this(); this.sessione = s; - String str; - Ipotesi ip; - if ((ip = this.sessione.getIpotesiCorrente()) == null) { - str = s.getMessaggio().getTestoCifrato(); - jTextArea1.setText(str); - } else { - jTextArea1.setText(ip.getMessaggioParzialmenteDecifrato()); - } + + updateIpotesi(); + + s.addObserver( this ); } /** @@ -49,6 +51,8 @@ private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); jButton3 = new javax.swing.JButton(); + jScrollPane2 = new javax.swing.JScrollPane(); + jTree1 = new javax.swing.JTree(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); @@ -81,26 +85,30 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { } }); + jScrollPane2.setViewportView(jTree1); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addGap(57, 57, 57) + .addComponent(jButton2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jButton1)) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addGap(74, 74, 74) .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton3)) - .addGroup(layout.createSequentialGroup() + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addContainerGap() - .addComponent(jScrollPane1)) - .addGroup(layout.createSequentialGroup() - .addGap(57, 57, 57) - .addComponent(jButton2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE) - .addComponent(jButton1))) - .addGap(52, 52, 52)) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 434, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGap(18, 18, 18) + .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE) + .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -108,30 +116,38 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addComponent(jLabel2) - .addGap(38, 38, 38)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addComponent(jButton3) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED))) - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jButton1) - .addComponent(jButton2)) - .addGap(35, 35, 35)) + .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel2) + .addGap(24, 24, 24)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(jButton3) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jButton2) + .addComponent(jButton1)) + .addGap(35, 35, 35)))) ); pack(); }// //GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - // TODO add your handling code here: + AnalisiFrequenze a = new AnalisiFrequenze(); + a.start( this.sessione.getIpotesiCorrente().getMessaggioParzialmenteDecifrato() ); + new PopUpViewer(a.toString()).setVisible(true); }//GEN-LAST:event_jButton1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed + final Sessione s = this.sessione; new Thread(new Runnable() { public void run() { - new SostituzioneLettera().setVisible(true); + new SostituzioneLettera( s ).setVisible(true); } }).start(); }//GEN-LAST:event_jButton2ActionPerformed @@ -151,6 +167,26 @@ private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS private javax.swing.JButton jButton3; private javax.swing.JLabel jLabel2; private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTextArea jTextArea1; + private javax.swing.JTree jTree1; // End of variables declaration//GEN-END:variables + + private void updateIpotesi() { + Sessione s = this.sessione; + Ipotesi ip = s.getIpotesiCorrente(); + + jTextArea1.setText(ip.getMessaggioParzialmenteDecifrato()); + + DefaultTreeModel treeModel = new DefaultTreeModel( s.getIpotesiRadice() ); + jTree1.setModel( treeModel ); + + for( int i = 0; i < jTree1.getRowCount(); i++ ) { + jTree1.expandRow(i); + } + } + @Override + public void update(Observable o, Object arg) { + updateIpotesi(); + } } diff --git a/src/GUI/spia/SostituzioneLettera.form b/src/GUI/spia/SostituzioneLettera.form index d2648d4..10f5874 100644 --- a/src/GUI/spia/SostituzioneLettera.form +++ b/src/GUI/spia/SostituzioneLettera.form @@ -23,34 +23,36 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + @@ -71,9 +73,11 @@
- + + + - +
@@ -96,13 +100,15 @@ - + + + + + + - - - @@ -112,5 +118,10 @@ + + + + + diff --git a/src/GUI/spia/SostituzioneLettera.java b/src/GUI/spia/SostituzioneLettera.java index 0682fc4..109c3da 100644 --- a/src/GUI/spia/SostituzioneLettera.java +++ b/src/GUI/spia/SostituzioneLettera.java @@ -6,18 +6,29 @@ package GUI.spia; +import java.util.Observable; +import model.spia.Ipotesi; +import model.spia.Sessione; +import model.spia.supportTools.analisiFrequenze.Replacer; + /** * * @author davide */ public class SostituzioneLettera extends javax.swing.JFrame { - + + /** * Creates new form SostituzioneLettera */ public SostituzioneLettera() { initComponents(); } + private Sessione sessione; + SostituzioneLettera( Sessione s ) { + this(); + this.sessione = s; + } /** * This method is called from within the constructor to initialize the form. @@ -25,87 +36,109 @@ public SostituzioneLettera() { * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - jLabel1 = new javax.swing.JLabel(); - jLabel2 = new javax.swing.JLabel(); - jLabel3 = new javax.swing.JLabel(); - jTextField1 = new javax.swing.JTextField(); - jTextField2 = new javax.swing.JTextField(); - jButton1 = new javax.swing.JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jLabel1.setText("Sostituisci la lettera:"); - - jLabel2.setText("Trasforma la lettera: "); - - jLabel3.setText("In:"); - - jTextField1.setText("jTextField1"); - - jTextField2.setText("jTextField2"); - - jButton1.setText("Sostituisci"); - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + jLabel3 = new javax.swing.JLabel(); + jTextField1 = new javax.swing.JTextField(); + jTextField2 = new javax.swing.JTextField(); + jButton1 = new javax.swing.JButton(); + jLabel4 = new javax.swing.JLabel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jLabel1.setText("Sostituisci la lettera:"); + + jLabel2.setText("Trasforma la lettera: "); + + jLabel3.setText("In:"); + + jTextField1.setMaximumSize(new java.awt.Dimension(1, 1)); + jTextField1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jTextField1ActionPerformed(evt); + } + }); + + jButton1.setText("Sostituisci"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jLabel4.setText("Se inserisci più caratteri verrà preso in considerazione solo il primo"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jButton1) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(144, 144, 144) + .addComponent(jLabel1)) .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(144, 144, 144) - .addComponent(jLabel1)) - .addGroup(layout.createSequentialGroup() - .addGap(47, 47, 47) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel3) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel2) - .addGap(55, 55, 55) - .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))) - .addContainerGap(137, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(jButton1) - .addGap(46, 46, 46)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(47, 47, 47) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel3) + .addGap(184, 184, 184) + .addComponent(jTextField2)) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel2) + .addGap(55, 55, 55) + .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGroup(layout.createSequentialGroup() - .addGap(21, 21, 21) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel1) - .addGap(37, 37, 37) - .addComponent(jLabel2)) - .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(39, 39, 39) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel3) - .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 82, Short.MAX_VALUE) - .addComponent(jButton1) - .addGap(50, 50, 50)) - ); - - pack(); - }// //GEN-END:initComponents + .addContainerGap() + .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 344, javax.swing.GroupLayout.PREFERRED_SIZE)))) + .addContainerGap(37, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(21, 21, 21) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel1) + .addGap(37, 37, 37) + .addComponent(jLabel2)) + .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(39, 39, 39) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel3) + .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) + .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGap(18, 18, 18) + .addComponent(jButton1) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - // TODO add your handling code here: + char crypt = jTextField1.getText().charAt(0); + char chiaro = jTextField2.getText().charAt(0); + + String msg = this.sessione.getIpotesiCorrente().getMessaggioParzialmenteDecifrato(); + String newMsg = new Replacer().start(msg, crypt, chiaro); + + Ipotesi nuova = new Ipotesi( crypt+" -> "+chiaro, newMsg); + this.sessione.add(nuova); + + this.dispose(); }//GEN-LAST:event_jButton1ActionPerformed + private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jTextField1ActionPerformed + /** * @param args the command line arguments */ @@ -141,12 +174,13 @@ public void run() { }); } - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton1; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; - private javax.swing.JTextField jTextField1; - private javax.swing.JTextField jTextField2; - // End of variables declaration//GEN-END:variables + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JTextField jTextField1; + private javax.swing.JTextField jTextField2; + // End of variables declaration//GEN-END:variables } diff --git a/src/model/spia/Sessione.java b/src/model/spia/Sessione.java index 457395b..86d7701 100644 --- a/src/model/spia/Sessione.java +++ b/src/model/spia/Sessione.java @@ -9,6 +9,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import java.util.Observable; import java.util.logging.Level; import java.util.logging.Logger; import model.Messaggio; @@ -23,7 +24,7 @@ * * @author user */ -public class Sessione implements Serializable { +public class Sessione extends Observable implements Serializable { public static class Properties extends java.util.Hashtable { } @@ -108,6 +109,9 @@ public static void saveSession(Sessione sessione) { public Sessione(Messaggio m) { this.messaggio = m; this.key = new java.sql.Timestamp(new java.util.Date().getTime()).toString(); + + this.root = new Ipotesi("radice", m.getTestoCifrato()); + this.ipCorrente = this.root; } public Ipotesi getIpotesiRadice() { @@ -122,11 +126,15 @@ public Messaggio getMessaggio() { return this.messaggio; } + public void add( Ipotesi nuova ) { + this.ipCorrente.add( nuova ); + ipCorrente = nuova; + + this.setChanged(); + this.notifyObservers(); + } public synchronized void start() { - this.root = new Ipotesi("nessuna_sostituzione", this.messaggio.getTestoCifrato()); - this.ipCorrente = this.root; - final Sessione self = this; new Thread(new Runnable() { public void run() { diff --git a/src/model/spia/supportTools/AnalisiFrequenze.java b/src/model/spia/supportTools/AnalisiFrequenze.java deleted file mode 100644 index 1e6d037..0000000 --- a/src/model/spia/supportTools/AnalisiFrequenze.java +++ /dev/null @@ -1,23 +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 model.spia.supportTools; - -import model.spia.*; -import model.Messaggio; - -/** - * - * @author user - */ -public class AnalisiFrequenze implements SistemaDiSupporto { - - @Override - public Ipotesi start(Ipotesi ipCorrente, Messaggio messaggio) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - -} diff --git a/src/model/spia/supportTools/analisiFrequenze/AnalisiFrequenze.java b/src/model/spia/supportTools/analisiFrequenze/AnalisiFrequenze.java index d69ed45..63a6d4c 100644 --- a/src/model/spia/supportTools/analisiFrequenze/AnalisiFrequenze.java +++ b/src/model/spia/supportTools/analisiFrequenze/AnalisiFrequenze.java @@ -12,7 +12,7 @@ public class AnalisiFrequenze { private HashMap table; private int msgLength; - public void start (String msg){ + public void start (String msg) { table = new HashMap(); // msg = msg.toLowerCase(); msg = msg.replaceAll("\\s", ""); /*rimuove gli spazi*/ From acbe8b56aee52961a6ace501c2d72803af759a1f Mon Sep 17 00:00:00 2001 From: Roberto Date: Sun, 21 Sep 2014 19:22:45 +0200 Subject: [PATCH 19/45] --- .gitignore | 4 +- nbproject/project.properties | 152 +++++++++++++++++------------------ src/model/UserInfo.java | 4 +- 3 files changed, 81 insertions(+), 79 deletions(-) diff --git a/.gitignore b/.gitignore index 838458f..fab78c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -/dist/ \ No newline at end of file +/dist/ +/nbproject/private/ +/build/ \ No newline at end of file diff --git a/nbproject/project.properties b/nbproject/project.properties index b007f4a..32e63c5 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,76 +1,76 @@ -annotation.processing.enabled=true -annotation.processing.enabled.in.editor=false -annotation.processing.processors.list= -annotation.processing.run.all.processors=true -annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output -application.title=CryptoHelper -application.vendor=user -build.classes.dir=${build.dir}/classes -build.classes.excludes=**/*.java,**/*.form -# This directory is removed when the project is cleaned: -build.dir=build -build.generated.dir=${build.dir}/generated -build.generated.sources.dir=${build.dir}/generated-sources -# Only compile against the classpath explicitly listed here: -build.sysclasspath=ignore -build.test.classes.dir=${build.dir}/test/classes -build.test.results.dir=${build.dir}/test/results -# Uncomment to specify the preferred debugger connection transport: -#debug.transport=dt_socket -debug.classpath=\ - ${run.classpath} -debug.test.classpath=\ - ${run.test.classpath} -# Files in build.classes.dir which should be excluded from distribution jar -dist.archive.excludes= -# This directory is removed when the project is cleaned: -dist.dir=dist -dist.jar=${dist.dir}/CryptoHelper.jar -dist.javadoc.dir=${dist.dir}/javadoc -endorsed.classpath= -excludes= -includes=** -jar.compress=false -javac.classpath=\ - ${libs.MySQLDriver.classpath} -# Space-separated list of extra javac options -javac.compilerargs= -javac.deprecation=false -javac.processorpath=\ - ${javac.classpath} -javac.source=1.7 -javac.target=1.7 -javac.test.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -javac.test.processorpath=\ - ${javac.test.classpath} -javadoc.additionalparam= -javadoc.author=false -javadoc.encoding=${source.encoding} -javadoc.noindex=false -javadoc.nonavbar=false -javadoc.notree=false -javadoc.private=false -javadoc.splitindex=true -javadoc.use=true -javadoc.version=false -javadoc.windowtitle= -main.class=GUI.Main -manifest.file=manifest.mf -meta.inf.dir=${src.dir}/META-INF -mkdist.disabled=false -platform.active=default_platform -run.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -# Space-separated list of JVM arguments used when running the project. -# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. -# To set system properties for unit tests define test-sys-prop.name=value: -run.jvmargs= -run.test.classpath=\ - ${javac.test.classpath}:\ - ${build.test.classes.dir} -source.encoding=UTF-8 -src.dir=src -test.src.dir=test +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=CryptoHelper +application.vendor=user +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/CryptoHelper.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath=\ + ${libs.MySQLDriver.classpath} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=GUI.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/src/model/UserInfo.java b/src/model/UserInfo.java index 84f5cc7..028298f 100644 --- a/src/model/UserInfo.java +++ b/src/model/UserInfo.java @@ -36,8 +36,8 @@ public UserInfo(String id){ QueryResult rs = db.execute(q); rs.next(); this.username = rs.getString(2); - this.nome = rs.getString(2); - this.cognome = rs.getString(2); + this.nome = rs.getString(4); + this.cognome = rs.getString(5); } catch(SQLException ex){ throw new RuntimeException( ex.getMessage(), ex ); From 220d4c8f9faa972dd736a323864d92d9685acc58 Mon Sep 17 00:00:00 2001 From: BobCaSUaL Date: Sun, 21 Sep 2014 19:25:33 +0200 Subject: [PATCH 20/45] Rispristina sessione di lavoro and package reduction --- src/GUI/spia/CicloDiAnalisi.form | 71 ++++++---- src/GUI/spia/CicloDiAnalisi.java | 84 ++++++++---- src/GUI/spia/RipristinaIpotesiPrecedente.form | 87 ++++++++++++ src/GUI/spia/RipristinaIpotesiPrecedente.java | 128 ++++++++++++++++++ src/GUI/spia/SostituzioneLettera.java | 4 +- src/model/Messaggio.java | 2 +- .../AnalisiFrequenze.java | 2 +- src/model/spia/Sessione.java | 5 + ...eplacer.java => SostituzioneSemplice.java} | 4 +- .../TesterAnalisiFrequenze.java | 8 +- 10 files changed, 328 insertions(+), 67 deletions(-) create mode 100644 src/GUI/spia/RipristinaIpotesiPrecedente.form create mode 100644 src/GUI/spia/RipristinaIpotesiPrecedente.java rename src/model/spia/{supportTools/analisiFrequenze => }/AnalisiFrequenze.java (96%) rename src/model/spia/{supportTools/analisiFrequenze/Replacer.java => SostituzioneSemplice.java} (83%) rename src/test/model/spia/{supportTools => }/TesterAnalisiFrequenze.java (77%) diff --git a/src/GUI/spia/CicloDiAnalisi.form b/src/GUI/spia/CicloDiAnalisi.form index 28a0d65..08e41c2 100644 --- a/src/GUI/spia/CicloDiAnalisi.form +++ b/src/GUI/spia/CicloDiAnalisi.form @@ -24,25 +24,33 @@ - + - - - - + + + + + + + + + + + + + - - + + + + + - - - - - + + - @@ -54,27 +62,24 @@ - - + + - - - - - - - - + + - - - - - + + + + + + - + + + @@ -139,5 +144,13 @@ + + + + + + + + diff --git a/src/GUI/spia/CicloDiAnalisi.java b/src/GUI/spia/CicloDiAnalisi.java index efb670a..26de265 100644 --- a/src/GUI/spia/CicloDiAnalisi.java +++ b/src/GUI/spia/CicloDiAnalisi.java @@ -9,10 +9,15 @@ import java.util.Observable; import java.util.Observer; import javax.swing.JFrame; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeNode; +import javax.swing.tree.TreePath; import model.spia.Ipotesi; import model.spia.Sessione; -import model.spia.supportTools.analisiFrequenze.AnalisiFrequenze; +import model.spia.AnalisiFrequenze; /** * @@ -32,7 +37,6 @@ public CicloDiAnalisi(Sessione s) { this.sessione = s; updateIpotesi(); - s.addObserver( this ); } @@ -53,6 +57,7 @@ private void initComponents() { jButton3 = new javax.swing.JButton(); jScrollPane2 = new javax.swing.JScrollPane(); jTree1 = new javax.swing.JTree(); + jButton4 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); @@ -87,26 +92,38 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { jScrollPane2.setViewportView(jTree1); + jButton4.setText("RipristinaIpotesi"); + jButton4.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton4ActionPerformed(evt); + } + }); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addGap(57, 57, 57) - .addComponent(jButton2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jButton1)) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addGap(74, 74, 74) - .addComponent(jLabel2) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(74, 74, 74) + .addComponent(jLabel2) + .addGap(117, 117, 117) + .addComponent(jButton3)) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 434, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGap(18, 18, 18)) + .addGroup(layout.createSequentialGroup() + .addGap(58, 58, 58) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jButton3)) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addContainerGap() - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 434, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addGap(18, 18, 18) + .addComponent(jButton1) + .addGap(30, 30, 30))) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE) .addContainerGap()) ); @@ -116,22 +133,21 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) + .addContainerGap()) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel2) - .addGap(24, 24, 24)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addComponent(jButton3) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))) - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel2) + .addComponent(jButton3)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(27, 27, 27) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton2) .addComponent(jButton1)) - .addGap(35, 35, 35)))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jButton4) + .addGap(26, 26, 26)))) ); pack(); @@ -159,12 +175,17 @@ private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS } }//GEN-LAST:event_jButton3ActionPerformed + private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed + new RipristinaIpotesiPrecedente( this.sessione ).setVisible(true); + }//GEN-LAST:event_jButton4ActionPerformed + private Sessione sessione; // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; + private javax.swing.JButton jButton4; private javax.swing.JLabel jLabel2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; @@ -172,6 +193,7 @@ private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS private javax.swing.JTree jTree1; // End of variables declaration//GEN-END:variables + private void updateIpotesi() { Sessione s = this.sessione; Ipotesi ip = s.getIpotesiCorrente(); @@ -184,6 +206,12 @@ private void updateIpotesi() { for( int i = 0; i < jTree1.getRowCount(); i++ ) { jTree1.expandRow(i); } + + DefaultMutableTreeNode currentNode = this.sessione.getIpotesiCorrente(); + TreeNode[] nodes = ((DefaultTreeModel) jTree1.getModel()).getPathToRoot( currentNode ); + TreePath tpath = new TreePath(nodes); + jTree1.scrollPathToVisible(tpath); + jTree1.setSelectionPath(tpath); } @Override public void update(Observable o, Object arg) { diff --git a/src/GUI/spia/RipristinaIpotesiPrecedente.form b/src/GUI/spia/RipristinaIpotesiPrecedente.form new file mode 100644 index 0000000..674ecae --- /dev/null +++ b/src/GUI/spia/RipristinaIpotesiPrecedente.form @@ -0,0 +1,87 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/spia/RipristinaIpotesiPrecedente.java b/src/GUI/spia/RipristinaIpotesiPrecedente.java new file mode 100644 index 0000000..efcad5b --- /dev/null +++ b/src/GUI/spia/RipristinaIpotesiPrecedente.java @@ -0,0 +1,128 @@ +/* + * 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 GUI.spia; + +import GUI.PopUpViewer; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeSelectionModel; +import model.spia.Ipotesi; +import model.spia.Sessione; + +/** + * + * @author user + */ +public class RipristinaIpotesiPrecedente extends javax.swing.JFrame { + + /** + * Creates new form RipristinaIpotesiPrecedente + */ + public RipristinaIpotesiPrecedente() { + initComponents(); + } + + public RipristinaIpotesiPrecedente(Sessione s) { + this(); + this.sessione = s; + + Ipotesi ip = s.getIpotesiCorrente(); + + DefaultTreeModel treeModel = new DefaultTreeModel( s.getIpotesiRadice() ); + jTree1.setModel( treeModel ); + jTree1.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); + + for( int i = 0; i < jTree1.getRowCount(); i++ ) { + jTree1.expandRow(i); + } + } + + /** + * 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() { + + jScrollPane1 = new javax.swing.JScrollPane(); + jTree1 = new javax.swing.JTree(); + jButton1 = new javax.swing.JButton(); + jButton2 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jScrollPane1.setViewportView(jTree1); + + jButton1.setText("Annulla"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jButton2.setText("Ripristina"); + jButton2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton2ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(20, 20, 20) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 352, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addComponent(jButton1) + .addGap(80, 80, 80) + .addComponent(jButton2))) + .addContainerGap(28, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton1) + .addComponent(jButton2)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed + Ipotesi selected = (Ipotesi)jTree1.getLastSelectedPathComponent(); + if( selected != null ) { + this.sessione.setIpotesiCorrente(selected); + this.dispose(); + } else { + new PopUpViewer("Scegli l'ipotesi da ripristinare").setVisible(true); + } + }//GEN-LAST:event_jButton2ActionPerformed + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + this.dispose(); + }//GEN-LAST:event_jButton1ActionPerformed + + + private Sessione sessione; + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTree jTree1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/GUI/spia/SostituzioneLettera.java b/src/GUI/spia/SostituzioneLettera.java index 109c3da..09fa053 100644 --- a/src/GUI/spia/SostituzioneLettera.java +++ b/src/GUI/spia/SostituzioneLettera.java @@ -9,7 +9,7 @@ import java.util.Observable; import model.spia.Ipotesi; import model.spia.Sessione; -import model.spia.supportTools.analisiFrequenze.Replacer; +import model.spia.SostituzioneSemplice; /** * @@ -127,7 +127,7 @@ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS char chiaro = jTextField2.getText().charAt(0); String msg = this.sessione.getIpotesiCorrente().getMessaggioParzialmenteDecifrato(); - String newMsg = new Replacer().start(msg, crypt, chiaro); + String newMsg = new SostituzioneSemplice().start(msg, crypt, chiaro); Ipotesi nuova = new Ipotesi( crypt+" -> "+chiaro, newMsg); this.sessione.add(nuova); diff --git a/src/model/Messaggio.java b/src/model/Messaggio.java index 0dfbb48..9274324 100644 --- a/src/model/Messaggio.java +++ b/src/model/Messaggio.java @@ -205,7 +205,7 @@ public String toString(){ result = result.replaceAll("%mittenteID%", getMittente().getId()); result = result.replaceAll("%destinatarioID%", getDestinatario().getId()); result = result.replaceAll("%testo%", getTesto()); - result = result.replaceAll("%testoCif", getTestoCifrato()); + result = result.replaceAll("%testoCif%", getTestoCifrato()); return result; } diff --git a/src/model/spia/supportTools/analisiFrequenze/AnalisiFrequenze.java b/src/model/spia/AnalisiFrequenze.java similarity index 96% rename from src/model/spia/supportTools/analisiFrequenze/AnalisiFrequenze.java rename to src/model/spia/AnalisiFrequenze.java index 63a6d4c..7494b7e 100644 --- a/src/model/spia/supportTools/analisiFrequenze/AnalisiFrequenze.java +++ b/src/model/spia/AnalisiFrequenze.java @@ -3,7 +3,7 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package model.spia.supportTools.analisiFrequenze; +package model.spia; import java.util.HashMap; /** * diff --git a/src/model/spia/Sessione.java b/src/model/spia/Sessione.java index 86d7701..7012224 100644 --- a/src/model/spia/Sessione.java +++ b/src/model/spia/Sessione.java @@ -121,6 +121,11 @@ public Ipotesi getIpotesiRadice() { public Ipotesi getIpotesiCorrente() { return ipCorrente; } + public void setIpotesiCorrente( Ipotesi ip ) { + this.ipCorrente = ip; + this.setChanged(); + this.notifyObservers(); + } public Messaggio getMessaggio() { return this.messaggio; diff --git a/src/model/spia/supportTools/analisiFrequenze/Replacer.java b/src/model/spia/SostituzioneSemplice.java similarity index 83% rename from src/model/spia/supportTools/analisiFrequenze/Replacer.java rename to src/model/spia/SostituzioneSemplice.java index 716e1cb..e221a6a 100644 --- a/src/model/spia/supportTools/analisiFrequenze/Replacer.java +++ b/src/model/spia/SostituzioneSemplice.java @@ -4,13 +4,13 @@ * and open the template in the editor. */ -package model.spia.supportTools.analisiFrequenze; +package model.spia; /** * * @author davide */ -public class Replacer { +public class SostituzioneSemplice { public String start(String msg, char from, char to){ to = Character.toUpperCase(to); msg = msg.replace(from, to); diff --git a/src/test/model/spia/supportTools/TesterAnalisiFrequenze.java b/src/test/model/spia/TesterAnalisiFrequenze.java similarity index 77% rename from src/test/model/spia/supportTools/TesterAnalisiFrequenze.java rename to src/test/model/spia/TesterAnalisiFrequenze.java index ed4d185..e0ff5a5 100644 --- a/src/test/model/spia/supportTools/TesterAnalisiFrequenze.java +++ b/src/test/model/spia/TesterAnalisiFrequenze.java @@ -4,10 +4,10 @@ * and open the template in the editor. */ -package test.model.spia.supportTools; +package test.model.spia; -import model.spia.supportTools.analisiFrequenze.AnalisiFrequenze; -import model.spia.supportTools.analisiFrequenze.Replacer; +import model.spia.AnalisiFrequenze; +import model.spia.SostituzioneSemplice; /** * @@ -22,7 +22,7 @@ public static void main(String[] args) { AnalisiFrequenze tool = new AnalisiFrequenze(); String msg = "hello analisi frequenze"; tool.start(msg); - Replacer tool1 = new Replacer(); + SostituzioneSemplice tool1 = new SostituzioneSemplice(); String edit = msg; edit = tool1.start(edit, 'e', 'F'); System.out.println(msg + "\nSostituzione e con F \n" + edit); From b575b74f3fd2fd3528facf6cd6cc9447c8f37b48 Mon Sep 17 00:00:00 2001 From: BobCaSUaL Date: Mon, 22 Sep 2014 20:46:14 +0200 Subject: [PATCH 21/45] primo adattamento ai DSD --- src/GUI/GenericSelector.java | 209 +++++++++--------- src/GUI/spia/CicloDiAnalisi.java | 24 +- src/GUI/spia/GestisciSessioni.java | 34 --- ...rm => RipristinaIpotesiPrecedenteGUI.form} | 0 ...va => RipristinaIpotesiPrecedenteGUI.java} | 6 +- src/GUI/spia/SostituzioneLettera.form | 24 +- src/GUI/spia/SostituzioneLettera.java | 123 ++++++----- src/model/Messaggio.java | 9 +- src/model/spia/AnalisiFrequenze.java | 21 +- src/model/spia/Ipotesi.java | 3 +- .../spia/RipristinaIpotesiPrecedente.java | 19 ++ src/model/spia/Sessione.java | 36 +-- src/model/spia/SostituzioneSemplice.java | 32 ++- src/model/spia/Spia.java | 2 +- src/model/spia/StrumentoDiManipolazione.java | 17 ++ ...Supporto.java => StrumentoDiSupporto.java} | 6 +- src/test/model/spia/SessioneTest.java | 2 +- .../model/spia/TesterAnalisiFrequenze.java | 2 +- 18 files changed, 311 insertions(+), 258 deletions(-) rename src/GUI/spia/{RipristinaIpotesiPrecedente.form => RipristinaIpotesiPrecedenteGUI.form} (100%) rename src/GUI/spia/{RipristinaIpotesiPrecedente.java => RipristinaIpotesiPrecedenteGUI.java} (96%) create mode 100644 src/model/spia/RipristinaIpotesiPrecedente.java create mode 100644 src/model/spia/StrumentoDiManipolazione.java rename src/model/spia/{SistemaDiSupporto.java => StrumentoDiSupporto.java} (69%) diff --git a/src/GUI/GenericSelector.java b/src/GUI/GenericSelector.java index 992dcfc..be5bfd1 100644 --- a/src/GUI/GenericSelector.java +++ b/src/GUI/GenericSelector.java @@ -3,7 +3,6 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ - package GUI; import java.util.List; @@ -14,76 +13,81 @@ * @param */ public class GenericSelector extends javax.swing.JFrame { - - public static K selectOptions( List list ) { - - final SynchronizedBuffer buff = new SynchronizedBuffer<>(); - final List fList = list; - - new Thread( new Runnable() { - @Override - public void run() { - GenericSelector selector = new GenericSelector<>(buff); - selector.setOptionList( fList ); - selector.setVisible(true); - } - } ).start(); - - return buff.get(); - } - - - SynchronizedBuffer syncBuffer; - - public GenericSelector( SynchronizedBuffer c ) { - this(); - this.syncBuffer = c; - } - /** - * Creates new form NuovaSessione - */ - public GenericSelector () { - initComponents(); - } - - public void setOptionList( List list ) { - T[] arr = (T[]) list.toArray( new Object[list.size()] ); - jList1.setListData(arr); - } - - public static class SynchronizedBuffer { - private T contents; - private boolean available = false; - - public synchronized T get() { - while (available == false) { - try { - wait(); - } catch (InterruptedException e) { } - } - available = false; - notifyAll(); - return contents; + + public static K selectOptions(List list) { + + final SynchronizedBuffer buff = new SynchronizedBuffer<>(); + final List fList = list; + + new Thread(new Runnable() { + @Override + public void run() { + GenericSelector selector = new GenericSelector<>(buff); + selector.setOptionList(fList); + selector.setVisible(true); + } + }).start(); + + return buff.get(); + } + + SynchronizedBuffer syncBuffer; + + private GenericSelector(SynchronizedBuffer c) { + this(); + this.syncBuffer = c; + } + + /** + * Creates new form NuovaSessione + */ + private GenericSelector() { + initComponents(); + } + + public void setOptionList(List list) { + T[] arr = (T[]) list.toArray(new Object[list.size()]); + jList1.setListData(arr); + } + + // + private static class SynchronizedBuffer { + + private T contents; + private boolean available = false; + + public synchronized T get() { + while (available == false) { + try { + wait(); + } catch (InterruptedException e) { } + } + available = false; + notifyAll(); + return contents; + } - public synchronized void put(T value) { - while (available == true) { - try { - wait(); - } catch (InterruptedException e) { } - } - contents = value; - available = true; - notifyAll(); + public synchronized void put(T value) { + while (available == true) { + try { + wait(); + } catch (InterruptedException e) { } + } + contents = value; + available = true; + notifyAll(); } - - /** - * 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") + } + // + + /** + * 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() { @@ -132,48 +136,47 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { }// //GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - // TODO add your handling code here: - T selected = (T)jList1.getSelectedValue(); - this.syncBuffer.put(selected); - this.dispose(); + // TODO add your handling code here: + T selected = (T) jList1.getSelectedValue(); + this.syncBuffer.put(selected); + this.dispose(); }//GEN-LAST:event_jButton1ActionPerformed - /** - * @param args the command line arguments - */ - public static void main(String args[]) { - /* Set the Nimbus look and feel */ + /** + * @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(GenericSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(GenericSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(GenericSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(GenericSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + * 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; } - // - - List list = new java.util.ArrayList<>(); - list.add("A"); - list.add("B"); - list.add("C"); - list.add("D"); - - - System.out.println( GenericSelector.selectOptions(list) ); + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(GenericSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(GenericSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(GenericSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(GenericSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } + // + + List list = new java.util.ArrayList<>(); + list.add("A"); + list.add("B"); + list.add("C"); + list.add("D"); + + System.out.println(GenericSelector.selectOptions(list)); + } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; diff --git a/src/GUI/spia/CicloDiAnalisi.java b/src/GUI/spia/CicloDiAnalisi.java index 26de265..8862656 100644 --- a/src/GUI/spia/CicloDiAnalisi.java +++ b/src/GUI/spia/CicloDiAnalisi.java @@ -8,16 +8,17 @@ import GUI.PopUpViewer; import java.util.Observable; import java.util.Observer; -import javax.swing.JFrame; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; +import model.spia.AnalisiFrequenze; import model.spia.Ipotesi; import model.spia.Sessione; -import model.spia.AnalisiFrequenze; +import model.spia.SostituzioneSemplice; +import model.spia.StrumentoDiManipolazione; +import model.spia.StrumentoDiSupporto; +import model.spia.RipristinaIpotesiPrecedente; /** * @@ -154,29 +155,28 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { }// //GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - AnalisiFrequenze a = new AnalisiFrequenze(); + StrumentoDiSupporto a = new AnalisiFrequenze(); + a.start( this.sessione.getIpotesiCorrente().getMessaggioParzialmenteDecifrato() ); new PopUpViewer(a.toString()).setVisible(true); }//GEN-LAST:event_jButton1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed - final Sessione s = this.sessione; - new Thread(new Runnable() { - public void run() { - new SostituzioneLettera( s ).setVisible(true); - } - }).start(); + StrumentoDiManipolazione s = new SostituzioneSemplice(); + s.elabora( this.sessione ); }//GEN-LAST:event_jButton2ActionPerformed private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed this.dispose(); synchronized( this.sessione ) { + //torna il controllo a Sessione.start(); this.sessione.notify(); } }//GEN-LAST:event_jButton3ActionPerformed private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed - new RipristinaIpotesiPrecedente( this.sessione ).setVisible(true); + StrumentoDiManipolazione s = new RipristinaIpotesiPrecedente(); + s.elabora( this.sessione ); }//GEN-LAST:event_jButton4ActionPerformed private Sessione sessione; diff --git a/src/GUI/spia/GestisciSessioni.java b/src/GUI/spia/GestisciSessioni.java index 0113631..1d8db26 100644 --- a/src/GUI/spia/GestisciSessioni.java +++ b/src/GUI/spia/GestisciSessioni.java @@ -85,40 +85,6 @@ private void initComponents() { pack(); }// //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(GestisciSessioni.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(GestisciSessioni.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(GestisciSessioni.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(GestisciSessioni.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 GestisciSessioni().setVisible(true); - } - }); - } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; diff --git a/src/GUI/spia/RipristinaIpotesiPrecedente.form b/src/GUI/spia/RipristinaIpotesiPrecedenteGUI.form similarity index 100% rename from src/GUI/spia/RipristinaIpotesiPrecedente.form rename to src/GUI/spia/RipristinaIpotesiPrecedenteGUI.form diff --git a/src/GUI/spia/RipristinaIpotesiPrecedente.java b/src/GUI/spia/RipristinaIpotesiPrecedenteGUI.java similarity index 96% rename from src/GUI/spia/RipristinaIpotesiPrecedente.java rename to src/GUI/spia/RipristinaIpotesiPrecedenteGUI.java index efcad5b..9fa5504 100644 --- a/src/GUI/spia/RipristinaIpotesiPrecedente.java +++ b/src/GUI/spia/RipristinaIpotesiPrecedenteGUI.java @@ -16,16 +16,16 @@ * * @author user */ -public class RipristinaIpotesiPrecedente extends javax.swing.JFrame { +public class RipristinaIpotesiPrecedenteGUI extends javax.swing.JFrame { /** * Creates new form RipristinaIpotesiPrecedente */ - public RipristinaIpotesiPrecedente() { + public RipristinaIpotesiPrecedenteGUI() { initComponents(); } - public RipristinaIpotesiPrecedente(Sessione s) { + public RipristinaIpotesiPrecedenteGUI(Sessione s) { this(); this.sessione = s; diff --git a/src/GUI/spia/SostituzioneLettera.form b/src/GUI/spia/SostituzioneLettera.form index 10f5874..f74e168 100644 --- a/src/GUI/spia/SostituzioneLettera.form +++ b/src/GUI/spia/SostituzioneLettera.form @@ -1,6 +1,13 @@
+ + + + + + + @@ -27,10 +34,6 @@ - - - - @@ -59,13 +62,9 @@ - + - - - - - + @@ -83,11 +82,6 @@ - - - - - diff --git a/src/GUI/spia/SostituzioneLettera.java b/src/GUI/spia/SostituzioneLettera.java index 09fa053..3cacc95 100644 --- a/src/GUI/spia/SostituzioneLettera.java +++ b/src/GUI/spia/SostituzioneLettera.java @@ -6,6 +6,8 @@ package GUI.spia; +import GUI.GenericSelector; +import java.util.List; import java.util.Observable; import model.spia.Ipotesi; import model.spia.Sessione; @@ -17,17 +19,64 @@ */ public class SostituzioneLettera extends javax.swing.JFrame { + public static char[] getCaratteriDaSostituire() { + + final SynchronizedBuffer buff = new SynchronizedBuffer<>(); + + new Thread(new Runnable() { + @Override + public void run() { + SostituzioneLettera frame = new SostituzioneLettera(buff); + frame.setVisible(true); + } + }).start(); + + return buff.get(); + } + + // + private static class SynchronizedBuffer { + + private T contents; + private boolean available = false; + + public synchronized T get() { + while (available == false) { + try { + wait(); + } catch (InterruptedException e) { + } + } + available = false; + notifyAll(); + return contents; + } + + public synchronized void put(T value) { + while (available == true) { + try { + wait(); + } catch (InterruptedException e) { + } + } + contents = value; + available = true; + notifyAll(); + } + } + // + private SynchronizedBuffer buff; /** * Creates new form SostituzioneLettera */ - public SostituzioneLettera() { + private SostituzioneLettera() { initComponents(); } - private Sessione sessione; - SostituzioneLettera( Sessione s ) { + + private SostituzioneLettera( SynchronizedBuffer buff ) { this(); - this.sessione = s; + this.buff = buff; } /** @@ -47,10 +96,10 @@ private void initComponents() { jButton1 = new javax.swing.JButton(); jLabel4 = new javax.swing.JLabel(); - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - jLabel1.setText("Sostituisci la lettera:"); + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + jLabel2.setText("Trasforma la lettera: "); jLabel3.setText("In:"); @@ -79,9 +128,6 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jButton1) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(144, 144, 144) - .addComponent(jLabel1)) .addGroup(layout.createSequentialGroup() .addGap(47, 47, 47) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) @@ -101,12 +147,9 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addGap(21, 21, 21) + .addGap(65, 65, 65) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel1) - .addGap(37, 37, 37) - .addComponent(jLabel2)) + .addComponent(jLabel2) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(39, 39, 39) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) @@ -123,15 +166,12 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { }// //GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - char crypt = jTextField1.getText().charAt(0); - char chiaro = jTextField2.getText().charAt(0); - - String msg = this.sessione.getIpotesiCorrente().getMessaggioParzialmenteDecifrato(); - String newMsg = new SostituzioneSemplice().start(msg, crypt, chiaro); - - Ipotesi nuova = new Ipotesi( crypt+" -> "+chiaro, newMsg); - this.sessione.add(nuova); + char[] array = new char[2]; + array[0] = jTextField1.getText().charAt(0); + array[1] = jTextField2.getText().charAt(0); + + this.buff.put( array ); this.dispose(); }//GEN-LAST:event_jButton1ActionPerformed @@ -139,41 +179,12 @@ private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F // TODO add your handling code here: }//GEN-LAST:event_jTextField1ActionPerformed - /** - * @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(SostituzioneLettera.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(SostituzioneLettera.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(SostituzioneLettera.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(SostituzioneLettera.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 SostituzioneLettera().setVisible(true); - } - }); - } + public static void main( String[] args ) { + char[] r = getCaratteriDaSostituire(); + System.out.println(r[0]+" "+r[1]); + } + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; diff --git a/src/model/Messaggio.java b/src/model/Messaggio.java index 9274324..ea6646d 100644 --- a/src/model/Messaggio.java +++ b/src/model/Messaggio.java @@ -6,20 +6,21 @@ package model; -import model.user.Cifratore; -import model.user.SistemaCifratura; import db.DbManager; import db.Query; import db.QueryResult; +import java.io.Serializable; import java.sql.SQLException; -import java.util.List; import java.util.ArrayList; +import java.util.List; +import model.user.Cifratore; +import model.user.SistemaCifratura; /** * * @author MASTER */ -public class Messaggio implements MessaggioMittente, MessaggioDestinatario{ +public class Messaggio implements MessaggioMittente, MessaggioDestinatario, Serializable { private int id; private UserInfo mittente, destinatario; private SistemaCifratura sdc; diff --git a/src/model/spia/AnalisiFrequenze.java b/src/model/spia/AnalisiFrequenze.java index 7494b7e..3aa4019 100644 --- a/src/model/spia/AnalisiFrequenze.java +++ b/src/model/spia/AnalisiFrequenze.java @@ -9,17 +9,19 @@ * * @author davide */ -public class AnalisiFrequenze { +public class AnalisiFrequenze implements StrumentoDiSupporto { private HashMap table; private int msgLength; - public void start (String msg) { + + @Override + public void start (String messaggio) { table = new HashMap(); // msg = msg.toLowerCase(); - msg = msg.replaceAll("\\s", ""); /*rimuove gli spazi*/ - this. msgLength = msg.length(); - System.out.println(msg); - for(int i = 0; i < msg.length(); i++){ - Character c = msg.charAt(i); + messaggio = messaggio.replaceAll("\\s", ""); /*rimuove gli spazi*/ + this. msgLength = messaggio.length(); + System.out.println(messaggio); + for(int i = 0; i < messaggio.length(); i++){ + Character c = messaggio.charAt(i); if (table.containsKey(c)){ Integer occorrenze = (Integer)table.get(c)+1; table.put(c, occorrenze); @@ -30,6 +32,7 @@ public void start (String msg) { } System.out.println(/*table + " size " + */this.toString()); } + @Override public String toString() { String frequencyTable = "Numero lettere nel messaggio " + this.getMsgLength()+"\n"; for(Character currentKey : table.keySet()){ @@ -39,8 +42,8 @@ public String toString() { return frequencyTable; //return table.size()+" numero lettere "+this.getMsgLength(); } - public int getMsgLength(){ + + private int getMsgLength(){ return this.msgLength; } - } diff --git a/src/model/spia/Ipotesi.java b/src/model/spia/Ipotesi.java index 6ed52ed..ad8f2ff 100644 --- a/src/model/spia/Ipotesi.java +++ b/src/model/spia/Ipotesi.java @@ -1,6 +1,7 @@ package model.spia; +import java.io.Serializable; import java.util.Enumeration; import javax.swing.tree.TreeNode; @@ -14,7 +15,7 @@ * * @author user */ -public class Ipotesi extends javax.swing.tree.DefaultMutableTreeNode { +public class Ipotesi extends javax.swing.tree.DefaultMutableTreeNode implements Serializable { private String key; private String messaggioParzialmenteDecifrato; diff --git a/src/model/spia/RipristinaIpotesiPrecedente.java b/src/model/spia/RipristinaIpotesiPrecedente.java new file mode 100644 index 0000000..91eaea2 --- /dev/null +++ b/src/model/spia/RipristinaIpotesiPrecedente.java @@ -0,0 +1,19 @@ +/* + * 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 model.spia; + +/** + * + * @author user + */ +public class RipristinaIpotesiPrecedente implements StrumentoDiManipolazione { + @Override + public void elabora(Sessione s) { + new GUI.spia.RipristinaIpotesiPrecedenteGUI( s ).setVisible(true); + } + +} diff --git a/src/model/spia/Sessione.java b/src/model/spia/Sessione.java index 7012224..cc00991 100644 --- a/src/model/spia/Sessione.java +++ b/src/model/spia/Sessione.java @@ -1,6 +1,7 @@ package model.spia; import GUI.GenericSelector; +import GUI.PopUpViewer; import GUI.spia.CicloDiAnalisi; import db.DbManager; import db.Query; @@ -29,14 +30,14 @@ public class Sessione extends Observable implements Serializable { public static class Properties extends java.util.Hashtable { } - public static Sessione recuperaSessione(Studente s) throws SQLException { + public static Sessione recuperaSessione(Spia owner) throws SQLException { Sessione result = null; ArrayList optionList = new ArrayList<>(); //seleziona la key di una sessione salvata DbManager db = DbManager.getInstance(); Query q = db.createQuery("SELECT `key` FROM `Sessione` WHERE `userId` = ?"); - q.setString(1, s.getId()); + q.setString(1, owner.getId()); QueryResult rs = db.execute(q); while (rs.next()) { optionList.add(rs.getString("key")); @@ -45,23 +46,24 @@ public static Sessione recuperaSessione(Studente s) throws SQLException { //In base alla key scelta deserializza la Sessione dal database Query u = db.createQuery("SELECT `sessione` FROM `Sessione` WHERE `userId` = ? AND `key` = ? LIMIT 1"); - u.setString(1, s.getId()); + u.setString(1, owner.getId()); u.setString(2, key); QueryResult qr = db.execute(u); if (qr.next()) { result = qr.getObject("sessione", Sessione.class); + result.owner = owner; } return result; } - public static Sessione startNewSessione() { + public static Sessione startNewSessione( Spia owner ) { List options = Messaggio.getMessaggi(); for (Messaggio m : options) { m.setToStringF("%lingua%, %testoCif%"); } Messaggio selectedMsg = GenericSelector.selectOptions(options); - Sessione s = new Sessione(selectedMsg); + Sessione s = new Sessione(owner, selectedMsg); s.start(); return s; } @@ -84,11 +86,13 @@ public static void deleteSessione(Sessione sessione) { } } - public static void saveSession(Sessione sessione) { + public static void saveSessione(Sessione sessione) { + Spia owner = sessione.owner; + sessione.owner = null; try { DbManager db = DbManager.getInstance(); Query q = db.createQuery("INSERT INTO `Sessione`(`userId`,`key`,`session`) VALUES( ?, ?, ? )"); - q.setString(1, Studente.getLoggato().getId()); + q.setString(1, owner.getId()); q.setString(2, sessione.key); q.setObject(3, sessione); QueryResult rs = db.execute(q); @@ -100,14 +104,18 @@ public static void saveSession(Sessione sessione) { private int id; private String key; + private Spia owner; private Ipotesi root; private Ipotesi ipCorrente; + private int messaggioID; //utilizzato per recuperare il messaggio deserializzato private Messaggio messaggio; - public Sessione(Messaggio m) { + public Sessione(Spia owner, Messaggio m) { this.messaggio = m; + this.owner = owner; + this.key = new java.sql.Timestamp(new java.util.Date().getTime()).toString(); this.root = new Ipotesi("radice", m.getTestoCifrato()); @@ -146,11 +154,11 @@ public void run() { new CicloDiAnalisi(self).setVisible(true); } }).start(); - try { - wait(); - } catch (InterruptedException ex) { - throw new RuntimeException(ex.getMessage(), ex); - } - System.out.println("SALVARE SESSIONE"); + + try { wait(); } + catch (InterruptedException ex) { throw new RuntimeException(ex.getMessage(), ex); } + + saveSessione( this ); + new PopUpViewer("la sessione è stata salvata").setVisible(true); } } diff --git a/src/model/spia/SostituzioneSemplice.java b/src/model/spia/SostituzioneSemplice.java index e221a6a..4319baa 100644 --- a/src/model/spia/SostituzioneSemplice.java +++ b/src/model/spia/SostituzioneSemplice.java @@ -6,14 +6,42 @@ package model.spia; +import GUI.spia.SostituzioneLettera; + + /** * * @author davide */ -public class SostituzioneSemplice { - public String start(String msg, char from, char to){ +public class SostituzioneSemplice implements StrumentoDiManipolazione { + private static String sostituisci(String msg, char from, char to){ to = Character.toUpperCase(to); msg = msg.replace(from, to); return msg; } + + @Override + public void elabora(Sessione sessione) { + final Sessione s = sessione; + new Thread( new Runnable() { + @Override + public void run() { + char[] array = SostituzioneLettera.getCaratteriDaSostituire(); + + if( array != null && array.length == 2 ) { + char crypt = array[0]; + char plain = array[1]; + + Ipotesi ipotesiCorrente = s.getIpotesiCorrente(); + String messaggio = ipotesiCorrente.getMessaggioParzialmenteDecifrato(); + + messaggio = sostituisci(messaggio, crypt, plain); + + Ipotesi nuova = new Ipotesi( crypt+" -> "+plain, messaggio); + s.add(nuova); + } + } + }).start(); + } + } diff --git a/src/model/spia/Spia.java b/src/model/spia/Spia.java index c3b22a3..5292eeb 100644 --- a/src/model/spia/Spia.java +++ b/src/model/spia/Spia.java @@ -28,7 +28,7 @@ public Spia(String nome, String cognome, String id, String user, String password } public Sessione startNewSessione() { - Sessione s = Sessione.startNewSessione(); + Sessione s = Sessione.startNewSessione( this ); return s; } diff --git a/src/model/spia/StrumentoDiManipolazione.java b/src/model/spia/StrumentoDiManipolazione.java new file mode 100644 index 0000000..9fa31f5 --- /dev/null +++ b/src/model/spia/StrumentoDiManipolazione.java @@ -0,0 +1,17 @@ +/* + * 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 model.spia; + +import model.Messaggio; + +/** + * + * @author user + */ +public interface StrumentoDiManipolazione { + public void elabora( Sessione s ); +} diff --git a/src/model/spia/SistemaDiSupporto.java b/src/model/spia/StrumentoDiSupporto.java similarity index 69% rename from src/model/spia/SistemaDiSupporto.java rename to src/model/spia/StrumentoDiSupporto.java index 9c70579..3d4ad17 100644 --- a/src/model/spia/SistemaDiSupporto.java +++ b/src/model/spia/StrumentoDiSupporto.java @@ -14,6 +14,8 @@ * * @author user */ -public interface SistemaDiSupporto { - public Ipotesi start(Ipotesi ipCorrente, Messaggio messaggio); +public interface StrumentoDiSupporto { + public void start(String messaggio); + @Override + public String toString(); } diff --git a/src/test/model/spia/SessioneTest.java b/src/test/model/spia/SessioneTest.java index 1137453..a0c8e97 100644 --- a/src/test/model/spia/SessioneTest.java +++ b/src/test/model/spia/SessioneTest.java @@ -14,7 +14,7 @@ */ public class SessioneTest { public static void main( String[] args ) { - Sessione s = Sessione.startNewSessione(); + Sessione s = Sessione.startNewSessione( null ); System.out.println(s); } } diff --git a/src/test/model/spia/TesterAnalisiFrequenze.java b/src/test/model/spia/TesterAnalisiFrequenze.java index e0ff5a5..18158c6 100644 --- a/src/test/model/spia/TesterAnalisiFrequenze.java +++ b/src/test/model/spia/TesterAnalisiFrequenze.java @@ -24,7 +24,7 @@ public static void main(String[] args) { tool.start(msg); SostituzioneSemplice tool1 = new SostituzioneSemplice(); String edit = msg; - edit = tool1.start(edit, 'e', 'F'); + edit = tool1.sostituisci(edit, 'e', 'F'); System.out.println(msg + "\nSostituzione e con F \n" + edit); tool.start(edit); // TODO code application logic here From f3f64bed35f69ca7ca1cbb477b9f054b83f5d4b4 Mon Sep 17 00:00:00 2001 From: BobCaSUaL Date: Mon, 22 Sep 2014 22:19:10 +0200 Subject: [PATCH 22/45] bugfix and various --- ...tera.form => SostituzioneSempliceGUI.form} | 0 ...tera.java => SostituzioneSempliceGUI.java} | 8 +- src/db/DbManager.java | 6 +- src/model/Messaggio.java | 45 +---------- src/model/MessaggioDestinatario.java | 2 +- src/model/MessaggioMittente.java | 2 +- src/model/spia/Sessione.java | 76 +++++++++++++++---- src/model/spia/SostituzioneSemplice.java | 4 +- src/test/model/spia/SessioneTest.java | 20 ----- .../model/spia/TesterAnalisiFrequenze.java | 33 -------- 10 files changed, 77 insertions(+), 119 deletions(-) rename src/GUI/spia/{SostituzioneLettera.form => SostituzioneSempliceGUI.form} (100%) rename src/GUI/spia/{SostituzioneLettera.java => SostituzioneSempliceGUI.java} (96%) delete mode 100644 src/test/model/spia/SessioneTest.java delete mode 100644 src/test/model/spia/TesterAnalisiFrequenze.java diff --git a/src/GUI/spia/SostituzioneLettera.form b/src/GUI/spia/SostituzioneSempliceGUI.form similarity index 100% rename from src/GUI/spia/SostituzioneLettera.form rename to src/GUI/spia/SostituzioneSempliceGUI.form diff --git a/src/GUI/spia/SostituzioneLettera.java b/src/GUI/spia/SostituzioneSempliceGUI.java similarity index 96% rename from src/GUI/spia/SostituzioneLettera.java rename to src/GUI/spia/SostituzioneSempliceGUI.java index 3cacc95..edf0e28 100644 --- a/src/GUI/spia/SostituzioneLettera.java +++ b/src/GUI/spia/SostituzioneSempliceGUI.java @@ -17,7 +17,7 @@ * * @author davide */ -public class SostituzioneLettera extends javax.swing.JFrame { +public class SostituzioneSempliceGUI extends javax.swing.JFrame { public static char[] getCaratteriDaSostituire() { @@ -26,7 +26,7 @@ public static char[] getCaratteriDaSostituire() { new Thread(new Runnable() { @Override public void run() { - SostituzioneLettera frame = new SostituzioneLettera(buff); + SostituzioneSempliceGUI frame = new SostituzioneSempliceGUI(buff); frame.setVisible(true); } }).start(); @@ -70,11 +70,11 @@ public synchronized void put(T value) { /** * Creates new form SostituzioneLettera */ - private SostituzioneLettera() { + private SostituzioneSempliceGUI() { initComponents(); } - private SostituzioneLettera( SynchronizedBuffer buff ) { + private SostituzioneSempliceGUI( SynchronizedBuffer buff ) { this(); this.buff = buff; } diff --git a/src/db/DbManager.java b/src/db/DbManager.java index 3f44eae..0461205 100644 --- a/src/db/DbManager.java +++ b/src/db/DbManager.java @@ -70,8 +70,8 @@ public QueryResult execute( Query q ) throws SQLException { return new QueryResultImpl( q ); } - /*public QueryResult executeUpdate( Query q ) throws SQLException { - return new QueryResultImpl( q ); - }*/ + public void executeUpdate( Query q ) throws SQLException { + q.executeUpdate(); + } } diff --git a/src/model/Messaggio.java b/src/model/Messaggio.java index ea6646d..fa5e75f 100644 --- a/src/model/Messaggio.java +++ b/src/model/Messaggio.java @@ -9,7 +9,6 @@ import db.DbManager; import db.Query; import db.QueryResult; -import java.io.Serializable; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; @@ -20,7 +19,7 @@ * * @author MASTER */ -public class Messaggio implements MessaggioMittente, MessaggioDestinatario, Serializable { +public class Messaggio implements MessaggioMittente, MessaggioDestinatario { private int id; private UserInfo mittente, destinatario; private SistemaCifratura sdc; @@ -36,11 +35,7 @@ public Messaggio(QueryResult rs) throws SQLException { this.testoCifrato = rs.getString(5); this.sdc = SistemaCifratura.load( rs.getString("idsistemacifratura") ); this.bozza = rs.getBoolean(8); - this.letto = rs.getBoolean(9); - - - - + this.letto = rs.getBoolean(9); } public Messaggio(String testo, String lingua, UserInfo mittente, UserInfo destinatario){ @@ -82,20 +77,6 @@ public void setSdc(SistemaCifratura s){ this.sdc = s; } - /*public static Messaggio load(int id){ - DbManager db = connect(); - Messaggio m; - Vector v = db.eseguiQuery("SELECT * FROM `cryptohelper`.`messaggio` WHERE id = " + id); - if(v.size()<= 0) return new Messaggio(); - else{ - p = new Proposta[v.size()]; - for(int i = 0; i < v.size(); i++){ - p[i] = new Proposta(Integer.parseInt(((String[])v.elementAt(i))[0]), new UserInfo(Integer.parseInt(((String[])v.elementAt(i))[1])), new UserInfo(Integer.parseInt(((String[])v.elementAt(i))[2])), ((String[])v.elementAt(i))[3]); - } - //return v; - } - }//carica il messaggio*/ - public static List caricaIniviati(Studente s){ return null; } @@ -125,7 +106,7 @@ public static MessaggioDestinatario[] caricaRicevuti(){ ArrayList result = new ArrayList<>(); try{ DbManager db = DbManager.getInstance(); - Query q = db.createQuery("SELECT * FROM `cryptohelper`.`messaggio` WHERE id_destinatario = " + Session.getIdLoggedUser()); + Query q = db.createQuery("SELECT * FROM `messaggio` WHERE id_destinatario = " + Session.getIdLoggedUser()); QueryResult rs = db.execute(q); while( rs.next() ){ UserInfo mittente = new UserInfo(rs.getString(2)); @@ -139,17 +120,6 @@ public static MessaggioDestinatario[] caricaRicevuti(){ throw new RuntimeException( ex.getMessage(), ex ); } return result.toArray( new MessaggioDestinatario[result.size()] ); - /*DbManager db = connect(); - MessaggioDestinatario[] m; - Vector v = db.eseguiQuery("SELECT * FROM `cryptohelper`.`messaggio` WHERE id_destinatario = " + Session.getIdLoggedUser()); - if(v.size()<= 0) return new MessaggioDestinatario[0]; - else{ - m = new MessaggioDestinatario[v.size()]; - for(int i = 0; i < v.size(); i++){ - m[i] = new Messaggio(((String[])v.elementAt(i))[3], ((String[])v.elementAt(i))[5], new UserInfo(((String[])v.elementAt(i))[1]), new UserInfo(((String[])v.elementAt(i))[2])); - } - return m; - }*/ } public boolean elimina(){ @@ -161,7 +131,6 @@ public void setBozza(boolean b){ } public void cifra(){ - //SistemaCifratura.load(this.mittente, this.destinatario); this.getSdc().calcolaMappatura(); //sdc ha ora un oggetto mappatura this.testoCifrato = Cifratore.cifra(this.getTesto(), this.getSdc().getMappatura()); } @@ -171,14 +140,6 @@ public boolean isBozza(){ } public boolean save(){ - /*DbManager db = connect(); - if (!db.eseguiAggiornamento("INSERT INTO `cryptohelper`.`messaggio` (`id`, `id_mittente`, `id_destinatario`, `testo`, `testoCifrato`, `lingua`, `titolo`, `bozza`, `letto`) VALUES (NULL, '" +this.mittente.getId()+"', '"+this.destinatario.getId()+"', '" + this.testo + "', '" + this.testoCifrato + "' , '" + this.lingua + "', 'titoloDiProva', " + this.bozza + ", false);")) { - System.out.println("Errore nell'aggiornamento!"); - System.out.println(db.getErrore()); - return false; - } - System.out.println("sgsgf"); - return true;*/ try{ DbManager db = DbManager.getInstance(); Query q = db.createQuery("INSERT INTO `cryptohelper`.`messaggio` (`id`, `id_mittente`, `id_destinatario`, `testo`, `testoCifrato`, `lingua`, `titolo`, `bozza`, `letto`) VALUES (NULL, '" +this.getMittente().getId()+"', '"+this.getDestinatario().getId()+"', '" + this.getTesto() + "', '" + this.getTestoCifrato() + "' , '" + this.getLingua() + "', 'titoloDiProva', " + this.isBozza() + ", false);"); diff --git a/src/model/MessaggioDestinatario.java b/src/model/MessaggioDestinatario.java index 089e08e..8a9dd0c 100644 --- a/src/model/MessaggioDestinatario.java +++ b/src/model/MessaggioDestinatario.java @@ -10,6 +10,6 @@ * * @author MASTER */ -public interface MessaggioDestinatario { +public interface MessaggioDestinatario extends MessaggioAstratto { public boolean isLetto(); } diff --git a/src/model/MessaggioMittente.java b/src/model/MessaggioMittente.java index 7ecf28d..c63f54b 100644 --- a/src/model/MessaggioMittente.java +++ b/src/model/MessaggioMittente.java @@ -10,7 +10,7 @@ * * @author MASTER */ -public interface MessaggioMittente { +public interface MessaggioMittente extends MessaggioAstratto { public boolean isBozza(); public boolean save(); public void cifra(); diff --git a/src/model/spia/Sessione.java b/src/model/spia/Sessione.java index cc00991..bd60f93 100644 --- a/src/model/spia/Sessione.java +++ b/src/model/spia/Sessione.java @@ -6,13 +6,16 @@ import db.DbManager; import db.Query; import db.QueryResult; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.io.Serializable; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.Observable; -import java.util.logging.Level; -import java.util.logging.Logger; import model.Messaggio; import model.Studente; @@ -45,14 +48,37 @@ public static Sessione recuperaSessione(Spia owner) throws SQLException { String key = GenericSelector.selectOptions(optionList); //In base alla key scelta deserializza la Sessione dal database - Query u = db.createQuery("SELECT `sessione` FROM `Sessione` WHERE `userId` = ? AND `key` = ? LIMIT 1"); + Query u = db.createQuery("SELECT `id`, `sessione` FROM `Sessione` WHERE `userId` = ? AND `key` = ? LIMIT 1"); u.setString(1, owner.getId()); u.setString(2, key); QueryResult qr = db.execute(u); if (qr.next()) { - result = qr.getObject("sessione", Sessione.class); + + try { + ByteArrayInputStream bais; + ObjectInputStream ins; + bais = new ByteArrayInputStream(qr.getBytes("sessione")); + ins = new ObjectInputStream(bais); + result =(Sessione)ins.readObject(); + + } catch( IOException | ClassNotFoundException ex ) { + throw new RuntimeException( ex.getMessage(), ex ); + } + + result.id = qr.getInt("id"); result.owner = owner; + + Query w = db.createQuery("SELECT * FROM `messaggio` WHERE `id` = ?"); + w.setInt(1, result.messaggioID); + QueryResult qu = db.execute( w ); + + if( qu.next() ) { + result.messaggio = new Messaggio( qu ); + } else { + throw new RuntimeException("il messaggion con id "+result.messaggioID+"non è stato trovato nel database"); + } + } return result; } @@ -77,9 +103,9 @@ public static void deleteSessione(Sessione sessione) { try { DbManager db = DbManager.getInstance(); Query q = db.createQuery("DELETE FROM `Sessione` WHERE `id` = ? AND `userId` = ?"); - q.setString(1, Studente.getLoggato().getId()); - q.setInt(2, sessione.id); - QueryResult rs = db.execute(q); + q.setInt(1, sessione.id); + q.setString(2, sessione.owner.getId()); + db.executeUpdate(q); } catch (SQLException ex) { throw new RuntimeException(ex.getMessage(), ex); @@ -87,17 +113,33 @@ public static void deleteSessione(Sessione sessione) { } public static void saveSessione(Sessione sessione) { + + //i set a null sono essenziali per la serializzazione della classe Spia owner = sessione.owner; sessione.owner = null; + sessione.messaggioID = sessione.messaggio.getId(); + sessione.messaggio = null; + try { + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(sessione); + oos.flush(); + oos.close(); + bos.close(); + byte[] data = bos.toByteArray(); + DbManager db = DbManager.getInstance(); - Query q = db.createQuery("INSERT INTO `Sessione`(`userId`,`key`,`session`) VALUES( ?, ?, ? )"); + Query q = db.createQuery("INSERT INTO `Sessione`(`userId`,`key`,`sessione`) VALUES( ?, ?, ? ) ON DUPLICATE KEY UPDATE `sessione` = ?"); q.setString(1, owner.getId()); q.setString(2, sessione.key); - q.setObject(3, sessione); - QueryResult rs = db.execute(q); + q.setObject(3, data); + q.setObject(4, data); + + db.executeUpdate(q); - } catch (SQLException ex) { + } catch (IOException | SQLException ex) { throw new RuntimeException(ex.getMessage(), ex); } } @@ -114,6 +156,8 @@ public static void saveSessione(Sessione sessione) { public Sessione(Spia owner, Messaggio m) { this.messaggio = m; + this.messaggioID = m.getId(); + this.owner = owner; this.key = new java.sql.Timestamp(new java.util.Date().getTime()).toString(); @@ -158,7 +202,13 @@ public void run() { try { wait(); } catch (InterruptedException ex) { throw new RuntimeException(ex.getMessage(), ex); } - saveSessione( this ); - new PopUpViewer("la sessione è stata salvata").setVisible(true); + try { + saveSessione( this ); + new PopUpViewer("la sessione è stata salvata").setVisible(true); + } catch( RuntimeException ex ) { + new PopUpViewer("La sessione non è stata salvata: \n\n"+ex.getMessage()).setVisible(true); + throw ex; + } + } } diff --git a/src/model/spia/SostituzioneSemplice.java b/src/model/spia/SostituzioneSemplice.java index 4319baa..a396449 100644 --- a/src/model/spia/SostituzioneSemplice.java +++ b/src/model/spia/SostituzioneSemplice.java @@ -6,7 +6,7 @@ package model.spia; -import GUI.spia.SostituzioneLettera; +import GUI.spia.SostituzioneSempliceGUI; /** @@ -26,7 +26,7 @@ public void elabora(Sessione sessione) { new Thread( new Runnable() { @Override public void run() { - char[] array = SostituzioneLettera.getCaratteriDaSostituire(); + char[] array = SostituzioneSempliceGUI.getCaratteriDaSostituire(); if( array != null && array.length == 2 ) { char crypt = array[0]; diff --git a/src/test/model/spia/SessioneTest.java b/src/test/model/spia/SessioneTest.java deleted file mode 100644 index a0c8e97..0000000 --- a/src/test/model/spia/SessioneTest.java +++ /dev/null @@ -1,20 +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 test.model.spia; - -import model.spia.Sessione; - -/** - * - * @author user - */ -public class SessioneTest { - public static void main( String[] args ) { - Sessione s = Sessione.startNewSessione( null ); - System.out.println(s); - } -} diff --git a/src/test/model/spia/TesterAnalisiFrequenze.java b/src/test/model/spia/TesterAnalisiFrequenze.java deleted file mode 100644 index 18158c6..0000000 --- a/src/test/model/spia/TesterAnalisiFrequenze.java +++ /dev/null @@ -1,33 +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 test.model.spia; - -import model.spia.AnalisiFrequenze; -import model.spia.SostituzioneSemplice; - -/** - * - * @author davide - */ -public class TesterAnalisiFrequenze { - - /** - * @param args the command line arguments - */ - public static void main(String[] args) { - AnalisiFrequenze tool = new AnalisiFrequenze(); - String msg = "hello analisi frequenze"; - tool.start(msg); - SostituzioneSemplice tool1 = new SostituzioneSemplice(); - String edit = msg; - edit = tool1.sostituisci(edit, 'e', 'F'); - System.out.println(msg + "\nSostituzione e con F \n" + edit); - tool.start(edit); - // TODO code application logic here - } - -} From 8c41b2204ee647f8ae4efb6872408f519625e656 Mon Sep 17 00:00:00 2001 From: Roberto Date: Mon, 22 Sep 2014 22:30:56 +0200 Subject: [PATCH 23/45] Eliminata classe Session.java con tute le relative dipendenze --- src/GUI/Main.java | 1 - src/GUI/user/NuoveProposte.java | 6 ++-- src/GUI/user/NuovoMessaggio.java | 4 +-- src/GUI/user/PropostaSistemaDiCifratura.java | 3 +- src/GUI/user/Utente_Regolamentare.java | 4 +-- src/controller/Controller.java | 3 +- src/model/Messaggio.java | 2 +- src/model/Session.java | 30 -------------------- src/model/user/SistemaCifratura.java | 5 ++-- 9 files changed, 12 insertions(+), 46 deletions(-) delete mode 100644 src/model/Session.java diff --git a/src/GUI/Main.java b/src/GUI/Main.java index 4da4fbe..7e6759f 100644 --- a/src/GUI/Main.java +++ b/src/GUI/Main.java @@ -9,7 +9,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JFrame; -import model.Session; import model.Studente; import model.spia.Spia; diff --git a/src/GUI/user/NuoveProposte.java b/src/GUI/user/NuoveProposte.java index 5186fda..929da88 100644 --- a/src/GUI/user/NuoveProposte.java +++ b/src/GUI/user/NuoveProposte.java @@ -10,7 +10,7 @@ /*import Clmodelession; import ClasmodelrInfo;*/ import controller.CommunicationController; -import model.Session; +import model.Studente; /** * @@ -106,7 +106,7 @@ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS Proposta p = (Proposta)jList1.getSelectedValue(); if(p != null){ CommunicationController.inviaDecisione(p, "accettata"); - Proposta[] nuovo = CommunicationController.getProposte(Session.getIdLoggedUser()); + Proposta[] nuovo = CommunicationController.getProposte(Studente.getLoggato().getId()); jList1.setListData(nuovo); } }//GEN-LAST:event_jButton1ActionPerformed @@ -116,7 +116,7 @@ private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS Proposta p = (Proposta)jList1.getSelectedValue(); if(p != null){ CommunicationController.inviaDecisione(p, "rifiutata"); - Proposta[] nuovo = CommunicationController.getProposte(Session.getIdLoggedUser()); + Proposta[] nuovo = CommunicationController.getProposte(Studente.getLoggato().getId()); jList1.setListData(nuovo); } }//GEN-LAST:event_jButton2ActionPerformed diff --git a/src/GUI/user/NuovoMessaggio.java b/src/GUI/user/NuovoMessaggio.java index b2fa7a2..3b1d676 100644 --- a/src/GUI/user/NuovoMessaggio.java +++ b/src/GUI/user/NuovoMessaggio.java @@ -16,7 +16,7 @@ * @author MASTER */ public class NuovoMessaggio extends javax.swing.JFrame { - private PropostaConfermata[] a = CommunicationController.getProposteAccettate(Session.getIdLoggedUser()); + private PropostaConfermata[] a = CommunicationController.getProposteAccettate(Studente.getLoggato().getId()); private int index; private Messaggio m = null; /** @@ -24,7 +24,7 @@ public class NuovoMessaggio extends javax.swing.JFrame { */ public NuovoMessaggio() { initComponents(); - m.setMittente(new UserInfo(Session.getIdLoggedUser())); + m.setMittente(new UserInfo(Studente.getLoggato().getId())); //a = CommunicationController.getProposteAccettate(Session.getIdLoggedUser()); int[] id_list = new int[a.length]; for(int i=0; i 0){ NuoveProposte n = new NuoveProposte(p); n.setVisible(true); diff --git a/src/controller/Controller.java b/src/controller/Controller.java index 99ad83c..724cfd9 100644 --- a/src/controller/Controller.java +++ b/src/controller/Controller.java @@ -10,7 +10,6 @@ import db.QueryResult; import java.sql.SQLException; import java.util.ArrayList; -import model.Session; import model.Studente; import model.UserInfo; import model.user.Proposta; @@ -96,7 +95,7 @@ public static UserInfo[] recuperaUtenti(){ ArrayList result = new ArrayList<>(); try{ DbManager db = DbManager.getInstance(); - Query q = db.createQuery("SELECT * FROM user where username <> '" + Session.getLoggedUser() + "'"); + Query q = db.createQuery("SELECT * FROM user where username <> '" + Studente.getLoggato().getId() + "'"); QueryResult rs = db.execute( q ); while( rs.next() ) { String id = rs.getString(1); diff --git a/src/model/Messaggio.java b/src/model/Messaggio.java index fa5e75f..8fb695a 100644 --- a/src/model/Messaggio.java +++ b/src/model/Messaggio.java @@ -106,7 +106,7 @@ public static MessaggioDestinatario[] caricaRicevuti(){ ArrayList result = new ArrayList<>(); try{ DbManager db = DbManager.getInstance(); - Query q = db.createQuery("SELECT * FROM `messaggio` WHERE id_destinatario = " + Session.getIdLoggedUser()); + Query q = db.createQuery("SELECT * FROM `messaggio` WHERE id_destinatario = " + Studente.getLoggato().getId()); QueryResult rs = db.execute(q); while( rs.next() ){ UserInfo mittente = new UserInfo(rs.getString(2)); diff --git a/src/model/Session.java b/src/model/Session.java deleted file mode 100644 index 3ec6ae7..0000000 --- a/src/model/Session.java +++ /dev/null @@ -1,30 +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 model; - -/** - * - * @author MASTER - */ -public class Session { - private static String loggedUser; - private static String id; - private String username, nome, cognome; - - public Session(String id, String user){ - this.id = id; - this.loggedUser = user; - } - - public static String getLoggedUser(){ - return loggedUser; - } - - public static String getIdLoggedUser(){ - return id; - } -} diff --git a/src/model/user/SistemaCifratura.java b/src/model/user/SistemaCifratura.java index 9008552..af68f2e 100644 --- a/src/model/user/SistemaCifratura.java +++ b/src/model/user/SistemaCifratura.java @@ -13,7 +13,6 @@ import db.QueryResult; import java.sql.SQLException; import java.util.Vector; -import model.Session; import model.Studente; import model.UserInfo; @@ -88,10 +87,10 @@ public SistemaCifratura(String id, String chiave, String metodo, UserInfo creato public SistemaCifratura(String chiave, String metodo){ this.chiave = chiave; this.metodo = metodo; - this.creatore = new UserInfo(Session.getIdLoggedUser()); + this.creatore = new UserInfo(Studente.getLoggato().getId()); try{ DbManager db = DbManager.getInstance(); - Query q = db.createQuery("INSERT INTO `cryptohelper`.`sistemacifratura` (`id`, `chiave`, `metodo`, `idcreatore`) VALUES (NULL, '" +chiave+"', '"+metodo+"', '" + Session.getIdLoggedUser() + "')"); + Query q = db.createQuery("INSERT INTO `cryptohelper`.`sistemacifratura` (`id`, `chiave`, `metodo`, `idcreatore`) VALUES (NULL, '" +chiave+"', '"+metodo+"', '" + Studente.getLoggato().getId() + "')"); q.executeUpdate(); q = db.createQuery("SELECT * FROM `cryptohelper`.`sistemacifratura` ORDER BY id DESC"); QueryResult rs = db.execute(q); From e37d6286291c49e361022c67789a29dcd79a07e0 Mon Sep 17 00:00:00 2001 From: BobCaSUaL Date: Mon, 22 Sep 2014 23:00:55 +0200 Subject: [PATCH 24/45] DSD upload --- .../cd0e9af6-d876-4478-9594-47c5f205ede1.png | 1 + src/DatabaseDUMPS/model.puml | 83 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 src/DatabaseDUMPS/cd0e9af6-d876-4478-9594-47c5f205ede1.png create mode 100644 src/DatabaseDUMPS/model.puml diff --git a/src/DatabaseDUMPS/cd0e9af6-d876-4478-9594-47c5f205ede1.png b/src/DatabaseDUMPS/cd0e9af6-d876-4478-9594-47c5f205ede1.png new file mode 100644 index 0000000..b7738df --- /dev/null +++ b/src/DatabaseDUMPS/cd0e9af6-d876-4478-9594-47c5f205ede1.png @@ -0,0 +1 @@ +GUIcontrollerdbmodelGenericSelectorPopUpViewerCicloDiAnalisiSostituzioneSempliceGUIControllerDbManagerQueryQueryResultMessaggioStudenteUserInfoSpiaSessioneIpotesiStrumentoDiManipolazioneRipristinaIpotesiPrecedenteSostituzioneSempliceStrumentoDiSupportoAnalisiFrequenzeCalcolatoreCesareCalcolatoreParolaChiaveCalcolatorePseudocasualeCifratoreMappaturaPropostaPropostaConfermataSistemaCifraturaMessaggioAstrattoMessaggioDestinatarioMessaggioMittenteCalcolatoreMappatura \ No newline at end of file diff --git a/src/DatabaseDUMPS/model.puml b/src/DatabaseDUMPS/model.puml new file mode 100644 index 0000000..60163d4 --- /dev/null +++ b/src/DatabaseDUMPS/model.puml @@ -0,0 +1,83 @@ +@startuml + +class GUI.GenericSelector +class GUI.PopUpViewer +class GUI.CicloDiAnalisi +class GUI.SostituzioneSempliceGUI +class controller.Controller +class db.DbManager +class db.Query +class db.QueryResult + + +class model.Messaggio +class model.Studente +class model.UserInfo + +class model.Spia +class model.Studente + +class model.Sessione +class model.Ipotesi + +interface model.StrumentoDiManipolazione +class model.RipristinaIpotesiPrecedente +class model.SostituzioneSemplice + +interface model.StrumentoDiSupporto +class model.AnalisiFrequenze + + +class model.CalcolatoreCesare +class model.CalcolatoreParolaChiave +class model.CalcolatorePseudocasuale +class model.Cifratore +class model.Mappatura +class model.Proposta +class model.PropostaConfermata +class model.SistemaCifratura + + +interface model.MessaggioAstratto +interface model.MessaggioDestinatario +interface model.MessaggioMittente + +interface model.CalcolatoreMappatura + +model.Messaggio ..> model.Cifratore +model.Messaggio ..> model.SistemaCifratura + +model.Messaggio --|> model.MessaggioDestinatario +model.Messaggio --|> model.MessaggioMittente + + +model.AnalisiFrequenze --|> model.StrumentoDiSupporto + +model.RipristinaIpotesiPrecedente --|> model.StrumentoDiManipolazione +model.SostituzioneSemplice ..> GUI.SostituzioneSempliceGUI +model.SostituzioneSemplice --|> model.StrumentoDiManipolazione + + +model.Sessione ..> GUI.GenericSelector +model.Sessione ..> GUI.PopUpViewer +model.Sessione ..> GUI.CicloDiAnalisi + +model.Sessione ..> model.Messaggio +model.Sessione ..> model.Studente + +model.Spia --|> model.Studente +model.CalcolatoreCesare --|> model.CalcolatoreMappatura +model.CalcolatoreParolaChiave --|> model.CalcolatoreMappatura +model.CalcolatorePseudocasuale --|> model.CalcolatoreMappatura +model.Proposta ..> controller.Controller +model.Proposta ..> model.UserInfo +model.PropostaConfermata ..> model.UserInfo +model.PropostaConfermata --|> model.Proposta + +model.SistemaCifratura ..> model.Studente +model.SistemaCifratura ..> model.UserInfo +model.MessaggioDestinatario --|> model.MessaggioAstratto +model.MessaggioMittente --|> model.MessaggioAstratto +model.StrumentoDiManipolazione ..> model.Messaggio +model.StrumentoDiSupporto ..> model.Messaggio +@enduml \ No newline at end of file From 6f8c2c4e179b4db10087481f6186376c7baf3100 Mon Sep 17 00:00:00 2001 From: Roberto Date: Mon, 22 Sep 2014 23:50:13 +0200 Subject: [PATCH 25/45] bug fix --- src/GUI/user/Utente_Regolamentare.java | 4 ---- src/model/Studente.java | 8 +------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/GUI/user/Utente_Regolamentare.java b/src/GUI/user/Utente_Regolamentare.java index fe4bbdb..172a769 100644 --- a/src/GUI/user/Utente_Regolamentare.java +++ b/src/GUI/user/Utente_Regolamentare.java @@ -26,10 +26,6 @@ public class Utente_Regolamentare extends javax.swing.JFrame { */ public Utente_Regolamentare() { initComponents(); - /*try{ - Thread.sleep(1000); - } - catch(Exception e){}*/ Proposta[] p = CommunicationController.getProposte(Studente.getLoggato().getId()); if(p.length > 0){ NuoveProposte n = new NuoveProposte(p); diff --git a/src/model/Studente.java b/src/model/Studente.java index 6389669..3057359 100644 --- a/src/model/Studente.java +++ b/src/model/Studente.java @@ -52,13 +52,6 @@ public Studente(String user, String password){ } public boolean login(){ - /*DbManager db = connect(); - System.out.println(login + " " + pwd); - Vector v = db.eseguiQuery("SELECT * FROM user WHERE username = '"+this.login+"' and password = '"+this.pwd+"';"); - if(v.size() <= 0) return false; - String s = ((String[])v.elementAt(0))[0]; - this.id = s; - return true;*/ try{ DbManager db = DbManager.getInstance(); Query q = db.createQuery("SELECT * FROM user WHERE username = ? and password = ?"); @@ -68,6 +61,7 @@ public boolean login(){ QueryResult rs = db.execute(q); if( rs.next() ) { this.id = rs.getString("id"); + this.loggato = new Studente("", "", this.id, this.getLogin(), this.getPwd()); return true; } else { return false; From 7302f2d68991e51006b5919a91c9252ff5a2a386 Mon Sep 17 00:00:00 2001 From: BobCaSUaL Date: Fri, 12 Dec 2014 17:18:47 +0100 Subject: [PATCH 26/45] Debugging and other --- src/GUI/Main.java | 2 +- src/GUI/spia/GestisciSessioneDiLavoro.java | 10 ++- src/GUI/user/LeggiMessaggi.java | 40 +-------- src/GUI/user/NuoveProposte.java | 10 ++- src/GUI/user/NuovoMessaggio.java | 88 +++++++------------- src/GUI/user/PropostaSistemaDiCifratura.java | 58 ++++--------- src/GUI/user/Registrazione.java | 1 - src/GUI/user/Utente_Regolamentare.java | 61 ++++---------- src/controller/Controller.java | 4 +- src/model/Messaggio.java | 6 +- src/model/Studente.java | 10 +-- src/model/UserInfo.java | 4 + src/model/spia/Sessione.java | 13 +-- src/model/spia/Spia.java | 7 +- src/model/user/Proposta.java | 10 +-- src/model/user/PropostaConfermata.java | 4 +- src/model/user/SistemaCifratura.java | 55 +++++------- 17 files changed, 124 insertions(+), 259 deletions(-) diff --git a/src/GUI/Main.java b/src/GUI/Main.java index 7e6759f..56d0100 100644 --- a/src/GUI/Main.java +++ b/src/GUI/Main.java @@ -211,7 +211,7 @@ public void run() { } else { new Thread( new Runnable() { public void run() { - new Utente_Regolamentare().setVisible(true); + new Utente_Regolamentare(s).setVisible(true); } }).start(); } diff --git a/src/GUI/spia/GestisciSessioneDiLavoro.java b/src/GUI/spia/GestisciSessioneDiLavoro.java index 6810674..3b5d464 100644 --- a/src/GUI/spia/GestisciSessioneDiLavoro.java +++ b/src/GUI/spia/GestisciSessioneDiLavoro.java @@ -6,7 +6,10 @@ package GUI.spia; +import GUI.GenericSelector; +import java.util.List; import javax.swing.JFrame; +import model.Messaggio; import model.spia.Sessione; import model.spia.Spia; @@ -93,7 +96,12 @@ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS new Thread( new Runnable() { public void run() { self.setVisible(false); - s.startNewSessione(); + List options = Messaggio.getMessaggi(); + for (Messaggio m : options) { + m.setToStringF("%lingua%, %testoCif%"); + } + Messaggio selectedMsg = GenericSelector.selectOptions(options); + s.startNewSessione( selectedMsg ); self.setVisible(true); } }).start(); diff --git a/src/GUI/user/LeggiMessaggi.java b/src/GUI/user/LeggiMessaggi.java index cf03770..59321f7 100644 --- a/src/GUI/user/LeggiMessaggi.java +++ b/src/GUI/user/LeggiMessaggi.java @@ -8,6 +8,7 @@ import model.Messaggio; import model.MessaggioDestinatario; +import model.Studente; /** * @@ -18,9 +19,9 @@ public class LeggiMessaggi extends javax.swing.JFrame { /** * Creates new form LeggiMessaggi */ - public LeggiMessaggi() { + public LeggiMessaggi( Studente s ) { initComponents(); - MessaggioDestinatario[] l = Messaggio.caricaRicevuti(); + MessaggioDestinatario[] l = Messaggio.caricaRicevuti( s ); jList1.setListData(l); jLabel1.setText("Hai " + l.length + " messaggi da leggere"); } @@ -71,41 +72,6 @@ private void initComponents() { pack(); }// //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(LeggiMessaggi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(LeggiMessaggi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(LeggiMessaggi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(LeggiMessaggi.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 LeggiMessaggi().setVisible(true); - } - }); - } - // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel jLabel1; private javax.swing.JList jList1; diff --git a/src/GUI/user/NuoveProposte.java b/src/GUI/user/NuoveProposte.java index 929da88..a683e56 100644 --- a/src/GUI/user/NuoveProposte.java +++ b/src/GUI/user/NuoveProposte.java @@ -21,9 +21,11 @@ public class NuoveProposte extends javax.swing.JFrame { /** * Creates new form PropostePendenti */ - public NuoveProposte(Proposta[] p) { + public NuoveProposte(Studente s, Proposta[] p) { initComponents(); jList1.setListData(p); + + this.studente = s; } /** @@ -106,7 +108,7 @@ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS Proposta p = (Proposta)jList1.getSelectedValue(); if(p != null){ CommunicationController.inviaDecisione(p, "accettata"); - Proposta[] nuovo = CommunicationController.getProposte(Studente.getLoggato().getId()); + Proposta[] nuovo = CommunicationController.getProposte(this.studente.getId()); jList1.setListData(nuovo); } }//GEN-LAST:event_jButton1ActionPerformed @@ -116,7 +118,7 @@ private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS Proposta p = (Proposta)jList1.getSelectedValue(); if(p != null){ CommunicationController.inviaDecisione(p, "rifiutata"); - Proposta[] nuovo = CommunicationController.getProposte(Studente.getLoggato().getId()); + Proposta[] nuovo = CommunicationController.getProposte(this.studente.getId()); jList1.setListData(nuovo); } }//GEN-LAST:event_jButton2ActionPerformed @@ -156,6 +158,8 @@ public void run() { }); } + private Studente studente; + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; diff --git a/src/GUI/user/NuovoMessaggio.java b/src/GUI/user/NuovoMessaggio.java index 3b1d676..8ef1055 100644 --- a/src/GUI/user/NuovoMessaggio.java +++ b/src/GUI/user/NuovoMessaggio.java @@ -9,26 +9,34 @@ import model.user.PropostaConfermata; import controller.CommunicationController; import model.*; -import controller.Controller; +import model.user.SistemaCifratura; /** * * @author MASTER */ public class NuovoMessaggio extends javax.swing.JFrame { - private PropostaConfermata[] a = CommunicationController.getProposteAccettate(Studente.getLoggato().getId()); - private int index; - private Messaggio m = null; + + /** + * Elenco di tutte le proposte inviate + */ + private PropostaConfermata[] proposte; + + /* L'oggetto studente, ovvero l'utente loggato */ + private Studente studente; + /** * Creates new form NuovoMessaggio */ - public NuovoMessaggio() { + public NuovoMessaggio( Studente s ) { initComponents(); - m.setMittente(new UserInfo(Studente.getLoggato().getId())); - //a = CommunicationController.getProposteAccettate(Session.getIdLoggedUser()); - int[] id_list = new int[a.length]; + + this.studente = s; + + this.proposte = CommunicationController.getProposteAccettate(this.studente.getId()); + int[] id_list = new int[proposte.length]; for(int i=0; i - /* 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(NuovoMessaggio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(NuovoMessaggio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(NuovoMessaggio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(NuovoMessaggio.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 NuovoMessaggio().setVisible(true); - } - }); - } - // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; diff --git a/src/GUI/user/PropostaSistemaDiCifratura.java b/src/GUI/user/PropostaSistemaDiCifratura.java index 37c53f0..c242563 100644 --- a/src/GUI/user/PropostaSistemaDiCifratura.java +++ b/src/GUI/user/PropostaSistemaDiCifratura.java @@ -26,11 +26,14 @@ public class PropostaSistemaDiCifratura extends javax.swing.JFrame { private Proposta p; /** * Creates new form NuovoMessaggio + * @param s */ - public PropostaSistemaDiCifratura() { + public PropostaSistemaDiCifratura( Studente s ) { initComponents(); - UserInfo[] s = Controller.recuperaUtenti(); - jList2.setListData(s); + UserInfo[] ui = Controller.recuperaUtenti( s ); + jList2.setListData(ui); + + this.studente = s; } /** @@ -171,11 +174,14 @@ private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI }//GEN-LAST:event_jComboBox1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed - // TODO add your handling code here: - //System.out.println(UserInfo.getLoggedUser()); - //System.out.println("E così tu, " + UserInfo.getLoggedUser() + ", vorresti mandare a " + (jList2.getSelectedValue()).toString() + "un messaggio usando " +(String)jComboBox1.getSelectedItem() + ", giusto?? bravoooo!!"); - SistemaCifratura s = new SistemaCifratura(jTextField1.getText(), (String)jComboBox1.getSelectedItem()); - boolean b = CommunicationController.inviaProposta(Studente.getLoggato().getId(), ((Studente)jList2.getSelectedValue()).getId(), s); + + SistemaCifratura sdc = new SistemaCifratura(jTextField1.getText(), (String)jComboBox1.getSelectedItem()); + UserInfo creatore = new UserInfo( this.studente.getId(), this.studente.getLogin() ); + sdc.setCreatore( creatore ); + + sdc.save(); + + boolean b = CommunicationController.inviaProposta(this.studente.getId(), ((UserInfo)jList2.getSelectedValue()).getId(), sdc); System.out.println(b); }//GEN-LAST:event_jButton2ActionPerformed @@ -183,40 +189,8 @@ private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F // TODO add your handling code here: }//GEN-LAST:event_jTextField1ActionPerformed - /** - * @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(PropostaSistemaDiCifratura.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(PropostaSistemaDiCifratura.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(PropostaSistemaDiCifratura.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(PropostaSistemaDiCifratura.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 PropostaSistemaDiCifratura().setVisible(true); - } - }); - } + + private Studente studente; // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton2; diff --git a/src/GUI/user/Registrazione.java b/src/GUI/user/Registrazione.java index a45a750..9892c2b 100644 --- a/src/GUI/user/Registrazione.java +++ b/src/GUI/user/Registrazione.java @@ -6,7 +6,6 @@ package GUI.user; -import controller.Controller; import model.Studente; /** diff --git a/src/GUI/user/Utente_Regolamentare.java b/src/GUI/user/Utente_Regolamentare.java index fe4bbdb..8d50bef 100644 --- a/src/GUI/user/Utente_Regolamentare.java +++ b/src/GUI/user/Utente_Regolamentare.java @@ -10,7 +10,6 @@ /*import Clmodelession; import ClasmodelrInfo;*/ import controller.CommunicationController; -import java.awt.List; import model.Messaggio; import model.MessaggioDestinatario; import model.Studente; @@ -24,19 +23,19 @@ public class Utente_Regolamentare extends javax.swing.JFrame { /** * Creates new form Mittente */ - public Utente_Regolamentare() { + public Utente_Regolamentare( Studente s ) { initComponents(); - /*try{ - Thread.sleep(1000); - } - catch(Exception e){}*/ - Proposta[] p = CommunicationController.getProposte(Studente.getLoggato().getId()); - if(p.length > 0){ - NuoveProposte n = new NuoveProposte(p); + this.studente = s; + + /* E' parte di interfaccia: popup per le nuove proposte */ + Proposta[] p = CommunicationController.getProposte(s.getId()); + if(p.length > 0) { + NuoveProposte n = new NuoveProposte( this.studente, p ); n.setVisible(true); } - - MessaggioDestinatario[] l = Messaggio.caricaRicevuti(); + + /* Controllo di interfaccia: se ci sono messaggi si possono leggere */ + MessaggioDestinatario[] l = Messaggio.caricaRicevuti( this.studente ); if(l.length > 0) jButton3.setText("Leggi Messaggi (" + l.length + ")"); } @@ -106,7 +105,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: - new NuovoMessaggio().setVisible(true); + new NuovoMessaggio( this.studente ).setVisible(true); }//GEN-LAST:event_jButton1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed @@ -115,44 +114,12 @@ private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed // TODO add your handling code here: - new LeggiMessaggi().setVisible(true); + new LeggiMessaggi( this.studente ).setVisible(true); }//GEN-LAST:event_jButton3ActionPerformed - /** - * @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(Utente_Regolamentare.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(Utente_Regolamentare.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(Utente_Regolamentare.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(Utente_Regolamentare.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 Utente_Regolamentare().setVisible(true); - } - }); - } + private Studente studente; + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; diff --git a/src/controller/Controller.java b/src/controller/Controller.java index 724cfd9..ca8bd33 100644 --- a/src/controller/Controller.java +++ b/src/controller/Controller.java @@ -91,11 +91,11 @@ public static boolean rifiutaProposta(Proposta p){ - public static UserInfo[] recuperaUtenti(){ + public static UserInfo[] recuperaUtenti( Studente s ){ ArrayList result = new ArrayList<>(); try{ DbManager db = DbManager.getInstance(); - Query q = db.createQuery("SELECT * FROM user where username <> '" + Studente.getLoggato().getId() + "'"); + Query q = db.createQuery("SELECT * FROM user where username <> '" + s.getId() + "'"); QueryResult rs = db.execute( q ); while( rs.next() ) { String id = rs.getString(1); diff --git a/src/model/Messaggio.java b/src/model/Messaggio.java index 8fb695a..31ae9b7 100644 --- a/src/model/Messaggio.java +++ b/src/model/Messaggio.java @@ -102,11 +102,11 @@ public static List getMessaggi(){ return result; } - public static MessaggioDestinatario[] caricaRicevuti(){ + public static MessaggioDestinatario[] caricaRicevuti( Studente s ){ ArrayList result = new ArrayList<>(); try{ DbManager db = DbManager.getInstance(); - Query q = db.createQuery("SELECT * FROM `messaggio` WHERE id_destinatario = " + Studente.getLoggato().getId()); + Query q = db.createQuery("SELECT * FROM `messaggio` WHERE id_destinatario = " + s.getId()); QueryResult rs = db.execute(q); while( rs.next() ){ UserInfo mittente = new UserInfo(rs.getString(2)); @@ -142,7 +142,7 @@ public boolean isBozza(){ public boolean save(){ try{ DbManager db = DbManager.getInstance(); - Query q = db.createQuery("INSERT INTO `cryptohelper`.`messaggio` (`id`, `id_mittente`, `id_destinatario`, `testo`, `testoCifrato`, `lingua`, `titolo`, `bozza`, `letto`) VALUES (NULL, '" +this.getMittente().getId()+"', '"+this.getDestinatario().getId()+"', '" + this.getTesto() + "', '" + this.getTestoCifrato() + "' , '" + this.getLingua() + "', 'titoloDiProva', " + this.isBozza() + ", false);"); + Query q = db.createQuery("INSERT INTO `cryptohelper`.`messaggio` (`id`, `id_mittente`, `id_destinatario`, `testo`, `testoCifrato`, `lingua`, `titolo`, `bozza`, `letto`, `idsistemacifratura`) VALUES (NULL, '" +this.getMittente().getId()+"', '"+this.getDestinatario().getId()+"', '" + this.getTesto() + "', '" + this.getTestoCifrato() + "' , '" + this.getLingua() + "', 'titoloDiProva', " + this.isBozza() + ", false, "+this.getSdc().getId()+");"); q.executeUpdate(); } catch (SQLException ex){ diff --git a/src/model/Studente.java b/src/model/Studente.java index 6389669..7327075 100644 --- a/src/model/Studente.java +++ b/src/model/Studente.java @@ -17,15 +17,6 @@ * @author MASTER */ public class Studente { - - private static Studente loggato = null; - - public static void setLoggato( Studente s ) { - loggato = s; - } - public static Studente getLoggato() { - return loggato; - } private String nome; private String cognome; @@ -141,4 +132,5 @@ public String getPwd() { public DbManager getDbManager0() { return DbManager0; } + } diff --git a/src/model/UserInfo.java b/src/model/UserInfo.java index 028298f..ed5c6a1 100644 --- a/src/model/UserInfo.java +++ b/src/model/UserInfo.java @@ -52,4 +52,8 @@ public UserInfo(String id, String user){ public String getId(){ return this.id; } + + public String toString() { + return this.username; + } } diff --git a/src/model/spia/Sessione.java b/src/model/spia/Sessione.java index bd60f93..cb4a25d 100644 --- a/src/model/spia/Sessione.java +++ b/src/model/spia/Sessione.java @@ -29,7 +29,7 @@ * @author user */ public class Sessione extends Observable implements Serializable { - + public static class Properties extends java.util.Hashtable { } @@ -83,17 +83,6 @@ public static Sessione recuperaSessione(Spia owner) throws SQLException { return result; } - public static Sessione startNewSessione( Spia owner ) { - List options = Messaggio.getMessaggi(); - for (Messaggio m : options) { - m.setToStringF("%lingua%, %testoCif%"); - } - Messaggio selectedMsg = GenericSelector.selectOptions(options); - Sessione s = new Sessione(owner, selectedMsg); - s.start(); - return s; - } - public static Sessione restoreSessione(Sessione s) { s.start(); return s; diff --git a/src/model/spia/Spia.java b/src/model/spia/Spia.java index 5292eeb..619d5fa 100644 --- a/src/model/spia/Spia.java +++ b/src/model/spia/Spia.java @@ -6,7 +6,9 @@ * and open the template in the editor. */ +import GUI.GenericSelector; import java.sql.SQLException; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import model.*; @@ -27,8 +29,9 @@ public Spia(String nome, String cognome, String id, String user, String password super( nome, cognome, id, user, password ); } - public Sessione startNewSessione() { - Sessione s = Sessione.startNewSessione( this ); + public Sessione startNewSessione( Messaggio selectedMsg ) { + Sessione s = new Sessione(this, selectedMsg); + s.start(); return s; } diff --git a/src/model/user/Proposta.java b/src/model/user/Proposta.java index 54d4caa..4399447 100644 --- a/src/model/user/Proposta.java +++ b/src/model/user/Proposta.java @@ -23,14 +23,14 @@ public class Proposta { protected int id; protected UserInfo proponente, partner; protected String stato; - protected SistemaCifratura s; + protected SistemaCifratura sdc; protected boolean notificata; public Proposta(int id, UserInfo proponente, UserInfo partner, SistemaCifratura sdc){ this.id = id; this.proponente = proponente; this.partner = partner; - this.s = sdc; + this.sdc = sdc; this.stato = "in attesa"; } @@ -39,7 +39,7 @@ public Proposta(){ } public SistemaCifratura getSdc(){ - return this.s; + return this.sdc; } public UserInfo getPartner(){ @@ -57,7 +57,7 @@ public boolean save(){ return true;*/ try{ DbManager db = DbManager.getInstance(); - Query q = db.createQuery("INSERT INTO `cryptohelper`.`proposta` (`id`, `id_mittente`, `id_destinatario`, `idsistemacifratura`, `stato`, `notificata`) VALUES (NULL, '" +this.proponente.getId()+"', '"+this.partner.getId()+"', '" + Integer.parseInt(this.s.getId()) + "', 'in attesa', NULL);"); + Query q = db.createQuery("INSERT INTO `cryptohelper`.`proposta` (`id`, `id_mittente`, `id_destinatario`, `idsistemacifratura`, `stato`, `notificata`) VALUES (NULL, '" +this.proponente.getId()+"', '"+this.partner.getId()+"', '" + Integer.parseInt(this.sdc.getId()) + "', 'in attesa', NULL);"); q.executeUpdate(); } catch (SQLException ex){ @@ -91,7 +91,7 @@ public int getId(){ }*/ public String toString(){ - return "Utente con id " + proponente.getId() + " vuole scambiare un messaggio utilizzando " + s.getSdc(); + return "Utente con id " + proponente.getId() + " vuole scambiare un messaggio utilizzando " + sdc.getSdc(); } } diff --git a/src/model/user/PropostaConfermata.java b/src/model/user/PropostaConfermata.java index 7812eb1..3ac226e 100644 --- a/src/model/user/PropostaConfermata.java +++ b/src/model/user/PropostaConfermata.java @@ -18,12 +18,12 @@ public PropostaConfermata(int id, UserInfo proponente, UserInfo partner, Sistema this.id = id; this.proponente = proponente; this.partner = partner; - this.s = sdc; + this.sdc = sdc; this.stato = "in attesa"; } public String toString(){ - return "Invia messaggio a " + this.partner.getId() + " utilizzando " + this.s.getSdc(); + return "Invia messaggio a " + this.partner.getId() + " utilizzando " + this.sdc.getSdc(); } } diff --git a/src/model/user/SistemaCifratura.java b/src/model/user/SistemaCifratura.java index af68f2e..ea217f3 100644 --- a/src/model/user/SistemaCifratura.java +++ b/src/model/user/SistemaCifratura.java @@ -29,26 +29,19 @@ public class SistemaCifratura { private Mappatura m; public String toString(){ - return "Sistema di cifratura: creato da " + creatore.getId() + ", cifratura con " + metodo + " e chiave " + chiave; + return "Sistema di cifratura: creato da " + creatore.getId() + ", cifratura con " + this.metodo + " e chiave " + this.chiave; } public static void caricaSistemaCifratura(Studente s){ - + /** TODO **/ } public Mappatura getMappatura(){ return this.m; } - /*public static SistemaCifratura load(String user1, String user2){ - - return new SistemaCifratura(); - }*/ public static SistemaCifratura load(String id){ - /*DbManager db = connect(); - Vector v = db.eseguiQuery("SELECT * FROM `cryptohelper`.`sistemacifratura` WHERE id = '" + id + "'"); - return new SistemaCifratura(((String[])v.elementAt(0))[0], ((String[])v.elementAt(0))[1], ((String[])v.elementAt(0))[2], new UserInfo(((String[])v.elementAt(0))[3]));*/ try{ DbManager db = DbManager.getInstance(); Query q = db.createQuery("SELECT * FROM `cryptohelper`.`sistemacifratura` WHERE id = '" + id + "'"); @@ -71,6 +64,11 @@ public String getSdc(){ public String getId(){ return this.id; } + public void setCreatore( UserInfo creatore ) { + this.creatore = creatore; + } + + public SistemaCifratura(String id, String chiave, String metodo){ this.id = id; this.chiave = chiave; @@ -87,32 +85,6 @@ public SistemaCifratura(String id, String chiave, String metodo, UserInfo creato public SistemaCifratura(String chiave, String metodo){ this.chiave = chiave; this.metodo = metodo; - this.creatore = new UserInfo(Studente.getLoggato().getId()); - try{ - DbManager db = DbManager.getInstance(); - Query q = db.createQuery("INSERT INTO `cryptohelper`.`sistemacifratura` (`id`, `chiave`, `metodo`, `idcreatore`) VALUES (NULL, '" +chiave+"', '"+metodo+"', '" + Studente.getLoggato().getId() + "')"); - q.executeUpdate(); - q = db.createQuery("SELECT * FROM `cryptohelper`.`sistemacifratura` ORDER BY id DESC"); - QueryResult rs = db.execute(q); - rs.next(); - this.id = rs.getInt(1) + ""; - } - catch(SQLException ex){ - throw new RuntimeException( ex.getMessage(), ex ); - } - /*DbManager db = connect(); - System.out.println("INSERT INTO `cryptohelper`.`sistemacifratura` (`id`, `chiave`, `metodo`, `idcreatore`) VALUES (NULL, '" +chiave+"', '"+metodo+"', '" + Session.getIdLoggedUser() + "')"); - if (!db.eseguiAggiornamento("INSERT INTO `cryptohelper`.`sistemacifratura` (`id`, `chiave`, `metodo`, `idcreatore`) VALUES (NULL, '" +chiave+"', '"+metodo+"', '" + Session.getIdLoggedUser() + "')")) { - System.out.println("Errore nell'aggiornamento!"); - System.out.println(db.getErrore()); - } - Vector v = db.eseguiQuery("SELECT * FROM `cryptohelper`.`sistemacifratura` ORDER BY id DESC"); - this.id = (((String[])v.elementAt(0))[0]); - */ - } - - public SistemaCifratura(){ - /*query result*/ } public String prova(String testo){ @@ -138,6 +110,17 @@ public void calcolaMappatura(){ } public void save(){ - + try{ + DbManager db = DbManager.getInstance(); + Query q = db.createQuery("INSERT INTO `cryptohelper`.`sistemacifratura` (`id`, `chiave`, `metodo`, `idcreatore`) VALUES (NULL, '" +chiave+"', '"+metodo+"', '" + creatore.getId() + "')"); + q.executeUpdate(); + q = db.createQuery("SELECT * FROM `cryptohelper`.`sistemacifratura` ORDER BY id DESC"); + QueryResult rs = db.execute(q); + rs.next(); + this.id = rs.getInt(1) + ""; + } + catch(SQLException ex){ + throw new RuntimeException( ex.getMessage(), ex ); + } } } From 64bda2fa009b38bc11740207ad197f7659e66f89 Mon Sep 17 00:00:00 2001 From: BobCaSUaL Date: Fri, 12 Dec 2014 17:31:52 +0100 Subject: [PATCH 27/45] Merge origin/GUI_analisi_sessione into GUI_analisi_sessione Conflicts: src/GUI/user/Utente_Regolamentare.java --- src/model/Studente.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/model/Studente.java b/src/model/Studente.java index ed9a0cd..547ffc0 100644 --- a/src/model/Studente.java +++ b/src/model/Studente.java @@ -52,8 +52,7 @@ public boolean login(){ QueryResult rs = db.execute(q); if( rs.next() ) { this.id = rs.getString("id"); - this.loggato = new Studente("", "", this.id, this.getLogin(), this.getPwd()); - return true; + return true; } else { return false; } From 7fcdc202ba1cbf82bb7ac324c9f7f9ead198c043 Mon Sep 17 00:00:00 2001 From: Roberto Date: Sat, 13 Dec 2014 22:44:12 +0100 Subject: [PATCH 28/45] =?UTF-8?q?Ora=20=C3=A8=20possibile=20salvare=20i=20?= =?UTF-8?q?messaggi=20come=20bozza=20ed=20inviarli=20in=20un=20secondo=20m?= =?UTF-8?q?omento.=20Modifiche=20effettuate=20principalmente=20alla=20clas?= =?UTF-8?q?se=20Messaggio=20ed=20all'interfaccia=20Nuovo=20Messaggio.=20Ag?= =?UTF-8?q?giunta=20interfaccia=20ApriMessaggioPrecedente?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nbproject/project.properties | 3 +- src/GUI/user/ApriMessaggioPrecedente.form | 94 +++++++++++ src/GUI/user/ApriMessaggioPrecedente.java | 138 ++++++++++++++++ src/GUI/user/NuovoMessaggio.form | 18 ++- src/GUI/user/NuovoMessaggio.java | 117 ++++++++++---- src/GUI/user/Utente_Regolamentare.java | 5 +- src/db/DbManager.java | 4 +- src/model/Messaggio.java | 187 ++++++++++++--------- test/model/spia/SessioneTest.java | 188 ++++++++++++++++++++++ 9 files changed, 646 insertions(+), 108 deletions(-) create mode 100644 src/GUI/user/ApriMessaggioPrecedente.form create mode 100644 src/GUI/user/ApriMessaggioPrecedente.java create mode 100644 test/model/spia/SessioneTest.java diff --git a/nbproject/project.properties b/nbproject/project.properties index 32e63c5..9cfa4d8 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -42,7 +42,8 @@ javac.source=1.7 javac.target=1.7 javac.test.classpath=\ ${javac.classpath}:\ - ${build.classes.dir} + ${build.classes.dir}:\ + ${libs.junit_4.classpath} javac.test.processorpath=\ ${javac.test.classpath} javadoc.additionalparam= diff --git a/src/GUI/user/ApriMessaggioPrecedente.form b/src/GUI/user/ApriMessaggioPrecedente.form new file mode 100644 index 0000000..d93e0e5 --- /dev/null +++ b/src/GUI/user/ApriMessaggioPrecedente.form @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/GUI/user/ApriMessaggioPrecedente.java b/src/GUI/user/ApriMessaggioPrecedente.java new file mode 100644 index 0000000..acef74a --- /dev/null +++ b/src/GUI/user/ApriMessaggioPrecedente.java @@ -0,0 +1,138 @@ +/* + * 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 GUI.user; + +import model.Messaggio; +import model.Studente; + +/** + * + * @author MASTER + */ +public class ApriMessaggioPrecedente extends javax.swing.JFrame { + + /** + * Creates new form ApriMessaggioPrecedente + */ + public ApriMessaggioPrecedente(Studente s) { + initComponents(); + Messaggio[] l = Messaggio.caricaBozze(s); + jList1.setListData(l); + } + + /** + * 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() { + + jScrollPane1 = new javax.swing.JScrollPane(); + jList1 = new javax.swing.JList(); + jLabel1 = new javax.swing.JLabel(); + jButton1 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jList1.setModel(new javax.swing.AbstractListModel() { + String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; + public int getSize() { return strings.length; } + public Object getElementAt(int i) { return strings[i]; } + }); + jScrollPane1.setViewportView(jList1); + + jLabel1.setText("Seleziona Bozza"); + + jButton1.setText("Avanti"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(349, 349, 349) + .addComponent(jLabel1) + .addContainerGap(429, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1) + .addContainerGap()) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(42, 42, 42)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(19, 19, 19) + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(22, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + // TODO add your handling code here: + Messaggio m = (Messaggio)jList1.getSelectedValue(); + new NuovoMessaggio(null, m).setVisible(true); + }//GEN-LAST:event_jButton1ActionPerformed + + /** + * @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(ApriMessaggioPrecedente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(ApriMessaggioPrecedente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(ApriMessaggioPrecedente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(ApriMessaggioPrecedente.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 ApriMessaggioPrecedente().setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JLabel jLabel1; + private javax.swing.JList jList1; + private javax.swing.JScrollPane jScrollPane1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/GUI/user/NuovoMessaggio.form b/src/GUI/user/NuovoMessaggio.form index d01ce62..62f5412 100644 --- a/src/GUI/user/NuovoMessaggio.form +++ b/src/GUI/user/NuovoMessaggio.form @@ -52,6 +52,8 @@ + + @@ -84,7 +86,10 @@ - + + + + @@ -125,6 +130,9 @@ + + + @@ -150,5 +158,13 @@ + + + + + + + + diff --git a/src/GUI/user/NuovoMessaggio.java b/src/GUI/user/NuovoMessaggio.java index 8ef1055..6b22dc8 100644 --- a/src/GUI/user/NuovoMessaggio.java +++ b/src/GUI/user/NuovoMessaggio.java @@ -3,7 +3,6 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ - package GUI.user; import model.user.PropostaConfermata; @@ -16,30 +15,39 @@ * @author MASTER */ public class NuovoMessaggio extends javax.swing.JFrame { - + /** * Elenco di tutte le proposte inviate */ private PropostaConfermata[] proposte; - + /* L'oggetto studente, ovvero l'utente loggato */ private Studente studente; - + private Messaggio restore; + /** * Creates new form NuovoMessaggio */ - public NuovoMessaggio( Studente s ) { + public NuovoMessaggio(Studente s, Messaggio r) { initComponents(); - - this.studente = s; - - this.proposte = CommunicationController.getProposteAccettate(this.studente.getId()); - int[] id_list = new int[proposte.length]; - for(int i=0; i caricaIniviati(Studente s){ + + public static List caricaIniviati(Studente s) { return null; } - - public static List caricaBozze(Studente s){ - return null; + + public static Messaggio[] caricaBozze(Studente s) { + Messaggio temp; + ArrayList result = new ArrayList<>(); + try { + DbManager db = DbManager.getInstance(); + Query q = db.createQuery("SELECT * FROM `messaggio` WHERE id_mittente = " + s.getId() + " && bozza = '1'"); + QueryResult rs = db.execute(q); + while (rs.next()) { + UserInfo mittente = new UserInfo(rs.getString(2)); + UserInfo destinatario = new UserInfo(rs.getString(3)); + String testo = rs.getString(4); + String lingua = rs.getString(6); + String sdc = rs.getString(10); + temp = new Messaggio(testo, lingua, mittente, destinatario, SistemaCifratura.load(sdc)); + temp.setBozza(true); + temp.setId(Integer.parseInt(rs.getString(1))); + result.add(temp); + } + } catch (SQLException ex) { + throw new RuntimeException(ex.getMessage(), ex); + } + return result.toArray(new Messaggio[result.size()]); } - - public static List getMessaggi(){ + + public static List getMessaggi() { ArrayList result = new ArrayList<>(); - try{ + try { DbManager db = DbManager.getInstance(); Query q = db.createQuery("SELECT * FROM `cryptohelper`.`messaggio`"); QueryResult rs = db.execute(q); - while( rs.next() ){ - - result.add( new Messaggio(rs) ); + while (rs.next()) { + + result.add(new Messaggio(rs)); } - } - catch (SQLException ex){ - throw new RuntimeException( ex.getMessage(), ex ); + } catch (SQLException ex) { + throw new RuntimeException(ex.getMessage(), ex); } return result; } - - public static MessaggioDestinatario[] caricaRicevuti( Studente s ){ + + public static MessaggioDestinatario[] caricaRicevuti(Studente s) { ArrayList result = new ArrayList<>(); - try{ + try { DbManager db = DbManager.getInstance(); - Query q = db.createQuery("SELECT * FROM `messaggio` WHERE id_destinatario = " + s.getId()); + Query q = db.createQuery("SELECT * FROM `messaggio` WHERE id_destinatario = " + s.getId() + " && bozza = '0'"); QueryResult rs = db.execute(q); - while( rs.next() ){ + while (rs.next()) { UserInfo mittente = new UserInfo(rs.getString(2)); UserInfo destinatario = new UserInfo(rs.getString(3)); String testo = rs.getString(4); String lingua = rs.getString(6); result.add(new Messaggio(testo, lingua, mittente, destinatario)); } + } catch (SQLException ex) { + throw new RuntimeException(ex.getMessage(), ex); } - catch (SQLException ex){ - throw new RuntimeException( ex.getMessage(), ex ); - } - return result.toArray( new MessaggioDestinatario[result.size()] ); + return result.toArray(new MessaggioDestinatario[result.size()]); } - - public boolean elimina(){ + + public boolean elimina() { + try { + DbManager db = DbManager.getInstance(); + System.out.println(this.id); + Query q = db.createQuery("DELETE FROM `cryptohelper`.`messaggio` WHERE `messaggio`.`id` = " + this.id + ";"); + q.executeUpdate(); + System.out.println("eliminato"); + } catch (SQLException ex) { + throw new RuntimeException(ex.getMessage(), ex); + } return true; } - - public void setBozza(boolean b){ + + public void setBozza(boolean b) { this.bozza = b; } - - public void cifra(){ + + public void cifra() { this.getSdc().calcolaMappatura(); //sdc ha ora un oggetto mappatura - this.testoCifrato = Cifratore.cifra(this.getTesto(), this.getSdc().getMappatura()); + this.testoCifrato = Cifratore.cifra(this.getTesto(), this.getSdc().getMappatura()); } - - public boolean isBozza(){ - return true; + + public boolean isBozza() { + return this.bozza; } - - public boolean save(){ - try{ + + public boolean save() { + try { DbManager db = DbManager.getInstance(); - Query q = db.createQuery("INSERT INTO `cryptohelper`.`messaggio` (`id`, `id_mittente`, `id_destinatario`, `testo`, `testoCifrato`, `lingua`, `titolo`, `bozza`, `letto`, `idsistemacifratura`) VALUES (NULL, '" +this.getMittente().getId()+"', '"+this.getDestinatario().getId()+"', '" + this.getTesto() + "', '" + this.getTestoCifrato() + "' , '" + this.getLingua() + "', 'titoloDiProva', " + this.isBozza() + ", false, "+this.getSdc().getId()+");"); + Query q = db.createQuery("INSERT INTO `cryptohelper`.`messaggio` (`id`, `id_mittente`, `id_destinatario`, `testo`, `testoCifrato`, `lingua`, `titolo`, `bozza`, `letto`, `idsistemacifratura`) VALUES (NULL, '" + this.getMittente().getId() + "', '" + this.getDestinatario().getId() + "', '" + this.getTesto() + "', '" + this.getTestoCifrato() + "' , '" + this.getLingua() + "', 'titoloDiProva', " + this.isBozza() + ", false, " + this.getSdc().getId() + ");"); q.executeUpdate(); - } - catch (SQLException ex){ - throw new RuntimeException( ex.getMessage(), ex ); + } catch (SQLException ex) { + throw new RuntimeException(ex.getMessage(), ex); } return true; } - - public boolean isLetto(){ + + public boolean isLetto() { return true; } - - private String toStringF = "Messaggio in lingua: %lingua% inviato da utente con id %mittenteID% ad utente con id %destinatario% e testo: %testo%"; - public String setToStringF( String f ) { + + private String toStringF = "Messaggio in lingua: %lingua% inviato da utente con id %mittenteID% ad utente con id %destinatarioID% e testo: %testo%"; + + public String setToStringF(String f) { String result = getToStringF(); this.toStringF = f; return result; } - public String toString(){ + + public String toString() { String result = getToStringF(); result = result.replaceAll("%lingua%", getLingua()); result = result.replaceAll("%mittenteID%", getMittente().getId()); result = result.replaceAll("%destinatarioID%", getDestinatario().getId()); result = result.replaceAll("%testo%", getTesto()); result = result.replaceAll("%testoCif%", getTestoCifrato()); - return result; + return result; } - - public boolean send(){ - this.setBozza(false); - this.save(); - return true; + + public boolean send() { + if (this.isBozza()) { //se il messaggio era una bozza + System.out.println("era una bozza"); + this.setBozza(false); + this.save(); //salva il messaggio + this.elimina(); //elimina la bozza + return true; + } else { + System.out.println("non era una bozza"); + this.save(); + return true; + } + } /** @@ -232,5 +269,9 @@ public String getTitolo() { public String getToStringF() { return toStringF; } - + + private void setId(int id) { + this.id = id; + } + } diff --git a/test/model/spia/SessioneTest.java b/test/model/spia/SessioneTest.java new file mode 100644 index 0000000..721c1c1 --- /dev/null +++ b/test/model/spia/SessioneTest.java @@ -0,0 +1,188 @@ +/* + * 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 model.spia; + +import model.Messaggio; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author MASTER + */ +public class SessioneTest { + + public SessioneTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of recuperaSessione method, of class Sessione. + */ + @Test + public void testRecuperaSessione() throws Exception { + System.out.println("recuperaSessione"); + Spia owner = null; + Sessione expResult = null; + Sessione result = Sessione.recuperaSessione(owner); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of startNewSessione method, of class Sessione. + */ + @Test + public void testStartNewSessione() { + System.out.println("startNewSessione"); + Spia owner = null; + Sessione expResult = null; + Sessione result = Sessione.startNewSessione(owner); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of restoreSessione method, of class Sessione. + */ + @Test + public void testRestoreSessione() { + System.out.println("restoreSessione"); + Sessione s = null; + Sessione expResult = null; + Sessione result = Sessione.restoreSessione(s); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of deleteSessione method, of class Sessione. + */ + @Test + public void testDeleteSessione() { + System.out.println("deleteSessione"); + Sessione sessione = null; + Sessione.deleteSessione(sessione); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of saveSessione method, of class Sessione. + */ + @Test + public void testSaveSessione() { + System.out.println("saveSessione"); + Sessione sessione = null; + Sessione.saveSessione(sessione); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of getIpotesiRadice method, of class Sessione. + */ + @Test + public void testGetIpotesiRadice() { + System.out.println("getIpotesiRadice"); + Sessione instance = null; + Ipotesi expResult = null; + Ipotesi result = instance.getIpotesiRadice(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of getIpotesiCorrente method, of class Sessione. + */ + @Test + public void testGetIpotesiCorrente() { + System.out.println("getIpotesiCorrente"); + Sessione instance = null; + Ipotesi expResult = null; + Ipotesi result = instance.getIpotesiCorrente(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of setIpotesiCorrente method, of class Sessione. + */ + @Test + public void testSetIpotesiCorrente() { + System.out.println("setIpotesiCorrente"); + Ipotesi ip = null; + Sessione instance = null; + instance.setIpotesiCorrente(ip); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of getMessaggio method, of class Sessione. + */ + @Test + public void testGetMessaggio() { + System.out.println("getMessaggio"); + Sessione instance = null; + Messaggio expResult = null; + Messaggio result = instance.getMessaggio(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of add method, of class Sessione. + */ + @Test + public void testAdd() { + System.out.println("add"); + Ipotesi nuova = null; + Sessione instance = null; + instance.add(nuova); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of start method, of class Sessione. + */ + @Test + public void testStart() { + System.out.println("start"); + Sessione instance = null; + instance.start(); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + +} From 6ccfc810264278a6e4ac0139b58aa8a9d36e1569 Mon Sep 17 00:00:00 2001 From: Roberto Date: Sat, 13 Dec 2014 23:43:10 +0100 Subject: [PATCH 29/45] Aggiunta interfaccia DettagliMessaggio, per leggere completamente il messaggio ricevuto selezionato (da migliorare) --- src/GUI/user/DettagliMessaggio.form | 75 +++++++++++++++++ src/GUI/user/DettagliMessaggio.java | 123 ++++++++++++++++++++++++++++ src/GUI/user/LeggiMessaggi.form | 17 +++- src/GUI/user/LeggiMessaggi.java | 24 +++++- 4 files changed, 237 insertions(+), 2 deletions(-) create mode 100644 src/GUI/user/DettagliMessaggio.form create mode 100644 src/GUI/user/DettagliMessaggio.java diff --git a/src/GUI/user/DettagliMessaggio.form b/src/GUI/user/DettagliMessaggio.form new file mode 100644 index 0000000..8f698ea --- /dev/null +++ b/src/GUI/user/DettagliMessaggio.form @@ -0,0 +1,75 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/user/DettagliMessaggio.java b/src/GUI/user/DettagliMessaggio.java new file mode 100644 index 0000000..e026691 --- /dev/null +++ b/src/GUI/user/DettagliMessaggio.java @@ -0,0 +1,123 @@ +/* + * 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 GUI.user; + +import model.Messaggio; +import model.MessaggioDestinatario; + +/** + * + * @author MASTER + */ +public class DettagliMessaggio extends javax.swing.JFrame { + + /** + * Creates new form DettagliMessaggio + */ + public DettagliMessaggio(MessaggioDestinatario m) { + initComponents(); + jTextArea1.setText(m.getTesto()); + jTextArea1.disable(); + } + + /** + * 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() { + + jButton1 = new javax.swing.JButton(); + jScrollPane1 = new javax.swing.JScrollPane(); + jTextArea1 = new javax.swing.JTextArea(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jButton1.setText("Rispondi"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jTextArea1.setColumns(20); + jTextArea1.setRows(5); + jScrollPane1.setViewportView(jTextArea1); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(283, 283, 283) + .addComponent(jButton1) + .addContainerGap(24, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 74, Short.MAX_VALUE) + .addComponent(jButton1) + .addGap(44, 44, 44)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jButton1ActionPerformed + + /** + * @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(DettagliMessaggio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(DettagliMessaggio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(DettagliMessaggio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(DettagliMessaggio.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 DettagliMessaggio().setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextArea jTextArea1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/GUI/user/LeggiMessaggi.form b/src/GUI/user/LeggiMessaggi.form index d9ffa53..19b85ce 100644 --- a/src/GUI/user/LeggiMessaggi.form +++ b/src/GUI/user/LeggiMessaggi.form @@ -36,6 +36,11 @@
+ + + + +
@@ -45,7 +50,9 @@ - + + + @@ -72,5 +79,13 @@ + + + + + + + + diff --git a/src/GUI/user/LeggiMessaggi.java b/src/GUI/user/LeggiMessaggi.java index 59321f7..4a823e0 100644 --- a/src/GUI/user/LeggiMessaggi.java +++ b/src/GUI/user/LeggiMessaggi.java @@ -38,6 +38,7 @@ private void initComponents() { jLabel1 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); jList1 = new javax.swing.JList(); + jButton1 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); @@ -45,6 +46,13 @@ private void initComponents() { jScrollPane1.setViewportView(jList1); + jButton1.setText("Avanti"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( @@ -58,6 +66,10 @@ private void initComponents() { .addGap(99, 99, 99) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 589, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(105, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(jButton1) + .addGap(91, 91, 91)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -66,13 +78,23 @@ private void initComponents() { .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(135, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 54, Short.MAX_VALUE) + .addComponent(jButton1) + .addGap(52, 52, 52)) ); pack(); }// //GEN-END:initComponents + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + // TODO add your handling code here: + MessaggioDestinatario m = (MessaggioDestinatario)jList1.getSelectedValue(); + System.out.println(m.getTesto()); + new DettagliMessaggio(m).setVisible(true); + }//GEN-LAST:event_jButton1ActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JList jList1; private javax.swing.JScrollPane jScrollPane1; From 3a7c39c2ead7d0544b262637b64403744ecbd166 Mon Sep 17 00:00:00 2001 From: Roberto Date: Sun, 14 Dec 2014 12:22:00 +0100 Subject: [PATCH 30/45] Piccoli miglioramenti. --- src/GUI/user/DettagliMessaggio.form | 44 ++++++++++++++++++++-------- src/GUI/user/DettagliMessaggio.java | 41 ++++++++++++++++++-------- src/model/Messaggio.java | 8 ++--- src/model/MessaggioDestinatario.java | 2 ++ 4 files changed, 66 insertions(+), 29 deletions(-) diff --git a/src/GUI/user/DettagliMessaggio.form b/src/GUI/user/DettagliMessaggio.form index 8f698ea..2329a6a 100644 --- a/src/GUI/user/DettagliMessaggio.form +++ b/src/GUI/user/DettagliMessaggio.form @@ -23,26 +23,34 @@ - - - - - + + + + + - - + + + + + + - - - - - + + + + + + + + + @@ -50,7 +58,7 @@ - + @@ -71,5 +79,15 @@ + + + + + + + + + + diff --git a/src/GUI/user/DettagliMessaggio.java b/src/GUI/user/DettagliMessaggio.java index e026691..041cf90 100644 --- a/src/GUI/user/DettagliMessaggio.java +++ b/src/GUI/user/DettagliMessaggio.java @@ -22,6 +22,8 @@ public DettagliMessaggio(MessaggioDestinatario m) { initComponents(); jTextArea1.setText(m.getTesto()); jTextArea1.disable(); + jLabel1.setText("Mittente: " + m.getMittente().toString()); + jLabel2.setText("Lingua testo: " + m.getLingua()); } /** @@ -36,10 +38,12 @@ private void initComponents() { jButton1 = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - jButton1.setText("Rispondi"); + jButton1.setText("Rispondi (non funziona e mai funzionerà)"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); @@ -50,27 +54,38 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { jTextArea1.setRows(5); jScrollPane1.setViewportView(jTextArea1); + jLabel1.setText("jLabel1"); + + jLabel2.setText("jLabel2"); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(283, 283, 283) - .addComponent(jButton1) - .addContainerGap(24, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(69, 69, 69)) + .addGroup(layout.createSequentialGroup() .addContainerGap() - .addComponent(jScrollPane1) - .addContainerGap()) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 441, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel1) + .addComponent(jLabel2)) + .addContainerGap(44, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 74, Short.MAX_VALUE) - .addComponent(jButton1) - .addGap(44, 44, 44)) + .addGap(26, 26, 26) + .addComponent(jLabel1) + .addGap(33, 33, 33) + .addComponent(jLabel2) + .addGap(38, 38, 38) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE) + .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(35, 35, 35)) ); pack(); @@ -117,6 +132,8 @@ public void run() { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextArea jTextArea1; // End of variables declaration//GEN-END:variables diff --git a/src/model/Messaggio.java b/src/model/Messaggio.java index 2ab1bb0..47ebe90 100644 --- a/src/model/Messaggio.java +++ b/src/model/Messaggio.java @@ -181,7 +181,7 @@ public boolean isLetto() { return true; } - private String toStringF = "Messaggio in lingua: %lingua% inviato da utente con id %mittenteID% ad utente con id %destinatarioID% e testo: %testo%"; + private String toStringF = "Messaggio in lingua: %lingua% inviato da %mittente%: %testo%"; public String setToStringF(String f) { String result = getToStringF(); @@ -192,8 +192,8 @@ public String setToStringF(String f) { public String toString() { String result = getToStringF(); result = result.replaceAll("%lingua%", getLingua()); - result = result.replaceAll("%mittenteID%", getMittente().getId()); - result = result.replaceAll("%destinatarioID%", getDestinatario().getId()); + result = result.replaceAll("%mittente%", getMittente().toString()); + result = result.replaceAll("%destinatarioID%", getDestinatario().toString()); result = result.replaceAll("%testo%", getTesto()); result = result.replaceAll("%testoCif%", getTestoCifrato()); return result; @@ -225,7 +225,7 @@ public int getId() { * @return the mittente */ public UserInfo getMittente() { - return mittente; + return this.mittente; } /** diff --git a/src/model/MessaggioDestinatario.java b/src/model/MessaggioDestinatario.java index 8a9dd0c..b74ed04 100644 --- a/src/model/MessaggioDestinatario.java +++ b/src/model/MessaggioDestinatario.java @@ -12,4 +12,6 @@ */ public interface MessaggioDestinatario extends MessaggioAstratto { public boolean isLetto(); + + public UserInfo getMittente(); } From 67db5f3e243f4da56b2dc708dff527ee5a59480c Mon Sep 17 00:00:00 2001 From: Roberto Date: Sun, 14 Dec 2014 19:02:52 +0100 Subject: [PATCH 31/45] Aggiunta classe di test --- test/model/MessaggioTest.java | 412 ++++++++++++++++++++++++++++++++++ 1 file changed, 412 insertions(+) create mode 100644 test/model/MessaggioTest.java diff --git a/test/model/MessaggioTest.java b/test/model/MessaggioTest.java new file mode 100644 index 0000000..89d160b --- /dev/null +++ b/test/model/MessaggioTest.java @@ -0,0 +1,412 @@ +/* + * 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 model; + +import java.util.List; +import model.user.SistemaCifratura; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author MASTER + */ +public class MessaggioTest { + + Messaggio m = new Messaggio(null, null, null, null); + + public MessaggioTest() { + + } + + @BeforeClass + public static void setUpClass() { + System.out.println("Inizio test"); + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + System.out.println("prima del test"); + } + + @After + public void tearDown() { + System.out.println("dopo il test"); + //m = new Messaggio(null, null, null, null); + } + + /** + * Test of setLingua method, of class Messaggio. + */ + @Test + public void testSetLingua() { + System.out.println("setLingua"); + String l = "prova"; + m.setLingua(l); + // TODO review the generated test code and remove the default call to fail. + assertEquals(l, m.getLingua()); + } + + /** + * Test of setTesto method, of class Messaggio. + */ + @Test + public void testSetTesto() { + System.out.println("setTesto"); + String text = "setTesto"; + m.setTesto(text); + // TODO review the generated test code and remove the default call to fail. + assertEquals(text, m.getTesto()); + } + + /** + * Test of setDestinatario method, of class Messaggio. + */ + @Test + public void testSetDestinatario() { + System.out.println("setDestinatario"); + UserInfo d = new UserInfo("id", "prova"); + m.setDestinatario(d); + // TODO review the generated test code and remove the default call to fail. + assertEquals(d, m.getDestinatario()); + } + + /** + * Test of setMittente method, of class Messaggio. + */ + @Test + public void testSetMittente() { + System.out.println("setMittente"); + UserInfo d = new UserInfo("id", "prova"); + m.setMittente(d); + // TODO review the generated test code and remove the default call to fail. + assertEquals(d, m.getMittente()); + } + + /** + * Test of getSdc method, of class Messaggio. + */ + @Test + public void testGetSdc() { + System.out.println("getSdc"); + SistemaCifratura expResult = new SistemaCifratura("id", "chiave", "metodo"); + m.setSdc(expResult); + SistemaCifratura result = m.getSdc(); + assertEquals(expResult, result); + } + + /** + * Test of setSdc method, of class Messaggio. + */ + @Test + public void testSetSdc() { + System.out.println("setSdc"); + SistemaCifratura s = new SistemaCifratura("id", "chiave", "metodo"); + m.setSdc(s); + assertEquals(s, m.getSdc()); + } + + /** + * Test of caricaIniviati method, of class Messaggio. + */ + /*@Test + public void testCaricaIniviati() { + System.out.println("caricaIniviati"); + Studente s = null; + List expResult = null; + List result = Messaggio.caricaIniviati(s); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + }*/ + + /** + * Test of caricaBozze method, of class Messaggio. + */ + /*@Test + public void testCaricaBozze() { + System.out.println("caricaBozze"); + Studente s = null; + Messaggio[] expResult = null; + Messaggio[] result = Messaggio.caricaBozze(s); + assertArrayEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + }*/ + + /** + * Test of getMessaggi method, of class Messaggio. + */ + /*@Test + public void testGetMessaggi() { + System.out.println("getMessaggi"); + List expResult = null; + List result = Messaggio.getMessaggi(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + }*/ + + /** + * Test of caricaRicevuti method, of class Messaggio. + */ + /*@Test + public void testCaricaRicevuti() { + System.out.println("caricaRicevuti"); + Studente s = null; + MessaggioDestinatario[] expResult = null; + MessaggioDestinatario[] result = Messaggio.caricaRicevuti(s); + assertArrayEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + }*/ + + /** + * Test of elimina method, of class Messaggio. + */ + /*@Test + public void testElimina() { + System.out.println("elimina"); + Messaggio instance = null; + boolean expResult = false; + boolean result = instance.elimina(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + }*/ + + /** + * Test of setBozza method, of class Messaggio. + */ + /*@Test + public void testSetBozza() { + System.out.println("setBozza"); + boolean b = false; + Messaggio instance = null; + instance.setBozza(b); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + }*/ + + /** + * Test of cifra method, of class Messaggio. + */ + /*@Test + public void testCifra() { + System.out.println("cifra"); + Messaggio instance = null; + instance.cifra(); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + }*/ + + /** + * Test of isBozza method, of class Messaggio. + */ + /*@Test + public void testIsBozza() { + System.out.println("isBozza"); + Messaggio instance = null; + boolean expResult = false; + boolean result = instance.isBozza(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + }*/ + + /** + * Test of save method, of class Messaggio. + */ + /*@Test + public void testSave() { + System.out.println("save"); + Messaggio instance = null; + boolean expResult = false; + boolean result = instance.save(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + }/* + + /** + * Test of isLetto method, of class Messaggio. + */ + /*@Test + public void testIsLetto() { + System.out.println("isLetto"); + Messaggio instance = null; + boolean expResult = false; + boolean result = instance.isLetto(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + }*/ + + /** + * Test of setToStringF method, of class Messaggio. + */ + /*@Test + public void testSetToStringF() { + System.out.println("setToStringF"); + String f = ""; + Messaggio instance = null; + String expResult = ""; + String result = instance.setToStringF(f); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + }*/ + + /** + * Test of toString method, of class Messaggio. + */ + /*@Test + public void testToString() { + System.out.println("toString"); + Messaggio instance = null; + String expResult = ""; + String result = instance.toString(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + }*/ + + /** + * Test of send method, of class Messaggio. + */ + /*@Test + public void testSend() { + System.out.println("send"); + Messaggio instance = null; + boolean expResult = false; + boolean result = instance.send(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + }*/ + + /** + * Test of getId method, of class Messaggio. + */ + /*@Test + public void testGetId() { + System.out.println("getId"); + Messaggio instance = null; + int expResult = 0; + int result = instance.getId(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + }*/ + + /** + * Test of getMittente method, of class Messaggio. + */ + /*@Test + public void testGetMittente() { + System.out.println("getMittente"); + Messaggio instance = null; + UserInfo expResult = null; + UserInfo result = instance.getMittente(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + }*/ + + /** + * Test of getDestinatario method, of class Messaggio. + */ + /*@Test + public void testGetDestinatario() { + System.out.println("getDestinatario"); + Messaggio instance = null; + UserInfo expResult = null; + UserInfo result = instance.getDestinatario(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + }*/ + + /** + * Test of getTesto method, of class Messaggio. + */ + /*@Test + public void testGetTesto() { + System.out.println("getTesto"); + Messaggio instance = null; + String expResult = ""; + String result = instance.getTesto(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + }*/ + + /** + * Test of getTestoCifrato method, of class Messaggio. + */ + /*@Test + public void testGetTestoCifrato() { + System.out.println("getTestoCifrato"); + Messaggio instance = null; + String expResult = ""; + String result = instance.getTestoCifrato(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + }*/ + + /** + * Test of getLingua method, of class Messaggio. + */ + /*@Test + public void testGetLingua() { + System.out.println("getLingua"); + Messaggio instance = null; + String expResult = ""; + String result = instance.getLingua(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + }*/ + + /** + * Test of getTitolo method, of class Messaggio. + */ + /*@Test + public void testGetTitolo() { + System.out.println("getTitolo"); + Messaggio instance = null; + String expResult = ""; + String result = instance.getTitolo(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + }*/ + + /** + * Test of getToStringF method, of class Messaggio. + */ + /*@Test + public void testGetToStringF() { + System.out.println("getToStringF"); + Messaggio instance = null; + String expResult = ""; + String result = instance.getToStringF(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + }*/ + +} From a66f7708efdb43da982634c76044be6575618a8f Mon Sep 17 00:00:00 2001 From: Roberto Date: Sun, 21 Dec 2014 22:44:06 +0100 Subject: [PATCH 32/45] Aggiunta classe di test --- test/model/MessaggioTest.java | 10 +- test/model/spia/SessioneTest.java | 188 ------------------------------ 2 files changed, 4 insertions(+), 194 deletions(-) delete mode 100644 test/model/spia/SessioneTest.java diff --git a/test/model/MessaggioTest.java b/test/model/MessaggioTest.java index 89d160b..88e277d 100644 --- a/test/model/MessaggioTest.java +++ b/test/model/MessaggioTest.java @@ -121,7 +121,7 @@ public void testSetSdc() { /** * Test of caricaIniviati method, of class Messaggio. */ - /*@Test + @Test public void testCaricaIniviati() { System.out.println("caricaIniviati"); Studente s = null; @@ -129,13 +129,12 @@ public void testCaricaIniviati() { List result = Messaggio.caricaIniviati(s); assertEquals(expResult, result); // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ + } /** * Test of caricaBozze method, of class Messaggio. */ - /*@Test + @Test public void testCaricaBozze() { System.out.println("caricaBozze"); Studente s = null; @@ -143,8 +142,7 @@ public void testCaricaBozze() { Messaggio[] result = Messaggio.caricaBozze(s); assertArrayEquals(expResult, result); // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ + } /** * Test of getMessaggi method, of class Messaggio. diff --git a/test/model/spia/SessioneTest.java b/test/model/spia/SessioneTest.java deleted file mode 100644 index 721c1c1..0000000 --- a/test/model/spia/SessioneTest.java +++ /dev/null @@ -1,188 +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 model.spia; - -import model.Messaggio; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import static org.junit.Assert.*; - -/** - * - * @author MASTER - */ -public class SessioneTest { - - public SessioneTest() { - } - - @BeforeClass - public static void setUpClass() { - } - - @AfterClass - public static void tearDownClass() { - } - - @Before - public void setUp() { - } - - @After - public void tearDown() { - } - - /** - * Test of recuperaSessione method, of class Sessione. - */ - @Test - public void testRecuperaSessione() throws Exception { - System.out.println("recuperaSessione"); - Spia owner = null; - Sessione expResult = null; - Sessione result = Sessione.recuperaSessione(owner); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of startNewSessione method, of class Sessione. - */ - @Test - public void testStartNewSessione() { - System.out.println("startNewSessione"); - Spia owner = null; - Sessione expResult = null; - Sessione result = Sessione.startNewSessione(owner); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of restoreSessione method, of class Sessione. - */ - @Test - public void testRestoreSessione() { - System.out.println("restoreSessione"); - Sessione s = null; - Sessione expResult = null; - Sessione result = Sessione.restoreSessione(s); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of deleteSessione method, of class Sessione. - */ - @Test - public void testDeleteSessione() { - System.out.println("deleteSessione"); - Sessione sessione = null; - Sessione.deleteSessione(sessione); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of saveSessione method, of class Sessione. - */ - @Test - public void testSaveSessione() { - System.out.println("saveSessione"); - Sessione sessione = null; - Sessione.saveSessione(sessione); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of getIpotesiRadice method, of class Sessione. - */ - @Test - public void testGetIpotesiRadice() { - System.out.println("getIpotesiRadice"); - Sessione instance = null; - Ipotesi expResult = null; - Ipotesi result = instance.getIpotesiRadice(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of getIpotesiCorrente method, of class Sessione. - */ - @Test - public void testGetIpotesiCorrente() { - System.out.println("getIpotesiCorrente"); - Sessione instance = null; - Ipotesi expResult = null; - Ipotesi result = instance.getIpotesiCorrente(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of setIpotesiCorrente method, of class Sessione. - */ - @Test - public void testSetIpotesiCorrente() { - System.out.println("setIpotesiCorrente"); - Ipotesi ip = null; - Sessione instance = null; - instance.setIpotesiCorrente(ip); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of getMessaggio method, of class Sessione. - */ - @Test - public void testGetMessaggio() { - System.out.println("getMessaggio"); - Sessione instance = null; - Messaggio expResult = null; - Messaggio result = instance.getMessaggio(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of add method, of class Sessione. - */ - @Test - public void testAdd() { - System.out.println("add"); - Ipotesi nuova = null; - Sessione instance = null; - instance.add(nuova); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of start method, of class Sessione. - */ - @Test - public void testStart() { - System.out.println("start"); - Sessione instance = null; - instance.start(); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - -} From f9edf9ea4a87725642e4a17d807095f202d02c28 Mon Sep 17 00:00:00 2001 From: bob Date: Thu, 5 Feb 2015 17:17:13 +0100 Subject: [PATCH 33/45] added use cryptohelper --- nbproject/test | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 nbproject/test diff --git a/nbproject/test b/nbproject/test new file mode 100644 index 0000000..e69de29 From c04d811144bb6ca8e772f618e49d9d27df20c6d5 Mon Sep 17 00:00:00 2001 From: bob Date: Thu, 5 Feb 2015 17:18:07 +0100 Subject: [PATCH 34/45] ok Here I am --- nbproject/test | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 nbproject/test diff --git a/nbproject/test b/nbproject/test deleted file mode 100644 index e69de29..0000000 From 5c61f7d27c6d3f04611f8d8c3ddeebc01b6173c5 Mon Sep 17 00:00:00 2001 From: Alessandro Rosso Date: Thu, 5 Feb 2015 17:25:45 +0100 Subject: [PATCH 35/45] modifica parti della mappatura --- src/GUI/Main.form | 68 ++++++++++++------- src/GUI/Main.java | 55 +++++++++------ src/db/DbManager.java | 154 +++++++++++++++++++++--------------------- 3 files changed, 153 insertions(+), 124 deletions(-) diff --git a/src/GUI/Main.form b/src/GUI/Main.form index 3881aa1..8e35596 100644 --- a/src/GUI/Main.form +++ b/src/GUI/Main.form @@ -46,30 +46,12 @@ - - - - - - - - - - - - - - - - - - - - + + @@ -86,6 +68,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -103,19 +109,21 @@ - + + + - - - + + + + + - - @@ -193,5 +201,13 @@ + + + + + + + + diff --git a/src/GUI/Main.java b/src/GUI/Main.java index 56d0100..76b343a 100644 --- a/src/GUI/Main.java +++ b/src/GUI/Main.java @@ -23,6 +23,7 @@ public class Main extends javax.swing.JFrame { */ public Main() { initComponents(); + jLabel6.setVisible(false); //facciamo scomparire la scritta "nome utente o password errato" } /** @@ -52,6 +53,7 @@ private void initComponents() { jPasswordField1 = new javax.swing.JPasswordField(); jRadioButton1 = new javax.swing.JRadioButton(); jRadioButton2 = new javax.swing.JRadioButton(); + jLabel6 = new javax.swing.JLabel(); jButton2.setText("jButton2"); @@ -106,31 +108,20 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { buttonGroup1.add(jRadioButton2); jRadioButton2.setText("Utente Regolamentare"); + jLabel6.setForeground(new java.awt.Color(255, 0, 0)); + jLabel6.setText("Nome utente e/o password errata"); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(42, 42, 42) - .addComponent(jButton3)) - .addGroup(layout.createSequentialGroup() - .addGap(58, 58, 58) - .addComponent(jLabel5) - .addGap(67, 67, 67) - .addComponent(jRadioButton1) - .addGap(18, 18, 18) - .addComponent(jRadioButton2))) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(71, 71, 71) - .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jButton1)) + .addComponent(jLabel4) + .addGap(0, 0, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(83, 83, 83) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -141,6 +132,25 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE) .addComponent(jPasswordField1)))) .addGap(69, 69, 69)) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(58, 58, 58) + .addComponent(jLabel5) + .addGap(67, 67, 67) + .addComponent(jRadioButton1) + .addGap(18, 18, 18) + .addComponent(jRadioButton2)) + .addGroup(layout.createSequentialGroup() + .addGap(123, 123, 123) + .addComponent(jLabel6))) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addGap(42, 42, 42) + .addComponent(jButton3) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jButton1) + .addGap(47, 47, 47)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -155,17 +165,19 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jLabel6) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5) .addComponent(jRadioButton1) .addComponent(jRadioButton2)) .addGap(43, 43, 43) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel4) + .addComponent(jLabel4) + .addGap(34, 34, 34) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton3) .addComponent(jButton1)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jButton3) .addGap(36, 36, 36)) ); @@ -276,6 +288,7 @@ public static synchronized void main(String args[]) { private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; + private javax.swing.JLabel jLabel6; private javax.swing.JPasswordField jPasswordField1; private javax.swing.JRadioButton jRadioButton1; private javax.swing.JRadioButton jRadioButton2; diff --git a/src/db/DbManager.java b/src/db/DbManager.java index 83246c5..e8c7349 100644 --- a/src/db/DbManager.java +++ b/src/db/DbManager.java @@ -1,77 +1,77 @@ -/* - * 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 db; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; - -/** - * - * @author BobCaSUaL - */ -public class DbManager { - - /********** static part *********/ - private static DbManager instance = null; - - public static synchronized DbManager getInstance() throws SQLException { - if( null == instance ) { - instance = new DbManager(); - } - return instance; - } - - - /******* object definition *******/ - - private String schema = "cryptohelper"; // Nome del Database a cui connettersi - private String uname = "root"; // Nome utente utilizzato per la connessione al Database - private String passw = "root"; // Password usata per la connessione al Database - - private Connection engine; // La connessione col Database - - - /******* internal classes *******/ - - public class QueryImpl extends QueryAbstract { - String sql; - public QueryImpl( String sql ) throws SQLException { - super( engine.prepareStatement(sql), sql ); - } - } - public class QueryResultImpl extends QueryResultAbstract { - - public QueryResultImpl(Query q) throws SQLException { - super(q.executeQuery(), q); - } - } - - /*public class QueryResultImpl2 extends QueryResultAbstract { - - public QueryResultImpl2(Query q) throws SQLException { - super(q.executeUpdate(), q); - } - }*/ - - private DbManager() throws SQLException { - DriverManager.registerDriver( new com.mysql.jdbc.Driver() ); - engine = DriverManager.getConnection("jdbc:mysql://localhost/" + schema, uname, passw); - } - - public Query createQuery( String sql ) throws SQLException { - return new QueryImpl( sql ); - } - public QueryResult execute( Query q ) throws SQLException { - return new QueryResultImpl( q ); - } - - public void executeUpdate( Query q ) throws SQLException { - q.executeUpdate(); - } - -} +/* + * 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 db; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +/** + * + * @author BobCaSUaL + */ +public class DbManager { + + /********** static part *********/ + private static DbManager instance = null; + + public static synchronized DbManager getInstance() throws SQLException { + if( null == instance ) { + instance = new DbManager(); + } + return instance; + } + + + /******* object definition *******/ + + private String schema = "cryptohelper"; // Nome del Database a cui connettersi + private String uname = "root"; // Nome utente utilizzato per la connessione al Database + private String passw = ""; // Password usata per la connessione al Database + + private Connection engine; // La connessione col Database + + + /******* internal classes *******/ + + public class QueryImpl extends QueryAbstract { + String sql; + public QueryImpl( String sql ) throws SQLException { + super( engine.prepareStatement(sql), sql ); + } + } + public class QueryResultImpl extends QueryResultAbstract { + + public QueryResultImpl(Query q) throws SQLException { + super(q.executeQuery(), q); + } + } + + /*public class QueryResultImpl2 extends QueryResultAbstract { + + public QueryResultImpl2(Query q) throws SQLException { + super(q.executeUpdate(), q); + } + }*/ + + private DbManager() throws SQLException { + DriverManager.registerDriver( new com.mysql.jdbc.Driver() ); + engine = DriverManager.getConnection("jdbc:mysql://localhost/" + schema, uname, passw); + } + + public Query createQuery( String sql ) throws SQLException { + return new QueryImpl( sql ); + } + public QueryResult execute( Query q ) throws SQLException { + return new QueryResultImpl( q ); + } + + public void executeUpdate( Query q ) throws SQLException { + q.executeUpdate(); + } + +} From bcafc7722f08d15a86db941b90c25e37d9fd34ca Mon Sep 17 00:00:00 2001 From: davide Date: Thu, 5 Feb 2015 17:56:44 +0100 Subject: [PATCH 36/45] fixed form sostituzione semplice --- src/GUI/spia/SostituzioneSempliceGUI.form | 17 +-- src/GUI/spia/SostituzioneSempliceGUI.java | 156 +++++++++++----------- 2 files changed, 84 insertions(+), 89 deletions(-) diff --git a/src/GUI/spia/SostituzioneSempliceGUI.form b/src/GUI/spia/SostituzioneSempliceGUI.form index f74e168..5f4cc16 100644 --- a/src/GUI/spia/SostituzioneSempliceGUI.form +++ b/src/GUI/spia/SostituzioneSempliceGUI.form @@ -36,17 +36,14 @@ + + + + + - - - - - - - - - - + + diff --git a/src/GUI/spia/SostituzioneSempliceGUI.java b/src/GUI/spia/SostituzioneSempliceGUI.java index edf0e28..a13dcd6 100644 --- a/src/GUI/spia/SostituzioneSempliceGUI.java +++ b/src/GUI/spia/SostituzioneSempliceGUI.java @@ -85,85 +85,83 @@ private SostituzioneSempliceGUI( SynchronizedBuffer buff ) { * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { + // //GEN-BEGIN:initComponents + private void initComponents() { - jLabel1 = new javax.swing.JLabel(); - jLabel2 = new javax.swing.JLabel(); - jLabel3 = new javax.swing.JLabel(); - jTextField1 = new javax.swing.JTextField(); - jTextField2 = new javax.swing.JTextField(); - jButton1 = new javax.swing.JButton(); - jLabel4 = new javax.swing.JLabel(); + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + jLabel3 = new javax.swing.JLabel(); + jTextField1 = new javax.swing.JTextField(); + jTextField2 = new javax.swing.JTextField(); + jButton1 = new javax.swing.JButton(); + jLabel4 = new javax.swing.JLabel(); - jLabel1.setText("Sostituisci la lettera:"); + jLabel1.setText("Sostituisci la lettera:"); - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - jLabel2.setText("Trasforma la lettera: "); + jLabel2.setText("Trasforma la lettera: "); - jLabel3.setText("In:"); + jLabel3.setText("In:"); - jTextField1.setMaximumSize(new java.awt.Dimension(1, 1)); - jTextField1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jTextField1ActionPerformed(evt); - } - }); + jTextField1.setMaximumSize(new java.awt.Dimension(1, 1)); + jTextField1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jTextField1ActionPerformed(evt); + } + }); - jButton1.setText("Sostituisci"); - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - - jLabel4.setText("Se inserisci più caratteri verrà preso in considerazione solo il primo"); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(jButton1) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + jButton1.setText("Sostituisci"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jLabel4.setText("Se inserisci più caratteri verrà preso in considerazione solo il primo"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addGap(47, 47, 47) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel3) - .addGap(184, 184, 184) - .addComponent(jTextField2)) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel2) - .addGap(55, 55, 55) - .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)))) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jButton1) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(47, 47, 47) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel2) + .addComponent(jLabel3)) + .addGap(55, 55, 55) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE) + .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 344, javax.swing.GroupLayout.PREFERRED_SIZE)))) + .addContainerGap(37, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 344, javax.swing.GroupLayout.PREFERRED_SIZE)))) - .addContainerGap(37, Short.MAX_VALUE)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(65, 65, 65) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(jLabel2) - .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(39, 39, 39) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel3) - .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(18, 18, 18) - .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGap(18, 18, 18) - .addComponent(jButton1) - .addContainerGap()) - ); - - pack(); - }// //GEN-END:initComponents + .addGap(65, 65, 65) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jLabel2) + .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(39, 39, 39) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel3) + .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) + .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGap(18, 18, 18) + .addComponent(jButton1) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed char[] array = new char[2]; @@ -185,13 +183,13 @@ public static void main( String[] args ) { System.out.println(r[0]+" "+r[1]); } - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton1; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; - private javax.swing.JLabel jLabel4; - private javax.swing.JTextField jTextField1; - private javax.swing.JTextField jTextField2; - // End of variables declaration//GEN-END:variables + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JTextField jTextField1; + private javax.swing.JTextField jTextField2; + // End of variables declaration//GEN-END:variables } From bfadda615365e7dfcb6e32ccd8457327fa41c654 Mon Sep 17 00:00:00 2001 From: Roberto Date: Thu, 8 Jan 2015 15:05:09 +0100 Subject: [PATCH 37/45] --- test/model/MessaggioTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/model/MessaggioTest.java b/test/model/MessaggioTest.java index 88e277d..8e3f0a5 100644 --- a/test/model/MessaggioTest.java +++ b/test/model/MessaggioTest.java @@ -137,7 +137,7 @@ public void testCaricaIniviati() { @Test public void testCaricaBozze() { System.out.println("caricaBozze"); - Studente s = null; + Studente s = new Studente("bob"); Messaggio[] expResult = null; Messaggio[] result = Messaggio.caricaBozze(s); assertArrayEquals(expResult, result); @@ -147,7 +147,7 @@ public void testCaricaBozze() { /** * Test of getMessaggi method, of class Messaggio. */ - /*@Test + @Test public void testGetMessaggi() { System.out.println("getMessaggi"); List expResult = null; @@ -155,7 +155,7 @@ public void testGetMessaggi() { assertEquals(expResult, result); // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); - }*/ + } /** * Test of caricaRicevuti method, of class Messaggio. From 20f330ace91747ac0d5faf79d8279e89cdd5edca Mon Sep 17 00:00:00 2001 From: davide Date: Fri, 6 Feb 2015 14:11:38 +0100 Subject: [PATCH 38/45] fixato lancio eccezione al ripristino della sessione adeguata alle specifiche la cifratura di cesare --- src/model/spia/Sessione.java | 8 +- src/model/user/CalcolatoreCesare.java | 61 +++--- src/model/user/CalcolatoreMappatura.java | 34 +-- src/model/user/Cifratore.java | 74 +++---- src/model/user/Mappatura.java | 99 +++++---- src/model/user/SistemaCifratura.java | 255 ++++++++++++----------- 6 files changed, 273 insertions(+), 258 deletions(-) diff --git a/src/model/spia/Sessione.java b/src/model/spia/Sessione.java index cb4a25d..1cd8710 100644 --- a/src/model/spia/Sessione.java +++ b/src/model/spia/Sessione.java @@ -48,7 +48,7 @@ public static Sessione recuperaSessione(Spia owner) throws SQLException { String key = GenericSelector.selectOptions(optionList); //In base alla key scelta deserializza la Sessione dal database - Query u = db.createQuery("SELECT `id`, `sessione` FROM `Sessione` WHERE `userId` = ? AND `key` = ? LIMIT 1"); + Query u = db.createQuery("SELECT `id`, `session` FROM `Sessione` WHERE `userId` = ? AND `key` = ? LIMIT 1"); u.setString(1, owner.getId()); u.setString(2, key); QueryResult qr = db.execute(u); @@ -58,7 +58,7 @@ public static Sessione recuperaSessione(Spia owner) throws SQLException { try { ByteArrayInputStream bais; ObjectInputStream ins; - bais = new ByteArrayInputStream(qr.getBytes("sessione")); + bais = new ByteArrayInputStream(qr.getBytes("session")); ins = new ObjectInputStream(bais); result =(Sessione)ins.readObject(); @@ -120,14 +120,14 @@ public static void saveSessione(Sessione sessione) { byte[] data = bos.toByteArray(); DbManager db = DbManager.getInstance(); - Query q = db.createQuery("INSERT INTO `Sessione`(`userId`,`key`,`sessione`) VALUES( ?, ?, ? ) ON DUPLICATE KEY UPDATE `sessione` = ?"); + Query q = db.createQuery("INSERT INTO `Sessione`(`userId`,`key`,`session`) VALUES( ?, ?, ? ) ON DUPLICATE KEY UPDATE `session` = ?"); q.setString(1, owner.getId()); q.setString(2, sessione.key); q.setObject(3, data); q.setObject(4, data); db.executeUpdate(q); - + System.out.println("Sessione salvata correttamente"); } catch (IOException | SQLException ex) { throw new RuntimeException(ex.getMessage(), ex); } diff --git a/src/model/user/CalcolatoreCesare.java b/src/model/user/CalcolatoreCesare.java index dd3fe5f..7168d95 100644 --- a/src/model/user/CalcolatoreCesare.java +++ b/src/model/user/CalcolatoreCesare.java @@ -1,25 +1,36 @@ -/* - * 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 model.user; - -/** - * - * @author MASTER - */ -public class CalcolatoreCesare implements CalcolatoreMappatura { - //private String chiave; - - /*public CalcolatoreCesare(String c){ - this.chiave = c; - }*/ - - public Mappatura calcola(String c){ - Mappatura m = new Mappatura(); - m.map(c); - return m; - } -} +/* + * 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 model.user; + +/** + * + * @author MASTER + */ +public class CalcolatoreCesare implements CalcolatoreMappatura { + //private String chiave; + + /*public CalcolatoreCesare(String c){ + this.chiave = c; + }*/ + + public Mappatura calcola(String c){ + //Mappatura m = new Mappatura(); + int chiave = Integer.parseInt(c); + //mappaInversa = new char[mappa.length]; + for(int i=0; i Date: Fri, 6 Feb 2015 14:54:51 +0100 Subject: [PATCH 39/45] prima bozza cifratura a parola chiave --- src/model/user/CalcolatoreCesare.java | 14 +--- src/model/user/CalcolatoreParolaChiave.java | 83 ++++++++++++++------ src/model/user/CalcolatorePseudocasuale.java | 53 +++++++------ 3 files changed, 87 insertions(+), 63 deletions(-) diff --git a/src/model/user/CalcolatoreCesare.java b/src/model/user/CalcolatoreCesare.java index 7168d95..20d350a 100644 --- a/src/model/user/CalcolatoreCesare.java +++ b/src/model/user/CalcolatoreCesare.java @@ -18,19 +18,9 @@ public class CalcolatoreCesare implements CalcolatoreMappatura { }*/ public Mappatura calcola(String c){ - //Mappatura m = new Mappatura(); int chiave = Integer.parseInt(c); - //mappaInversa = new char[mappa.length]; - for(int i=0; i Date: Fri, 6 Feb 2015 17:28:47 +0100 Subject: [PATCH 40/45] quasi finita classe di test --- src/db/DbManager.java | 2 +- src/model/Messaggio.java | 8 ++ src/model/Studente.java | 8 -- test/model/MessaggioTest.java | 45 +++++----- test/model/StudenteTest.java | 155 ++++++++++++++++++++++++++++++++++ 5 files changed, 186 insertions(+), 32 deletions(-) create mode 100644 test/model/StudenteTest.java diff --git a/src/db/DbManager.java b/src/db/DbManager.java index e8c7349..fdedad4 100644 --- a/src/db/DbManager.java +++ b/src/db/DbManager.java @@ -31,7 +31,7 @@ public static synchronized DbManager getInstance() throws SQLException { private String schema = "cryptohelper"; // Nome del Database a cui connettersi private String uname = "root"; // Nome utente utilizzato per la connessione al Database - private String passw = ""; // Password usata per la connessione al Database + private String passw = "root"; // Password usata per la connessione al Database private Connection engine; // La connessione col Database diff --git a/src/model/Messaggio.java b/src/model/Messaggio.java index 47ebe90..aa95255 100644 --- a/src/model/Messaggio.java +++ b/src/model/Messaggio.java @@ -52,6 +52,14 @@ public Messaggio(String testo, String lingua, UserInfo mittente, UserInfo destin this.destinatario = destinatario; this.sdc = sdc; } + + public Messaggio(){ + this.testo = null; + this.lingua = null; + this.mittente = null; + this.destinatario = null; + this.sdc = null; + } public void setLingua(String l) { this.lingua = l; diff --git a/src/model/Studente.java b/src/model/Studente.java index 547ffc0..1ba7dee 100644 --- a/src/model/Studente.java +++ b/src/model/Studente.java @@ -23,7 +23,6 @@ public class Studente { private String id; private String login; private String pwd; - private DbManager DbManager0; public Studente(String user){ this.login = user; @@ -118,12 +117,5 @@ public String getLogin() { public String getPwd() { return pwd; } - - /** - * @return the DbManager0 - */ - public DbManager getDbManager0() { - return DbManager0; - } } diff --git a/test/model/MessaggioTest.java b/test/model/MessaggioTest.java index 8e3f0a5..f2737b8 100644 --- a/test/model/MessaggioTest.java +++ b/test/model/MessaggioTest.java @@ -6,6 +6,7 @@ package model; +import java.util.ArrayList; import java.util.List; import model.user.SistemaCifratura; import org.junit.After; @@ -137,8 +138,8 @@ public void testCaricaIniviati() { @Test public void testCaricaBozze() { System.out.println("caricaBozze"); - Studente s = new Studente("bob"); - Messaggio[] expResult = null; + Studente s = new Studente("utentetest"); + Messaggio[] expResult = new Messaggio[0]; Messaggio[] result = Messaggio.caricaBozze(s); assertArrayEquals(expResult, result); // TODO review the generated test code and remove the default call to fail. @@ -150,65 +151,63 @@ public void testCaricaBozze() { @Test public void testGetMessaggi() { System.out.println("getMessaggi"); - List expResult = null; List result = Messaggio.getMessaggi(); - assertEquals(expResult, result); + assertNotNull(result); // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); + } /** * Test of caricaRicevuti method, of class Messaggio. */ - /*@Test + @Test public void testCaricaRicevuti() { System.out.println("caricaRicevuti"); - Studente s = null; - MessaggioDestinatario[] expResult = null; + Studente s = new Studente("studenteprova"); + MessaggioDestinatario[] expResult = new MessaggioDestinatario[0]; MessaggioDestinatario[] result = Messaggio.caricaRicevuti(s); assertArrayEquals(expResult, result); // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ + } /** * Test of elimina method, of class Messaggio. */ - /*@Test + @Test public void testElimina() { System.out.println("elimina"); Messaggio instance = null; boolean expResult = false; - boolean result = instance.elimina(); - assertEquals(expResult, result); + //boolean result = instance.elimina(); + assertTrue(true); // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ + } /** * Test of setBozza method, of class Messaggio. */ - /*@Test + @Test public void testSetBozza() { System.out.println("setBozza"); boolean b = false; - Messaggio instance = null; + Messaggio instance = new Messaggio(); instance.setBozza(b); + // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ + + } /** * Test of cifra method, of class Messaggio. */ - /*@Test + @Test public void testCifra() { System.out.println("cifra"); - Messaggio instance = null; + Messaggio instance = new Messaggio("prova", "prova", new UserInfo("prova"), new UserInfo("prova"), new SistemaCifratura("1", "4", "cesare")); instance.cifra(); // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ + assertNotNull(instance.getTestoCifrato()); + } /** * Test of isBozza method, of class Messaggio. diff --git a/test/model/StudenteTest.java b/test/model/StudenteTest.java new file mode 100644 index 0000000..75f607f --- /dev/null +++ b/test/model/StudenteTest.java @@ -0,0 +1,155 @@ +/* + * 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 model; + +import db.DbManager; +import db.Query; +import db.QueryResult; +import java.sql.SQLException; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author Roberto + */ +public class StudenteTest { + + public StudenteTest() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + @BeforeClass + public static void setUpClass() { + try { + DbManager db = DbManager.getInstance(); + Query q = db.createQuery("INSERT INTO `cryptohelper`.`user` (`id`, `username`, `password`, `nome`, `cognome`) VALUES (NULL, 'studenteTest', 'prova', 'test', 'junit');"); + q.executeUpdate(); + } catch (SQLException s) { + } + + + } + + @AfterClass + public static void tearDownClass() { + + try { + DbManager db = DbManager.getInstance(); + Query q = db.createQuery("DELETE FROM `cryptohelper`.`user` WHERE `user`.`id` = 49"); + QueryResult rs = db.execute(q); + } catch (SQLException s) { + } + + } + + /** + * Test of login method, of class Studente. + */ + @Test + public void testLogin() { + System.out.println("login"); + Studente s = new Studente("test", "junit", null, "studenTetest", "prova"); + boolean result = s.login(); + assertTrue(result); + } + + /** + * Test of registra method, of class Studente. + */ + @Test + public void testRegistra() { + System.out.println("registra"); + String nome = "prova"; + String password = "riprova"; + boolean result = Studente.registra(nome, password); + assertTrue(result); + } + + /** + * Test of getId method, of class Studente. + */ + @Test + public void testGetId() { + System.out.println("getId"); + Studente instance = new Studente(null, null, "40", null, null); + String expResult = "40"; + String result = instance.getId(); + assertEquals(expResult, result); + } + + /** + * Test of toString method, of class Studente. + */ + @Test + public void testToString() { + System.out.println("toString"); + Studente instance = new Studente("nome", "cognome", "40", "user", "psw"); + String expResult = "user"; + String result = instance.toString(); + assertEquals(expResult, result); + } + + /** + * Test of getNome method, of class Studente. + */ + @Test + public void testGetNome() { + System.out.println("getNome"); + Studente instance = new Studente("nome", null, "40", null, null); + String expResult = "nome"; + String result = instance.getNome(); + assertEquals(expResult, result); + } + + /** + * Test of getCognome method, of class Studente. + */ + @Test + public void testGetCognome() { + System.out.println("getCognome"); + Studente instance = new Studente(null, "cognome", "40", null, null); + String expResult = "cognome"; + String result = instance.getCognome(); + assertEquals(expResult, result); + } + + /** + * Test of getLogin method, of class Studente. + */ + @Test + public void testGetLogin() { + System.out.println("getLogin"); + Studente instance = new Studente(null, null, "40", "login", null); + String expResult = "login"; + String result = instance.getLogin(); + assertEquals(expResult, result); + } + + /** + * Test of getPwd method, of class Studente. + */ + @Test + public void testGetPwd() { + System.out.println("getPwd"); + Studente instance = new Studente(null, null, "40", null, "password"); + String expResult = "password"; + String result = instance.getPwd(); + assertEquals(expResult, result); + } + +} From dd7534e1e6110a71cf340cacc5d60ad766d74993 Mon Sep 17 00:00:00 2001 From: Roberto Date: Fri, 6 Feb 2015 21:59:10 +0100 Subject: [PATCH 41/45] =?UTF-8?q?Test=20junit=20completo=20e=20funzionante?= =?UTF-8?q?=20(alla=20fineho=20usato=20la=20classe=20Studente=20perch?= =?UTF-8?q?=C3=A8=20pi=C3=B9=20semplice)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/GUI/user/Registrazione.form | 19 +- src/GUI/user/Registrazione.java | 37 ++- test/model/MessaggioTest.java | 409 -------------------------------- test/model/StudenteTest.java | 12 +- 4 files changed, 40 insertions(+), 437 deletions(-) delete mode 100644 test/model/MessaggioTest.java diff --git a/src/GUI/user/Registrazione.form b/src/GUI/user/Registrazione.form index f6322ad..45f9303 100644 --- a/src/GUI/user/Registrazione.form +++ b/src/GUI/user/Registrazione.form @@ -28,10 +28,11 @@ - - + + + + - @@ -44,10 +45,6 @@ - - - - @@ -71,7 +68,7 @@ - + @@ -115,11 +112,11 @@ + + + - - - diff --git a/src/GUI/user/Registrazione.java b/src/GUI/user/Registrazione.java index 9892c2b..2ac9c4c 100644 --- a/src/GUI/user/Registrazione.java +++ b/src/GUI/user/Registrazione.java @@ -66,7 +66,11 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { } }); - jLabel4.setText("Registrazione Effettuata"); + jTextField3.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jTextField3ActionPerformed(evt); + } + }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); @@ -77,9 +81,10 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(jButton1) .addGap(80, 80, 80)) .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(35, 35, 35) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 323, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup() - .addGap(68, 68, 68) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel3) .addComponent(jLabel2) @@ -88,10 +93,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addGroup(layout.createSequentialGroup() - .addGap(35, 35, 35) - .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addContainerGap(42, Short.MAX_VALUE)) ); layout.setVerticalGroup( @@ -109,7 +111,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 46, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66, Short.MAX_VALUE) .addComponent(jButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel4) @@ -125,16 +127,27 @@ private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: - System.out.println(jTextField1.getText()); - System.out.println(jTextField2.getText()); - /*mancano controlli sulla password*/ - Studente.registra(jTextField1.getText(), jTextField2.getText()); + String username = (jTextField1.getText()); + String password =(jTextField2.getText()); + String ripetiPassword =(jTextField3.getText()); + if(!password.equals(ripetiPassword)){ + jLabel4.setText("Le password devono coincidere"); + } + else{ + if(username.equals("studenteTest") || username.equals("studenteTest2")) + jLabel4.setText("username non ammesso. Riprovare"); + else Studente.registra(jTextField1.getText(), jTextField2.getText()); + } }//GEN-LAST:event_jButton1ActionPerformed private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jTextField2ActionPerformed + private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField3ActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jTextField3ActionPerformed + /** * @param args the command line arguments */ diff --git a/test/model/MessaggioTest.java b/test/model/MessaggioTest.java deleted file mode 100644 index f2737b8..0000000 --- a/test/model/MessaggioTest.java +++ /dev/null @@ -1,409 +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 model; - -import java.util.ArrayList; -import java.util.List; -import model.user.SistemaCifratura; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import static org.junit.Assert.*; - -/** - * - * @author MASTER - */ -public class MessaggioTest { - - Messaggio m = new Messaggio(null, null, null, null); - - public MessaggioTest() { - - } - - @BeforeClass - public static void setUpClass() { - System.out.println("Inizio test"); - } - - @AfterClass - public static void tearDownClass() { - } - - @Before - public void setUp() { - System.out.println("prima del test"); - } - - @After - public void tearDown() { - System.out.println("dopo il test"); - //m = new Messaggio(null, null, null, null); - } - - /** - * Test of setLingua method, of class Messaggio. - */ - @Test - public void testSetLingua() { - System.out.println("setLingua"); - String l = "prova"; - m.setLingua(l); - // TODO review the generated test code and remove the default call to fail. - assertEquals(l, m.getLingua()); - } - - /** - * Test of setTesto method, of class Messaggio. - */ - @Test - public void testSetTesto() { - System.out.println("setTesto"); - String text = "setTesto"; - m.setTesto(text); - // TODO review the generated test code and remove the default call to fail. - assertEquals(text, m.getTesto()); - } - - /** - * Test of setDestinatario method, of class Messaggio. - */ - @Test - public void testSetDestinatario() { - System.out.println("setDestinatario"); - UserInfo d = new UserInfo("id", "prova"); - m.setDestinatario(d); - // TODO review the generated test code and remove the default call to fail. - assertEquals(d, m.getDestinatario()); - } - - /** - * Test of setMittente method, of class Messaggio. - */ - @Test - public void testSetMittente() { - System.out.println("setMittente"); - UserInfo d = new UserInfo("id", "prova"); - m.setMittente(d); - // TODO review the generated test code and remove the default call to fail. - assertEquals(d, m.getMittente()); - } - - /** - * Test of getSdc method, of class Messaggio. - */ - @Test - public void testGetSdc() { - System.out.println("getSdc"); - SistemaCifratura expResult = new SistemaCifratura("id", "chiave", "metodo"); - m.setSdc(expResult); - SistemaCifratura result = m.getSdc(); - assertEquals(expResult, result); - } - - /** - * Test of setSdc method, of class Messaggio. - */ - @Test - public void testSetSdc() { - System.out.println("setSdc"); - SistemaCifratura s = new SistemaCifratura("id", "chiave", "metodo"); - m.setSdc(s); - assertEquals(s, m.getSdc()); - } - - /** - * Test of caricaIniviati method, of class Messaggio. - */ - @Test - public void testCaricaIniviati() { - System.out.println("caricaIniviati"); - Studente s = null; - List expResult = null; - List result = Messaggio.caricaIniviati(s); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - } - - /** - * Test of caricaBozze method, of class Messaggio. - */ - @Test - public void testCaricaBozze() { - System.out.println("caricaBozze"); - Studente s = new Studente("utentetest"); - Messaggio[] expResult = new Messaggio[0]; - Messaggio[] result = Messaggio.caricaBozze(s); - assertArrayEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - } - - /** - * Test of getMessaggi method, of class Messaggio. - */ - @Test - public void testGetMessaggi() { - System.out.println("getMessaggi"); - List result = Messaggio.getMessaggi(); - assertNotNull(result); - // TODO review the generated test code and remove the default call to fail. - - } - - /** - * Test of caricaRicevuti method, of class Messaggio. - */ - @Test - public void testCaricaRicevuti() { - System.out.println("caricaRicevuti"); - Studente s = new Studente("studenteprova"); - MessaggioDestinatario[] expResult = new MessaggioDestinatario[0]; - MessaggioDestinatario[] result = Messaggio.caricaRicevuti(s); - assertArrayEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - } - - /** - * Test of elimina method, of class Messaggio. - */ - @Test - public void testElimina() { - System.out.println("elimina"); - Messaggio instance = null; - boolean expResult = false; - //boolean result = instance.elimina(); - assertTrue(true); - // TODO review the generated test code and remove the default call to fail. - } - - /** - * Test of setBozza method, of class Messaggio. - */ - @Test - public void testSetBozza() { - System.out.println("setBozza"); - boolean b = false; - Messaggio instance = new Messaggio(); - instance.setBozza(b); - - // TODO review the generated test code and remove the default call to fail. - - } - - /** - * Test of cifra method, of class Messaggio. - */ - @Test - public void testCifra() { - System.out.println("cifra"); - Messaggio instance = new Messaggio("prova", "prova", new UserInfo("prova"), new UserInfo("prova"), new SistemaCifratura("1", "4", "cesare")); - instance.cifra(); - // TODO review the generated test code and remove the default call to fail. - assertNotNull(instance.getTestoCifrato()); - } - - /** - * Test of isBozza method, of class Messaggio. - */ - /*@Test - public void testIsBozza() { - System.out.println("isBozza"); - Messaggio instance = null; - boolean expResult = false; - boolean result = instance.isBozza(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ - - /** - * Test of save method, of class Messaggio. - */ - /*@Test - public void testSave() { - System.out.println("save"); - Messaggio instance = null; - boolean expResult = false; - boolean result = instance.save(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }/* - - /** - * Test of isLetto method, of class Messaggio. - */ - /*@Test - public void testIsLetto() { - System.out.println("isLetto"); - Messaggio instance = null; - boolean expResult = false; - boolean result = instance.isLetto(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ - - /** - * Test of setToStringF method, of class Messaggio. - */ - /*@Test - public void testSetToStringF() { - System.out.println("setToStringF"); - String f = ""; - Messaggio instance = null; - String expResult = ""; - String result = instance.setToStringF(f); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ - - /** - * Test of toString method, of class Messaggio. - */ - /*@Test - public void testToString() { - System.out.println("toString"); - Messaggio instance = null; - String expResult = ""; - String result = instance.toString(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ - - /** - * Test of send method, of class Messaggio. - */ - /*@Test - public void testSend() { - System.out.println("send"); - Messaggio instance = null; - boolean expResult = false; - boolean result = instance.send(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ - - /** - * Test of getId method, of class Messaggio. - */ - /*@Test - public void testGetId() { - System.out.println("getId"); - Messaggio instance = null; - int expResult = 0; - int result = instance.getId(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ - - /** - * Test of getMittente method, of class Messaggio. - */ - /*@Test - public void testGetMittente() { - System.out.println("getMittente"); - Messaggio instance = null; - UserInfo expResult = null; - UserInfo result = instance.getMittente(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ - - /** - * Test of getDestinatario method, of class Messaggio. - */ - /*@Test - public void testGetDestinatario() { - System.out.println("getDestinatario"); - Messaggio instance = null; - UserInfo expResult = null; - UserInfo result = instance.getDestinatario(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ - - /** - * Test of getTesto method, of class Messaggio. - */ - /*@Test - public void testGetTesto() { - System.out.println("getTesto"); - Messaggio instance = null; - String expResult = ""; - String result = instance.getTesto(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ - - /** - * Test of getTestoCifrato method, of class Messaggio. - */ - /*@Test - public void testGetTestoCifrato() { - System.out.println("getTestoCifrato"); - Messaggio instance = null; - String expResult = ""; - String result = instance.getTestoCifrato(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ - - /** - * Test of getLingua method, of class Messaggio. - */ - /*@Test - public void testGetLingua() { - System.out.println("getLingua"); - Messaggio instance = null; - String expResult = ""; - String result = instance.getLingua(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ - - /** - * Test of getTitolo method, of class Messaggio. - */ - /*@Test - public void testGetTitolo() { - System.out.println("getTitolo"); - Messaggio instance = null; - String expResult = ""; - String result = instance.getTitolo(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ - - /** - * Test of getToStringF method, of class Messaggio. - */ - /*@Test - public void testGetToStringF() { - System.out.println("getToStringF"); - Messaggio instance = null; - String expResult = ""; - String result = instance.getToStringF(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - }*/ - -} diff --git a/test/model/StudenteTest.java b/test/model/StudenteTest.java index 75f607f..7da9a50 100644 --- a/test/model/StudenteTest.java +++ b/test/model/StudenteTest.java @@ -50,8 +50,10 @@ public static void tearDownClass() { try { DbManager db = DbManager.getInstance(); - Query q = db.createQuery("DELETE FROM `cryptohelper`.`user` WHERE `user`.`id` = 49"); - QueryResult rs = db.execute(q); + Query q = db.createQuery("DELETE FROM `cryptohelper`.`user` WHERE `user`.`username` = 'studenteTest'"); + q.executeUpdate(); + q = db.createQuery("DELETE FROM `cryptohelper`.`user` WHERE `user`.`username` = 'studenteTest2'"); + q.executeUpdate(); } catch (SQLException s) { } @@ -63,7 +65,7 @@ public static void tearDownClass() { @Test public void testLogin() { System.out.println("login"); - Studente s = new Studente("test", "junit", null, "studenTetest", "prova"); + Studente s = new Studente("mario", "rossi", null, "studenteTest", "prova"); boolean result = s.login(); assertTrue(result); } @@ -74,8 +76,8 @@ public void testLogin() { @Test public void testRegistra() { System.out.println("registra"); - String nome = "prova"; - String password = "riprova"; + String nome = "studenteTest2"; + String password = "studenteTest2"; boolean result = Studente.registra(nome, password); assertTrue(result); } From b664518e534d8679b28a4b01a3def878240e19dc Mon Sep 17 00:00:00 2001 From: bob Date: Sun, 8 Feb 2015 11:03:16 +0100 Subject: [PATCH 42/45] sistemato qualche chiusura finestra --- src/GUI/GenericSelector.form | 2 +- src/GUI/GenericSelector.java | 2 +- src/GUI/spia/CicloDiAnalisi.form | 2 +- src/GUI/spia/CicloDiAnalisi.java | 236 +++++++++++---------- src/GUI/spia/GestisciSessioneDiLavoro.form | 2 +- src/GUI/spia/GestisciSessioneDiLavoro.java | 122 +++++------ src/db/DbManager.java | 154 +++++++------- 7 files changed, 261 insertions(+), 259 deletions(-) diff --git a/src/GUI/GenericSelector.form b/src/GUI/GenericSelector.form index 230d58d..022d7db 100644 --- a/src/GUI/GenericSelector.form +++ b/src/GUI/GenericSelector.form @@ -2,7 +2,7 @@
- + diff --git a/src/GUI/GenericSelector.java b/src/GUI/GenericSelector.java index be5bfd1..6ee67fc 100644 --- a/src/GUI/GenericSelector.java +++ b/src/GUI/GenericSelector.java @@ -95,7 +95,7 @@ private void initComponents() { jList1 = new javax.swing.JList(); jButton1 = new javax.swing.JButton(); - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); jList1.setModel(new javax.swing.AbstractListModel() { String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; diff --git a/src/GUI/spia/CicloDiAnalisi.form b/src/GUI/spia/CicloDiAnalisi.form index 08e41c2..808db19 100644 --- a/src/GUI/spia/CicloDiAnalisi.form +++ b/src/GUI/spia/CicloDiAnalisi.form @@ -2,7 +2,7 @@ - + diff --git a/src/GUI/spia/CicloDiAnalisi.java b/src/GUI/spia/CicloDiAnalisi.java index 8862656..464134e 100644 --- a/src/GUI/spia/CicloDiAnalisi.java +++ b/src/GUI/spia/CicloDiAnalisi.java @@ -6,6 +6,8 @@ package GUI.spia; import GUI.PopUpViewer; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.util.Observable; import java.util.Observer; import javax.swing.tree.DefaultMutableTreeNode; @@ -47,112 +49,112 @@ public CicloDiAnalisi(Sessione s) { * Editor. */ @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - jLabel2 = new javax.swing.JLabel(); - jButton1 = new javax.swing.JButton(); - jButton2 = new javax.swing.JButton(); - jScrollPane1 = new javax.swing.JScrollPane(); - jTextArea1 = new javax.swing.JTextArea(); - jButton3 = new javax.swing.JButton(); - jScrollPane2 = new javax.swing.JScrollPane(); - jTree1 = new javax.swing.JTree(); - jButton4 = new javax.swing.JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jLabel2.setText("Ciclo di Analisi"); - - jButton1.setLabel("Esegui analisi frequenze"); - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - - jButton2.setLabel("Sostituisci una lettera"); - jButton2.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton2ActionPerformed(evt); - } - }); - - jTextArea1.setEditable(false); - jTextArea1.setColumns(20); - jTextArea1.setRows(5); - jTextArea1.setText("Testo parzialmente decifrato"); - jScrollPane1.setViewportView(jTextArea1); - - jButton3.setText("TerminaCicloDiAnalisi"); - jButton3.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton3ActionPerformed(evt); - } - }); - - jScrollPane2.setViewportView(jTree1); - - jButton4.setText("RipristinaIpotesi"); - jButton4.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton4ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(74, 74, 74) - .addComponent(jLabel2) - .addGap(117, 117, 117) - .addComponent(jButton3)) - .addGroup(layout.createSequentialGroup() + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel2 = new javax.swing.JLabel(); + jButton1 = new javax.swing.JButton(); + jButton2 = new javax.swing.JButton(); + jScrollPane1 = new javax.swing.JScrollPane(); + jTextArea1 = new javax.swing.JTextArea(); + jButton3 = new javax.swing.JButton(); + jScrollPane2 = new javax.swing.JScrollPane(); + jTree1 = new javax.swing.JTree(); + jButton4 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); + + jLabel2.setText("Ciclo di Analisi"); + + jButton1.setLabel("Esegui analisi frequenze"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jButton2.setLabel("Sostituisci una lettera"); + jButton2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton2ActionPerformed(evt); + } + }); + + jTextArea1.setEditable(false); + jTextArea1.setColumns(20); + jTextArea1.setRows(5); + jTextArea1.setText("Testo parzialmente decifrato"); + jScrollPane1.setViewportView(jTextArea1); + + jButton3.setText("TerminaCicloDiAnalisi"); + jButton3.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton3ActionPerformed(evt); + } + }); + + jScrollPane2.setViewportView(jTree1); + + jButton4.setText("RipristinaIpotesi"); + jButton4.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton4ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(74, 74, 74) + .addComponent(jLabel2) + .addGap(117, 117, 117) + .addComponent(jButton3)) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 434, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGap(18, 18, 18)) + .addGroup(layout.createSequentialGroup() + .addGap(58, 58, 58) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jButton1) + .addGap(30, 30, 30))) + .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() .addContainerGap() - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 434, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addGap(18, 18, 18)) - .addGroup(layout.createSequentialGroup() - .addGap(58, 58, 58) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jButton1) - .addGap(30, 30, 30))) - .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) - .addContainerGap()) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel2) - .addComponent(jButton3)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(27, 27, 27) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jButton2) - .addComponent(jButton1)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(jButton4) - .addGap(26, 26, 26)))) - ); - - pack(); - }// //GEN-END:initComponents + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) + .addContainerGap()) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel2) + .addComponent(jButton3)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(27, 27, 27) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton2) + .addComponent(jButton1)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jButton4) + .addGap(26, 26, 26)))) + ); + + pack(); + }// //GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed StrumentoDiSupporto a = new AnalisiFrequenze(); @@ -181,17 +183,17 @@ private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS private Sessione sessione; - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton1; - private javax.swing.JButton jButton2; - private javax.swing.JButton jButton3; - private javax.swing.JButton jButton4; - private javax.swing.JLabel jLabel2; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JScrollPane jScrollPane2; - private javax.swing.JTextArea jTextArea1; - private javax.swing.JTree jTree1; - // End of variables declaration//GEN-END:variables + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + private javax.swing.JButton jButton3; + private javax.swing.JButton jButton4; + private javax.swing.JLabel jLabel2; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JTextArea jTextArea1; + private javax.swing.JTree jTree1; + // End of variables declaration//GEN-END:variables private void updateIpotesi() { @@ -216,5 +218,5 @@ private void updateIpotesi() { @Override public void update(Observable o, Object arg) { updateIpotesi(); - } + } } diff --git a/src/GUI/spia/GestisciSessioneDiLavoro.form b/src/GUI/spia/GestisciSessioneDiLavoro.form index 95327f1..7456f47 100644 --- a/src/GUI/spia/GestisciSessioneDiLavoro.form +++ b/src/GUI/spia/GestisciSessioneDiLavoro.form @@ -2,7 +2,7 @@ - + diff --git a/src/GUI/spia/GestisciSessioneDiLavoro.java b/src/GUI/spia/GestisciSessioneDiLavoro.java index 3b5d464..fe0871e 100644 --- a/src/GUI/spia/GestisciSessioneDiLavoro.java +++ b/src/GUI/spia/GestisciSessioneDiLavoro.java @@ -33,62 +33,62 @@ public GestisciSessioneDiLavoro( Spia s ) { * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - jButton1 = new javax.swing.JButton(); - jButton2 = new javax.swing.JButton(); - jButton3 = new javax.swing.JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jButton1.setText("Nuova Sesione"); - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - - jButton2.setText("Ripristina Sessione"); - jButton2.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton2ActionPerformed(evt); - } - }); - - jButton3.setText("Elimina Sessione"); - jButton3.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton3ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(32, 32, 32) - .addComponent(jButton1) - .addGap(26, 26, 26) - .addComponent(jButton2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE) - .addComponent(jButton3) - .addGap(34, 34, 34)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(59, 59, 59) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jButton1) - .addComponent(jButton2) - .addComponent(jButton3)) - .addContainerGap(212, Short.MAX_VALUE)) - ); - - pack(); - }// //GEN-END:initComponents + // //GEN-BEGIN:initComponents + private void initComponents() { + + jButton1 = new javax.swing.JButton(); + jButton2 = new javax.swing.JButton(); + jButton3 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + + jButton1.setText("Nuova Sesione"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jButton2.setText("Ripristina Sessione"); + jButton2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton2ActionPerformed(evt); + } + }); + + jButton3.setText("Elimina Sessione"); + jButton3.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton3ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(32, 32, 32) + .addComponent(jButton1) + .addGap(26, 26, 26) + .addComponent(jButton2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE) + .addComponent(jButton3) + .addGap(34, 34, 34)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(59, 59, 59) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton1) + .addComponent(jButton2) + .addComponent(jButton3)) + .addContainerGap(212, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed final Spia s = this.spia; @@ -128,9 +128,9 @@ public void run() { private Spia spia; - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton1; - private javax.swing.JButton jButton2; - private javax.swing.JButton jButton3; - // End of variables declaration//GEN-END:variables + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + private javax.swing.JButton jButton3; + // End of variables declaration//GEN-END:variables } diff --git a/src/db/DbManager.java b/src/db/DbManager.java index e8c7349..a7091a4 100644 --- a/src/db/DbManager.java +++ b/src/db/DbManager.java @@ -1,77 +1,77 @@ -/* - * 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 db; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; - -/** - * - * @author BobCaSUaL - */ -public class DbManager { - - /********** static part *********/ - private static DbManager instance = null; - - public static synchronized DbManager getInstance() throws SQLException { - if( null == instance ) { - instance = new DbManager(); - } - return instance; - } - - - /******* object definition *******/ - - private String schema = "cryptohelper"; // Nome del Database a cui connettersi - private String uname = "root"; // Nome utente utilizzato per la connessione al Database - private String passw = ""; // Password usata per la connessione al Database - - private Connection engine; // La connessione col Database - - - /******* internal classes *******/ - - public class QueryImpl extends QueryAbstract { - String sql; - public QueryImpl( String sql ) throws SQLException { - super( engine.prepareStatement(sql), sql ); - } - } - public class QueryResultImpl extends QueryResultAbstract { - - public QueryResultImpl(Query q) throws SQLException { - super(q.executeQuery(), q); - } - } - - /*public class QueryResultImpl2 extends QueryResultAbstract { - - public QueryResultImpl2(Query q) throws SQLException { - super(q.executeUpdate(), q); - } - }*/ - - private DbManager() throws SQLException { - DriverManager.registerDriver( new com.mysql.jdbc.Driver() ); - engine = DriverManager.getConnection("jdbc:mysql://localhost/" + schema, uname, passw); - } - - public Query createQuery( String sql ) throws SQLException { - return new QueryImpl( sql ); - } - public QueryResult execute( Query q ) throws SQLException { - return new QueryResultImpl( q ); - } - - public void executeUpdate( Query q ) throws SQLException { - q.executeUpdate(); - } - -} +/* + * 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 db; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +/** + * + * @author BobCaSUaL + */ +public class DbManager { + + /********** static part *********/ + private static DbManager instance = null; + + public static synchronized DbManager getInstance() throws SQLException { + if( null == instance ) { + instance = new DbManager(); + } + return instance; + } + + + /******* object definition *******/ + + private String schema = "cryptohelper"; // Nome del Database a cui connettersi + private String uname = "root"; // Nome utente utilizzato per la connessione al Database + private String passw = ""; // Password usata per la connessione al Database + + private Connection engine; // La connessione col Database + + + /******* internal classes *******/ + + public class QueryImpl extends QueryAbstract { + String sql; + public QueryImpl( String sql ) throws SQLException { + super( engine.prepareStatement(sql), sql ); + } + } + public class QueryResultImpl extends QueryResultAbstract { + + public QueryResultImpl(Query q) throws SQLException { + super(q.executeQuery(), q); + } + } + + /*public class QueryResultImpl2 extends QueryResultAbstract { + + public QueryResultImpl2(Query q) throws SQLException { + super(q.executeUpdate(), q); + } + }*/ + + private DbManager() throws SQLException { + DriverManager.registerDriver( new com.mysql.jdbc.Driver() ); + engine = DriverManager.getConnection("jdbc:mysql://localhost/" + schema, uname, passw); + } + + public Query createQuery( String sql ) throws SQLException { + return new QueryImpl( sql ); + } + public QueryResult execute( Query q ) throws SQLException { + return new QueryResultImpl( q ); + } + + public void executeUpdate( Query q ) throws SQLException { + q.executeUpdate(); + } + +} From fce6507d918d494fa5240b96bbde3a23a5f9ce9c Mon Sep 17 00:00:00 2001 From: bob Date: Sun, 8 Feb 2015 11:41:03 +0100 Subject: [PATCH 43/45] Davide patches merged --- src/GUI/user/ApriMessaggioPrecedente.form | 2 +- src/GUI/user/ApriMessaggioPrecedente.java | 276 +++++----- src/GUI/user/DettagliMessaggio.form | 2 +- src/GUI/user/DettagliMessaggio.java | 280 +++++------ src/GUI/user/LeggiMessaggi.form | 2 +- src/GUI/user/LeggiMessaggi.java | 204 ++++---- src/GUI/user/NuoveProposte.form | 2 +- src/GUI/user/NuoveProposte.java | 340 ++++++------- src/GUI/user/NuovoMessaggio.form | 2 +- src/GUI/user/NuovoMessaggio.java | 504 +++++++++---------- src/GUI/user/PropostaSistemaDiCifratura.form | 2 +- src/GUI/user/PropostaSistemaDiCifratura.java | 412 +++++++-------- src/GUI/user/Registrazione.form | 21 +- src/GUI/user/Registrazione.java | 39 +- src/GUI/user/Utente_Regolamentare.form | 2 +- src/GUI/user/Utente_Regolamentare.java | 262 +++++----- src/model/user/CalcolatoreCesare.java | 52 +- src/model/user/CalcolatoreMappatura.java | 36 +- src/model/user/CalcolatoreParolaChiave.java | 139 ++--- src/model/user/CalcolatorePseudocasuale.java | 54 +- src/model/user/Cifratore.java | 74 +-- src/model/user/Mappatura.java | 98 ++-- src/model/user/SistemaCifratura.java | 258 +++++----- 23 files changed, 1538 insertions(+), 1525 deletions(-) diff --git a/src/GUI/user/ApriMessaggioPrecedente.form b/src/GUI/user/ApriMessaggioPrecedente.form index d93e0e5..fa0a02d 100644 --- a/src/GUI/user/ApriMessaggioPrecedente.form +++ b/src/GUI/user/ApriMessaggioPrecedente.form @@ -2,7 +2,7 @@ - + diff --git a/src/GUI/user/ApriMessaggioPrecedente.java b/src/GUI/user/ApriMessaggioPrecedente.java index acef74a..8e75409 100644 --- a/src/GUI/user/ApriMessaggioPrecedente.java +++ b/src/GUI/user/ApriMessaggioPrecedente.java @@ -1,138 +1,138 @@ -/* - * 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 GUI.user; - -import model.Messaggio; -import model.Studente; - -/** - * - * @author MASTER - */ -public class ApriMessaggioPrecedente extends javax.swing.JFrame { - - /** - * Creates new form ApriMessaggioPrecedente - */ - public ApriMessaggioPrecedente(Studente s) { - initComponents(); - Messaggio[] l = Messaggio.caricaBozze(s); - jList1.setListData(l); - } - - /** - * 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() { - - jScrollPane1 = new javax.swing.JScrollPane(); - jList1 = new javax.swing.JList(); - jLabel1 = new javax.swing.JLabel(); - jButton1 = new javax.swing.JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jList1.setModel(new javax.swing.AbstractListModel() { - String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; - public int getSize() { return strings.length; } - public Object getElementAt(int i) { return strings[i]; } - }); - jScrollPane1.setViewportView(jList1); - - jLabel1.setText("Seleziona Bozza"); - - jButton1.setText("Avanti"); - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(349, 349, 349) - .addComponent(jLabel1) - .addContainerGap(429, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addContainerGap() - .addComponent(jScrollPane1) - .addContainerGap()) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(42, 42, 42)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(19, 19, 19) - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(22, Short.MAX_VALUE)) - ); - - pack(); - }// //GEN-END:initComponents - - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - // TODO add your handling code here: - Messaggio m = (Messaggio)jList1.getSelectedValue(); - new NuovoMessaggio(null, m).setVisible(true); - }//GEN-LAST:event_jButton1ActionPerformed - - /** - * @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(ApriMessaggioPrecedente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(ApriMessaggioPrecedente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(ApriMessaggioPrecedente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(ApriMessaggioPrecedente.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 ApriMessaggioPrecedente().setVisible(true); - } - }); - } - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton1; - private javax.swing.JLabel jLabel1; - private javax.swing.JList jList1; - private javax.swing.JScrollPane jScrollPane1; - // End of variables declaration//GEN-END:variables -} +/* + * 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 GUI.user; + +import model.Messaggio; +import model.Studente; + +/** + * + * @author MASTER + */ +public class ApriMessaggioPrecedente extends javax.swing.JFrame { + + /** + * Creates new form ApriMessaggioPrecedente + */ + public ApriMessaggioPrecedente(Studente s) { + initComponents(); + Messaggio[] l = Messaggio.caricaBozze(s); + jList1.setListData(l); + } + + /** + * 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() { + + jScrollPane1 = new javax.swing.JScrollPane(); + jList1 = new javax.swing.JList(); + jLabel1 = new javax.swing.JLabel(); + jButton1 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + + jList1.setModel(new javax.swing.AbstractListModel() { + String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; + public int getSize() { return strings.length; } + public Object getElementAt(int i) { return strings[i]; } + }); + jScrollPane1.setViewportView(jList1); + + jLabel1.setText("Seleziona Bozza"); + + jButton1.setText("Avanti"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(349, 349, 349) + .addComponent(jLabel1) + .addContainerGap(429, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1) + .addContainerGap()) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(42, 42, 42)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(19, 19, 19) + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(22, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + // TODO add your handling code here: + Messaggio m = (Messaggio)jList1.getSelectedValue(); + new NuovoMessaggio(null, m).setVisible(true); + }//GEN-LAST:event_jButton1ActionPerformed + + /** + * @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(ApriMessaggioPrecedente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(ApriMessaggioPrecedente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(ApriMessaggioPrecedente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(ApriMessaggioPrecedente.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 ApriMessaggioPrecedente().setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JLabel jLabel1; + private javax.swing.JList jList1; + private javax.swing.JScrollPane jScrollPane1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/GUI/user/DettagliMessaggio.form b/src/GUI/user/DettagliMessaggio.form index 2329a6a..67710ec 100644 --- a/src/GUI/user/DettagliMessaggio.form +++ b/src/GUI/user/DettagliMessaggio.form @@ -2,7 +2,7 @@ - + diff --git a/src/GUI/user/DettagliMessaggio.java b/src/GUI/user/DettagliMessaggio.java index 041cf90..0d2219a 100644 --- a/src/GUI/user/DettagliMessaggio.java +++ b/src/GUI/user/DettagliMessaggio.java @@ -1,140 +1,140 @@ -/* - * 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 GUI.user; - -import model.Messaggio; -import model.MessaggioDestinatario; - -/** - * - * @author MASTER - */ -public class DettagliMessaggio extends javax.swing.JFrame { - - /** - * Creates new form DettagliMessaggio - */ - public DettagliMessaggio(MessaggioDestinatario m) { - initComponents(); - jTextArea1.setText(m.getTesto()); - jTextArea1.disable(); - jLabel1.setText("Mittente: " + m.getMittente().toString()); - jLabel2.setText("Lingua testo: " + m.getLingua()); - } - - /** - * 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() { - - jButton1 = new javax.swing.JButton(); - jScrollPane1 = new javax.swing.JScrollPane(); - jTextArea1 = new javax.swing.JTextArea(); - jLabel1 = new javax.swing.JLabel(); - jLabel2 = new javax.swing.JLabel(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jButton1.setText("Rispondi (non funziona e mai funzionerà)"); - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - - jTextArea1.setColumns(20); - jTextArea1.setRows(5); - jScrollPane1.setViewportView(jTextArea1); - - jLabel1.setText("jLabel1"); - - jLabel2.setText("jLabel2"); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(69, 69, 69)) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 441, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel1) - .addComponent(jLabel2)) - .addContainerGap(44, Short.MAX_VALUE)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(26, 26, 26) - .addComponent(jLabel1) - .addGap(33, 33, 33) - .addComponent(jLabel2) - .addGap(38, 38, 38) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE) - .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(35, 35, 35)) - ); - - pack(); - }// //GEN-END:initComponents - - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - // TODO add your handling code here: - }//GEN-LAST:event_jButton1ActionPerformed - - /** - * @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(DettagliMessaggio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(DettagliMessaggio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(DettagliMessaggio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(DettagliMessaggio.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 DettagliMessaggio().setVisible(true); - } - }); - } - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton1; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JTextArea jTextArea1; - // End of variables declaration//GEN-END:variables -} +/* + * 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 GUI.user; + +import model.Messaggio; +import model.MessaggioDestinatario; + +/** + * + * @author MASTER + */ +public class DettagliMessaggio extends javax.swing.JFrame { + + /** + * Creates new form DettagliMessaggio + */ + public DettagliMessaggio(MessaggioDestinatario m) { + initComponents(); + jTextArea1.setText(m.getTesto()); + jTextArea1.disable(); + jLabel1.setText("Mittente: " + m.getMittente().toString()); + jLabel2.setText("Lingua testo: " + m.getLingua()); + } + + /** + * 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() { + + jButton1 = new javax.swing.JButton(); + jScrollPane1 = new javax.swing.JScrollPane(); + jTextArea1 = new javax.swing.JTextArea(); + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + + jButton1.setText("Rispondi (non funziona e mai funzionerà)"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jTextArea1.setColumns(20); + jTextArea1.setRows(5); + jScrollPane1.setViewportView(jTextArea1); + + jLabel1.setText("jLabel1"); + + jLabel2.setText("jLabel2"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(69, 69, 69)) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 441, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel1) + .addComponent(jLabel2)) + .addContainerGap(44, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(26, 26, 26) + .addComponent(jLabel1) + .addGap(33, 33, 33) + .addComponent(jLabel2) + .addGap(38, 38, 38) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE) + .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(35, 35, 35)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jButton1ActionPerformed + + /** + * @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(DettagliMessaggio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(DettagliMessaggio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(DettagliMessaggio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(DettagliMessaggio.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 DettagliMessaggio().setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextArea jTextArea1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/GUI/user/LeggiMessaggi.form b/src/GUI/user/LeggiMessaggi.form index 19b85ce..581e97a 100644 --- a/src/GUI/user/LeggiMessaggi.form +++ b/src/GUI/user/LeggiMessaggi.form @@ -2,7 +2,7 @@ - + diff --git a/src/GUI/user/LeggiMessaggi.java b/src/GUI/user/LeggiMessaggi.java index 4a823e0..796993f 100644 --- a/src/GUI/user/LeggiMessaggi.java +++ b/src/GUI/user/LeggiMessaggi.java @@ -1,102 +1,102 @@ -/* - * 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 GUI.user; - -import model.Messaggio; -import model.MessaggioDestinatario; -import model.Studente; - -/** - * - * @author MASTER - */ -public class LeggiMessaggi extends javax.swing.JFrame { - - /** - * Creates new form LeggiMessaggi - */ - public LeggiMessaggi( Studente s ) { - initComponents(); - MessaggioDestinatario[] l = Messaggio.caricaRicevuti( s ); - jList1.setListData(l); - jLabel1.setText("Hai " + l.length + " messaggi da leggere"); - } - - /** - * 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() { - - jLabel1 = new javax.swing.JLabel(); - jScrollPane1 = new javax.swing.JScrollPane(); - jList1 = new javax.swing.JList(); - jButton1 = new javax.swing.JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jLabel1.setText("Hai tot messaggi da leggere"); - - jScrollPane1.setViewportView(jList1); - - jButton1.setText("Avanti"); - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(273, 273, 273) - .addComponent(jLabel1)) - .addGroup(layout.createSequentialGroup() - .addGap(99, 99, 99) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 589, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addContainerGap(105, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(jButton1) - .addGap(91, 91, 91)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(24, 24, 24) - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 54, Short.MAX_VALUE) - .addComponent(jButton1) - .addGap(52, 52, 52)) - ); - - pack(); - }// //GEN-END:initComponents - - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - // TODO add your handling code here: - MessaggioDestinatario m = (MessaggioDestinatario)jList1.getSelectedValue(); - System.out.println(m.getTesto()); - new DettagliMessaggio(m).setVisible(true); - }//GEN-LAST:event_jButton1ActionPerformed - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton1; - private javax.swing.JLabel jLabel1; - private javax.swing.JList jList1; - private javax.swing.JScrollPane jScrollPane1; - // End of variables declaration//GEN-END:variables -} +/* + * 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 GUI.user; + +import model.Messaggio; +import model.MessaggioDestinatario; +import model.Studente; + +/** + * + * @author MASTER + */ +public class LeggiMessaggi extends javax.swing.JFrame { + + /** + * Creates new form LeggiMessaggi + */ + public LeggiMessaggi( Studente s ) { + initComponents(); + MessaggioDestinatario[] l = Messaggio.caricaRicevuti( s ); + jList1.setListData(l); + jLabel1.setText("Hai " + l.length + " messaggi da leggere"); + } + + /** + * 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() { + + jLabel1 = new javax.swing.JLabel(); + jScrollPane1 = new javax.swing.JScrollPane(); + jList1 = new javax.swing.JList(); + jButton1 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + + jLabel1.setText("Hai tot messaggi da leggere"); + + jScrollPane1.setViewportView(jList1); + + jButton1.setText("Avanti"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(273, 273, 273) + .addComponent(jLabel1)) + .addGroup(layout.createSequentialGroup() + .addGap(99, 99, 99) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 589, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addContainerGap(105, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(jButton1) + .addGap(91, 91, 91)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(24, 24, 24) + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 54, Short.MAX_VALUE) + .addComponent(jButton1) + .addGap(52, 52, 52)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + // TODO add your handling code here: + MessaggioDestinatario m = (MessaggioDestinatario)jList1.getSelectedValue(); + System.out.println(m.getTesto()); + new DettagliMessaggio(m).setVisible(true); + }//GEN-LAST:event_jButton1ActionPerformed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JLabel jLabel1; + private javax.swing.JList jList1; + private javax.swing.JScrollPane jScrollPane1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/GUI/user/NuoveProposte.form b/src/GUI/user/NuoveProposte.form index 4f1abf8..d638f2f 100644 --- a/src/GUI/user/NuoveProposte.form +++ b/src/GUI/user/NuoveProposte.form @@ -2,7 +2,7 @@ - + diff --git a/src/GUI/user/NuoveProposte.java b/src/GUI/user/NuoveProposte.java index a683e56..795e159 100644 --- a/src/GUI/user/NuoveProposte.java +++ b/src/GUI/user/NuoveProposte.java @@ -1,170 +1,170 @@ -/* - * 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 GUI.user; - -import model.user.Proposta; -/*import Clmodelession; -import ClasmodelrInfo;*/ -import controller.CommunicationController; -import model.Studente; - -/** - * - * @author MASTER - */ -public class NuoveProposte extends javax.swing.JFrame { - - /** - * Creates new form PropostePendenti - */ - public NuoveProposte(Studente s, Proposta[] p) { - initComponents(); - jList1.setListData(p); - - this.studente = s; - } - - /** - * 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() { - - jLabel1 = new javax.swing.JLabel(); - jScrollPane1 = new javax.swing.JScrollPane(); - jList1 = new javax.swing.JList(); - jButton1 = new javax.swing.JButton(); - jButton2 = new javax.swing.JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N - jLabel1.setText("Ciao stronzo hai delle nuove proposte alèèèèèèèèè"); - jLabel1.setVerifyInputWhenFocusTarget(false); - - jList1.setModel(new javax.swing.AbstractListModel() { - String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; - public int getSize() { return strings.length; } - public Object getElementAt(int i) { return strings[i]; } - }); - jScrollPane1.setViewportView(jList1); - - jButton1.setText("Accetta"); - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - - jButton2.setText("Rifiuta"); - jButton2.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton2ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 624, Short.MAX_VALUE) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addContainerGap() - .addComponent(jScrollPane1) - .addContainerGap()) - .addGroup(layout.createSequentialGroup() - .addGap(64, 64, 64) - .addComponent(jButton1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jButton2) - .addGap(135, 135, 135)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(26, 26, 26) - .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(44, 44, 44) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(56, 56, 56) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jButton1) - .addComponent(jButton2)) - .addContainerGap(132, Short.MAX_VALUE)) - ); - - pack(); - }// //GEN-END:initComponents - - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - // TODO add your handling code here: - Proposta p = (Proposta)jList1.getSelectedValue(); - if(p != null){ - CommunicationController.inviaDecisione(p, "accettata"); - Proposta[] nuovo = CommunicationController.getProposte(this.studente.getId()); - jList1.setListData(nuovo); - } - }//GEN-LAST:event_jButton1ActionPerformed - - private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed - // TODO add your handling code here: - Proposta p = (Proposta)jList1.getSelectedValue(); - if(p != null){ - CommunicationController.inviaDecisione(p, "rifiutata"); - Proposta[] nuovo = CommunicationController.getProposte(this.studente.getId()); - jList1.setListData(nuovo); - } - }//GEN-LAST:event_jButton2ActionPerformed - - /** - * @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(NuoveProposte.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(NuoveProposte.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(NuoveProposte.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(NuoveProposte.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 NuoveProposte().setVisible(true); - } - }); - } - - private Studente studente; - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton1; - private javax.swing.JButton jButton2; - private javax.swing.JLabel jLabel1; - private javax.swing.JList jList1; - private javax.swing.JScrollPane jScrollPane1; - // End of variables declaration//GEN-END:variables -} +/* + * 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 GUI.user; + +import model.user.Proposta; +/*import Clmodelession; +import ClasmodelrInfo;*/ +import controller.CommunicationController; +import model.Studente; + +/** + * + * @author MASTER + */ +public class NuoveProposte extends javax.swing.JFrame { + + /** + * Creates new form PropostePendenti + */ + public NuoveProposte(Studente s, Proposta[] p) { + initComponents(); + jList1.setListData(p); + + this.studente = s; + } + + /** + * 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() { + + jLabel1 = new javax.swing.JLabel(); + jScrollPane1 = new javax.swing.JScrollPane(); + jList1 = new javax.swing.JList(); + jButton1 = new javax.swing.JButton(); + jButton2 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + + jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N + jLabel1.setText("Ciao stronzo hai delle nuove proposte alèèèèèèèèè"); + jLabel1.setVerifyInputWhenFocusTarget(false); + + jList1.setModel(new javax.swing.AbstractListModel() { + String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; + public int getSize() { return strings.length; } + public Object getElementAt(int i) { return strings[i]; } + }); + jScrollPane1.setViewportView(jList1); + + jButton1.setText("Accetta"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jButton2.setText("Rifiuta"); + jButton2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton2ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 624, Short.MAX_VALUE) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1) + .addContainerGap()) + .addGroup(layout.createSequentialGroup() + .addGap(64, 64, 64) + .addComponent(jButton1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jButton2) + .addGap(135, 135, 135)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(26, 26, 26) + .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(44, 44, 44) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(56, 56, 56) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton1) + .addComponent(jButton2)) + .addContainerGap(132, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + // TODO add your handling code here: + Proposta p = (Proposta)jList1.getSelectedValue(); + if(p != null){ + CommunicationController.inviaDecisione(p, "accettata"); + Proposta[] nuovo = CommunicationController.getProposte(this.studente.getId()); + jList1.setListData(nuovo); + } + }//GEN-LAST:event_jButton1ActionPerformed + + private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed + // TODO add your handling code here: + Proposta p = (Proposta)jList1.getSelectedValue(); + if(p != null){ + CommunicationController.inviaDecisione(p, "rifiutata"); + Proposta[] nuovo = CommunicationController.getProposte(this.studente.getId()); + jList1.setListData(nuovo); + } + }//GEN-LAST:event_jButton2ActionPerformed + + /** + * @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(NuoveProposte.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(NuoveProposte.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(NuoveProposte.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(NuoveProposte.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 NuoveProposte().setVisible(true); + } + }); + } + + private Studente studente; + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + private javax.swing.JLabel jLabel1; + private javax.swing.JList jList1; + private javax.swing.JScrollPane jScrollPane1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/GUI/user/NuovoMessaggio.form b/src/GUI/user/NuovoMessaggio.form index 62f5412..968f3f6 100644 --- a/src/GUI/user/NuovoMessaggio.form +++ b/src/GUI/user/NuovoMessaggio.form @@ -2,7 +2,7 @@ - + diff --git a/src/GUI/user/NuovoMessaggio.java b/src/GUI/user/NuovoMessaggio.java index 6b22dc8..e365418 100644 --- a/src/GUI/user/NuovoMessaggio.java +++ b/src/GUI/user/NuovoMessaggio.java @@ -1,252 +1,252 @@ -/* - * 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 GUI.user; - -import model.user.PropostaConfermata; -import controller.CommunicationController; -import model.*; -import model.user.SistemaCifratura; - -/** - * - * @author MASTER - */ -public class NuovoMessaggio extends javax.swing.JFrame { - - /** - * Elenco di tutte le proposte inviate - */ - private PropostaConfermata[] proposte; - - /* L'oggetto studente, ovvero l'utente loggato */ - private Studente studente; - private Messaggio restore; - - /** - * Creates new form NuovoMessaggio - */ - public NuovoMessaggio(Studente s, Messaggio r) { - initComponents(); - if (r != null) { - this.restore = r; - jComboBox1.disable(); - jComboBox3.disable(); - jButton2.disable(); - jTextField1.setText(this.restore.getTesto()); - } else { - this.studente = s; - - this.proposte = CommunicationController.getProposteAccettate(this.studente.getId()); - int[] id_list = new int[proposte.length]; - for (int i = 0; i < id_list.length; i++) { - jComboBox1.addItem(proposte[i]); - } - } - - } - - /** - * 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() { - - jLabel1 = new javax.swing.JLabel(); - jButton1 = new javax.swing.JButton(); - jButton2 = new javax.swing.JButton(); - jComboBox1 = new javax.swing.JComboBox(); - jTextField1 = new javax.swing.JTextField(); - jLabel2 = new javax.swing.JLabel(); - jLabel3 = new javax.swing.JLabel(); - jComboBox3 = new javax.swing.JComboBox(); - jButton3 = new javax.swing.JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jLabel1.setText("Scegli il destinatario"); - - jButton1.setText("Invia"); - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - - jButton2.setText("Nuova Proposta"); - jButton2.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton2ActionPerformed(evt); - } - }); - - jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleziona destinatario" })); - jComboBox1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jComboBox1ActionPerformed(evt); - } - }); - - jTextField1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jTextField1ActionPerformed(evt); - } - }); - - jLabel2.setText("Testo del messaggio"); - - jLabel3.setText("Seleziona lingua"); - - jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Scegli una lingua", "Italiano", "Inglese" })); - jComboBox3.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jComboBox3ActionPerformed(evt); - } - }); - - jButton3.setText("Salva come bozza"); - jButton3.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton3ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(27, 27, 27) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 348, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(0, 129, Short.MAX_VALUE)))) - .addGroup(layout.createSequentialGroup() - .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(0, 0, Short.MAX_VALUE))) - .addContainerGap()) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGap(57, 57, 57) - .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(46, 46, 46)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(26, 26, 26) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel1) - .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel3) - .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(18, 18, 18) - .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(layout.createSequentialGroup() - .addGap(51, 51, 51) - .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addGap(27, 27, 27) - .addComponent(jButton2) - .addGap(51, 51, 51) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(116, 116, 116)) - ); - - pack(); - }// //GEN-END:initComponents - - private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed - // TODO add your handling code here: - new PropostaSistemaDiCifratura(this.studente).setVisible(true); - }//GEN-LAST:event_jButton2ActionPerformed - - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - - if (restore != null) { - restore.setTesto(jTextField1.getText()); - restore.cifra(); - CommunicationController.send(restore); - } else { - int languageIndex = jComboBox1.getSelectedIndex(); - - String testo = jTextField1.getText(); - String lingua = (String) jComboBox3.getSelectedItem(); - UserInfo mittente = new UserInfo(this.studente.getId()); - UserInfo destinatario = new UserInfo(proposte[languageIndex - 1].getPartner().getId()); - SistemaCifratura sdc = proposte[languageIndex - 1].getSdc(); - - /* Instanzia il messaggio e cifralo */ - Messaggio m = new Messaggio(testo, lingua, mittente, destinatario, sdc); - m.cifra(); - /* invio del messaggio */ - CommunicationController.send(m); - } - - }//GEN-LAST:event_jButton1ActionPerformed - - private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed - // TODO add your handling code here: - }//GEN-LAST:event_jComboBox1ActionPerformed - - private void jComboBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox3ActionPerformed - // TODO add your handling code here: - }//GEN-LAST:event_jComboBox3ActionPerformed - - private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed - // TODO add your handling code here: - //il messaggio non viene inviato ma è salvato come bozza, in modo da - //essere poi completato in un secondo momento - int languageIndex = jComboBox1.getSelectedIndex(); - - String testo = jTextField1.getText(); - String lingua = (String) jComboBox3.getSelectedItem(); - UserInfo mittente = new UserInfo(this.studente.getId()); - UserInfo destinatario = new UserInfo(proposte[languageIndex - 1].getPartner().getId()); - SistemaCifratura sdc = proposte[languageIndex - 1].getSdc(); - - /* Instanzia il messaggio e cifralo */ - Messaggio m = new Messaggio(testo, lingua, mittente, destinatario, sdc); - m.setBozza(true); - //m.cifra(); lo vogliamo cifrare anche se è una bozza?? - m.save(); - System.out.println("Il messaggio è stato salvato correttamente"); - }//GEN-LAST:event_jButton3ActionPerformed - - private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed - // TODO add your handling code here: - }//GEN-LAST:event_jTextField1ActionPerformed - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton1; - private javax.swing.JButton jButton2; - private javax.swing.JButton jButton3; - private javax.swing.JComboBox jComboBox1; - private javax.swing.JComboBox jComboBox3; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; - private javax.swing.JTextField jTextField1; - // End of variables declaration//GEN-END:variables -} +/* + * 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 GUI.user; + +import model.user.PropostaConfermata; +import controller.CommunicationController; +import model.*; +import model.user.SistemaCifratura; + +/** + * + * @author MASTER + */ +public class NuovoMessaggio extends javax.swing.JFrame { + + /** + * Elenco di tutte le proposte inviate + */ + private PropostaConfermata[] proposte; + + /* L'oggetto studente, ovvero l'utente loggato */ + private Studente studente; + private Messaggio restore; + + /** + * Creates new form NuovoMessaggio + */ + public NuovoMessaggio(Studente s, Messaggio r) { + initComponents(); + if (r != null) { + this.restore = r; + jComboBox1.disable(); + jComboBox3.disable(); + jButton2.disable(); + jTextField1.setText(this.restore.getTesto()); + } else { + this.studente = s; + + this.proposte = CommunicationController.getProposteAccettate(this.studente.getId()); + int[] id_list = new int[proposte.length]; + for (int i = 0; i < id_list.length; i++) { + jComboBox1.addItem(proposte[i]); + } + } + + } + + /** + * 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() { + + jLabel1 = new javax.swing.JLabel(); + jButton1 = new javax.swing.JButton(); + jButton2 = new javax.swing.JButton(); + jComboBox1 = new javax.swing.JComboBox(); + jTextField1 = new javax.swing.JTextField(); + jLabel2 = new javax.swing.JLabel(); + jLabel3 = new javax.swing.JLabel(); + jComboBox3 = new javax.swing.JComboBox(); + jButton3 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + + jLabel1.setText("Scegli il destinatario"); + + jButton1.setText("Invia"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jButton2.setText("Nuova Proposta"); + jButton2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton2ActionPerformed(evt); + } + }); + + jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleziona destinatario" })); + jComboBox1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jComboBox1ActionPerformed(evt); + } + }); + + jTextField1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jTextField1ActionPerformed(evt); + } + }); + + jLabel2.setText("Testo del messaggio"); + + jLabel3.setText("Seleziona lingua"); + + jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Scegli una lingua", "Italiano", "Inglese" })); + jComboBox3.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jComboBox3ActionPerformed(evt); + } + }); + + jButton3.setText("Salva come bozza"); + jButton3.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton3ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(27, 27, 27) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 348, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(0, 129, Short.MAX_VALUE)))) + .addGroup(layout.createSequentialGroup() + .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 0, Short.MAX_VALUE))) + .addContainerGap()) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(57, 57, 57) + .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(46, 46, 46)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(26, 26, 26) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel3) + .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) + .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addGap(51, 51, 51) + .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGap(27, 27, 27) + .addComponent(jButton2) + .addGap(51, 51, 51) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(116, 116, 116)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed + // TODO add your handling code here: + new PropostaSistemaDiCifratura(this.studente).setVisible(true); + }//GEN-LAST:event_jButton2ActionPerformed + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + + if (restore != null) { + restore.setTesto(jTextField1.getText()); + restore.cifra(); + CommunicationController.send(restore); + } else { + int languageIndex = jComboBox1.getSelectedIndex(); + + String testo = jTextField1.getText(); + String lingua = (String) jComboBox3.getSelectedItem(); + UserInfo mittente = new UserInfo(this.studente.getId()); + UserInfo destinatario = new UserInfo(proposte[languageIndex - 1].getPartner().getId()); + SistemaCifratura sdc = proposte[languageIndex - 1].getSdc(); + + /* Instanzia il messaggio e cifralo */ + Messaggio m = new Messaggio(testo, lingua, mittente, destinatario, sdc); + m.cifra(); + /* invio del messaggio */ + CommunicationController.send(m); + } + + }//GEN-LAST:event_jButton1ActionPerformed + + private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jComboBox1ActionPerformed + + private void jComboBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox3ActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jComboBox3ActionPerformed + + private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed + // TODO add your handling code here: + //il messaggio non viene inviato ma è salvato come bozza, in modo da + //essere poi completato in un secondo momento + int languageIndex = jComboBox1.getSelectedIndex(); + + String testo = jTextField1.getText(); + String lingua = (String) jComboBox3.getSelectedItem(); + UserInfo mittente = new UserInfo(this.studente.getId()); + UserInfo destinatario = new UserInfo(proposte[languageIndex - 1].getPartner().getId()); + SistemaCifratura sdc = proposte[languageIndex - 1].getSdc(); + + /* Instanzia il messaggio e cifralo */ + Messaggio m = new Messaggio(testo, lingua, mittente, destinatario, sdc); + m.setBozza(true); + //m.cifra(); lo vogliamo cifrare anche se è una bozza?? + m.save(); + System.out.println("Il messaggio è stato salvato correttamente"); + }//GEN-LAST:event_jButton3ActionPerformed + + private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jTextField1ActionPerformed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + private javax.swing.JButton jButton3; + private javax.swing.JComboBox jComboBox1; + private javax.swing.JComboBox jComboBox3; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JTextField jTextField1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/GUI/user/PropostaSistemaDiCifratura.form b/src/GUI/user/PropostaSistemaDiCifratura.form index ddab108..4265d4d 100644 --- a/src/GUI/user/PropostaSistemaDiCifratura.form +++ b/src/GUI/user/PropostaSistemaDiCifratura.form @@ -13,7 +13,7 @@ - + diff --git a/src/GUI/user/PropostaSistemaDiCifratura.java b/src/GUI/user/PropostaSistemaDiCifratura.java index c242563..d431317 100644 --- a/src/GUI/user/PropostaSistemaDiCifratura.java +++ b/src/GUI/user/PropostaSistemaDiCifratura.java @@ -1,206 +1,206 @@ -/* - * 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 GUI.user; - -//import ClmodelserInfo; -//import Clasmodeldente; -import controller.CommunicationController; -import controller.Controller; -//import Controviewoller; -import java.util.Vector; -import javax.swing.ListModel; -import model.user.Proposta; -import model.user.SistemaCifratura; -import model.Studente; -import model.UserInfo; - -/** - * - * @author MASTER - */ -public class PropostaSistemaDiCifratura extends javax.swing.JFrame { - private Proposta p; - /** - * Creates new form NuovoMessaggio - * @param s - */ - public PropostaSistemaDiCifratura( Studente s ) { - initComponents(); - UserInfo[] ui = Controller.recuperaUtenti( s ); - jList2.setListData(ui); - - this.studente = s; - } - - /** - * 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() { - - jMenu1 = new javax.swing.JMenu(); - jLabel1 = new javax.swing.JLabel(); - jLabel2 = new javax.swing.JLabel(); - jComboBox1 = new javax.swing.JComboBox(); - jButton2 = new javax.swing.JButton(); - jScrollPane2 = new javax.swing.JScrollPane(); - jList2 = new javax.swing.JList(); - jLabel3 = new javax.swing.JLabel(); - jTextField1 = new javax.swing.JTextField(); - - jMenu1.setText("jMenu1"); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jLabel1.setText("A chi vuoi mandare il messaggio?"); - - jLabel2.setText("Quale metodo di cifratura proponi?"); - - jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Scegli sistema", "Sistema di cesare", "Pseudocasuale", "Parola chiave" })); - jComboBox1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jComboBox1ActionPerformed(evt); - } - }); - - jButton2.setText("Proponi sistema di cifratura"); - jButton2.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton2ActionPerformed(evt); - } - }); - - jScrollPane2.setViewportView(jList2); - - jLabel3.setText("Chiave"); - - jTextField1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jTextField1ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(56, 56, 56) - .addComponent(jLabel1) - .addGap(126, 126, 126) - .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(layout.createSequentialGroup() - .addGap(48, 48, 48) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel2) - .addComponent(jLabel3)) - .addGap(49, 49, 49) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jTextField1)))) - .addContainerGap(137, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(jButton2) - .addGap(53, 53, 53)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(100, 100, 100) - .addComponent(jLabel1)) - .addGroup(layout.createSequentialGroup() - .addGap(31, 31, 31) - .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addGap(46, 46, 46) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel2) - .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel3) - .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(23, 23, 23) - .addComponent(jButton2) - .addContainerGap(71, Short.MAX_VALUE)) - ); - - pack(); - }// //GEN-END:initComponents - - private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed - // TODO add your handling code here: - /*if(((String)jComboBox1.getSelectedItem()).equals("Scegli sistema")){ - jLabel3.setEnabled(false); - jLabel4.setEnabled(false); - jTextField1.setEnabled(false); - jTextField2.setEnabled(false); - } - - if(((String)jComboBox1.getSelectedItem()).equals("Sistema di cesare")){ - jLabel3.setEnabled(true); - jLabel4.setEnabled(false); - jTextField1.setEnabled(true); - jTextField2.setEnabled(false); - } - - if(((String)jComboBox1.getSelectedItem()).equals("Pseudocasuale")){ - /*jLabel3.setEnabled(false); - jLabel4.setEnabled(false); - jTextField1.setEnabled(false); - jTextField2.setEnabled(false); - DA FARE - } - - if(((String)jComboBox1.getSelectedItem()).equals("Parola chiave")){ - jLabel3.setEnabled(false); - jLabel4.setEnabled(true); - jTextField1.setEnabled(false); - jTextField2.setEnabled(true); - }*/ - - - }//GEN-LAST:event_jComboBox1ActionPerformed - - private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed - - SistemaCifratura sdc = new SistemaCifratura(jTextField1.getText(), (String)jComboBox1.getSelectedItem()); - UserInfo creatore = new UserInfo( this.studente.getId(), this.studente.getLogin() ); - sdc.setCreatore( creatore ); - - sdc.save(); - - boolean b = CommunicationController.inviaProposta(this.studente.getId(), ((UserInfo)jList2.getSelectedValue()).getId(), sdc); - System.out.println(b); - }//GEN-LAST:event_jButton2ActionPerformed - - private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed - // TODO add your handling code here: - }//GEN-LAST:event_jTextField1ActionPerformed - - - private Studente studente; - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton2; - private javax.swing.JComboBox jComboBox1; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; - private javax.swing.JList jList2; - private javax.swing.JMenu jMenu1; - private javax.swing.JScrollPane jScrollPane2; - private javax.swing.JTextField jTextField1; - // End of variables declaration//GEN-END:variables -} +/* + * 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 GUI.user; + +//import ClmodelserInfo; +//import Clasmodeldente; +import controller.CommunicationController; +import controller.Controller; +//import Controviewoller; +import java.util.Vector; +import javax.swing.ListModel; +import model.user.Proposta; +import model.user.SistemaCifratura; +import model.Studente; +import model.UserInfo; + +/** + * + * @author MASTER + */ +public class PropostaSistemaDiCifratura extends javax.swing.JFrame { + private Proposta p; + /** + * Creates new form NuovoMessaggio + * @param s + */ + public PropostaSistemaDiCifratura( Studente s ) { + initComponents(); + UserInfo[] ui = Controller.recuperaUtenti( s ); + jList2.setListData(ui); + + this.studente = s; + } + + /** + * 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() { + + jMenu1 = new javax.swing.JMenu(); + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + jComboBox1 = new javax.swing.JComboBox(); + jButton2 = new javax.swing.JButton(); + jScrollPane2 = new javax.swing.JScrollPane(); + jList2 = new javax.swing.JList(); + jLabel3 = new javax.swing.JLabel(); + jTextField1 = new javax.swing.JTextField(); + + jMenu1.setText("jMenu1"); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + + jLabel1.setText("A chi vuoi mandare il messaggio?"); + + jLabel2.setText("Quale metodo di cifratura proponi?"); + + jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Scegli sistema", "Sistema di cesare", "Pseudocasuale", "Parola chiave" })); + jComboBox1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jComboBox1ActionPerformed(evt); + } + }); + + jButton2.setText("Proponi sistema di cifratura"); + jButton2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton2ActionPerformed(evt); + } + }); + + jScrollPane2.setViewportView(jList2); + + jLabel3.setText("Chiave"); + + jTextField1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jTextField1ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(56, 56, 56) + .addComponent(jLabel1) + .addGap(126, 126, 126) + .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addGap(48, 48, 48) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel2) + .addComponent(jLabel3)) + .addGap(49, 49, 49) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jTextField1)))) + .addContainerGap(137, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(jButton2) + .addGap(53, 53, 53)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(100, 100, 100) + .addComponent(jLabel1)) + .addGroup(layout.createSequentialGroup() + .addGap(31, 31, 31) + .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGap(46, 46, 46) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel2) + .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel3) + .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(23, 23, 23) + .addComponent(jButton2) + .addContainerGap(71, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed + // TODO add your handling code here: + /*if(((String)jComboBox1.getSelectedItem()).equals("Scegli sistema")){ + jLabel3.setEnabled(false); + jLabel4.setEnabled(false); + jTextField1.setEnabled(false); + jTextField2.setEnabled(false); + } + + if(((String)jComboBox1.getSelectedItem()).equals("Sistema di cesare")){ + jLabel3.setEnabled(true); + jLabel4.setEnabled(false); + jTextField1.setEnabled(true); + jTextField2.setEnabled(false); + } + + if(((String)jComboBox1.getSelectedItem()).equals("Pseudocasuale")){ + /*jLabel3.setEnabled(false); + jLabel4.setEnabled(false); + jTextField1.setEnabled(false); + jTextField2.setEnabled(false); + DA FARE + } + + if(((String)jComboBox1.getSelectedItem()).equals("Parola chiave")){ + jLabel3.setEnabled(false); + jLabel4.setEnabled(true); + jTextField1.setEnabled(false); + jTextField2.setEnabled(true); + }*/ + + + }//GEN-LAST:event_jComboBox1ActionPerformed + + private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed + + SistemaCifratura sdc = new SistemaCifratura(jTextField1.getText(), (String)jComboBox1.getSelectedItem()); + UserInfo creatore = new UserInfo( this.studente.getId(), this.studente.getLogin() ); + sdc.setCreatore( creatore ); + + sdc.save(); + + boolean b = CommunicationController.inviaProposta(this.studente.getId(), ((UserInfo)jList2.getSelectedValue()).getId(), sdc); + System.out.println(b); + }//GEN-LAST:event_jButton2ActionPerformed + + private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jTextField1ActionPerformed + + + private Studente studente; + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton2; + private javax.swing.JComboBox jComboBox1; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JList jList2; + private javax.swing.JMenu jMenu1; + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JTextField jTextField1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/GUI/user/Registrazione.form b/src/GUI/user/Registrazione.form index 45f9303..c8b2232 100644 --- a/src/GUI/user/Registrazione.form +++ b/src/GUI/user/Registrazione.form @@ -2,7 +2,7 @@ - + @@ -28,11 +28,10 @@ - - - - + + + @@ -45,6 +44,10 @@ + + + + @@ -68,7 +71,7 @@ - + @@ -112,11 +115,11 @@ - - - + + + diff --git a/src/GUI/user/Registrazione.java b/src/GUI/user/Registrazione.java index 2ac9c4c..20c3ba3 100644 --- a/src/GUI/user/Registrazione.java +++ b/src/GUI/user/Registrazione.java @@ -39,7 +39,7 @@ private void initComponents() { jTextField3 = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); jLabel1.setText("Username"); @@ -66,11 +66,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { } }); - jTextField3.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jTextField3ActionPerformed(evt); - } - }); + jLabel4.setText("Registrazione Effettuata"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); @@ -81,10 +77,9 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(jButton1) .addGap(80, 80, 80)) .addGroup(layout.createSequentialGroup() - .addGap(35, 35, 35) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 323, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() + .addGap(68, 68, 68) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel3) .addComponent(jLabel2) @@ -93,7 +88,10 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)))) + .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGroup(layout.createSequentialGroup() + .addGap(35, 35, 35) + .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(42, Short.MAX_VALUE)) ); layout.setVerticalGroup( @@ -111,7 +109,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 46, Short.MAX_VALUE) .addComponent(jButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel4) @@ -127,27 +125,16 @@ private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: - String username = (jTextField1.getText()); - String password =(jTextField2.getText()); - String ripetiPassword =(jTextField3.getText()); - if(!password.equals(ripetiPassword)){ - jLabel4.setText("Le password devono coincidere"); - } - else{ - if(username.equals("studenteTest") || username.equals("studenteTest2")) - jLabel4.setText("username non ammesso. Riprovare"); - else Studente.registra(jTextField1.getText(), jTextField2.getText()); - } + System.out.println(jTextField1.getText()); + System.out.println(jTextField2.getText()); + /*mancano controlli sulla password*/ + Studente.registra(jTextField1.getText(), jTextField2.getText()); }//GEN-LAST:event_jButton1ActionPerformed private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jTextField2ActionPerformed - private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField3ActionPerformed - // TODO add your handling code here: - }//GEN-LAST:event_jTextField3ActionPerformed - /** * @param args the command line arguments */ diff --git a/src/GUI/user/Utente_Regolamentare.form b/src/GUI/user/Utente_Regolamentare.form index 6ceb0bb..9a336a3 100644 --- a/src/GUI/user/Utente_Regolamentare.form +++ b/src/GUI/user/Utente_Regolamentare.form @@ -2,7 +2,7 @@
- + diff --git a/src/GUI/user/Utente_Regolamentare.java b/src/GUI/user/Utente_Regolamentare.java index 0aa26e6..710e435 100644 --- a/src/GUI/user/Utente_Regolamentare.java +++ b/src/GUI/user/Utente_Regolamentare.java @@ -1,131 +1,131 @@ -/* - * 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 GUI.user; - -import model.user.Proposta; -/*import Clmodelession; -import ClasmodelrInfo;*/ -import controller.CommunicationController; -import model.Messaggio; -import model.MessaggioDestinatario; -import model.Studente; - -/** - * - * @author MASTER - */ -public class Utente_Regolamentare extends javax.swing.JFrame { - - /** - * Creates new form Mittente - */ - public Utente_Regolamentare( Studente s ) { - initComponents(); - this.studente = s; - - /* E' parte di interfaccia: popup per le nuove proposte */ - Proposta[] p = CommunicationController.getProposte(s.getId()); - if(p.length > 0) { - NuoveProposte n = new NuoveProposte( this.studente, p ); - n.setVisible(true); - } - - /* Controllo di interfaccia: se ci sono messaggi si possono leggere */ - MessaggioDestinatario[] l = Messaggio.caricaRicevuti( this.studente ); - if(l.length > 0) - jButton3.setText("Leggi Messaggi (" + l.length + ")"); - } - - /** - * 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() { - - jButton1 = new javax.swing.JButton(); - jButton2 = new javax.swing.JButton(); - jButton3 = new javax.swing.JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jButton1.setText("Invia Nuovo Messaggio"); - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - - jButton2.setText("Apri Messaggio precedente"); - jButton2.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton2ActionPerformed(evt); - } - }); - - jButton3.setText("Leggi Messaggi"); - jButton3.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton3ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(112, 112, 112) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE) - .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap(141, Short.MAX_VALUE)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(154, 154, 154) - .addComponent(jButton1) - .addGap(29, 29, 29) - .addComponent(jButton2) - .addGap(29, 29, 29) - .addComponent(jButton3) - .addContainerGap(139, Short.MAX_VALUE)) - ); - - pack(); - }// //GEN-END:initComponents - - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - // TODO add your handling code here: - new NuovoMessaggio( this.studente, null ).setVisible(true); - }//GEN-LAST:event_jButton1ActionPerformed - - private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed - // TODO add your handling code here: - System.out.println("ok"); - new ApriMessaggioPrecedente(this.studente).setVisible(true); - System.out.println("ok"); - }//GEN-LAST:event_jButton2ActionPerformed - - private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed - // TODO add your handling code here: - new LeggiMessaggi( this.studente ).setVisible(true); - }//GEN-LAST:event_jButton3ActionPerformed - - - private Studente studente; - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton1; - private javax.swing.JButton jButton2; - private javax.swing.JButton jButton3; - // End of variables declaration//GEN-END:variables -} +/* + * 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 GUI.user; + +import model.user.Proposta; +/*import Clmodelession; +import ClasmodelrInfo;*/ +import controller.CommunicationController; +import model.Messaggio; +import model.MessaggioDestinatario; +import model.Studente; + +/** + * + * @author MASTER + */ +public class Utente_Regolamentare extends javax.swing.JFrame { + + /** + * Creates new form Mittente + */ + public Utente_Regolamentare( Studente s ) { + initComponents(); + this.studente = s; + + /* E' parte di interfaccia: popup per le nuove proposte */ + Proposta[] p = CommunicationController.getProposte(s.getId()); + if(p.length > 0) { + NuoveProposte n = new NuoveProposte( this.studente, p ); + n.setVisible(true); + } + + /* Controllo di interfaccia: se ci sono messaggi si possono leggere */ + MessaggioDestinatario[] l = Messaggio.caricaRicevuti( this.studente ); + if(l.length > 0) + jButton3.setText("Leggi Messaggi (" + l.length + ")"); + } + + /** + * 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() { + + jButton1 = new javax.swing.JButton(); + jButton2 = new javax.swing.JButton(); + jButton3 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + + jButton1.setText("Invia Nuovo Messaggio"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jButton2.setText("Apri Messaggio precedente"); + jButton2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton2ActionPerformed(evt); + } + }); + + jButton3.setText("Leggi Messaggi"); + jButton3.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton3ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(112, 112, 112) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE) + .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap(141, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(154, 154, 154) + .addComponent(jButton1) + .addGap(29, 29, 29) + .addComponent(jButton2) + .addGap(29, 29, 29) + .addComponent(jButton3) + .addContainerGap(139, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + // TODO add your handling code here: + new NuovoMessaggio( this.studente, null ).setVisible(true); + }//GEN-LAST:event_jButton1ActionPerformed + + private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed + // TODO add your handling code here: + System.out.println("ok"); + new ApriMessaggioPrecedente(this.studente).setVisible(true); + System.out.println("ok"); + }//GEN-LAST:event_jButton2ActionPerformed + + private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed + // TODO add your handling code here: + new LeggiMessaggi( this.studente ).setVisible(true); + }//GEN-LAST:event_jButton3ActionPerformed + + + private Studente studente; + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + private javax.swing.JButton jButton3; + // End of variables declaration//GEN-END:variables +} diff --git a/src/model/user/CalcolatoreCesare.java b/src/model/user/CalcolatoreCesare.java index 20d350a..bfb6643 100644 --- a/src/model/user/CalcolatoreCesare.java +++ b/src/model/user/CalcolatoreCesare.java @@ -1,26 +1,26 @@ -/* - * 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 model.user; - -/** - * - * @author MASTER - */ -public class CalcolatoreCesare implements CalcolatoreMappatura { - //private String chiave; - - /*public CalcolatoreCesare(String c){ - this.chiave = c; - }*/ - - public Mappatura calcola(String c){ - int chiave = Integer.parseInt(c); - for(int i=0; i Date: Sun, 8 Feb 2015 11:44:53 +0100 Subject: [PATCH 44/45] tolto... --- src/GUI/user/NuoveProposte.form | 10 +++++++--- src/GUI/user/NuoveProposte.java | 9 ++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/GUI/user/NuoveProposte.form b/src/GUI/user/NuoveProposte.form index d638f2f..c83e18d 100644 --- a/src/GUI/user/NuoveProposte.form +++ b/src/GUI/user/NuoveProposte.form @@ -23,7 +23,6 @@ - @@ -32,10 +31,15 @@ - + + + + + + @@ -61,7 +65,7 @@ - + diff --git a/src/GUI/user/NuoveProposte.java b/src/GUI/user/NuoveProposte.java index 795e159..f367588 100644 --- a/src/GUI/user/NuoveProposte.java +++ b/src/GUI/user/NuoveProposte.java @@ -46,7 +46,7 @@ private void initComponents() { setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N - jLabel1.setText("Ciao stronzo hai delle nuove proposte alèèèèèèèèè"); + jLabel1.setText(" Hai delle nuove proposte"); jLabel1.setVerifyInputWhenFocusTarget(false); jList1.setModel(new javax.swing.AbstractListModel() { @@ -74,7 +74,6 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 624, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1) @@ -82,9 +81,13 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(layout.createSequentialGroup() .addGap(64, 64, 64) .addComponent(jButton1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 314, Short.MAX_VALUE) .addComponent(jButton2) .addGap(135, 135, 135)) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) From dc467c126e21450a025a9bccb80519764f0b3d04 Mon Sep 17 00:00:00 2001 From: bob Date: Mon, 9 Feb 2015 19:30:51 +0100 Subject: [PATCH 45/45] davide commit --- src/DatabaseDUMPS/Sessione.sql | 24 +- src/DatabaseDUMPS/cryptohelper.sql | 318 +-- src/DatabaseDUMPS/model.puml | 164 +- src/GUI/GenericSelector.form | 160 +- src/GUI/GenericSelector.java | 372 ++-- src/GUI/Main.form | 6 + src/GUI/Main.java | 596 +++--- src/GUI/PopUpViewer.form | 152 +- src/GUI/PopUpViewer.java | 246 +-- src/GUI/spia/CicloDiAnalisi.form | 312 +-- src/GUI/spia/CicloDiAnalisi.java | 442 +++-- src/GUI/spia/GestisciSessioneDiLavoro.form | 154 +- src/GUI/spia/GestisciSessioneDiLavoro.java | 272 +-- src/GUI/spia/GestisciSessioni.form | 206 +- src/GUI/spia/GestisciSessioni.java | 192 +- .../spia/RipristinaIpotesiPrecedenteGUI.form | 174 +- .../spia/RipristinaIpotesiPrecedenteGUI.java | 256 +-- src/GUI/spia/SostituzioneSempliceGUI.java | 390 ++-- src/GUI/user/ApriMessaggioPrecedente.form | 23 +- src/GUI/user/ApriMessaggioPrecedente.java | 27 +- src/GUI/user/DettagliMessaggio.form | 4 +- src/GUI/user/DettagliMessaggio.java | 4 +- src/GUI/user/LeggiMessaggi.form | 182 +- src/GUI/user/LeggiMessaggi.java | 2 +- src/GUI/user/NuoveProposte.form | 12 +- src/GUI/user/NuoveProposte.java | 11 +- src/GUI/user/NuovoMessaggio.form | 43 +- src/GUI/user/NuovoMessaggio.java | 69 +- src/GUI/user/PropostaSistemaDiCifratura.form | 52 +- src/GUI/user/PropostaSistemaDiCifratura.java | 53 +- src/GUI/user/Registrazione.form | 250 +-- src/GUI/user/Registrazione.java | 2 +- src/GUI/user/Utente_Regolamentare.form | 154 +- src/GUI/user/Utente_Regolamentare.java | 2 +- src/controller/CommunicationController.java | 14 +- src/db/DbManager.java | 154 +- src/db/PreparedStatementWrapper.java | 896 ++++----- src/db/Query.java | 34 +- src/db/QueryAbstract.java | 52 +- src/db/QueryResult.java | 34 +- src/db/QueryResultAbstract.java | 56 +- src/db/ResultSetWrapper.java | 1716 ++++++++--------- src/model/Messaggio.java | 17 +- src/model/MessaggioAstratto.java | 2 +- src/model/Studente.java | 8 + src/model/spia/AnalisiFrequenze.java | 98 +- src/model/spia/Ipotesi.java | 88 +- .../spia/RipristinaIpotesiPrecedente.java | 38 +- src/model/spia/Sessione.java | 406 ++-- src/model/spia/SostituzioneSemplice.java | 94 +- src/model/spia/Spia.java | 116 +- src/model/spia/StrumentoDiManipolazione.java | 34 +- src/model/spia/StrumentoDiSupporto.java | 42 +- src/model/user/CalcolatoreParolaChiave.java | 11 +- src/model/user/CalcolatorePseudocasuale.java | 18 +- src/model/user/Proposta.java | 9 +- src/model/user/PropostaConfermata.java | 5 +- src/model/user/SistemaCifratura.java | 12 +- 58 files changed, 4676 insertions(+), 4604 deletions(-) diff --git a/src/DatabaseDUMPS/Sessione.sql b/src/DatabaseDUMPS/Sessione.sql index aacc734..3e33ceb 100644 --- a/src/DatabaseDUMPS/Sessione.sql +++ b/src/DatabaseDUMPS/Sessione.sql @@ -1,13 +1,13 @@ - --- --- Struttura della tabella `Sessione` --- - -CREATE TABLE IF NOT EXISTS `Sessione` ( - `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique ID', - `userId` int(11) NOT NULL COMMENT 'user ID', - `key` varchar(255) NOT NULL COMMENT 'Human Readable key', - `sessione` blob NOT NULL COMMENT 'The serialized Session object', - PRIMARY KEY (`id`), - UNIQUE KEY `userId` (`userId`,`key`) + +-- +-- Struttura della tabella `Sessione` +-- + +CREATE TABLE IF NOT EXISTS `Sessione` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique ID', + `userId` int(11) NOT NULL COMMENT 'user ID', + `key` varchar(255) NOT NULL COMMENT 'Human Readable key', + `sessione` blob NOT NULL COMMENT 'The serialized Session object', + PRIMARY KEY (`id`), + UNIQUE KEY `userId` (`userId`,`key`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; \ No newline at end of file diff --git a/src/DatabaseDUMPS/cryptohelper.sql b/src/DatabaseDUMPS/cryptohelper.sql index 39faa69..56faed6 100644 --- a/src/DatabaseDUMPS/cryptohelper.sql +++ b/src/DatabaseDUMPS/cryptohelper.sql @@ -1,159 +1,159 @@ --- phpMyAdmin SQL Dump --- version 4.0.10deb1 --- http://www.phpmyadmin.net --- --- Host: localhost --- Generato il: Set 18, 2014 alle 22:57 --- Versione del server: 5.5.38-0ubuntu0.14.04.1 --- Versione PHP: 5.5.9-1ubuntu4.3 - -SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; -SET time_zone = "+00:00"; - - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; - --- --- Database: `cryptohelper` --- - --- -------------------------------------------------------- - --- --- Struttura della tabella `messaggio` --- - -CREATE TABLE IF NOT EXISTS `messaggio` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `id_mittente` int(11) NOT NULL, - `id_destinatario` int(11) NOT NULL, - `testo` varchar(120) NOT NULL, - `testoCifrato` varchar(120) NOT NULL, - `lingua` varchar(120) NOT NULL, - `titolo` varchar(120) NOT NULL, - `bozza` tinyint(1) NOT NULL, - `letto` tinyint(1) NOT NULL, - `idsistemacifratura` int(11) NOT NULL, - PRIMARY KEY (`id`), - KEY `id_mittente` (`id_mittente`), - KEY `id_destinatario` (`id_destinatario`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=22 ; - --- --- Dump dei dati per la tabella `messaggio` --- - -INSERT INTO `messaggio` (`id`, `id_mittente`, `id_destinatario`, `testo`, `testoCifrato`, `lingua`, `titolo`, `bozza`, `letto`, `idsistemacifratura`) VALUES -(19, 1, 3, 'bellaaaaaaaaaaaaa!!!!', 'bellaaaaaaaaaaaaa', 'Italiano', 'titoloDiProva', 0, 0, 0), -(20, 1, 2, 'ciao bob qui tutto a posto', 'rxp~ q~q ??x ????~ p ~??~', 'null', 'titoloDiProva', 0, 0, 0), -(21, 1, 2, 'ciao', 'rxp~', 'Italiano', 'titoloDiProva', 0, 0, 0); - --- -------------------------------------------------------- - --- --- Struttura della tabella `proposta` --- - -CREATE TABLE IF NOT EXISTS `proposta` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `id_mittente` varchar(120) NOT NULL, - `id_destinatario` varchar(120) NOT NULL, - `idsistemacifratura` int(11) NOT NULL, - `stato` varchar(120) NOT NULL, - `notificata` datetime DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `user_mittente` (`id_mittente`), - KEY `user_destinatario` (`id_destinatario`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ; - --- --- Dump dei dati per la tabella `proposta` --- - -INSERT INTO `proposta` (`id`, `id_mittente`, `id_destinatario`, `idsistemacifratura`, `stato`, `notificata`) VALUES -(7, '1', '2', 5, 'accettata', NULL), -(8, '1', '3', 6, 'accettata', NULL), -(9, '1', '2', 7, 'accettata', NULL), -(10, '2', '3', 8, 'rifiutata', NULL); - --- -------------------------------------------------------- - --- --- Struttura della tabella `Sessione` --- - -CREATE TABLE IF NOT EXISTS `Sessione` ( - `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique ID', - `userId` int(11) NOT NULL COMMENT 'user ID', - `key` varchar(255) NOT NULL COMMENT 'Human Readable key', - `session` blob NOT NULL COMMENT 'The serialized Session object', - PRIMARY KEY (`id`), - UNIQUE KEY `userId` (`userId`,`key`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; - --- -------------------------------------------------------- - --- --- Struttura della tabella `sistemacifratura` --- - -CREATE TABLE IF NOT EXISTS `sistemacifratura` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `chiave` varchar(120) NOT NULL, - `metodo` varchar(120) NOT NULL, - `idcreatore` int(11) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ; - --- --- Dump dei dati per la tabella `sistemacifratura` --- - -INSERT INTO `sistemacifratura` (`id`, `chiave`, `metodo`, `idcreatore`) VALUES -(5, '15', 'Sistema di cesare', 1), -(6, '0', 'Sistema di cesare', 1), -(7, 'ciaao', 'Parola chiave', 1), -(8, '30', 'Sistema di cesare', 2); - --- -------------------------------------------------------- - --- --- Struttura della tabella `user` --- - -CREATE TABLE IF NOT EXISTS `user` ( - `id` int(120) NOT NULL AUTO_INCREMENT, - `username` varchar(120) NOT NULL, - `password` varchar(120) NOT NULL, - `nome` varchar(120) DEFAULT NULL, - `cognome` varchar(120) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `username` (`username`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; - --- --- Dump dei dati per la tabella `user` --- - -INSERT INTO `user` (`id`, `username`, `password`, `nome`, `cognome`) VALUES -(1, 'roberto', 'root', NULL, NULL), -(2, 'bob', 'root', NULL, NULL), -(3, 'davide', 'prova', NULL, NULL); - --- --- Limiti per le tabelle scaricate --- - --- --- Limiti per la tabella `messaggio` --- -ALTER TABLE `messaggio` - ADD CONSTRAINT `messaggio_ibfk_1` FOREIGN KEY (`id_mittente`) REFERENCES `user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, - ADD CONSTRAINT `messaggio_ibfk_2` FOREIGN KEY (`id_destinatario`) REFERENCES `user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION; - -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +-- phpMyAdmin SQL Dump +-- version 4.0.10deb1 +-- http://www.phpmyadmin.net +-- +-- Host: localhost +-- Generato il: Set 18, 2014 alle 22:57 +-- Versione del server: 5.5.38-0ubuntu0.14.04.1 +-- Versione PHP: 5.5.9-1ubuntu4.3 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; + +-- +-- Database: `cryptohelper` +-- + +-- -------------------------------------------------------- + +-- +-- Struttura della tabella `messaggio` +-- + +CREATE TABLE IF NOT EXISTS `messaggio` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `id_mittente` int(11) NOT NULL, + `id_destinatario` int(11) NOT NULL, + `testo` varchar(120) NOT NULL, + `testoCifrato` varchar(120) NOT NULL, + `lingua` varchar(120) NOT NULL, + `titolo` varchar(120) NOT NULL, + `bozza` tinyint(1) NOT NULL, + `letto` tinyint(1) NOT NULL, + `idsistemacifratura` int(11) NOT NULL, + PRIMARY KEY (`id`), + KEY `id_mittente` (`id_mittente`), + KEY `id_destinatario` (`id_destinatario`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=22 ; + +-- +-- Dump dei dati per la tabella `messaggio` +-- + +INSERT INTO `messaggio` (`id`, `id_mittente`, `id_destinatario`, `testo`, `testoCifrato`, `lingua`, `titolo`, `bozza`, `letto`, `idsistemacifratura`) VALUES +(19, 1, 3, 'bellaaaaaaaaaaaaa!!!!', 'bellaaaaaaaaaaaaa', 'Italiano', 'titoloDiProva', 0, 0, 0), +(20, 1, 2, 'ciao bob qui tutto a posto', 'rxp~ q~q ??x ????~ p ~??~', 'null', 'titoloDiProva', 0, 0, 0), +(21, 1, 2, 'ciao', 'rxp~', 'Italiano', 'titoloDiProva', 0, 0, 0); + +-- -------------------------------------------------------- + +-- +-- Struttura della tabella `proposta` +-- + +CREATE TABLE IF NOT EXISTS `proposta` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `id_mittente` varchar(120) NOT NULL, + `id_destinatario` varchar(120) NOT NULL, + `idsistemacifratura` int(11) NOT NULL, + `stato` varchar(120) NOT NULL, + `notificata` datetime DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `user_mittente` (`id_mittente`), + KEY `user_destinatario` (`id_destinatario`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ; + +-- +-- Dump dei dati per la tabella `proposta` +-- + +INSERT INTO `proposta` (`id`, `id_mittente`, `id_destinatario`, `idsistemacifratura`, `stato`, `notificata`) VALUES +(7, '1', '2', 5, 'accettata', NULL), +(8, '1', '3', 6, 'accettata', NULL), +(9, '1', '2', 7, 'accettata', NULL), +(10, '2', '3', 8, 'rifiutata', NULL); + +-- -------------------------------------------------------- + +-- +-- Struttura della tabella `Sessione` +-- + +CREATE TABLE IF NOT EXISTS `Sessione` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique ID', + `userId` int(11) NOT NULL COMMENT 'user ID', + `key` varchar(255) NOT NULL COMMENT 'Human Readable key', + `session` blob NOT NULL COMMENT 'The serialized Session object', + PRIMARY KEY (`id`), + UNIQUE KEY `userId` (`userId`,`key`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; + +-- -------------------------------------------------------- + +-- +-- Struttura della tabella `sistemacifratura` +-- + +CREATE TABLE IF NOT EXISTS `sistemacifratura` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `chiave` varchar(120) NOT NULL, + `metodo` varchar(120) NOT NULL, + `idcreatore` int(11) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ; + +-- +-- Dump dei dati per la tabella `sistemacifratura` +-- + +INSERT INTO `sistemacifratura` (`id`, `chiave`, `metodo`, `idcreatore`) VALUES +(5, '15', 'Sistema di cesare', 1), +(6, '0', 'Sistema di cesare', 1), +(7, 'ciaao', 'Parola chiave', 1), +(8, '30', 'Sistema di cesare', 2); + +-- -------------------------------------------------------- + +-- +-- Struttura della tabella `user` +-- + +CREATE TABLE IF NOT EXISTS `user` ( + `id` int(120) NOT NULL AUTO_INCREMENT, + `username` varchar(120) NOT NULL, + `password` varchar(120) NOT NULL, + `nome` varchar(120) DEFAULT NULL, + `cognome` varchar(120) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `username` (`username`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; + +-- +-- Dump dei dati per la tabella `user` +-- + +INSERT INTO `user` (`id`, `username`, `password`, `nome`, `cognome`) VALUES +(1, 'roberto', 'root', NULL, NULL), +(2, 'bob', 'root', NULL, NULL), +(3, 'davide', 'prova', NULL, NULL); + +-- +-- Limiti per le tabelle scaricate +-- + +-- +-- Limiti per la tabella `messaggio` +-- +ALTER TABLE `messaggio` + ADD CONSTRAINT `messaggio_ibfk_1` FOREIGN KEY (`id_mittente`) REFERENCES `user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + ADD CONSTRAINT `messaggio_ibfk_2` FOREIGN KEY (`id_destinatario`) REFERENCES `user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/src/DatabaseDUMPS/model.puml b/src/DatabaseDUMPS/model.puml index 60163d4..fbfd37b 100644 --- a/src/DatabaseDUMPS/model.puml +++ b/src/DatabaseDUMPS/model.puml @@ -1,83 +1,83 @@ -@startuml - -class GUI.GenericSelector -class GUI.PopUpViewer -class GUI.CicloDiAnalisi -class GUI.SostituzioneSempliceGUI -class controller.Controller -class db.DbManager -class db.Query -class db.QueryResult - - -class model.Messaggio -class model.Studente -class model.UserInfo - -class model.Spia -class model.Studente - -class model.Sessione -class model.Ipotesi - -interface model.StrumentoDiManipolazione -class model.RipristinaIpotesiPrecedente -class model.SostituzioneSemplice - -interface model.StrumentoDiSupporto -class model.AnalisiFrequenze - - -class model.CalcolatoreCesare -class model.CalcolatoreParolaChiave -class model.CalcolatorePseudocasuale -class model.Cifratore -class model.Mappatura -class model.Proposta -class model.PropostaConfermata -class model.SistemaCifratura - - -interface model.MessaggioAstratto -interface model.MessaggioDestinatario -interface model.MessaggioMittente - -interface model.CalcolatoreMappatura - -model.Messaggio ..> model.Cifratore -model.Messaggio ..> model.SistemaCifratura - -model.Messaggio --|> model.MessaggioDestinatario -model.Messaggio --|> model.MessaggioMittente - - -model.AnalisiFrequenze --|> model.StrumentoDiSupporto - -model.RipristinaIpotesiPrecedente --|> model.StrumentoDiManipolazione -model.SostituzioneSemplice ..> GUI.SostituzioneSempliceGUI -model.SostituzioneSemplice --|> model.StrumentoDiManipolazione - - -model.Sessione ..> GUI.GenericSelector -model.Sessione ..> GUI.PopUpViewer -model.Sessione ..> GUI.CicloDiAnalisi - -model.Sessione ..> model.Messaggio -model.Sessione ..> model.Studente - -model.Spia --|> model.Studente -model.CalcolatoreCesare --|> model.CalcolatoreMappatura -model.CalcolatoreParolaChiave --|> model.CalcolatoreMappatura -model.CalcolatorePseudocasuale --|> model.CalcolatoreMappatura -model.Proposta ..> controller.Controller -model.Proposta ..> model.UserInfo -model.PropostaConfermata ..> model.UserInfo -model.PropostaConfermata --|> model.Proposta - -model.SistemaCifratura ..> model.Studente -model.SistemaCifratura ..> model.UserInfo -model.MessaggioDestinatario --|> model.MessaggioAstratto -model.MessaggioMittente --|> model.MessaggioAstratto -model.StrumentoDiManipolazione ..> model.Messaggio -model.StrumentoDiSupporto ..> model.Messaggio +@startuml + +class GUI.GenericSelector +class GUI.PopUpViewer +class GUI.CicloDiAnalisi +class GUI.SostituzioneSempliceGUI +class controller.Controller +class db.DbManager +class db.Query +class db.QueryResult + + +class model.Messaggio +class model.Studente +class model.UserInfo + +class model.Spia +class model.Studente + +class model.Sessione +class model.Ipotesi + +interface model.StrumentoDiManipolazione +class model.RipristinaIpotesiPrecedente +class model.SostituzioneSemplice + +interface model.StrumentoDiSupporto +class model.AnalisiFrequenze + + +class model.CalcolatoreCesare +class model.CalcolatoreParolaChiave +class model.CalcolatorePseudocasuale +class model.Cifratore +class model.Mappatura +class model.Proposta +class model.PropostaConfermata +class model.SistemaCifratura + + +interface model.MessaggioAstratto +interface model.MessaggioDestinatario +interface model.MessaggioMittente + +interface model.CalcolatoreMappatura + +model.Messaggio ..> model.Cifratore +model.Messaggio ..> model.SistemaCifratura + +model.Messaggio --|> model.MessaggioDestinatario +model.Messaggio --|> model.MessaggioMittente + + +model.AnalisiFrequenze --|> model.StrumentoDiSupporto + +model.RipristinaIpotesiPrecedente --|> model.StrumentoDiManipolazione +model.SostituzioneSemplice ..> GUI.SostituzioneSempliceGUI +model.SostituzioneSemplice --|> model.StrumentoDiManipolazione + + +model.Sessione ..> GUI.GenericSelector +model.Sessione ..> GUI.PopUpViewer +model.Sessione ..> GUI.CicloDiAnalisi + +model.Sessione ..> model.Messaggio +model.Sessione ..> model.Studente + +model.Spia --|> model.Studente +model.CalcolatoreCesare --|> model.CalcolatoreMappatura +model.CalcolatoreParolaChiave --|> model.CalcolatoreMappatura +model.CalcolatorePseudocasuale --|> model.CalcolatoreMappatura +model.Proposta ..> controller.Controller +model.Proposta ..> model.UserInfo +model.PropostaConfermata ..> model.UserInfo +model.PropostaConfermata --|> model.Proposta + +model.SistemaCifratura ..> model.Studente +model.SistemaCifratura ..> model.UserInfo +model.MessaggioDestinatario --|> model.MessaggioAstratto +model.MessaggioMittente --|> model.MessaggioAstratto +model.StrumentoDiManipolazione ..> model.Messaggio +model.StrumentoDiSupporto ..> model.Messaggio @enduml \ No newline at end of file diff --git a/src/GUI/GenericSelector.form b/src/GUI/GenericSelector.form index 022d7db..7e44460 100644 --- a/src/GUI/GenericSelector.form +++ b/src/GUI/GenericSelector.form @@ -1,80 +1,80 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/GenericSelector.java b/src/GUI/GenericSelector.java index 6ee67fc..0966105 100644 --- a/src/GUI/GenericSelector.java +++ b/src/GUI/GenericSelector.java @@ -1,186 +1,186 @@ -/* - * 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 GUI; - -import java.util.List; - -/** - * - * @author user - * @param - */ -public class GenericSelector extends javax.swing.JFrame { - - public static K selectOptions(List list) { - - final SynchronizedBuffer buff = new SynchronizedBuffer<>(); - final List fList = list; - - new Thread(new Runnable() { - @Override - public void run() { - GenericSelector selector = new GenericSelector<>(buff); - selector.setOptionList(fList); - selector.setVisible(true); - } - }).start(); - - return buff.get(); - } - - SynchronizedBuffer syncBuffer; - - private GenericSelector(SynchronizedBuffer c) { - this(); - this.syncBuffer = c; - } - - /** - * Creates new form NuovaSessione - */ - private GenericSelector() { - initComponents(); - } - - public void setOptionList(List list) { - T[] arr = (T[]) list.toArray(new Object[list.size()]); - jList1.setListData(arr); - } - - // - private static class SynchronizedBuffer { - - private T contents; - private boolean available = false; - - public synchronized T get() { - while (available == false) { - try { - wait(); - } catch (InterruptedException e) { - } - } - available = false; - notifyAll(); - return contents; - } - - public synchronized void put(T value) { - while (available == true) { - try { - wait(); - } catch (InterruptedException e) { - } - } - contents = value; - available = true; - notifyAll(); - } - } - // - - /** - * 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() { - - jScrollPane1 = new javax.swing.JScrollPane(); - jList1 = new javax.swing.JList(); - jButton1 = new javax.swing.JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - - jList1.setModel(new javax.swing.AbstractListModel() { - String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; - public int getSize() { return strings.length; } - public Object getElementAt(int i) { return strings[i]; } - }); - jScrollPane1.setViewportView(jList1); - - jButton1.setText("Scegli"); - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(jButton1) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 335, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap(53, Short.MAX_VALUE)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(23, 23, 23) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(44, 44, 44) - .addComponent(jButton1) - .addContainerGap(64, Short.MAX_VALUE)) - ); - - pack(); - }// //GEN-END:initComponents - - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - // TODO add your handling code here: - T selected = (T) jList1.getSelectedValue(); - this.syncBuffer.put(selected); - this.dispose(); - }//GEN-LAST:event_jButton1ActionPerformed - - /** - * @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(GenericSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(GenericSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(GenericSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(GenericSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } - // - - List list = new java.util.ArrayList<>(); - list.add("A"); - list.add("B"); - list.add("C"); - list.add("D"); - - System.out.println(GenericSelector.selectOptions(list)); - } - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton1; - private javax.swing.JList jList1; - private javax.swing.JScrollPane jScrollPane1; - // End of variables declaration//GEN-END:variables -} +/* + * 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 GUI; + +import java.util.List; + +/** + * + * @author user + * @param + */ +public class GenericSelector extends javax.swing.JFrame { + + public static K selectOptions(List list) { + + final SynchronizedBuffer buff = new SynchronizedBuffer<>(); + final List fList = list; + + new Thread(new Runnable() { + @Override + public void run() { + GenericSelector selector = new GenericSelector<>(buff); + selector.setOptionList(fList); + selector.setVisible(true); + } + }).start(); + + return buff.get(); + } + + SynchronizedBuffer syncBuffer; + + private GenericSelector(SynchronizedBuffer c) { + this(); + this.syncBuffer = c; + } + + /** + * Creates new form NuovaSessione + */ + private GenericSelector() { + initComponents(); + } + + public void setOptionList(List list) { + T[] arr = (T[]) list.toArray(new Object[list.size()]); + jList1.setListData(arr); + } + + // + private static class SynchronizedBuffer { + + private T contents; + private boolean available = false; + + public synchronized T get() { + while (available == false) { + try { + wait(); + } catch (InterruptedException e) { + } + } + available = false; + notifyAll(); + return contents; + } + + public synchronized void put(T value) { + while (available == true) { + try { + wait(); + } catch (InterruptedException e) { + } + } + contents = value; + available = true; + notifyAll(); + } + } + // + + /** + * 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() { + + jScrollPane1 = new javax.swing.JScrollPane(); + jList1 = new javax.swing.JList(); + jButton1 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jList1.setModel(new javax.swing.AbstractListModel() { + String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; + public int getSize() { return strings.length; } + public Object getElementAt(int i) { return strings[i]; } + }); + jScrollPane1.setViewportView(jList1); + + jButton1.setText("Scegli"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jButton1) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 335, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(53, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(23, 23, 23) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(44, 44, 44) + .addComponent(jButton1) + .addContainerGap(64, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + // TODO add your handling code here: + T selected = (T) jList1.getSelectedValue(); + this.syncBuffer.put(selected); + this.dispose(); + }//GEN-LAST:event_jButton1ActionPerformed + + /** + * @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(GenericSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(GenericSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(GenericSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(GenericSelector.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + List list = new java.util.ArrayList<>(); + list.add("A"); + list.add("B"); + list.add("C"); + list.add("D"); + + System.out.println(GenericSelector.selectOptions(list)); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JList jList1; + private javax.swing.JScrollPane jScrollPane1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/GUI/Main.form b/src/GUI/Main.form index 8e35596..09734c1 100644 --- a/src/GUI/Main.form +++ b/src/GUI/Main.form @@ -140,6 +140,9 @@
+ + + @@ -178,6 +181,9 @@ + + + diff --git a/src/GUI/Main.java b/src/GUI/Main.java index 76b343a..0163065 100644 --- a/src/GUI/Main.java +++ b/src/GUI/Main.java @@ -1,297 +1,299 @@ -package GUI; - -import GUI.spia.GestisciSessioneDiLavoro; -import GUI.user.Registrazione; -import GUI.user.Utente_Regolamentare; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.Vector; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.JFrame; -import model.Studente; -import model.spia.Spia; - -/** - * - * @author MASTER - */ -public class Main extends javax.swing.JFrame { - - /** - * Creates new form Login - */ - public Main() { - initComponents(); - jLabel6.setVisible(false); //facciamo scomparire la scritta "nome utente o password errato" - } - - /** - * 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() { - - jButton2 = new javax.swing.JButton(); - buttonGroup1 = new javax.swing.ButtonGroup(); - buttonGroup2 = new javax.swing.ButtonGroup(); - buttonGroup3 = new javax.swing.ButtonGroup(); - jCheckBox1 = new javax.swing.JCheckBox(); - buttonGroup4 = new javax.swing.ButtonGroup(); - buttonGroup5 = new javax.swing.ButtonGroup(); - jLabel1 = new javax.swing.JLabel(); - jTextField1 = new javax.swing.JTextField(); - jLabel2 = new javax.swing.JLabel(); - jLabel3 = new javax.swing.JLabel(); - jButton1 = new javax.swing.JButton(); - jButton3 = new javax.swing.JButton(); - jLabel4 = new javax.swing.JLabel(); - jLabel5 = new javax.swing.JLabel(); - jPasswordField1 = new javax.swing.JPasswordField(); - jRadioButton1 = new javax.swing.JRadioButton(); - jRadioButton2 = new javax.swing.JRadioButton(); - jLabel6 = new javax.swing.JLabel(); - - jButton2.setText("jButton2"); - - jCheckBox1.setText("jCheckBox1"); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jLabel1.setFont(new java.awt.Font("Times New Roman", 0, 24)); // NOI18N - jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); - jLabel1.setText("Benvenuto su CryptoHelper!!"); - - jTextField1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jTextField1ActionPerformed(evt); - } - }); - - jLabel2.setText("Username"); - - jLabel3.setText("Password"); - - jButton1.setText("Log in"); - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - - jButton3.setText("Registrati"); - jButton3.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton3ActionPerformed(evt); - } - }); - - jLabel5.setText("Login come:"); - - jPasswordField1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jPasswordField1ActionPerformed(evt); - } - }); - - buttonGroup1.add(jRadioButton1); - jRadioButton1.setText("Spia"); - jRadioButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jRadioButton1ActionPerformed(evt); - } - }); - - buttonGroup1.add(jRadioButton2); - jRadioButton2.setText("Utente Regolamentare"); - - jLabel6.setForeground(new java.awt.Color(255, 0, 0)); - jLabel6.setText("Nome utente e/o password errata"); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGap(71, 71, 71) - .addComponent(jLabel4) - .addGap(0, 0, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGap(83, 83, 83) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel2) - .addComponent(jLabel3)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE) - .addComponent(jPasswordField1)))) - .addGap(69, 69, 69)) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(58, 58, 58) - .addComponent(jLabel5) - .addGap(67, 67, 67) - .addComponent(jRadioButton1) - .addGap(18, 18, 18) - .addComponent(jRadioButton2)) - .addGroup(layout.createSequentialGroup() - .addGap(123, 123, 123) - .addComponent(jLabel6))) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(layout.createSequentialGroup() - .addGap(42, 42, 42) - .addComponent(jButton3) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jButton1) - .addGap(47, 47, 47)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(jLabel1) - .addGap(80, 80, 80) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel2)) - .addGap(34, 34, 34) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel3) - .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(jLabel6) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel5) - .addComponent(jRadioButton1) - .addComponent(jRadioButton2)) - .addGap(43, 43, 43) - .addComponent(jLabel4) - .addGap(34, 34, 34) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jButton3) - .addComponent(jButton1)) - .addGap(36, 36, 36)) - ); - - pack(); - }// //GEN-END:initComponents - - private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed - // TODO add your handling code here: - }//GEN-LAST:event_jTextField1ActionPerformed - - private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed - Registrazione r = new Registrazione(); - r.setVisible(true); - }//GEN-LAST:event_jButton3ActionPerformed - - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - - if (jTextField1.getText().equals("")) { - jLabel4.setText("Inserisci username"); - } - if (jPasswordField1.getPassword().equals("")) { - jLabel4.setText("Inserisci Password"); - } else { - - if (jRadioButton1.isSelected()) { - final Spia s = new Spia(jTextField1.getText(), "" + jPasswordField1.getText()); - boolean conferma = s.login(); - if (!conferma) { - jLabel4.setText("Username e/o password non corretti: riprova"); - } else { - new Thread( new Runnable() { - public void run() { - new GestisciSessioneDiLavoro(s).setVisible(true); - } - }).start(); - } - } - if (jRadioButton2.isSelected()) { - final Studente s = new Studente(jTextField1.getText(), "" + jPasswordField1.getText()); - boolean conferma = s.login(); - if (!conferma) { - jLabel4.setText("Username e/o password non corretti: riprova"); - } else { - new Thread( new Runnable() { - public void run() { - new Utente_Regolamentare(s).setVisible(true); - } - }).start(); - } - } - } - - }//GEN-LAST:event_jButton1ActionPerformed - - private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed - // TODO add your handling code here: - }//GEN-LAST:event_jRadioButton1ActionPerformed - - private void jPasswordField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPasswordField1ActionPerformed - // TODO add your handling code here: - }//GEN-LAST:event_jPasswordField1ActionPerformed - - /** - * @param args the command line arguments - */ - public static synchronized 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(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } - // - - new Main().setVisible(true); - - } - - private static Object lock = new Object(); - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.ButtonGroup buttonGroup1; - private javax.swing.ButtonGroup buttonGroup2; - private javax.swing.ButtonGroup buttonGroup3; - private javax.swing.ButtonGroup buttonGroup4; - private javax.swing.ButtonGroup buttonGroup5; - private javax.swing.JButton jButton1; - private javax.swing.JButton jButton2; - private javax.swing.JButton jButton3; - private javax.swing.JCheckBox jCheckBox1; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; - private javax.swing.JLabel jLabel4; - private javax.swing.JLabel jLabel5; - private javax.swing.JLabel jLabel6; - private javax.swing.JPasswordField jPasswordField1; - private javax.swing.JRadioButton jRadioButton1; - private javax.swing.JRadioButton jRadioButton2; - private javax.swing.JTextField jTextField1; - // End of variables declaration//GEN-END:variables -} +package GUI; + +import GUI.spia.GestisciSessioneDiLavoro; +import GUI.user.Registrazione; +import GUI.user.Utente_Regolamentare; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.util.Vector; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.JFrame; +import model.Studente; +import model.spia.Spia; + +/** + * + * @author MASTER + */ +public class Main extends javax.swing.JFrame { + + /** + * Creates new form Login + */ + public Main() { + initComponents(); + jLabel6.setVisible(false); //facciamo scomparire la scritta "nome utente o password errato" + } + + /** + * 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() { + + jButton2 = new javax.swing.JButton(); + buttonGroup1 = new javax.swing.ButtonGroup(); + buttonGroup2 = new javax.swing.ButtonGroup(); + buttonGroup3 = new javax.swing.ButtonGroup(); + jCheckBox1 = new javax.swing.JCheckBox(); + buttonGroup4 = new javax.swing.ButtonGroup(); + buttonGroup5 = new javax.swing.ButtonGroup(); + jLabel1 = new javax.swing.JLabel(); + jTextField1 = new javax.swing.JTextField(); + jLabel2 = new javax.swing.JLabel(); + jLabel3 = new javax.swing.JLabel(); + jButton1 = new javax.swing.JButton(); + jButton3 = new javax.swing.JButton(); + jLabel4 = new javax.swing.JLabel(); + jLabel5 = new javax.swing.JLabel(); + jPasswordField1 = new javax.swing.JPasswordField(); + jRadioButton1 = new javax.swing.JRadioButton(); + jRadioButton2 = new javax.swing.JRadioButton(); + jLabel6 = new javax.swing.JLabel(); + + jButton2.setText("jButton2"); + + jCheckBox1.setText("jCheckBox1"); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jLabel1.setFont(new java.awt.Font("Times New Roman", 0, 24)); // NOI18N + jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jLabel1.setText("Benvenuto su CryptoHelper!!"); + + jTextField1.setText("bob"); + jTextField1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jTextField1ActionPerformed(evt); + } + }); + + jLabel2.setText("Username"); + + jLabel3.setText("Password"); + + jButton1.setText("Log in"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jButton3.setText("Registrati"); + jButton3.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton3ActionPerformed(evt); + } + }); + + jLabel5.setText("Login come:"); + + jPasswordField1.setText("root"); + jPasswordField1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jPasswordField1ActionPerformed(evt); + } + }); + + buttonGroup1.add(jRadioButton1); + jRadioButton1.setText("Spia"); + jRadioButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jRadioButton1ActionPerformed(evt); + } + }); + + buttonGroup1.add(jRadioButton2); + jRadioButton2.setText("Utente Regolamentare"); + + jLabel6.setForeground(new java.awt.Color(255, 0, 0)); + jLabel6.setText("Nome utente e/o password errata"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(71, 71, 71) + .addComponent(jLabel4) + .addGap(0, 0, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(83, 83, 83) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel2) + .addComponent(jLabel3)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE) + .addComponent(jPasswordField1)))) + .addGap(69, 69, 69)) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(58, 58, 58) + .addComponent(jLabel5) + .addGap(67, 67, 67) + .addComponent(jRadioButton1) + .addGap(18, 18, 18) + .addComponent(jRadioButton2)) + .addGroup(layout.createSequentialGroup() + .addGap(123, 123, 123) + .addComponent(jLabel6))) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addGap(42, 42, 42) + .addComponent(jButton3) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jButton1) + .addGap(47, 47, 47)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel1) + .addGap(80, 80, 80) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel2)) + .addGap(34, 34, 34) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel3) + .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jLabel6) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel5) + .addComponent(jRadioButton1) + .addComponent(jRadioButton2)) + .addGap(43, 43, 43) + .addComponent(jLabel4) + .addGap(34, 34, 34) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton3) + .addComponent(jButton1)) + .addGap(36, 36, 36)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jTextField1ActionPerformed + + private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed + Registrazione r = new Registrazione(); + r.setVisible(true); + }//GEN-LAST:event_jButton3ActionPerformed + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + + if (jTextField1.getText().equals("")) { + jLabel4.setText("Inserisci username"); + } + if (jPasswordField1.getPassword().equals("")) { + jLabel4.setText("Inserisci Password"); + } else { + + if (jRadioButton1.isSelected()) { + final Spia s = new Spia(jTextField1.getText(), "" + jPasswordField1.getText()); + boolean conferma = s.login(); + if (!conferma) { + jLabel4.setText("Username e/o password non corretti: riprova"); + } else { + new Thread( new Runnable() { + public void run() { + new GestisciSessioneDiLavoro(s).setVisible(true); + } + }).start(); + } + } + if (jRadioButton2.isSelected()) { + final Studente s = new Studente(jTextField1.getText(), "" + jPasswordField1.getText()); + boolean conferma = s.login(); + if (!conferma) { + jLabel4.setText("Username e/o password non corretti: riprova"); + } else { + new Thread( new Runnable() { + public void run() { + new Utente_Regolamentare(s).setVisible(true); + } + }).start(); + } + } + } + + }//GEN-LAST:event_jButton1ActionPerformed + + private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jRadioButton1ActionPerformed + + private void jPasswordField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPasswordField1ActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jPasswordField1ActionPerformed + + /** + * @param args the command line arguments + */ + public static synchronized 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(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + new Main().setVisible(true); + + } + + private static Object lock = new Object(); + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.ButtonGroup buttonGroup1; + private javax.swing.ButtonGroup buttonGroup2; + private javax.swing.ButtonGroup buttonGroup3; + private javax.swing.ButtonGroup buttonGroup4; + private javax.swing.ButtonGroup buttonGroup5; + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + private javax.swing.JButton jButton3; + private javax.swing.JCheckBox jCheckBox1; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JLabel jLabel5; + private javax.swing.JLabel jLabel6; + private javax.swing.JPasswordField jPasswordField1; + private javax.swing.JRadioButton jRadioButton1; + private javax.swing.JRadioButton jRadioButton2; + private javax.swing.JTextField jTextField1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/GUI/PopUpViewer.form b/src/GUI/PopUpViewer.form index b6af39d..5431646 100644 --- a/src/GUI/PopUpViewer.form +++ b/src/GUI/PopUpViewer.form @@ -1,76 +1,76 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/PopUpViewer.java b/src/GUI/PopUpViewer.java index 8e6a9d9..c6f6432 100644 --- a/src/GUI/PopUpViewer.java +++ b/src/GUI/PopUpViewer.java @@ -1,123 +1,123 @@ -/* - * 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 GUI; - -/** - * - * @author user - */ -public class PopUpViewer extends javax.swing.JFrame { - - /** - * Creates new form PopUpViewer - */ - public PopUpViewer() { - initComponents(); - } - - public PopUpViewer(String toString) { - this(); - jTextArea1.setText(toString); - } - - /** - * 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() { - - jScrollPane1 = new javax.swing.JScrollPane(); - jTextArea1 = new javax.swing.JTextArea(); - jButton1 = new javax.swing.JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jTextArea1.setColumns(20); - jTextArea1.setRows(5); - jScrollPane1.setViewportView(jTextArea1); - - jButton1.setText("Ok"); - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 432, Short.MAX_VALUE) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(jButton1))) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 294, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jButton1) - .addContainerGap(34, Short.MAX_VALUE)) - ); - - pack(); - }// //GEN-END:initComponents - - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - this.dispose(); - }//GEN-LAST:event_jButton1ActionPerformed - - /** - * @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(PopUpViewer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(PopUpViewer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(PopUpViewer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(PopUpViewer.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 PopUpViewer().setVisible(true); - } - }); - } - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton1; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JTextArea jTextArea1; - // End of variables declaration//GEN-END:variables -} +/* + * 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 GUI; + +/** + * + * @author user + */ +public class PopUpViewer extends javax.swing.JFrame { + + /** + * Creates new form PopUpViewer + */ + public PopUpViewer() { + initComponents(); + } + + public PopUpViewer(String toString) { + this(); + jTextArea1.setText(toString); + } + + /** + * 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() { + + jScrollPane1 = new javax.swing.JScrollPane(); + jTextArea1 = new javax.swing.JTextArea(); + jButton1 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jTextArea1.setColumns(20); + jTextArea1.setRows(5); + jScrollPane1.setViewportView(jTextArea1); + + jButton1.setText("Ok"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 432, Short.MAX_VALUE) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(jButton1))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 294, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButton1) + .addContainerGap(34, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + this.dispose(); + }//GEN-LAST:event_jButton1ActionPerformed + + /** + * @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(PopUpViewer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(PopUpViewer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(PopUpViewer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(PopUpViewer.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 PopUpViewer().setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextArea jTextArea1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/GUI/spia/CicloDiAnalisi.form b/src/GUI/spia/CicloDiAnalisi.form index 808db19..349cd9a 100644 --- a/src/GUI/spia/CicloDiAnalisi.form +++ b/src/GUI/spia/CicloDiAnalisi.form @@ -1,156 +1,156 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/spia/CicloDiAnalisi.java b/src/GUI/spia/CicloDiAnalisi.java index 464134e..c47d415 100644 --- a/src/GUI/spia/CicloDiAnalisi.java +++ b/src/GUI/spia/CicloDiAnalisi.java @@ -1,222 +1,220 @@ -/* - * 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 GUI.spia; - -import GUI.PopUpViewer; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.Observable; -import java.util.Observer; -import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.DefaultTreeModel; -import javax.swing.tree.TreeNode; -import javax.swing.tree.TreePath; -import model.spia.AnalisiFrequenze; -import model.spia.Ipotesi; -import model.spia.Sessione; -import model.spia.SostituzioneSemplice; -import model.spia.StrumentoDiManipolazione; -import model.spia.StrumentoDiSupporto; -import model.spia.RipristinaIpotesiPrecedente; - -/** - * - * @author davide - */ -public class CicloDiAnalisi extends javax.swing.JFrame implements Observer { - - public CicloDiAnalisi() { - initComponents(); - } - - /** - * Creates new form CicloDiAnalisi - */ - public CicloDiAnalisi(Sessione s) { - this(); - this.sessione = s; - - updateIpotesi(); - s.addObserver( this ); - } - - /** - * 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() { - - jLabel2 = new javax.swing.JLabel(); - jButton1 = new javax.swing.JButton(); - jButton2 = new javax.swing.JButton(); - jScrollPane1 = new javax.swing.JScrollPane(); - jTextArea1 = new javax.swing.JTextArea(); - jButton3 = new javax.swing.JButton(); - jScrollPane2 = new javax.swing.JScrollPane(); - jTree1 = new javax.swing.JTree(); - jButton4 = new javax.swing.JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); - - jLabel2.setText("Ciclo di Analisi"); - - jButton1.setLabel("Esegui analisi frequenze"); - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - - jButton2.setLabel("Sostituisci una lettera"); - jButton2.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton2ActionPerformed(evt); - } - }); - - jTextArea1.setEditable(false); - jTextArea1.setColumns(20); - jTextArea1.setRows(5); - jTextArea1.setText("Testo parzialmente decifrato"); - jScrollPane1.setViewportView(jTextArea1); - - jButton3.setText("TerminaCicloDiAnalisi"); - jButton3.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton3ActionPerformed(evt); - } - }); - - jScrollPane2.setViewportView(jTree1); - - jButton4.setText("RipristinaIpotesi"); - jButton4.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton4ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(74, 74, 74) - .addComponent(jLabel2) - .addGap(117, 117, 117) - .addComponent(jButton3)) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 434, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addGap(18, 18, 18)) - .addGroup(layout.createSequentialGroup() - .addGap(58, 58, 58) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jButton1) - .addGap(30, 30, 30))) - .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) - .addContainerGap()) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel2) - .addComponent(jButton3)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(27, 27, 27) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jButton2) - .addComponent(jButton1)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(jButton4) - .addGap(26, 26, 26)))) - ); - - pack(); - }// //GEN-END:initComponents - - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - StrumentoDiSupporto a = new AnalisiFrequenze(); - - a.start( this.sessione.getIpotesiCorrente().getMessaggioParzialmenteDecifrato() ); - new PopUpViewer(a.toString()).setVisible(true); - }//GEN-LAST:event_jButton1ActionPerformed - - private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed - StrumentoDiManipolazione s = new SostituzioneSemplice(); - s.elabora( this.sessione ); - }//GEN-LAST:event_jButton2ActionPerformed - - private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed - this.dispose(); - synchronized( this.sessione ) { - //torna il controllo a Sessione.start(); - this.sessione.notify(); - } - }//GEN-LAST:event_jButton3ActionPerformed - - private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed - StrumentoDiManipolazione s = new RipristinaIpotesiPrecedente(); - s.elabora( this.sessione ); - }//GEN-LAST:event_jButton4ActionPerformed - - private Sessione sessione; - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton1; - private javax.swing.JButton jButton2; - private javax.swing.JButton jButton3; - private javax.swing.JButton jButton4; - private javax.swing.JLabel jLabel2; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JScrollPane jScrollPane2; - private javax.swing.JTextArea jTextArea1; - private javax.swing.JTree jTree1; - // End of variables declaration//GEN-END:variables - - - private void updateIpotesi() { - Sessione s = this.sessione; - Ipotesi ip = s.getIpotesiCorrente(); - - jTextArea1.setText(ip.getMessaggioParzialmenteDecifrato()); - - DefaultTreeModel treeModel = new DefaultTreeModel( s.getIpotesiRadice() ); - jTree1.setModel( treeModel ); - - for( int i = 0; i < jTree1.getRowCount(); i++ ) { - jTree1.expandRow(i); - } - - DefaultMutableTreeNode currentNode = this.sessione.getIpotesiCorrente(); - TreeNode[] nodes = ((DefaultTreeModel) jTree1.getModel()).getPathToRoot( currentNode ); - TreePath tpath = new TreePath(nodes); - jTree1.scrollPathToVisible(tpath); - jTree1.setSelectionPath(tpath); - } - @Override - public void update(Observable o, Object arg) { - updateIpotesi(); - } -} +/* + * 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 GUI.spia; + +import GUI.PopUpViewer; +import java.util.Observable; +import java.util.Observer; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeNode; +import javax.swing.tree.TreePath; +import model.spia.AnalisiFrequenze; +import model.spia.Ipotesi; +import model.spia.Sessione; +import model.spia.SostituzioneSemplice; +import model.spia.StrumentoDiManipolazione; +import model.spia.StrumentoDiSupporto; +import model.spia.RipristinaIpotesiPrecedente; + +/** + * + * @author davide + */ +public class CicloDiAnalisi extends javax.swing.JFrame implements Observer { + + public CicloDiAnalisi() { + initComponents(); + } + + /** + * Creates new form CicloDiAnalisi + */ + public CicloDiAnalisi(Sessione s) { + this(); + this.sessione = s; + + updateIpotesi(); + s.addObserver( this ); + } + + /** + * 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() { + + jLabel2 = new javax.swing.JLabel(); + jButton1 = new javax.swing.JButton(); + jButton2 = new javax.swing.JButton(); + jScrollPane1 = new javax.swing.JScrollPane(); + jTextArea1 = new javax.swing.JTextArea(); + jButton3 = new javax.swing.JButton(); + jScrollPane2 = new javax.swing.JScrollPane(); + jTree1 = new javax.swing.JTree(); + jButton4 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jLabel2.setText("Ciclo di Analisi"); + + jButton1.setLabel("Esegui analisi frequenze"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jButton2.setLabel("Sostituisci una lettera"); + jButton2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton2ActionPerformed(evt); + } + }); + + jTextArea1.setEditable(false); + jTextArea1.setColumns(20); + jTextArea1.setRows(5); + jTextArea1.setText("Testo parzialmente decifrato"); + jScrollPane1.setViewportView(jTextArea1); + + jButton3.setText("TerminaCicloDiAnalisi"); + jButton3.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton3ActionPerformed(evt); + } + }); + + jScrollPane2.setViewportView(jTree1); + + jButton4.setText("RipristinaIpotesi"); + jButton4.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton4ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(74, 74, 74) + .addComponent(jLabel2) + .addGap(117, 117, 117) + .addComponent(jButton3)) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 434, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGap(18, 18, 18)) + .addGroup(layout.createSequentialGroup() + .addGap(58, 58, 58) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jButton1) + .addGap(30, 30, 30))) + .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) + .addContainerGap()) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel2) + .addComponent(jButton3)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(27, 27, 27) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton2) + .addComponent(jButton1)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jButton4) + .addGap(26, 26, 26)))) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + StrumentoDiSupporto a = new AnalisiFrequenze(); + + a.start( this.sessione.getIpotesiCorrente().getMessaggioParzialmenteDecifrato() ); + new PopUpViewer(a.toString()).setVisible(true); + }//GEN-LAST:event_jButton1ActionPerformed + + private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed + StrumentoDiManipolazione s = new SostituzioneSemplice(); + s.elabora( this.sessione ); + }//GEN-LAST:event_jButton2ActionPerformed + + private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed + this.dispose(); + synchronized( this.sessione ) { + //torna il controllo a Sessione.start(); + this.sessione.notify(); + } + }//GEN-LAST:event_jButton3ActionPerformed + + private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed + StrumentoDiManipolazione s = new RipristinaIpotesiPrecedente(); + s.elabora( this.sessione ); + }//GEN-LAST:event_jButton4ActionPerformed + + private Sessione sessione; + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + private javax.swing.JButton jButton3; + private javax.swing.JButton jButton4; + private javax.swing.JLabel jLabel2; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JTextArea jTextArea1; + private javax.swing.JTree jTree1; + // End of variables declaration//GEN-END:variables + + + private void updateIpotesi() { + Sessione s = this.sessione; + Ipotesi ip = s.getIpotesiCorrente(); + + jTextArea1.setText(ip.getMessaggioParzialmenteDecifrato()); + + DefaultTreeModel treeModel = new DefaultTreeModel( s.getIpotesiRadice() ); + jTree1.setModel( treeModel ); + + for( int i = 0; i < jTree1.getRowCount(); i++ ) { + jTree1.expandRow(i); + } + + DefaultMutableTreeNode currentNode = this.sessione.getIpotesiCorrente(); + TreeNode[] nodes = ((DefaultTreeModel) jTree1.getModel()).getPathToRoot( currentNode ); + TreePath tpath = new TreePath(nodes); + jTree1.scrollPathToVisible(tpath); + jTree1.setSelectionPath(tpath); + } + @Override + public void update(Observable o, Object arg) { + updateIpotesi(); + } +} diff --git a/src/GUI/spia/GestisciSessioneDiLavoro.form b/src/GUI/spia/GestisciSessioneDiLavoro.form index 7456f47..c998f73 100644 --- a/src/GUI/spia/GestisciSessioneDiLavoro.form +++ b/src/GUI/spia/GestisciSessioneDiLavoro.form @@ -1,77 +1,77 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/spia/GestisciSessioneDiLavoro.java b/src/GUI/spia/GestisciSessioneDiLavoro.java index fe0871e..8f9cd97 100644 --- a/src/GUI/spia/GestisciSessioneDiLavoro.java +++ b/src/GUI/spia/GestisciSessioneDiLavoro.java @@ -1,136 +1,136 @@ -/* - * 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 GUI.spia; - -import GUI.GenericSelector; -import java.util.List; -import javax.swing.JFrame; -import model.Messaggio; -import model.spia.Sessione; -import model.spia.Spia; - -/** - * - * @author user - */ -public class GestisciSessioneDiLavoro extends javax.swing.JFrame { - - /** - * Creates new form GestisciSessioneDiLavoro - */ - public GestisciSessioneDiLavoro( Spia s ) { - this.spia = s; - 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() { - - jButton1 = new javax.swing.JButton(); - jButton2 = new javax.swing.JButton(); - jButton3 = new javax.swing.JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - - jButton1.setText("Nuova Sesione"); - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - - jButton2.setText("Ripristina Sessione"); - jButton2.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton2ActionPerformed(evt); - } - }); - - jButton3.setText("Elimina Sessione"); - jButton3.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton3ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(32, 32, 32) - .addComponent(jButton1) - .addGap(26, 26, 26) - .addComponent(jButton2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE) - .addComponent(jButton3) - .addGap(34, 34, 34)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(59, 59, 59) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jButton1) - .addComponent(jButton2) - .addComponent(jButton3)) - .addContainerGap(212, Short.MAX_VALUE)) - ); - - pack(); - }// //GEN-END:initComponents - - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - final Spia s = this.spia; - final JFrame self = this; - new Thread( new Runnable() { - public void run() { - self.setVisible(false); - List options = Messaggio.getMessaggi(); - for (Messaggio m : options) { - m.setToStringF("%lingua%, %testoCif%"); - } - Messaggio selectedMsg = GenericSelector.selectOptions(options); - s.startNewSessione( selectedMsg ); - self.setVisible(true); - } - }).start(); - }//GEN-LAST:event_jButton1ActionPerformed - - private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed - final Spia s = this.spia; - new Thread( new Runnable() { - public void run() { - s.restoreSessione(); - } - }).start(); - }//GEN-LAST:event_jButton2ActionPerformed - - private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed - final Spia s = this.spia; - new Thread( new Runnable() { - public void run() { - s.deleteSessione(); - } - }).start(); - }//GEN-LAST:event_jButton3ActionPerformed - - - private Spia spia; - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton1; - private javax.swing.JButton jButton2; - private javax.swing.JButton jButton3; - // End of variables declaration//GEN-END:variables -} +/* + * 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 GUI.spia; + +import GUI.GenericSelector; +import java.util.List; +import javax.swing.JFrame; +import model.Messaggio; +import model.spia.Sessione; +import model.spia.Spia; + +/** + * + * @author user + */ +public class GestisciSessioneDiLavoro extends javax.swing.JFrame { + + /** + * Creates new form GestisciSessioneDiLavoro + */ + public GestisciSessioneDiLavoro( Spia s ) { + this.spia = s; + 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() { + + jButton1 = new javax.swing.JButton(); + jButton2 = new javax.swing.JButton(); + jButton3 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jButton1.setText("Nuova Sesione"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jButton2.setText("Ripristina Sessione"); + jButton2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton2ActionPerformed(evt); + } + }); + + jButton3.setText("Elimina Sessione"); + jButton3.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton3ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(32, 32, 32) + .addComponent(jButton1) + .addGap(26, 26, 26) + .addComponent(jButton2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE) + .addComponent(jButton3) + .addGap(34, 34, 34)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(59, 59, 59) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton1) + .addComponent(jButton2) + .addComponent(jButton3)) + .addContainerGap(212, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + final Spia s = this.spia; + final JFrame self = this; + new Thread( new Runnable() { + public void run() { + self.setVisible(false); + List options = Messaggio.getMessaggi(); + for (Messaggio m : options) { + m.setToStringF("%lingua%, %testoCif%"); + } + Messaggio selectedMsg = GenericSelector.selectOptions(options); + s.startNewSessione( selectedMsg ); + self.setVisible(true); + } + }).start(); + }//GEN-LAST:event_jButton1ActionPerformed + + private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed + final Spia s = this.spia; + new Thread( new Runnable() { + public void run() { + s.restoreSessione(); + } + }).start(); + }//GEN-LAST:event_jButton2ActionPerformed + + private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed + final Spia s = this.spia; + new Thread( new Runnable() { + public void run() { + s.deleteSessione(); + } + }).start(); + }//GEN-LAST:event_jButton3ActionPerformed + + + private Spia spia; + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + private javax.swing.JButton jButton3; + // End of variables declaration//GEN-END:variables +} diff --git a/src/GUI/spia/GestisciSessioni.form b/src/GUI/spia/GestisciSessioni.form index dfc9091..e921177 100644 --- a/src/GUI/spia/GestisciSessioni.form +++ b/src/GUI/spia/GestisciSessioni.form @@ -1,103 +1,103 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/spia/GestisciSessioni.java b/src/GUI/spia/GestisciSessioni.java index 1d8db26..e79352c 100644 --- a/src/GUI/spia/GestisciSessioni.java +++ b/src/GUI/spia/GestisciSessioni.java @@ -1,96 +1,96 @@ -/* - * 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 GUI.spia; - -/** - * - * @author davide - */ -public class GestisciSessioni extends javax.swing.JFrame { - - /** - * Creates new form GestisciSessioni - */ - public GestisciSessioni() { - 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() { - - jLabel1 = new javax.swing.JLabel(); - jScrollPane1 = new javax.swing.JScrollPane(); - jList1 = new javax.swing.JList(); - jButton1 = new javax.swing.JButton(); - jButton2 = new javax.swing.JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jLabel1.setText("Elenco sessioni di lavoro iniziate in passato"); - - jList1.setModel(new javax.swing.AbstractListModel() { - String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; - public int getSize() { return strings.length; } - public Object getElementAt(int i) { return strings[i]; } - }); - jScrollPane1.setViewportView(jList1); - - jButton1.setText("Riprendi sessione"); - - jButton2.setText("Cancella sessione"); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(98, 98, 98) - .addComponent(jLabel1)) - .addGroup(layout.createSequentialGroup() - .addGap(20, 20, 20) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 352, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(layout.createSequentialGroup() - .addGap(46, 46, 46) - .addComponent(jButton1) - .addGap(61, 61, 61) - .addComponent(jButton2))) - .addContainerGap(28, Short.MAX_VALUE)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(jLabel1) - .addGap(30, 30, 30) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jButton1) - .addComponent(jButton2)) - .addContainerGap()) - ); - - pack(); - }// //GEN-END:initComponents - - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton1; - private javax.swing.JButton jButton2; - private javax.swing.JLabel jLabel1; - private javax.swing.JList jList1; - private javax.swing.JScrollPane jScrollPane1; - // End of variables declaration//GEN-END:variables -} +/* + * 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 GUI.spia; + +/** + * + * @author davide + */ +public class GestisciSessioni extends javax.swing.JFrame { + + /** + * Creates new form GestisciSessioni + */ + public GestisciSessioni() { + 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() { + + jLabel1 = new javax.swing.JLabel(); + jScrollPane1 = new javax.swing.JScrollPane(); + jList1 = new javax.swing.JList(); + jButton1 = new javax.swing.JButton(); + jButton2 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jLabel1.setText("Elenco sessioni di lavoro iniziate in passato"); + + jList1.setModel(new javax.swing.AbstractListModel() { + String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; + public int getSize() { return strings.length; } + public Object getElementAt(int i) { return strings[i]; } + }); + jScrollPane1.setViewportView(jList1); + + jButton1.setText("Riprendi sessione"); + + jButton2.setText("Cancella sessione"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(98, 98, 98) + .addComponent(jLabel1)) + .addGroup(layout.createSequentialGroup() + .addGap(20, 20, 20) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 352, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addGap(46, 46, 46) + .addComponent(jButton1) + .addGap(61, 61, 61) + .addComponent(jButton2))) + .addContainerGap(28, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel1) + .addGap(30, 30, 30) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton1) + .addComponent(jButton2)) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + private javax.swing.JLabel jLabel1; + private javax.swing.JList jList1; + private javax.swing.JScrollPane jScrollPane1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/GUI/spia/RipristinaIpotesiPrecedenteGUI.form b/src/GUI/spia/RipristinaIpotesiPrecedenteGUI.form index 674ecae..20d18fc 100644 --- a/src/GUI/spia/RipristinaIpotesiPrecedenteGUI.form +++ b/src/GUI/spia/RipristinaIpotesiPrecedenteGUI.form @@ -1,87 +1,87 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/spia/RipristinaIpotesiPrecedenteGUI.java b/src/GUI/spia/RipristinaIpotesiPrecedenteGUI.java index 9fa5504..a42db3e 100644 --- a/src/GUI/spia/RipristinaIpotesiPrecedenteGUI.java +++ b/src/GUI/spia/RipristinaIpotesiPrecedenteGUI.java @@ -1,128 +1,128 @@ -/* - * 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 GUI.spia; - -import GUI.PopUpViewer; -import javax.swing.tree.DefaultTreeModel; -import javax.swing.tree.TreeSelectionModel; -import model.spia.Ipotesi; -import model.spia.Sessione; - -/** - * - * @author user - */ -public class RipristinaIpotesiPrecedenteGUI extends javax.swing.JFrame { - - /** - * Creates new form RipristinaIpotesiPrecedente - */ - public RipristinaIpotesiPrecedenteGUI() { - initComponents(); - } - - public RipristinaIpotesiPrecedenteGUI(Sessione s) { - this(); - this.sessione = s; - - Ipotesi ip = s.getIpotesiCorrente(); - - DefaultTreeModel treeModel = new DefaultTreeModel( s.getIpotesiRadice() ); - jTree1.setModel( treeModel ); - jTree1.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); - - for( int i = 0; i < jTree1.getRowCount(); i++ ) { - jTree1.expandRow(i); - } - } - - /** - * 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() { - - jScrollPane1 = new javax.swing.JScrollPane(); - jTree1 = new javax.swing.JTree(); - jButton1 = new javax.swing.JButton(); - jButton2 = new javax.swing.JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jScrollPane1.setViewportView(jTree1); - - jButton1.setText("Annulla"); - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - - jButton2.setText("Ripristina"); - jButton2.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton2ActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(20, 20, 20) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 352, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addContainerGap() - .addComponent(jButton1) - .addGap(80, 80, 80) - .addComponent(jButton2))) - .addContainerGap(28, Short.MAX_VALUE)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jButton1) - .addComponent(jButton2)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - pack(); - }// //GEN-END:initComponents - - private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed - Ipotesi selected = (Ipotesi)jTree1.getLastSelectedPathComponent(); - if( selected != null ) { - this.sessione.setIpotesiCorrente(selected); - this.dispose(); - } else { - new PopUpViewer("Scegli l'ipotesi da ripristinare").setVisible(true); - } - }//GEN-LAST:event_jButton2ActionPerformed - - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - this.dispose(); - }//GEN-LAST:event_jButton1ActionPerformed - - - private Sessione sessione; - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton1; - private javax.swing.JButton jButton2; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JTree jTree1; - // End of variables declaration//GEN-END:variables -} +/* + * 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 GUI.spia; + +import GUI.PopUpViewer; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeSelectionModel; +import model.spia.Ipotesi; +import model.spia.Sessione; + +/** + * + * @author user + */ +public class RipristinaIpotesiPrecedenteGUI extends javax.swing.JFrame { + + /** + * Creates new form RipristinaIpotesiPrecedente + */ + public RipristinaIpotesiPrecedenteGUI() { + initComponents(); + } + + public RipristinaIpotesiPrecedenteGUI(Sessione s) { + this(); + this.sessione = s; + + Ipotesi ip = s.getIpotesiCorrente(); + + DefaultTreeModel treeModel = new DefaultTreeModel( s.getIpotesiRadice() ); + jTree1.setModel( treeModel ); + jTree1.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); + + for( int i = 0; i < jTree1.getRowCount(); i++ ) { + jTree1.expandRow(i); + } + } + + /** + * 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() { + + jScrollPane1 = new javax.swing.JScrollPane(); + jTree1 = new javax.swing.JTree(); + jButton1 = new javax.swing.JButton(); + jButton2 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jScrollPane1.setViewportView(jTree1); + + jButton1.setText("Annulla"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jButton2.setText("Ripristina"); + jButton2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton2ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(20, 20, 20) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 352, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addComponent(jButton1) + .addGap(80, 80, 80) + .addComponent(jButton2))) + .addContainerGap(28, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton1) + .addComponent(jButton2)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed + Ipotesi selected = (Ipotesi)jTree1.getLastSelectedPathComponent(); + if( selected != null ) { + this.sessione.setIpotesiCorrente(selected); + this.dispose(); + } else { + new PopUpViewer("Scegli l'ipotesi da ripristinare").setVisible(true); + } + }//GEN-LAST:event_jButton2ActionPerformed + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + this.dispose(); + }//GEN-LAST:event_jButton1ActionPerformed + + + private Sessione sessione; + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTree jTree1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/GUI/spia/SostituzioneSempliceGUI.java b/src/GUI/spia/SostituzioneSempliceGUI.java index a13dcd6..5207faf 100644 --- a/src/GUI/spia/SostituzioneSempliceGUI.java +++ b/src/GUI/spia/SostituzioneSempliceGUI.java @@ -1,195 +1,195 @@ -/* - * 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 GUI.spia; - -import GUI.GenericSelector; -import java.util.List; -import java.util.Observable; -import model.spia.Ipotesi; -import model.spia.Sessione; -import model.spia.SostituzioneSemplice; - -/** - * - * @author davide - */ -public class SostituzioneSempliceGUI extends javax.swing.JFrame { - - public static char[] getCaratteriDaSostituire() { - - final SynchronizedBuffer buff = new SynchronizedBuffer<>(); - - new Thread(new Runnable() { - @Override - public void run() { - SostituzioneSempliceGUI frame = new SostituzioneSempliceGUI(buff); - frame.setVisible(true); - } - }).start(); - - return buff.get(); - } - - // - private static class SynchronizedBuffer { - - private T contents; - private boolean available = false; - - public synchronized T get() { - while (available == false) { - try { - wait(); - } catch (InterruptedException e) { - } - } - available = false; - notifyAll(); - return contents; - } - - public synchronized void put(T value) { - while (available == true) { - try { - wait(); - } catch (InterruptedException e) { - } - } - contents = value; - available = true; - notifyAll(); - } - } - // - - private SynchronizedBuffer buff; - /** - * Creates new form SostituzioneLettera - */ - private SostituzioneSempliceGUI() { - initComponents(); - } - - private SostituzioneSempliceGUI( SynchronizedBuffer buff ) { - this(); - this.buff = buff; - } - - /** - * 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() { - - jLabel1 = new javax.swing.JLabel(); - jLabel2 = new javax.swing.JLabel(); - jLabel3 = new javax.swing.JLabel(); - jTextField1 = new javax.swing.JTextField(); - jTextField2 = new javax.swing.JTextField(); - jButton1 = new javax.swing.JButton(); - jLabel4 = new javax.swing.JLabel(); - - jLabel1.setText("Sostituisci la lettera:"); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jLabel2.setText("Trasforma la lettera: "); - - jLabel3.setText("In:"); - - jTextField1.setMaximumSize(new java.awt.Dimension(1, 1)); - jTextField1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jTextField1ActionPerformed(evt); - } - }); - - jButton1.setText("Sostituisci"); - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - - jLabel4.setText("Se inserisci più caratteri verrà preso in considerazione solo il primo"); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(jButton1) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(47, 47, 47) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel2) - .addComponent(jLabel3)) - .addGap(55, 55, 55) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE) - .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 344, javax.swing.GroupLayout.PREFERRED_SIZE)))) - .addContainerGap(37, Short.MAX_VALUE)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(65, 65, 65) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(jLabel2) - .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(39, 39, 39) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel3) - .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(18, 18, 18) - .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGap(18, 18, 18) - .addComponent(jButton1) - .addContainerGap()) - ); - - pack(); - }// //GEN-END:initComponents - - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - char[] array = new char[2]; - - array[0] = jTextField1.getText().charAt(0); - array[1] = jTextField2.getText().charAt(0); - - this.buff.put( array ); - this.dispose(); - }//GEN-LAST:event_jButton1ActionPerformed - - private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed - // TODO add your handling code here: - }//GEN-LAST:event_jTextField1ActionPerformed - - - public static void main( String[] args ) { - char[] r = getCaratteriDaSostituire(); - System.out.println(r[0]+" "+r[1]); - } - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton1; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; - private javax.swing.JLabel jLabel4; - private javax.swing.JTextField jTextField1; - private javax.swing.JTextField jTextField2; - // End of variables declaration//GEN-END:variables -} +/* + * 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 GUI.spia; + +import GUI.GenericSelector; +import java.util.List; +import java.util.Observable; +import model.spia.Ipotesi; +import model.spia.Sessione; +import model.spia.SostituzioneSemplice; + +/** + * + * @author davide + */ +public class SostituzioneSempliceGUI extends javax.swing.JFrame { + + public static char[] getCaratteriDaSostituire() { + + final SynchronizedBuffer buff = new SynchronizedBuffer<>(); + + new Thread(new Runnable() { + @Override + public void run() { + SostituzioneSempliceGUI frame = new SostituzioneSempliceGUI(buff); + frame.setVisible(true); + } + }).start(); + + return buff.get(); + } + + // + private static class SynchronizedBuffer { + + private T contents; + private boolean available = false; + + public synchronized T get() { + while (available == false) { + try { + wait(); + } catch (InterruptedException e) { + } + } + available = false; + notifyAll(); + return contents; + } + + public synchronized void put(T value) { + while (available == true) { + try { + wait(); + } catch (InterruptedException e) { + } + } + contents = value; + available = true; + notifyAll(); + } + } + // + + private SynchronizedBuffer buff; + /** + * Creates new form SostituzioneLettera + */ + private SostituzioneSempliceGUI() { + initComponents(); + } + + private SostituzioneSempliceGUI( SynchronizedBuffer buff ) { + this(); + this.buff = buff; + } + + /** + * 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() { + + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + jLabel3 = new javax.swing.JLabel(); + jTextField1 = new javax.swing.JTextField(); + jTextField2 = new javax.swing.JTextField(); + jButton1 = new javax.swing.JButton(); + jLabel4 = new javax.swing.JLabel(); + + jLabel1.setText("Sostituisci la lettera:"); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jLabel2.setText("Trasforma la lettera: "); + + jLabel3.setText("In:"); + + jTextField1.setMaximumSize(new java.awt.Dimension(1, 1)); + jTextField1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jTextField1ActionPerformed(evt); + } + }); + + jButton1.setText("Sostituisci"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jLabel4.setText("Se inserisci più caratteri verrà preso in considerazione solo il primo"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jButton1) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(47, 47, 47) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel2) + .addComponent(jLabel3)) + .addGap(55, 55, 55) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE) + .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 344, javax.swing.GroupLayout.PREFERRED_SIZE)))) + .addContainerGap(37, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(65, 65, 65) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jLabel2) + .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(39, 39, 39) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel3) + .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) + .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGap(18, 18, 18) + .addComponent(jButton1) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + char[] array = new char[2]; + + array[0] = jTextField1.getText().charAt(0); + array[1] = jTextField2.getText().charAt(0); + + this.buff.put( array ); + this.dispose(); + }//GEN-LAST:event_jButton1ActionPerformed + + private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jTextField1ActionPerformed + + + public static void main( String[] args ) { + char[] r = getCaratteriDaSostituire(); + System.out.println(r[0]+" "+r[1]); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JTextField jTextField1; + private javax.swing.JTextField jTextField2; + // End of variables declaration//GEN-END:variables +} diff --git a/src/GUI/user/ApriMessaggioPrecedente.form b/src/GUI/user/ApriMessaggioPrecedente.form index fa0a02d..44de8b7 100644 --- a/src/GUI/user/ApriMessaggioPrecedente.form +++ b/src/GUI/user/ApriMessaggioPrecedente.form @@ -2,7 +2,7 @@
- + @@ -26,18 +26,19 @@ - + - + + + + + + + - - - - - @@ -47,9 +48,9 @@ - - - + + + diff --git a/src/GUI/user/ApriMessaggioPrecedente.java b/src/GUI/user/ApriMessaggioPrecedente.java index 8e75409..e3a8cb3 100644 --- a/src/GUI/user/ApriMessaggioPrecedente.java +++ b/src/GUI/user/ApriMessaggioPrecedente.java @@ -14,11 +14,12 @@ * @author MASTER */ public class ApriMessaggioPrecedente extends javax.swing.JFrame { - + Studente s; /** * Creates new form ApriMessaggioPrecedente */ public ApriMessaggioPrecedente(Studente s) { + this.s = s; initComponents(); Messaggio[] l = Messaggio.caricaBozze(s); jList1.setListData(l); @@ -38,7 +39,7 @@ private void initComponents() { jLabel1 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jList1.setModel(new javax.swing.AbstractListModel() { String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; @@ -63,15 +64,15 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(layout.createSequentialGroup() .addGap(349, 349, 349) .addComponent(jLabel1) - .addContainerGap(429, Short.MAX_VALUE)) + .addContainerGap(431, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() - .addComponent(jScrollPane1) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap()) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(42, 42, 42)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -80,18 +81,18 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(22, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButton1) + .addContainerGap(12, Short.MAX_VALUE)) ); pack(); }// //GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - // TODO add your handling code here: Messaggio m = (Messaggio)jList1.getSelectedValue(); - new NuovoMessaggio(null, m).setVisible(true); + System.out.println(this.s.getId()); + new NuovoMessaggio(this.s, m).setVisible(true); }//GEN-LAST:event_jButton1ActionPerformed /** diff --git a/src/GUI/user/DettagliMessaggio.form b/src/GUI/user/DettagliMessaggio.form index 67710ec..048b8f4 100644 --- a/src/GUI/user/DettagliMessaggio.form +++ b/src/GUI/user/DettagliMessaggio.form @@ -2,7 +2,7 @@ - + @@ -58,7 +58,7 @@ - + diff --git a/src/GUI/user/DettagliMessaggio.java b/src/GUI/user/DettagliMessaggio.java index 0d2219a..f29a608 100644 --- a/src/GUI/user/DettagliMessaggio.java +++ b/src/GUI/user/DettagliMessaggio.java @@ -41,9 +41,9 @@ private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - jButton1.setText("Rispondi (non funziona e mai funzionerà)"); + jButton1.setText("Rispondi (non funziona)"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); diff --git a/src/GUI/user/LeggiMessaggi.form b/src/GUI/user/LeggiMessaggi.form index 581e97a..f538da0 100644 --- a/src/GUI/user/LeggiMessaggi.form +++ b/src/GUI/user/LeggiMessaggi.form @@ -1,91 +1,91 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/user/LeggiMessaggi.java b/src/GUI/user/LeggiMessaggi.java index 796993f..fdf3df5 100644 --- a/src/GUI/user/LeggiMessaggi.java +++ b/src/GUI/user/LeggiMessaggi.java @@ -40,7 +40,7 @@ private void initComponents() { jList1 = new javax.swing.JList(); jButton1 = new javax.swing.JButton(); - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setText("Hai tot messaggi da leggere"); diff --git a/src/GUI/user/NuoveProposte.form b/src/GUI/user/NuoveProposte.form index c83e18d..0783192 100644 --- a/src/GUI/user/NuoveProposte.form +++ b/src/GUI/user/NuoveProposte.form @@ -2,7 +2,7 @@
- + @@ -23,6 +23,7 @@ + @@ -31,15 +32,10 @@ - + - - - - - @@ -65,7 +61,7 @@ - + diff --git a/src/GUI/user/NuoveProposte.java b/src/GUI/user/NuoveProposte.java index f367588..742a905 100644 --- a/src/GUI/user/NuoveProposte.java +++ b/src/GUI/user/NuoveProposte.java @@ -43,10 +43,10 @@ private void initComponents() { jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N - jLabel1.setText(" Hai delle nuove proposte"); + jLabel1.setText("Ciao hai delle nuove proposte"); jLabel1.setVerifyInputWhenFocusTarget(false); jList1.setModel(new javax.swing.AbstractListModel() { @@ -74,6 +74,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 624, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1) @@ -81,13 +82,9 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(layout.createSequentialGroup() .addGap(64, 64, 64) .addComponent(jButton1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 314, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton2) .addGap(135, 135, 135)) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) diff --git a/src/GUI/user/NuovoMessaggio.form b/src/GUI/user/NuovoMessaggio.form index 968f3f6..12c6752 100644 --- a/src/GUI/user/NuovoMessaggio.form +++ b/src/GUI/user/NuovoMessaggio.form @@ -2,7 +2,7 @@ - + @@ -26,7 +26,7 @@ - + @@ -46,18 +46,17 @@ + + + + + + - - - - - - - @@ -83,14 +82,16 @@ - - - - - - + + + + + + + + - + @@ -148,7 +149,7 @@ - + @@ -166,5 +167,13 @@ + + + + + + + + diff --git a/src/GUI/user/NuovoMessaggio.java b/src/GUI/user/NuovoMessaggio.java index e365418..076f3c4 100644 --- a/src/GUI/user/NuovoMessaggio.java +++ b/src/GUI/user/NuovoMessaggio.java @@ -30,19 +30,29 @@ public class NuovoMessaggio extends javax.swing.JFrame { */ public NuovoMessaggio(Studente s, Messaggio r) { initComponents(); - if (r != null) { + this.studente = s; +// System.out.println("id del messaggio recuperato " + r.getId()); + this.proposte = CommunicationController.getProposteAccettate(this.studente.getId()); + if (r != null) {//se riceve un messaggi in input sta recuperando una bozza this.restore = r; + + System.out.println("Invia messaggio a " + this.restore.getDestinatario()); + jComboBox1.addItem("Invia messaggio a " + this.restore.getDestinatario()); + jComboBox1.setSelectedItem("Invia messaggio a " + this.restore.getDestinatario()); + + jComboBox3.setSelectedItem(this.restore.getLingua()); jComboBox1.disable(); jComboBox3.disable(); jButton2.disable(); jTextField1.setText(this.restore.getTesto()); } else { - this.studente = s; + //this.studente = s; - this.proposte = CommunicationController.getProposteAccettate(this.studente.getId()); + + int[] id_list = new int[proposte.length]; for (int i = 0; i < id_list.length; i++) { - jComboBox1.addItem(proposte[i]); + jComboBox1.addItem("Invia messaggio a " + proposte[i]); } } @@ -66,8 +76,9 @@ private void initComponents() { jLabel3 = new javax.swing.JLabel(); jComboBox3 = new javax.swing.JComboBox(); jButton3 = new javax.swing.JButton(); + jButton4 = new javax.swing.JButton(); - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setText("Scegli il destinatario"); @@ -102,7 +113,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { jLabel3.setText("Seleziona lingua"); - jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Scegli una lingua", "Italiano", "Inglese" })); + jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Non specificata", "Italiano", "Inglese" })); jComboBox3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jComboBox3ActionPerformed(evt); @@ -116,6 +127,13 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { } }); + jButton4.setText("jButton4"); + jButton4.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton4ActionPerformed(evt); + } + }); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( @@ -138,14 +156,14 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGap(0, 129, Short.MAX_VALUE)))) .addGroup(layout.createSequentialGroup() .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(18, 18, 18) + .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(18, 18, 18) + .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGap(57, 57, 57) - .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(46, 46, 46)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -165,13 +183,14 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(layout.createSequentialGroup() .addGap(51, 51, 51) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addGap(27, 27, 27) - .addComponent(jButton2) - .addGap(51, 51, 51) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(116, 116, 116)) + .addGap(25, 25, 25) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) + .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jButton1) + .addComponent(jButton4))) + .addGap(50, 50, 50)) ); pack(); @@ -215,10 +234,9 @@ private void jComboBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI }//GEN-LAST:event_jComboBox3ActionPerformed private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed - // TODO add your handling code here: //il messaggio non viene inviato ma è salvato come bozza, in modo da //essere poi completato in un secondo momento - int languageIndex = jComboBox1.getSelectedIndex(); + int languageIndex = jComboBox1.getSelectedIndex(); //indice del destinatario selezionato nella combobox String testo = jTextField1.getText(); String lingua = (String) jComboBox3.getSelectedItem(); @@ -229,8 +247,10 @@ private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS /* Instanzia il messaggio e cifralo */ Messaggio m = new Messaggio(testo, lingua, mittente, destinatario, sdc); m.setBozza(true); - //m.cifra(); lo vogliamo cifrare anche se è una bozza?? m.save(); + if (restore != null ) + CommunicationController.removeBozza(restore); + System.out.println("Il messaggio è stato salvato correttamente"); }//GEN-LAST:event_jButton3ActionPerformed @@ -238,10 +258,15 @@ private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F // TODO add your handling code here: }//GEN-LAST:event_jTextField1ActionPerformed + private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed + + }//GEN-LAST:event_jButton4ActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; + private javax.swing.JButton jButton4; private javax.swing.JComboBox jComboBox1; private javax.swing.JComboBox jComboBox3; private javax.swing.JLabel jLabel1; diff --git a/src/GUI/user/PropostaSistemaDiCifratura.form b/src/GUI/user/PropostaSistemaDiCifratura.form index 4265d4d..987e5aa 100644 --- a/src/GUI/user/PropostaSistemaDiCifratura.form +++ b/src/GUI/user/PropostaSistemaDiCifratura.form @@ -13,7 +13,7 @@ - + @@ -35,32 +35,43 @@ + - - - - - + + + - + + + + - + - - + + + - + - - + + + + + + + + + + @@ -88,8 +99,12 @@
+ + + + - +
@@ -146,7 +161,7 @@ - + @@ -154,5 +169,12 @@ + + + + + + + diff --git a/src/GUI/user/PropostaSistemaDiCifratura.java b/src/GUI/user/PropostaSistemaDiCifratura.java index d431317..e09928e 100644 --- a/src/GUI/user/PropostaSistemaDiCifratura.java +++ b/src/GUI/user/PropostaSistemaDiCifratura.java @@ -54,10 +54,12 @@ private void initComponents() { jList2 = new javax.swing.JList(); jLabel3 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); + jLabel4 = new javax.swing.JLabel(); + jLabel5 = new javax.swing.JLabel(); jMenu1.setText("jMenu1"); - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setText("A chi vuoi mandare il messaggio?"); @@ -79,7 +81,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { jScrollPane2.setViewportView(jList2); - jLabel3.setText("Chiave"); + jLabel3.setText("Chiave*"); jTextField1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { @@ -87,31 +89,40 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { } }); + jLabel5.setText("*Inserisci una stringa di lettere per la cifratura a parola chiave, un numero per la cifratura pseudocasuale e di cesare"); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() + .addGap(48, 48, 48) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addGap(56, 56, 56) - .addComponent(jLabel1) - .addGap(126, 126, 126) - .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(633, 633, 633) + .addComponent(jLabel4)) .addGroup(layout.createSequentialGroup() - .addGap(48, 48, 48) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2) - .addComponent(jLabel3)) - .addGap(49, 49, 49) + .addComponent(jLabel3) + .addGroup(layout.createSequentialGroup() + .addGap(8, 8, 8) + .addComponent(jLabel1))) + .addGap(45, 45, 45) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) + .addComponent(jComboBox1, 0, 213, Short.MAX_VALUE) .addComponent(jTextField1)))) - .addContainerGap(137, Short.MAX_VALUE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) - .addComponent(jButton2) - .addGap(53, 53, 53)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(jButton2) + .addGap(38, 38, 38)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(jLabel5) + .addGap(27, 27, 27)))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -132,8 +143,12 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(jLabel3) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(23, 23, 23) + .addComponent(jLabel4) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE) + .addComponent(jLabel5) + .addGap(32, 32, 32) .addComponent(jButton2) - .addContainerGap(71, Short.MAX_VALUE)) + .addGap(14, 14, 14)) ); pack(); @@ -174,8 +189,12 @@ private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI }//GEN-LAST:event_jComboBox1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed - - SistemaCifratura sdc = new SistemaCifratura(jTextField1.getText(), (String)jComboBox1.getSelectedItem()); + model.user.CalcolatorePseudocasuale calcolatore = new model.user.CalcolatorePseudocasuale(); + String chiave = jTextField1.getText(); + String metodo = (String)jComboBox1.getSelectedItem(); + if (metodo.equalsIgnoreCase("pseudocasuale")) //se il metodo scelto è pseudo casuale + chiave = calcolatore.calcolaParolaChiave(chiave); //genero una parola chiave del numero di caratteri in input nella textbox + SistemaCifratura sdc = new SistemaCifratura(chiave, metodo); UserInfo creatore = new UserInfo( this.studente.getId(), this.studente.getLogin() ); sdc.setCreatore( creatore ); @@ -198,6 +217,8 @@ private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JLabel jLabel5; private javax.swing.JList jList2; private javax.swing.JMenu jMenu1; private javax.swing.JScrollPane jScrollPane2; diff --git a/src/GUI/user/Registrazione.form b/src/GUI/user/Registrazione.form index c8b2232..57c410d 100644 --- a/src/GUI/user/Registrazione.form +++ b/src/GUI/user/Registrazione.form @@ -1,125 +1,125 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/user/Registrazione.java b/src/GUI/user/Registrazione.java index 20c3ba3..9892c2b 100644 --- a/src/GUI/user/Registrazione.java +++ b/src/GUI/user/Registrazione.java @@ -39,7 +39,7 @@ private void initComponents() { jTextField3 = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setText("Username"); diff --git a/src/GUI/user/Utente_Regolamentare.form b/src/GUI/user/Utente_Regolamentare.form index 9a336a3..6c587a2 100644 --- a/src/GUI/user/Utente_Regolamentare.form +++ b/src/GUI/user/Utente_Regolamentare.form @@ -1,77 +1,77 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/user/Utente_Regolamentare.java b/src/GUI/user/Utente_Regolamentare.java index 710e435..c1319ce 100644 --- a/src/GUI/user/Utente_Regolamentare.java +++ b/src/GUI/user/Utente_Regolamentare.java @@ -53,7 +53,7 @@ private void initComponents() { jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jButton1.setText("Invia Nuovo Messaggio"); jButton1.addActionListener(new java.awt.event.ActionListener() { diff --git a/src/controller/CommunicationController.java b/src/controller/CommunicationController.java index 6d67019..93675c8 100644 --- a/src/controller/CommunicationController.java +++ b/src/controller/CommunicationController.java @@ -53,17 +53,6 @@ public static Proposta[] getProposte(String id_user) { //proposte pendenti } public static PropostaConfermata[] getProposteAccettate(String id_user){ //proposte pendenti - /*DbManager db = connect(); - PropostaConfermata[] p; - Vector v = db.eseguiQuery("SELECT * FROM `cryptohelper`.`proposta` WHERE id_mittente = " + id_user + " && stato = 'accettata'"); - if(v.size()<= 0) return new PropostaConfermata[0]; - else{ - p = new PropostaConfermata[v.size()]; - for(int i = 0; i < v.size(); i++){ - p[i] = new PropostaConfermata(Integer.parseInt(((String[])v.elementAt(i))[0]), new UserInfo(((String[])v.elementAt(i))[1]), new UserInfo(((String[])v.elementAt(i))[2]), SistemaCifratura.load(((String[])v.elementAt(i))[3])); - } - return p; - }*/ ArrayList result = new ArrayList<>(); try { @@ -110,5 +99,8 @@ public static boolean send(Messaggio m){ public Messaggio apriMessaggioRicevuto(int id){ return null; } + public static boolean removeBozza(Messaggio m){ + return m.elimina(); + } } diff --git a/src/db/DbManager.java b/src/db/DbManager.java index e8c7349..a7091a4 100644 --- a/src/db/DbManager.java +++ b/src/db/DbManager.java @@ -1,77 +1,77 @@ -/* - * 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 db; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; - -/** - * - * @author BobCaSUaL - */ -public class DbManager { - - /********** static part *********/ - private static DbManager instance = null; - - public static synchronized DbManager getInstance() throws SQLException { - if( null == instance ) { - instance = new DbManager(); - } - return instance; - } - - - /******* object definition *******/ - - private String schema = "cryptohelper"; // Nome del Database a cui connettersi - private String uname = "root"; // Nome utente utilizzato per la connessione al Database - private String passw = ""; // Password usata per la connessione al Database - - private Connection engine; // La connessione col Database - - - /******* internal classes *******/ - - public class QueryImpl extends QueryAbstract { - String sql; - public QueryImpl( String sql ) throws SQLException { - super( engine.prepareStatement(sql), sql ); - } - } - public class QueryResultImpl extends QueryResultAbstract { - - public QueryResultImpl(Query q) throws SQLException { - super(q.executeQuery(), q); - } - } - - /*public class QueryResultImpl2 extends QueryResultAbstract { - - public QueryResultImpl2(Query q) throws SQLException { - super(q.executeUpdate(), q); - } - }*/ - - private DbManager() throws SQLException { - DriverManager.registerDriver( new com.mysql.jdbc.Driver() ); - engine = DriverManager.getConnection("jdbc:mysql://localhost/" + schema, uname, passw); - } - - public Query createQuery( String sql ) throws SQLException { - return new QueryImpl( sql ); - } - public QueryResult execute( Query q ) throws SQLException { - return new QueryResultImpl( q ); - } - - public void executeUpdate( Query q ) throws SQLException { - q.executeUpdate(); - } - -} +/* + * 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 db; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +/** + * + * @author BobCaSUaL + */ +public class DbManager { + + /********** static part *********/ + private static DbManager instance = null; + + public static synchronized DbManager getInstance() throws SQLException { + if( null == instance ) { + instance = new DbManager(); + } + return instance; + } + + + /******* object definition *******/ + + private String schema = "cryptohelper"; // Nome del Database a cui connettersi + private String uname = "root"; // Nome utente utilizzato per la connessione al Database + private String passw = ""; // Password usata per la connessione al Database + + private Connection engine; // La connessione col Database + + + /******* internal classes *******/ + + public class QueryImpl extends QueryAbstract { + String sql; + public QueryImpl( String sql ) throws SQLException { + super( engine.prepareStatement(sql), sql ); + } + } + public class QueryResultImpl extends QueryResultAbstract { + + public QueryResultImpl(Query q) throws SQLException { + super(q.executeQuery(), q); + } + } + + /*public class QueryResultImpl2 extends QueryResultAbstract { + + public QueryResultImpl2(Query q) throws SQLException { + super(q.executeUpdate(), q); + } + }*/ + + private DbManager() throws SQLException { + DriverManager.registerDriver( new com.mysql.jdbc.Driver() ); + engine = DriverManager.getConnection("jdbc:mysql://localhost/" + schema, uname, passw); + } + + public Query createQuery( String sql ) throws SQLException { + return new QueryImpl( sql ); + } + public QueryResult execute( Query q ) throws SQLException { + return new QueryResultImpl( q ); + } + + public void executeUpdate( Query q ) throws SQLException { + q.executeUpdate(); + } + +} diff --git a/src/db/PreparedStatementWrapper.java b/src/db/PreparedStatementWrapper.java index dae1c6b..3ae4c83 100644 --- a/src/db/PreparedStatementWrapper.java +++ b/src/db/PreparedStatementWrapper.java @@ -1,448 +1,448 @@ -/* - * 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 db; - -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.net.URL; -import java.sql.Array; -import java.sql.Blob; -import java.sql.Clob; -import java.sql.Connection; -import java.sql.Date; -import java.sql.NClob; -import java.sql.ParameterMetaData; -import java.sql.PreparedStatement; -import java.sql.Ref; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.RowId; -import java.sql.SQLException; -import java.sql.SQLWarning; -import java.sql.SQLXML; -import java.sql.Time; -import java.sql.Timestamp; -import java.util.Calendar; - - -public class PreparedStatementWrapper implements PreparedStatement { - private PreparedStatement wrapped; - - public PreparedStatementWrapper( PreparedStatement stmt ) { - this.wrapped = stmt; - } -// - public void addBatch() throws SQLException { - wrapped.addBatch(); - } - - public void addBatch(String arg0) throws SQLException { - wrapped.addBatch(arg0); - } - - public void cancel() throws SQLException { - wrapped.cancel(); - } - - public void clearBatch() throws SQLException { - wrapped.clearBatch(); - } - - public void clearParameters() throws SQLException { - wrapped.clearParameters(); - } - - public void clearWarnings() throws SQLException { - wrapped.clearWarnings(); - } - - public void close() throws SQLException { - wrapped.close(); - } - - public void closeOnCompletion() throws SQLException { - wrapped.closeOnCompletion(); - } - - public boolean execute() throws SQLException { - return wrapped.execute(); - } - - public boolean execute(String arg0, int arg1) throws SQLException { - return wrapped.execute(arg0, arg1); - } - - public boolean execute(String arg0, int[] arg1) throws SQLException { - return wrapped.execute(arg0, arg1); - } - - public boolean execute(String arg0, String[] arg1) throws SQLException { - return wrapped.execute(arg0, arg1); - } - - public boolean execute(String arg0) throws SQLException { - return wrapped.execute(arg0); - } - - public int[] executeBatch() throws SQLException { - return wrapped.executeBatch(); - } - - public ResultSet executeQuery() throws SQLException { - return wrapped.executeQuery(); - } - - public ResultSet executeQuery(String arg0) throws SQLException { - return wrapped.executeQuery(arg0); - } - - public int executeUpdate() throws SQLException { - return wrapped.executeUpdate(); - } - - public int executeUpdate(String arg0, int arg1) throws SQLException { - return wrapped.executeUpdate(arg0, arg1); - } - - public int executeUpdate(String arg0, int[] arg1) throws SQLException { - return wrapped.executeUpdate(arg0, arg1); - } - - public int executeUpdate(String arg0, String[] arg1) throws SQLException { - return wrapped.executeUpdate(arg0, arg1); - } - - public int executeUpdate(String arg0) throws SQLException { - return wrapped.executeUpdate(arg0); - } - - public Connection getConnection() throws SQLException { - return wrapped.getConnection(); - } - - public int getFetchDirection() throws SQLException { - return wrapped.getFetchDirection(); - } - - public int getFetchSize() throws SQLException { - return wrapped.getFetchSize(); - } - - public ResultSet getGeneratedKeys() throws SQLException { - return wrapped.getGeneratedKeys(); - } - - public int getMaxFieldSize() throws SQLException { - return wrapped.getMaxFieldSize(); - } - - public int getMaxRows() throws SQLException { - return wrapped.getMaxRows(); - } - - public ResultSetMetaData getMetaData() throws SQLException { - return wrapped.getMetaData(); - } - - public boolean getMoreResults() throws SQLException { - return wrapped.getMoreResults(); - } - - public boolean getMoreResults(int arg0) throws SQLException { - return wrapped.getMoreResults(arg0); - } - - public ParameterMetaData getParameterMetaData() throws SQLException { - return wrapped.getParameterMetaData(); - } - - public int getQueryTimeout() throws SQLException { - return wrapped.getQueryTimeout(); - } - - public ResultSet getResultSet() throws SQLException { - return wrapped.getResultSet(); - } - - public int getResultSetConcurrency() throws SQLException { - return wrapped.getResultSetConcurrency(); - } - - public int getResultSetHoldability() throws SQLException { - return wrapped.getResultSetHoldability(); - } - - public int getResultSetType() throws SQLException { - return wrapped.getResultSetType(); - } - - public int getUpdateCount() throws SQLException { - return wrapped.getUpdateCount(); - } - - public SQLWarning getWarnings() throws SQLException { - return wrapped.getWarnings(); - } - - public boolean isCloseOnCompletion() throws SQLException { - return wrapped.isCloseOnCompletion(); - } - - public boolean isClosed() throws SQLException { - return wrapped.isClosed(); - } - - public boolean isPoolable() throws SQLException { - return wrapped.isPoolable(); - } - - public boolean isWrapperFor(Class iface) throws SQLException { - return wrapped.isWrapperFor(iface); - } - - public void setArray(int arg0, Array arg1) throws SQLException { - wrapped.setArray(arg0, arg1); - } - - public void setAsciiStream(int arg0, InputStream arg1, int arg2) - throws SQLException { - wrapped.setAsciiStream(arg0, arg1, arg2); - } - - public void setAsciiStream(int arg0, InputStream arg1, long arg2) - throws SQLException { - wrapped.setAsciiStream(arg0, arg1, arg2); - } - - public void setAsciiStream(int arg0, InputStream arg1) throws SQLException { - wrapped.setAsciiStream(arg0, arg1); - } - - public void setBigDecimal(int arg0, BigDecimal arg1) throws SQLException { - wrapped.setBigDecimal(arg0, arg1); - } - - public void setBinaryStream(int arg0, InputStream arg1, int arg2) - throws SQLException { - wrapped.setBinaryStream(arg0, arg1, arg2); - } - - public void setBinaryStream(int arg0, InputStream arg1, long arg2) - throws SQLException { - wrapped.setBinaryStream(arg0, arg1, arg2); - } - - public void setBinaryStream(int arg0, InputStream arg1) throws SQLException { - wrapped.setBinaryStream(arg0, arg1); - } - - public void setBlob(int arg0, Blob arg1) throws SQLException { - wrapped.setBlob(arg0, arg1); - } - - public void setBlob(int arg0, InputStream arg1, long arg2) - throws SQLException { - wrapped.setBlob(arg0, arg1, arg2); - } - - public void setBlob(int arg0, InputStream arg1) throws SQLException { - wrapped.setBlob(arg0, arg1); - } - - public void setBoolean(int arg0, boolean arg1) throws SQLException { - wrapped.setBoolean(arg0, arg1); - } - - public void setByte(int arg0, byte arg1) throws SQLException { - wrapped.setByte(arg0, arg1); - } - - public void setBytes(int arg0, byte[] arg1) throws SQLException { - wrapped.setBytes(arg0, arg1); - } - - public void setCharacterStream(int arg0, Reader arg1, int arg2) - throws SQLException { - wrapped.setCharacterStream(arg0, arg1, arg2); - } - - public void setCharacterStream(int arg0, Reader arg1, long arg2) - throws SQLException { - wrapped.setCharacterStream(arg0, arg1, arg2); - } - - public void setCharacterStream(int arg0, Reader arg1) throws SQLException { - wrapped.setCharacterStream(arg0, arg1); - } - - public void setClob(int arg0, Clob arg1) throws SQLException { - wrapped.setClob(arg0, arg1); - } - - public void setClob(int arg0, Reader arg1, long arg2) throws SQLException { - wrapped.setClob(arg0, arg1, arg2); - } - - public void setClob(int arg0, Reader arg1) throws SQLException { - wrapped.setClob(arg0, arg1); - } - - public void setCursorName(String arg0) throws SQLException { - wrapped.setCursorName(arg0); - } - - public void setDate(int arg0, Date arg1, Calendar arg2) throws SQLException { - wrapped.setDate(arg0, arg1, arg2); - } - - public void setDate(int arg0, Date arg1) throws SQLException { - wrapped.setDate(arg0, arg1); - } - - public void setDouble(int arg0, double arg1) throws SQLException { - wrapped.setDouble(arg0, arg1); - } - - public void setEscapeProcessing(boolean arg0) throws SQLException { - wrapped.setEscapeProcessing(arg0); - } - - public void setFetchDirection(int arg0) throws SQLException { - wrapped.setFetchDirection(arg0); - } - - public void setFetchSize(int arg0) throws SQLException { - wrapped.setFetchSize(arg0); - } - - public void setFloat(int arg0, float arg1) throws SQLException { - wrapped.setFloat(arg0, arg1); - } - - public void setInt(int arg0, int arg1) throws SQLException { - wrapped.setInt(arg0, arg1); - } - - public void setLong(int arg0, long arg1) throws SQLException { - wrapped.setLong(arg0, arg1); - } - - public void setMaxFieldSize(int arg0) throws SQLException { - wrapped.setMaxFieldSize(arg0); - } - - public void setMaxRows(int arg0) throws SQLException { - wrapped.setMaxRows(arg0); - } - - public void setNCharacterStream(int arg0, Reader arg1, long arg2) - throws SQLException { - wrapped.setNCharacterStream(arg0, arg1, arg2); - } - - public void setNCharacterStream(int arg0, Reader arg1) throws SQLException { - wrapped.setNCharacterStream(arg0, arg1); - } - - public void setNClob(int arg0, NClob arg1) throws SQLException { - wrapped.setNClob(arg0, arg1); - } - - public void setNClob(int arg0, Reader arg1, long arg2) throws SQLException { - wrapped.setNClob(arg0, arg1, arg2); - } - - public void setNClob(int arg0, Reader arg1) throws SQLException { - wrapped.setNClob(arg0, arg1); - } - - public void setNString(int arg0, String arg1) throws SQLException { - wrapped.setNString(arg0, arg1); - } - - public void setNull(int arg0, int arg1, String arg2) throws SQLException { - wrapped.setNull(arg0, arg1, arg2); - } - - public void setNull(int arg0, int arg1) throws SQLException { - wrapped.setNull(arg0, arg1); - } - - public void setObject(int arg0, Object arg1, int arg2, int arg3) - throws SQLException { - wrapped.setObject(arg0, arg1, arg2, arg3); - } - - public void setObject(int arg0, Object arg1, int arg2) throws SQLException { - wrapped.setObject(arg0, arg1, arg2); - } - - public void setObject(int arg0, Object arg1) throws SQLException { - wrapped.setObject(arg0, arg1); - } - - public void setPoolable(boolean arg0) throws SQLException { - wrapped.setPoolable(arg0); - } - - public void setQueryTimeout(int arg0) throws SQLException { - wrapped.setQueryTimeout(arg0); - } - - public void setRef(int arg0, Ref arg1) throws SQLException { - wrapped.setRef(arg0, arg1); - } - - public void setRowId(int arg0, RowId arg1) throws SQLException { - wrapped.setRowId(arg0, arg1); - } - - public void setSQLXML(int arg0, SQLXML arg1) throws SQLException { - wrapped.setSQLXML(arg0, arg1); - } - - public void setShort(int arg0, short arg1) throws SQLException { - wrapped.setShort(arg0, arg1); - } - - public void setString(int arg0, String arg1) throws SQLException { - wrapped.setString(arg0, arg1); - } - - public void setTime(int arg0, Time arg1, Calendar arg2) throws SQLException { - wrapped.setTime(arg0, arg1, arg2); - } - - public void setTime(int arg0, Time arg1) throws SQLException { - wrapped.setTime(arg0, arg1); - } - - public void setTimestamp(int arg0, Timestamp arg1, Calendar arg2) - throws SQLException { - wrapped.setTimestamp(arg0, arg1, arg2); - } - - public void setTimestamp(int arg0, Timestamp arg1) throws SQLException { - wrapped.setTimestamp(arg0, arg1); - } - - public void setURL(int arg0, URL arg1) throws SQLException { - wrapped.setURL(arg0, arg1); - } - - public void setUnicodeStream(int arg0, InputStream arg1, int arg2) - throws SQLException { - wrapped.setUnicodeStream(arg0, arg1, arg2); - } - - public T unwrap(Class iface) throws SQLException { - return wrapped.unwrap(iface); - } - -// -} +/* + * 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 db; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.Array; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Connection; +import java.sql.Date; +import java.sql.NClob; +import java.sql.ParameterMetaData; +import java.sql.PreparedStatement; +import java.sql.Ref; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLWarning; +import java.sql.SQLXML; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.Calendar; + + +public class PreparedStatementWrapper implements PreparedStatement { + private PreparedStatement wrapped; + + public PreparedStatementWrapper( PreparedStatement stmt ) { + this.wrapped = stmt; + } +// + public void addBatch() throws SQLException { + wrapped.addBatch(); + } + + public void addBatch(String arg0) throws SQLException { + wrapped.addBatch(arg0); + } + + public void cancel() throws SQLException { + wrapped.cancel(); + } + + public void clearBatch() throws SQLException { + wrapped.clearBatch(); + } + + public void clearParameters() throws SQLException { + wrapped.clearParameters(); + } + + public void clearWarnings() throws SQLException { + wrapped.clearWarnings(); + } + + public void close() throws SQLException { + wrapped.close(); + } + + public void closeOnCompletion() throws SQLException { + wrapped.closeOnCompletion(); + } + + public boolean execute() throws SQLException { + return wrapped.execute(); + } + + public boolean execute(String arg0, int arg1) throws SQLException { + return wrapped.execute(arg0, arg1); + } + + public boolean execute(String arg0, int[] arg1) throws SQLException { + return wrapped.execute(arg0, arg1); + } + + public boolean execute(String arg0, String[] arg1) throws SQLException { + return wrapped.execute(arg0, arg1); + } + + public boolean execute(String arg0) throws SQLException { + return wrapped.execute(arg0); + } + + public int[] executeBatch() throws SQLException { + return wrapped.executeBatch(); + } + + public ResultSet executeQuery() throws SQLException { + return wrapped.executeQuery(); + } + + public ResultSet executeQuery(String arg0) throws SQLException { + return wrapped.executeQuery(arg0); + } + + public int executeUpdate() throws SQLException { + return wrapped.executeUpdate(); + } + + public int executeUpdate(String arg0, int arg1) throws SQLException { + return wrapped.executeUpdate(arg0, arg1); + } + + public int executeUpdate(String arg0, int[] arg1) throws SQLException { + return wrapped.executeUpdate(arg0, arg1); + } + + public int executeUpdate(String arg0, String[] arg1) throws SQLException { + return wrapped.executeUpdate(arg0, arg1); + } + + public int executeUpdate(String arg0) throws SQLException { + return wrapped.executeUpdate(arg0); + } + + public Connection getConnection() throws SQLException { + return wrapped.getConnection(); + } + + public int getFetchDirection() throws SQLException { + return wrapped.getFetchDirection(); + } + + public int getFetchSize() throws SQLException { + return wrapped.getFetchSize(); + } + + public ResultSet getGeneratedKeys() throws SQLException { + return wrapped.getGeneratedKeys(); + } + + public int getMaxFieldSize() throws SQLException { + return wrapped.getMaxFieldSize(); + } + + public int getMaxRows() throws SQLException { + return wrapped.getMaxRows(); + } + + public ResultSetMetaData getMetaData() throws SQLException { + return wrapped.getMetaData(); + } + + public boolean getMoreResults() throws SQLException { + return wrapped.getMoreResults(); + } + + public boolean getMoreResults(int arg0) throws SQLException { + return wrapped.getMoreResults(arg0); + } + + public ParameterMetaData getParameterMetaData() throws SQLException { + return wrapped.getParameterMetaData(); + } + + public int getQueryTimeout() throws SQLException { + return wrapped.getQueryTimeout(); + } + + public ResultSet getResultSet() throws SQLException { + return wrapped.getResultSet(); + } + + public int getResultSetConcurrency() throws SQLException { + return wrapped.getResultSetConcurrency(); + } + + public int getResultSetHoldability() throws SQLException { + return wrapped.getResultSetHoldability(); + } + + public int getResultSetType() throws SQLException { + return wrapped.getResultSetType(); + } + + public int getUpdateCount() throws SQLException { + return wrapped.getUpdateCount(); + } + + public SQLWarning getWarnings() throws SQLException { + return wrapped.getWarnings(); + } + + public boolean isCloseOnCompletion() throws SQLException { + return wrapped.isCloseOnCompletion(); + } + + public boolean isClosed() throws SQLException { + return wrapped.isClosed(); + } + + public boolean isPoolable() throws SQLException { + return wrapped.isPoolable(); + } + + public boolean isWrapperFor(Class iface) throws SQLException { + return wrapped.isWrapperFor(iface); + } + + public void setArray(int arg0, Array arg1) throws SQLException { + wrapped.setArray(arg0, arg1); + } + + public void setAsciiStream(int arg0, InputStream arg1, int arg2) + throws SQLException { + wrapped.setAsciiStream(arg0, arg1, arg2); + } + + public void setAsciiStream(int arg0, InputStream arg1, long arg2) + throws SQLException { + wrapped.setAsciiStream(arg0, arg1, arg2); + } + + public void setAsciiStream(int arg0, InputStream arg1) throws SQLException { + wrapped.setAsciiStream(arg0, arg1); + } + + public void setBigDecimal(int arg0, BigDecimal arg1) throws SQLException { + wrapped.setBigDecimal(arg0, arg1); + } + + public void setBinaryStream(int arg0, InputStream arg1, int arg2) + throws SQLException { + wrapped.setBinaryStream(arg0, arg1, arg2); + } + + public void setBinaryStream(int arg0, InputStream arg1, long arg2) + throws SQLException { + wrapped.setBinaryStream(arg0, arg1, arg2); + } + + public void setBinaryStream(int arg0, InputStream arg1) throws SQLException { + wrapped.setBinaryStream(arg0, arg1); + } + + public void setBlob(int arg0, Blob arg1) throws SQLException { + wrapped.setBlob(arg0, arg1); + } + + public void setBlob(int arg0, InputStream arg1, long arg2) + throws SQLException { + wrapped.setBlob(arg0, arg1, arg2); + } + + public void setBlob(int arg0, InputStream arg1) throws SQLException { + wrapped.setBlob(arg0, arg1); + } + + public void setBoolean(int arg0, boolean arg1) throws SQLException { + wrapped.setBoolean(arg0, arg1); + } + + public void setByte(int arg0, byte arg1) throws SQLException { + wrapped.setByte(arg0, arg1); + } + + public void setBytes(int arg0, byte[] arg1) throws SQLException { + wrapped.setBytes(arg0, arg1); + } + + public void setCharacterStream(int arg0, Reader arg1, int arg2) + throws SQLException { + wrapped.setCharacterStream(arg0, arg1, arg2); + } + + public void setCharacterStream(int arg0, Reader arg1, long arg2) + throws SQLException { + wrapped.setCharacterStream(arg0, arg1, arg2); + } + + public void setCharacterStream(int arg0, Reader arg1) throws SQLException { + wrapped.setCharacterStream(arg0, arg1); + } + + public void setClob(int arg0, Clob arg1) throws SQLException { + wrapped.setClob(arg0, arg1); + } + + public void setClob(int arg0, Reader arg1, long arg2) throws SQLException { + wrapped.setClob(arg0, arg1, arg2); + } + + public void setClob(int arg0, Reader arg1) throws SQLException { + wrapped.setClob(arg0, arg1); + } + + public void setCursorName(String arg0) throws SQLException { + wrapped.setCursorName(arg0); + } + + public void setDate(int arg0, Date arg1, Calendar arg2) throws SQLException { + wrapped.setDate(arg0, arg1, arg2); + } + + public void setDate(int arg0, Date arg1) throws SQLException { + wrapped.setDate(arg0, arg1); + } + + public void setDouble(int arg0, double arg1) throws SQLException { + wrapped.setDouble(arg0, arg1); + } + + public void setEscapeProcessing(boolean arg0) throws SQLException { + wrapped.setEscapeProcessing(arg0); + } + + public void setFetchDirection(int arg0) throws SQLException { + wrapped.setFetchDirection(arg0); + } + + public void setFetchSize(int arg0) throws SQLException { + wrapped.setFetchSize(arg0); + } + + public void setFloat(int arg0, float arg1) throws SQLException { + wrapped.setFloat(arg0, arg1); + } + + public void setInt(int arg0, int arg1) throws SQLException { + wrapped.setInt(arg0, arg1); + } + + public void setLong(int arg0, long arg1) throws SQLException { + wrapped.setLong(arg0, arg1); + } + + public void setMaxFieldSize(int arg0) throws SQLException { + wrapped.setMaxFieldSize(arg0); + } + + public void setMaxRows(int arg0) throws SQLException { + wrapped.setMaxRows(arg0); + } + + public void setNCharacterStream(int arg0, Reader arg1, long arg2) + throws SQLException { + wrapped.setNCharacterStream(arg0, arg1, arg2); + } + + public void setNCharacterStream(int arg0, Reader arg1) throws SQLException { + wrapped.setNCharacterStream(arg0, arg1); + } + + public void setNClob(int arg0, NClob arg1) throws SQLException { + wrapped.setNClob(arg0, arg1); + } + + public void setNClob(int arg0, Reader arg1, long arg2) throws SQLException { + wrapped.setNClob(arg0, arg1, arg2); + } + + public void setNClob(int arg0, Reader arg1) throws SQLException { + wrapped.setNClob(arg0, arg1); + } + + public void setNString(int arg0, String arg1) throws SQLException { + wrapped.setNString(arg0, arg1); + } + + public void setNull(int arg0, int arg1, String arg2) throws SQLException { + wrapped.setNull(arg0, arg1, arg2); + } + + public void setNull(int arg0, int arg1) throws SQLException { + wrapped.setNull(arg0, arg1); + } + + public void setObject(int arg0, Object arg1, int arg2, int arg3) + throws SQLException { + wrapped.setObject(arg0, arg1, arg2, arg3); + } + + public void setObject(int arg0, Object arg1, int arg2) throws SQLException { + wrapped.setObject(arg0, arg1, arg2); + } + + public void setObject(int arg0, Object arg1) throws SQLException { + wrapped.setObject(arg0, arg1); + } + + public void setPoolable(boolean arg0) throws SQLException { + wrapped.setPoolable(arg0); + } + + public void setQueryTimeout(int arg0) throws SQLException { + wrapped.setQueryTimeout(arg0); + } + + public void setRef(int arg0, Ref arg1) throws SQLException { + wrapped.setRef(arg0, arg1); + } + + public void setRowId(int arg0, RowId arg1) throws SQLException { + wrapped.setRowId(arg0, arg1); + } + + public void setSQLXML(int arg0, SQLXML arg1) throws SQLException { + wrapped.setSQLXML(arg0, arg1); + } + + public void setShort(int arg0, short arg1) throws SQLException { + wrapped.setShort(arg0, arg1); + } + + public void setString(int arg0, String arg1) throws SQLException { + wrapped.setString(arg0, arg1); + } + + public void setTime(int arg0, Time arg1, Calendar arg2) throws SQLException { + wrapped.setTime(arg0, arg1, arg2); + } + + public void setTime(int arg0, Time arg1) throws SQLException { + wrapped.setTime(arg0, arg1); + } + + public void setTimestamp(int arg0, Timestamp arg1, Calendar arg2) + throws SQLException { + wrapped.setTimestamp(arg0, arg1, arg2); + } + + public void setTimestamp(int arg0, Timestamp arg1) throws SQLException { + wrapped.setTimestamp(arg0, arg1); + } + + public void setURL(int arg0, URL arg1) throws SQLException { + wrapped.setURL(arg0, arg1); + } + + public void setUnicodeStream(int arg0, InputStream arg1, int arg2) + throws SQLException { + wrapped.setUnicodeStream(arg0, arg1, arg2); + } + + public T unwrap(Class iface) throws SQLException { + return wrapped.unwrap(iface); + } + +// +} diff --git a/src/db/Query.java b/src/db/Query.java index 1b9f02c..aad6220 100644 --- a/src/db/Query.java +++ b/src/db/Query.java @@ -1,17 +1,17 @@ -/* - * 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 db; - -import java.sql.PreparedStatement; - -/** - * - * @author BobCaSUaL - */ -public interface Query extends PreparedStatement { - public String getSqlCode(); -} +/* + * 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 db; + +import java.sql.PreparedStatement; + +/** + * + * @author BobCaSUaL + */ +public interface Query extends PreparedStatement { + public String getSqlCode(); +} diff --git a/src/db/QueryAbstract.java b/src/db/QueryAbstract.java index b177594..280fe68 100644 --- a/src/db/QueryAbstract.java +++ b/src/db/QueryAbstract.java @@ -1,26 +1,26 @@ -/* - * 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 db; - -import java.sql.PreparedStatement; - -/** - * - * @author BobCaSUaL - */ -public abstract class QueryAbstract extends PreparedStatementWrapper implements Query { - private String sql; - - public QueryAbstract( PreparedStatement stmt, String sql ) { - super(stmt); - this.sql = sql; - } - - public String getSqlCode() { - return this.sql; - } -} +/* + * 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 db; + +import java.sql.PreparedStatement; + +/** + * + * @author BobCaSUaL + */ +public abstract class QueryAbstract extends PreparedStatementWrapper implements Query { + private String sql; + + public QueryAbstract( PreparedStatement stmt, String sql ) { + super(stmt); + this.sql = sql; + } + + public String getSqlCode() { + return this.sql; + } +} diff --git a/src/db/QueryResult.java b/src/db/QueryResult.java index 78766bf..c145dfd 100644 --- a/src/db/QueryResult.java +++ b/src/db/QueryResult.java @@ -1,17 +1,17 @@ -/* - * 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 db; - -import java.sql.ResultSet; - -/** - * - * @author BobCaSUaL - */ -public interface QueryResult extends ResultSet { - public Query getQuery(); -} +/* + * 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 db; + +import java.sql.ResultSet; + +/** + * + * @author BobCaSUaL + */ +public interface QueryResult extends ResultSet { + public Query getQuery(); +} diff --git a/src/db/QueryResultAbstract.java b/src/db/QueryResultAbstract.java index ade1bd3..15de7d6 100644 --- a/src/db/QueryResultAbstract.java +++ b/src/db/QueryResultAbstract.java @@ -1,28 +1,28 @@ -/* - * 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 db; - -import java.sql.ResultSet; - -/** - * - * @author BobCaSUaL - */ -public abstract class QueryResultAbstract extends ResultSetWrapper implements QueryResult { - private Query query; - - public QueryResultAbstract( ResultSet rs, Query q ) { - super( rs ); - this.query = q; - } - /** - * @return the query - */ - public Query getQuery() { - return query; - } -} +/* + * 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 db; + +import java.sql.ResultSet; + +/** + * + * @author BobCaSUaL + */ +public abstract class QueryResultAbstract extends ResultSetWrapper implements QueryResult { + private Query query; + + public QueryResultAbstract( ResultSet rs, Query q ) { + super( rs ); + this.query = q; + } + /** + * @return the query + */ + public Query getQuery() { + return query; + } +} diff --git a/src/db/ResultSetWrapper.java b/src/db/ResultSetWrapper.java index 567c1e7..43ba77a 100644 --- a/src/db/ResultSetWrapper.java +++ b/src/db/ResultSetWrapper.java @@ -1,858 +1,858 @@ -/* - * 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 db; - -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.net.URL; -import java.sql.Array; -import java.sql.Blob; -import java.sql.Clob; -import java.sql.Date; -import java.sql.NClob; -import java.sql.Ref; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.RowId; -import java.sql.SQLException; -import java.sql.SQLWarning; -import java.sql.SQLXML; -import java.sql.Statement; -import java.sql.Time; -import java.sql.Timestamp; -import java.util.Calendar; -import java.util.Map; - -/** - * - * @author BobCaSUaL - */ -public abstract class ResultSetWrapper implements ResultSet { - private ResultSet wrapped; - - public ResultSetWrapper( ResultSet rs ) { - this.wrapped = rs; - } -// - - public boolean absolute(int row) throws SQLException { - return wrapped.absolute(row); - } - - public void afterLast() throws SQLException { - wrapped.afterLast(); - } - - public void beforeFirst() throws SQLException { - wrapped.beforeFirst(); - } - - public void cancelRowUpdates() throws SQLException { - wrapped.cancelRowUpdates(); - } - - public void clearWarnings() throws SQLException { - wrapped.clearWarnings(); - } - - public void close() throws SQLException { - wrapped.close(); - } - - public void deleteRow() throws SQLException { - wrapped.deleteRow(); - } - - public int findColumn(String columnLabel) throws SQLException { - return wrapped.findColumn(columnLabel); - } - - public boolean first() throws SQLException { - return wrapped.first(); - } - - public Array getArray(int columnIndex) throws SQLException { - return wrapped.getArray(columnIndex); - } - - public Array getArray(String columnLabel) throws SQLException { - return wrapped.getArray(columnLabel); - } - - public InputStream getAsciiStream(int columnIndex) throws SQLException { - return wrapped.getAsciiStream(columnIndex); - } - - public InputStream getAsciiStream(String columnLabel) throws SQLException { - return wrapped.getAsciiStream(columnLabel); - } - - public BigDecimal getBigDecimal(int columnIndex, int scale) - throws SQLException { - return wrapped.getBigDecimal(columnIndex, scale); - } - - public BigDecimal getBigDecimal(int columnIndex) throws SQLException { - return wrapped.getBigDecimal(columnIndex); - } - - public BigDecimal getBigDecimal(String columnLabel, int scale) - throws SQLException { - return wrapped.getBigDecimal(columnLabel, scale); - } - - public BigDecimal getBigDecimal(String columnLabel) throws SQLException { - return wrapped.getBigDecimal(columnLabel); - } - - public InputStream getBinaryStream(int columnIndex) throws SQLException { - return wrapped.getBinaryStream(columnIndex); - } - - public InputStream getBinaryStream(String columnLabel) throws SQLException { - return wrapped.getBinaryStream(columnLabel); - } - - public Blob getBlob(int columnIndex) throws SQLException { - return wrapped.getBlob(columnIndex); - } - - public Blob getBlob(String columnLabel) throws SQLException { - return wrapped.getBlob(columnLabel); - } - - public boolean getBoolean(int columnIndex) throws SQLException { - return wrapped.getBoolean(columnIndex); - } - - public boolean getBoolean(String columnLabel) throws SQLException { - return wrapped.getBoolean(columnLabel); - } - - public byte getByte(int columnIndex) throws SQLException { - return wrapped.getByte(columnIndex); - } - - public byte getByte(String columnLabel) throws SQLException { - return wrapped.getByte(columnLabel); - } - - public byte[] getBytes(int columnIndex) throws SQLException { - return wrapped.getBytes(columnIndex); - } - - public byte[] getBytes(String columnLabel) throws SQLException { - return wrapped.getBytes(columnLabel); - } - - public Reader getCharacterStream(int columnIndex) throws SQLException { - return wrapped.getCharacterStream(columnIndex); - } - - public Reader getCharacterStream(String columnLabel) throws SQLException { - return wrapped.getCharacterStream(columnLabel); - } - - public Clob getClob(int columnIndex) throws SQLException { - return wrapped.getClob(columnIndex); - } - - public Clob getClob(String columnLabel) throws SQLException { - return wrapped.getClob(columnLabel); - } - - public int getConcurrency() throws SQLException { - return wrapped.getConcurrency(); - } - - public String getCursorName() throws SQLException { - return wrapped.getCursorName(); - } - - public Date getDate(int columnIndex, Calendar cal) throws SQLException { - return wrapped.getDate(columnIndex, cal); - } - - public Date getDate(int columnIndex) throws SQLException { - return wrapped.getDate(columnIndex); - } - - public Date getDate(String columnLabel, Calendar cal) throws SQLException { - return wrapped.getDate(columnLabel, cal); - } - - public Date getDate(String columnLabel) throws SQLException { - return wrapped.getDate(columnLabel); - } - - public double getDouble(int columnIndex) throws SQLException { - return wrapped.getDouble(columnIndex); - } - - public double getDouble(String columnLabel) throws SQLException { - return wrapped.getDouble(columnLabel); - } - - public int getFetchDirection() throws SQLException { - return wrapped.getFetchDirection(); - } - - public int getFetchSize() throws SQLException { - return wrapped.getFetchSize(); - } - - public float getFloat(int columnIndex) throws SQLException { - return wrapped.getFloat(columnIndex); - } - - public float getFloat(String columnLabel) throws SQLException { - return wrapped.getFloat(columnLabel); - } - - public int getHoldability() throws SQLException { - return wrapped.getHoldability(); - } - - public int getInt(int columnIndex) throws SQLException { - return wrapped.getInt(columnIndex); - } - - public int getInt(String columnLabel) throws SQLException { - return wrapped.getInt(columnLabel); - } - - public long getLong(int columnIndex) throws SQLException { - return wrapped.getLong(columnIndex); - } - - public long getLong(String columnLabel) throws SQLException { - return wrapped.getLong(columnLabel); - } - - public ResultSetMetaData getMetaData() throws SQLException { - return wrapped.getMetaData(); - } - - public Reader getNCharacterStream(int columnIndex) throws SQLException { - return wrapped.getNCharacterStream(columnIndex); - } - - public Reader getNCharacterStream(String columnLabel) throws SQLException { - return wrapped.getNCharacterStream(columnLabel); - } - - public NClob getNClob(int columnIndex) throws SQLException { - return wrapped.getNClob(columnIndex); - } - - public NClob getNClob(String columnLabel) throws SQLException { - return wrapped.getNClob(columnLabel); - } - - public String getNString(int columnIndex) throws SQLException { - return wrapped.getNString(columnIndex); - } - - public String getNString(String columnLabel) throws SQLException { - return wrapped.getNString(columnLabel); - } - - public T getObject(int columnIndex, Class type) throws SQLException { - return wrapped.getObject(columnIndex, type); - } - - public Object getObject(int columnIndex, Map> map) - throws SQLException { - return wrapped.getObject(columnIndex, map); - } - - public Object getObject(int columnIndex) throws SQLException { - return wrapped.getObject(columnIndex); - } - - public T getObject(String columnLabel, Class type) - throws SQLException { - return wrapped.getObject(columnLabel, type); - } - - public Object getObject(String columnLabel, Map> map) - throws SQLException { - return wrapped.getObject(columnLabel, map); - } - - public Object getObject(String columnLabel) throws SQLException { - return wrapped.getObject(columnLabel); - } - - public Ref getRef(int columnIndex) throws SQLException { - return wrapped.getRef(columnIndex); - } - - public Ref getRef(String columnLabel) throws SQLException { - return wrapped.getRef(columnLabel); - } - - public int getRow() throws SQLException { - return wrapped.getRow(); - } - - public RowId getRowId(int columnIndex) throws SQLException { - return wrapped.getRowId(columnIndex); - } - - public RowId getRowId(String columnLabel) throws SQLException { - return wrapped.getRowId(columnLabel); - } - - public SQLXML getSQLXML(int columnIndex) throws SQLException { - return wrapped.getSQLXML(columnIndex); - } - - public SQLXML getSQLXML(String columnLabel) throws SQLException { - return wrapped.getSQLXML(columnLabel); - } - - public short getShort(int columnIndex) throws SQLException { - return wrapped.getShort(columnIndex); - } - - public short getShort(String columnLabel) throws SQLException { - return wrapped.getShort(columnLabel); - } - - public Statement getStatement() throws SQLException { - return wrapped.getStatement(); - } - - public String getString(int columnIndex) throws SQLException { - return wrapped.getString(columnIndex); - } - - public String getString(String columnLabel) throws SQLException { - return wrapped.getString(columnLabel); - } - - public Time getTime(int columnIndex, Calendar cal) throws SQLException { - return wrapped.getTime(columnIndex, cal); - } - - public Time getTime(int columnIndex) throws SQLException { - return wrapped.getTime(columnIndex); - } - - public Time getTime(String columnLabel, Calendar cal) throws SQLException { - return wrapped.getTime(columnLabel, cal); - } - - public Time getTime(String columnLabel) throws SQLException { - return wrapped.getTime(columnLabel); - } - - public Timestamp getTimestamp(int columnIndex, Calendar cal) - throws SQLException { - return wrapped.getTimestamp(columnIndex, cal); - } - - public Timestamp getTimestamp(int columnIndex) throws SQLException { - return wrapped.getTimestamp(columnIndex); - } - - public Timestamp getTimestamp(String columnLabel, Calendar cal) - throws SQLException { - return wrapped.getTimestamp(columnLabel, cal); - } - - public Timestamp getTimestamp(String columnLabel) throws SQLException { - return wrapped.getTimestamp(columnLabel); - } - - public int getType() throws SQLException { - return wrapped.getType(); - } - - public URL getURL(int columnIndex) throws SQLException { - return wrapped.getURL(columnIndex); - } - - public URL getURL(String columnLabel) throws SQLException { - return wrapped.getURL(columnLabel); - } - - public InputStream getUnicodeStream(int columnIndex) throws SQLException { - return wrapped.getUnicodeStream(columnIndex); - } - - public InputStream getUnicodeStream(String columnLabel) throws SQLException { - return wrapped.getUnicodeStream(columnLabel); - } - - public SQLWarning getWarnings() throws SQLException { - return wrapped.getWarnings(); - } - - public void insertRow() throws SQLException { - wrapped.insertRow(); - } - - public boolean isAfterLast() throws SQLException { - return wrapped.isAfterLast(); - } - - public boolean isBeforeFirst() throws SQLException { - return wrapped.isBeforeFirst(); - } - - public boolean isClosed() throws SQLException { - return wrapped.isClosed(); - } - - public boolean isFirst() throws SQLException { - return wrapped.isFirst(); - } - - public boolean isLast() throws SQLException { - return wrapped.isLast(); - } - - public boolean isWrapperFor(Class iface) throws SQLException { - return wrapped.isWrapperFor(iface); - } - - public boolean last() throws SQLException { - return wrapped.last(); - } - - public void moveToCurrentRow() throws SQLException { - wrapped.moveToCurrentRow(); - } - - public void moveToInsertRow() throws SQLException { - wrapped.moveToInsertRow(); - } - - public boolean next() throws SQLException { - return wrapped.next(); - } - - public boolean previous() throws SQLException { - return wrapped.previous(); - } - - public void refreshRow() throws SQLException { - wrapped.refreshRow(); - } - - public boolean relative(int rows) throws SQLException { - return wrapped.relative(rows); - } - - public boolean rowDeleted() throws SQLException { - return wrapped.rowDeleted(); - } - - public boolean rowInserted() throws SQLException { - return wrapped.rowInserted(); - } - - public boolean rowUpdated() throws SQLException { - return wrapped.rowUpdated(); - } - - public void setFetchDirection(int direction) throws SQLException { - wrapped.setFetchDirection(direction); - } - - public void setFetchSize(int rows) throws SQLException { - wrapped.setFetchSize(rows); - } - - public T unwrap(Class iface) throws SQLException { - return wrapped.unwrap(iface); - } - - public void updateArray(int columnIndex, Array x) throws SQLException { - wrapped.updateArray(columnIndex, x); - } - - public void updateArray(String columnLabel, Array x) throws SQLException { - wrapped.updateArray(columnLabel, x); - } - - public void updateAsciiStream(int columnIndex, InputStream x, int length) - throws SQLException { - wrapped.updateAsciiStream(columnIndex, x, length); - } - - public void updateAsciiStream(int columnIndex, InputStream x, long length) - throws SQLException { - wrapped.updateAsciiStream(columnIndex, x, length); - } - - public void updateAsciiStream(int columnIndex, InputStream x) - throws SQLException { - wrapped.updateAsciiStream(columnIndex, x); - } - - public void updateAsciiStream(String columnLabel, InputStream x, int length) - throws SQLException { - wrapped.updateAsciiStream(columnLabel, x, length); - } - - public void updateAsciiStream(String columnLabel, InputStream x, long length) - throws SQLException { - wrapped.updateAsciiStream(columnLabel, x, length); - } - - public void updateAsciiStream(String columnLabel, InputStream x) - throws SQLException { - wrapped.updateAsciiStream(columnLabel, x); - } - - public void updateBigDecimal(int columnIndex, BigDecimal x) - throws SQLException { - wrapped.updateBigDecimal(columnIndex, x); - } - - public void updateBigDecimal(String columnLabel, BigDecimal x) - throws SQLException { - wrapped.updateBigDecimal(columnLabel, x); - } - - public void updateBinaryStream(int columnIndex, InputStream x, int length) - throws SQLException { - wrapped.updateBinaryStream(columnIndex, x, length); - } - - public void updateBinaryStream(int columnIndex, InputStream x, long length) - throws SQLException { - wrapped.updateBinaryStream(columnIndex, x, length); - } - - public void updateBinaryStream(int columnIndex, InputStream x) - throws SQLException { - wrapped.updateBinaryStream(columnIndex, x); - } - - public void updateBinaryStream(String columnLabel, InputStream x, int length) - throws SQLException { - wrapped.updateBinaryStream(columnLabel, x, length); - } - - public void updateBinaryStream(String columnLabel, InputStream x, - long length) throws SQLException { - wrapped.updateBinaryStream(columnLabel, x, length); - } - - public void updateBinaryStream(String columnLabel, InputStream x) - throws SQLException { - wrapped.updateBinaryStream(columnLabel, x); - } - - public void updateBlob(int columnIndex, Blob x) throws SQLException { - wrapped.updateBlob(columnIndex, x); - } - - public void updateBlob(int columnIndex, InputStream inputStream, long length) - throws SQLException { - wrapped.updateBlob(columnIndex, inputStream, length); - } - - public void updateBlob(int columnIndex, InputStream inputStream) - throws SQLException { - wrapped.updateBlob(columnIndex, inputStream); - } - - public void updateBlob(String columnLabel, Blob x) throws SQLException { - wrapped.updateBlob(columnLabel, x); - } - - public void updateBlob(String columnLabel, InputStream inputStream, - long length) throws SQLException { - wrapped.updateBlob(columnLabel, inputStream, length); - } - - public void updateBlob(String columnLabel, InputStream inputStream) - throws SQLException { - wrapped.updateBlob(columnLabel, inputStream); - } - - public void updateBoolean(int columnIndex, boolean x) throws SQLException { - wrapped.updateBoolean(columnIndex, x); - } - - public void updateBoolean(String columnLabel, boolean x) - throws SQLException { - wrapped.updateBoolean(columnLabel, x); - } - - public void updateByte(int columnIndex, byte x) throws SQLException { - wrapped.updateByte(columnIndex, x); - } - - public void updateByte(String columnLabel, byte x) throws SQLException { - wrapped.updateByte(columnLabel, x); - } - - public void updateBytes(int columnIndex, byte[] x) throws SQLException { - wrapped.updateBytes(columnIndex, x); - } - - public void updateBytes(String columnLabel, byte[] x) throws SQLException { - wrapped.updateBytes(columnLabel, x); - } - - public void updateCharacterStream(int columnIndex, Reader x, int length) - throws SQLException { - wrapped.updateCharacterStream(columnIndex, x, length); - } - - public void updateCharacterStream(int columnIndex, Reader x, long length) - throws SQLException { - wrapped.updateCharacterStream(columnIndex, x, length); - } - - public void updateCharacterStream(int columnIndex, Reader x) - throws SQLException { - wrapped.updateCharacterStream(columnIndex, x); - } - - public void updateCharacterStream(String columnLabel, Reader reader, - int length) throws SQLException { - wrapped.updateCharacterStream(columnLabel, reader, length); - } - - public void updateCharacterStream(String columnLabel, Reader reader, - long length) throws SQLException { - wrapped.updateCharacterStream(columnLabel, reader, length); - } - - public void updateCharacterStream(String columnLabel, Reader reader) - throws SQLException { - wrapped.updateCharacterStream(columnLabel, reader); - } - - public void updateClob(int columnIndex, Clob x) throws SQLException { - wrapped.updateClob(columnIndex, x); - } - - public void updateClob(int columnIndex, Reader reader, long length) - throws SQLException { - wrapped.updateClob(columnIndex, reader, length); - } - - public void updateClob(int columnIndex, Reader reader) throws SQLException { - wrapped.updateClob(columnIndex, reader); - } - - public void updateClob(String columnLabel, Clob x) throws SQLException { - wrapped.updateClob(columnLabel, x); - } - - public void updateClob(String columnLabel, Reader reader, long length) - throws SQLException { - wrapped.updateClob(columnLabel, reader, length); - } - - public void updateClob(String columnLabel, Reader reader) - throws SQLException { - wrapped.updateClob(columnLabel, reader); - } - - public void updateDate(int columnIndex, Date x) throws SQLException { - wrapped.updateDate(columnIndex, x); - } - - public void updateDate(String columnLabel, Date x) throws SQLException { - wrapped.updateDate(columnLabel, x); - } - - public void updateDouble(int columnIndex, double x) throws SQLException { - wrapped.updateDouble(columnIndex, x); - } - - public void updateDouble(String columnLabel, double x) throws SQLException { - wrapped.updateDouble(columnLabel, x); - } - - public void updateFloat(int columnIndex, float x) throws SQLException { - wrapped.updateFloat(columnIndex, x); - } - - public void updateFloat(String columnLabel, float x) throws SQLException { - wrapped.updateFloat(columnLabel, x); - } - - public void updateInt(int columnIndex, int x) throws SQLException { - wrapped.updateInt(columnIndex, x); - } - - public void updateInt(String columnLabel, int x) throws SQLException { - wrapped.updateInt(columnLabel, x); - } - - public void updateLong(int columnIndex, long x) throws SQLException { - wrapped.updateLong(columnIndex, x); - } - - public void updateLong(String columnLabel, long x) throws SQLException { - wrapped.updateLong(columnLabel, x); - } - - public void updateNCharacterStream(int columnIndex, Reader x, long length) - throws SQLException { - wrapped.updateNCharacterStream(columnIndex, x, length); - } - - public void updateNCharacterStream(int columnIndex, Reader x) - throws SQLException { - wrapped.updateNCharacterStream(columnIndex, x); - } - - public void updateNCharacterStream(String columnLabel, Reader reader, - long length) throws SQLException { - wrapped.updateNCharacterStream(columnLabel, reader, length); - } - - public void updateNCharacterStream(String columnLabel, Reader reader) - throws SQLException { - wrapped.updateNCharacterStream(columnLabel, reader); - } - - public void updateNClob(int columnIndex, NClob nClob) throws SQLException { - wrapped.updateNClob(columnIndex, nClob); - } - - public void updateNClob(int columnIndex, Reader reader, long length) - throws SQLException { - wrapped.updateNClob(columnIndex, reader, length); - } - - public void updateNClob(int columnIndex, Reader reader) throws SQLException { - wrapped.updateNClob(columnIndex, reader); - } - - public void updateNClob(String columnLabel, NClob nClob) - throws SQLException { - wrapped.updateNClob(columnLabel, nClob); - } - - public void updateNClob(String columnLabel, Reader reader, long length) - throws SQLException { - wrapped.updateNClob(columnLabel, reader, length); - } - - public void updateNClob(String columnLabel, Reader reader) - throws SQLException { - wrapped.updateNClob(columnLabel, reader); - } - - public void updateNString(int columnIndex, String nString) - throws SQLException { - wrapped.updateNString(columnIndex, nString); - } - - public void updateNString(String columnLabel, String nString) - throws SQLException { - wrapped.updateNString(columnLabel, nString); - } - - public void updateNull(int columnIndex) throws SQLException { - wrapped.updateNull(columnIndex); - } - - public void updateNull(String columnLabel) throws SQLException { - wrapped.updateNull(columnLabel); - } - - public void updateObject(int columnIndex, Object x, int scaleOrLength) - throws SQLException { - wrapped.updateObject(columnIndex, x, scaleOrLength); - } - - public void updateObject(int columnIndex, Object x) throws SQLException { - wrapped.updateObject(columnIndex, x); - } - - public void updateObject(String columnLabel, Object x, int scaleOrLength) - throws SQLException { - wrapped.updateObject(columnLabel, x, scaleOrLength); - } - - public void updateObject(String columnLabel, Object x) throws SQLException { - wrapped.updateObject(columnLabel, x); - } - - public void updateRef(int columnIndex, Ref x) throws SQLException { - wrapped.updateRef(columnIndex, x); - } - - public void updateRef(String columnLabel, Ref x) throws SQLException { - wrapped.updateRef(columnLabel, x); - } - - public void updateRow() throws SQLException { - wrapped.updateRow(); - } - - public void updateRowId(int columnIndex, RowId x) throws SQLException { - wrapped.updateRowId(columnIndex, x); - } - - public void updateRowId(String columnLabel, RowId x) throws SQLException { - wrapped.updateRowId(columnLabel, x); - } - - public void updateSQLXML(int columnIndex, SQLXML xmlObject) - throws SQLException { - wrapped.updateSQLXML(columnIndex, xmlObject); - } - - public void updateSQLXML(String columnLabel, SQLXML xmlObject) - throws SQLException { - wrapped.updateSQLXML(columnLabel, xmlObject); - } - - public void updateShort(int columnIndex, short x) throws SQLException { - wrapped.updateShort(columnIndex, x); - } - - public void updateShort(String columnLabel, short x) throws SQLException { - wrapped.updateShort(columnLabel, x); - } - - public void updateString(int columnIndex, String x) throws SQLException { - wrapped.updateString(columnIndex, x); - } - - public void updateString(String columnLabel, String x) throws SQLException { - wrapped.updateString(columnLabel, x); - } - - public void updateTime(int columnIndex, Time x) throws SQLException { - wrapped.updateTime(columnIndex, x); - } - - public void updateTime(String columnLabel, Time x) throws SQLException { - wrapped.updateTime(columnLabel, x); - } - - public void updateTimestamp(int columnIndex, Timestamp x) - throws SQLException { - wrapped.updateTimestamp(columnIndex, x); - } - - public void updateTimestamp(String columnLabel, Timestamp x) - throws SQLException { - wrapped.updateTimestamp(columnLabel, x); - } - - public boolean wasNull() throws SQLException { - return wrapped.wasNull(); - } -// -} +/* + * 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 db; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.Array; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.NClob; +import java.sql.Ref; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLWarning; +import java.sql.SQLXML; +import java.sql.Statement; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.Calendar; +import java.util.Map; + +/** + * + * @author BobCaSUaL + */ +public abstract class ResultSetWrapper implements ResultSet { + private ResultSet wrapped; + + public ResultSetWrapper( ResultSet rs ) { + this.wrapped = rs; + } +// + + public boolean absolute(int row) throws SQLException { + return wrapped.absolute(row); + } + + public void afterLast() throws SQLException { + wrapped.afterLast(); + } + + public void beforeFirst() throws SQLException { + wrapped.beforeFirst(); + } + + public void cancelRowUpdates() throws SQLException { + wrapped.cancelRowUpdates(); + } + + public void clearWarnings() throws SQLException { + wrapped.clearWarnings(); + } + + public void close() throws SQLException { + wrapped.close(); + } + + public void deleteRow() throws SQLException { + wrapped.deleteRow(); + } + + public int findColumn(String columnLabel) throws SQLException { + return wrapped.findColumn(columnLabel); + } + + public boolean first() throws SQLException { + return wrapped.first(); + } + + public Array getArray(int columnIndex) throws SQLException { + return wrapped.getArray(columnIndex); + } + + public Array getArray(String columnLabel) throws SQLException { + return wrapped.getArray(columnLabel); + } + + public InputStream getAsciiStream(int columnIndex) throws SQLException { + return wrapped.getAsciiStream(columnIndex); + } + + public InputStream getAsciiStream(String columnLabel) throws SQLException { + return wrapped.getAsciiStream(columnLabel); + } + + public BigDecimal getBigDecimal(int columnIndex, int scale) + throws SQLException { + return wrapped.getBigDecimal(columnIndex, scale); + } + + public BigDecimal getBigDecimal(int columnIndex) throws SQLException { + return wrapped.getBigDecimal(columnIndex); + } + + public BigDecimal getBigDecimal(String columnLabel, int scale) + throws SQLException { + return wrapped.getBigDecimal(columnLabel, scale); + } + + public BigDecimal getBigDecimal(String columnLabel) throws SQLException { + return wrapped.getBigDecimal(columnLabel); + } + + public InputStream getBinaryStream(int columnIndex) throws SQLException { + return wrapped.getBinaryStream(columnIndex); + } + + public InputStream getBinaryStream(String columnLabel) throws SQLException { + return wrapped.getBinaryStream(columnLabel); + } + + public Blob getBlob(int columnIndex) throws SQLException { + return wrapped.getBlob(columnIndex); + } + + public Blob getBlob(String columnLabel) throws SQLException { + return wrapped.getBlob(columnLabel); + } + + public boolean getBoolean(int columnIndex) throws SQLException { + return wrapped.getBoolean(columnIndex); + } + + public boolean getBoolean(String columnLabel) throws SQLException { + return wrapped.getBoolean(columnLabel); + } + + public byte getByte(int columnIndex) throws SQLException { + return wrapped.getByte(columnIndex); + } + + public byte getByte(String columnLabel) throws SQLException { + return wrapped.getByte(columnLabel); + } + + public byte[] getBytes(int columnIndex) throws SQLException { + return wrapped.getBytes(columnIndex); + } + + public byte[] getBytes(String columnLabel) throws SQLException { + return wrapped.getBytes(columnLabel); + } + + public Reader getCharacterStream(int columnIndex) throws SQLException { + return wrapped.getCharacterStream(columnIndex); + } + + public Reader getCharacterStream(String columnLabel) throws SQLException { + return wrapped.getCharacterStream(columnLabel); + } + + public Clob getClob(int columnIndex) throws SQLException { + return wrapped.getClob(columnIndex); + } + + public Clob getClob(String columnLabel) throws SQLException { + return wrapped.getClob(columnLabel); + } + + public int getConcurrency() throws SQLException { + return wrapped.getConcurrency(); + } + + public String getCursorName() throws SQLException { + return wrapped.getCursorName(); + } + + public Date getDate(int columnIndex, Calendar cal) throws SQLException { + return wrapped.getDate(columnIndex, cal); + } + + public Date getDate(int columnIndex) throws SQLException { + return wrapped.getDate(columnIndex); + } + + public Date getDate(String columnLabel, Calendar cal) throws SQLException { + return wrapped.getDate(columnLabel, cal); + } + + public Date getDate(String columnLabel) throws SQLException { + return wrapped.getDate(columnLabel); + } + + public double getDouble(int columnIndex) throws SQLException { + return wrapped.getDouble(columnIndex); + } + + public double getDouble(String columnLabel) throws SQLException { + return wrapped.getDouble(columnLabel); + } + + public int getFetchDirection() throws SQLException { + return wrapped.getFetchDirection(); + } + + public int getFetchSize() throws SQLException { + return wrapped.getFetchSize(); + } + + public float getFloat(int columnIndex) throws SQLException { + return wrapped.getFloat(columnIndex); + } + + public float getFloat(String columnLabel) throws SQLException { + return wrapped.getFloat(columnLabel); + } + + public int getHoldability() throws SQLException { + return wrapped.getHoldability(); + } + + public int getInt(int columnIndex) throws SQLException { + return wrapped.getInt(columnIndex); + } + + public int getInt(String columnLabel) throws SQLException { + return wrapped.getInt(columnLabel); + } + + public long getLong(int columnIndex) throws SQLException { + return wrapped.getLong(columnIndex); + } + + public long getLong(String columnLabel) throws SQLException { + return wrapped.getLong(columnLabel); + } + + public ResultSetMetaData getMetaData() throws SQLException { + return wrapped.getMetaData(); + } + + public Reader getNCharacterStream(int columnIndex) throws SQLException { + return wrapped.getNCharacterStream(columnIndex); + } + + public Reader getNCharacterStream(String columnLabel) throws SQLException { + return wrapped.getNCharacterStream(columnLabel); + } + + public NClob getNClob(int columnIndex) throws SQLException { + return wrapped.getNClob(columnIndex); + } + + public NClob getNClob(String columnLabel) throws SQLException { + return wrapped.getNClob(columnLabel); + } + + public String getNString(int columnIndex) throws SQLException { + return wrapped.getNString(columnIndex); + } + + public String getNString(String columnLabel) throws SQLException { + return wrapped.getNString(columnLabel); + } + + public T getObject(int columnIndex, Class type) throws SQLException { + return wrapped.getObject(columnIndex, type); + } + + public Object getObject(int columnIndex, Map> map) + throws SQLException { + return wrapped.getObject(columnIndex, map); + } + + public Object getObject(int columnIndex) throws SQLException { + return wrapped.getObject(columnIndex); + } + + public T getObject(String columnLabel, Class type) + throws SQLException { + return wrapped.getObject(columnLabel, type); + } + + public Object getObject(String columnLabel, Map> map) + throws SQLException { + return wrapped.getObject(columnLabel, map); + } + + public Object getObject(String columnLabel) throws SQLException { + return wrapped.getObject(columnLabel); + } + + public Ref getRef(int columnIndex) throws SQLException { + return wrapped.getRef(columnIndex); + } + + public Ref getRef(String columnLabel) throws SQLException { + return wrapped.getRef(columnLabel); + } + + public int getRow() throws SQLException { + return wrapped.getRow(); + } + + public RowId getRowId(int columnIndex) throws SQLException { + return wrapped.getRowId(columnIndex); + } + + public RowId getRowId(String columnLabel) throws SQLException { + return wrapped.getRowId(columnLabel); + } + + public SQLXML getSQLXML(int columnIndex) throws SQLException { + return wrapped.getSQLXML(columnIndex); + } + + public SQLXML getSQLXML(String columnLabel) throws SQLException { + return wrapped.getSQLXML(columnLabel); + } + + public short getShort(int columnIndex) throws SQLException { + return wrapped.getShort(columnIndex); + } + + public short getShort(String columnLabel) throws SQLException { + return wrapped.getShort(columnLabel); + } + + public Statement getStatement() throws SQLException { + return wrapped.getStatement(); + } + + public String getString(int columnIndex) throws SQLException { + return wrapped.getString(columnIndex); + } + + public String getString(String columnLabel) throws SQLException { + return wrapped.getString(columnLabel); + } + + public Time getTime(int columnIndex, Calendar cal) throws SQLException { + return wrapped.getTime(columnIndex, cal); + } + + public Time getTime(int columnIndex) throws SQLException { + return wrapped.getTime(columnIndex); + } + + public Time getTime(String columnLabel, Calendar cal) throws SQLException { + return wrapped.getTime(columnLabel, cal); + } + + public Time getTime(String columnLabel) throws SQLException { + return wrapped.getTime(columnLabel); + } + + public Timestamp getTimestamp(int columnIndex, Calendar cal) + throws SQLException { + return wrapped.getTimestamp(columnIndex, cal); + } + + public Timestamp getTimestamp(int columnIndex) throws SQLException { + return wrapped.getTimestamp(columnIndex); + } + + public Timestamp getTimestamp(String columnLabel, Calendar cal) + throws SQLException { + return wrapped.getTimestamp(columnLabel, cal); + } + + public Timestamp getTimestamp(String columnLabel) throws SQLException { + return wrapped.getTimestamp(columnLabel); + } + + public int getType() throws SQLException { + return wrapped.getType(); + } + + public URL getURL(int columnIndex) throws SQLException { + return wrapped.getURL(columnIndex); + } + + public URL getURL(String columnLabel) throws SQLException { + return wrapped.getURL(columnLabel); + } + + public InputStream getUnicodeStream(int columnIndex) throws SQLException { + return wrapped.getUnicodeStream(columnIndex); + } + + public InputStream getUnicodeStream(String columnLabel) throws SQLException { + return wrapped.getUnicodeStream(columnLabel); + } + + public SQLWarning getWarnings() throws SQLException { + return wrapped.getWarnings(); + } + + public void insertRow() throws SQLException { + wrapped.insertRow(); + } + + public boolean isAfterLast() throws SQLException { + return wrapped.isAfterLast(); + } + + public boolean isBeforeFirst() throws SQLException { + return wrapped.isBeforeFirst(); + } + + public boolean isClosed() throws SQLException { + return wrapped.isClosed(); + } + + public boolean isFirst() throws SQLException { + return wrapped.isFirst(); + } + + public boolean isLast() throws SQLException { + return wrapped.isLast(); + } + + public boolean isWrapperFor(Class iface) throws SQLException { + return wrapped.isWrapperFor(iface); + } + + public boolean last() throws SQLException { + return wrapped.last(); + } + + public void moveToCurrentRow() throws SQLException { + wrapped.moveToCurrentRow(); + } + + public void moveToInsertRow() throws SQLException { + wrapped.moveToInsertRow(); + } + + public boolean next() throws SQLException { + return wrapped.next(); + } + + public boolean previous() throws SQLException { + return wrapped.previous(); + } + + public void refreshRow() throws SQLException { + wrapped.refreshRow(); + } + + public boolean relative(int rows) throws SQLException { + return wrapped.relative(rows); + } + + public boolean rowDeleted() throws SQLException { + return wrapped.rowDeleted(); + } + + public boolean rowInserted() throws SQLException { + return wrapped.rowInserted(); + } + + public boolean rowUpdated() throws SQLException { + return wrapped.rowUpdated(); + } + + public void setFetchDirection(int direction) throws SQLException { + wrapped.setFetchDirection(direction); + } + + public void setFetchSize(int rows) throws SQLException { + wrapped.setFetchSize(rows); + } + + public T unwrap(Class iface) throws SQLException { + return wrapped.unwrap(iface); + } + + public void updateArray(int columnIndex, Array x) throws SQLException { + wrapped.updateArray(columnIndex, x); + } + + public void updateArray(String columnLabel, Array x) throws SQLException { + wrapped.updateArray(columnLabel, x); + } + + public void updateAsciiStream(int columnIndex, InputStream x, int length) + throws SQLException { + wrapped.updateAsciiStream(columnIndex, x, length); + } + + public void updateAsciiStream(int columnIndex, InputStream x, long length) + throws SQLException { + wrapped.updateAsciiStream(columnIndex, x, length); + } + + public void updateAsciiStream(int columnIndex, InputStream x) + throws SQLException { + wrapped.updateAsciiStream(columnIndex, x); + } + + public void updateAsciiStream(String columnLabel, InputStream x, int length) + throws SQLException { + wrapped.updateAsciiStream(columnLabel, x, length); + } + + public void updateAsciiStream(String columnLabel, InputStream x, long length) + throws SQLException { + wrapped.updateAsciiStream(columnLabel, x, length); + } + + public void updateAsciiStream(String columnLabel, InputStream x) + throws SQLException { + wrapped.updateAsciiStream(columnLabel, x); + } + + public void updateBigDecimal(int columnIndex, BigDecimal x) + throws SQLException { + wrapped.updateBigDecimal(columnIndex, x); + } + + public void updateBigDecimal(String columnLabel, BigDecimal x) + throws SQLException { + wrapped.updateBigDecimal(columnLabel, x); + } + + public void updateBinaryStream(int columnIndex, InputStream x, int length) + throws SQLException { + wrapped.updateBinaryStream(columnIndex, x, length); + } + + public void updateBinaryStream(int columnIndex, InputStream x, long length) + throws SQLException { + wrapped.updateBinaryStream(columnIndex, x, length); + } + + public void updateBinaryStream(int columnIndex, InputStream x) + throws SQLException { + wrapped.updateBinaryStream(columnIndex, x); + } + + public void updateBinaryStream(String columnLabel, InputStream x, int length) + throws SQLException { + wrapped.updateBinaryStream(columnLabel, x, length); + } + + public void updateBinaryStream(String columnLabel, InputStream x, + long length) throws SQLException { + wrapped.updateBinaryStream(columnLabel, x, length); + } + + public void updateBinaryStream(String columnLabel, InputStream x) + throws SQLException { + wrapped.updateBinaryStream(columnLabel, x); + } + + public void updateBlob(int columnIndex, Blob x) throws SQLException { + wrapped.updateBlob(columnIndex, x); + } + + public void updateBlob(int columnIndex, InputStream inputStream, long length) + throws SQLException { + wrapped.updateBlob(columnIndex, inputStream, length); + } + + public void updateBlob(int columnIndex, InputStream inputStream) + throws SQLException { + wrapped.updateBlob(columnIndex, inputStream); + } + + public void updateBlob(String columnLabel, Blob x) throws SQLException { + wrapped.updateBlob(columnLabel, x); + } + + public void updateBlob(String columnLabel, InputStream inputStream, + long length) throws SQLException { + wrapped.updateBlob(columnLabel, inputStream, length); + } + + public void updateBlob(String columnLabel, InputStream inputStream) + throws SQLException { + wrapped.updateBlob(columnLabel, inputStream); + } + + public void updateBoolean(int columnIndex, boolean x) throws SQLException { + wrapped.updateBoolean(columnIndex, x); + } + + public void updateBoolean(String columnLabel, boolean x) + throws SQLException { + wrapped.updateBoolean(columnLabel, x); + } + + public void updateByte(int columnIndex, byte x) throws SQLException { + wrapped.updateByte(columnIndex, x); + } + + public void updateByte(String columnLabel, byte x) throws SQLException { + wrapped.updateByte(columnLabel, x); + } + + public void updateBytes(int columnIndex, byte[] x) throws SQLException { + wrapped.updateBytes(columnIndex, x); + } + + public void updateBytes(String columnLabel, byte[] x) throws SQLException { + wrapped.updateBytes(columnLabel, x); + } + + public void updateCharacterStream(int columnIndex, Reader x, int length) + throws SQLException { + wrapped.updateCharacterStream(columnIndex, x, length); + } + + public void updateCharacterStream(int columnIndex, Reader x, long length) + throws SQLException { + wrapped.updateCharacterStream(columnIndex, x, length); + } + + public void updateCharacterStream(int columnIndex, Reader x) + throws SQLException { + wrapped.updateCharacterStream(columnIndex, x); + } + + public void updateCharacterStream(String columnLabel, Reader reader, + int length) throws SQLException { + wrapped.updateCharacterStream(columnLabel, reader, length); + } + + public void updateCharacterStream(String columnLabel, Reader reader, + long length) throws SQLException { + wrapped.updateCharacterStream(columnLabel, reader, length); + } + + public void updateCharacterStream(String columnLabel, Reader reader) + throws SQLException { + wrapped.updateCharacterStream(columnLabel, reader); + } + + public void updateClob(int columnIndex, Clob x) throws SQLException { + wrapped.updateClob(columnIndex, x); + } + + public void updateClob(int columnIndex, Reader reader, long length) + throws SQLException { + wrapped.updateClob(columnIndex, reader, length); + } + + public void updateClob(int columnIndex, Reader reader) throws SQLException { + wrapped.updateClob(columnIndex, reader); + } + + public void updateClob(String columnLabel, Clob x) throws SQLException { + wrapped.updateClob(columnLabel, x); + } + + public void updateClob(String columnLabel, Reader reader, long length) + throws SQLException { + wrapped.updateClob(columnLabel, reader, length); + } + + public void updateClob(String columnLabel, Reader reader) + throws SQLException { + wrapped.updateClob(columnLabel, reader); + } + + public void updateDate(int columnIndex, Date x) throws SQLException { + wrapped.updateDate(columnIndex, x); + } + + public void updateDate(String columnLabel, Date x) throws SQLException { + wrapped.updateDate(columnLabel, x); + } + + public void updateDouble(int columnIndex, double x) throws SQLException { + wrapped.updateDouble(columnIndex, x); + } + + public void updateDouble(String columnLabel, double x) throws SQLException { + wrapped.updateDouble(columnLabel, x); + } + + public void updateFloat(int columnIndex, float x) throws SQLException { + wrapped.updateFloat(columnIndex, x); + } + + public void updateFloat(String columnLabel, float x) throws SQLException { + wrapped.updateFloat(columnLabel, x); + } + + public void updateInt(int columnIndex, int x) throws SQLException { + wrapped.updateInt(columnIndex, x); + } + + public void updateInt(String columnLabel, int x) throws SQLException { + wrapped.updateInt(columnLabel, x); + } + + public void updateLong(int columnIndex, long x) throws SQLException { + wrapped.updateLong(columnIndex, x); + } + + public void updateLong(String columnLabel, long x) throws SQLException { + wrapped.updateLong(columnLabel, x); + } + + public void updateNCharacterStream(int columnIndex, Reader x, long length) + throws SQLException { + wrapped.updateNCharacterStream(columnIndex, x, length); + } + + public void updateNCharacterStream(int columnIndex, Reader x) + throws SQLException { + wrapped.updateNCharacterStream(columnIndex, x); + } + + public void updateNCharacterStream(String columnLabel, Reader reader, + long length) throws SQLException { + wrapped.updateNCharacterStream(columnLabel, reader, length); + } + + public void updateNCharacterStream(String columnLabel, Reader reader) + throws SQLException { + wrapped.updateNCharacterStream(columnLabel, reader); + } + + public void updateNClob(int columnIndex, NClob nClob) throws SQLException { + wrapped.updateNClob(columnIndex, nClob); + } + + public void updateNClob(int columnIndex, Reader reader, long length) + throws SQLException { + wrapped.updateNClob(columnIndex, reader, length); + } + + public void updateNClob(int columnIndex, Reader reader) throws SQLException { + wrapped.updateNClob(columnIndex, reader); + } + + public void updateNClob(String columnLabel, NClob nClob) + throws SQLException { + wrapped.updateNClob(columnLabel, nClob); + } + + public void updateNClob(String columnLabel, Reader reader, long length) + throws SQLException { + wrapped.updateNClob(columnLabel, reader, length); + } + + public void updateNClob(String columnLabel, Reader reader) + throws SQLException { + wrapped.updateNClob(columnLabel, reader); + } + + public void updateNString(int columnIndex, String nString) + throws SQLException { + wrapped.updateNString(columnIndex, nString); + } + + public void updateNString(String columnLabel, String nString) + throws SQLException { + wrapped.updateNString(columnLabel, nString); + } + + public void updateNull(int columnIndex) throws SQLException { + wrapped.updateNull(columnIndex); + } + + public void updateNull(String columnLabel) throws SQLException { + wrapped.updateNull(columnLabel); + } + + public void updateObject(int columnIndex, Object x, int scaleOrLength) + throws SQLException { + wrapped.updateObject(columnIndex, x, scaleOrLength); + } + + public void updateObject(int columnIndex, Object x) throws SQLException { + wrapped.updateObject(columnIndex, x); + } + + public void updateObject(String columnLabel, Object x, int scaleOrLength) + throws SQLException { + wrapped.updateObject(columnLabel, x, scaleOrLength); + } + + public void updateObject(String columnLabel, Object x) throws SQLException { + wrapped.updateObject(columnLabel, x); + } + + public void updateRef(int columnIndex, Ref x) throws SQLException { + wrapped.updateRef(columnIndex, x); + } + + public void updateRef(String columnLabel, Ref x) throws SQLException { + wrapped.updateRef(columnLabel, x); + } + + public void updateRow() throws SQLException { + wrapped.updateRow(); + } + + public void updateRowId(int columnIndex, RowId x) throws SQLException { + wrapped.updateRowId(columnIndex, x); + } + + public void updateRowId(String columnLabel, RowId x) throws SQLException { + wrapped.updateRowId(columnLabel, x); + } + + public void updateSQLXML(int columnIndex, SQLXML xmlObject) + throws SQLException { + wrapped.updateSQLXML(columnIndex, xmlObject); + } + + public void updateSQLXML(String columnLabel, SQLXML xmlObject) + throws SQLException { + wrapped.updateSQLXML(columnLabel, xmlObject); + } + + public void updateShort(int columnIndex, short x) throws SQLException { + wrapped.updateShort(columnIndex, x); + } + + public void updateShort(String columnLabel, short x) throws SQLException { + wrapped.updateShort(columnLabel, x); + } + + public void updateString(int columnIndex, String x) throws SQLException { + wrapped.updateString(columnIndex, x); + } + + public void updateString(String columnLabel, String x) throws SQLException { + wrapped.updateString(columnLabel, x); + } + + public void updateTime(int columnIndex, Time x) throws SQLException { + wrapped.updateTime(columnIndex, x); + } + + public void updateTime(String columnLabel, Time x) throws SQLException { + wrapped.updateTime(columnLabel, x); + } + + public void updateTimestamp(int columnIndex, Timestamp x) + throws SQLException { + wrapped.updateTimestamp(columnIndex, x); + } + + public void updateTimestamp(String columnLabel, Timestamp x) + throws SQLException { + wrapped.updateTimestamp(columnLabel, x); + } + + public boolean wasNull() throws SQLException { + return wrapped.wasNull(); + } +// +} diff --git a/src/model/Messaggio.java b/src/model/Messaggio.java index aa95255..8315846 100644 --- a/src/model/Messaggio.java +++ b/src/model/Messaggio.java @@ -52,14 +52,6 @@ public Messaggio(String testo, String lingua, UserInfo mittente, UserInfo destin this.destinatario = destinatario; this.sdc = sdc; } - - public Messaggio(){ - this.testo = null; - this.lingua = null; - this.mittente = null; - this.destinatario = null; - this.sdc = null; - } public void setLingua(String l) { this.lingua = l; @@ -189,7 +181,7 @@ public boolean isLetto() { return true; } - private String toStringF = "Messaggio in lingua: %lingua% inviato da %mittente%: %testo%"; + private String toStringF = "Messaggio in lingua: %lingua% inviato da %mittente%, per %destinatarioID%: %testo%"; public String setToStringF(String f) { String result = getToStringF(); @@ -264,13 +256,6 @@ public String getLingua() { return lingua; } - /** - * @return the titolo - */ - public String getTitolo() { - return titolo; - } - /** * @return the toStringF */ diff --git a/src/model/MessaggioAstratto.java b/src/model/MessaggioAstratto.java index e8148e9..df95f6c 100644 --- a/src/model/MessaggioAstratto.java +++ b/src/model/MessaggioAstratto.java @@ -14,6 +14,6 @@ public interface MessaggioAstratto { public String getTesto(); public String getTestoCifrato(); public String getLingua(); - public String getTitolo(); + public boolean elimina(); } diff --git a/src/model/Studente.java b/src/model/Studente.java index 1ba7dee..547ffc0 100644 --- a/src/model/Studente.java +++ b/src/model/Studente.java @@ -23,6 +23,7 @@ public class Studente { private String id; private String login; private String pwd; + private DbManager DbManager0; public Studente(String user){ this.login = user; @@ -117,5 +118,12 @@ public String getLogin() { public String getPwd() { return pwd; } + + /** + * @return the DbManager0 + */ + public DbManager getDbManager0() { + return DbManager0; + } } diff --git a/src/model/spia/AnalisiFrequenze.java b/src/model/spia/AnalisiFrequenze.java index 3aa4019..fbacc33 100644 --- a/src/model/spia/AnalisiFrequenze.java +++ b/src/model/spia/AnalisiFrequenze.java @@ -1,49 +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 model.spia; -import java.util.HashMap; -/** - * - * @author davide - */ -public class AnalisiFrequenze implements StrumentoDiSupporto { - private HashMap table; - private int msgLength; - - @Override - public void start (String messaggio) { - table = new HashMap(); -// msg = msg.toLowerCase(); - messaggio = messaggio.replaceAll("\\s", ""); /*rimuove gli spazi*/ - this. msgLength = messaggio.length(); - System.out.println(messaggio); - for(int i = 0; i < messaggio.length(); i++){ - Character c = messaggio.charAt(i); - if (table.containsKey(c)){ - Integer occorrenze = (Integer)table.get(c)+1; - table.put(c, occorrenze); - } - else{ - table.put(c, new Integer(1)); - } - } - System.out.println(/*table + " size " + */this.toString()); - } - @Override - public String toString() { - String frequencyTable = "Numero lettere nel messaggio " + this.getMsgLength()+"\n"; - for(Character currentKey : table.keySet()){ - Integer occurence =table.get(currentKey); - frequencyTable += currentKey + " numero occorrenze " + occurence + " percentuale " + (double)occurence/this.getMsgLength()*100+"\n"; - } - return frequencyTable; - //return table.size()+" numero lettere "+this.getMsgLength(); - } - - private int getMsgLength(){ - return this.msgLength; - } -} +/* + * 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 model.spia; +import java.util.HashMap; +/** + * + * @author davide + */ +public class AnalisiFrequenze implements StrumentoDiSupporto { + private HashMap table; + private int msgLength; + + @Override + public void start (String messaggio) { + table = new HashMap(); +// msg = msg.toLowerCase(); + messaggio = messaggio.replaceAll("\\s", ""); /*rimuove gli spazi*/ + this. msgLength = messaggio.length(); + System.out.println(messaggio); + for(int i = 0; i < messaggio.length(); i++){ + Character c = messaggio.charAt(i); + if (table.containsKey(c)){ + Integer occorrenze = (Integer)table.get(c)+1; + table.put(c, occorrenze); + } + else{ + table.put(c, new Integer(1)); + } + } + System.out.println(/*table + " size " + */this.toString()); + } + @Override + public String toString() { + String frequencyTable = "Numero lettere nel messaggio " + this.getMsgLength()+"\n"; + for(Character currentKey : table.keySet()){ + Integer occurence =table.get(currentKey); + frequencyTable += currentKey + " numero occorrenze " + occurence + " percentuale " + (double)occurence/this.getMsgLength()*100+"\n"; + } + return frequencyTable; + //return table.size()+" numero lettere "+this.getMsgLength(); + } + + private int getMsgLength(){ + return this.msgLength; + } +} diff --git a/src/model/spia/Ipotesi.java b/src/model/spia/Ipotesi.java index ad8f2ff..e1b0029 100644 --- a/src/model/spia/Ipotesi.java +++ b/src/model/spia/Ipotesi.java @@ -1,44 +1,44 @@ -package model.spia; - - -import java.io.Serializable; -import java.util.Enumeration; -import javax.swing.tree.TreeNode; - -/* - * 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. - */ - -/** - * - * @author user - */ -public class Ipotesi extends javax.swing.tree.DefaultMutableTreeNode implements Serializable { - - private String key; - private String messaggioParzialmenteDecifrato; - - public Ipotesi( String key, String messaggioParzialmenteDecifrato ) { - this.key = key; - this.messaggioParzialmenteDecifrato = messaggioParzialmenteDecifrato; - } - - public String getMessaggioParzialmenteDecifrato() { - return this.messaggioParzialmenteDecifrato; - } - - public void add( Ipotesi p ) { - super.add( p ); - } - - public void remove( Ipotesi p ) { - super.remove( p ); - } - - public String toString() { - return this.key; - } - -} +package model.spia; + + +import java.io.Serializable; +import java.util.Enumeration; +import javax.swing.tree.TreeNode; + +/* + * 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. + */ + +/** + * + * @author user + */ +public class Ipotesi extends javax.swing.tree.DefaultMutableTreeNode implements Serializable { + + private String key; + private String messaggioParzialmenteDecifrato; + + public Ipotesi( String key, String messaggioParzialmenteDecifrato ) { + this.key = key; + this.messaggioParzialmenteDecifrato = messaggioParzialmenteDecifrato; + } + + public String getMessaggioParzialmenteDecifrato() { + return this.messaggioParzialmenteDecifrato; + } + + public void add( Ipotesi p ) { + super.add( p ); + } + + public void remove( Ipotesi p ) { + super.remove( p ); + } + + public String toString() { + return this.key; + } + +} diff --git a/src/model/spia/RipristinaIpotesiPrecedente.java b/src/model/spia/RipristinaIpotesiPrecedente.java index 91eaea2..1e3861a 100644 --- a/src/model/spia/RipristinaIpotesiPrecedente.java +++ b/src/model/spia/RipristinaIpotesiPrecedente.java @@ -1,19 +1,19 @@ -/* - * 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 model.spia; - -/** - * - * @author user - */ -public class RipristinaIpotesiPrecedente implements StrumentoDiManipolazione { - @Override - public void elabora(Sessione s) { - new GUI.spia.RipristinaIpotesiPrecedenteGUI( s ).setVisible(true); - } - -} +/* + * 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 model.spia; + +/** + * + * @author user + */ +public class RipristinaIpotesiPrecedente implements StrumentoDiManipolazione { + @Override + public void elabora(Sessione s) { + new GUI.spia.RipristinaIpotesiPrecedenteGUI( s ).setVisible(true); + } + +} diff --git a/src/model/spia/Sessione.java b/src/model/spia/Sessione.java index 1cd8710..29c1e2b 100644 --- a/src/model/spia/Sessione.java +++ b/src/model/spia/Sessione.java @@ -1,203 +1,203 @@ -package model.spia; - -import GUI.GenericSelector; -import GUI.PopUpViewer; -import GUI.spia.CicloDiAnalisi; -import db.DbManager; -import db.Query; -import db.QueryResult; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.Observable; -import model.Messaggio; -import model.Studente; - -/* - * 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. - */ -/** - * - * @author user - */ -public class Sessione extends Observable implements Serializable { - - public static class Properties extends java.util.Hashtable { - } - - public static Sessione recuperaSessione(Spia owner) throws SQLException { - Sessione result = null; - ArrayList optionList = new ArrayList<>(); - - //seleziona la key di una sessione salvata - DbManager db = DbManager.getInstance(); - Query q = db.createQuery("SELECT `key` FROM `Sessione` WHERE `userId` = ?"); - q.setString(1, owner.getId()); - QueryResult rs = db.execute(q); - while (rs.next()) { - optionList.add(rs.getString("key")); - } - String key = GenericSelector.selectOptions(optionList); - - //In base alla key scelta deserializza la Sessione dal database - Query u = db.createQuery("SELECT `id`, `session` FROM `Sessione` WHERE `userId` = ? AND `key` = ? LIMIT 1"); - u.setString(1, owner.getId()); - u.setString(2, key); - QueryResult qr = db.execute(u); - - if (qr.next()) { - - try { - ByteArrayInputStream bais; - ObjectInputStream ins; - bais = new ByteArrayInputStream(qr.getBytes("session")); - ins = new ObjectInputStream(bais); - result =(Sessione)ins.readObject(); - - } catch( IOException | ClassNotFoundException ex ) { - throw new RuntimeException( ex.getMessage(), ex ); - } - - result.id = qr.getInt("id"); - result.owner = owner; - - Query w = db.createQuery("SELECT * FROM `messaggio` WHERE `id` = ?"); - w.setInt(1, result.messaggioID); - QueryResult qu = db.execute( w ); - - if( qu.next() ) { - result.messaggio = new Messaggio( qu ); - } else { - throw new RuntimeException("il messaggion con id "+result.messaggioID+"non è stato trovato nel database"); - } - - } - return result; - } - - public static Sessione restoreSessione(Sessione s) { - s.start(); - return s; - } - - public static void deleteSessione(Sessione sessione) { - try { - DbManager db = DbManager.getInstance(); - Query q = db.createQuery("DELETE FROM `Sessione` WHERE `id` = ? AND `userId` = ?"); - q.setInt(1, sessione.id); - q.setString(2, sessione.owner.getId()); - db.executeUpdate(q); - - } catch (SQLException ex) { - throw new RuntimeException(ex.getMessage(), ex); - } - } - - public static void saveSessione(Sessione sessione) { - - //i set a null sono essenziali per la serializzazione della classe - Spia owner = sessione.owner; - sessione.owner = null; - sessione.messaggioID = sessione.messaggio.getId(); - sessione.messaggio = null; - - try { - - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(bos); - oos.writeObject(sessione); - oos.flush(); - oos.close(); - bos.close(); - byte[] data = bos.toByteArray(); - - DbManager db = DbManager.getInstance(); - Query q = db.createQuery("INSERT INTO `Sessione`(`userId`,`key`,`session`) VALUES( ?, ?, ? ) ON DUPLICATE KEY UPDATE `session` = ?"); - q.setString(1, owner.getId()); - q.setString(2, sessione.key); - q.setObject(3, data); - q.setObject(4, data); - - db.executeUpdate(q); - System.out.println("Sessione salvata correttamente"); - } catch (IOException | SQLException ex) { - throw new RuntimeException(ex.getMessage(), ex); - } - } - - private int id; - private String key; - private Spia owner; - - private Ipotesi root; - private Ipotesi ipCorrente; - - private int messaggioID; //utilizzato per recuperare il messaggio deserializzato - private Messaggio messaggio; - - public Sessione(Spia owner, Messaggio m) { - this.messaggio = m; - this.messaggioID = m.getId(); - - this.owner = owner; - - this.key = new java.sql.Timestamp(new java.util.Date().getTime()).toString(); - - this.root = new Ipotesi("radice", m.getTestoCifrato()); - this.ipCorrente = this.root; - } - - public Ipotesi getIpotesiRadice() { - return root; - } - - public Ipotesi getIpotesiCorrente() { - return ipCorrente; - } - public void setIpotesiCorrente( Ipotesi ip ) { - this.ipCorrente = ip; - this.setChanged(); - this.notifyObservers(); - } - - public Messaggio getMessaggio() { - return this.messaggio; - } - - public void add( Ipotesi nuova ) { - this.ipCorrente.add( nuova ); - ipCorrente = nuova; - - this.setChanged(); - this.notifyObservers(); - } - public synchronized void start() { - - final Sessione self = this; - new Thread(new Runnable() { - public void run() { - new CicloDiAnalisi(self).setVisible(true); - } - }).start(); - - try { wait(); } - catch (InterruptedException ex) { throw new RuntimeException(ex.getMessage(), ex); } - - try { - saveSessione( this ); - new PopUpViewer("la sessione è stata salvata").setVisible(true); - } catch( RuntimeException ex ) { - new PopUpViewer("La sessione non è stata salvata: \n\n"+ex.getMessage()).setVisible(true); - throw ex; - } - - } -} +package model.spia; + +import GUI.GenericSelector; +import GUI.PopUpViewer; +import GUI.spia.CicloDiAnalisi; +import db.DbManager; +import db.Query; +import db.QueryResult; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Observable; +import model.Messaggio; +import model.Studente; + +/* + * 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. + */ +/** + * + * @author user + */ +public class Sessione extends Observable implements Serializable { + + public static class Properties extends java.util.Hashtable { + } + + public static Sessione recuperaSessione(Spia owner) throws SQLException { + Sessione result = null; + ArrayList optionList = new ArrayList<>(); + + //seleziona la key di una sessione salvata + DbManager db = DbManager.getInstance(); + Query q = db.createQuery("SELECT `key` FROM `Sessione` WHERE `userId` = ?"); + q.setString(1, owner.getId()); + QueryResult rs = db.execute(q); + while (rs.next()) { + optionList.add(rs.getString("key")); + } + String key = GenericSelector.selectOptions(optionList); + + //In base alla key scelta deserializza la Sessione dal database + Query u = db.createQuery("SELECT `id`, `session` FROM `Sessione` WHERE `userId` = ? AND `key` = ? LIMIT 1"); + u.setString(1, owner.getId()); + u.setString(2, key); + QueryResult qr = db.execute(u); + + if (qr.next()) { + + try { + ByteArrayInputStream bais; + ObjectInputStream ins; + bais = new ByteArrayInputStream(qr.getBytes("session")); + ins = new ObjectInputStream(bais); + result =(Sessione)ins.readObject(); + + } catch( IOException | ClassNotFoundException ex ) { + throw new RuntimeException( ex.getMessage(), ex ); + } + + result.id = qr.getInt("id"); + result.owner = owner; + + Query w = db.createQuery("SELECT * FROM `messaggio` WHERE `id` = ?"); + w.setInt(1, result.messaggioID); + QueryResult qu = db.execute( w ); + + if( qu.next() ) { + result.messaggio = new Messaggio( qu ); + } else { + throw new RuntimeException("il messaggion con id "+result.messaggioID+"non è stato trovato nel database"); + } + + } + return result; + } + + public static Sessione restoreSessione(Sessione s) { + s.start(); + return s; + } + + public static void deleteSessione(Sessione sessione) { + try { + DbManager db = DbManager.getInstance(); + Query q = db.createQuery("DELETE FROM `Sessione` WHERE `id` = ? AND `userId` = ?"); + q.setInt(1, sessione.id); + q.setString(2, sessione.owner.getId()); + db.executeUpdate(q); + + } catch (SQLException ex) { + throw new RuntimeException(ex.getMessage(), ex); + } + } + + public static void saveSessione(Sessione sessione) { + + //i set a null sono essenziali per la serializzazione della classe + Spia owner = sessione.owner; + sessione.owner = null; + sessione.messaggioID = sessione.messaggio.getId(); + sessione.messaggio = null; + + try { + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(sessione); + oos.flush(); + oos.close(); + bos.close(); + byte[] data = bos.toByteArray(); + + DbManager db = DbManager.getInstance(); + Query q = db.createQuery("INSERT INTO `Sessione`(`userId`,`key`,`session`) VALUES( ?, ?, ? ) ON DUPLICATE KEY UPDATE `session` = ?"); + q.setString(1, owner.getId()); + q.setString(2, sessione.key); + q.setObject(3, data); + q.setObject(4, data); + + db.executeUpdate(q); + System.out.println("Sessione salvata correttamente"); + } catch (IOException | SQLException ex) { + throw new RuntimeException(ex.getMessage(), ex); + } + } + + private int id; + private String key; + private Spia owner; + + private Ipotesi root; + private Ipotesi ipCorrente; + + private int messaggioID; //utilizzato per recuperare il messaggio deserializzato + private Messaggio messaggio; + + public Sessione(Spia owner, Messaggio m) { + this.messaggio = m; + this.messaggioID = m.getId(); + + this.owner = owner; + + this.key = new java.sql.Timestamp(new java.util.Date().getTime()).toString(); + + this.root = new Ipotesi("radice", m.getTestoCifrato()); + this.ipCorrente = this.root; + } + + public Ipotesi getIpotesiRadice() { + return root; + } + + public Ipotesi getIpotesiCorrente() { + return ipCorrente; + } + public void setIpotesiCorrente( Ipotesi ip ) { + this.ipCorrente = ip; + this.setChanged(); + this.notifyObservers(); + } + + public Messaggio getMessaggio() { + return this.messaggio; + } + + public void add( Ipotesi nuova ) { + this.ipCorrente.add( nuova ); + ipCorrente = nuova; + + this.setChanged(); + this.notifyObservers(); + } + public synchronized void start() { + + final Sessione self = this; + new Thread(new Runnable() { + public void run() { + new CicloDiAnalisi(self).setVisible(true); + } + }).start(); + + try { wait(); } + catch (InterruptedException ex) { throw new RuntimeException(ex.getMessage(), ex); } + + try { + saveSessione( this ); + new PopUpViewer("la sessione è stata salvata").setVisible(true); + } catch( RuntimeException ex ) { + new PopUpViewer("La sessione non è stata salvata: \n\n"+ex.getMessage()).setVisible(true); + throw ex; + } + + } +} diff --git a/src/model/spia/SostituzioneSemplice.java b/src/model/spia/SostituzioneSemplice.java index a396449..91c186d 100644 --- a/src/model/spia/SostituzioneSemplice.java +++ b/src/model/spia/SostituzioneSemplice.java @@ -1,47 +1,47 @@ -/* - * 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 model.spia; - -import GUI.spia.SostituzioneSempliceGUI; - - -/** - * - * @author davide - */ -public class SostituzioneSemplice implements StrumentoDiManipolazione { - private static String sostituisci(String msg, char from, char to){ - to = Character.toUpperCase(to); - msg = msg.replace(from, to); - return msg; - } - - @Override - public void elabora(Sessione sessione) { - final Sessione s = sessione; - new Thread( new Runnable() { - @Override - public void run() { - char[] array = SostituzioneSempliceGUI.getCaratteriDaSostituire(); - - if( array != null && array.length == 2 ) { - char crypt = array[0]; - char plain = array[1]; - - Ipotesi ipotesiCorrente = s.getIpotesiCorrente(); - String messaggio = ipotesiCorrente.getMessaggioParzialmenteDecifrato(); - - messaggio = sostituisci(messaggio, crypt, plain); - - Ipotesi nuova = new Ipotesi( crypt+" -> "+plain, messaggio); - s.add(nuova); - } - } - }).start(); - } - -} +/* + * 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 model.spia; + +import GUI.spia.SostituzioneSempliceGUI; + + +/** + * + * @author davide + */ +public class SostituzioneSemplice implements StrumentoDiManipolazione { + private static String sostituisci(String msg, char from, char to){ + to = Character.toUpperCase(to); + msg = msg.replace(from, to); + return msg; + } + + @Override + public void elabora(Sessione sessione) { + final Sessione s = sessione; + new Thread( new Runnable() { + @Override + public void run() { + char[] array = SostituzioneSempliceGUI.getCaratteriDaSostituire(); + + if( array != null && array.length == 2 ) { + char crypt = array[0]; + char plain = array[1]; + + Ipotesi ipotesiCorrente = s.getIpotesiCorrente(); + String messaggio = ipotesiCorrente.getMessaggioParzialmenteDecifrato(); + + messaggio = sostituisci(messaggio, crypt, plain); + + Ipotesi nuova = new Ipotesi( crypt+" -> "+plain, messaggio); + s.add(nuova); + } + } + }).start(); + } + +} diff --git a/src/model/spia/Spia.java b/src/model/spia/Spia.java index 619d5fa..0e35a32 100644 --- a/src/model/spia/Spia.java +++ b/src/model/spia/Spia.java @@ -1,58 +1,58 @@ -package model.spia; - -/* - * 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. - */ - -import GUI.GenericSelector; -import java.sql.SQLException; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import model.*; - -/** - * - * @author user - */ -public class Spia extends Studente { - - public Spia(String user) { - super(user); - } - public Spia( String user, String password ){ - super( user, password ); - } - public Spia(String nome, String cognome, String id, String user, String password){ - super( nome, cognome, id, user, password ); - } - - public Sessione startNewSessione( Messaggio selectedMsg ) { - Sessione s = new Sessione(this, selectedMsg); - s.start(); - return s; - } - - public Sessione restoreSessione() { - try { - Sessione recuperata = Sessione.recuperaSessione(this); - Sessione s = Sessione.restoreSessione( recuperata ); - return s; - } catch (SQLException ex) { - throw new RuntimeException( ex.getMessage(), ex ); - } - } - - public Sessione deleteSessione() { - try { - Sessione s = Sessione.recuperaSessione( this ); - Sessione.deleteSessione( s ); - return s; - } catch (SQLException ex) { - throw new RuntimeException( ex.getMessage(), ex ); - } - } - -} +package model.spia; + +/* + * 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. + */ + +import GUI.GenericSelector; +import java.sql.SQLException; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import model.*; + +/** + * + * @author user + */ +public class Spia extends Studente { + + public Spia(String user) { + super(user); + } + public Spia( String user, String password ){ + super( user, password ); + } + public Spia(String nome, String cognome, String id, String user, String password){ + super( nome, cognome, id, user, password ); + } + + public Sessione startNewSessione( Messaggio selectedMsg ) { + Sessione s = new Sessione(this, selectedMsg); + s.start(); + return s; + } + + public Sessione restoreSessione() { + try { + Sessione recuperata = Sessione.recuperaSessione(this); + Sessione s = Sessione.restoreSessione( recuperata ); + return s; + } catch (SQLException ex) { + throw new RuntimeException( ex.getMessage(), ex ); + } + } + + public Sessione deleteSessione() { + try { + Sessione s = Sessione.recuperaSessione( this ); + Sessione.deleteSessione( s ); + return s; + } catch (SQLException ex) { + throw new RuntimeException( ex.getMessage(), ex ); + } + } + +} diff --git a/src/model/spia/StrumentoDiManipolazione.java b/src/model/spia/StrumentoDiManipolazione.java index 9fa31f5..d915259 100644 --- a/src/model/spia/StrumentoDiManipolazione.java +++ b/src/model/spia/StrumentoDiManipolazione.java @@ -1,17 +1,17 @@ -/* - * 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 model.spia; - -import model.Messaggio; - -/** - * - * @author user - */ -public interface StrumentoDiManipolazione { - public void elabora( Sessione s ); -} +/* + * 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 model.spia; + +import model.Messaggio; + +/** + * + * @author user + */ +public interface StrumentoDiManipolazione { + public void elabora( Sessione s ); +} diff --git a/src/model/spia/StrumentoDiSupporto.java b/src/model/spia/StrumentoDiSupporto.java index 3d4ad17..259b0eb 100644 --- a/src/model/spia/StrumentoDiSupporto.java +++ b/src/model/spia/StrumentoDiSupporto.java @@ -1,21 +1,21 @@ -package model.spia; - - -import model.Messaggio; -import model.Messaggio; - -/* - * 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. - */ - -/** - * - * @author user - */ -public interface StrumentoDiSupporto { - public void start(String messaggio); - @Override - public String toString(); -} +package model.spia; + + +import model.Messaggio; +import model.Messaggio; + +/* + * 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. + */ + +/** + * + * @author user + */ +public interface StrumentoDiSupporto { + public void start(String messaggio); + @Override + public String toString(); +} diff --git a/src/model/user/CalcolatoreParolaChiave.java b/src/model/user/CalcolatoreParolaChiave.java index a31d24c..274330b 100644 --- a/src/model/user/CalcolatoreParolaChiave.java +++ b/src/model/user/CalcolatoreParolaChiave.java @@ -35,7 +35,7 @@ public Mappatura calcola(String s){ // i usato per ciclare sulla mappaInversa j++; System.out.println("carattere della mappa da cui iniziare" + mappa[position]); - while (j < mappaInversa.length){ + while (i < mappaInversa.length){ System.out.println("Mappatura in posizione " + j + "\n" +m.toString()); System.out.println("carattere letto " + mappa[j] + " " +s.indexOf(mappa[j])); //System.out.println(s.charAt(mappa[j])); @@ -44,11 +44,14 @@ public Mappatura calcola(String s){ System.out.println("aggiunto in posizione "+i); i++; } - else + else { System.out.println("non aggiunto"); - j++; + } + if (j == mappa.length-1) //se sono arrivato in fondo alla mappa originale + j=0; //ricomincio con la mappatura dall'inizio + else + j++; //altrimenti prosegui semplicemente } - //return new Mappatura(); return new Mappatura(mappaInversa); } /** diff --git a/src/model/user/CalcolatorePseudocasuale.java b/src/model/user/CalcolatorePseudocasuale.java index df7e89d..4a317d9 100644 --- a/src/model/user/CalcolatorePseudocasuale.java +++ b/src/model/user/CalcolatorePseudocasuale.java @@ -20,8 +20,20 @@ public CalcolatorePseudocasuale(String c){ }*/ public Mappatura calcola(String s){ - String ris; - //return new Mappatura(); - return null; + //s = calcolaParolaChiave(s); + //System.out.println(s); + CalcolatoreParolaChiave calcParChiave = new CalcolatoreParolaChiave(); + return calcParChiave.calcola(s); + } + + public String calcolaParolaChiave(String s) { + int length = Integer.parseInt(s); + s=""; + java.util.Random rand = new java.util.Random(); //estraggo un numeri compresi tra 0 e 25 (122-97 -> lettere minuscole dalla z alla a) + for (int i = 0; i