UserInterface.CDC.VARESCityReportingJPanel.java Source code

Java tutorial

Introduction

Here is the source code for UserInterface.CDC.VARESCityReportingJPanel.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 UserInterface.CDC;

import Business.Business;
import Business.NationalEnterprise.CDC;
import Business.Network.CityNetwork;
import Business.Network.StateNetwork;
import Business.Organization.CDCOrganization;
import Business.UserAccount.UserAccount;
import java.awt.CardLayout;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;

/**
 *
 * @author Vaibhav
 */
public class VARESCityReportingJPanel extends javax.swing.JPanel {

    /**
     * Creates new form VARESReportingJPanel
     */
    private JPanel workContainer;
    private UserAccount userAccount;
    private Business business;
    private CDC cdcEnterprise;
    private CDCOrganization cdcOrg;
    private StateNetwork state;

    public VARESCityReportingJPanel(JPanel workContainer, UserAccount userAccount, Business business,
            CDC cdcEnterprise, CDCOrganization cdcOrg, StateNetwork state) {
        initComponents();
        this.workContainer = workContainer;
        this.userAccount = userAccount;
        this.business = business;
        this.cdcEnterprise = cdcEnterprise;
        this.cdcOrg = cdcOrg;
        this.state = state;
        statejTextField.setText(state.getStateName());
        populateTable();

    }

    private void populateTable() {
        DefaultTableModel model = (DefaultTableModel) summaryjTable.getModel();
        model.setRowCount(0);
        if (business.getStateList() != null) {
            for (CityNetwork city : state.getCityList()) {
                Object[] row = new Object[3];
                row[0] = city;
                row[1] = city.getTotalVaccinesAdministeredInCity();
                row[2] = city.getTotalFailedVaccinesInCity();

                model.addRow(row);
            }

        }

    }

    /**
     * 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();
        jScrollPane1 = new javax.swing.JScrollPane();
        summaryjTable = new javax.swing.JTable();
        viewDetailsjButton = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        statejTextField = new javax.swing.JTextField();
        viewChartjButton = new javax.swing.JButton();
        backJButton5 = new javax.swing.JButton();

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Vaccine Adverse Event Reporting System (VARES)");

        summaryjTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

        }, new String[] { "City", "Total Vaccines Administered", "No. of Failed Vaccines" }) {
            boolean[] canEdit = new boolean[] { false, false, false };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        summaryjTable.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(summaryjTable);

        viewDetailsjButton.setText("View Details >>");
        viewDetailsjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewDetailsjButtonActionPerformed(evt);
            }
        });

        jLabel2.setText("State:");

        statejTextField.setEnabled(false);

        viewChartjButton.setText("View Chart");
        viewChartjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewChartjButtonActionPerformed(evt);
            }
        });

        backJButton5.setText("<< Back");
        backJButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backJButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 658, Short.MAX_VALUE)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                layout.createSequentialGroup().addComponent(backJButton5)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(viewChartjButton).addGap(175, 175, 175)
                                        .addComponent(viewDetailsjButton))
                        .addGroup(layout.createSequentialGroup().addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(statejTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 122,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addContainerGap()));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel2).addComponent(statejTextField,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(16, 16, 16)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 356,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(viewDetailsjButton).addComponent(viewChartjButton)
                                .addComponent(backJButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 23,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(74, Short.MAX_VALUE)));
    }// </editor-fold>//GEN-END:initComponents

    private void viewDetailsjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewDetailsjButtonActionPerformed
        // TODO add your handling code here:
        int selectedRow = summaryjTable.getSelectedRow();

        if (selectedRow < 0) {
            JOptionPane.showMessageDialog(null, "Please select a City");
            return;
        }
        CityNetwork city = (CityNetwork) summaryjTable.getValueAt(selectedRow, 0);

        VARESProviderReportingJPanel panel = new VARESProviderReportingJPanel(workContainer, userAccount, business,
                cdcEnterprise, cdcOrg, city);
        workContainer.add("VARESCityReportingJPanel", panel);
        CardLayout layout = (CardLayout) workContainer.getLayout();
        layout.next(workContainer);

    }//GEN-LAST:event_viewDetailsjButtonActionPerformed

    private void viewChartjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewChartjButtonActionPerformed
        // TODO add your handling code here:

        DefaultPieDataset pieDataset = new DefaultPieDataset();
        for (CityNetwork city : state.getCityList()) {
            pieDataset.setValue(city.getName(), city.getTotalFailedVaccinesInCity());

        }
        JFreeChart chart = ChartFactory.createPieChart("Total Failed Vaccines", pieDataset, true, true, true);
        PiePlot p = (PiePlot) chart.getPlot();
        ChartFrame frame = new ChartFrame("Total Failed Vaccines", chart);
        frame.setVisible(true);
        frame.setSize(450, 500);
    }//GEN-LAST:event_viewChartjButtonActionPerformed

    private void backJButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backJButton5ActionPerformed
        // TODO add your handling code here:
        workContainer.remove(this);
        CardLayout layout = (CardLayout) workContainer.getLayout();
        layout.previous(workContainer);
    }//GEN-LAST:event_backJButton5ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton backJButton3;
    private javax.swing.JButton backJButton4;
    private javax.swing.JButton backJButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField statejTextField;
    private javax.swing.JTable summaryjTable;
    private javax.swing.JButton viewChartjButton;
    private javax.swing.JButton viewDetailsjButton;
    // End of variables declaration//GEN-END:variables
}