Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Libretto Scolastico - Frame.java

Frame.java

Caricato da: Ale.gatti96
Scarica il programma completo

  1. //workspace/LibrettoScolastico/Frame.java
  2. import java.awt.BorderLayout;
  3. import java.awt.Dimension;
  4. import java.awt.FlowLayout;
  5. import java.awt.Font;
  6. import java.awt.GridLayout;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import java.util.Calendar;
  10.  
  11. import javax.swing.Box;
  12. import javax.swing.ButtonGroup;
  13. import javax.swing.JButton;
  14. import javax.swing.JComboBox;
  15. import javax.swing.JFrame;
  16. import javax.swing.JLabel;
  17. import javax.swing.JOptionPane;
  18. import javax.swing.JPanel;
  19. import javax.swing.JRadioButton;
  20. import javax.swing.JScrollPane;
  21. import javax.swing.JSpinner;
  22. import javax.swing.JTextArea;
  23. import javax.swing.JTextField;
  24. import javax.swing.SpinnerNumberModel;
  25. import javax.swing.SwingConstants;
  26.  
  27. public class Frame extends JFrame{
  28.   private static final long serialVersionUID = 1L;
  29.   private JPanel menu,rightPanel;
  30.   private JButton riepilogoButton,
  31.       addVotoButton,
  32.       removeVotoButton,
  33.       matAddButton,
  34.       matModButton,
  35.       matRemoveButton;
  36.   private JButton vediVoti;
  37.   private LibrettoScolastico LS;
  38.    
  39.   public Frame(){
  40.         super("Libretto Scolastico");
  41.         setLayout(new BorderLayout(10,10));
  42.         LS=new LibrettoScolastico();
  43.        
  44.         //Creazione Menu
  45.         menu=new JPanel(new GridLayout(9,1,2,2));
  46.         riepilogoButton=new JButton("Riepilogo");
  47.         addVotoButton=new JButton("Inserisci Voto");
  48.         removeVotoButton=new JButton("Cancella Voto");
  49.         matAddButton=new JButton("Aggiungi Materia");
  50.         matModButton=new JButton("Modifica Materia");
  51.         matRemoveButton=new JButton("Cancella Materia");
  52.        
  53.         vediVoti=new JButton("Vedi Voti");
  54.         menu.add(new JPanel());
  55.         menu.add(riepilogoButton);
  56.         menu.add(addVotoButton);
  57.         menu.add(removeVotoButton);
  58.         menu.add(matAddButton);
  59.         menu.add(matModButton);
  60.         menu.add(matRemoveButton);
  61.         menu.add(vediVoti);
  62.         add(menu,BorderLayout.WEST);
  63.        
  64.         rightPanel=new JPanel();
  65.         if(LS.size()==0)
  66.           rightPanel.add(new MaterieAddPanel());
  67.         else
  68.           rightPanel.add(new RiepilogoPanel());
  69.         add(rightPanel,BorderLayout.CENTER);
  70.        
  71.     //Gestione Eventi
  72.         MenuHelander menuHelander=new MenuHelander();
  73.         riepilogoButton.addActionListener(menuHelander);
  74.         addVotoButton.addActionListener(menuHelander);
  75.         removeVotoButton.addActionListener(menuHelander);
  76.         vediVoti.addActionListener(menuHelander);
  77.         matAddButton.addActionListener(menuHelander);
  78.         matModButton.addActionListener(menuHelander);
  79.         matRemoveButton.addActionListener(menuHelander);
  80.   }
  81.  
  82.   public boolean scegliMateria(){
  83.         if(LS.size()==0){
  84.           errNessunaMateria();
  85.           return false;
  86.         }
  87.         String[] materie=LS.getStringArrMaterie();
  88.         String sel=(String)JOptionPane.showInputDialog(
  89.                         null, "Scegli", "Scegli",
  90.             JOptionPane.QUESTION_MESSAGE, null,
  91.             materie, materie[0]);
  92.         if(sel==null)
  93.           return false;
  94.         for(int i=0;i<LS.size();i++){
  95.           if(LS.get(i).getNome().equals(sel)){
  96.                 LS.setMat(i);
  97.                 break;
  98.           }
  99.         }
  100.         return true;
  101.   }
  102.   public void errNessunaMateria(){
  103.         JOptionPane.showMessageDialog(null,"Nessuna materia inserita!",
  104.           "Nessuna materia inserita!",JOptionPane.ERROR_MESSAGE);
  105.         rightPanel.removeAll();
  106.         rightPanel.add(new MaterieAddPanel());
  107.         rightPanel.repaint();
  108.         rightPanel.validate();
  109.   }
  110.   public void errNessunVoto(){
  111.         JOptionPane.showMessageDialog(null,"Nessuna materia inserita!",
  112.           "Nessuna voto inserito di "+LS.get(LS.getMat())+"!",
  113.           JOptionPane.ERROR_MESSAGE);
  114.         rightPanel.removeAll();
  115.         rightPanel.add(new RiepilogoPanel());
  116.         rightPanel.repaint();
  117.         rightPanel.validate();
  118.   }
  119.  
  120.   class MenuHelander implements ActionListener{
  121.         public void actionPerformed(ActionEvent event) {
  122.           Object src=event.getSource();
  123.           if(LS.size()==0&&src!=matAddButton){
  124.                 errNessunaMateria();
  125.                 return;
  126.           }
  127.          
  128.           if(src==riepilogoButton){
  129.                 rightPanel.removeAll();
  130.                 rightPanel.add(new RiepilogoPanel());
  131.                 rightPanel.repaint();
  132.                 rightPanel.validate();}
  133.           if(src==addVotoButton&&scegliMateria()==true){
  134.                 rightPanel.removeAll();
  135.                 rightPanel.add(new AddVotoPanel());
  136.                 rightPanel.repaint();
  137.                 rightPanel.validate();}
  138.           if(src==removeVotoButton&&scegliMateria()==true){
  139.                 rightPanel.removeAll();
  140.                 rightPanel.add(new RemoveVotoPanel());
  141.                 rightPanel.repaint();
  142.                 rightPanel.validate();}
  143.          
  144.          
  145.           if(src==matAddButton){
  146.                 rightPanel.removeAll();
  147.                 rightPanel.add(new MaterieAddPanel());
  148.                 rightPanel.repaint();
  149.                 rightPanel.validate();}  
  150.          
  151.           if(src==matModButton){
  152.                 rightPanel.removeAll();
  153.                 rightPanel.add(new MaterieModPanel());
  154.                 rightPanel.repaint();
  155.                 rightPanel.validate();}
  156.          
  157.           if(src==matRemoveButton){
  158.                 rightPanel.removeAll();
  159.                 rightPanel.add(new MaterieRemovePanel());
  160.                 rightPanel.repaint();
  161.                 rightPanel.validate();}
  162.          
  163.           if(src==vediVoti&&scegliMateria()==true){
  164.                 rightPanel.removeAll();
  165.                 rightPanel.add(new VediVotiPanel());
  166.                 rightPanel.repaint();
  167.                 rightPanel.validate();}
  168.         }
  169.   }
  170.  
  171.   class RiepilogoPanel extends JPanel{
  172.         private static final long serialVersionUID = 1L;
  173.  
  174.         RiepilogoPanel(){
  175.           setLayout(new BorderLayout(5,5));
  176.           JLabel titolo=new JLabel("Riepilogo Materie");
  177.            titolo.setFont(new Font("Serif",Font.BOLD+Font.ITALIC,25));
  178.            titolo.setHorizontalAlignment(SwingConstants.CENTER);
  179.           add(titolo,BorderLayout.NORTH);
  180.          
  181.           JLabel riepMateriePanel=new JLabel(LS.size()!=0?
  182.                           "Materie: "+LS.size():
  183.                           "Nessuna materia inserita");
  184.           JLabel mediaLabel=new JLabel(LS.getMedia()!=-1?
  185.                           "Media generale: "+
  186.                           String.format("%.2f",Math.round(LS.getMedia()*100.0)/100.0):
  187.                           "Nessun voto inserito");
  188.           riepMateriePanel.setHorizontalAlignment(SwingConstants.CENTER);
  189.           mediaLabel.setHorizontalAlignment(SwingConstants.CENTER);
  190.           JPanel riepilogoLabelPanel=new JPanel(new GridLayout(2,1));
  191.           riepilogoLabelPanel.add(riepMateriePanel);
  192.           riepilogoLabelPanel.add(mediaLabel);
  193.           add(riepilogoLabelPanel,BorderLayout.CENTER);
  194.          
  195.           JTextArea riepilogo=new JTextArea(15,22);
  196.            riepilogo.setText(LS.riepilogo());
  197.            riepilogo.setEditable(false);
  198.           JScrollPane scroll=new JScrollPane(riepilogo,
  199.                         JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
  200.                         JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  201.           scroll.setMaximumSize(new Dimension(100,100));
  202.           add(scroll,BorderLayout.SOUTH);
  203.            
  204.         }
  205.   }
  206.  
  207.   class AddVotoPanel extends JPanel{
  208.         private static final long serialVersionUID = 1L;
  209.         JTextField votoText,annoText,giornoText,meseText;
  210.         JSpinner annoSpinner,meseSpinner,giornoSpinner;
  211.         JRadioButton scrittoRB,oraleRB,laboratorioRB;
  212.         ButtonGroup radioGroup;
  213.         AddVotoPanel(){
  214.           setLayout(new BorderLayout());
  215.           JLabel titolo=new JLabel("Inserisci voto di "+
  216.                  LS.get(LS.getMat()).getNome()+" ");
  217.           titolo.setFont(new Font("Serif",Font.BOLD+Font.ITALIC,25));
  218.           titolo.setHorizontalAlignment(SwingConstants.CENTER);
  219.           add(titolo,BorderLayout.NORTH);
  220.          
  221.           Box center=Box.createVerticalBox();
  222.            for(int i=0;i<3;i++)center.add(new JPanel());
  223.            
  224.           JPanel votoPanel=new JPanel(new GridLayout(1,4));
  225.            JLabel votoLabel=new JLabel("Voto:");
  226.             votoLabel.setHorizontalAlignment(SwingConstants.RIGHT);
  227.            votoText=new JTextField(3);
  228.            votoPanel.add(votoLabel);
  229.            votoPanel.add(votoText);
  230.            votoPanel.add(new JPanel());
  231.           center.add(votoPanel);
  232.          
  233.           JPanel giornoPanel=new JPanel(new GridLayout(1,4));
  234.            JLabel giornoLabel=new JLabel("Giorno:");
  235.             giornoLabel.setHorizontalAlignment(SwingConstants.RIGHT);
  236.            giornoSpinner=new JSpinner();
  237.                 giornoSpinner.setModel(new SpinnerNumberModel(1,1,31,1));
  238.            giornoPanel.add(giornoLabel);
  239.            giornoPanel.add(giornoSpinner);
  240.            giornoPanel.add(new JPanel());
  241.           center.add(giornoPanel);
  242.          
  243.           JPanel mesePanel=new JPanel(new GridLayout(1,4));
  244.            JLabel meseLabel=new JLabel("Mese:");
  245.             meseLabel.setHorizontalAlignment(SwingConstants.RIGHT);
  246.            meseSpinner=new JSpinner();
  247.             meseSpinner.setModel(new SpinnerNumberModel(1,1,12,1));
  248.            mesePanel.add(meseLabel);
  249.            mesePanel.add(meseSpinner);
  250.            mesePanel.add(new JPanel());
  251.           center.add(mesePanel);
  252.          
  253.           Calendar calendar=Calendar.getInstance();
  254.           int a=calendar.get(Calendar.YEAR),
  255.               x=(calendar.get(Calendar.MONTH)>=9?a:a-1);
  256.           JPanel annoPanel=new JPanel(new GridLayout(1,4));
  257.            JLabel annoLabel=new JLabel("Anno:");
  258.             annoLabel.setHorizontalAlignment(SwingConstants.RIGHT);
  259.            annoSpinner=new JSpinner();
  260.             annoSpinner.setModel(new SpinnerNumberModel(a,x,x+1,1));
  261.             annoSpinner.setEditor(new JSpinner.NumberEditor(annoSpinner, "#"));
  262.            annoPanel.add(annoLabel);
  263.            annoPanel.add(annoSpinner);
  264.            annoPanel.add(new JPanel());
  265.           center.add(annoPanel);
  266.          
  267.          
  268.           radioGroup=new ButtonGroup();
  269.            scrittoRB=new JRadioButton("Scritto",true);
  270.            oraleRB=new JRadioButton("Orale",false);
  271.            laboratorioRB=new JRadioButton("Laboratorio",false);
  272.            radioGroup.add(scrittoRB);
  273.            radioGroup.add(oraleRB);
  274.            radioGroup.add(laboratorioRB);
  275.           JPanel radioPanel=new JPanel(new FlowLayout(FlowLayout.CENTER));
  276.            radioPanel.add(scrittoRB);
  277.            radioPanel.add(oraleRB);
  278.            radioPanel.add(laboratorioRB);
  279.           center.add(radioPanel);
  280.          
  281.           JPanel buttonPanel=new JPanel(new GridLayout(1,4));
  282.            JButton add=new JButton("Aggiungi");
  283.            buttonPanel.add(new JPanel());
  284.            buttonPanel.add(add);
  285.            buttonPanel.add(new JPanel());
  286.           center.add(buttonPanel);
  287.          
  288.           add(center,BorderLayout.CENTER);
  289.           add.addActionListener(
  290.             new ActionListener(){
  291.                   public void actionPerformed(ActionEvent arg0){
  292.                         double v;
  293.                         int g,m,a;
  294.                         try{
  295.                           StringBuffer s=new StringBuffer(votoText.getText());
  296.                           int i=s.indexOf(",");
  297.                           if(i!=-1)
  298.                 s.setCharAt(i,'.');
  299.                           v=Double.parseDouble(s.toString());
  300.                           g=Integer.parseInt(giornoSpinner.getValue().toString());
  301.                           m=Integer.parseInt(meseSpinner.getValue().toString())-1;
  302.                           a=Integer.parseInt(annoSpinner.getValue().toString());
  303.                         }catch(NumberFormatException e){
  304.                           JOptionPane.showMessageDialog(null,
  305.                             "Errore: "+e+"\n\n\tInserire tutti i valori e in modo corretto!",
  306.                                 "Errore",JOptionPane.ERROR_MESSAGE);
  307.                           votoText.setText("");
  308.                           return;
  309.                         }catch(Exception e){
  310.                           JOptionPane.showMessageDialog(null,e,"Errore",
  311.                                 JOptionPane.ERROR_MESSAGE);
  312.                           return;
  313.                         }
  314.                        
  315.                         int ggMesi[]={31,28,31,30,31,30,31,31,30,31,30,31};
  316.                         if(g>ggMesi[m]||(m==2&&(g==29&&(a%400==0||(a%4==0||a%100!=0))))){
  317.                       JOptionPane.showMessageDialog(null,"Inserire data corretta",
  318.                                 "Errore",JOptionPane.ERROR_MESSAGE);
  319.                           return;
  320.                         }
  321.                        
  322.                         if(v<0||v>10){
  323.                           JOptionPane.showMessageDialog(null,"Inserire una valutazione Valida",
  324.                                    "Errore",JOptionPane.ERROR_MESSAGE);
  325.                           votoText.setText("");
  326.                           return;
  327.                         }
  328.                        
  329.                         Voto voto=new Voto();
  330.                         voto.setValore(v);
  331.                         voto.setData(a, m, g);
  332.                        
  333.                         if(laboratorioRB.getSelectedObjects()!=null)
  334.                           voto.setTipo(Voto.Tipo.Laboratorio);
  335.                         else if(oraleRB.getSelectedObjects()!=null)
  336.                           voto.setTipo(Voto.Tipo.Orale);
  337.                         else
  338.                           voto.setTipo(Voto.Tipo.Scritto);
  339.                        
  340.                         LS.get(LS.getMat()).addVoto(voto);
  341.                         LS.salvaFile();
  342.                         int ris=JOptionPane.showConfirmDialog(null,
  343.                                 "Voto Inserito, inserirne un altro?","Voto Inserito",
  344.                                 JOptionPane.YES_NO_OPTION);
  345.                        
  346.                         rightPanel.removeAll();
  347.                         if(ris==JOptionPane.YES_OPTION)
  348.                                 rightPanel.add(new AddVotoPanel());
  349.                         else if (ris==JOptionPane.NO_OPTION)
  350.                           rightPanel.add(new VediVotiPanel());
  351.                         rightPanel.repaint();
  352.                         rightPanel.validate();
  353.                   }
  354.             }
  355.           );
  356.         }
  357.   }
  358.  
  359.   class RemoveVotoPanel extends JPanel{
  360.         private static final long serialVersionUID = 1L;
  361.         private JComboBox jcb;
  362.         int n=1,s,o,l;
  363.        
  364.         RemoveVotoPanel(){
  365.           setLayout(new BorderLayout());
  366.          
  367.           if(LS.get(LS.getMat()).size()==0){
  368.                 errNessunVoto();
  369.                 return;
  370.           }
  371.          
  372.           JLabel titolo=new JLabel("Rimozione voto di "+
  373.                  LS.get(LS.getMat()).getNome()+" ");
  374.           titolo.setFont(new Font("Serif",Font.BOLD+Font.ITALIC,25));
  375.           titolo.setHorizontalAlignment(SwingConstants.CENTER);
  376.           add(titolo,BorderLayout.NORTH);
  377.          
  378.       Materia mat=LS.get(LS.getMat());
  379.           JPanel center=new JPanel();
  380.            center.add(new JLabel("Voto da cancellare: "));
  381.            String array[]=new String[mat.size()];
  382.            for(int i=0;i<mat.size();i++)
  383.                  array[i]=""+(i+1);
  384.            jcb=new JComboBox(array);
  385.            center.add(jcb);
  386.            JButton button=new JButton("Cancella");
  387.            center.add(button);
  388.           add(center,BorderLayout.CENTER);
  389.          
  390.           String st="";
  391.           if(mat.getGVS().size()!=0){
  392.             //Stampa voti Scritti
  393.             st=String.format("Voti Scritti:\n%2s %4s  Data\n","N","Voto");
  394.         for(int i=0;i<mat.getGVS().size();i++,n++){
  395.           st+=String.format("%2s",n);
  396.           st+=String.format("  %-1.2f ",mat.getGVS().get(i).getValore());
  397.           st+=String.format("%11s\n",mat.getGVS().get(i).getData());
  398.           s=n;
  399.         }
  400.       }
  401.           if(mat.getGVO().size()!=0){
  402.         //Stampa voti Orale
  403.             st+=String.format("\nVoti Orali:\n%2s %4s  Data\n","N","Voto");
  404.         for(int i=0;i<mat.getGVO().size();i++,n++){
  405.           st+=String.format("%2s",n);
  406.           st+=String.format("  %-1.2f ",mat.getGVO().get(i).getValore());
  407.           st+=String.format("%11s\n",mat.getGVO().get(i).getData());
  408.           o=n;
  409.         }
  410.           }
  411.       if(mat.getGVL().size()!=0){
  412.             //Stampa voti di Laboratorio
  413.             st+=String.format("\nVoti di Laboratorio:\n%2s %4s  Data\n","N","Voto");
  414.         for(int i=0;i<mat.getGVL().size();i++,n++){
  415.           st+=String.format("%2s",n);
  416.           st+=String.format("  %-1.2f ",mat.getGVL().get(i).getValore());
  417.           st+=String.format("%11s\n",mat.getGVL().get(i).getData());
  418.           l=n;
  419.         }
  420.       }
  421.          
  422.           JTextArea text=new JTextArea();
  423.            text.setText(st);
  424.            text.setEditable(false);
  425.           JScrollPane scroll=new JScrollPane(text,
  426.                         JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
  427.                     JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  428.           add(scroll,BorderLayout.SOUTH);
  429.          
  430.           button.addActionListener(
  431.             new ActionListener(){
  432.              public void actionPerformed(ActionEvent arg0) {
  433.                Voto voto;
  434.                char gv;
  435.                int i,scelta=jcb.getSelectedIndex();
  436.               if(0<=scelta&&scelta<s){
  437.                       i=scelta;
  438.                   voto=LS.get(LS.getMat()).getGVS().get(i);
  439.                   gv='s';
  440.                }else if(s<=scelta&&scelta<o){
  441.                        i=scelta-s;
  442.                    voto=LS.get(LS.getMat()).getGVO().get(i);
  443.                        gv='o';
  444.                  }else{
  445.                            i=scelta-o;
  446.                    voto=LS.get(LS.getMat()).getGVL().get(i);
  447.                        gv='l';
  448.                }
  449.                    int risp=JOptionPane.showConfirmDialog(null, "Cancellare voto "+
  450.                 voto.getValore()+" del "+voto.getData()+" ?",
  451.                         "Conferma",JOptionPane.YES_NO_OPTION);
  452.                    if(risp==JOptionPane.NO_OPTION)
  453.                          return;
  454.                    switch(gv){
  455.                    case 's':LS.get(LS.getMat()).getGVS().removeVoto(i);break;
  456.                    case 'o':LS.get(LS.getMat()).getGVO().removeVoto(i);break;
  457.                    case 'l':LS.get(LS.getMat()).getGVL().removeVoto(i);break;
  458.                    }
  459.                    LS.salvaFile();
  460.                    rightPanel.removeAll();
  461.                    if(LS.get(LS.getMat()).size()!=0)
  462.                      rightPanel.add(new RemoveVotoPanel());
  463.                    else
  464.                          rightPanel.add(new RiepilogoPanel());
  465.                    rightPanel.repaint();
  466.                    rightPanel.validate();
  467.                  }
  468.             }
  469.           );
  470.         }
  471.   }
  472.  
  473.   class VediVotiPanel extends JPanel{
  474.         private static final long serialVersionUID = 1L;
  475.         VediVotiPanel(){
  476.           setLayout(new BorderLayout());
  477.          
  478.           JLabel titolo=new JLabel("Visualizza voti di "+
  479.                  LS.get(LS.getMat()).getNome()+" ");
  480.           titolo.setFont(new Font("Serif",Font.BOLD+Font.ITALIC,25));
  481.           titolo.setHorizontalAlignment(SwingConstants.CENTER);
  482.           add(titolo,BorderLayout.NORTH);
  483.  
  484.           JPanel center=new JPanel(new GridLayout(2,1));
  485.            if(LS.get(LS.getMat()).getMediaSO()!=-1){
  486.          JLabel mediaSOLabel=new JLabel("Media Scritto-Orale: "+
  487.            Math.round(LS.get(LS.getMat()).getMediaSO()*100)/100.0);
  488.          mediaSOLabel.setHorizontalAlignment(SwingConstants.CENTER);
  489.          center.add(mediaSOLabel);
  490.            }
  491.        if(LS.get(LS.getMat()).getGVL().getMedia()!=-1){
  492.          JLabel mediaLabLabel=new JLabel("Media Laboratorio: "+
  493.           Math.round(LS.get(LS.getMat()).getGVL().getMedia()*100)/100.0);
  494.          mediaLabLabel.setHorizontalAlignment(SwingConstants.CENTER);
  495.          center.add(mediaLabLabel);
  496.        }
  497.           add(center,BorderLayout.CENTER);       
  498.          
  499.           boolean s,o,l;
  500.           s=o=l=false;
  501.           JPanel south=new JPanel(new BorderLayout(5,5));
  502.           JScrollPane jspS,jspO,jspL;
  503.           jspS=jspO=jspL=null;
  504.           if(LS.get(LS.getMat()).getGVS().size()!=0){
  505.             s=true;
  506.             String sS=String.format("Voti Scritti:\n%5s  Data\n","Voto");
  507.             GruppoVoti g=LS.get(LS.getMat()).getGVS();
  508.             for(int i=0;i<g.size();i++){
  509.               sS+=String.format("  %-3.2f ",g.get(i).getValore());
  510.               sS+=String.format("%11s\n",g.get(i).getData());
  511.             }
  512.             JTextArea textS=new JTextArea();
  513.                  textS.setFont(new Font("Serif",Font.PLAIN,18));
  514.                  textS.setText(sS);
  515.                  textS.setEditable(false);
  516.                 jspS=new JScrollPane(textS,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
  517.                   JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  518.           }
  519.          
  520.           if(LS.get(LS.getMat()).getGVO().size()!=0){
  521.                 o=true;
  522.             String sO=String.format("Voti Orali:\n%5s  Data\n","Voto");
  523.             GruppoVoti g=LS.get(LS.getMat()).getGVO();
  524.             for(int i=0;i<g.size();i++){
  525.               sO+=String.format("  %-3.2f ",g.get(i).getValore());
  526.               sO+=String.format("%11s\n",g.get(i).getData());
  527.             }
  528.             JTextArea textO=new JTextArea();
  529.                  textO.setFont(new Font("Serif",Font.PLAIN,18));
  530.                  textO.setText(sO);
  531.                  textO.setEditable(false);
  532.                 jspO=new JScrollPane(textO,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
  533.                   JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  534.           }
  535.          
  536.           if(LS.get(LS.getMat()).getGVL().size()!=0){
  537.             l=true;
  538.             String sL=String.format("Voti di Laboratorio:\n%5s  Data\n","Voto");
  539.             GruppoVoti g=LS.get(LS.getMat()).getGVL();
  540.             for(int i=0;i<g.size();i++){
  541.               sL+=String.format("  %-3.2f ",g.get(i).getValore());
  542.               sL+=String.format("%11s\n",g.get(i).getData());
  543.             }
  544.             JTextArea textL=new JTextArea();
  545.                  textL.setFont(new Font("Serif",Font.PLAIN,18));
  546.                  textL.setText(sL);
  547.                  textL.setEditable(false);
  548.                 jspL=new JScrollPane(textL,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
  549.                   JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  550.           }
  551.      
  552.           //Varie disposizioni
  553.           //Nessun Voto
  554.           if(!s&&!o&&!l){
  555.                 add(new JLabel("Nessun voto presente"),BorderLayout.SOUTH);
  556.             return;
  557.           }
  558.          
  559.           //Tre tipologie di voti
  560.           if(s&&o&&l){
  561.                 south.add(jspS,BorderLayout.WEST);
  562.                 south.add(jspO,BorderLayout.EAST);
  563.                 south.add(jspL,BorderLayout.SOUTH);
  564.           }
  565.          
  566.           //Solo una tipologia di voti
  567.           if(!o&&!l){
  568.                 south.add(jspS,BorderLayout.CENTER);
  569.           }else if(!s&&!l){//Solo voti Orali
  570.                 south.add(jspO,BorderLayout.CENTER);
  571.           }else if(!s&&!l){//Solo voti di Laboratorio
  572.                 south.add(jspL,BorderLayout.CENTER);
  573.           }
  574.          
  575.           //Due tipologie di voti
  576.           else if(s&&(o||l)){
  577.                 if(o){
  578.                   south.add(jspS,BorderLayout.WEST);
  579.                   south.add(jspO,BorderLayout.EAST);
  580.                 }else{
  581.                   south.add(jspS,BorderLayout.CENTER);
  582.                   south.add(jspL,BorderLayout.SOUTH);
  583.                 }
  584.           }else if(o&&(s||l)){
  585.                 south.add(jspO,BorderLayout.NORTH);
  586.                 south.add(jspL,BorderLayout.SOUTH);
  587.           }      
  588.          
  589.           add(south,BorderLayout.SOUTH);
  590.         }
  591.   }
  592.  
  593.   class MaterieAddPanel extends JPanel{
  594.     private static final long serialVersionUID = 1L;
  595.     JTextField nomeTextField;
  596.    
  597.     MaterieAddPanel(){
  598.       setLayout(new BorderLayout());
  599.       JLabel titolo=new JLabel("Aggiungi Nuova Materia");
  600.       titolo.setFont(new Font("Serif",Font.BOLD+Font.ITALIC,25));
  601.       titolo.setHorizontalAlignment(SwingConstants.CENTER);
  602.       add(titolo,BorderLayout.NORTH);
  603.      
  604.       JLabel nomeLabel=new JLabel("Nome materia: ");
  605.       nomeTextField=new JTextField("",10);
  606.      
  607.       JButton aggiungi=new JButton("Aggiungi");
  608.       JPanel panel=new JPanel(new FlowLayout());
  609.       panel.add(nomeLabel);
  610.       panel.add(nomeTextField);
  611.       panel.add(aggiungi);
  612.       add(panel,BorderLayout.CENTER);
  613.      
  614.       if(LS.size()!=0){
  615.         JTextArea mat=new JTextArea("Materie già inserite:\n");
  616.         mat.setEditable(false);
  617.         for(int i=0;i<LS.size();i++)
  618.           mat.append(" - "+LS.get(i).getNome()+"\n");
  619.         add(new JScrollPane(mat),BorderLayout.SOUTH);
  620.       }
  621.      
  622.       aggiungi.addActionListener(
  623.         new ActionListener(){
  624.           public void actionPerformed(ActionEvent event){
  625.                 String n= nomeTextField.getText();
  626.                         if(n=="")return;
  627.                         n=n.substring(0,1).toUpperCase()+n.substring(1);
  628.                         nomeTextField.setText(n);
  629.                 LS.addMateria(n);
  630.                 JOptionPane.showMessageDialog(null, "Inserita nuova materia \""+n+"\"",
  631.                                 "Nuova Materia Inserita",JOptionPane.INFORMATION_MESSAGE);
  632.                 nomeTextField.setText("");
  633.                 rightPanel.removeAll();
  634.                 rightPanel.add(new MaterieAddPanel());
  635.                 rightPanel.repaint();
  636.                 rightPanel.validate();
  637.           }
  638.         }
  639.       );
  640.     }
  641.   }
  642.  
  643.   class MaterieModPanel extends JPanel{
  644.     private static final long serialVersionUID = 1L;
  645.     JComboBox matComboBox;
  646.     JTextField nome;
  647.    
  648.     MaterieModPanel(){
  649.       setLayout(new BorderLayout());
  650.       JLabel titolo=new JLabel("Modifica nome Materia");
  651.       titolo.setFont(new Font("Serif",Font.BOLD+Font.ITALIC,25));
  652.       titolo.setHorizontalAlignment(SwingConstants.CENTER);
  653.       add(titolo,BorderLayout.NORTH);
  654.      
  655.       JPanel center=new JPanel(new GridLayout(4,3,3,3));
  656.       JLabel label1=new JLabel("Modificare: ");
  657.        label1.setHorizontalAlignment(SwingConstants.RIGHT);
  658.       String[] materie=LS.getStringArrMaterie();
  659.       matComboBox=new JComboBox(materie);
  660.       JLabel label2=new JLabel("Nuovo nome: ");
  661.        label2.setHorizontalAlignment(SwingConstants.RIGHT);
  662.       nome=new JTextField(10);
  663.       JButton modifica=new JButton("Modifica");
  664.       for(int i=0;i<3;i++)center.add(new JPanel());
  665.       center.add(label1);
  666.       center.add(matComboBox);
  667.       center.add(new JPanel());
  668.       center.add(label2);
  669.       center.add(nome);
  670.       center.add(new JPanel());
  671.       center.add(new JPanel());
  672.       center.add(modifica);
  673.       add(center,BorderLayout.CENTER);
  674.       modifica.addActionListener(
  675.         new ActionListener(){
  676.                   public void actionPerformed(ActionEvent e){
  677.                         String n=nome.getText();
  678.                         if(n=="")return;
  679.                         n=n.substring(0,1).toUpperCase()+n.substring(1);
  680.                         nome.setText(n);
  681.                         int risp=JOptionPane.showConfirmDialog(null,
  682.                                 "Modificare \""+LS.get(matComboBox.getSelectedIndex())
  683.                                 +"\" in \""+n+"\"?","ConfermaModifica",JOptionPane.YES_NO_OPTION,
  684.                                 JOptionPane.QUESTION_MESSAGE);
  685.                     if(risp==JOptionPane.YES_OPTION)
  686.                       LS.modMateria(matComboBox.getSelectedIndex(),nome.getText());
  687.                    
  688.                     rightPanel.removeAll();
  689.                         rightPanel.add(new MaterieModPanel());
  690.                         rightPanel.repaint();
  691.                         rightPanel.validate();
  692.                   }
  693.         }
  694.       );
  695.     }
  696.    }
  697.  
  698.   class MaterieRemovePanel extends JPanel{
  699.     private static final long serialVersionUID = 1L;
  700.     JComboBox matComboBox;
  701.    
  702.     MaterieRemovePanel(){
  703.       setLayout(new BorderLayout());
  704.       JLabel titolo=new JLabel("Rimuovi Materia");
  705.       titolo.setFont(new Font("Serif",Font.BOLD+Font.ITALIC,25));
  706.       titolo.setHorizontalAlignment(SwingConstants.CENTER);
  707.       add(titolo,BorderLayout.NORTH);
  708.      
  709.       JPanel center=new JPanel(new GridLayout(3,3,3,3));
  710.       JLabel label=new JLabel("Cancellare: ");
  711.        label.setHorizontalAlignment(SwingConstants.RIGHT);
  712.       String[] materie=LS.getStringArrMaterie();
  713.        matComboBox=new JComboBox(materie);
  714.       JButton remove=new JButton("Cancella");
  715.      
  716.       for(int i=0;i<3;i++)center.add(new JPanel());
  717.       center.add(label);
  718.       center.add(matComboBox);
  719.       center.add(new JPanel());
  720.       center.add(new JPanel());
  721.       center.add(remove);
  722.      
  723.       add(center,BorderLayout.CENTER);
  724.      
  725.       remove.addActionListener(
  726.         new ActionListener(){
  727.                   public void actionPerformed(ActionEvent arg0) {
  728.                         int risp=JOptionPane.showConfirmDialog(null,
  729.                                 "Cancellare \""+LS.get(matComboBox.getSelectedIndex())+"\"?",
  730.                                 "Conferma",JOptionPane.YES_NO_OPTION,
  731.                                 JOptionPane.QUESTION_MESSAGE);
  732.                         if(risp==JOptionPane.NO_OPTION)
  733.                           return;
  734.                         LS.remove(matComboBox.getSelectedIndex());
  735.                         rightPanel.removeAll();
  736.                         if(LS.size()!=0)
  737.                           rightPanel.add(new MaterieRemovePanel());
  738.                         else
  739.                           rightPanel.add(new MaterieAddPanel());
  740.                         rightPanel.repaint();
  741.                         rightPanel.validate();
  742.                   }            
  743.         }
  744.       );
  745.     }
  746.   }
  747. }