userinterface.SystemAdminWorkArea.DisplayOperationJPanel.java Source code

Java tutorial

Introduction

Here is the source code for userinterface.SystemAdminWorkArea.DisplayOperationJPanel.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 Business.TreatmentCatalog.TreatedFor;
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 DisplayOperationJPanel extends javax.swing.JPanel {

    private JPanel userProcessContainer;
    private EcoSystem system;

    /**
     * Creates new form DisplayOperationJPanel
     */
    public DisplayOperationJPanel(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) treatmentTable.getModel();

        model.setRowCount(0);

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

        for (Enterprise enterprise : network.getEnterpriseDirectory().getEnterpriseList()) {
            TreatedFor t = enterprise.findMaxVal();

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

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

            row[2] = t == null ? "No patient Diagnosed Yet!" : t.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();
        stateCombo = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        treatmentTable = new javax.swing.JTable();
        jButton2 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

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

        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 36)); // NOI18N
        jLabel1.setText("Display Patients Treated For");
        add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(317, 16, -1, -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(230, 180, 148, -1));

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel2.setText("Select State");
        add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 180, -1, 30));

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

        add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 230, 860, 102));

        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(100, 390, 125, -1));

        jButton1.setFont(new java.awt.Font("Tahoma", 1, 18)); // 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(100, 560, -1, -1));
    }// </editor-fold>//GEN-END:initComponents

    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 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 jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        int selectedRow = treatmentTable.getSelectedRow();

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

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

        for (TreatedFor t : ent.getTreatmentCatalog().getTreatmentList()) {

            dataSet.setValue(t.getCount(), "Treatments", t.getTreatment());

            i++;

        }

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

    }//GEN-LAST:event_jButton2ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    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;
    private javax.swing.JTable treatmentTable;
    // End of variables declaration//GEN-END:variables
}