1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
| public class ChoixAnnee extends JFrame implements ActionListener, WindowListener{
/**
* serialVersionUID
*/
private static final long serialVersionUID = 1L;
private JList liste;
ListeAnneeModel annee;
private JButton creer;
private JPanel panneau1;
private JLabel label;
private JCheckBox saturdayCheck;
private JCheckBox sundayCheck;
private JCheckBox ferieCheck;
private Serialiser serialise;
private Accueil accueil;
public ChoixAnnee(Accueil accueil){
this.accueil = accueil;
setTitle("Gestion d'emploi du temps");
initUI();
//Cases à cocher pour la gestion des jours ouvrés / non ouvrés
JLabel holidays = new JLabel("Jours Non-ouvrés");
holidays.setFont(new Font(null, Font.BOLD, 12));
JPanel checkBox = new JPanel();
checkBox.add(holidays);
saturdayCheck = new JCheckBox("Samedi");
sundayCheck = new JCheckBox("Dimanche");
ferieCheck = new JCheckBox("Jours Fériés");
checkBox.add(saturdayCheck);
checkBox.add(sundayCheck);
checkBox.add(ferieCheck);
panneau1 = new JPanel();
annee = new ListeAnneeModel();
liste = new JList(annee);
creer = new JButton("Créer le calendrier");
label = new JLabel("Veuillez choisir une année scolaire pour créer le planning");
label.setFont(new Font(null, Font.BOLD, 16));
liste.setSelectedIndex(5);
liste.setSelectionMode(ListSelectionModel.SINGLE_SELECTION) ;
JScrollPane ascenseur = new JScrollPane(liste);
ascenseur.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
panneau1.setLayout(new BorderLayout());
panneau1.add(BorderLayout.CENTER, ascenseur);
panneau1.add(BorderLayout.SOUTH, checkBox);
add(label, BorderLayout.NORTH);
add(panneau1);
add(creer, BorderLayout.SOUTH);
this.addWindowListener(this);
creer.addActionListener(this);
}
private void initUI() {
setSize(500,250);
setLocationRelativeTo(null);
}
public void actionPerformed(ActionEvent event) {
Object source = event.getSource();
boolean saturday = false;
boolean sunday = false;
boolean ferie = false;
if (source.equals(creer)) {
if(saturdayCheck.isSelected()){
saturday = true;
}
if(sundayCheck.isSelected()){
sunday = true;
}
if(ferieCheck.isSelected()){
ferie = true;
}
Object valeur = liste.getSelectedValue();
Calendrier calendrier= new Calendrier();
Annee uneAnnee = new Annee();
uneAnnee = uneAnnee.convertirUneAnnee(valeur.toString());
calendrier.setUneAnnee(uneAnnee);
calendrier.setSamediOuvrable(saturday);
calendrier.setDimancheOuvrable(sunday);
calendrier.setFerieOuvrable(ferie);
int anneeSuivante = uneAnnee.anneeChoisit(uneAnnee);
anneeSuivante = anneeSuivante +1;
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("/Documents"));
int retrival = chooser.showSaveDialog(null);
if (retrival == JFileChooser.APPROVE_OPTION) {
try {
String fw = (chooser.getSelectedFile()+"_Vierge_"+uneAnnee.getAnnee()+"_"+anneeSuivante+".dat");
serialise = new Serialiser(fw, calendrier);
serialise.serialiser();
JOptionPane.showMessageDialog(this,"Le fichier a été enregister dans " +fw+ " !", "Information", JOptionPane.INFORMATION_MESSAGE);
} catch (Exception ex) {
ex.printStackTrace();
}
}
new CalendarWeekViewer(calendrier);
this.setVisible(false);
}
}
@Override
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowClosed(WindowEvent arg0) {
accueil.setVisible(true);
}
@Override
public void windowClosing(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub
}
} |
Partager