streaming.swing.JPanelListeSeries.java Source code

Java tutorial

Introduction

Here is the source code for streaming.swing.JPanelListeSeries.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 java.awt.BorderLayout;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import javax.swing.JPanel;
import javax.swing.text.html.parser.DTDConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import streaming.entity.Pays;
import streaming.entity.Saison;
import streaming.entity.Serie;
import streaming.service.SerieService;

/**
 *
 * @author admin
 */
@Component
public class JPanelListeSeries extends javax.swing.JPanel {

    @Autowired
    private SerieService serieService;
    @Autowired
    TableModelListeSerie tableModelListeSerie;
    @Autowired
    JDialogSeries jDialogSeries;

    public JPanelListeSaison jpSaison = null;
    public JPanelListeSeries jpSerie = null;

    public void supprimerPanneau() {
        if (jpSerie == null) {
            return;
        }
        this.remove(jpSerie);

    }

    public JPanelListeSeries() {

        initComponents();
        //        rafraichitJtable();
    }

    public void rafraichitJtable() {
        tableModelListeSerie.initialiser();
        jtSerie.setModel(tableModelListeSerie);
        jtSerie.repaint();
    }

    /**
     * Creates new form JPanelListeSeries
     */

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

        jToolBar1 = new javax.swing.JToolBar();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtSerie = new javax.swing.JTable();
        jButton3 = new javax.swing.JButton();

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

        jToolBar1.setRollover(true);

        jButton1.setText("Ajouter une srie");
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton1);

        jButton2.setText("Supprimer une Srie");
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton2);

        add(jToolBar1, java.awt.BorderLayout.PAGE_START);

        jtSerie.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" }));
        jScrollPane1.setViewportView(jtSerie);

        add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jButton3.setText("Accder aux saisons");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        add(jButton3, java.awt.BorderLayout.PAGE_END);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        jDialogSeries.setJpListeSerie(this);
        jDialogSeries.setVisible(true);

    }//GEN-LAST:event_jButton1ActionPerformed

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

        TableModelListeSerie model = (TableModelListeSerie) jtSerie.getModel();
        Serie s = model.getSerie().get(i);
        serieService.supprimer(s.getId());
        this.rafraichitJtable();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        int j = jtSerie.getSelectedRow();
        if (j == -1) {
            return;
        }

        supprimerPanneau();

        JPanelListeSaison jpSaison = new JPanelListeSaison();
        TableModelListeSaison model2 = (TableModelListeSaison) jpSaison.getJtSaison().getModel(); //jtSaison.getModel();
        Saison sa = model2.getSaison().get(j);
        add(jpSaison, BorderLayout.CENTER);
        this.rafraichitJtable();
        jtSerie.setVisible(false);

    }//GEN-LAST:event_jButton3ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JTable jtSerie;
    // End of variables declaration//GEN-END:variables
}