boundary.ReportProduce.java Source code

Java tutorial

Introduction

Here is the source code for boundary.ReportProduce.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 boundary;

import businessLogic.DBManager;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.FileOutputStream;
import businessLogic.PDFManager;
import businessLogic.ReportProduceControl;
import businessLogic.WindowManager;
import entity.Musician;
import entity.SoundManInSession;
import java.awt.Desktop;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.util.Rotation;

/**
 *
 * @author Shai Gutman
 */
public class ReportProduce extends javax.swing.JPanel {

    public ReportProduce() {
        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() {

        jLabel19 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTable3 = new javax.swing.JTable();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jButton2 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox<>();
        jLabel2 = new javax.swing.JLabel();
        titleLabel = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setOpaque(false);
        setLayout(null);

        jLabel19.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N
        jLabel19.setText("Musicians participated in selected record:");
        add(jLabel19);
        jLabel19.setBounds(390, 350, 360, 20);

        jLabel18.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N
        jLabel18.setText("Soundmans participated in selected record:");
        add(jLabel18);
        jLabel18.setBounds(50, 350, 360, 20);

        jScrollPane5.setViewportView(jTable3);

        add(jScrollPane5);
        jScrollPane5.setBounds(390, 380, 280, 170);

        jScrollPane4.setViewportView(jTable2);

        add(jScrollPane4);
        jScrollPane4.setBounds(50, 380, 280, 170);

        jButton2.setText("Printable document");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        add(jButton2);
        jButton2.setBounds(530, 70, 180, 24);

        jScrollPane1.setViewportView(jTable1);
        if (jTable1.getColumnModel().getColumnCount() > 0) {
            jTable1.getColumnModel().getColumn(0).setResizable(false);
            jTable1.getColumnModel().getColumn(1).setResizable(false);
            jTable1.getColumnModel().getColumn(2).setResizable(false);
            jTable1.getColumnModel().getColumn(3).setResizable(false);
            jTable1.getColumnModel().getColumn(4).setResizable(false);
        }

        add(jScrollPane1);
        jScrollPane1.setBounds(50, 110, 680, 220);

        jButton1.setText("Suspend Artist");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        add(jButton1);
        jButton1.setBounds(380, 70, 140, 24);

        jComboBox1.addItem("Select Artist");
        for (String s : ReportProduceControl.getArtists()) {
            jComboBox1.addItem(s);
        }
        jComboBox1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBox1ItemStateChanged(evt);
            }
        });
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });
        add(jComboBox1);
        jComboBox1.setBounds(200, 70, 140, 24);

        jLabel2.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N
        jLabel2.setText("Choose artist:");
        add(jLabel2);
        jLabel2.setBounds(60, 70, 150, 20);

        titleLabel.setFont(new java.awt.Font("Dialog", 0, 24)); // NOI18N
        titleLabel.setForeground(new java.awt.Color(0, 0, 0));
        titleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        titleLabel.setText("Artist Productivity Report");
        add(titleLabel);
        titleLabel.setBounds(0, 10, 850, 40);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imgs/container3.png"))); // NOI18N
        add(jLabel1);
        jLabel1.setBounds(0, 0, 850, 580);
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox1ItemStateChanged

    }//GEN-LAST:event_jComboBox1ItemStateChanged

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if (jComboBox1.getSelectedIndex() == 0) {
            return;
        }
        if (ReportProduceControl.suspendArtist(String.valueOf(jComboBox1.getSelectedItem()))) {
            JOptionPane.showMessageDialog(null, "The artist was suspended successfully!");
            return;
        } else
            JOptionPane.showMessageDialog(null, "The artist is already inactive");
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        /*HandsInTheAir.getPDF().createPDF(1, "Muza Music "+jComboBox1.getSelectedItem().toString()+" Profit Report");
        PDFManager.PDFFile pdf1 = HandsInTheAir.getPDF().getPDFFile(1);
        try {
        pdf1.addTitlePage("Muza Music "+jComboBox1.getSelectedItem().toString()+" Profit Report");
        String[] titles = new String[]{"Show ID","Created By","Presale sales","Regular sales","Total income","Total cost","Profit"};
        ArrayList<String> row = new ArrayList();
        ArrayList<String> artists = new ArrayList<>();
        for (int i = 0; i < jTable1.getRowCount(); i++) {
            row.clear();
            artists.clear();
            for (int j = 0; j < jTable1.getColumnCount(); j++) {
                row.add(jTable1.getModel().getValueAt(i, j).toString());
            }
            pdf1.addTable(jTable1.getColumnCount(),1, titles, row.toArray(new String[row.size()]));
            ArrayList<String> rs = rpController.getParticipatedArtists(Integer.valueOf(jTable1.getModel().getValueAt(i, 0).toString()));
            artists.add(rpController.getShow(Integer.valueOf(jTable1.getModel().getValueAt(i, 0).toString())).getMainArtist().getArtistAlphaCode());
            for (String r : rs) {
                artists.add(r);
            }
            pdf1.addList("Participated Artists:",artists);
        }
        } catch (DocumentException ex) {
        Logger.getLogger(ReportProduce.class.getName()).log(Level.SEVERE, null, ex);
        }
        HandsInTheAir.getPDF().getPDFFile(1).launchPDF();*/
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        if (jComboBox1.getSelectedIndex() == 0) {
            return;
        }
        setTable();
    }//GEN-LAST:event_jComboBox1ActionPerformed

    public void setTable() {
        DefaultTableModel model = new DefaultTableModel();
        jTable1.setModel(model);
        model.addColumn("No.");
        model.addColumn("Title");
        model.addColumn("Status");
        model.addColumn("Recording Session No.");
        model.addColumn("Recording Date");

        for (Map.Entry<Integer, ArrayList<Object>> entry : ReportProduceControl
                .getRecordings(String.valueOf(jComboBox1.getSelectedItem())).entrySet()) {
            Integer key = entry.getKey();
            ArrayList<Object> value = entry.getValue();
            value.add(0, key);
            model.addRow(value.toArray());
        }

        jTable1.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (jTable1.getSelectedRow() > -1) {
                    setSoundmanTbl((String) jTable1.getValueAt(jTable1.getSelectedRow(), 3));
                    setMusicianTbl((String) jTable1.getValueAt(jTable1.getSelectedRow(), 3));
                }
            }
        });
    }

    private void setSoundmanTbl(String session) {
        DefaultTableModel model = new DefaultTableModel();
        jTable2.setModel(model);
        model.addColumn("ID");
        model.addColumn("Producer");
        model.addColumn("Mix Tech");
        model.addColumn("Master Tech");

        for (SoundManInSession entry : ReportProduceControl.getSoundmans(Integer.valueOf(session))) {
            model.addRow(new Object[] { entry.getSoundManID(), entry.isProducer(), entry.isMasterTech(),
                    entry.isMasterTech() });
        }
    }

    private void setMusicianTbl(String session) {
        DefaultTableModel model = new DefaultTableModel();
        jTable3.setModel(model);
        model.addColumn("ID");
        model.addColumn("Instrument");
        for (Musician entry : ReportProduceControl.getMusicians(Integer.valueOf(session))) {
            model.addRow(new Object[] { entry.getFreelancerID(), entry.getType() });
        }
    }

    public String formated(double d) {
        String s = String.valueOf(d);
        String[] result = s.split("\\.");
        return result[0] + "." + result[1].charAt(0);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox<String> jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTable jTable3;
    private javax.swing.JLabel titleLabel;
    // End of variables declaration//GEN-END:variables
}