vista.ReporteConversionLeads.java Source code

Java tutorial

Introduction

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

import controlador.ControladorSession;
import java.awt.Dimension;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import javax.swing.ImageIcon;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.PieDataset;

/**
 *
 * @author Emiliano
 */
public class ReporteConversionLeads extends javax.swing.JFrame {

    /**
     * Creates new form ReporteConversionLeads
     */
    public ReporteConversionLeads() {
        initComponents();
        setIconImage(new ImageIcon(getClass().getResource("/recursos/logoTT.png")).getImage());
    }

    public void iniciaVista() {
        setLocationRelativeTo(null);
        setVisible(true);
    }

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

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        cantClientesLeadActuales = new javax.swing.JLabel();
        cantClientesHabActuales = new javax.swing.JLabel();
        cantLeadsaHabituales = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Reporte de Conversin de LEADS");
        setResizable(false);

        jLabel1.setText("Cantidad de Clientes Lead Actuales");

        jLabel2.setText("Cantidad de Clientes Habituales Actuales");

        jLabel3.setText("Porcentaje de clientes Lead que pasaron a ser Habituales");

        jPanel1.setPreferredSize(new java.awt.Dimension(600, 400));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 387, Short.MAX_VALUE));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 301, Short.MAX_VALUE));

        cantClientesLeadActuales.setText("jLabel4");

        cantClientesHabActuales.setText("jLabel5");

        cantLeadsaHabituales.setText("jLabel6");

        jPanel2.setPreferredSize(new java.awt.Dimension(600, 400));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(jPanel2Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 387, Short.MAX_VALUE));
        jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 301, Short.MAX_VALUE));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGap(26, 26, 26).addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup().addComponent(jLabel1).addGap(110, 110, 110)
                                .addComponent(cantClientesLeadActuales))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 387,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(layout.createSequentialGroup().addComponent(jLabel2)
                                                .addGap(83, 83, 83).addComponent(cantClientesHabActuales)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 64,
                                        Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup().addComponent(jLabel3)
                                                .addGap(45, 45, 45).addComponent(cantLeadsaHabituales))
                                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 387,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(28, 28, 28)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGap(21, 21, 21).addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel1).addComponent(cantClientesLeadActuales))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel2).addComponent(cantClientesHabActuales))
                                .addGap(29, 29, 29).addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        301, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel3).addComponent(cantLeadsaHabituales))
                                .addGap(39, 39, 39).addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        301, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(24, Short.MAX_VALUE)));

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

    public void setControladorSession(ControladorSession c) {
        this.getContentPane().addMouseListener(c);
        this.getContentPane().addFocusListener(c);
    }

    public void iniciarGraficos(PieDataset datasetCantidades, PieDataset datasetConversion) {
        double porcConversion = 0;
        this.cantClientesLeadActuales.setText(Integer.toString(datasetCantidades.getValue(0).intValue()));
        this.cantClientesHabActuales.setText(Integer.toString(datasetCantidades.getValue(1).intValue()));
        double base = datasetConversion.getValue(0).floatValue() + datasetConversion.getValue(1).floatValue();
        if (base > 0) {
            porcConversion = (datasetConversion.getValue(1).floatValue() * 100) / base;
        }

        NumberFormat nf = new DecimalFormat("##.##");
        this.cantLeadsaHabituales.setText(nf.format(porcConversion) + "%");

        JFreeChart chartCa = ChartFactory.createPieChart("Clientes y Leads", // chart title 
                datasetCantidades, // data    
                true, // include legend   
                true, false);

        JFreeChart chartCo = ChartFactory.createPieChart("Conversion Leads a Habituales", // chart title 
                datasetConversion, // data    
                true, // include legend   
                true, false);

        ChartPanel chartCantidades = new ChartPanel(chartCa);
        ChartPanel chartConversion = new ChartPanel(chartCo);
        chartCantidades.setSize(new Dimension(600, 400));
        chartCantidades.setMouseWheelEnabled(true);
        chartConversion.setSize(new Dimension(600, 400));
        chartConversion.setMouseWheelEnabled(true);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout
                .setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup().addGap(0, 0, 0)
                                .addComponent(chartCantidades).addContainerGap(0, Short.MAX_VALUE)));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addGap(0, 0, 0).addComponent(chartCantidades)
                        .addContainerGap(0, Short.MAX_VALUE)));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout
                .setHorizontalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup().addGap(0, 0, 0)
                                .addComponent(chartConversion).addContainerGap(0, Short.MAX_VALUE)));
        jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup().addGap(0, 0, 0).addComponent(chartConversion)
                        .addContainerGap(0, Short.MAX_VALUE)));

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel cantClientesHabActuales;
    private javax.swing.JLabel cantClientesLeadActuales;
    private javax.swing.JLabel cantLeadsaHabituales;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration//GEN-END:variables
}