co.edu.eam.ingesoft.desarrollo.vista.gui.ReportesEstadisticas.java Source code

Java tutorial

Introduction

Here is the source code for co.edu.eam.ingesoft.desarrollo.vista.gui.ReportesEstadisticas.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 co.edu.eam.ingesoft.desarrollo.vista.gui;

import java.awt.Color;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;

import co.edu.eam.desarrollo.proyectoFinal.gui.controladores.ControladorVentanaReportesyEstadisticas;
import co.edu.eam.desarrolloSoftware.proyectoFinal.modelo.Empresa;
import co.edu.eam.desarrolloSoftware.proyectoFinal.modelo.InformacionLaboral;
import co.edu.eam.desarrolloSoftware.proyectoFinal.modelo.Programa;

/**
 *
 * @author carlos
 */
public class ReportesEstadisticas extends javax.swing.JFrame {

    private ControladorVentanaReportesyEstadisticas controlador;

    /**
     * Creates new form ReportesEstadisticas
     */
    public ReportesEstadisticas() {
        initComponents();
        this.setTitle("Reportes y Estadisticas");
        this.setLocationRelativeTo(null);
        this.setResizable(false);
        this.setIconImage(new ImageIcon(getClass().getResource("/imagenes/icono.png")).getImage());
        controlador = new ControladorVentanaReportesyEstadisticas();
        cargarEmpresas();
    }

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

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jBAgregarPalabra = new javax.swing.JButton();
        jTabbedPane2 = new javax.swing.JTabbedPane();
        jPanelEgresadosPorOcup = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jCBPrograma = new javax.swing.JComboBox();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jCBEmpresa = new javax.swing.JComboBox();
        jBbuscar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTtablaEmpresaEgresado = new javax.swing.JTable();
        jPNumeroOfertas = new javax.swing.JPanel();
        jPOfertaPrograma = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(242, 242, 249));

        jBAgregarPalabra.setBackground(new java.awt.Color(66, 183, 42));
        jBAgregarPalabra.setFont(new java.awt.Font("SansSerif", 1, 12)); // NOI18N
        jBAgregarPalabra.setForeground(new java.awt.Color(255, 255, 255));
        jBAgregarPalabra.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Inicio.png"))); // NOI18N
        jBAgregarPalabra.setToolTipText("Ir al inicio");
        jBAgregarPalabra.setBorder(null);
        jBAgregarPalabra.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jBAgregarPalabra.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAgregarPalabraActionPerformed(evt);
            }
        });

        jLabel2.setText("PROGRAMA:");

        jCBPrograma.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jCBProgramaItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout jPanelEgresadosPorOcupLayout = new javax.swing.GroupLayout(jPanelEgresadosPorOcup);
        jPanelEgresadosPorOcup.setLayout(jPanelEgresadosPorOcupLayout);
        jPanelEgresadosPorOcupLayout.setHorizontalGroup(jPanelEgresadosPorOcupLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelEgresadosPorOcupLayout.createSequentialGroup().addGap(152, 152, 152)
                        .addComponent(jLabel2).addGap(31, 31, 31).addComponent(jCBPrograma,
                                javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(162, Short.MAX_VALUE)));
        jPanelEgresadosPorOcupLayout.setVerticalGroup(
                jPanelEgresadosPorOcupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanelEgresadosPorOcupLayout.createSequentialGroup().addGap(49, 49, 49)
                                .addGroup(jPanelEgresadosPorOcupLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jCBPrograma, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel2))
                                .addContainerGap(311, Short.MAX_VALUE)));

        jTabbedPane2.addTab("Egresados Por Tipo Ocupacion", jPanelEgresadosPorOcup);

        jLabel1.setText("EMPRESA:");

        jBbuscar.setText("Buscar");
        jBbuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBbuscarActionPerformed(evt);
            }
        });

        jTtablaEmpresaEgresado.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[] { "Nombre", "Programa", "Cargo", "Fecha Entrada" }));
        jScrollPane1.setViewportView(jTtablaEmpresaEgresado);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(jPanel3Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup().addGroup(jPanel3Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel3Layout.createSequentialGroup().addGap(45, 45, 45).addComponent(
                                jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel3Layout.createSequentialGroup().addGap(100, 100, 100).addComponent(jLabel1)
                                .addGap(18, 18, 18)
                                .addComponent(jCBEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, 167,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(43, 43, 43).addComponent(jBbuscar)))
                        .addContainerGap(54, Short.MAX_VALUE)));
        jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup().addGap(102, 102, 102).addGroup(jPanel3Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jCBEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel1).addComponent(jBbuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 28,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 65, Short.MAX_VALUE)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 93,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(92, 92, 92)));

        jTabbedPane2.addTab("Empleados Por Empresa", jPanel3);

        javax.swing.GroupLayout jPNumeroOfertasLayout = new javax.swing.GroupLayout(jPNumeroOfertas);
        jPNumeroOfertas.setLayout(jPNumeroOfertasLayout);
        jPNumeroOfertasLayout.setHorizontalGroup(jPNumeroOfertasLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 551, Short.MAX_VALUE));
        jPNumeroOfertasLayout.setVerticalGroup(jPNumeroOfertasLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 380, Short.MAX_VALUE));

        jTabbedPane2.addTab("Numero de Ofertas Abiertas", jPNumeroOfertas);

        javax.swing.GroupLayout jPOfertaProgramaLayout = new javax.swing.GroupLayout(jPOfertaPrograma);
        jPOfertaPrograma.setLayout(jPOfertaProgramaLayout);
        jPOfertaProgramaLayout.setHorizontalGroup(jPOfertaProgramaLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 551, Short.MAX_VALUE));
        jPOfertaProgramaLayout.setVerticalGroup(jPOfertaProgramaLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 380, Short.MAX_VALUE));

        jTabbedPane2.addTab("Oferta Por Programa", jPOfertaPrograma);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup().addGap(27, 27, 27).addComponent(
                                        jBAgregarPalabra, javax.swing.GroupLayout.PREFERRED_SIZE, 52,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel1Layout.createSequentialGroup().addGap(39, 39, 39).addComponent(
                                        jTabbedPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 556,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(52, Short.MAX_VALUE)));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                        jPanel1Layout.createSequentialGroup()
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jTabbedPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 408,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jBAgregarPalabra, javax.swing.GroupLayout.PREFERRED_SIZE, 35,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap()));

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel3.setText("REPORTES Y ESTADISTICAS");

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/estadisticas.png"))); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                        .addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(
                                                layout.createSequentialGroup().addContainerGap().addComponent(
                                                        jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addGroup(layout.createSequentialGroup().addGap(194, 194, 194)
                                                .addComponent(jLabel3)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 109,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addGap(23, 23, 23)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup().addGap(14, 14, 14)
                                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 0,
                                                Short.MAX_VALUE)
                                        .addGap(18, 18, 18))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                        layout.createSequentialGroup().addContainerGap(46, Short.MAX_VALUE)
                                                .addComponent(jLabel3).addGap(26, 26, 26)))
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 466,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap()));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBAgregarPalabraActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jBAgregarPalabraActionPerformed
        VentanaPrincipal vp = new VentanaPrincipal();
        vp.setVisible(true);
        this.setVisible(false);
    }// GEN-LAST:event_jBAgregarPalabraActionPerformed

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

        try {
            ChartPanel panel;
            Programa programa = (Programa) jCBPrograma.getSelectedItem();
            List<InformacionLaboral> listaInfoLab = controlador.listaEgresadosPorOcupacion(programa);

            jPanelEgresadosPorOcup.removeAll();

            double empleado = 0;
            double desempleado = 0;
            double independiente = 0;
            double empresario = 0;

            int contadorEmpleado = 0;
            int contadordDesempleado = 0;
            int contadorIndependiente = 0;
            int contadorEmpresario = 0;

            for (int i = 0; i < listaInfoLab.size(); i++) {
                if (listaInfoLab.get(i).getSituacionActual().equals("Empleado")) {
                    contadorEmpleado++;
                } else if (listaInfoLab.get(i).getSituacionActual().equals("Desempleado")) {
                    contadordDesempleado++;
                } else if (listaInfoLab.get(i).getSituacionActual().equals("Independiente")) {
                    contadorIndependiente++;
                } else if (listaInfoLab.get(i).getSituacionActual().equals("Empresario")) {
                    contadorEmpresario++;
                } else {
                    JOptionPane.showMessageDialog(null, "No hay empleados registrados");
                }

                empleado = (contadorEmpleado * 100) / listaInfoLab.size();
                desempleado = (contadordDesempleado * 100) / listaInfoLab.size();
                independiente = (contadorIndependiente * 100) / listaInfoLab.size();
                empresario = (contadorEmpresario * 100) / listaInfoLab.size();
            }
            DefaultPieDataset ds = new DefaultPieDataset();
            ds.setValue("Empleado: " + empleado + "%", empleado);
            ds.setValue("Desempleado: " + desempleado + "%", desempleado);
            ds.setValue("Independiente: " + independiente + "%", independiente);
            ds.setValue("Empresario: " + empresario + "%", empresario);

            JFreeChart jf = ChartFactory.createPieChart3D("Reporte de egresados por tipo de ocupacin", ds, true,
                    true, true);

            panel = new ChartPanel(jf);
            panel.setBounds(20, 50, 720, 350);

            jPanelEgresadosPorOcup.add(panel);

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    private void jBbuscarActionPerformed(java.awt.event.ActionEvent evt) {

        Empresa em = (Empresa) jCBEmpresa.getSelectedItem();
        listarTabla(em);

    }

    /**
     * Cargamos todas las empresas que se encuentran en la bd
     */
    public void cargarEmpresas() {
        try {
            jCBEmpresa.removeAllItems();
            List<Empresa> lista = controlador.listarEmpresas();
            for (Empresa sl : lista) {
                jCBEmpresa.addItem(sl);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * lista la tabla con todos los datos requeridos
     */
    public void listarTabla(Empresa e) {
        try {
            DefaultTableModel dtm = (DefaultTableModel) jTtablaEmpresaEgresado.getModel();
            dtm.setRowCount(0);
            List<InformacionLaboral> lista = controlador.listarEgresadosPorEmpresa(e);

            for (InformacionLaboral infoLaboral : lista) {
                dtm.addRow(new Object[] { infoLaboral.getEgresado().getNombre(),
                        infoLaboral.getEgresado().getPrograma(), infoLaboral.getCargo(),
                        infoLaboral.getFechaIngreso() });
            }

        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBAgregarPalabra;
    private javax.swing.JButton jBbuscar;
    private javax.swing.JComboBox jCBEmpresa;
    private javax.swing.JComboBox jCBPrograma;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPNumeroOfertas;
    private javax.swing.JPanel jPOfertaPrograma;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanelEgresadosPorOcup;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTabbedPane jTabbedPane2;
    private javax.swing.JTable jTtablaEmpresaEgresado;
    // End of variables declaration//GEN-END:variables
}