userinterface.SystemAdminWorkArea.DisplayAllergyJPanel.java Source code

Java tutorial

Introduction

Here is the source code for userinterface.SystemAdminWorkArea.DisplayAllergyJPanel.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.SystemAdminWorkArea;

import Business.AllergyList.Allergy;
import Business.EcoSystem;
import Business.Enterprise.Enterprise;
import Business.Network.Network;
import java.awt.CardLayout;
import java.awt.Color;
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.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 *
 * @author Neelu
 */
public class DisplayAllergyJPanel extends javax.swing.JPanel {

    private JPanel userProcessContainer;
    private EcoSystem system;

    /**
     * Creates new form DisplayAllergyJPanel
     */
    public DisplayAllergyJPanel(JPanel upc, EcoSystem s) {
        initComponents();
        userProcessContainer = upc;
        system = s;

        populateCombo();

    }

    public void populateCombo() {
        for (Network net : system.getNetworkList()) {
            stateCombo.addItem(net);
        }
    }

    public void populateTable() {
        DefaultTableModel model = (DefaultTableModel) allergyTable.getModel();

        model.setRowCount(0);

        Network network = (Network) stateCombo.getSelectedItem();

        for (Enterprise enterprise : network.getEnterpriseDirectory().getEnterpriseList()) {

            Allergy a = enterprise.findMaxValue();

            Object row[] = new Object[3];
            row[0] = enterprise;

            row[1] = a == null ? "No patient Diagnosed Yet!" : a.getAllergyName();

            row[2] = a == null ? "No patient Diagnosed Yet!" : a.getCount();

            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();
        allergyTable = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        stateCombo = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();

        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 36)); // NOI18N
        jLabel1.setText("Display Allergies Affecting a State");
        add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(323, 16, -1, -1));

        allergyTable.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        allergyTable
                .setModel(new javax.swing.table.DefaultTableModel(
                        new Object[][] { { null, null, null }, { null, null, null }, { null, null, null },
                                { null, null, null } },
                        new String[] { "Enterprise", "Alllergy", "Allergy Count" }));
        jScrollPane1.setViewportView(allergyTable);

        add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 240, 820, 102));

        jButton1.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
        jButton1.setText("<<Back");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 520, -1, -1));

        jButton2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jButton2.setText("Bar Chart");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 390, 125, -1));

        stateCombo.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        stateCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stateComboActionPerformed(evt);
            }
        });
        add(stateCombo, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 190, 150, -1));

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel2.setText("Select State");
        add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 190, -1, 30));
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        userProcessContainer.remove(this);
        CardLayout cardLayout = (CardLayout) userProcessContainer.getLayout();
        cardLayout.previous(userProcessContainer);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void stateComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stateComboActionPerformed
        // TODO add your handling code here:
        populateTable();
    }//GEN-LAST:event_stateComboActionPerformed

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

        if (selectedRow < 0) {
            JOptionPane.showMessageDialog(null, "Please select a Row!");
            return;
        }
        Enterprise ent = (Enterprise) allergyTable.getValueAt(selectedRow, 0);

        DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
        int i = 1;

        for (Allergy a : ent.getAllergyList().getAllergyList()) {

            dataSet.setValue(a.getCount(), "Allergies", a.getAllergyName());

            i++;

        }

        JFreeChart chart = ChartFactory.createBarChart("Allergies Affecting A State", "Allergy Name", "Count",
                dataSet, PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.BLACK);
        ChartFrame frame = new ChartFrame("Allergies In A State", chart);
        frame.setVisible(true);
        frame.setSize(800, 550);

    }//GEN-LAST:event_jButton2ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable allergyTable;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JComboBox stateCombo;
    // End of variables declaration//GEN-END:variables
}