/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package GUIS; import CDB.Backdrops; import CDB.Cast; import CDB.Genres; import CDB.Movies; import DB.CouchDbAccess; import Helpers.EasyFile; import Helpers.SwingUtils; import java.net.MalformedURLException; import java.net.URL; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.ImageIcon; /** * * @author Greenlamp */ public class Details extends javax.swing.JDialog { /** * Creates new form Details */ private String id = null; private CouchDbAccess couch = null; private String urlWebfs = null; public Details(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); } public Details(java.awt.Frame parent, boolean modal, String key, CouchDbAccess couch) { super(parent, modal); initComponents(); String hostWebfs = EasyFile.getConfig("Configs", "webfs_host"); String portWebFs = EasyFile.getConfig("Configs", "webfs_port"); urlWebfs = "http://" + hostWebfs + ":" + portWebFs + "/"; this.id = key; this.couch = couch; Movies movie = couch.getMovie(this.id); fillPage(movie); } /** * 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() { jLabel3 = new javax.swing.JLabel(); Lcertification = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); LdateSortie = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); Lpopularite = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); LnbVote = new javax.swing.JLabel(); jLabel11 = new javax.swing.JLabel(); Ladult = new javax.swing.JLabel(); jLabel13 = new javax.swing.JLabel(); Lbudget = new javax.swing.JLabel(); jLabel15 = new javax.swing.JLabel(); Lrating = new javax.swing.JLabel(); jLabel17 = new javax.swing.JLabel(); Lduree = new javax.swing.JLabel(); jLabel19 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); Gresume = new javax.swing.JTextArea(); jLabel20 = new javax.swing.JLabel(); jScrollPane2 = new javax.swing.JScrollPane(); Gactors = new javax.swing.JList(); jLabel21 = new javax.swing.JLabel(); jScrollPane3 = new javax.swing.JScrollPane(); Gdirectors = new javax.swing.JList(); jLabel22 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); Limage = new javax.swing.JLabel(); jScrollPane4 = new javax.swing.JScrollPane(); Lgenre = new javax.swing.JList(); jLabel1 = new javax.swing.JLabel(); Lid = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); jLabel3.setText("Certification: "); Lcertification.setText("Lcertification"); jLabel5.setText("Date de sortie: "); LdateSortie.setText("LdateSortie"); jLabel7.setText("Popularité: "); Lpopularite.setText("Lpopularite"); jLabel9.setText("Nombre de votes: "); LnbVote.setText("LnbVote"); jLabel11.setText("adult: "); Ladult.setText("Ladult"); jLabel13.setText("budget: "); Lbudget.setText("Lbudget"); jLabel15.setText("Rating: "); Lrating.setText("Lrating"); jLabel17.setText("Durée: "); Lduree.setText("Lduree"); jLabel19.setText("Résumé:"); Gresume.setColumns(20); Gresume.setRows(5); jScrollPane1.setViewportView(Gresume); jLabel20.setText("Actors: "); jScrollPane2.setViewportView(Gactors); jLabel21.setText("Directors:"); jScrollPane3.setViewportView(Gdirectors); jLabel22.setText("Genre: "); jLabel2.setText("Image:"); Limage.setText("Limage"); jScrollPane4.setViewportView(Lgenre); jLabel1.setText("Id: "); Lid.setText("Lid"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jScrollPane1) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2) .addComponent(Limage) .addGroup(layout.createSequentialGroup() .addComponent(jLabel22) .addGap(57, 57, 57) .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel9) .addComponent(jLabel7) .addComponent(jLabel11) .addComponent(jLabel13) .addComponent(jLabel15) .addComponent(jLabel17)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(Lbudget) .addComponent(Ladult) .addComponent(Lpopularite) .addComponent(LnbVote) .addComponent(Lrating) .addComponent(Lduree))) .addComponent(jLabel19) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel5) .addComponent(jLabel3) .addComponent(jLabel1)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(Lid) .addComponent(Lcertification) .addComponent(LdateSortie)))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 218, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel21) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(jLabel20) .addGap(151, 151, 151)) .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE))) .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel20) .addComponent(jLabel1) .addComponent(Lid)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(Lcertification)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5) .addComponent(LdateSortie)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel7) .addComponent(Lpopularite)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel9) .addComponent(LnbVote)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel11) .addComponent(Ladult)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel13) .addComponent(Lbudget)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Lrating) .addComponent(jLabel15)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Lduree) .addComponent(jLabel17)) .addGap(6, 6, 6) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel22) .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(5, 5, 5) .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(Limage) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel19)) .addGroup(layout.createSequentialGroup() .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(11, 11, 11) .addComponent(jLabel21) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(27, Short.MAX_VALUE)) ); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); setBounds((screenSize.width-738)/2, (screenSize.height-606)/2, 738, 606); }// </editor-fold>//GEN-END:initComponents /** * @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(Details.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Details.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Details.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Details.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() { Details dialog = new Details(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.JList Gactors; private javax.swing.JList Gdirectors; private javax.swing.JTextArea Gresume; private javax.swing.JLabel Ladult; private javax.swing.JLabel Lbudget; private javax.swing.JLabel Lcertification; private javax.swing.JLabel LdateSortie; private javax.swing.JLabel Lduree; private javax.swing.JList Lgenre; private javax.swing.JLabel Lid; private javax.swing.JLabel Limage; private javax.swing.JLabel LnbVote; private javax.swing.JLabel Lpopularite; private javax.swing.JLabel Lrating; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel17; private javax.swing.JLabel jLabel19; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel20; private javax.swing.JLabel jLabel21; private javax.swing.JLabel jLabel22; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel9; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JScrollPane jScrollPane4; // End of variables declaration//GEN-END:variables private void fillPage(Movies movie) { this.setTitle(movie.getName()); Lid.setText(String.valueOf(movie.getId())); Lcertification.setText(movie.getCertification()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf2 = new SimpleDateFormat("dd/MM/yyyy"); Date dateInit = null; String dateApres = null; try { dateInit = sdf.parse(movie.getReleased()); dateApres = sdf2.format(dateInit); } catch (ParseException ex) { Logger.getLogger(Details.class.getName()).log(Level.SEVERE, null, ex); } LdateSortie.setText(dateApres); Lpopularite.setText(String.valueOf(movie.getPopularity())); LnbVote.setText(String.valueOf(movie.getVotes())); Ladult.setText(movie.isAdult() == true ? "Oui" : "Non"); Lbudget.setText(String.valueOf(movie.getBudget())); Lrating.setText(String.valueOf(movie.getRating())); Lduree.setText(String.valueOf(movie.getRuntime())); for(Genres genre : movie.getGenres()){ SwingUtils.addToList(Lgenre, genre.getName()); } for(Cast cast : movie.getCast()){ if(cast.getJob().equals("Actor")){ SwingUtils.addToList(Gactors, cast.getName()); }else if(cast.getJob().equals("Director")){ SwingUtils.addToList(Gdirectors, cast.getName()); } } String resume = movie.getOverview(); if(resume != null){ resume = movie.getOverview().replace(".", ".\n"); } Gresume.setText(resume); Backdrops bd = null; try{ bd = movie.getBackdrops().getFirst(); }catch(Exception ex){ jLabel2.setText(null); Limage.setText(null); return; } String urlImage = urlWebfs + movie.getId() + ".jpg"; try { URL url = new URL(urlImage); ImageIcon imageTemp = new ImageIcon(url); Limage.setIcon(imageTemp); Limage.setText(null); } catch (MalformedURLException ex) { Logger.getLogger(Details.class.getName()).log(Level.SEVERE, null, ex); } } }