UserInterface.CDC.VaccineCityDistributionJPanel.java Source code

Java tutorial

Introduction

Here is the source code for UserInterface.CDC.VaccineCityDistributionJPanel.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 VaccineCityDistributionJPanel 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 VaccineCityDistributionJPanel(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[2];
                row[0] = city;
                row[1] = city.getTotalVaccinesDistributedInCity();

                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();
        backJButton3 = new javax.swing.JButton();

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Vaccine Distribution in State");

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

        }, new String[] { "City", "Total Vaccines Distibuted" }) {
            boolean[] canEdit = new boolean[] { 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);
            }
        });

        backJButton3.setText("<< Back");
        backJButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backJButton3ActionPerformed(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(backJButton3)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(viewChartjButton).addGap(162, 162, 162)
                                        .addComponent(viewDetailsjButton))
                        .addGroup(layout.createSequentialGroup().addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(statejTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 127,
                                        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.RELATED)
                        .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(18, 18, 18)
                        .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(backJButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 23,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(77, 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);

        VaccineProviderDistributionJPanel panel = new VaccineProviderDistributionJPanel(workContainer, userAccount,
                business, cdcEnterprise, cdcOrg, city);
        workContainer.add("VaccineProviderDistributionJPanel", 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.getTotalVaccinesDistributedInCity());

        }
        JFreeChart chart = ChartFactory.createPieChart("Total Vaccines Distributed", pieDataset, true, true, true);
        PiePlot p = (PiePlot) chart.getPlot();
        ChartFrame frame = new ChartFrame("Total Vaccines Distributed", chart);
        frame.setVisible(true);
        frame.setSize(450, 500);

    }//GEN-LAST:event_viewChartjButtonActionPerformed

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton backJButton3;
    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
}