diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fab78c6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/dist/ +/nbproject/private/ +/build/ \ No newline at end of file diff --git a/nbproject/project.properties b/nbproject/project.properties index 0825295..9cfa4d8 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,76 +1,77 @@ -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=progetto_sas.Progetto_SAS -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}:\ + ${libs.junit_4.classpath} +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/DatabaseDUMPS/Sessione.sql b/src/DatabaseDUMPS/Sessione.sql new file mode 100644 index 0000000..3e33ceb --- /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/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/cryptohelper.sql b/src/DatabaseDUMPS/cryptohelper.sql new file mode 100644 index 0000000..56faed6 --- /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/DatabaseDUMPS/model.puml b/src/DatabaseDUMPS/model.puml new file mode 100644 index 0000000..fbfd37b --- /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 diff --git a/src/GUI/GenericSelector.form b/src/GUI/GenericSelector.form new file mode 100644 index 0000000..7e44460 --- /dev/null +++ b/src/GUI/GenericSelector.form @@ -0,0 +1,80 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/GenericSelector.java b/src/GUI/GenericSelector.java new file mode 100644 index 0000000..0966105 --- /dev/null +++ b/src/GUI/GenericSelector.java @@ -0,0 +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.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/view/Login.form b/src/GUI/Main.form similarity index 83% rename from src/view/Login.form rename to src/GUI/Main.form index 3881aa1..09734c1 100644 --- a/src/view/Login.form +++ b/src/GUI/Main.form @@ -46,30 +46,12 @@ - - - - - - - - - - - - - - - - - - - - + + @@ -86,6 +68,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -103,19 +109,21 @@ - + + + - - - + + + + + - - @@ -132,6 +140,9 @@ + + + @@ -170,6 +181,9 @@ + + + @@ -193,5 +207,13 @@ + + + + + + + + diff --git a/src/view/Login.java b/src/GUI/Main.java similarity index 64% rename from src/view/Login.java rename to src/GUI/Main.java index f801757..0163065 100644 --- a/src/view/Login.java +++ b/src/GUI/Main.java @@ -1,272 +1,299 @@ -/* - * 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; - -import model.Session; -/*import Clmodeltudente; -import ClasmodelrInfo;*/ -import controller.Controller; -import java.util.Vector; -import model.Studente; - -/** - * - * @author MASTER - */ -public class Login extends javax.swing.JFrame { - - /** - * Creates new form Login - */ - public Login() { - 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() { - - 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(); - - 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"); - - 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)) - .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)) - ); - 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.RELATED, 43, 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(jButton1)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jButton3) - .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 - // TODO add your handling code here: - Vector v; - if(jTextField1.getText().equals("")) - jLabel4.setText("Inserisci username"); - 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{ - //jLabel4.setText("Ok sei loggato"); - Session g = new Session(s.getId(), s.toString()); - Utente_Regolamentare m = new Utente_Regolamentare(); - m.setVisible(true); - } - - - - } - }//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 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(Login.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); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(Login.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); - } - // - - /* Create and display the form */ - java.awt.EventQueue.invokeLater(new Runnable() { - public void run() { - new Login().setVisible(true); - } - }); - } - - // 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.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 new file mode 100644 index 0000000..5431646 --- /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..c6f6432 --- /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 new file mode 100644 index 0000000..349cd9a --- /dev/null +++ b/src/GUI/spia/CicloDiAnalisi.form @@ -0,0 +1,156 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/spia/CicloDiAnalisi.java b/src/GUI/spia/CicloDiAnalisi.java new file mode 100644 index 0000000..c47d415 --- /dev/null +++ b/src/GUI/spia/CicloDiAnalisi.java @@ -0,0 +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.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 new file mode 100644 index 0000000..c998f73 --- /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..8f9cd97 --- /dev/null +++ b/src/GUI/spia/GestisciSessioneDiLavoro.java @@ -0,0 +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.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 new file mode 100644 index 0000000..e921177 --- /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..e79352c --- /dev/null +++ b/src/GUI/spia/GestisciSessioni.java @@ -0,0 +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 +} diff --git a/src/GUI/spia/RipristinaIpotesiPrecedenteGUI.form b/src/GUI/spia/RipristinaIpotesiPrecedenteGUI.form new file mode 100644 index 0000000..20d18fc --- /dev/null +++ b/src/GUI/spia/RipristinaIpotesiPrecedenteGUI.form @@ -0,0 +1,87 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/spia/RipristinaIpotesiPrecedenteGUI.java b/src/GUI/spia/RipristinaIpotesiPrecedenteGUI.java new file mode 100644 index 0000000..a42db3e --- /dev/null +++ b/src/GUI/spia/RipristinaIpotesiPrecedenteGUI.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 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.form b/src/GUI/spia/SostituzioneSempliceGUI.form new file mode 100644 index 0000000..5f4cc16 --- /dev/null +++ b/src/GUI/spia/SostituzioneSempliceGUI.form @@ -0,0 +1,118 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/spia/SostituzioneSempliceGUI.java b/src/GUI/spia/SostituzioneSempliceGUI.java new file mode 100644 index 0000000..5207faf --- /dev/null +++ b/src/GUI/spia/SostituzioneSempliceGUI.java @@ -0,0 +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 +} diff --git a/src/GUI/user/ApriMessaggioPrecedente.form b/src/GUI/user/ApriMessaggioPrecedente.form new file mode 100644 index 0000000..44de8b7 --- /dev/null +++ b/src/GUI/user/ApriMessaggioPrecedente.form @@ -0,0 +1,95 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/user/ApriMessaggioPrecedente.java b/src/GUI/user/ApriMessaggioPrecedente.java new file mode 100644 index 0000000..e3a8cb3 --- /dev/null +++ b/src/GUI/user/ApriMessaggioPrecedente.java @@ -0,0 +1,139 @@ +/* + * 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 { + Studente s; + /** + * Creates new form ApriMessaggioPrecedente + */ + public ApriMessaggioPrecedente(Studente s) { + this.s = 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(431, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .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()) + ); + 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.RELATED) + .addComponent(jButton1) + .addContainerGap(12, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + Messaggio m = (Messaggio)jList1.getSelectedValue(); + System.out.println(this.s.getId()); + new NuovoMessaggio(this.s, 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 new file mode 100644 index 0000000..048b8f4 --- /dev/null +++ b/src/GUI/user/DettagliMessaggio.form @@ -0,0 +1,93 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/GUI/user/DettagliMessaggio.java b/src/GUI/user/DettagliMessaggio.java new file mode 100644 index 0000000..f29a608 --- /dev/null +++ b/src/GUI/user/DettagliMessaggio.java @@ -0,0 +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)"); + 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/view/LeggiMessaggi.form b/src/GUI/user/LeggiMessaggi.form similarity index 78% rename from src/view/LeggiMessaggi.form rename to src/GUI/user/LeggiMessaggi.form index d9ffa53..f538da0 100644 --- a/src/view/LeggiMessaggi.form +++ b/src/GUI/user/LeggiMessaggi.form @@ -1,76 +1,91 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/view/LeggiMessaggi.java b/src/GUI/user/LeggiMessaggi.java similarity index 60% rename from src/view/LeggiMessaggi.java rename to src/GUI/user/LeggiMessaggi.java index d2d7b97..fdf3df5 100644 --- a/src/view/LeggiMessaggi.java +++ b/src/GUI/user/LeggiMessaggi.java @@ -1,114 +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 view; - -import model.Messaggio; -import model.MessaggioDestinatario; - -/** - * - * @author MASTER - */ -public class LeggiMessaggi extends javax.swing.JFrame { - - /** - * Creates new form LeggiMessaggi - */ - public LeggiMessaggi() { - initComponents(); - MessaggioDestinatario[] l = Messaggio.caricaRicevuti(); - 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(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jLabel1.setText("Hai tot messaggi da leggere"); - - jScrollPane1.setViewportView(jList1); - - 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)) - ); - 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) - .addContainerGap(135, Short.MAX_VALUE)) - ); - - 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; - 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.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 +} diff --git a/src/view/NuoveProposte.form b/src/GUI/user/NuoveProposte.form similarity index 98% rename from src/view/NuoveProposte.form rename to src/GUI/user/NuoveProposte.form index 4f1abf8..0783192 100644 --- a/src/view/NuoveProposte.form +++ b/src/GUI/user/NuoveProposte.form @@ -61,7 +61,7 @@ - +
diff --git a/src/view/NuoveProposte.java b/src/GUI/user/NuoveProposte.java similarity index 93% rename from src/view/NuoveProposte.java rename to src/GUI/user/NuoveProposte.java index 2090899..742a905 100644 --- a/src/view/NuoveProposte.java +++ b/src/GUI/user/NuoveProposte.java @@ -1,166 +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 view; - -import model.Proposta; -/*import Clmodelession; -import ClasmodelrInfo;*/ -import controller.CommunicationController; -import model.Session; - -/** - * - * @author MASTER - */ -public class NuoveProposte extends javax.swing.JFrame { - - /** - * Creates new form PropostePendenti - */ - public NuoveProposte(Proposta[] p) { - initComponents(); - jList1.setListData(p); - } - - /** - * 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.DEFAULT_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(Session.getIdLoggedUser()); - 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(Session.getIdLoggedUser()); - 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); - } - }); - } - - // 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.EXIT_ON_CLOSE); + + jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N + jLabel1.setText("Ciao hai delle nuove proposte"); + 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.DEFAULT_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/view/NuovoMessaggio.form b/src/GUI/user/NuovoMessaggio.form similarity index 76% rename from src/view/NuovoMessaggio.form rename to src/GUI/user/NuovoMessaggio.form index d01ce62..12c6752 100644 --- a/src/view/NuovoMessaggio.form +++ b/src/GUI/user/NuovoMessaggio.form @@ -26,7 +26,7 @@ - + @@ -46,16 +46,17 @@ + + + + + + - - - - -
@@ -81,11 +82,16 @@ - - - - - + + + + + + + + + + @@ -125,6 +131,9 @@ + + + @@ -140,7 +149,7 @@ - + @@ -150,5 +159,21 @@ + + + + + + + + + + + + + + + + diff --git a/src/view/NuovoMessaggio.java b/src/GUI/user/NuovoMessaggio.java similarity index 54% rename from src/view/NuovoMessaggio.java rename to src/GUI/user/NuovoMessaggio.java index c0ddc1d..076f3c4 100644 --- a/src/view/NuovoMessaggio.java +++ b/src/GUI/user/NuovoMessaggio.java @@ -1,218 +1,277 @@ -/* - * 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; - -import controller.CommunicationController; -import model.*; -import controller.Controller; - -/** - * - * @author MASTER - */ -public class NuovoMessaggio extends javax.swing.JFrame { - private PropostaConfermata[] a = CommunicationController.getProposteAccettate(Session.getIdLoggedUser()); - private int index; - private Messaggio m = new Messaggio(); - /** - * Creates new form NuovoMessaggio - */ - public NuovoMessaggio() { - initComponents(); - m.setMittente(new UserInfo(Session.getIdLoggedUser())); - //a = CommunicationController.getProposteAccettate(Session.getIdLoggedUser()); - int[] id_list = new int[a.length]; - for(int i=0; i//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(); - - 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); - } - }); - - 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); - } - }); - - 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() - .addContainerGap(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) - .addComponent(jButton1, 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().setVisible(true); - }//GEN-LAST:event_jButton2ActionPerformed - - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - // TODO add your handling code here: - m.setTesto(jTextField1.getText()); - m.cifra(); //cifra il messaggio - CommunicationController.send(m); //invio del messaggio - - }//GEN-LAST:event_jButton1ActionPerformed - - private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed - // TODO add your handling code here: - index = jComboBox1.getSelectedIndex(); - m.setDestinatario(new UserInfo(a[index-1].getPartner().getId())); - m.setSdc(a[index-1].getSdc()); - System.out.println(m.getSdc()); - - }//GEN-LAST:event_jComboBox1ActionPerformed - - private void jComboBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox3ActionPerformed - // TODO add your handling code here: - //System.out.println((String)jComboBox1.getSelectedItem()); - m.setLingua((String)jComboBox3.getSelectedItem()); - }//GEN-LAST:event_jComboBox3ActionPerformed - - /** - * @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(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; - 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(); + 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; + + + + int[] id_list = new int[proposte.length]; + for (int i = 0; i < id_list.length; i++) { + jComboBox1.addItem("Invia messaggio a " + 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(); + jButton4 = 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[] { "Non specificata", "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); + } + }); + + 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( + 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(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()) + ); + 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(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(); + }// //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 + //il messaggio non viene inviato ma è salvato come bozza, in modo da + //essere poi completato in un secondo momento + int languageIndex = jComboBox1.getSelectedIndex(); //indice del destinatario selezionato nella combobox + + 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.save(); + if (restore != null ) + CommunicationController.removeBozza(restore); + + 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 + + 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; + 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/view/PropostaSistemaDiCifratura.form b/src/GUI/user/PropostaSistemaDiCifratura.form similarity index 76% rename from src/view/PropostaSistemaDiCifratura.form rename to src/GUI/user/PropostaSistemaDiCifratura.form index ddab108..987e5aa 100644 --- a/src/view/PropostaSistemaDiCifratura.form +++ b/src/GUI/user/PropostaSistemaDiCifratura.form @@ -35,32 +35,43 @@ + - - - - - + + + - + + + + - + - - + + + - + - - + + + + + + + + + + @@ -88,8 +99,12 @@ + + + + - + @@ -146,7 +161,7 @@ - + @@ -154,5 +169,12 @@ + + + + + + + diff --git a/src/view/PropostaSistemaDiCifratura.java b/src/GUI/user/PropostaSistemaDiCifratura.java similarity index 68% rename from src/view/PropostaSistemaDiCifratura.java rename to src/GUI/user/PropostaSistemaDiCifratura.java index bf86d1f..e09928e 100644 --- a/src/view/PropostaSistemaDiCifratura.java +++ b/src/GUI/user/PropostaSistemaDiCifratura.java @@ -1,232 +1,227 @@ -/* - * 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; - -import model.Session; -//import ClmodelserInfo; -//import Clasmodeldente; -import controller.CommunicationController; -import controller.Controller; -//import Controviewoller; -import java.util.Vector; -import javax.swing.ListModel; -import model.Proposta; -import model.SistemaCifratura; -import model.Studente; - -/** - * - * @author MASTER - */ -public class PropostaSistemaDiCifratura extends javax.swing.JFrame { - private Proposta p; - /** - * Creates new form NuovoMessaggio - */ - public PropostaSistemaDiCifratura() { - initComponents(); - Studente[] s = Controller.recuperaUtenti(); - jList2.setListData(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 - // 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(Session.getIdLoggedUser(), ((Studente)jList2.getSelectedValue()).getId(), s); - 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 - - /** - * @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); - } - }); - } - - // 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(); + jLabel4 = new javax.swing.JLabel(); + jLabel5 = new javax.swing.JLabel(); + + 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); + } + }); + + 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(633, 633, 633) + .addComponent(jLabel4)) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel2) + .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(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) + .addComponent(jComboBox1, 0, 213, Short.MAX_VALUE) + .addComponent(jTextField1)))) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .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) + .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(jLabel4) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE) + .addComponent(jLabel5) + .addGap(32, 32, 32) + .addComponent(jButton2) + .addGap(14, 14, 14)) + ); + + 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 + 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 ); + + 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.JLabel jLabel4; + private javax.swing.JLabel jLabel5; + 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/view/Registrazione.form b/src/GUI/user/Registrazione.form similarity index 98% rename from src/view/Registrazione.form rename to src/GUI/user/Registrazione.form index f6322ad..57c410d 100644 --- a/src/view/Registrazione.form +++ b/src/GUI/user/Registrazione.form @@ -1,125 +1,125 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/view/Registrazione.java b/src/GUI/user/Registrazione.java similarity index 96% rename from src/view/Registrazione.java rename to src/GUI/user/Registrazione.java index f371146..9892c2b 100644 --- a/src/view/Registrazione.java +++ b/src/GUI/user/Registrazione.java @@ -4,9 +4,8 @@ * and open the template in the editor. */ -package view; +package GUI.user; -import controller.Controller; import model.Studente; /** @@ -129,7 +128,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/view/Utente_Regolamentare.form b/src/GUI/user/Utente_Regolamentare.form similarity index 98% rename from src/view/Utente_Regolamentare.form rename to src/GUI/user/Utente_Regolamentare.form index 6ceb0bb..6c587a2 100644 --- a/src/view/Utente_Regolamentare.form +++ b/src/GUI/user/Utente_Regolamentare.form @@ -1,77 +1,77 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/view/Utente_Regolamentare.java b/src/GUI/user/Utente_Regolamentare.java similarity index 65% rename from src/view/Utente_Regolamentare.java rename to src/GUI/user/Utente_Regolamentare.java index 0ff252f..c1319ce 100644 --- a/src/view/Utente_Regolamentare.java +++ b/src/GUI/user/Utente_Regolamentare.java @@ -1,161 +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 view; - -import model.Proposta; -/*import Clmodelession; -import ClasmodelrInfo;*/ -import controller.CommunicationController; -import java.awt.List; -import model.Messaggio; -import model.MessaggioDestinatario; -import model.Session; - -/** - * - * @author MASTER - */ -public class Utente_Regolamentare extends javax.swing.JFrame { - - /** - * Creates new form Mittente - */ - public Utente_Regolamentare() { - initComponents(); - /*try{ - Thread.sleep(1000); - } - catch(Exception e){}*/ - Proposta[] p = CommunicationController.getProposte(Session.getIdLoggedUser()); - if(p.length > 0){ - NuoveProposte n = new NuoveProposte(p); - n.setVisible(true); - } - - MessaggioDestinatario[] l = Messaggio.caricaRicevuti(); - 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().setVisible(true); - }//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 - - private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed - // TODO add your handling code here: - new LeggiMessaggi().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); - } - }); - } - - // 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.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 +} diff --git a/src/controller/CommunicationController.java b/src/controller/CommunicationController.java index f01ba26..93675c8 100644 --- a/src/controller/CommunicationController.java +++ b/src/controller/CommunicationController.java @@ -7,17 +7,14 @@ 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.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; @@ -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 ); @@ -56,21 +53,10 @@ 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 { - 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 +97,10 @@ public static boolean send(Messaggio m){ } public Messaggio apriMessaggioRicevuto(int id){ - return new Messaggio(); + return null; + } + public static boolean removeBozza(Messaggio m){ + return m.elimina(); } } diff --git a/src/controller/Controller.java b/src/controller/Controller.java index 13af619..ca8bd33 100644 --- a/src/controller/Controller.java +++ b/src/controller/Controller.java @@ -5,22 +5,14 @@ */ package controller; -import model.Proposta; -//import Clmodelession; -//import Clasmodeldente; -//import Classemodelnfo; import db.DbManager; -import db.DbManager0; import db.Query; import db.QueryResult; import java.sql.SQLException; import java.util.ArrayList; -import java.util.Vector; -import model.PropostaConfermata; -import model.Session; -import model.SistemaCifratura; import model.Studente; import model.UserInfo; +import model.user.Proposta; /** * * @author MASTER @@ -53,7 +45,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 +62,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(); } @@ -99,21 +91,21 @@ public static boolean rifiutaProposta(Proposta p){ - public static Studente[] recuperaUtenti(){ - ArrayList result = new ArrayList<>(); + public static UserInfo[] recuperaUtenti( Studente s ){ + ArrayList result = new ArrayList<>(); try{ - DbManager0 db = DbManager0.getInstance(); - Query q = db.createQuery("SELECT * FROM user where username <> '" + Session.getLoggedUser() + "'"); + DbManager db = DbManager.getInstance(); + Query q = db.createQuery("SELECT * FROM user where username <> '" + s.getId() + "'"); QueryResult rs = db.execute( q ); 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/db/DbManager.java b/src/db/DbManager.java index b236d0b..a7091a4 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 = "root"; // Nome utente utilizzato per la connessione al Database - private String pwdUtente = "root"; // 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 = "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 { -// 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 void executeUpdate( Query q ) throws SQLException { + q.executeUpdate(); + } + +} diff --git a/src/db/DbManager0.java b/src/db/DbManager0.java deleted file mode 100644 index 1c84b15..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 = "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 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/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/CalcolatoreParolaChiave.java b/src/model/CalcolatoreParolaChiave.java deleted file mode 100644 index 8c74c35..0000000 --- a/src/model/CalcolatoreParolaChiave.java +++ /dev/null @@ -1,25 +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 CalcolatoreParolaChiave implements CalcolatoreMappatura{ - - /*private String c; - - public CalcolatoreParolaChiave(String c){ - this.c = c; - }*/ - - public Mappatura calcola(String s){ - String ris; - return new Mappatura(); - } -} diff --git a/src/model/CalcolatorePseudocasuale.java b/src/model/CalcolatorePseudocasuale.java deleted file mode 100644 index 8772b3e..0000000 --- a/src/model/CalcolatorePseudocasuale.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -package model; - -/** - * - * @author MASTER - */ -public class CalcolatorePseudocasuale implements CalcolatoreMappatura{ - - /*private String chiave; - - - public CalcolatorePseudocasuale(String c){ - this.chiave = c; - }*/ - - public Mappatura calcola(String s){ - String ris; - return new Mappatura(); - } -} diff --git a/src/model/Messaggio.java b/src/model/Messaggio.java index 4e813b9..8315846 100644 --- a/src/model/Messaggio.java +++ b/src/model/Messaggio.java @@ -3,176 +3,268 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ - package model; -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.ArrayList; -import java.util.Vector; +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 { + private int id; private UserInfo mittente, destinatario; private SistemaCifratura sdc; 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){ + + public Messaggio(String testo, String lingua, UserInfo mittente, UserInfo destinatario) { this.testo = testo; this.lingua = lingua; this.mittente = mittente; this.destinatario = destinatario; } - - public Messaggio(String testo, String lingua, UserInfo mittente, UserInfo destinatario, SistemaCifratura sdc){ + + public Messaggio(String testo, String lingua, UserInfo mittente, UserInfo destinatario, SistemaCifratura sdc) { this.testo = testo; this.lingua = lingua; this.mittente = mittente; this.destinatario = destinatario; this.sdc = sdc; } - - public void setLingua(String l){ + + public void setLingua(String l) { this.lingua = l; } - - public void setTesto(String text){ + + public void setTesto(String text) { this.testo = text; } - - public void setDestinatario(UserInfo d){ + + public void setDestinatario(UserInfo d) { this.destinatario = d; } - - public void setMittente(UserInfo m){ + + public void setMittente(UserInfo m) { this.mittente = m; } - - public SistemaCifratura getSdc(){ + + public SistemaCifratura getSdc() { return this.sdc; } - - public void setSdc(SistemaCifratura s){ + + 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]); + + public static List caricaIniviati(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); } - //return v; + } catch (SQLException ex) { + throw new RuntimeException(ex.getMessage(), ex); } - }//carica il messaggio*/ - - public static List caricaIniviati(Studente s){ - return new List(); + return result.toArray(new Messaggio[result.size()]); } - - public static List caricaBozze(Studente s){ - return new List(); + + 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(){ + + public static MessaggioDestinatario[] caricaRicevuti(Studente s) { ArrayList result = new ArrayList<>(); - try{ - DbManager0 db = DbManager0.getInstance(); - Query q = db.createQuery("SELECT * FROM `cryptohelper`.`messaggio` WHERE id_destinatario = " + Session.getIdLoggedUser()); + try { + DbManager db = DbManager.getInstance(); + 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()] ); - /*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; - }*/ + 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(){ - //SistemaCifratura.load(this.mittente, this.destinatario); - this.sdc.calcolaMappatura(); //sdc ha ora un oggetto mappatura - this.testoCifrato = Cifratore.cifra(this.testo, this.sdc.getMappatura()); + + public void cifra() { + this.getSdc().calcolaMappatura(); //sdc ha ora un oggetto mappatura + this.testoCifrato = Cifratore.cifra(this.getTesto(), this.getSdc().getMappatura()); } - - public boolean isBozza(){ - return true; + + public boolean isBozza() { + return this.bozza; } - - 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{ - DbManager0 db = DbManager0.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);"); + + 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() + ");"); 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; } - - 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; + + private String toStringF = "Messaggio in lingua: %lingua% inviato da %mittente%, per %destinatarioID%: %testo%"; + + public String setToStringF(String f) { + String result = getToStringF(); + this.toStringF = f; + return result; + } + + public String toString() { + String result = getToStringF(); + result = result.replaceAll("%lingua%", getLingua()); + result = result.replaceAll("%mittente%", getMittente().toString()); + result = result.replaceAll("%destinatarioID%", getDestinatario().toString()); + result = result.replaceAll("%testo%", getTesto()); + result = result.replaceAll("%testoCif%", getTestoCifrato()); + 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; + } + + } + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @return the mittente + */ + public UserInfo getMittente() { + return this.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 toStringF + */ + public String getToStringF() { + return toStringF; + } + + private void setId(int id) { + this.id = id; } - + } 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/MessaggioDestinatario.java b/src/model/MessaggioDestinatario.java index 089e08e..b74ed04 100644 --- a/src/model/MessaggioDestinatario.java +++ b/src/model/MessaggioDestinatario.java @@ -10,6 +10,8 @@ * * @author MASTER */ -public interface MessaggioDestinatario { +public interface MessaggioDestinatario extends MessaggioAstratto { public boolean isLetto(); + + public UserInfo getMittente(); } 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/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/Studente.java b/src/model/Studente.java index aadec76..547ffc0 100644 --- a/src/model/Studente.java +++ b/src/model/Studente.java @@ -8,33 +8,27 @@ //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; /** * * @author MASTER */ public class Studente { + private String nome; private String cognome; private String id; private String login; private String pwd; - private DbManager0 DbManager0; + private DbManager DbManager0; 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; @@ -43,34 +37,32 @@ 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; } 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{ - DbManager0 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")+""; - return true; + 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);")) { @@ -81,8 +73,8 @@ public boolean registra(){ // Ora chiudo la connessione col Database: db.disconnetti();*/ try{ - DbManager0 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){ @@ -96,6 +88,42 @@ 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/UserInfo.java b/src/model/UserInfo.java index 8f3bbbb..ed5c6a1 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,13 +31,13 @@ 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(); 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 ); @@ -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/AnalisiFrequenze.java b/src/model/spia/AnalisiFrequenze.java new file mode 100644 index 0000000..fbacc33 --- /dev/null +++ b/src/model/spia/AnalisiFrequenze.java @@ -0,0 +1,49 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package 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 new file mode 100644 index 0000000..e1b0029 --- /dev/null +++ b/src/model/spia/Ipotesi.java @@ -0,0 +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; + } + +} diff --git a/src/model/spia/RipristinaIpotesiPrecedente.java b/src/model/spia/RipristinaIpotesiPrecedente.java new file mode 100644 index 0000000..1e3861a --- /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 new file mode 100644 index 0000000..29c1e2b --- /dev/null +++ b/src/model/spia/Sessione.java @@ -0,0 +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; + } + + } +} diff --git a/src/model/spia/SostituzioneSemplice.java b/src/model/spia/SostituzioneSemplice.java new file mode 100644 index 0000000..91c186d --- /dev/null +++ b/src/model/spia/SostituzioneSemplice.java @@ -0,0 +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(); + } + +} diff --git a/src/model/spia/Spia.java b/src/model/spia/Spia.java new file mode 100644 index 0000000..0e35a32 --- /dev/null +++ b/src/model/spia/Spia.java @@ -0,0 +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 ); + } + } + +} diff --git a/src/model/spia/StrumentoDiManipolazione.java b/src/model/spia/StrumentoDiManipolazione.java new file mode 100644 index 0000000..d915259 --- /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/StrumentoDiSupporto.java b/src/model/spia/StrumentoDiSupporto.java new file mode 100644 index 0000000..259b0eb --- /dev/null +++ b/src/model/spia/StrumentoDiSupporto.java @@ -0,0 +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(); +} diff --git a/src/model/CalcolatoreCesare.java b/src/model/user/CalcolatoreCesare.java similarity index 65% rename from src/model/CalcolatoreCesare.java rename to src/model/user/CalcolatoreCesare.java index f4b4bf0..bfb6643 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; /** * @@ -18,8 +18,9 @@ public class CalcolatoreCesare implements CalcolatoreMappatura { }*/ public Mappatura calcola(String c){ - Mappatura m = new Mappatura(); - m.map(c); - return m; + int chiave = Integer.parseInt(c); + for(int i=0; i lettere minuscole dalla z alla a) + for (int i = 0; i