/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package GUIS; import CDB.Movies; import DB.CouchDbAccess; import DB.OracleAccess; import java.util.LinkedList; import java.util.Random; /** * * @author Greenlamp */ public class Send extends javax.swing.JDialog { /** * Creates new form Send */ LinkedList<String> listeId = null; OracleAccess oracle = null; private CouchDbAccess couch = null; int physique = 0; int digitale = 0; public Send(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); } Send(java.awt.Frame parent, boolean modal, LinkedList<String> listeIdEffective, CouchDbAccess couch) { super(parent, modal); initComponents(); this.listeId = listeIdEffective; this.couch = couch; LnbFilms.setText(String.valueOf(listeId.size())); Gphysique.setText("1"); Gdigitale.setText("0"); oracle = new OracleAccess(); } /** * 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(); LnbFilms = new javax.swing.JLabel(); jSeparator1 = new javax.swing.JSeparator(); jLabel3 = new javax.swing.JLabel(); LnouveauFilm = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); Lerreur = new javax.swing.JLabel(); Benvoyer = new javax.swing.JButton(); jSeparator2 = new javax.swing.JSeparator(); jLabel2 = new javax.swing.JLabel(); Gphysique = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); Gdigitale = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); jLabel1.setText("Nombre de films à insérer: "); LnbFilms.setText("0"); jLabel3.setText("Nouveau film:"); LnouveauFilm.setText("0"); jLabel7.setText("Erreur:"); Lerreur.setText("0"); Benvoyer.setText("Envoyer"); Benvoyer.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { BenvoyerActionPerformed(evt); } }); jLabel2.setText("Copie Physique: "); jLabel4.setText("Copie Digitale:"); jButton1.setText("Distribution normale"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); 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) .addComponent(jSeparator2) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel4) .addComponent(jLabel2)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(Gphysique) .addComponent(Gdigitale))) .addGroup(layout.createSequentialGroup() .addComponent(Benvoyer) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE) .addComponent(jButton1)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(LnbFilms)) .addGroup(layout.createSequentialGroup() .addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(LnouveauFilm)) .addGroup(layout.createSequentialGroup() .addComponent(jLabel7) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(Lerreur))) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(LnbFilms)) .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(jLabel3) .addComponent(LnouveauFilm)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel7) .addComponent(Lerreur)) .addGap(46, 46, 46) .addComponent(jSeparator2, 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(jLabel2) .addComponent(Gphysique, 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(jLabel4) .addComponent(Gdigitale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Benvoyer) .addComponent(jButton1)) .addContainerGap()) ); 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 BenvoyerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BenvoyerActionPerformed physique = (Gphysique.getText().isEmpty() ? 0 : Integer.parseInt(Gphysique.getText())); digitale = (Gdigitale.getText().isEmpty() ? 0 : Integer.parseInt(Gdigitale.getText())); new Thread(){ public void run(){ doJob(); } }.start(); }//GEN-LAST:event_BenvoyerActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed float mean = (float)4.2; float ecartType = (float) 5.0; float[] nbObtenu = distributionNormale(mean, ecartType); int nb1 = (int)nbObtenu[0]; int nb2 = (int)nbObtenu[1]; Gphysique.setText(String.valueOf(nb1)); Gdigitale.setText(String.valueOf(nb2)); }//GEN-LAST:event_jButton1ActionPerformed /** * @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(Send.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Send.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Send.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Send.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the dialog */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { Send dialog = new Send(new javax.swing.JFrame(), true); dialog.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); dialog.setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton Benvoyer; private javax.swing.JTextField Gdigitale; private javax.swing.JTextField Gphysique; private javax.swing.JLabel Lerreur; private javax.swing.JLabel LnbFilms; private javax.swing.JLabel LnouveauFilm; private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel7; private javax.swing.JSeparator jSeparator1; private javax.swing.JSeparator jSeparator2; // End of variables declaration//GEN-END:variables private void doJob() { int cpt = 0; int cptErreur = 0; for(String id : listeId){ Movies movie = couch.getMovie(id); oracle.initCall("Package_CB", "insertMovie", 21); int retour = oracle.insertMovie(movie, physique, digitale); if(retour == 1){ cpt++; LnouveauFilm.setText(String.valueOf(cpt)); }else if(retour == -1){ cptErreur++; Lerreur.setText(String.valueOf(cptErreur)); } } } private float[] distributionNormale(float mean, float ecartType) { Random rand = new Random(); float theta = 2 * (float) Math.PI * rand.nextFloat(); float rho = (float) Math.sqrt(-2 * Math.log(1 - rand.nextFloat())); float scale = ecartType * rho; float x = (float) (mean + scale * Math.cos(theta)); float y = (float) (mean + scale * Math.sin(theta)); if(x < 0) x = x * -1; if(y < 0) y = y * -1; float[] result = {x, y}; return result; } }