package viewGraphique;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.SpinnerListModel;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.JSpinner.DateEditor;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.text.MaskFormatter;
public class InfoPopupNouvelleSeance extends JDialog implements ActionListener, ChangeListener {
private JLabel lCoef = null;
private JLabel lDiff = null;
private JLabel lHeure = null;
private JLabel lheurePM = null;
private JSpinner sCoef = null;
private JSpinner sDiff = null;
private JSpinner sHeure = null;
private JSpinner sHeurePM = null;
private JCheckBox sbAvance = null;
private JButton bValider = null;
private JFrame parent = null;
public InfoPopupNouvelleSeance(JFrame frame){
super(frame);
this.parent = frame;
buildFrame();
}
private void buildFrame() {
this.setSize(550, 400);
this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
this.setLocationRelativeTo(this.parent);
this.setResizable(false);
this.setLayout(null);
this.lCoef = new JLabel("Coefficient de la mar�e : ");
this.lCoef.setBounds(20, 20, 150, 30);
this.lDiff = new JLabel("Difficult� de la s�ance : ");
this.lDiff.setBounds(20, 60, 150, 30);
this.lHeure = new JLabel("Heure de d�but : ");
this.lHeure.setBounds(20, 200, 150, 30);
this.lheurePM = new JLabel("Heure de d�but ( en PM+X ) :");
this.lheurePM.setBounds(20, 240, 180, 30);
String[] dataCoef = {"45", "60", "90"};
SpinnerModel modelCoef = new SpinnerListModel(dataCoef);
this.sCoef = new JSpinner(modelCoef);
this.sCoef.setBounds(180, 20, 100, 30);
String[] data = {"Initiation", "Entrainement"};
SpinnerModel model = new SpinnerListModel(data);
this.sDiff = new JSpinner(model);
this.sDiff.setBounds(180, 60, 100, 30);
this.sbAvance = new JCheckBox("Activer les options avanc�es");
this.sbAvance.setBounds(300, 20, 200, 30);
this.sbAvance.addChangeListener(this);
this.bValider = new JButton("Valider");
this.bValider.setBounds(220, 300, 100, 30);
this.bValider.addActionListener(this);
String[] dataHeure = new String[24];
for(int i = 0; i < 24; i++){
dataHeure[i] = String.valueOf(i);
}
SpinnerModel modelHeure = new SpinnerListModel(dataHeure);
this.sHeure = new JSpinner(modelHeure);
this.sHeure.setBounds(220, 200, 150, 30);
this.sHeure.setEnabled(false);
String[] dataHeurePM = new String[12];
for(int i = 0; i < 12; i++){
dataHeurePM[i] = String.valueOf(i);
}
SpinnerModel modelHeurePM = new SpinnerListModel(dataHeurePM);
this.sHeurePM = new JSpinner(modelHeurePM);
this.sHeurePM.setBounds(220, 240, 150, 30);
this.sHeurePM.setEnabled(false);
this.add(this.lCoef);
this.add(this.lDiff);
this.add(this.lHeure);
this.add(this.lheurePM);
this.add(this.sbAvance);
this.add(this.sCoef);
this.add(this.sDiff);
this.add(this.sHeure);
this.add(this.sHeurePM);
this.add(this.bValider);
}
@Override
public void setVisible(boolean b) {
super.setVisible(b);
// Remettre � 0 les inputs
}
@Override
public void actionPerformed(ActionEvent arg0) {
int diff = -1;
if(sDiff.getValue().equals("Initiation")){
diff = 0;
} else if(sDiff.getValue().equals("Entrainement")){
diff = 1;
}
if(diff != -1){
if(!this.sbAvance.isSelected()){
((Fenetre)this.parent).notifyDemarrerNouvelleSeance(Integer.valueOf((String) this.sCoef.getValue()), diff);
} else {
((Fenetre)this.parent).notifyDemarrerNouvelleSeance(Integer.valueOf((String) this.sCoef.getValue()), diff, Integer.valueOf((String) this.sHeure.getValue()), Integer.valueOf((String) this.sHeurePM.getValue()));
}
}
}
@Override
public void stateChanged(ChangeEvent arg0) {
if(arg0.getSource() == this.sbAvance){
if(this.sbAvance.isSelected()){
this.sHeure.setEnabled(true);
this.sHeurePM.setEnabled(true);
} else {
this.sHeure.setEnabled(false);
this.sHeurePM.setEnabled(false);
}
}
}
}