userinterface.AdminRole.DataAnalysisJPanel.java Source code

Java tutorial

Introduction

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

import business.Enterprise.Enterprise;
import business.Organization.DonorOrganization;
import business.Organization.Organization;
import business.EcoSystem;
import business.Organization.LabOrganization;
import business.Organization.NutritionistOrganization;
import business.Person.Donor;
import business.Person.VitalSigns;
import business.WorkQueue.WorkRequest;
import java.awt.CardLayout;
import java.awt.Color;
import javax.swing.JPanel;
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.PiePlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;

/**
 *
 * @author piyush sharma
 */
public class DataAnalysisJPanel extends javax.swing.JPanel {

    /**
     * Creates new form DataAnalysisJPanel
     */
    public JPanel userProcessContainer;
    public Enterprise enterprise;
    public Organization organization;
    public EcoSystem ecosystem;

    public DataAnalysisJPanel(JPanel userProcessContainer, Enterprise enterprise, Organization organization,
            EcoSystem ecosystem) {
        initComponents();
        this.userProcessContainer = userProcessContainer;
        this.enterprise = enterprise;
        this.organization = organization;
        this.ecosystem = ecosystem;
    }

    /**
     * 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() {

        donorGenderButton = new javax.swing.JButton();
        backButton = new javax.swing.JButton();
        donorHealthBtn = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jButton5 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();

        setBackground(new java.awt.Color(255, 255, 255));
        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        donorGenderButton.setFont(new java.awt.Font("Calibri", 1, 18)); // NOI18N
        donorGenderButton.setText("View Chart");
        donorGenderButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                donorGenderButtonActionPerformed(evt);
            }
        });
        add(donorGenderButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 120, 140, -1));

        backButton.setFont(new java.awt.Font("Calibri", 1, 18)); // NOI18N
        backButton.setText("<<Back");
        backButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backButtonActionPerformed(evt);
            }
        });
        add(backButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 480, -1, -1));

        donorHealthBtn.setFont(new java.awt.Font("Calibri", 1, 18)); // NOI18N
        donorHealthBtn.setText("View Chart");
        donorHealthBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                donorHealthBtnActionPerformed(evt);
            }
        });
        add(donorHealthBtn, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 180, 145, -1));

        jButton4.setFont(new java.awt.Font("Calibri", 1, 18)); // NOI18N
        jButton4.setText("View Chart");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        add(jButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 250, 145, -1));

        jLabel1.setFont(new java.awt.Font("Calibri", 1, 36)); // NOI18N
        jLabel1.setText("Data analysis");
        add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(43, 16, 331, 46));

        jLabel2.setFont(new java.awt.Font("Calibri", 1, 18)); // NOI18N
        jLabel2.setText("Age Group :");
        add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 320, 240, 30));

        jLabel3.setFont(new java.awt.Font("Calibri", 1, 18)); // NOI18N
        jLabel3.setText("Donor Gender Ratio:");
        add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 120, 240, 30));

        jLabel5.setFont(new java.awt.Font("Calibri", 1, 18)); // NOI18N
        jLabel5.setText("Donor Health :");
        add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 180, 240, 30));

        jButton5.setFont(new java.awt.Font("Calibri", 1, 18)); // NOI18N
        jButton5.setText("View Chart");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 320, 145, -1));

        jLabel6.setFont(new java.awt.Font("Calibri", 1, 18)); // NOI18N
        jLabel6.setText("Donor Vital Signs :");
        add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 250, 240, 30));
    }// </editor-fold>//GEN-END:initComponents

    private void donorGenderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_donorGenderButtonActionPerformed
        // TODO add your handling code here:
        int m = 0, f = 0;

        for (Organization org : enterprise.getOrganizationDirectory().getOrganizationList()) {
            if (org instanceof DonorOrganization) {
                for (Donor donor : org.getDonorDirectory().getDonorList()) {

                    if (donor.getGender().equalsIgnoreCase("male")) {
                        m++;
                    }
                    if (donor.getGender().equalsIgnoreCase("female")) {
                        f++;
                    }
                }
            }
        }
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.setValue(m, "Number", "Male");
        dataset.setValue(f, "Number", "Female");

        JFreeChart chart = ChartFactory.createBarChart("Donors", "Gender", "Number", dataset,
                PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.black);

        ChartFrame frame = new ChartFrame("Availability Bar Chart", chart);

        frame.setVisible(true);
        frame.setSize(450, 500);

        //       panel.removeAll();
        //        panel.add(frame, BorderLayout.CENTER);
        //        panel.validate();
    }//GEN-LAST:event_donorGenderButtonActionPerformed

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

    private void donorHealthBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_donorHealthBtnActionPerformed
        // TODO add your handling code here:
        int count = 0;
        int count1 = 0;

        for (Organization org : enterprise.getOrganizationDirectory().getOrganizationList()) {

            if (org instanceof NutritionistOrganization) {
                for (WorkRequest request : org.getWorkQueue().getWorkRequestList()) {
                    count = count + 1;
                }
            }
            if (org instanceof LabOrganization) {
                for (WorkRequest request : org.getWorkQueue().getWorkRequestList()) {
                    count1++;
                }
            }

        }

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.setValue(count, "Number", "unfit");
        dataset.setValue(count1, "Number", "fit");

        JFreeChart chart = ChartFactory.createBarChart("Donors", "Donor", "Number", dataset,
                PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.black);

        ChartFrame frame = new ChartFrame("Donor Information", chart);

        frame.setVisible(true);
        frame.setSize(450, 500);

    }//GEN-LAST:event_donorHealthBtnActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        int haemo = 0, bp = 0, weight = 0, temp = 0;

        for (Organization org : enterprise.getOrganizationDirectory().getOrganizationList()) {
            if (org instanceof DonorOrganization) {
                for (Donor donor : org.getDonorDirectory().getDonorList()) {
                    for (VitalSigns vs : donor.getVsh().getVitalSignHistory()) {
                        if (vs.getHaemoglobinLevel() < 13) {
                            haemo++;
                        }
                        if (vs.getBloodPressure() < 80 || vs.getBloodPressure() > 120) {
                            bp++;
                        }
                        if (vs.getWeight() < 110 || vs.getWeight() > 400) {
                            weight++;
                        }
                        if (vs.getTemperature() < 90 || vs.getTemperature() > 99) {
                            temp++;
                        }
                    }
                }
            }
        }
        DefaultPieDataset dataset = new DefaultPieDataset();
        dataset.setValue("haemoglobin", haemo);
        dataset.setValue("bloodpressure", bp);
        dataset.setValue("weight", weight);
        dataset.setValue("temperature", temp);

        JFreeChart chart = ChartFactory.createPieChart("DonorInformation", dataset, true, true, true);
        //        CategoryPlot p = chart.getCategoryPlot();
        //        p.setRangeGridlinePaint(Color.black);
        PiePlot p = (PiePlot) chart.getPlot();
        ChartFrame frame = new ChartFrame("Donor Information", chart);

        frame.setVisible(true);
        frame.setSize(450, 500);

    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        // TODO add your handling code here:
        int m = 0, f = 0, g = 0;

        for (Organization org : enterprise.getOrganizationDirectory().getOrganizationList()) {
            if (org instanceof DonorOrganization) {
                for (Donor donor : org.getDonorDirectory().getDonorList()) {
                    int age = donor.getAge();

                    if (age >= 17 && age <= 35) {
                        m++;
                    }
                    if (age >= 36 && age <= 50) {
                        f++;
                    }
                    if (age >= 51 && age <= 65) {
                        g++;
                    }

                }
            }
        }
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.setValue(m, "Number", "Group1(17 - 35");
        dataset.setValue(f, "Number", "Group2(36 - 50");
        dataset.setValue(g, "Number", "Group3(51 - 65");

        JFreeChart chart = ChartFactory.createBarChart("Age Chart", "Age Group", "Number", dataset,
                PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.black);

        ChartFrame frame = new ChartFrame("Age Bar Chart", chart);

        frame.setVisible(true);
        frame.setSize(450, 500);

    }//GEN-LAST:event_jButton5ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton backButton;
    private javax.swing.JButton donorGenderButton;
    private javax.swing.JButton donorHealthBtn;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    // End of variables declaration//GEN-END:variables
}