diff --git a/java/src/Database/ConnessioneDatabase.java b/java/src/Database/ConnessioneDatabase.java index 5027bb14..e825297d 100644 --- a/java/src/Database/ConnessioneDatabase.java +++ b/java/src/Database/ConnessioneDatabase.java @@ -38,4 +38,5 @@ public static ConnessioneDatabase getInstance() throws SQLException { } return instance; } + } diff --git a/java/src/GUI/CercaCorso.java b/java/src/GUI/CercaCorso.java new file mode 100644 index 00000000..916e9af9 --- /dev/null +++ b/java/src/GUI/CercaCorso.java @@ -0,0 +1,161 @@ +package GUI; + +import java.awt.Color; +import java.awt.EventQueue; +import java.awt.Toolkit; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import javax.swing.DefaultComboBoxModel; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JEditorPane; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JTextField; +import javax.swing.JTextPane; +import javax.swing.border.EmptyBorder; +import javax.swing.border.EtchedBorder; +import javax.swing.border.MatteBorder; + +import controller.Controller; + +public class CercaCorso { + + private JFrame frame; + Controller controller; + + public CercaCorso(Controller c) { + controller = c; + initialize(); + frame.setVisible(true); + } + + + private void initialize() { + frame = new JFrame(); + frame.setTitle("Manabi"); + frame.setIconImage(Toolkit.getDefaultToolkit().getImage(VisualizzaTestDaCompilare.class.getResource("/Immagini/icona manabi.png"))); + frame.getContentPane().setBackground(Color.WHITE); + frame.setBounds(100, 100, 609, 599); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.getContentPane().setLayout(null); + String[] mat = controller.returnAllMat(); + String[] rs = controller.returnAllTestName(); + + int max = rs.length; + controller.caricaTest(rs[0]); + controller.caricaInsegnante(controller.t.creatoreTest); + + + String tempo = controller.t.tempo.toString(); + tempo = tempo.substring(11, 19); + + JTextPane txtpnSelezionaCorso = new JTextPane(); + txtpnSelezionaCorso.setText("Seleziona corso"); + txtpnSelezionaCorso.setEditable(false); + txtpnSelezionaCorso.setBounds(284, 11, 122, 20); + frame.getContentPane().add(txtpnSelezionaCorso); + + JComboBox comboMat = new JComboBox(); + comboMat.setBounds(10, 32, 198, 22); + frame.getContentPane().add(comboMat); + comboMat.setMaximumRowCount(mat.length); + comboMat.setModel(new DefaultComboBoxModel(mat)); + + + JComboBox comboBox = new JComboBox(); + + comboBox.setMaximumRowCount(max); + comboBox.setModel(new DefaultComboBoxModel(rs)); + comboBox.setBounds(284, 32, 299, 22); + frame.getContentPane().add(comboBox); + + JTextPane txtpnElencoDeiTest = new JTextPane(); + txtpnElencoDeiTest.setText("Seleziona materia:"); + txtpnElencoDeiTest.setEditable(false); + txtpnElencoDeiTest.setBounds(10, 11, 299, 20); + frame.getContentPane().add(txtpnElencoDeiTest); + + JTextPane textNomeTest = new JTextPane(); + textNomeTest.setEditable(false); + textNomeTest.setBorder(null); + textNomeTest.setText("Nome test: "+controller.t.nomeTest); + textNomeTest.setBounds(10, 84, 198, 43); + frame.getContentPane().add(textNomeTest); + + JTextPane txtpnTempo = new JTextPane(); + txtpnTempo.setText("Tempo: "+tempo); + txtpnTempo.setEditable(false); + txtpnTempo.setBounds(383, 84, 200, 20); + frame.getContentPane().add(txtpnTempo); + + JEditorPane editorDescrizione = new JEditorPane(); + editorDescrizione.setEditable(false); + editorDescrizione.setText(controller.t.descrizione); + editorDescrizione.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0))); + editorDescrizione.setBounds(10, 181, 573, 292); + frame.getContentPane().add(editorDescrizione); + + JTextPane textDesc = new JTextPane(); + textDesc.setText("Descrizione:"); + textDesc.setEditable(false); + textDesc.setBounds(10, 150, 82, 20); + frame.getContentPane().add(textDesc); + + JTextPane editorMateria = new JTextPane(); + editorMateria.setEditable(false); + editorMateria.setBorder(null); + editorMateria.setText("Autore: "+controller.i.cognome+" "+controller.i.nome); + editorMateria.setBounds(218, 84, 149, 43); + frame.getContentPane().add(editorMateria); + + JButton btnNewButton = new JButton("Indietro"); + btnNewButton.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + frame.setVisible(false); + } + }); + btnNewButton.setBounds(10, 526, 89, 23); + frame.getContentPane().add(btnNewButton); + + + JLabel lblNewLabel = new JLabel(""); + lblNewLabel.setIcon(new ImageIcon(VisualizzaTestInsegnante.class.getResource("/Immagini/SFONDO TUTTO.png"))); + lblNewLabel.setBounds(102, 0, 823, 602); + frame.getContentPane().add(lblNewLabel); + + comboBox.addMouseListener(new MouseAdapter() { + public void mouseEntered(MouseEvent e) { + int selected = 0; + selected = comboBox.getSelectedIndex(); + controller.caricaTest(rs[selected]); + + String tempo = controller.t.tempo.toString(); + tempo = tempo.substring(11, 19); textNomeTest.setText("Nome Test: "+controller.t.nomeTest); editorDescrizione.setText(controller.t.descrizione); + txtpnTempo.setText("Tempo: "+tempo); editorMateria.setText("Autore: "+controller.i.cognome+" "+controller.i.nome); } + }); + + comboBox.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + + int selected = 0; + selected = comboBox.getSelectedIndex(); + controller.caricaTest(rs[selected]); + + String tempo = controller.t.tempo.toString(); + tempo = tempo.substring(11, 19); + textNomeTest.setText("Nome Test: "+controller.t.nomeTest); editorDescrizione.setText(controller.t.descrizione); + txtpnTempo.setText("Tempo: "+tempo); editorMateria.setText("Autore: "+controller.i.cognome+" "+controller.i.nome); + + + } + }); + + } +} + diff --git a/java/src/GUI/CompilaTest.java b/java/src/GUI/CompilaTest.java index e6a01034..80bf437b 100644 --- a/java/src/GUI/CompilaTest.java +++ b/java/src/GUI/CompilaTest.java @@ -142,6 +142,7 @@ private void initialize() { Ttempo = new JTextField(); Ttempo.setText("Tempo rimanente: "+controller.t.tempo.getTime()); + Ttempo.setVisible(false); Ttempo.setEditable(false); Ttempo.setBounds(603, 11, 186, 20); frame.getContentPane().add(Ttempo); @@ -184,6 +185,7 @@ public void mouseClicked(MouseEvent e) { progresso--; frame.setVisible(false); TestCompletato next = new TestCompletato(controller); + return; } textDomanda.setText(controller.t.quesiti[progresso].domanda); @@ -237,6 +239,7 @@ public void mouseClicked(MouseEvent e) { progresso--; frame.setVisible(false); TestCompletato next = new TestCompletato(controller); + return; } textDomanda.setText(controller.t.quesiti[progresso].domanda); diff --git a/java/src/GUI/DBSettings.java b/java/src/GUI/DBSettings.java index 9697bfeb..b2713723 100644 --- a/java/src/GUI/DBSettings.java +++ b/java/src/GUI/DBSettings.java @@ -13,12 +13,16 @@ import java.sql.SQLException; import javax.swing.SwingConstants; +import java.awt.Toolkit; +import javax.swing.border.LineBorder; public class DBSettings { JFrame frame; - private JTextField textOutput; + private JTextPane textOutput; Controller controller; + private JTextField getUrl; + private JTextField getPass; public DBSettings(Controller c) { controller = c; @@ -28,6 +32,8 @@ public DBSettings(Controller c) { private void initialize() { frame = new JFrame(); + frame.setIconImage(Toolkit.getDefaultToolkit().getImage(DBSettings.class.getResource("/Immagini/icona manabi.png"))); + frame.setTitle("Manabi"); frame.getContentPane().setBackground(Color.WHITE); frame.setBounds(100, 100, 450, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); @@ -50,33 +56,28 @@ public void mouseClicked(MouseEvent e) { btnBack.setBounds(10, 227, 89, 23); frame.getContentPane().add(btnBack); - textOutput = new JTextField(); + textOutput = new JTextPane(); + textOutput.setBorder(new LineBorder(new Color(0, 0, 0))); textOutput.setToolTipText("Console di Output"); - textOutput.setHorizontalAlignment(SwingConstants.LEFT); + textOutput.setEditable(false); textOutput.setBounds(10, 73, 414, 130); frame.getContentPane().add(textOutput); - textOutput.setColumns(10); - - JButton nuovoDB = new JButton("Crea DB"); - nuovoDB.setToolTipText("Se la verifica fallisce, premere qui per la creazione di un nuovo Database."); - nuovoDB.setEnabled(false); - nuovoDB.setBounds(335, 227, 89, 23); - frame.getContentPane().add(nuovoDB); JButton btnNewButton = new JButton("Test connessione"); btnNewButton.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { + try { if(controller.checkConnection()) { - textOutput.setText("Connessione effettuata con successo.\nNome: "+controller.connessione.nome+"\nConnessione: "+controller.connessione.url+"\nDriver: "+controller.connessione.driver); + textOutput.setText("Connessione effettuata con successo.\r\nNome: "+controller.connessione.nome+"\r\nConnessione: "+controller.connessione.url+"\r\nDriver: "+controller.connessione.driver); } - else {textOutput.setText("Connessione al Database fallita. Clicca su 'Crea nuovo database' per creare un nuovo DB."); nuovoDB.setEnabled(false);} + else {textOutput.setText("Connessione al Database fallita.");} } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); @@ -88,12 +89,29 @@ public void mouseClicked(MouseEvent e) { btnNewButton.setBounds(20, 42, 138, 23); frame.getContentPane().add(btnNewButton); + getUrl = new JTextField(); + getUrl.setText("jdbc:postgresql://localhost:5432/Manabi"); + getUrl.setBounds(286, 11, 138, 20); + frame.getContentPane().add(getUrl); + getUrl.setColumns(10); - nuovoDB.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - } - }); + getPass = new JTextField(); + getPass.setText("admin"); + getPass.setColumns(10); + getPass.setBounds(286, 43, 138, 20); + frame.getContentPane().add(getPass); + + JTextPane txtpnInserisciUrl = new JTextPane(); + txtpnInserisciUrl.setEditable(false); + txtpnInserisciUrl.setText("Inserisci URL:"); + txtpnInserisciUrl.setBounds(181, 11, 77, 20); + frame.getContentPane().add(txtpnInserisciUrl); + + JTextPane txtpnInserisciPassword = new JTextPane(); + txtpnInserisciPassword.setEditable(false); + txtpnInserisciPassword.setText("Inserisci password:"); + txtpnInserisciPassword.setBounds(181, 42, 99, 20); + frame.getContentPane().add(txtpnInserisciPassword); } diff --git a/java/src/GUI/MenuInsegnante.java b/java/src/GUI/MenuInsegnante.java index 6fbcf514..25cd15f9 100644 --- a/java/src/GUI/MenuInsegnante.java +++ b/java/src/GUI/MenuInsegnante.java @@ -1,9 +1,7 @@ package GUI; -import java.awt.EventQueue; + import controller.*; -import modelli.Quesiti; -import modelli.Test; import javax.swing.JFrame; import javax.swing.JTextField; @@ -19,6 +17,7 @@ import java.awt.Toolkit; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; +import javax.swing.border.EmptyBorder; public class MenuInsegnante { @@ -29,8 +28,6 @@ public class MenuInsegnante { private JTextField txtCreaQuesito; private JTextField txtVisualizzaTest; private JTextField txtCorreggiTest; - private JTextField txtNonHaiCreato; - private JTextField txtNonHaiCreato_1; public MenuInsegnante(Controller c) { controller = c; @@ -65,6 +62,7 @@ private void initialize() { frame.getContentPane().add(txtCreaTest); txtBenvenuto = new JTextField(); + txtBenvenuto.setBorder(new EmptyBorder(0, 0, 0, 0)); txtBenvenuto.setBackground(Color.WHITE); txtBenvenuto.setEditable(false); txtBenvenuto.setText("Benvenuto, "+controller.i.username); @@ -92,6 +90,15 @@ public void mouseClicked(MouseEvent e) { frame.getContentPane().add(creaTest); JButton vediTest = new JButton(""); + vediTest.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + frame.setVisible(false); + @SuppressWarnings("unused") + VisualizzaTestInsegnante next = new VisualizzaTestInsegnante(controller); + + + } + }); vediTest.setBackground(new Color(255, 255, 102)); vediTest.setBorderPainted(false); vediTest.setIcon(new ImageIcon(MenuInsegnante.class.getResource("/Immagini/photo5778473851175418934.jpg"))); @@ -145,6 +152,14 @@ public void mouseClicked(MouseEvent e) { frame.getContentPane().add(logout); JButton apriSettings = new JButton(""); + apriSettings.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + @SuppressWarnings("unused") + UserSettings next = new UserSettings(controller, true); + } + }); + apriSettings.setBorder(new EmptyBorder(0, 0, 0, 0)); apriSettings.setContentAreaFilled(false); apriSettings.setBorderPainted(false); apriSettings.setIcon(new ImageIcon(MenuInsegnante.class.getResource("/Immagini/settings.png"))); @@ -183,27 +198,5 @@ public void mouseClicked(MouseEvent e) { txtCorreggiTest.setColumns(10); txtCorreggiTest.setBounds(473, 495, 149, 20); frame.getContentPane().add(txtCorreggiTest); - - txtNonHaiCreato = new JTextField(); - txtNonHaiCreato.setForeground(new Color(255, 99, 71)); - txtNonHaiCreato.setFont(new Font("Tahoma", Font.BOLD, 11)); - txtNonHaiCreato.setOpaque(false); - txtNonHaiCreato.setBorder(null); - txtNonHaiCreato.setEditable(false); - txtNonHaiCreato.setText("Non hai creato ancora nessun test! Prima di poterlo visualizzare devi crearne uno."); - txtNonHaiCreato.setBounds(139, 526, 471, 20); - frame.getContentPane().add(txtNonHaiCreato); - txtNonHaiCreato.setColumns(10); - - txtNonHaiCreato_1 = new JTextField(); - txtNonHaiCreato_1.setText("Non hai creato ancora nessun test! Prima di poter aggiungere quesiti devi crearlo."); - txtNonHaiCreato_1.setOpaque(false); - txtNonHaiCreato_1.setForeground(new Color(255, 99, 71)); - txtNonHaiCreato_1.setFont(new Font("Tahoma", Font.BOLD, 11)); - txtNonHaiCreato_1.setEditable(false); - txtNonHaiCreato_1.setColumns(10); - txtNonHaiCreato_1.setBorder(null); - txtNonHaiCreato_1.setBounds(139, 540, 471, 20); - frame.getContentPane().add(txtNonHaiCreato_1); } } \ No newline at end of file diff --git a/java/src/GUI/MenuStudente.java b/java/src/GUI/MenuStudente.java index 213104e0..e429d444 100644 --- a/java/src/GUI/MenuStudente.java +++ b/java/src/GUI/MenuStudente.java @@ -34,8 +34,8 @@ public class MenuStudente { private JTextField txtMettiPuntiSce; private JTextField txtUltimoTestSvolto; private JTextField txtBenvenuto; - private JTextField txtAggiornamiStudentecorrezione; private JTextField txtMettiUltimoTest; + private JLabel lblNewLabel; public MenuStudente(Controller c) { controller = c; @@ -66,6 +66,12 @@ private void initialize() { frmManabi.getContentPane().add(txtTotali); JButton btnElencoCorsiSeguiti = new JButton(""); + btnElencoCorsiSeguiti.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + VisualizaTestSvolti next = new VisualizaTestSvolti(controller); + } + }); btnElencoCorsiSeguiti.setIcon(new ImageIcon(MenuStudente.class.getResource("/Immagini/sfondi/studente1.png"))); btnElencoCorsiSeguiti.setFont(new Font("Candara", Font.PLAIN, 13)); btnElencoCorsiSeguiti.setBounds(472, 112, 141, 315); @@ -87,6 +93,7 @@ public void mouseClicked(MouseEvent e) { frmManabi.getContentPane().add(btnNewButton_4); txtPunti = new JTextField(); + txtPunti.setEditable(false); txtPunti.setBorder(null); txtPunti.setOpaque(false); txtPunti.setBackground(Color.WHITE); @@ -101,6 +108,13 @@ public void mouseClicked(MouseEvent e) { frmManabi.getContentPane().add(separator); JButton btnElencoCorsiSeguiti_1 = new JButton(""); + btnElencoCorsiSeguiti_1.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + @SuppressWarnings("unused") + UserSettings next = new UserSettings(controller, false); + } + }); btnElencoCorsiSeguiti_1.setIcon(new ImageIcon(MenuStudente.class.getResource("/Immagini/sfondi/studente4.png"))); btnElencoCorsiSeguiti_1.setFont(new Font("Candara", Font.PLAIN, 13)); btnElencoCorsiSeguiti_1.setBounds(321, 112, 141, 315); @@ -120,6 +134,7 @@ public void mouseClicked(MouseEvent e) { frmManabi.getContentPane().add(btnElencoCorsiSeguiti_1_1_1); JButton btnElencoCorsiSeguiti_1_1 = new JButton(""); + btnElencoCorsiSeguiti_1_1.setIgnoreRepaint(true); btnElencoCorsiSeguiti_1_1.setIcon(new ImageIcon(MenuStudente.class.getResource("/Immagini/sfondi/studente2.png"))); btnElencoCorsiSeguiti_1_1.setFont(new Font("Candara", Font.PLAIN, 13)); @@ -171,9 +186,9 @@ public void mouseClicked(MouseEvent e) { frmManabi.getContentPane().add(txtTestSvolti); txtMettiPuntiSce = new JTextField(); + txtMettiPuntiSce.setText(String.valueOf(controller.ottieniPunteggioStudente(controller.s.username))); txtMettiPuntiSce.setEditable(false); txtMettiPuntiSce.setHorizontalAlignment(SwingConstants.CENTER); - txtMettiPuntiSce.setText(String.valueOf(controller.ottieniPunteggioStudente(controller.s.username))); txtMettiPuntiSce.setBorder(null); txtMettiPuntiSce.setOpaque(false); txtMettiPuntiSce.setBounds(514, 505, 39, 39); @@ -205,23 +220,24 @@ public void mouseClicked(MouseEvent e) { txtBenvenuto.setForeground(new Color(112, 128, 144)); txtBenvenuto.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 13)); txtBenvenuto.setColumns(10); - txtBenvenuto.setBounds(440, 11, 182, 20); + txtBenvenuto.setBounds(226, 11, 182, 20); frmManabi.getContentPane().add(txtBenvenuto); - txtAggiornamiStudentecorrezione = new JTextField(); - txtAggiornamiStudentecorrezione.setText("AGGIORNAMI STUDENTE_CORREZIONE"); - txtAggiornamiStudentecorrezione.setBounds(226, 511, 236, 20); - frmManabi.getContentPane().add(txtAggiornamiStudentecorrezione); - txtAggiornamiStudentecorrezione.setColumns(10); - txtMettiUltimoTest = new JTextField(); + txtMettiUltimoTest.setEditable(false); txtMettiUltimoTest.setHorizontalAlignment(SwingConstants.CENTER); - txtMettiUltimoTest.setText("metti ultimo test svolto"); + txtMettiUltimoTest.setText(controller.ottieniUltimoTestSvolto(controller.s.username)); txtMettiUltimoTest.setBorder(null); txtMettiUltimoTest.setOpaque(false); txtMettiUltimoTest.setBounds(20, 449, 593, 20); frmManabi.getContentPane().add(txtMettiUltimoTest); txtMettiUltimoTest.setColumns(10); + + btnElencoCorsiSeguiti_1_1.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + CercaCorso next = new CercaCorso(controller); + } + }); } } \ No newline at end of file diff --git a/java/src/GUI/SimulaTest.java b/java/src/GUI/SimulaTest.java new file mode 100644 index 00000000..4b0cf56e --- /dev/null +++ b/java/src/GUI/SimulaTest.java @@ -0,0 +1,359 @@ +package GUI; + +import java.awt.Color; +import java.awt.EventQueue; +import java.awt.Font; +import java.awt.Toolkit; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JProgressBar; +import javax.swing.JRadioButton; +import javax.swing.JTextField; +import javax.swing.JTextPane; +import javax.swing.SwingConstants; +import javax.swing.border.EtchedBorder; + +import controller.*; +public class SimulaTest { + + private JFrame frame; + Controller controller; + private JTextPane textRispostaAperta; + int progresso = 0; + private JTextField warnNoRisp; + String[] rs; + private JTextField Ttempo; + boolean isIns; + + public SimulaTest(Controller c, boolean is) { + controller = c; + isIns = is; + controller.caricaQuesitiTest(controller.t.id); + initialize(); + frame.setVisible(true); + } + + + + private void initialize() { + frame = new JFrame(); + + int lunghezzaTest = controller.t.quesiti.length; + rs = controller.t.quesiti[progresso].risposte; + + rs = shuffle(rs); + + frame.getContentPane().setBackground(Color.WHITE); + frame.setAlwaysOnTop(true); + frame.setTitle("Manabi"); + frame.setResizable(false); + frame.setIconImage(Toolkit.getDefaultToolkit().getImage(CompilaTest.class.getResource("/Immagini/icona manabi.png"))); + frame.setBounds(100, 100, 840, 641); + frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + frame.getContentPane().setLayout(null); + + + + JProgressBar progressBar = new JProgressBar(); + progressBar.setMaximum(lunghezzaTest); + progressBar.setBounds(302, 568, 146, 14); + frame.getContentPane().add(progressBar); + + JButton Avanti = new JButton("Avanti"); + + Avanti.setBounds(725, 568, 89, 23); + frame.getContentPane().add(Avanti); + + + + JTextPane titoloTest = new JTextPane(); + titoloTest.setText(controller.t.nomeTest); + titoloTest.setEditable(false); + titoloTest.setBounds(10, 11, 192, 20); + frame.getContentPane().add(titoloTest); + + JTextPane textDomanda = new JTextPane(); + textDomanda.setText(controller.t.quesiti[progresso].domanda); + + textDomanda.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null)); + textDomanda.setBounds(20, 42, 769, 145); + frame.getContentPane().add(textDomanda); + + warnNoRisp = new JTextField(); + warnNoRisp.setBorder(null); + warnNoRisp.setFont(new Font("Tahoma", Font.PLAIN, 15)); + warnNoRisp.setText("Devi dare una risposta!"); + warnNoRisp.setForeground(Color.RED); + warnNoRisp.setBackground(Color.WHITE); + warnNoRisp.setEditable(false); + warnNoRisp.setBounds(20, 548, 272, 43); + frame.getContentPane().add(warnNoRisp); + warnNoRisp.setColumns(10); + warnNoRisp.setVisible(false); + + JRadioButton A = new JRadioButton("a"); + A.setVerticalAlignment(SwingConstants.TOP); + A.setFont(new Font("Tahoma", Font.PLAIN, 8)); + A.setBackground(Color.WHITE); + A.setBounds(232, 194, 308, 65); + frame.getContentPane().add(A); + + JRadioButton B = new JRadioButton("b"); + B.setVerticalAlignment(SwingConstants.TOP); + B.setFont(new Font("Tahoma", Font.PLAIN, 8)); + B.setBackground(Color.WHITE); + B.setBounds(232, 262, 308, 65); + frame.getContentPane().add(B); + + JRadioButton C = new JRadioButton("c"); + C.setVerticalAlignment(SwingConstants.TOP); + C.setFont(new Font("Tahoma", Font.PLAIN, 8)); + C.setBackground(Color.WHITE); + C.setBounds(232, 330, 308, 71); + frame.getContentPane().add(C); + + JRadioButton D = new JRadioButton("d"); + D.setVerticalAlignment(SwingConstants.TOP); + D.setFont(new Font("Tahoma", Font.PLAIN, 8)); + D.setBackground(Color.WHITE); + D.setBounds(232, 404, 308, 69); + frame.getContentPane().add(D); + + JRadioButton E = new JRadioButton("e"); + E.setVerticalAlignment(SwingConstants.TOP); + E.setFont(new Font("Tahoma", Font.PLAIN, 8)); + E.setBackground(Color.WHITE); + E.setBounds(232, 476, 308, 65); + frame.getContentPane().add(E); + + textRispostaAperta = new JTextPane(); + textRispostaAperta.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null)); + textRispostaAperta.setBounds(20, 284, 769, 262); + frame.getContentPane().add(textRispostaAperta); + + Ttempo = new JTextField(); + Ttempo.setText("Tempo rimanente: "+controller.t.tempo.getTime()); + Ttempo.setEditable(false); + Ttempo.setVisible(false); + Ttempo.setBounds(603, 11, 186, 20); + frame.getContentPane().add(Ttempo); + Ttempo.setColumns(10); + + + + + if(controller.t.quesiti[0].isOpen) { + A.setVisible(false); B.setVisible(false); C.setVisible(false); D.setVisible(false); E.setVisible(false); + textRispostaAperta.setVisible(true); + + } + else { + if(rs[0].equals("")) {A.setVisible(false);} else {A.setVisible(true); A.setText(rs[0]);} + if(rs[1].equals("")) {B.setVisible(false);} else {B.setVisible(true); B.setText(rs[1]);} + if(rs[2].equals("")) {C.setVisible(false);} else {B.setVisible(true); B.setText(rs[2]);} + if(rs[3].equals("")) {D.setVisible(false);} else {B.setVisible(true); B.setText(rs[3]);} + if(rs[4].equals("")) {E.setVisible(false);} else {B.setVisible(true); B.setText(rs[4]);} + + + if(A.isVisible()) + + textRispostaAperta.setVisible(false); + } + + + Avanti.addMouseListener(new MouseAdapter() { + + public void mouseClicked(MouseEvent e) { + + if(controller.t.quesiti[progresso].isOpen) { + progresso++; + + progressBar.setValue(progresso); + if(checkProgress(progresso, lunghezzaTest)) { + progresso--; + frame.setVisible(false); + if(isIns) + {VisualizzaTestInsegnante back = new VisualizzaTestInsegnante(controller);} + else { VisualizaTestSvolti back = new VisualizaTestSvolti(controller);} + return; + } + + textDomanda.setText(controller.t.quesiti[progresso].domanda); + if(controller.t.quesiti[progresso].isOpen) { + A.setVisible(false); B.setVisible(false); C.setVisible(false); D.setVisible(false); E.setVisible(false); + textRispostaAperta.setVisible(true);} + + else { + rs = controller.t.quesiti[progresso].risposte; + rs = shuffle(rs); + if(rs[0].equals("")) { A.setVisible(false); A.setText(rs[0]);} + else {A.setVisible(true); A.setText(rs[0]);} + if(rs[1].equals("")) {B.setVisible(false); B.setText(rs[1]);} + else {B.setVisible(true); B.setText(rs[1]);} + if(rs[2].equals("")) {C.setVisible(false); C.setText(rs[2]);} + else {C.setVisible(true); C.setText(rs[2]);} + if(rs[3].equals("")) {D.setVisible(false); D.setText(rs[3]);} + else {D.setVisible(true); D.setText(rs[3]);} + if(rs[4].equals("")) {E.setVisible(false); E.setText(rs[4]);} + else {E.setVisible(true); E.setText(rs[4]);} + textRispostaAperta.setVisible(false); + } + } + + else { + boolean a; + if(!(B.isSelected() || C.isSelected() || D.isSelected() || E.isSelected() || A.isSelected())) { + a = false; warnNoRisp.setVisible(true); + } + else { + a = true; warnNoRisp.setVisible(false); + } + + if(a) { + String risposta = ""; + + if(A.isSelected()) { risposta = A.getText();} + + else if(B.isSelected()) {risposta = B.getText();} + + else if(C.isSelected()) {risposta = C.getText();} + + else if(D.isSelected()) {risposta = D.getText();} + + else if(E.isSelected()) {risposta = E.getText();} + + + progresso++; + progressBar.setValue(progresso); + if(checkProgress(progresso, lunghezzaTest)) { + progresso--; + frame.setVisible(false); + if(isIns) + {VisualizzaTestInsegnante back = new VisualizzaTestInsegnante(controller);} + else { VisualizaTestSvolti back = new VisualizaTestSvolti(controller);} + return; + + } + textDomanda.setText(controller.t.quesiti[progresso].domanda); + + + if(controller.t.quesiti[progresso].isOpen) { + A.setVisible(false); B.setVisible(false); C.setVisible(false); D.setVisible(false); E.setVisible(false); + textRispostaAperta.setVisible(true);} + else { + A.setSelected(false); B.setSelected(false); C.setSelected(false); D.setSelected(false); E.setSelected(false); + rs = controller.t.quesiti[progresso].risposte; + rs = shuffle(rs); + if(rs[0].equals("")) { A.setVisible(false); A.setText(rs[0]);} + else {A.setVisible(true); A.setText(rs[0]);} + if(rs[1].equals("")) {B.setVisible(false); B.setText(rs[1]);} + else {B.setVisible(true); B.setText(rs[1]);} + if(rs[2].equals("")) {C.setVisible(false); C.setText(rs[2]);} + else {C.setVisible(true); C.setText(rs[2]);} + if(rs[3].equals("")) {D.setVisible(false); D.setText(rs[3]);} + else {D.setVisible(true); D.setText(rs[3]);} + if(rs[4].equals("")) {E.setVisible(false); E.setText(rs[4]);} + else {E.setVisible(true); E.setText(rs[4]);} + textRispostaAperta.setVisible(false); + } + + } + + } + + + } + }); + + A.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + B.setSelected(false); + C.setSelected(false); + D.setSelected(false); + E.setSelected(false); + } + }); + + B.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + A.setSelected(false); + C.setSelected(false); + D.setSelected(false); + E.setSelected(false); + } + }); + + C.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + B.setSelected(false); + A.setSelected(false); + D.setSelected(false); + E.setSelected(false); + } + }); + + D.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + B.setSelected(false); + C.setSelected(false); + A.setSelected(false); + E.setSelected(false); + } + }); + + E.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + B.setSelected(false); + C.setSelected(false); + D.setSelected(false); + A.setSelected(false); + } + }); + + frame.addFocusListener(new FocusAdapter() { + + public void focusGained(FocusEvent e) { + + } + }); + + } + + + + public boolean checkProgress(int progresso, int max) { + if(progresso == max) return true; + else return false; + } + + public String[] shuffle(String [] rs) { + + List shuffle = Arrays.asList(rs); + + Collections.shuffle(shuffle); + + shuffle.toArray(rs); + + for(int i = 0; i < rs.length; i++) { + if(rs[i] == null) rs[i] = ""; + } + + return rs; + + } + + +} diff --git a/java/src/GUI/UserSettings.java b/java/src/GUI/UserSettings.java new file mode 100644 index 00000000..58d049cc --- /dev/null +++ b/java/src/GUI/UserSettings.java @@ -0,0 +1,214 @@ +package GUI; + +import java.awt.EventQueue; + +import javax.swing.JFrame; + +import controller.Controller; +import java.awt.Toolkit; +import javax.swing.JTextField; +import javax.swing.JTextPane; +import java.awt.Color; +import javax.swing.JButton; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import javax.swing.JPasswordField; +import java.awt.Font; + +public class UserSettings { + + private JFrame frame; + Controller controller; + private JTextField txtNom; + private JTextField txtCon; + private JPasswordField passwordField; + private JPasswordField passwordField_1; + boolean isIns; + String oldUsername; + + public UserSettings(Controller c, boolean is) { + controller = c; + isIns = is; + initialize(); + frame.setVisible(true); + } + + private void initialize() { + frame = new JFrame(); + frame.getContentPane().setBackground(Color.WHITE); + frame.setIconImage(Toolkit.getDefaultToolkit().getImage(UserSettings.class.getResource("/Immagini/icona manabi.png"))); + frame.setTitle("Manabi"); + frame.setBounds(100, 100, 545, 289); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.getContentPane().setLayout(null); + + passwordField = new JPasswordField(); + passwordField.setBounds(133, 42, 223, 20); + frame.getContentPane().add(passwordField); + + passwordField_1 = new JPasswordField(); + passwordField_1.setBounds(133, 73, 223, 20); + frame.getContentPane().add(passwordField_1); + + + + JTextPane txtpnPasswordNonValida = new JTextPane(); + txtpnPasswordNonValida.setText("Le password deve essere pi\u00F9 lunga!"); + txtpnPasswordNonValida.setForeground(Color.RED); + txtpnPasswordNonValida.setVisible(false); + txtpnPasswordNonValida.setEditable(false); + txtpnPasswordNonValida.setBounds(366, 42, 140, 34); + frame.getContentPane().add(txtpnPasswordNonValida); + + JTextPane txtpnLePassowordNon = new JTextPane(); + txtpnLePassowordNon.setText("Le password non corrispondono!"); + txtpnLePassowordNon.setForeground(Color.RED); + txtpnLePassowordNon.setVisible(false); + txtpnLePassowordNon.setEditable(false); + txtpnLePassowordNon.setBounds(223, 205, 96, 34); + frame.getContentPane().add(txtpnLePassowordNon); + + JTextPane txtpnNomeNonValido = new JTextPane(); + txtpnNomeNonValido.setText("Nome non valido!"); + txtpnNomeNonValido.setForeground(Color.RED); + txtpnNomeNonValido.setVisible(false); + txtpnNomeNonValido.setEditable(false); + txtpnNomeNonValido.setBounds(366, 104, 140, 20); + frame.getContentPane().add(txtpnNomeNonValido); + + JTextPane txtpnCognomeNonValido = new JTextPane(); + txtpnCognomeNonValido.setText("Cognome non valido!"); + txtpnCognomeNonValido.setVisible(false); + txtpnCognomeNonValido.setForeground(Color.RED); + txtpnCognomeNonValido.setEditable(false); + txtpnCognomeNonValido.setBounds(366, 135, 140, 20); + frame.getContentPane().add(txtpnCognomeNonValido); + + txtNom = new JTextField(); + + txtNom.setColumns(10); + txtNom.setBounds(133, 104, 223, 20); + frame.getContentPane().add(txtNom); + + txtCon = new JTextField(); + + txtCon.setColumns(10); + txtCon.setBounds(133, 135, 223, 20); + frame.getContentPane().add(txtCon); + if(isIns) { + txtNom.setText(controller.i.nome); + txtCon.setText(controller.i.cognome); + + oldUsername = controller.i.username; + } + else { + txtNom.setText(controller.s.nome); + txtCon.setText(controller.s.cognome); + + oldUsername = controller.s.username; + } + + JTextPane txtpnNome = new JTextPane(); + txtpnNome.setText("Nome:"); + txtpnNome.setEditable(false); + txtpnNome.setBackground(Color.WHITE); + txtpnNome.setBounds(85, 104, 38, 20); + frame.getContentPane().add(txtpnNome); + + JTextPane txtpnCognome = new JTextPane(); + txtpnCognome.setText("Cognome:"); + txtpnCognome.setEditable(false); + txtpnCognome.setBackground(Color.WHITE); + txtpnCognome.setBounds(67, 135, 56, 20); + frame.getContentPane().add(txtpnCognome); + + JTextPane txtpnPassword = new JTextPane(); + txtpnPassword.setText("Password:"); + txtpnPassword.setEditable(false); + txtpnPassword.setBackground(Color.WHITE); + txtpnPassword.setBounds(59, 42, 64, 20); + frame.getContentPane().add(txtpnPassword); + + JTextPane txtpnConfermaPassword = new JTextPane(); + txtpnConfermaPassword.setFont(new Font("Tahoma", Font.PLAIN, 9)); + txtpnConfermaPassword.setText("Conferma password:"); + txtpnConfermaPassword.setEditable(false); + txtpnConfermaPassword.setBackground(Color.WHITE); + txtpnConfermaPassword.setBounds(37, 73, 96, 20); + frame.getContentPane().add(txtpnConfermaPassword); + + JButton btnNewButton = new JButton("Indietro"); + + btnNewButton.setBounds(10, 216, 89, 23); + frame.getContentPane().add(btnNewButton); + + JButton btnNewButton_1 = new JButton("Salva"); + btnNewButton_1.addMouseListener(new MouseAdapter() { + @SuppressWarnings("deprecation") + @Override + public void mouseClicked(MouseEvent e) { + boolean b, c, d, f; + String password, cpassword, nome, cognome; + + + password = passwordField.getText(); + + if(password.length() < 8 || password.length() > 25) {txtpnPasswordNonValida.setVisible(true); b = false;} + else {txtpnPasswordNonValida.setVisible(false); b = true;} + + + nome = txtNom.getText(); + if(nome.length() < 2) {txtpnNomeNonValido.setVisible(true); c = false;} + else {txtpnNomeNonValido.setVisible(false); c = true;} + + cognome = txtCon.getText(); + if(cognome.length() < 2) { txtpnCognomeNonValido.setVisible(true); d = false;} + else {txtpnCognomeNonValido.setVisible(false); d = true;} + + cpassword = passwordField_1.getText(); + + if(!password.equals(cpassword)) {txtpnLePassowordNon.setVisible(true); f = false;} + else {txtpnLePassowordNon.setVisible(false); f = true;} + + + if(b && c && d && f) + { + if(isIns) { + System.out.println("ESEGUO!"); + controller.aggiornaUtente(cpassword, nome, cognome, isIns, oldUsername); + controller.caricaInsegnante(controller.i.username); + + } + else { + controller.aggiornaUtente(cpassword, nome, cognome, isIns, oldUsername); + controller.caricaStudente(controller.s.username); + } + } + } + }); + + btnNewButton_1.setBounds(417, 216, 89, 23); + frame.getContentPane().add(btnNewButton_1); + + btnNewButton.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if(isIns) { + + frame.setVisible(false); + return; + } + else { + + frame.setVisible(false); + return; + } + } + + }); + + + + + } +} diff --git a/java/src/GUI/VisualizaTestSvolti.java b/java/src/GUI/VisualizaTestSvolti.java new file mode 100644 index 00000000..eefc880b --- /dev/null +++ b/java/src/GUI/VisualizaTestSvolti.java @@ -0,0 +1,193 @@ +package GUI; + +import java.awt.Color; +import java.awt.EventQueue; + +import javax.swing.JFrame; +import controller.*; +import java.awt.Toolkit; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import javax.swing.JTextPane; +import javax.swing.border.MatteBorder; +import javax.swing.DefaultComboBoxModel; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JEditorPane; +public class VisualizaTestSvolti { + + private JFrame frame; + Controller controller; + + public VisualizaTestSvolti(Controller c) { + controller = c; + initialize(); + frame.setVisible(true); + } + + private void initialize() { + frame = new JFrame(); + frame.setTitle("Manabi"); + frame.setIconImage(Toolkit.getDefaultToolkit().getImage(VisualizzaTestDaCompilare.class.getResource("/Immagini/icona manabi.png"))); + frame.getContentPane().setBackground(Color.WHITE); + frame.setBounds(100, 100, 609, 599); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.getContentPane().setLayout(null); + String[] rs = controller.returnAllTestName(controller.s.username); + + + JTextPane warn = new JTextPane(); + warn.setForeground(Color.RED); + warn.setText("Non hai svolto nessun test!"); + warn.setEditable(false); + warn.setVisible(false); + + + JTextPane txtpnIlPunteggio = new JTextPane(); + txtpnIlPunteggio.setEditable(false); + txtpnIlPunteggio.setText("Il punteggio \u00E8 parziale. Devi attendere che l'insegnante corregga le tue risposte"); + txtpnIlPunteggio.setVisible(false); + txtpnIlPunteggio.setBounds(109, 506, 362, 43); + frame.getContentPane().add(txtpnIlPunteggio); + + warn.setBounds(319, 47, 241, 20); + frame.getContentPane().add(warn); + + if(rs == null) { + warn.setVisible(true); + + } + int max = rs.length; + controller.caricaTest(rs[0]); + controller.caricaInsegnante(controller.t.creatoreTest); + + if(controller.checkAlreadySolved(controller.t.id, controller.s.username)) {txtpnIlPunteggio.setVisible(false);} + JTextPane textPunt = new JTextPane(); + textPunt.setText("Punteggio: "+String.valueOf(controller.ottieniVotoTest(controller.s.username, controller.t.id))); + textPunt.setBounds(377, 150, 151, 20); + frame.getContentPane().add(textPunt); + + String tempo = controller.t.tempo.toString(); + tempo = tempo.substring(11, 19); + + + JComboBox comboBox = new JComboBox(); + + comboBox.setMaximumRowCount(max); + comboBox.setModel(new DefaultComboBoxModel(rs)); + comboBox.setBounds(10, 47, 299, 22); + frame.getContentPane().add(comboBox); + + JTextPane txtpnElencoTestSvolti = new JTextPane(); + txtpnElencoTestSvolti.setText("Elenco dei test svolti: "); + txtpnElencoTestSvolti.setEditable(false); + txtpnElencoTestSvolti.setBounds(10, 11, 299, 20); + frame.getContentPane().add(txtpnElencoTestSvolti); + + JTextPane textNomeTest = new JTextPane(); + textNomeTest.setText("Nome test: "+controller.t.nomeTest); + textNomeTest.setEditable(false); + textNomeTest.setBounds(10, 96, 129, 20); + frame.getContentPane().add(textNomeTest); + + JTextPane txtpnAutore = new JTextPane(); + txtpnAutore.setText("Autore: "+controller.i.cognome+" "+controller.i.nome); + txtpnAutore.setEditable(false); + txtpnAutore.setBounds(227, 96, 140, 43); + frame.getContentPane().add(txtpnAutore); + + JTextPane txtpnTempo = new JTextPane(); + txtpnTempo.setText("Tempo: "+tempo); + txtpnTempo.setEditable(false); + txtpnTempo.setBounds(377, 96, 200, 20); + frame.getContentPane().add(txtpnTempo); + + JEditorPane editorDescrizione = new JEditorPane(); + editorDescrizione.setText(controller.t.descrizione); + editorDescrizione.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0))); + editorDescrizione.setEditable(false); + editorDescrizione.setBounds(10, 181, 573, 292); + frame.getContentPane().add(editorDescrizione); + + JTextPane textDesc = new JTextPane(); + textDesc.setText("Descrizione:"); + textDesc.setEditable(false); + textDesc.setBounds(10, 150, 82, 20); + frame.getContentPane().add(textDesc); + + JTextPane txtpnMateria = new JTextPane(); + txtpnMateria.setText("Materia: "+controller.t.materia); + txtpnMateria.setEditable(false); + txtpnMateria.setBounds(227, 150, 120, 20); + frame.getContentPane().add(txtpnMateria); + + JButton btnNewButton = new JButton("Indietro"); + btnNewButton.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + frame.setVisible(false); + } + }); + btnNewButton.setBounds(10, 526, 89, 23); + frame.getContentPane().add(btnNewButton); + + JButton btnSimula = new JButton("Simula"); + btnSimula.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + int selected = 0; + selected = comboBox.getSelectedIndex(); + controller.caricaTest(rs[selected]); + controller.caricaInsegnante(controller.t.creatoreTest); + + + + SimulaTest next = new SimulaTest(controller, false); + frame.setVisible(false); + } + }); + btnSimula.setBounds(494, 526, 89, 23); + frame.getContentPane().add(btnSimula); + + + + + comboBox.addMouseListener(new MouseAdapter() { + @Override + public void mouseEntered(MouseEvent e) { + int selected = 0; + + selected = comboBox.getSelectedIndex(); + controller.caricaTest(rs[selected]); + controller.caricaInsegnante(controller.t.creatoreTest); + String tempo = controller.t.tempo.toString(); + tempo = tempo.substring(11, 19); + textNomeTest.setText("Nome test: "+controller.t.nomeTest); editorDescrizione.setText(controller.t.descrizione); + txtpnAutore.setText("Autore: "+controller.i.cognome+" "+controller.i.nome); txtpnTempo.setText("Tempo: "+tempo); txtpnMateria.setText("Materia: "+controller.t.materia); + + } + }); + + comboBox.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + + int selected = 0; + selected = comboBox.getSelectedIndex(); + controller.caricaTest(rs[selected]); + controller.caricaInsegnante(controller.t.creatoreTest); + String tempo = controller.t.tempo.toString(); + tempo = tempo.substring(11, 19); + textNomeTest.setText("Nome test: "+controller.t.nomeTest); editorDescrizione.setText(controller.t.descrizione); + txtpnAutore.setText("Autore: "+controller.i.cognome+" "+controller.i.nome); txtpnTempo.setText("Tempo: "+tempo); txtpnMateria.setText("Materia: "+controller.t.materia); + + + } + }); + + } + +} diff --git a/java/src/GUI/VisualizzaTestCreati.java b/java/src/GUI/VisualizzaTestCreati.java index dd56e99b..6aefb1e4 100644 --- a/java/src/GUI/VisualizzaTestCreati.java +++ b/java/src/GUI/VisualizzaTestCreati.java @@ -1,20 +1,13 @@ package GUI; -import java.awt.EventQueue; - import javax.swing.JFrame; import controller.*; import javax.swing.JTextPane; import java.awt.Color; -import javax.swing.JList; import javax.swing.JComboBox; -import javax.swing.JTextField; import javax.swing.JButton; -import javax.swing.border.SoftBevelBorder; -import javax.swing.border.BevelBorder; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import javax.swing.AbstractListModel; import javax.swing.DefaultComboBoxModel; import java.awt.Toolkit; import java.awt.Font; @@ -34,6 +27,7 @@ public VisualizzaTestCreati(Controller c) { frame.setVisible(true); } + @SuppressWarnings({ "unchecked", "rawtypes" }) private void initialize() { String[] rs = controller.returnTestName(controller.i.username); int max = rs.length; @@ -79,11 +73,7 @@ public void mouseClicked(MouseEvent e) { frame.getContentPane().add(btnNewButton_2); btnNewButton_2.setVisible(false); - - /*if(CONTROLLA CONDIZIONE) { - txtpnNonPuoiCreare.setVisible(true); btnNewButton_2.setVisible(true); btnNewButton_2.setEnabled(true); txtpnSelezionaIlTest.setVisible(false); comboBox.setVisible(false); - }*/ - + JButton btnNewButton = new JButton("Modifica"); btnNewButton.setEnabled(false); @@ -95,6 +85,7 @@ public void mouseClicked(MouseEvent e) { @Override public void mouseClicked(MouseEvent e) { + @SuppressWarnings("unused") MenuInsegnante back = new MenuInsegnante(controller); frame.setVisible(false); diff --git a/java/src/GUI/VisualizzaTestDaCompilare.java b/java/src/GUI/VisualizzaTestDaCompilare.java index a37a30fc..4936c33a 100644 --- a/java/src/GUI/VisualizzaTestDaCompilare.java +++ b/java/src/GUI/VisualizzaTestDaCompilare.java @@ -1,6 +1,5 @@ package GUI; -import java.awt.EventQueue; import javax.swing.JFrame; import controller.*; @@ -13,10 +12,6 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.DefaultComboBoxModel; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; -import java.awt.event.MouseMotionAdapter; -import java.text.SimpleDateFormat; import java.awt.event.ItemListener; import java.awt.event.ItemEvent; import javax.swing.JCheckBox; @@ -114,6 +109,7 @@ private void initialize() { btnNewButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { + MenuStudente back = new MenuStudente(controller); frame.setVisible(false); } }); diff --git a/java/src/GUI/VisualizzaTestInsegnante.java b/java/src/GUI/VisualizzaTestInsegnante.java new file mode 100644 index 00000000..542c7041 --- /dev/null +++ b/java/src/GUI/VisualizzaTestInsegnante.java @@ -0,0 +1,231 @@ +package GUI; + +import java.awt.Color; +import java.awt.EventQueue; +import java.awt.Toolkit; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import javax.swing.DefaultComboBoxModel; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JEditorPane; +import javax.swing.JFrame; +import javax.swing.JTextPane; +import javax.swing.border.MatteBorder; + +import controller.Controller; +import javax.swing.JTextField; +import javax.swing.border.EmptyBorder; +import javax.swing.border.EtchedBorder; +import javax.swing.JLabel; +import javax.swing.ImageIcon; + +public class VisualizzaTestInsegnante { + + private JFrame frame; + Controller controller; + private JTextField txtID; + private JTextField txtNomeTest; + private JTextField txtMateria; + private JTextField warn; + + public VisualizzaTestInsegnante(Controller c) { + controller = c; + initialize(); + frame.setVisible(true); + } + + + private void initialize() { + frame = new JFrame(); + frame.setTitle("Manabi"); + frame.setIconImage(Toolkit.getDefaultToolkit().getImage(VisualizzaTestDaCompilare.class.getResource("/Immagini/icona manabi.png"))); + frame.getContentPane().setBackground(Color.WHITE); + frame.setBounds(100, 100, 609, 599); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.getContentPane().setLayout(null); + String[] rs = controller.returnAllTest(controller.i.username); + if(rs == null) { + System.out.println("No test"); + } + + int max = rs.length; + controller.caricaTest(rs[0]); + controller.caricaInsegnante(controller.t.creatoreTest); + + + String tempo = controller.t.tempo.toString(); + tempo = tempo.substring(11, 19); + + warn = new JTextField(); + warn.setBorder(new EmptyBorder(0, 0, 0, 0)); + warn.setForeground(Color.RED); + warn.setText("Il test non ha quesiti!"); + warn.setVisible(false); + warn.setEditable(false); + warn.setBounds(109, 527, 221, 20); + frame.getContentPane().add(warn); + warn.setColumns(10); + + + JComboBox comboBox = new JComboBox(); + + comboBox.setMaximumRowCount(max); + comboBox.setModel(new DefaultComboBoxModel(rs)); + comboBox.setBounds(10, 31, 299, 22); + frame.getContentPane().add(comboBox); + + JTextPane txtpnElencoDeiTest = new JTextPane(); + txtpnElencoDeiTest.setText("Elenco dei test creati: "); + txtpnElencoDeiTest.setEditable(false); + txtpnElencoDeiTest.setBounds(10, 11, 299, 20); + frame.getContentPane().add(txtpnElencoDeiTest); + + JTextPane textNomeTest = new JTextPane(); + textNomeTest.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null)); + textNomeTest.setText(controller.t.nomeTest); + textNomeTest.setBounds(10, 84, 198, 43); + frame.getContentPane().add(textNomeTest); + + JTextPane txtpnTempo = new JTextPane(); + txtpnTempo.setText("Tempo: "+tempo); + txtpnTempo.setEditable(false); + txtpnTempo.setBounds(377, 96, 200, 20); + frame.getContentPane().add(txtpnTempo); + + JEditorPane editorDescrizione = new JEditorPane(); + editorDescrizione.setText(controller.t.descrizione); + editorDescrizione.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0))); + editorDescrizione.setBounds(10, 181, 573, 292); + frame.getContentPane().add(editorDescrizione); + + JTextPane textDesc = new JTextPane(); + textDesc.setText("Descrizione:"); + textDesc.setEditable(false); + textDesc.setBounds(10, 150, 82, 20); + frame.getContentPane().add(textDesc); + + JTextPane editorMateria = new JTextPane(); + editorMateria.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null)); + editorMateria.setText(controller.t.descrizione); + editorMateria.setBounds(218, 84, 149, 43); + frame.getContentPane().add(editorMateria); + + JButton btnNewButton = new JButton("Indietro"); + btnNewButton.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + frame.setVisible(false); + MenuInsegnante back = new MenuInsegnante(controller); + } + }); + btnNewButton.setBounds(10, 526, 89, 23); + frame.getContentPane().add(btnNewButton); + + JButton btnNewButton_1 = new JButton("Modifica"); + btnNewButton_1.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + int selected = 0; + selected = comboBox.getSelectedIndex(); + + controller.t.nomeTest = textNomeTest.getText(); + controller.t.descrizione = editorDescrizione.getText(); + controller.t.materia = editorMateria.getText(); + + controller.updateTest(); + controller.caricaTest(rs[selected]); + + } + }); + btnNewButton_1.setBounds(494, 526, 89, 23); + frame.getContentPane().add(btnNewButton_1); + + txtID = new JTextField(); + txtID.setBorder(new EmptyBorder(0, 0, 0, 0)); + txtID.setBackground(Color.WHITE); + txtID.setText("Identificativo: "+controller.t.id); + txtID.setEditable(false); + txtID.setBounds(336, 32, 167, 20); + frame.getContentPane().add(txtID); + txtID.setColumns(10); + + JButton btnSimula = new JButton("Simula"); + btnSimula.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if(!controller.hasQ()) { + warn.setVisible(true); + } + else { + SimulaTest next = new SimulaTest(controller, true); + frame.setVisible(false); + } + + } + }); + btnSimula.setBounds(244, 484, 89, 23); + frame.getContentPane().add(btnSimula); + + txtNomeTest = new JTextField(); + txtNomeTest.setBackground(Color.WHITE); + txtNomeTest.setBorder(new EmptyBorder(0, 0, 0, 0)); + txtNomeTest.setEditable(false); + txtNomeTest.setText("Nome test: "); + txtNomeTest.setBounds(10, 64, 86, 20); + frame.getContentPane().add(txtNomeTest); + txtNomeTest.setColumns(10); + + txtMateria = new JTextField(); + txtMateria.setText("Materia:"); + txtMateria.setEditable(false); + txtMateria.setColumns(10); + txtMateria.setBorder(new EmptyBorder(0, 0, 0, 0)); + txtMateria.setBackground(Color.WHITE); + txtMateria.setBounds(218, 64, 86, 20); + frame.getContentPane().add(txtMateria); + + JLabel lblNewLabel = new JLabel(""); + lblNewLabel.setIcon(new ImageIcon(VisualizzaTestInsegnante.class.getResource("/Immagini/SFONDO TUTTO.png"))); + lblNewLabel.setBounds(102, 0, 823, 602); + frame.getContentPane().add(lblNewLabel); + + + + comboBox.addMouseListener(new MouseAdapter() { + public void mouseEntered(MouseEvent e) { + int selected = 0; + selected = comboBox.getSelectedIndex(); + controller.caricaTest(rs[selected]); + + String tempo = controller.t.tempo.toString(); + tempo = tempo.substring(11, 19); + txtID.setText("Identificativo: "+controller.t.id); + textNomeTest.setText(controller.t.nomeTest); editorDescrizione.setText(controller.t.descrizione); + txtpnTempo.setText("Tempo: "+tempo); editorMateria.setText(controller.t.materia); } + }); + + comboBox.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + + int selected = 0; + selected = comboBox.getSelectedIndex(); + controller.caricaTest(rs[selected]); + + String tempo = controller.t.tempo.toString(); + txtID.setText("Identificativo: "+controller.t.id); + tempo = tempo.substring(11, 19); + textNomeTest.setText(controller.t.nomeTest); editorDescrizione.setText(controller.t.descrizione); + txtpnTempo.setText("Tempo: "+tempo); editorMateria.setText(controller.t.materia); + + + } + }); + + + } +} diff --git a/java/src/PostgresDAO/InsegnanteDAO.java b/java/src/PostgresDAO/InsegnanteDAO.java index 4f446393..199dcd74 100644 --- a/java/src/PostgresDAO/InsegnanteDAO.java +++ b/java/src/PostgresDAO/InsegnanteDAO.java @@ -136,4 +136,44 @@ public void insertInsegnante(Insegnante i) { } + public void aggiornaUtente(String password, String nome, String cognome, boolean who, String oldusername) { + PreparedStatement update; + + + + if(who) { + try { + update = connessione.prepareStatement( + "UPDATE INSEGNANTE SET password_i = '"+password+"', nome = '"+nome+"', cognome = '"+cognome+"' WHERE username_i = '"+oldusername+"'"); + + update.executeUpdate(); + return; + + } + catch (SQLException e) { + + e.printStackTrace(); + return; + + } + } + else { + try { + update = connessione.prepareStatement( + "UPDATE STUDENTE SET password_s = '"+password+"', nome = '"+nome+"', cognome = '"+cognome+"' WHERE username_s = '"+oldusername+"'"); + + update.executeUpdate(); + return; + + } + catch (SQLException e) { + + e.printStackTrace(); + return; + + } + } + + } + } diff --git a/java/src/PostgresDAO/QuesitiDAO.java b/java/src/PostgresDAO/QuesitiDAO.java index c111a6f7..c73d834a 100644 --- a/java/src/PostgresDAO/QuesitiDAO.java +++ b/java/src/PostgresDAO/QuesitiDAO.java @@ -273,59 +273,4 @@ public boolean checkIfOpen(int id_q) { } - public int nQuizA(int id) { - PreparedStatement g; - int n = 0; - - try { - g = connessione.prepareStatement( - "select count(id_test) from quesito_aperto where id_test = "+id); - - ResultSet rs = g.executeQuery(); - while(rs.next()) { - n = rs.getInt("count"); - - - } - rs.close(); - return n; - - - } - catch (SQLException e) { - - e.printStackTrace(); - return 0; - - } - - } - - public int nQuizM(int id) { - PreparedStatement g; - int n = 0; - - try { - g = connessione.prepareStatement( - "select count(id_test) from quesito_multiplo where id_test = "+id); - - ResultSet rs = g.executeQuery(); - while(rs.next()) { - n = rs.getInt("count"); - - - } - rs.close(); - return n; - - - } - catch (SQLException e) { - - e.printStackTrace(); - return 0; - - } - - } } diff --git a/java/src/PostgresDAO/RispostaDAO.java b/java/src/PostgresDAO/RispostaDAO.java index 9d4394c1..659bef67 100644 --- a/java/src/PostgresDAO/RispostaDAO.java +++ b/java/src/PostgresDAO/RispostaDAO.java @@ -6,12 +6,12 @@ import java.sql.SQLException; import Database.ConnessioneDatabase; -import modelli.Risposta; + public class RispostaDAO { Connection connessione; - Risposta r; + public RispostaDAO() { try { diff --git a/java/src/PostgresDAO/TestDAO.java b/java/src/PostgresDAO/TestDAO.java index 05fbbc81..8d136ff3 100644 --- a/java/src/PostgresDAO/TestDAO.java +++ b/java/src/PostgresDAO/TestDAO.java @@ -237,7 +237,58 @@ public String[] returnCompTestName(String username) { } } + public String[] returnAllTest(String username) { + PreparedStatement g; + String[] t = new String[100]; + int i; + try { + g = connessione.prepareStatement( + "SELECT nome_test FROM TEST WHERE username_i = '"+username+"'"); + + ResultSet rs = g.executeQuery(); + for(i = 0; rs.next(); i++) { + t[i] = rs.getString("nome_test"); + + } + + String[] tmp = new String[i]; + for(int z = 0; z < i; z++) { + tmp[z] = t[z]; + } + + rs.close(); + return tmp; + + + } + catch (SQLException e) { + e.printStackTrace(); + return null; + + } + + } + + public void updateTest(int id, String nomeTest, String materia, String descrizione) { + PreparedStatement update; + + + try { + update = connessione.prepareStatement( + "UPDATE TEST SET nome_test = '"+nomeTest+"', materia_test = '"+materia+"', descrizione = '"+descrizione+"' WHERE id_test = "+id); + + update.executeUpdate(); + return; + + } + catch (SQLException e) { + + e.printStackTrace(); + return; + + } + } public Test returnTest(String nome_test, String username) { PreparedStatement g; @@ -365,6 +416,29 @@ public void aggiornaCorrezione(String username_i, String username_s, int id) { } + public boolean hasQ(int id) { + PreparedStatement g; + + + try { + + g = connessione.prepareStatement( + "SELECT id_test FROM test WHERE id_test = "+id+" AND id_test IN (SELECT id_test FROM QUESITO_MULTIPLO WHERE id_test = "+id+") OR id_test IN (SELECT id_test FROM QUESITO_APERTO WHERE id_test = "+id+")"); + + ResultSet rs = g.executeQuery(); + + if(rs.next()) return true; + else return false; + } + catch (SQLException e) { + + e.printStackTrace(); + return false; + + } + + } + public boolean checkAlreadySolved(int id, String username) { PreparedStatement g; int check = 0; @@ -388,4 +462,190 @@ public boolean checkAlreadySolved(int id, String username) { } } + + public String[] returnAllTestName(String username) { + PreparedStatement g; + int i; + int[] id = new int[100]; + + + try { + + g = connessione.prepareStatement("SELECT id_test FROM CORREZIONE WHERE username_s = '"+username+"'"); + ResultSet rs = g.executeQuery(); + for(i = 0; rs.next(); i++) { + id[i] = rs.getInt("id_test"); + } + + String[] tmp = new String[i]; + for(int j = 0; j < i; j++) { + g = connessione.prepareStatement( + "SELECT nome_test FROM TEST WHERE id_test ="+id[j]); + rs = g.executeQuery(); + while(rs.next()) { + tmp[j] = rs.getString("nome_test"); + } + + } + + rs.close(); + return tmp; + + + } + catch (SQLException e) { + + e.printStackTrace(); + return null; + + } + + } + + public String[] returnAllTestName() { + PreparedStatement g; + int i; + int[] id = new int[100]; + + + try { + + g = connessione.prepareStatement("SELECT id_test FROM TEST"); + ResultSet rs = g.executeQuery(); + for(i = 0; rs.next(); i++) { + id[i] = rs.getInt("id_test"); + } + + String[] tmp = new String[i]; + for(int j = 0; j < i; j++) { + g = connessione.prepareStatement( + "SELECT nome_test FROM TEST WHERE id_test ="+id[j]); + rs = g.executeQuery(); + while(rs.next()) { + tmp[j] = rs.getString("nome_test"); + } + + } + + rs.close(); + return tmp; + + + } + catch (SQLException e) { + + e.printStackTrace(); + return null; + + } + + } + + public String[] returnAllMat() { + PreparedStatement g; + int i, c = 0; + int[] id = new int[100]; + + + try { + + g = connessione.prepareStatement("SELECT id_test FROM TEST"); + ResultSet rs = g.executeQuery(); + for(i = 0; rs.next(); i++) { + id[i] = rs.getInt("id_test"); + } + + String[] tmp = new String[i]; + for(int j = 0; j < i; j++) { + g = connessione.prepareStatement( + "SELECT materia_test FROM TEST WHERE id_test ="+id[j]); + rs = g.executeQuery(); + while(rs.next()) { + tmp[j] = rs.getString("materia_test"); + if(!tmp[j].equals("")) { + c++; + } + } + } + String[] output = new String[c]; + c = 0; + for(int j = 0; j < i; j++) { + if(tmp[j].equals("")) {} + else { + output[c] = tmp[j]; c++; + } + } + rs.close(); + return output; + + + } + catch (SQLException e) { + + e.printStackTrace(); + return null; + + } + + } + + public float ottieniVotoTest(String username, int id) { + PreparedStatement g; + float punteggio = 0; + + + try { + + g = connessione.prepareStatement("SELECT voto_test FROM CORREZIONE WHERE username_s = '"+username+"' AND id_test = "+id); + ResultSet rs = g.executeQuery(); + for(int i = 0; rs.next(); i++) { + punteggio = rs.getFloat("voto_test"); + } + + + return punteggio; + + + } + catch (SQLException e) { + + e.printStackTrace(); + return 0; + + } + } + + public String ottieniUltimoTestSvolto(String username) { + PreparedStatement g; + String nome_test = "Nessun test svolto di recente"; + int id = -1; + + try { + + g = connessione.prepareStatement("SELECT id_test FROM CORREZIONE WHERE username_s = '"+username+"'"); + ResultSet rs = g.executeQuery(); + for(int i = 0; rs.next();i++) { + id = rs.getInt("id_test"); + + } + g = connessione.prepareStatement("SELECT nome_test FROM TEST WHERE id_test = "+id); + rs = g.executeQuery(); + + while(rs.next()) { + nome_test = rs.getString("nome_test"); + } + + return nome_test; + + + } + catch (SQLException e) { + + e.printStackTrace(); + return nome_test; + + } + } + + } diff --git a/java/src/controller/Controller.java b/java/src/controller/Controller.java index b2c643ae..ed2df4af 100644 --- a/java/src/controller/Controller.java +++ b/java/src/controller/Controller.java @@ -3,7 +3,6 @@ import PostgresDAO.*; import java.sql.SQLException; -import java.util.ArrayList; import Database.*; @@ -13,7 +12,6 @@ public class Controller { public Quesiti q; public Studente s = null; public Test t; - public Risposta r; public Utente u; public ConnessioneDatabase connessione; @@ -56,7 +54,6 @@ public void login(String username, String password) { s = studenteDB.login(username, password); } - public void registraStudente() {} public boolean checkUsername() { //Controllo disponibilità dell'username String s = null, q = null; @@ -71,6 +68,20 @@ public void registraStudente() {} return false; } + public boolean checkUsername(String username) { //Controllo disponibilità dell'username + String s = null, q = null; + InsegnanteDAO insegnanteDB = new InsegnanteDAO(); + StudenteDAO studenteDB = new StudenteDAO(); + + q = studenteDB.getUsername(username); + if(q != null) return true; + s = insegnanteDB.getUsername(username); + if(s != null) return true; + + return false; + + } + public void inizializzaInsegnante() { i = new Insegnante(u.username, u.password, u.nome, u.cognome); InsegnanteDAO insegnanteDB = new InsegnanteDAO(); @@ -132,6 +143,14 @@ public String[] returnTestName(String username, int a) { } + public String[] returnAllTest(String username) { + TestDAO testDB = new TestDAO(); + String[] rs = testDB.returnAllTest(username); + + return rs; + + } + public void caricaTest(String nome_test, String username) { TestDAO testDB = new TestDAO(); @@ -232,4 +251,58 @@ public boolean checkAlreadySolved(int id, String username) { TestDAO testDB = new TestDAO(); return testDB.checkAlreadySolved(id, username); } + + public void updateTest() { + TestDAO testDB = new TestDAO(); + testDB.updateTest(t.id, t.nomeTest, t.materia, t.descrizione); + } + + public boolean hasQ() { + TestDAO testDB = new TestDAO(); + if(testDB.hasQ(t.id)) return true; + else return false; + } + + public void aggiornaUtente(String password, String nome, String cognome, boolean who, String oldUsername) { + InsegnanteDAO insegnanteDB = new InsegnanteDAO(); + + if(who) insegnanteDB.aggiornaUtente(password, nome, cognome, who, oldUsername); + else insegnanteDB.aggiornaUtente(password, nome, cognome, who, oldUsername); + } + + public String[] returnAllTestName(String username) { + TestDAO testDB = new TestDAO(); + String[] rs = testDB.returnAllTestName(username); + + return rs; + + } + + public String[] returnAllTestName() { + TestDAO testDB = new TestDAO(); + String[] rs = testDB.returnAllTestName(); + + return rs; + + } + + public String[] returnAllMat() { + TestDAO testDB = new TestDAO(); + String[] rs = testDB.returnAllMat(); + + return rs; + + } + + public float ottieniVotoTest(String username, int id) { + TestDAO testDB = new TestDAO(); + + return testDB.ottieniVotoTest(username, id); + } + + public String ottieniUltimoTestSvolto(String username) { + TestDAO testDB = new TestDAO(); + + return testDB.ottieniUltimoTestSvolto(username); + } } diff --git a/java/src/modelli/Insegnante.java b/java/src/modelli/Insegnante.java index c29fc928..8b67007d 100644 --- a/java/src/modelli/Insegnante.java +++ b/java/src/modelli/Insegnante.java @@ -1,13 +1,6 @@ package modelli; -import java.util.ArrayList; -import java.util.List; - public class Insegnante extends Utente{ -float puntegggioStudente; -List daCorreggere = new ArrayList(); -List corsiTenuti = new ArrayList(); - public Insegnante(String u, String p, String n, String c) { username = u; password = p; diff --git a/java/src/modelli/Studente.java b/java/src/modelli/Studente.java index 6ed31032..30e3969d 100644 --- a/java/src/modelli/Studente.java +++ b/java/src/modelli/Studente.java @@ -1,19 +1,12 @@ package modelli; - -import java.util.ArrayList; -import java.util.List; - public class Studente extends Utente{ -float punteggioStudente, mediaVotiCat; -List testSvolti = new ArrayList(); +float punteggioStudente; public Studente(String u, String p, String n, String c) { username = u; password = p; nome = n; cognome = c; -} - - + } } diff --git a/java/src/modelli/Test.java b/java/src/modelli/Test.java index bcf6fa21..09aacd01 100644 --- a/java/src/modelli/Test.java +++ b/java/src/modelli/Test.java @@ -1,8 +1,6 @@ package modelli; -import java.util.ArrayList; import java.util.Date; -import java.util.List; public class Test { diff --git a/java/src/modelli/Utente.java b/java/src/modelli/Utente.java index af8bb96a..a76b8a9b 100644 --- a/java/src/modelli/Utente.java +++ b/java/src/modelli/Utente.java @@ -8,7 +8,4 @@ public class Utente { public String nome; public String cognome; - - - }