userinterface.Citizen.CitizenWorkAreaJPanel.java Source code

Java tutorial

Introduction

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

import Business.EcoSystem;
import Business.Organization.Organization;
import Business.UserAccount.UserAccount;
import business.Area.Area;
import business.City.City;
import business.MedicalHistory.VitalSign;
import business.sensors.PollutionMonitorSensorUsage;
import businessLogic.formValidation.FormValidator;
import bussinesslogic.email.SendMail;
import controller.LineChartForHouseHoldPollutionLevels;
import controller.vitalSigns.VitalSignProcessor;
import java.awt.CardLayout;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.GregorianCalendar;
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 Aks
 */
public class CitizenWorkAreaJPanel extends javax.swing.JPanel {

    boolean addVitalSigns;
    private JPanel userProcessContainer;
    private UserAccount account;
    private Organization organization;
    private Area area;
    private City city;
    private EcoSystem business;

    /**
     * Creates new form CitizenWorkAreaJPanel
     */
    public CitizenWorkAreaJPanel(JPanel userProcessContainer, UserAccount account, Organization organization,
            Area area, City city, EcoSystem business) {
        initComponents();
        this.userProcessContainer = userProcessContainer;
        this.account = account;
        this.organization = organization;
        this.area = area;
        this.city = city;
        this.business = business;
        populateTable();
        populatePollutionLevelTable();
        populateInhalerSensorData();
        resetfields();
        addVitalSignButton.setEnabled(false);
    }

    public void populateInhalerSensorData() {
        DefaultTableModel dtm = (DefaultTableModel) inhalerTable.getModel();
        dtm.setRowCount(0);
        ArrayList<Date> keyList = new ArrayList<>(
                account.getCitizen().getHealthReport().getAsthamaInhalerSensor().getUsageHistory().keySet());
        Collections.sort(keyList);
        for (Date d : keyList) {
            Area area = account.getCitizen().getHealthReport().getAsthamaInhalerSensor().getUsageHistory().get(d);
            if (null != area) {
                Object row[] = new Object[2];
                row[0] = d.toString();
                row[1] = area;
                dtm.addRow(row);
            }
        }
    }

    public void populateTable() {

        DefaultTableModel dtm = (DefaultTableModel) vitalSigntable.getModel();
        int rowCount = vitalSigntable.getRowCount();
        for (int i = rowCount - 1; i >= 0; i--) {
            dtm.removeRow(i);
        }

        for (VitalSign vs : account.getCitizen().getHealthReport().getVitalSigns()) {
            Object row[] = new Object[2];
            row[0] = vs;
            if (vs.isVitalSignsNormal()) {
                row[1] = "Normal";
            } else {
                row[1] = "Abnormal";
            }
            dtm.addRow(row);
        }
    }

    public void resetfields() {
        this.bpField.setText("");
        this.resRateField.setText("");
        this.heartRateField.setText("");
        this.weightField.setText("");

    }

    public void populatePollutionLevelTable() {
        DefaultTableModel dtm = (DefaultTableModel) pollutionLevelTable.getModel();
        dtm.setRowCount(0);
        ArrayList<Date> keyList = new ArrayList<>(
                account.getCitizen().getResidence().getPollutionMonitorSensor().getUsageHistory().keySet());
        Collections.sort(keyList);
        for (Date d : keyList) {
            PollutionMonitorSensorUsage usage = account.getCitizen().getResidence().getPollutionMonitorSensor()
                    .getUsageHistory().get(d);
            if (null != usage && null != usage.getDate()) {
                Object row[] = new Object[2];
                row[0] = usage;
                if (usage.isPolluted()) {
                    row[1] = "Polluted";
                } else {
                    row[1] = "Clean";
                }
                dtm.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();
        jLabel2 = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        pollutionLevelTable = new javax.swing.JTable();
        jLabel9 = new javax.swing.JLabel();
        o3 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        co = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        pb = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        so2 = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        no2 = new javax.swing.JTextField();
        showLevels = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        resRateField = new javax.swing.JTextField();
        heartRateField = new javax.swing.JTextField();
        bpField = new javax.swing.JTextField();
        weightField = new javax.swing.JTextField();
        addVitalSignButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        vitalSigntable = new javax.swing.JTable();
        dispalyButton = new javax.swing.JButton();
        deleteButton = new javax.swing.JButton();
        updateVitalSign = new javax.swing.JButton();
        graphButton = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        addNewVitalSigns = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        inhalerTable = new javax.swing.JTable();
        backButton = new javax.swing.JButton();

        setBackground(new java.awt.Color(255, 255, 255));
        setForeground(new java.awt.Color(0, 51, 102));

        jLabel1.setFont(new java.awt.Font("Verdana", 1, 14)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(0, 51, 153));
        jLabel1.setText("Citizen Home");

        jLabel2.setText("Welcome");

        jTabbedPane1.setForeground(new java.awt.Color(0, 51, 153));

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));

        pollutionLevelTable.setModel(new javax.swing.table.DefaultTableModel(
                new Object[][] { { null, null }, { null, null }, { null, null }, { null, null } },
                new String[] { "Time Stamp", "Air Quality" }));
        jScrollPane2.setViewportView(pollutionLevelTable);

        jLabel9.setText("Ozone Level");

        o3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                o3ActionPerformed(evt);
            }
        });

        jLabel10.setText("Carbon Monoxide Level");

        jLabel11.setText("Lead Level");

        jLabel12.setText("Sulphur Dioxide Level");

        jLabel13.setText("Nitrogen Dioxide Level");

        no2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                no2ActionPerformed(evt);
            }
        });

        showLevels.setText("Show Levels");
        showLevels.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showLevelsActionPerformed(evt);
            }
        });

        jButton2.setText("Plot Line Chart");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(jPanel3Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup().addGroup(jPanel3Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap().addComponent(jScrollPane2,
                                javax.swing.GroupLayout.DEFAULT_SIZE, 553, Short.MAX_VALUE))
                        .addGroup(jPanel3Layout.createSequentialGroup().addGap(71, 71, 71).addGroup(jPanel3Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel3Layout.createSequentialGroup().addGroup(jPanel3Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel13).addComponent(jLabel12).addComponent(jLabel11))
                                        .addGap(48, 48, 48)
                                        .addGroup(jPanel3Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                                        false)
                                                .addComponent(so2, javax.swing.GroupLayout.Alignment.LEADING,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                                                .addComponent(pb, javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(no2)))
                                .addGroup(jPanel3Layout.createSequentialGroup()
                                        .addGroup(jPanel3Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel10).addComponent(jLabel9))
                                        .addGap(43, 43, 43)
                                        .addGroup(jPanel3Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                                        false)
                                                .addComponent(co, javax.swing.GroupLayout.DEFAULT_SIZE, 180,
                                                        Short.MAX_VALUE)
                                                .addComponent(o3)))
                                .addGroup(jPanel3Layout.createSequentialGroup().addComponent(showLevels)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jButton2).addGap(124, 124, 124)))))
                        .addContainerGap()));
        jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup().addGap(25, 25, 25)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 91,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(showLevels).addComponent(jButton2))
                        .addGap(24, 24, 24)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel9).addComponent(o3, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(12, 12, 12)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel10).addComponent(co, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel11).addComponent(pb, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel12).addComponent(so2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel13).addComponent(no2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(94, 94, 94)));

        jTabbedPane1.addTab("House Pollution Report", jPanel3);

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));

        jLabel4.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(0, 51, 153));
        jLabel4.setText("Respiratory Rate");

        jLabel5.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(0, 51, 153));
        jLabel5.setText("Heart Rate");

        jLabel6.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        jLabel6.setForeground(new java.awt.Color(0, 51, 153));
        jLabel6.setText("Systolic Blood Pressure");

        jLabel7.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(0, 51, 153));
        jLabel7.setText("Weight(pounds)");

        resRateField.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        resRateField.setForeground(new java.awt.Color(0, 51, 153));
        resRateField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resRateFieldActionPerformed(evt);
            }
        });
        resRateField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                resRateFieldKeyPressed(evt);
            }
        });

        heartRateField.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        heartRateField.setForeground(new java.awt.Color(0, 51, 153));
        heartRateField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                heartRateFieldActionPerformed(evt);
            }
        });

        bpField.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        bpField.setForeground(new java.awt.Color(0, 51, 153));
        bpField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bpFieldActionPerformed(evt);
            }
        });

        weightField.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        weightField.setForeground(new java.awt.Color(0, 51, 153));

        addVitalSignButton.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        addVitalSignButton.setForeground(new java.awt.Color(0, 51, 153));
        addVitalSignButton.setText("Add Vital Sign");
        addVitalSignButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addVitalSignButtonActionPerformed(evt);
            }
        });
        addVitalSignButton.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                addVitalSignButtonKeyPressed(evt);
            }
        });

        vitalSigntable.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        vitalSigntable.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        vitalSigntable.setForeground(new java.awt.Color(0, 51, 153));
        vitalSigntable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

        }, new String[] { "TimeStamp", "Is Vital Sign Normal" }) {
            boolean[] canEdit = new boolean[] { false, false };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        jScrollPane1.setViewportView(vitalSigntable);

        dispalyButton.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        dispalyButton.setForeground(new java.awt.Color(0, 51, 153));
        dispalyButton.setText("Display");
        dispalyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dispalyButtonActionPerformed(evt);
            }
        });

        deleteButton.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        deleteButton.setForeground(new java.awt.Color(0, 51, 153));
        deleteButton.setText("Delete");
        deleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteButtonActionPerformed(evt);
            }
        });

        updateVitalSign.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        updateVitalSign.setForeground(new java.awt.Color(0, 51, 153));
        updateVitalSign.setText("Update Vital Signs");
        updateVitalSign.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateVitalSignActionPerformed(evt);
            }
        });

        graphButton.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        graphButton.setForeground(new java.awt.Color(0, 51, 153));
        graphButton.setText("Display on a Linear Graph");
        graphButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                graphButtonActionPerformed(evt);
            }
        });

        jButton1.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        jButton1.setForeground(new java.awt.Color(0, 51, 153));
        jButton1.setText("Display on Bar Chart");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        addNewVitalSigns.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        addNewVitalSigns.setForeground(new java.awt.Color(0, 51, 153));
        addNewVitalSigns.setText("Add New Vital Signs");
        addNewVitalSigns.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addNewVitalSignsActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(jPanel4Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel4Layout.createSequentialGroup()
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 352,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(31, 31, 31)
                                        .addGroup(jPanel4Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 162,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(graphButton, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        162, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(jPanel4Layout.createSequentialGroup().addComponent(dispalyButton)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(deleteButton)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(updateVitalSign).addGap(87, 87, 87)
                                        .addComponent(addNewVitalSigns)))
                        .addGap(18, 18, 18))
                .addGroup(jPanel4Layout.createSequentialGroup().addGroup(jPanel4Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel4Layout.createSequentialGroup().addGap(93, 93, 93).addGroup(jPanel4Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel4Layout.createSequentialGroup().addGap(77, 77, 77).addComponent(
                                        addVitalSignButton, javax.swing.GroupLayout.PREFERRED_SIZE, 154,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel4Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(jPanel4Layout.createSequentialGroup().addComponent(jLabel7)
                                                .addGap(27, 27, 27).addComponent(weightField,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 119,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(jPanel4Layout.createSequentialGroup().addGroup(jPanel4Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel4).addComponent(jLabel5).addComponent(jLabel6))
                                                .addGap(27, 27, 27)
                                                .addGroup(jPanel4Layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(bpField,
                                                                javax.swing.GroupLayout.Alignment.TRAILING,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 119,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(heartRateField,
                                                                javax.swing.GroupLayout.Alignment.TRAILING,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 119,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(resRateField,
                                                                javax.swing.GroupLayout.Alignment.TRAILING,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 119,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))))))
                        .addGroup(
                                jPanel4Layout.createSequentialGroup().addGap(159, 159, 159).addComponent(jLabel3)))
                        .addContainerGap()));
        jPanel4Layout
                .setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel4Layout.createSequentialGroup().addGap(21, 21, 21).addComponent(jLabel3)
                                .addGap(18, 18, 18)
                                .addGroup(jPanel4Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 88,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                                jPanel4Layout.createSequentialGroup().addComponent(graphButton)
                                                        .addGap(18, 18, 18).addComponent(jButton1)))
                                .addGap(11, 11, 11)
                                .addGroup(jPanel4Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(dispalyButton).addComponent(deleteButton)
                                        .addComponent(updateVitalSign).addComponent(addNewVitalSigns))
                                .addGap(43, 43, 43)
                                .addGroup(jPanel4Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(resRateField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel4))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel4Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(heartRateField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel5))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel4Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(bpField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel6))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel4Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel7).addComponent(weightField,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(addVitalSignButton).addGap(24, 24, 24)));

        jTabbedPane1.addTab("Vital Signs", jPanel4);

        inhalerTable.setModel(new javax.swing.table.DefaultTableModel(
                new Object[][] { { null, null }, { null, null }, { null, null }, { null, null } },
                new String[] { "Time Stamp", "Area" }));
        jScrollPane3.setViewportView(inhalerTable);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(jPanel2Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup().addGap(42, 42, 42)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(79, 79, 79)));
        jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout
                        .createSequentialGroup().addGap(63, 63, 63).addComponent(jScrollPane3,
                                javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(303, Short.MAX_VALUE)));

        jTabbedPane1.addTab("Asthama Inhaler Reprt", jPanel2);

        backButton.setText("<<Back");
        backButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backButtonActionPerformed(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().addGap(25, 25, 25).addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup().addComponent(backButton).addGap(0, 0,
                                Short.MAX_VALUE))
                        .addGroup(layout.createSequentialGroup().addComponent(jTabbedPane1).addContainerGap())
                        .addGroup(layout.createSequentialGroup().addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel2).addGap(74, 74, 74)))));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel1).addComponent(jLabel2))
                        .addGap(23, 23, 23).addComponent(jTabbedPane1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(backButton)));
    }// </editor-fold>//GEN-END:initComponents

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

    private void addVitalSignButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addVitalSignButtonActionPerformed
        FormValidator fv = new FormValidator();
        VitalSignProcessor vsp = new VitalSignProcessor();
        if (fv.verifyStringInput(resRateField.getText()) && fv.verifyStringInput(heartRateField.getText())
                && fv.verifyStringInput(bpField.getText()) && fv.verifyStringInput(weightField.getText())) {
            int selectedRow = vitalSigntable.getSelectedRow();
            VitalSign vs = null;
            if (!addVitalSigns && selectedRow >= 0) {

                vs = (VitalSign) vitalSigntable.getValueAt(selectedRow, 0);
            } else {
                vs = account.getCitizen().getHealthReport().addVitalSigns();
            }
            vs.setRespiratoryRate(Float.parseFloat(resRateField.getText().trim()));
            vs.setHeartRate(Float.parseFloat(heartRateField.getText().trim()));
            vs.setSystolicBloodPressure(Float.parseFloat(bpField.getText().trim()));
            vs.setWeight(Float.parseFloat(weightField.getText().trim()));
            Calendar currentDateCalendar = new GregorianCalendar();
            Calendar birthDate = new GregorianCalendar();
            currentDateCalendar.setTime(account.getCitizen().getPerson().getDateOfBirth());
            birthDate.setTime(new Date());
            int diffYear = currentDateCalendar.get(Calendar.YEAR) - birthDate.get(Calendar.YEAR);

            vs.setVitalSignsNormal(vsp.verifyVitalSigns(vs, diffYear));
            vs.setTimeStamp(new Date());

            if (!vs.isVitalSignsNormal()) {
                SendMail mailer = new SendMail();
                mailer.sendAbnormalVitalSignsEmail(account.getCitizen(), vs);
            }
            populateTable();
            resetfields();
            JOptionPane.showMessageDialog(null, "Vital Sign Object Edited Successfully");

        } else {
            JOptionPane.showMessageDialog(null,
                    "One or more field empty or Invalid. Vital Signs Could not be added");
        }

    }//GEN-LAST:event_addVitalSignButtonActionPerformed

    private void addVitalSignButtonKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_addVitalSignButtonKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_addVitalSignButtonKeyPressed

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

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

    private void resRateFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_resRateFieldKeyPressed
        if (Character.isLetter(evt.getKeyChar())) {
            evt.consume();
        } else {
            return;
        }
    }//GEN-LAST:event_resRateFieldKeyPressed

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

    private void dispalyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dispalyButtonActionPerformed
        int selectedRow = vitalSigntable.getSelectedRow();
        if (selectedRow >= 0) {
            VitalSign vs = (VitalSign) vitalSigntable.getValueAt(selectedRow, 0);
            resRateField.setText(String.valueOf(vs.getRespiratoryRate()));
            heartRateField.setText(String.valueOf(vs.getHeartRate()));
            bpField.setText(String.valueOf(vs.getSystolicBloodPressure()));
            weightField.setText(String.valueOf(vs.getWeight()));
        } else {
            JOptionPane.showMessageDialog(null, "Please select a row from the table first", "Warning",
                    JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_dispalyButtonActionPerformed

    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
        int selectedRow = vitalSigntable.getSelectedRow();
        if (selectedRow >= 0) {
            int dialogButton = JOptionPane.YES_NO_OPTION;
            int dialogResult = JOptionPane.showConfirmDialog(null, "Would you like to delete Vital Sign?",
                    "Warning", dialogButton);
            if (dialogResult == JOptionPane.YES_OPTION) {
                VitalSign vs = (VitalSign) vitalSigntable.getValueAt(selectedRow, 0);
                account.getCitizen().getHealthReport().deleteVitalSign(vs);
                populateTable();
                resetfields();

            }
        } else {
            JOptionPane.showMessageDialog(null, "Please select a row from the table first", "Warning",
                    JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_deleteButtonActionPerformed

    private void updateVitalSignActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateVitalSignActionPerformed
        int selectedRow = vitalSigntable.getSelectedRow();
        if (selectedRow >= 0) {

            VitalSign vs = (VitalSign) vitalSigntable.getValueAt(selectedRow, 0);
            resRateField.setEditable(true);
            heartRateField.setEditable(true);
            bpField.setEditable(true);
            weightField.setEditable(true);
            addVitalSignButton.setEnabled(true);
            addVitalSigns = false;
        }

    }//GEN-LAST:event_updateVitalSignActionPerformed

    private void graphButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_graphButtonActionPerformed

        JFreeChart lineChart = ChartFactory.createLineChart("Vital Sign Chart", "TimeStamp", "Vital Signs",
                createDataset(), PlotOrientation.VERTICAL, true, true, false);
        ChartFrame cf = new ChartFrame("Vital Sign Chart", lineChart);
        CategoryPlot plot = lineChart.getCategoryPlot();
        //        Stroke[] seriesStrokeArray = new Stroke[3];
        //        seriesStrokeArray[0] = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
        //                1.0f, new float[]{10.0f, 6.0f}, 0.0f);
        //        seriesStrokeArray[1] = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
        //                1.0f, new float[]{6.0f, 6.0f}, 0.0f);
        //        seriesStrokeArray[2] = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
        //                1.0f, new float[]{2.0f, 6.0f}, 0.0f);
        //        plot.setShadowGenerator(null);
        lineChart.setBackgroundPaint(Color.yellow);
        plot.setBackgroundPaint(Color.yellow);
        cf.setSize(450, 450);
        cf.setVisible(true);
    }//GEN-LAST:event_graphButtonActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        JFreeChart lineChart = ChartFactory.createBarChart("Vital Sign Chart", "TimeStamp", "Vital Signs",
                createDataset(), PlotOrientation.VERTICAL, true, true, false);
        ChartFrame cf = new ChartFrame("Vital Sign Chart", lineChart);
        CategoryPlot plot = lineChart.getCategoryPlot();
        //        Stroke[] seriesStrokeArray = new Stroke[3];
        //        seriesStrokeArray[0] = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
        //                1.0f, new float[]{10.0f, 6.0f}, 0.0f);
        //        seriesStrokeArray[1] = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
        //                1.0f, new float[]{6.0f, 6.0f}, 0.0f);
        //        seriesStrokeArray[2] = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
        //                1.0f, new float[]{2.0f, 6.0f}, 0.0f);
        //        plot.setShadowGenerator(null);
        lineChart.setBackgroundPaint(Color.yellow);
        plot.setBackgroundPaint(Color.yellow);
        cf.setSize(450, 450);
        cf.setVisible(true);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void addNewVitalSignsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addNewVitalSignsActionPerformed
        resRateField.setEditable(true);
        heartRateField.setEditable(true);
        bpField.setEditable(true);
        weightField.setEditable(true);
        addVitalSignButton.setEnabled(true);
        addVitalSigns = true;
    }//GEN-LAST:event_addNewVitalSignsActionPerformed

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

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

    private void showLevelsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showLevelsActionPerformed
        int row = pollutionLevelTable.getSelectedRow();
        if (row < 0) {
            JOptionPane.showMessageDialog(null, "Please select a row");
        } else {
            PollutionMonitorSensorUsage usage = (PollutionMonitorSensorUsage) pollutionLevelTable.getValueAt(row,
                    0);
            if (null != usage) {
                o3.setText(String.valueOf(usage.getOzoneLevel()));
                if (usage.getOzoneLevel() > usage.getO3Threshold()) {
                    o3.setBackground(Color.pink);
                } else {
                    o3.setBackground(Color.green);
                }

                co.setText(String.valueOf(usage.getCarbonMonoxideLevel()));
                if (usage.getCarbonMonoxideLevel() > usage.getCoThreshold()) {
                    co.setBackground(Color.pink);
                } else {
                    co.setBackground(Color.green);
                }

                no2.setText(String.valueOf(usage.getNitrogenDioxideLevel()));
                if (usage.getNitrogenDioxideLevel() > usage.getNo2Threshold()) {
                    no2.setBackground(Color.pink);
                } else {
                    no2.setBackground(Color.green);
                }

                so2.setText(String.valueOf(usage.getSulfurDioxideLevel()));
                if (usage.getSulfurDioxideLevel() > usage.getSo2Threshold()) {
                    so2.setBackground(Color.pink);
                } else {
                    so2.setBackground(Color.green);
                }

                pb.setText(String.valueOf(usage.getLeadLevel()));
                if (usage.getLeadLevel() > usage.getPbThreshold()) {
                    pb.setBackground(Color.pink);
                } else {
                    pb.setBackground(Color.green);
                }
            }
        }
    }//GEN-LAST:event_showLevelsActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        LineChartForHouseHoldPollutionLevels lineCharter = new LineChartForHouseHoldPollutionLevels();
        lineCharter.generateLineChart(account.getCitizen());
    }//GEN-LAST:event_jButton2ActionPerformed

    private DefaultCategoryDataset createDataset() {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        for (VitalSign vs : account.getCitizen().getHealthReport().getVitalSigns()) {
            dataset.addValue(vs.getSystolicBloodPressure(), "blood Pressure", vs.getTimeStamp());
            dataset.addValue(vs.getHeartRate(), "Heart Rate", vs.getTimeStamp());
            dataset.addValue(vs.getRespiratoryRate(), "Respiratory Rate", vs.getTimeStamp());
            dataset.addValue(vs.getWeight(), "Weight", vs.getTimeStamp());

        }
        return dataset;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addNewVitalSigns;
    private javax.swing.JButton addVitalSignButton;
    private javax.swing.JButton backButton;
    private javax.swing.JTextField bpField;
    private javax.swing.JTextField co;
    private javax.swing.JButton deleteButton;
    private javax.swing.JButton dispalyButton;
    private javax.swing.JButton graphButton;
    private javax.swing.JTextField heartRateField;
    private javax.swing.JTable inhalerTable;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField no2;
    private javax.swing.JTextField o3;
    private javax.swing.JTextField pb;
    private javax.swing.JTable pollutionLevelTable;
    private javax.swing.JTextField resRateField;
    private javax.swing.JButton showLevels;
    private javax.swing.JTextField so2;
    private javax.swing.JButton updateVitalSign;
    private javax.swing.JTable vitalSigntable;
    private javax.swing.JTextField weightField;
    // End of variables declaration//GEN-END:variables
}