Visao.Relatorio.Relatorio_QuantidadeReclamacoesCidadeIntervalo.java Source code

Java tutorial

Introduction

Here is the source code for Visao.Relatorio.Relatorio_QuantidadeReclamacoesCidadeIntervalo.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 Visao.Relatorio;

import Controle.ControlePrincipal;
import DAO.DAO_Relatorio;
import DAO.GeneralDAO;
import Modelo.ModeloTabela;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image;
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.awt.Toolkit;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author Gustavo
 */
public class Relatorio_QuantidadeReclamacoesCidadeIntervalo extends javax.swing.JDialog {

    /**
     * Creates new form Relatorio_QuantidadeReclamacoesCidadeIntervalo
     */
    private GeneralDAO dao;
    private List<String> city;
    private ControlePrincipal controlePrincipal = new ControlePrincipal();
    private String cidade;
    private int mes, ano;
    private long quantidade;
    double notamedia, tempoResposta;
    private DecimalFormat decimalFormat = new DecimalFormat("#.####");

    public Relatorio_QuantidadeReclamacoesCidadeIntervalo(java.awt.Frame parent, boolean modal, GeneralDAO dao) {
        super(parent, modal);
        initComponents();
        this.dao = dao;
        preencherCidade();
        jButtonPDF.setEnabled(false);
        jLabelEmpresas.setVisible(false);
        jScrollPane2.setVisible(false);
        jTableEmpresas.setVisible(false);
        jLabelQuantidadeReclamacao.setVisible(false);
        jTextFieldQuantidadeReclamacao.setVisible(false);
        jLabelAssunto.setVisible(false);
        jTableAssuntos.setVisible(false);
        jScrollPane1.setVisible(false);
        jLabelNotaMedia.setVisible(false);
        jTextFieldNotaMedia.setVisible(false);
        jLabelTempoResposta.setVisible(false);
        jTextFieldTempoResposta.setVisible(false);
        Toolkit kit = this.getToolkit();
        java.awt.Image icone = kit.getImage("src/Icones/relatorio.png");
        this.setIconImage(icone);
        jTableAssuntos.setAutoCreateRowSorter(true);
        jTableEmpresas.setAutoCreateRowSorter(true);
    }

    private void preencherCidade() {
        city = controlePrincipal.cidade(dao);
        for (String s : city) {
            jComboBoxCidade.addItem(s);
        }
    }

    /**
     * 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();
        jComboBoxMes = new javax.swing.JComboBox();
        jComboBoxAno = new javax.swing.JComboBox();
        jButtonGerarRelatorio = new javax.swing.JButton();
        jButtonPDF = new javax.swing.JButton();
        jComboBoxCidade = new javax.swing.JComboBox();
        jLabelEmpresas = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTableEmpresas = new javax.swing.JTable();
        jLabelQuantidadeReclamacao = new javax.swing.JLabel();
        jTextFieldQuantidadeReclamacao = new javax.swing.JTextField();
        jLabelAssunto = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableAssuntos = new javax.swing.JTable();
        jLabelNotaMedia = new javax.swing.JLabel();
        jTextFieldNotaMedia = new javax.swing.JTextField();
        jTextFieldTempoResposta = new javax.swing.JTextField();
        jLabelTempoResposta = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Reclamaes por Cidade");

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel1.setText("Cidade");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel2.setText("Ms");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel3.setText("Ano");

        jComboBoxMes.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jComboBoxMes.setModel(new javax.swing.DefaultComboBoxModel(
                new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }));
        jComboBoxMes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxMesActionPerformed(evt);
            }
        });

        jComboBoxAno.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jComboBoxAno.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2014", "2015", "2016" }));
        jComboBoxAno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxAnoActionPerformed(evt);
            }
        });

        jButtonGerarRelatorio.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButtonGerarRelatorio.setText("Gerar Relatrio");
        jButtonGerarRelatorio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGerarRelatorioActionPerformed(evt);
            }
        });

        jButtonPDF.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButtonPDF.setText("Gerar PDF");
        jButtonPDF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonPDFActionPerformed(evt);
            }
        });

        jComboBoxCidade.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jComboBoxCidade.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxCidadeActionPerformed(evt);
            }
        });

        jLabelEmpresas.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabelEmpresas.setText("Empresas Reclamadas");

        jTableEmpresas.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jTableEmpresas
                .setModel(new javax.swing.table.DefaultTableModel(new Object[][] { {}, {}, {}, {} }, new String[] {

        }));
        jTableEmpresas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableEmpresasMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(jTableEmpresas);

        jLabelQuantidadeReclamacao.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabelQuantidadeReclamacao.setText("Quantidade de Reclamaes:");

        jTextFieldQuantidadeReclamacao.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jTextFieldQuantidadeReclamacao.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextFieldQuantidadeReclamacao.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        jTextFieldQuantidadeReclamacao.setEnabled(false);

        jLabelAssunto.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabelAssunto.setText("Assuntos Reclamados");

        jTableAssuntos.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jTableAssuntos
                .setModel(new javax.swing.table.DefaultTableModel(new Object[][] { {}, {}, {}, {} }, new String[] {

        }));
        jTableAssuntos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableAssuntosMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTableAssuntos);

        jLabelNotaMedia.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabelNotaMedia.setText("Nota Mdia Consumidor");

        jTextFieldNotaMedia.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jTextFieldNotaMedia.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextFieldNotaMedia.setDisabledTextColor(new java.awt.Color(51, 51, 51));
        jTextFieldNotaMedia.setEnabled(false);

        jTextFieldTempoResposta.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jTextFieldTempoResposta.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextFieldTempoResposta.setDisabledTextColor(new java.awt.Color(51, 51, 51));
        jTextFieldTempoResposta.setEnabled(false);

        jLabelTempoResposta.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabelTempoResposta.setText("Tempo Mdio de Resposta");

        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(230, 230, 230).addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                        .addComponent(jLabelTempoResposta, javax.swing.GroupLayout.PREFERRED_SIZE, 170,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextFieldTempoResposta, javax.swing.GroupLayout.PREFERRED_SIZE, 184,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextFieldNotaMedia, javax.swing.GroupLayout.PREFERRED_SIZE, 165,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabelNotaMedia)
                        .addComponent(jTextFieldQuantidadeReclamacao, javax.swing.GroupLayout.PREFERRED_SIZE, 184,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabelQuantidadeReclamacao)).addGap(272, 272, 272))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup().addGap(158, 158, 158)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jButtonPDF, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jButtonGerarRelatorio, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGap(6, 6, 6))
                        .addGroup(layout.createSequentialGroup().addGap(31, 31, 31)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                                        .addComponent(jComboBoxMes, 0, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                Short.MAX_VALUE)
                                        .addComponent(jComboBoxCidade, 0, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                Short.MAX_VALUE))
                                .addGap(31, 31, 31)
                                .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(18, 18, 18).addComponent(jComboBoxAno, 0,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGap(204, 204, 204))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                        layout.createSequentialGroup().addContainerGap()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                                        .addComponent(jLabelEmpresas, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 180,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(524, 524, 524))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                        layout.createSequentialGroup().addGap(503, 503, 503)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                                        .addComponent(jLabelAssunto, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 180,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(48, 48, 48)));

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] { jTextFieldNotaMedia,
                jTextFieldQuantidadeReclamacao, jTextFieldTempoResposta });

        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGap(16, 16, 16).addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel1)
                        .addComponent(jComboBoxCidade, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup().addGap(22, 22, 22).addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                                                .addComponent(jComboBoxAno, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel3)
                                                .addComponent(jComboBoxMes, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel2)).addGap(28, 28, 28)
                                                .addComponent(jButtonGerarRelatorio).addGap(18, 18, 18)
                                                .addComponent(jButtonPDF)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        28, Short.MAX_VALUE)
                                                .addGroup(layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(jLabelAssunto).addComponent(jLabelEmpresas,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 15,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING, false)
                                                        .addComponent(
                                                                jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                323, Short.MAX_VALUE)
                                                        .addComponent(
                                                                jScrollPane2,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 0,
                                                                Short.MAX_VALUE))
                                                .addGap(115, 115, 115))
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout
                                                .createSequentialGroup()
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(jLabelQuantidadeReclamacao,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 17,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jTextFieldQuantidadeReclamacao,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(33, 33, 33).addComponent(jLabelNotaMedia)
                                                .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(jTextFieldNotaMedia,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(27, 27, 27).addComponent(jLabelTempoResposta)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jTextFieldTempoResposta,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(205, 205, 205)))));

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

    private void jComboBoxCidadeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxCidadeActionPerformed
        cidade = jComboBoxCidade.getSelectedItem().toString();
    }//GEN-LAST:event_jComboBoxCidadeActionPerformed

    private void jComboBoxMesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxMesActionPerformed
        mes = Integer.parseInt(jComboBoxMes.getSelectedItem().toString());
    }//GEN-LAST:event_jComboBoxMesActionPerformed

    private void jComboBoxAnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxAnoActionPerformed
        ano = Integer.parseInt(jComboBoxAno.getSelectedItem().toString());
    }//GEN-LAST:event_jComboBoxAnoActionPerformed

    private void jButtonGerarRelatorioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGerarRelatorioActionPerformed
        if (mes == 0) {
            mes = 1;
        }

        if (ano == 0) {
            ano = 2014;
        }

        if (cidade == null) {
            cidade = city.get(0);
        }

        String consulta = "select count(codigoreclamacao) from Reclamacao " + "where cidade='" + cidade
                + "' and mesabertura=" + mes + " and anoabertura=" + ano;
        quantidade = dao.codigo(consulta);
        if (quantidade == 0) {
            String saida = "No existe reclamao cadastrada em " + cidade + " em " + mes + " / " + ano;
            JOptionPane.showMessageDialog(null, saida);
        } else {

            jButtonPDF.setEnabled(true);
            jLabelEmpresas.setVisible(true);
            jScrollPane2.setVisible(true);
            jTableEmpresas.setVisible(true);
            jLabelQuantidadeReclamacao.setVisible(true);
            jTextFieldQuantidadeReclamacao.setVisible(true);
            jLabelAssunto.setVisible(true);
            jTableAssuntos.setVisible(true);
            jScrollPane1.setVisible(true);
            jLabelNotaMedia.setVisible(true);
            jTextFieldNotaMedia.setVisible(true);
            jLabelTempoResposta.setVisible(true);
            jTextFieldTempoResposta.setVisible(true);

            jTextFieldQuantidadeReclamacao.setText(String.valueOf(quantidade));

            preencherTabelaEmpresa();
            preencherTabelaAssunto();

            DAO_Relatorio dao_relatorio = new DAO_Relatorio(dao.getSessao());
            String consultaNota = "select avg(notaconsumidor) from Reclamacao" + " where cidade='" + cidade
                    + "' and mesabertura=" + mes + " and anoabertura=" + ano;
            notamedia = dao_relatorio.funcaoAgregacaoDouble(consultaNota);

            jTextFieldNotaMedia.setText(decimalFormat.format(notamedia));

            String consultaTempoResposta = "select avg(temporesposta) from Reclamacao" + " where cidade='" + cidade
                    + "' and mesabertura=" + mes + " and anoabertura=" + ano;
            tempoResposta = dao_relatorio.funcaoAgregacaoDouble(consultaTempoResposta);

            jTextFieldTempoResposta.setText(decimalFormat.format(tempoResposta) + " dias");

        }
    }//GEN-LAST:event_jButtonGerarRelatorioActionPerformed

    private void jButtonPDFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonPDFActionPerformed

        try {
            Date hoje = new Date();
            DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
            String data = dateFormat.format(hoje);
            String file = "src\\PDF\\Cidade\\Relatrio Cidade " + cidade + "_" + data + ".pdf";
            System.out.println(file);

            create(new FileOutputStream(new File(file)));
            JOptionPane.showMessageDialog(null, "PDF gerado com sucesso!\n\n" + "Salvo em: PDF\\Cidade");
        } catch (IOException | DocumentException ex) {
            JOptionPane.showMessageDialog(null, "ERRO! PDF no foi gerado!");
            Logger.getLogger(Relatorio_QuantidadeReclamacoesUF.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_jButtonPDFActionPerformed

    public void create(OutputStream outputStream) throws DocumentException, IOException {
        Document document = null;
        PdfWriter writer = null;

        try {
            //instantiate document and writer
            document = new Document();
            writer = PdfWriter.getInstance(document, outputStream);

            //open document
            document.open();
            Image img = Image.getInstance("src\\Imagens\\logo.png");
            img.setAlignment(Element.ALIGN_CENTER);
            document.add(img);

            Paragraph paragraph = new Paragraph("\n\nReclamaes\n\nCidade: " + cidade,
                    new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD));
            paragraph.setAlignment(Element.ALIGN_CENTER);
            document.add(paragraph);

            Paragraph paragraph1 = new Paragraph("\nMs Abertura: " + mes + "\nAno Abertura: " + ano,
                    new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD));

            document.add(paragraph1);

            document.add(new Paragraph("\n\n\n"));

            PdfPTable table = new PdfPTable(3);
            PdfPCell pdfWordCell = new PdfPCell();
            PdfPCell pdfWordCell1 = new PdfPCell();
            PdfPCell pdfWordCell2 = new PdfPCell();
            Phrase firstLine = new Phrase("Quantidade de reclamaes",
                    new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD));
            Phrase secondLine = new Phrase("Nota mdia consumidor",
                    new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD));
            Phrase thirdLine = new Phrase("Tempo mdio de resposta",
                    new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD));

            pdfWordCell.addElement(firstLine);
            pdfWordCell1.addElement(secondLine);
            pdfWordCell2.addElement(thirdLine);

            table.addCell(pdfWordCell);
            table.addCell(pdfWordCell1);
            table.addCell(pdfWordCell2);

            table.addCell(String.valueOf(quantidade));
            table.addCell(decimalFormat.format(notamedia));
            table.addCell(decimalFormat.format(tempoResposta) + " dias");

            document.add(table);

            document.add(new Paragraph("\n\n\nEmpresas Reclamadas\n\n",
                    new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD)));

            PdfPTable table1 = new PdfPTable(2);
            PdfPCell pdfWordCel3 = new PdfPCell();
            PdfPCell pdfWordCel4 = new PdfPCell();
            Phrase firstLine1 = new Phrase("Empresa", new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD));
            Phrase secondLine1 = new Phrase("Quantidade", new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD));

            pdfWordCel3.addElement(firstLine1);
            pdfWordCel4.addElement(secondLine1);

            table1.addCell(pdfWordCel3);
            table1.addCell(pdfWordCel4);

            String consulta = "Select e.nomefantasia, count(r.codigoreclamacao)" + " from Reclamacao r, Empresa e"
                    + " where r.codempresa = e.codigoempresa and" + " r.cidade='" + cidade + "' and r.mesabertura="
                    + mes + " and r.anoabertura=" + ano + " group by e.nomefantasia" + " order by e.nomefantasia";

            Iterator i = dao.getSessao().createSQLQuery(consulta).list().iterator();

            while (i.hasNext()) {
                Object[] reclamacaoEmpresa = (Object[]) i.next();
                table1.addCell(reclamacaoEmpresa[0].toString());
                table1.addCell(reclamacaoEmpresa[1].toString());
            }

            document.add(table1);

            document.add(new Paragraph("\n\n\nAssuntos Reclamados\n\n",
                    new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD)));
            PdfPTable table2 = new PdfPTable(2);
            PdfPCell pdfWordCel5 = new PdfPCell();
            PdfPCell pdfWordCel6 = new PdfPCell();
            Phrase firstLine5 = new Phrase("Assunto", new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD));

            pdfWordCel5.addElement(firstLine5);
            pdfWordCel6.addElement(secondLine1);

            table2.addCell(pdfWordCel5);
            table2.addCell(pdfWordCel6);

            String consulta1 = "select assunto, count(codigoreclamacao)" + " from Reclamacao where cidade='"
                    + cidade + "'" + " and mesabertura=" + mes + " and anoabertura=" + ano + " group by assunto "
                    + " order by assunto";
            Iterator ii = dao.getSessao().createSQLQuery(consulta1).list().iterator();

            while (ii.hasNext()) {
                Object[] reclamacaoAssunto = (Object[]) ii.next();
                table2.addCell(reclamacaoAssunto[0].toString());
                table2.addCell(reclamacaoAssunto[1].toString());
            }

            document.add(table2);

            document.close();
            document = null;

            writer.close();
            writer = null;
        } catch (DocumentException | IOException de) {
            throw de;
        } finally {
            //release resources
            if (null != document) {
                try {
                    document.close();
                } catch (Exception ex) {
                }
            }

            if (null != writer) {
                try {
                    writer.close();
                } catch (Exception ex) {
                }
            }
        }
    }

    private void jTableEmpresasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableEmpresasMouseClicked
        int selecionada = jTableEmpresas.getSelectedRow();
        String s = "\nEmpresa: " + jTableEmpresas.getValueAt(selecionada, 0).toString() + "\nQuantidade: "
                + jTableEmpresas.getValueAt(selecionada, 1).toString();
        JOptionPane.showMessageDialog(null, s);
    }//GEN-LAST:event_jTableEmpresasMouseClicked

    private void jTableAssuntosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableAssuntosMouseClicked
        int selecionada = jTableAssuntos.getSelectedRow();
        String s = "\nAssunto: " + jTableAssuntos.getValueAt(selecionada, 0).toString() + "\nQuantidade: "
                + jTableAssuntos.getValueAt(selecionada, 1).toString();
        JOptionPane.showMessageDialog(null, s);
    }//GEN-LAST:event_jTableAssuntosMouseClicked

    private void preencherTabelaEmpresa() {

        try {

            String emp = "Select e.nomefantasia, count(r.codigoreclamacao)" + " from Reclamacao r, Empresa e"
                    + " where r.empresa = e.codigoempresa and" + " r.cidade='" + cidade + "' and r.mesabertura="
                    + mes + " and r.anoabertura=" + ano + " group by e.nomefantasia" + " order by e.nomefantasia";
            String[] nomeColunas = new String[] { "Empresa", "Quantidade" };
            ArrayList dados = dao.listar(emp);
            DefaultTableCellRenderer centralizado = new DefaultTableCellRenderer();
            centralizado.setHorizontalAlignment(SwingConstants.CENTER);
            ModeloTabela modeloTabela = new ModeloTabela(dados, nomeColunas);
            jTableEmpresas.setModel(modeloTabela);

            jTableEmpresas.getColumnModel().getColumn(0).setPreferredWidth(10);
            jTableEmpresas.getColumnModel().getColumn(0).setResizable(true);
            jTableEmpresas.getColumnModel().getColumn(0).setHeaderValue(modeloTabela.getColumnNome(0));
            jTableEmpresas.getColumnModel().getColumn(0).setCellRenderer(centralizado);

            jTableEmpresas.getColumnModel().getColumn(1).setPreferredWidth(20);
            jTableEmpresas.getColumnModel().getColumn(1).setResizable(true);
            jTableEmpresas.getColumnModel().getColumn(1).setHeaderValue(modeloTabela.getColumnNome(1));
            jTableEmpresas.getColumnModel().getColumn(1).setCellRenderer(centralizado);

            jTableEmpresas.getTableHeader().setReorderingAllowed(false);
            jTableEmpresas.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
            jTableEmpresas.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        } catch (Exception exc) {

        }

    }

    private void preencherTabelaAssunto() {

        try {

            String consultaAssunto = "select assunto, count(codigoreclamacao)" + " from Reclamacao where cidade='"
                    + cidade + "'" + " and mesabertura=" + mes + " and anoabertura=" + ano + " group by assunto "
                    + " order by assunto";

            String[] nomeColunas = new String[] { "Assunto", "Quantidade" };
            ArrayList dados = dao.listar(consultaAssunto);
            DefaultTableCellRenderer centralizado = new DefaultTableCellRenderer();
            centralizado.setHorizontalAlignment(SwingConstants.CENTER);
            ModeloTabela modeloTabela = new ModeloTabela(dados, nomeColunas);
            jTableAssuntos.setModel(modeloTabela);

            jTableAssuntos.getColumnModel().getColumn(0).setPreferredWidth(10);
            jTableAssuntos.getColumnModel().getColumn(0).setResizable(true);
            jTableAssuntos.getColumnModel().getColumn(0).setHeaderValue(modeloTabela.getColumnNome(0));
            jTableAssuntos.getColumnModel().getColumn(0).setCellRenderer(centralizado);

            jTableAssuntos.getColumnModel().getColumn(1).setPreferredWidth(20);
            jTableAssuntos.getColumnModel().getColumn(1).setResizable(true);
            jTableAssuntos.getColumnModel().getColumn(1).setHeaderValue(modeloTabela.getColumnNome(1));
            jTableAssuntos.getColumnModel().getColumn(1).setCellRenderer(centralizado);

            jTableAssuntos.getTableHeader().setReorderingAllowed(false);
            jTableAssuntos.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
            jTableAssuntos.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        } catch (Exception exc) {

        }

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonGerarRelatorio;
    private javax.swing.JButton jButtonPDF;
    private javax.swing.JComboBox jComboBoxAno;
    private javax.swing.JComboBox jComboBoxCidade;
    private javax.swing.JComboBox jComboBoxMes;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabelAssunto;
    private javax.swing.JLabel jLabelEmpresas;
    private javax.swing.JLabel jLabelNotaMedia;
    private javax.swing.JLabel jLabelQuantidadeReclamacao;
    private javax.swing.JLabel jLabelTempoResposta;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTableAssuntos;
    private javax.swing.JTable jTableEmpresas;
    private javax.swing.JTextField jTextFieldNotaMedia;
    private javax.swing.JTextField jTextFieldQuantidadeReclamacao;
    private javax.swing.JTextField jTextFieldTempoResposta;
    // End of variables declaration//GEN-END:variables
}