/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package GUI; import DB.CouchDB; import Utils.GestionProgressBar; import java.util.HashSet; import java.util.Set; /** * * @author Greenlamp */ public class main extends javax.swing.JFrame { /** * Creates new form main */ private enum typeRecherche { ID, CRITERES }; private typeRecherche recherche = typeRecherche.ID; CouchDB cdb = null; GestionProgressBar gpb = null; private Set<String> listeMovies; public main() { initComponents(); gpb = new GestionProgressBar(GprogressSearch); if(recherche == typeRecherche.ID){ afficherCritere(false); } if(recherche == typeRecherche.CRITERES){ afficherCritere(true); } } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); jSeparator1 = new javax.swing.JSeparator(); Lidentifiant = new javax.swing.JLabel(); Gidentifiant = new javax.swing.JTextField(); Lacteur = new javax.swing.JLabel(); Gacteur = new javax.swing.JTextField(); Ltitre = new javax.swing.JLabel(); Gtitre = new javax.swing.JTextField(); Lmpaa = new javax.swing.JLabel(); Gmpaa = new javax.swing.JComboBox(); Lpopularite = new javax.swing.JLabel(); Gpopularite = new javax.swing.JTextField(); Lnbvotes = new javax.swing.JLabel(); Gnbvote = new javax.swing.JTextField(); Grechercher = new javax.swing.JButton(); Gafficher = new javax.swing.JButton(); GprogressSearch = new javax.swing.JProgressBar(); Ltuples = new javax.swing.JLabel(); Gtuples = new javax.swing.JTextField(); Lrealisateur = new javax.swing.JLabel(); Grealisateur = new javax.swing.JTextField(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenuItem3 = new javax.swing.JMenuItem(); jMenu2 = new javax.swing.JMenu(); jMenuItem1 = new javax.swing.JMenuItem(); jMenuItem2 = new javax.swing.JMenuItem(); jMenu3 = new javax.swing.JMenu(); jMenuItem4 = new javax.swing.JMenuItem(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setText("Recherche par identifiant"); Lidentifiant.setText("Identifiant: "); Gidentifiant.setText("100009"); Lacteur.setText("Acteur(s): "); Gacteur.setText("Patricia Vonne"); Ltitre.setText("Titre: "); Gtitre.setText("7 Minutes in Heaven"); Lmpaa.setText("MPAA: "); Lpopularite.setText("Popularité: "); Lnbvotes.setText("nb votes: "); Grechercher.setText("Rechercher"); Grechercher.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { GrechercherActionPerformed(evt); } }); Gafficher.setText("Afficher"); Ltuples.setText("nombre max de tuples: "); Lrealisateur.setText("Réalisateur(s): "); jMenu1.setText("Fichier"); jMenuItem3.setText("Quitter"); jMenuItem3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem3ActionPerformed(evt); } }); jMenu1.add(jMenuItem3); jMenuBar1.add(jMenu1); jMenu2.setText("Recherche"); jMenuItem1.setText("Par identifiant"); jMenuItem1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem1ActionPerformed(evt); } }); jMenu2.add(jMenuItem1); jMenuItem2.setText("Par critères"); jMenuItem2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem2ActionPerformed(evt); } }); jMenu2.add(jMenuItem2); jMenuBar1.add(jMenu2); jMenu3.setText("?"); jMenuItem4.setText("à propos"); jMenu3.add(jMenuItem4); jMenuBar1.add(jMenu3); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(GprogressSearch, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(Ltitre) .addComponent(Lmpaa)) .addGap(43, 43, 43) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(Gtitre) .addGroup(layout.createSequentialGroup() .addComponent(Gmpaa, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE)))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addComponent(Lidentifiant) .addGap(18, 18, 18) .addComponent(Gidentifiant, javax.swing.GroupLayout.PREFERRED_SIZE, 370, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(Lacteur) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(Gacteur, javax.swing.GroupLayout.PREFERRED_SIZE, 370, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(138, 138, 138) .addComponent(Grechercher) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(Gafficher, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(Ltuples) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(Gtuples, javax.swing.GroupLayout.PREFERRED_SIZE, 327, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(Lpopularite) .addComponent(Lnbvotes)) .addGap(23, 23, 23) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(Gnbvote, javax.swing.GroupLayout.PREFERRED_SIZE, 366, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(Gpopularite, javax.swing.GroupLayout.PREFERRED_SIZE, 366, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(layout.createSequentialGroup() .addComponent(Lrealisateur) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(Grealisateur, javax.swing.GroupLayout.PREFERRED_SIZE, 370, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) .addGroup(layout.createSequentialGroup() .addGap(173, 173, 173) .addComponent(jLabel1) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Gidentifiant, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(Lidentifiant)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Gacteur, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(Lacteur)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Lrealisateur) .addComponent(Grealisateur, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(Ltitre) .addComponent(Gtitre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Lmpaa) .addComponent(Gmpaa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Lpopularite) .addComponent(Gpopularite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Lnbvotes) .addComponent(Gnbvote, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Ltuples) .addComponent(Gtuples, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Grechercher) .addComponent(Gafficher)) .addGap(18, 18, 18) .addComponent(GprogressSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); java.awt.Dimension dialogSize = getSize(); setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2); }// </editor-fold>//GEN-END:initComponents private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed if(recherche == typeRecherche.CRITERES){ afficherCritere(false); recherche = typeRecherche.ID; } }//GEN-LAST:event_jMenuItem1ActionPerformed private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed if(recherche == typeRecherche.ID){ afficherCritere(true); recherche = typeRecherche.CRITERES; } }//GEN-LAST:event_jMenuItem2ActionPerformed private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed dispose(); }//GEN-LAST:event_jMenuItem3ActionPerformed private void GrechercherActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GrechercherActionPerformed cdb = new CouchDB(gpb); //Critere: Titre if(recherche == typeRecherche.ID){ if(!Gidentifiant.getText().isEmpty()){ listeMovies = cdb.getById(Integer.parseInt(Gidentifiant.getText()), null); } } if(recherche == typeRecherche.CRITERES){ Set<String> listeMovies = null; if(!Gacteur.getText().isEmpty()){ listeMovies = cdb.getByActor(Gacteur.getText(), listeMovies); } if(!Gtitre.getText().isEmpty()){ listeMovies = cdb.getByName(Gtitre.getText(), listeMovies); } } System.out.println("Taille: " + listeMovies.size()); for(String id: listeMovies){ System.out.println("id: " + id); } }//GEN-LAST:event_GrechercherActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new main().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JTextField Gacteur; private javax.swing.JButton Gafficher; private javax.swing.JTextField Gidentifiant; private javax.swing.JComboBox Gmpaa; private javax.swing.JTextField Gnbvote; private javax.swing.JTextField Gpopularite; private javax.swing.JProgressBar GprogressSearch; private javax.swing.JTextField Grealisateur; private javax.swing.JButton Grechercher; private javax.swing.JTextField Gtitre; private javax.swing.JTextField Gtuples; private javax.swing.JLabel Lacteur; private javax.swing.JLabel Lidentifiant; private javax.swing.JLabel Lmpaa; private javax.swing.JLabel Lnbvotes; private javax.swing.JLabel Lpopularite; private javax.swing.JLabel Lrealisateur; private javax.swing.JLabel Ltitre; private javax.swing.JLabel Ltuples; private javax.swing.JLabel jLabel1; private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenu jMenu3; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenuItem jMenuItem1; private javax.swing.JMenuItem jMenuItem2; private javax.swing.JMenuItem jMenuItem3; private javax.swing.JMenuItem jMenuItem4; private javax.swing.JSeparator jSeparator1; // End of variables declaration//GEN-END:variables private void afficherCritere(boolean value) { boolean contraire = !value; Lidentifiant.setVisible(contraire); Gidentifiant.setVisible(contraire); Lacteur.setVisible(value); Gacteur.setVisible(value); Lrealisateur.setVisible(value); Grealisateur.setVisible(value); Ltitre.setVisible(value); Gtitre.setVisible(value); Lmpaa.setVisible(value); Gmpaa.setVisible(value); Lpopularite.setVisible(value); Gpopularite.setVisible(value); Lnbvotes.setVisible(value); Gnbvote.setVisible(value); Ltuples.setVisible(value); Gtuples.setVisible(value); } }