UserInterface.DoctorRole.ViewDonorReport.java Source code

Java tutorial

Introduction

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

import Business.Donor.Donor;
import Business.DonorSensor.VitalSign;
import Business.DonorSensor.VitalSignDirectory;
import Business.Enterprise.Enterprise;
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.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 *
 * @author shivam
 */
public class ViewDonorReport extends javax.swing.JPanel {
    private VitalSignDirectory vitalSigndir;
    private Donor donor;
    private JPanel userProcessContainer;
    private Enterprise enterprise;
    private DefaultCategoryDataset dataset;

    /**
     * Creates new form ViewDonorReport
     */
    public ViewDonorReport(JPanel userProcessContainer, Enterprise enterprise, Donor donor) {
        initComponents();
        this.userProcessContainer = userProcessContainer;
        this.enterprise = enterprise;
        this.donor = donor;
        vitalSigndir = donor.getVitalSignDir();
        DonorNametext.setText(donor.getName());
        PopulateTable();
    }

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

        jScrollPane1 = new javax.swing.JScrollPane();
        DonorsummaryTable = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        DonorNametext = new javax.swing.JTextField();
        ViewGraphBtn = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

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

        DonorsummaryTable.setModel(new javax.swing.table.DefaultTableModel(
                new Object[][] { { null, null, null, null }, { null, null, null, null }, { null, null, null, null },
                        { null, null, null, null } },
                new String[] { "Timestamp", "Blood Pressure", "Blood Platlets", "Hemaglobin" }));
        jScrollPane1.setViewportView(DonorsummaryTable);

        add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(37, 43, -1, 155));

        jLabel1.setText("Name");
        add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(162, 247, -1, -1));
        add(DonorNametext, new org.netbeans.lib.awtextra.AbsoluteConstraints(204, 242, 97, -1));

        ViewGraphBtn.setIcon(
                new javax.swing.ImageIcon(getClass().getResource("/UserInterface/DoctorRole/Bar-chart.png"))); // NOI18N
        ViewGraphBtn.setText("View Graph");
        ViewGraphBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ViewGraphBtnActionPerformed(evt);
            }
        });
        add(ViewGraphBtn, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 290, 120, 130));

        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(20, 470, -1, -1));
    }// </editor-fold>//GEN-END:initComponents

    public void PopulateTable() {
        DefaultTableModel model = (DefaultTableModel) DonorsummaryTable.getModel();

        model.setRowCount(0);
        for (VitalSign vs : vitalSigndir.getVitalSignDir()) {
            Object row[] = new Object[4];
            row[0] = vs;
            row[1] = vs.getBloodPressure();
            row[2] = vs.getBloodPlatlets();
            row[3] = vs.getHemoglobinLevel();
            model.addRow(row);

        }
    }

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

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

        CardLayout layout = (CardLayout) userProcessContainer.getLayout();
        layout.previous(userProcessContainer);
    }//GEN-LAST:event_jButton1ActionPerformed

    public void Graph() {
        dataset = new DefaultCategoryDataset();
        if (vitalSigndir.getVitalSignDir().isEmpty()) {
            for (VitalSign vs : vitalSigndir.getVitalSignDir()) {

                dataset.addValue(Float.parseFloat(vs.getBloodPressure()), "Blood Pressure", vs.getTimestamp());
                dataset.addValue(Float.parseFloat(vs.getBloodPlatlets()), "Blood Platelets", vs.getTimestamp());
                dataset.addValue(Float.parseFloat(vs.getHemoglobinLevel()), "Hemoglobin Level", vs.getTimestamp());
                //dataset.addValue(vs.getWeight(), "Weight", vs.getTimestamp());

            }

            JFreeChart chartFactory = ChartFactory.createBarChart3D("VitalSign", "Time", "VitalSign", dataset,
                    PlotOrientation.VERTICAL, true, true, false);

            BarRenderer renderer = null;
            CategoryPlot plot = chartFactory.getCategoryPlot();
            renderer = new BarRenderer();
            ChartFrame frame = new ChartFrame("Bar Chart for VitalSign", chartFactory);
            frame.setVisible(true);
            frame.setSize(700, 320);
        }

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField DonorNametext;
    private javax.swing.JTable DonorsummaryTable;
    private javax.swing.JButton ViewGraphBtn;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}