com.tecnosur.view.Frm_PermisoChart.java Source code

Java tutorial

Introduction

Here is the source code for com.tecnosur.view.Frm_PermisoChart.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 com.tecnosur.view;

import com.tecnosur.coleccion.CPermiso;
import com.tecnosur.dao.Aula_dao;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 *
 * @author SISTEMAS
 */
public class Frm_PermisoChart extends javax.swing.JInternalFrame {

    CPermiso oc_permiso;
    Aula_dao oaula;

    /**
     * Creates new form Frm_PermisoChart
     */
    public Frm_PermisoChart(Aula_dao poaula) {
        initComponents();
        oaula = poaula;
    }

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

        jPanel1 = new javax.swing.JPanel();
        jToolBar1 = new javax.swing.JToolBar();
        jButton1 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setTitle("Grafica de permiso por Aula");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }

            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }

            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }

            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }

            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }

            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }

            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        jPanel1.setLayout(new java.awt.GridLayout(1, 1));

        jToolBar1.setRollover(true);

        jButton1.setText("Guardar Grfica");
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton1);

        jPanel1.add(jToolBar1);

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setLayout(new java.awt.GridLayout(1, 1));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 484, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                        Short.MAX_VALUE));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 27,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel2,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)));

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

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
        try {
            // TODO add your handling code here:

            Object valor[] = { "", oaula.getIdespecialidad(), oaula.getIdsemestre(), oaula.getIdturno(),
                    oaula.getIdseccion(), oaula.getIdperiodo() };
            oc_permiso = new CPermiso();
            oc_permiso.ofiltro.setValor(valor);
            oc_permiso.ListarGraficaEntregados();
            // Creamos y rellenamos el modelo de datos
            DefaultCategoryDataset dataset = new DefaultCategoryDataset();
            if (oc_permiso.size() > 0) {
                for (int x = 0; x < oc_permiso.size(); x++) {
                    dataset.setValue(oc_permiso.get(x).getCuenta(), oc_permiso.get(x).getEstado(),
                            oc_permiso.get(x).getMes());
                }
            }

            oc_permiso.ListarGraficaNoEntregados();
            if (oc_permiso.size() > 0) {
                for (int x = 0; x < oc_permiso.size(); x++) {
                    dataset.setValue(oc_permiso.get(x).getCuenta(), oc_permiso.get(x).getEstado(),
                            oc_permiso.get(x).getMes());
                }
            }
            // Visitas del sitio web 2            
            JFreeChart chart = ChartFactory.createBarChart("Permisos del Aula: Computacin I-A-M", "MES",
                    "ALUMNOS", dataset, PlotOrientation.VERTICAL, true, true, false);
            ChartPanel panel = new ChartPanel(chart);
            jPanel2.add(panel);

        } catch (SQLException ex) {
            Logger.getLogger(Frm_PermisoChart.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_formInternalFrameOpened

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration//GEN-END:variables
}