streaming.swing.JPanelListFilm.java Source code

Java tutorial

Introduction

Here is the source code for streaming.swing.JPanelListFilm.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package streaming.swing;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import streaming.entity.Film;
import streaming.service.FilmService;

/**
 *
 * @author admin
 */

@Component
public class JPanelListFilm extends javax.swing.JPanel {

    @Autowired
    private TableModelListFilm tmListeFilm;

    @Autowired
    private FilmService fServ;

    @Autowired
    private JDialogEditFilm jdialogEditFilm;

    public void rafraichitJTable() {

        tmListeFilm.rafraichir();
        jTableListFilm.setModel(tmListeFilm);
        jTableListFilm.validate();
        jTableListFilm.repaint();
    }

    /**
     * Creates new form JPanelFilmEdit
     */
    public JPanelListFilm() {
        initComponents();

    }

    /**
     * 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() {

        jToolBarEditFilm = new javax.swing.JToolBar();
        jButtonNouveauFilm = new javax.swing.JButton();
        jButtonSupprimer = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableListFilm = new javax.swing.JTable();

        setLayout(new java.awt.BorderLayout());

        jToolBarEditFilm.setRollover(true);

        jButtonNouveauFilm.setText("Nouveau Film");
        jButtonNouveauFilm.setFocusable(false);
        jButtonNouveauFilm.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonNouveauFilm.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButtonNouveauFilm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonNouveauFilmActionPerformed(evt);
            }
        });
        jToolBarEditFilm.add(jButtonNouveauFilm);

        jButtonSupprimer.setText("Supprimer");
        jButtonSupprimer.setFocusable(false);
        jButtonSupprimer.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonSupprimer.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButtonSupprimer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSupprimerActionPerformed(evt);
            }
        });
        jToolBarEditFilm.add(jButtonSupprimer);

        add(jToolBarEditFilm, java.awt.BorderLayout.NORTH);

        jTableListFilm
                .setModel(new javax.swing.table.DefaultTableModel(
                        new Object[][] { { null, null, null, null }, { null, null, null, null },
                                { null, null, null, null }, { null, null, null, null } },
                        new String[] { "Title 1", "Title 2", "Title 3", "Title 4" }));
        jTableListFilm.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableListFilmMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTableListFilm);

        add(jScrollPane1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonNouveauFilmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNouveauFilmActionPerformed
        jdialogEditFilm.setJplf(this);
        jdialogEditFilm.initialiser();
        jdialogEditFilm.setVisible(true);

        this.rafraichitJTable();
    }//GEN-LAST:event_jButtonNouveauFilmActionPerformed

    private void jButtonSupprimerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSupprimerActionPerformed
        int i = jTableListFilm.getSelectedRow();
        if (i == -1) {
            return;
        }

        Film f = tmListeFilm.getFilm().get(i);
        fServ.supprimer(f.getId());

        rafraichitJTable();
    }//GEN-LAST:event_jButtonSupprimerActionPerformed

    private void jTableListFilmMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableListFilmMouseClicked
        if (evt.getClickCount() == 2) {

            int i = jTableListFilm.getSelectedRow();
            Film f = tmListeFilm.getFilm().get(i);

            JDialogFilm jdg = new JDialogFilm(null, true, f);

            jdg.setVisible(true);
        }
    }//GEN-LAST:event_jTableListFilmMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonNouveauFilm;
    private javax.swing.JButton jButtonSupprimer;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableListFilm;
    private javax.swing.JToolBar jToolBarEditFilm;
    // End of variables declaration//GEN-END:variables
}