package com.vgo.movie.ecran;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import com.vgo.movie.data.DatabaseDAO;
import com.vgo.movie.domain.Generique;
import com.vgo.movie.domain.Movie;
import com.vgo.movie.util.Libelle;
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class AjoutFilm extends javax.swing.JDialog {
private static final long serialVersionUID = 1L;
private JLabel jLabelNomFilm;
private JLabel jLabelLangue;
private JComboBox jComboBoxLangue;
private JComboBox jComboBoxQualite;
private JComboBox jComboBoxCompression;
private JLabel jLabelQualite;
private JLabel jLabelCompression;
private JLabel jLabelInfoNumeroMedia;
private JTextField jTextNumeroMedia;
private JLabel jLabelNumeroMedia;
private JComboBox jComboBoxTypeMedia;
private JLabel jLabelTypeMedia;
private JTextField jTextNomFilm;
private Integer dernierNumMedia;
private JButton jButtonAjouter;
private Main localParent;
public AjoutFilm(Main parent) {
super(parent);
localParent = parent;
initGUI();
initLibelle();
}
private void initGUI() {
try {
{
getContentPane().setLayout(null);
{
jLabelNomFilm = new JLabel();
getContentPane().add(jLabelNomFilm);
jLabelNomFilm.setBounds(7, 28, 91, 28);
}
{
jTextNomFilm = new JTextField();
getContentPane().add(jTextNomFilm);
jTextNomFilm.setBounds(133, 28, 476, 28);
}
{
jLabelTypeMedia = new JLabel();
getContentPane().add(jLabelTypeMedia);
jLabelTypeMedia.setBounds(7, 63, 112, 28);
}
{
ComboBoxModel jComboBoxTypeMediaModel = new DefaultComboBoxModel(
new String[] { });
jComboBoxTypeMedia = new JComboBox();
getContentPane().add(jComboBoxTypeMedia);
jComboBoxTypeMedia.setModel(jComboBoxTypeMediaModel);
jComboBoxTypeMedia.setBounds(133, 63, 476, 28);
remplirListeMedia();
}
{
jLabelNumeroMedia = new JLabel();
getContentPane().add(jLabelNumeroMedia);
jLabelNumeroMedia.setBounds(7, 105, 112, 28);
}
{
jTextNumeroMedia = new JTextField();
getContentPane().add(jTextNumeroMedia);
jTextNumeroMedia.setBounds(133, 105, 84, 28);
}
{
jLabelInfoNumeroMedia = new JLabel();
getContentPane().add(jLabelInfoNumeroMedia);
jLabelInfoNumeroMedia.setBounds(224, 105, 392, 28);
jLabelInfoNumeroMedia.setFont(new java.awt.Font("Tahoma",0,9));
}
{
jLabelLangue = new JLabel();
getContentPane().add(jLabelLangue);
jLabelLangue.setBounds(7, 147, 112, 28);
}
{
ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(
new String[] {});
jComboBoxLangue = new JComboBox();
getContentPane().add(jComboBoxLangue);
jComboBoxLangue.setModel(jComboBox1Model);
jComboBoxLangue.setBounds(133, 147, 476, 28);
remplirListeLangue();
}
{
jLabelCompression = new JLabel();
getContentPane().add(jLabelCompression);
jLabelCompression.setBounds(7, 189, 112, 28);
}
{
ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(
new String[] {});
jComboBoxCompression = new JComboBox();
getContentPane().add(jComboBoxCompression);
jComboBoxCompression.setModel(jComboBox1Model);
jComboBoxCompression.setBounds(133, 189, 476, 28);
remplirListeCompression();
}
{
jLabelQualite = new JLabel();
getContentPane().add(jLabelQualite);
jLabelQualite.setBounds(7, 231, 112, 28);
}
{
ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(
new String[] {});
jComboBoxQualite = new JComboBox();
getContentPane().add(jComboBoxQualite);
jComboBoxQualite.setModel(jComboBox1Model);
jComboBoxQualite.setBounds(133, 231, 476, 28);
remplirListeQualite();
}
{
jButtonAjouter = new JButton();
getContentPane().add(jButtonAjouter);
jButtonAjouter.setBounds(245, 280, 161, 28);
jButtonAjouter.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButtonAjouterActionPerformed(evt);
}
});
}
recupDernierNumMedia();
}
this.setSize(631, 363);
} catch (Exception e) {
e.printStackTrace();
}
}
private void initLibelle(){
jLabelNomFilm.setText(Libelle.getLibelle("nomFilm"));
jLabelTypeMedia.setText(Libelle.getLibelle("typeMedia"));
jLabelNumeroMedia.setText(Libelle.getLibelle("numeroMedia"));
jLabelLangue.setText(Libelle.getLibelle("langue"));
jLabelCompression.setText(Libelle.getLibelle("compression"));
jLabelQualite.setText(Libelle.getLibelle("qualite"));
jButtonAjouter.setText(Libelle.getLibelle("bouttonAjouter"));
}
private void remplirListeMedia(){
try {
List tmpList = DatabaseDAO.selectAllMedias();
Iterator tmpIterator = tmpList.listIterator();
while(tmpIterator.hasNext()){
jComboBoxTypeMedia.addItem(((Generique)tmpIterator.next()).getCode());
}
} catch (SQLException e) {
JOptionPane.showOptionDialog(
SwingUtilities.getWindowAncestor(this),
Libelle.getLibelle("erreurInitialisationListeTypeMedia"),
Libelle.getLibelle("erreur") ,
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null,
null,
null);
}
}
private void remplirListeQualite(){
try {
List tmpList = DatabaseDAO.selectAllQualites();
Iterator tmpIterator = tmpList.listIterator();
while(tmpIterator.hasNext()){
jComboBoxQualite.addItem(((Generique)tmpIterator.next()).getCode());
}
} catch (SQLException e) {
JOptionPane.showOptionDialog(
SwingUtilities.getWindowAncestor(this),
Libelle.getLibelle("erreurInitialisationListeQualite"),
Libelle.getLibelle("erreur"),
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null,
null,
null);
}
}
private void remplirListeLangue(){
try {
List tmpList = DatabaseDAO.selectAllLangues();
Iterator tmpIterator = tmpList.listIterator();
while(tmpIterator.hasNext()){
jComboBoxLangue.addItem(((Generique)tmpIterator.next()).getCode());
}
} catch (SQLException e) {
JOptionPane.showOptionDialog(
SwingUtilities.getWindowAncestor(this),
Libelle.getLibelle("erreurInitialisationListeLangue"),
Libelle.getLibelle("erreur"),
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null,
null,
null);
}
}
private void remplirListeCompression(){
try {
List tmpList = DatabaseDAO.selectAllCompressions();
Iterator tmpIterator = tmpList.listIterator();
while(tmpIterator.hasNext()){
jComboBoxCompression.addItem(((Generique)tmpIterator.next()).getCode());
}
} catch (SQLException e) {
JOptionPane.showOptionDialog(
SwingUtilities.getWindowAncestor(this),
Libelle.getLibelle("erreurInitialisationListeCompression"),
Libelle.getLibelle("erreur"),
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null,
null,
null);
}
}
private void recupDernierNumMedia(){
try {
dernierNumMedia = ((Movie)DatabaseDAO.recupDernierNumMedia()).getIdMedia();
} catch (SQLException e) {
dernierNumMedia = 0;
}
jLabelInfoNumeroMedia.setText(Libelle.getLibelle("dernierNumeroMedia", dernierNumMedia.toString()));
}
private void jButtonAjouterActionPerformed(ActionEvent evt) {
/*Ajout d'un film dans la base de donn�es*/
Movie tmpMovie = new Movie();
boolean controlOk=false;
if(jTextNomFilm.getText().trim().equals("")){
JOptionPane.showOptionDialog(
SwingUtilities.getWindowAncestor(this),
Libelle.getLibelle("erreurNomFilmVide") ,
Libelle.getLibelle("erreur"),
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null,
null,
null);
}
else{
tmpMovie.setNom(jTextNomFilm.getText());
tmpMovie.setType((String)jComboBoxTypeMedia.getSelectedItem());
tmpMovie.setLangue((String)jComboBoxLangue.getSelectedItem());
tmpMovie.setCompression((String)jComboBoxCompression.getSelectedItem());
tmpMovie.setQualite((String)jComboBoxQualite.getSelectedItem());
try {
if(jTextNumeroMedia.getText().trim().equals("")){
//Dans ce cas on ajoute sur un nouveau m�dia
tmpMovie.setIdMedia(dernierNumMedia+1);
controlOk = true;
}
else{
Integer tmpNumMedia = new Integer(jTextNumeroMedia.getText().trim());
if(tmpNumMedia > dernierNumMedia ){
JOptionPane.showOptionDialog(
SwingUtilities.getWindowAncestor(this),
Libelle.getLibelle("dernierNumeroMedia",dernierNumMedia.toString()),
Libelle.getLibelle("erreur"),
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null,
null,
null);
}
else{
tmpMovie.setIdMedia(tmpNumMedia);
controlOk = true;
}
}
} catch (NumberFormatException e) {
JOptionPane.showOptionDialog(
SwingUtilities.getWindowAncestor(this),
Libelle.getLibelle("erreurNumMediaNonEntier"),
Libelle.getLibelle("erreur"),
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null,
null,
null);
}
}
/*A ce stade le film peut �tre ajout�*/
if(controlOk){
try {
DatabaseDAO.insertMovie(tmpMovie);
JOptionPane.showOptionDialog(
SwingUtilities.getWindowAncestor(this),
Libelle.getLibelle("insertionFilmOk",tmpMovie.getNom()),
"Insertion r�ussie",
JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
null,
null);
} catch (SQLException e) {
JOptionPane.showOptionDialog(
SwingUtilities.getWindowAncestor(this),
Libelle.getLibelle("erreurInsertionFilms"),
Libelle.getLibelle("erreur"),
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null,
null,
null);
}
recupDernierNumMedia();
jTextNumeroMedia.setText(dernierNumMedia.toString());
jTextNomFilm.setText("");
try {
tmpMovie = (Movie)DatabaseDAO.recupDernierFilm();
Object[] data = {new Integer(tmpMovie.getId()),
tmpMovie.getNom(),
tmpMovie.getType(),
new Integer(tmpMovie.getIdMedia()),
tmpMovie.getStatut(),
tmpMovie.getLangue(),
tmpMovie.getCompression(),
tmpMovie.getQualite()};
localParent.getListFilmModel().addRow(data);
} catch (SQLException e) {
JOptionPane.showOptionDialog(
SwingUtilities.getWindowAncestor(this),
Libelle.getLibelle("erreurRecupInfoFilmInsert"),
Libelle.getLibelle("erreur"),
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null,
null,
null);
}
}
}
}