UI.CityMayor.CityMayorFrame.java Source code

Java tutorial

Introduction

Here is the source code for UI.CityMayor.CityMayorFrame.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 UI.CityMayor;

import BLL.DrivingData.Drive;
import BLL.DrivingData.DriveDirectory;
import BLL.EcoSystem;
import BLL.Enterprise.Enterprise;
import BLL.Network.Network;
import BLL.Organization.Organization;
import BLL.UserAccount.UserAccount;
import static UI.SmartDriveMain.dB4OUtil;
import static UI.SmartDriveMain.isNetworkAdminAvailable;
import java.awt.BorderLayout;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 *
 * @author Ankur
 */
public class CityMayorFrame extends javax.swing.JFrame {

    /**
     * Creates new form ResidentAdminFrame
     */
    EcoSystem system;
    Enterprise enterprise;
    UserAccount account;
    Organization organization;
    DriveDirectory driveDirectory;

    public CityMayorFrame(UserAccount account, Organization organization, Enterprise enterprise, Network network,
            EcoSystem system) {
        initComponents();
        welcomeRoleLabel.setText(account.getPerson().getName());
        this.system = system;
        this.enterprise = enterprise;
        this.account = account;
        this.organization = organization;
        driveDirectory = network.getDriveDirectory();
        isNetworkAdminAvailable = 1;
    }

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

        horizontalSpiltPane = new javax.swing.JSplitPane();
        headerPanel = new javax.swing.JPanel();
        headerLabel = new javax.swing.JLabel();
        logoutBtn = new javax.swing.JButton();
        welcomeLabel = new javax.swing.JLabel();
        welcomeRoleLabel = new javax.swing.JLabel();
        generateReportsBtn = new javax.swing.JButton();
        mainPanel = new javax.swing.JPanel();
        mostFatalPairPanel = new javax.swing.JPanel();
        weatherTitleLabel1 = new javax.swing.JLabel();
        mostFatalPairLabel = new javax.swing.JLabel();
        noOfAccidentValueLbl1 = new javax.swing.JLabel();
        selectOrganizationLbl3 = new javax.swing.JLabel();
        individualFactorPanel = new javax.swing.JPanel();
        weatherTitleLabel3 = new javax.swing.JLabel();
        causeComboBox = new javax.swing.JComboBox();
        noOfOccurancesLbl = new javax.swing.JLabel();
        noOfAccidentsLbl = new javax.swing.JLabel();
        totalCauseOccuranceLbl = new javax.swing.JLabel();
        noOfCauseWiseAccidentValueLbl = new javax.swing.JLabel();
        noOfOccurancesLbl1 = new javax.swing.JLabel();
        causeForAccidentPercentageLbl = new javax.swing.JLabel();
        totalAccidentsPanel = new javax.swing.JPanel();
        selectOrganizationLbl = new javax.swing.JLabel();
        weatherTitleLabel = new javax.swing.JLabel();
        selectOrganizationLbl1 = new javax.swing.JLabel();
        accidentPercentageLbl = new javax.swing.JLabel();
        totalDrivingInstancesValueLbl = new javax.swing.JLabel();
        noOfAccidentValueLbl = new javax.swing.JLabel();
        accidentPercentageValueLbl = new javax.swing.JLabel();
        accidentStatisticsPanel = new javax.swing.JPanel();
        weatherTitleLabel2 = new javax.swing.JLabel();
        chartPanel = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Doctor");

        horizontalSpiltPane.setDividerLocation(100);
        horizontalSpiltPane.setDividerSize(1);
        horizontalSpiltPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

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

        headerLabel.setFont(new java.awt.Font("Tahoma", 3, 24)); // NOI18N
        headerLabel.setForeground(new java.awt.Color(0, 102, 153));
        headerLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/car.jpg"))); // NOI18N
        headerLabel.setText("Smart Drive");

        logoutBtn.setBackground(new java.awt.Color(255, 255, 255));
        logoutBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/logout.jpg"))); // NOI18N
        logoutBtn.setToolTipText("Logout and Close");
        logoutBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logoutBtnActionPerformed(evt);
            }
        });

        welcomeLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        welcomeLabel.setText("Welcome to Portal:");

        welcomeRoleLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        generateReportsBtn.setBackground(new java.awt.Color(255, 255, 255));
        generateReportsBtn.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        generateReportsBtn.setForeground(new java.awt.Color(0, 102, 153));
        generateReportsBtn.setText("Generate Reports");
        generateReportsBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                generateReportsBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout headerPanelLayout = new javax.swing.GroupLayout(headerPanel);
        headerPanel.setLayout(headerPanelLayout);
        headerPanelLayout.setHorizontalGroup(headerPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(headerPanelLayout.createSequentialGroup().addContainerGap()
                        .addGroup(headerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(headerPanelLayout.createSequentialGroup()
                                        .addComponent(headerLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 214,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(115, 115, 115).addComponent(generateReportsBtn))
                                .addGroup(headerPanelLayout.createSequentialGroup().addComponent(welcomeLabel)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(welcomeRoleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 144,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 285, Short.MAX_VALUE)
                        .addComponent(logoutBtn).addContainerGap()));
        headerPanelLayout
                .setVerticalGroup(
                        headerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, headerPanelLayout
                                        .createSequentialGroup().addGroup(headerPanelLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(headerPanelLayout.createSequentialGroup()
                                                        .addContainerGap()
                                                        .addGroup(headerPanelLayout.createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING, false)
                                                                .addComponent(logoutBtn,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        Short.MAX_VALUE)
                                                                .addComponent(headerLabel)))
                                                .addGroup(headerPanelLayout.createSequentialGroup()
                                                        .addGap(29, 29, 29).addComponent(generateReportsBtn,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 40,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGroup(headerPanelLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                                        false)
                                                .addComponent(welcomeLabel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(welcomeRoleLabel,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addContainerGap()));

        horizontalSpiltPane.setTopComponent(headerPanel);

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

        mostFatalPairPanel.setBackground(new java.awt.Color(255, 255, 255));
        mostFatalPairPanel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(240, 240, 240), 1, true));

        weatherTitleLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        weatherTitleLabel1.setText("Most Fatal cause pair:");

        mostFatalPairLabel.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        noOfAccidentValueLbl1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        selectOrganizationLbl3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        selectOrganizationLbl3.setText("Number of Accident Cases:");

        javax.swing.GroupLayout mostFatalPairPanelLayout = new javax.swing.GroupLayout(mostFatalPairPanel);
        mostFatalPairPanel.setLayout(mostFatalPairPanelLayout);
        mostFatalPairPanelLayout.setHorizontalGroup(mostFatalPairPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mostFatalPairPanelLayout.createSequentialGroup().addGap(63, 63, 63)
                        .addGroup(mostFatalPairPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(mostFatalPairPanelLayout.createSequentialGroup()
                                        .addComponent(selectOrganizationLbl3).addGap(18, 18, 18)
                                        .addComponent(noOfAccidentValueLbl1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                50, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(mostFatalPairPanelLayout.createSequentialGroup().addGap(91, 91, 91)
                                        .addComponent(weatherTitleLabel1))
                                .addComponent(mostFatalPairLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 300,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(53, Short.MAX_VALUE)));
        mostFatalPairPanelLayout.setVerticalGroup(
                mostFatalPairPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(mostFatalPairPanelLayout.createSequentialGroup().addContainerGap()
                                .addComponent(weatherTitleLabel1).addGap(18, 18, 18)
                                .addComponent(mostFatalPairLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 15,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addGroup(mostFatalPairPanelLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(selectOrganizationLbl3).addComponent(noOfAccidentValueLbl1,
                                                javax.swing.GroupLayout.PREFERRED_SIZE, 15,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        individualFactorPanel.setBackground(new java.awt.Color(255, 255, 255));
        individualFactorPanel
                .setBorder(new javax.swing.border.LineBorder(new java.awt.Color(240, 240, 240), 1, true));

        weatherTitleLabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        weatherTitleLabel3.setText("Individual Cause wise statistics:");

        causeComboBox.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        causeComboBox.setModel(new javax.swing.DefaultComboBoxModel(
                new String[] { "Overspeeding", "Abnormal Tyre Pressure", "Abnormal Health", "Harsh Weather" }));
        causeComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                causeChanged(evt);
            }
        });

        noOfOccurancesLbl.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        noOfOccurancesLbl.setText("No of occurances:");

        noOfAccidentsLbl.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        noOfAccidentsLbl.setText("Number of Accident Cases:");

        totalCauseOccuranceLbl.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        noOfCauseWiseAccidentValueLbl.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        noOfOccurancesLbl1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        noOfOccurancesLbl1.setText("Cause for Accident Percentage:");

        causeForAccidentPercentageLbl.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        javax.swing.GroupLayout individualFactorPanelLayout = new javax.swing.GroupLayout(individualFactorPanel);
        individualFactorPanel.setLayout(individualFactorPanelLayout);
        individualFactorPanelLayout.setHorizontalGroup(individualFactorPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, individualFactorPanelLayout
                        .createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(causeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(124, 124, 124))
                .addGroup(individualFactorPanelLayout.createSequentialGroup()
                        .addGroup(individualFactorPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(individualFactorPanelLayout.createSequentialGroup().addGap(112, 112, 112)
                                        .addComponent(weatherTitleLabel3))
                                .addGroup(individualFactorPanelLayout.createSequentialGroup().addGap(54, 54, 54)
                                        .addGroup(individualFactorPanelLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(noOfOccurancesLbl).addComponent(noOfAccidentsLbl)
                                                .addComponent(noOfOccurancesLbl1))
                                        .addGap(18, 18, 18)
                                        .addGroup(individualFactorPanelLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                                        false)
                                                .addComponent(totalCauseOccuranceLbl,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(noOfCauseWiseAccidentValueLbl,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(causeForAccidentPercentageLbl,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, 126,
                                                        Short.MAX_VALUE))))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        individualFactorPanelLayout.setVerticalGroup(individualFactorPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(individualFactorPanelLayout.createSequentialGroup().addContainerGap()
                        .addComponent(weatherTitleLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(causeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(48, 48, 48)
                        .addGroup(individualFactorPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(individualFactorPanelLayout.createSequentialGroup()
                                        .addGroup(individualFactorPanelLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(noOfOccurancesLbl)
                                                .addComponent(totalCauseOccuranceLbl,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 15,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(18, 18, 18).addComponent(noOfAccidentsLbl))
                                .addComponent(noOfCauseWiseAccidentValueLbl, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        15, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(individualFactorPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(noOfOccurancesLbl1).addComponent(causeForAccidentPercentageLbl,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 15,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        totalAccidentsPanel.setBackground(new java.awt.Color(255, 255, 255));
        totalAccidentsPanel
                .setBorder(new javax.swing.border.LineBorder(new java.awt.Color(240, 240, 240), 1, true));

        selectOrganizationLbl.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        selectOrganizationLbl.setText("Total Driving Instances:");

        weatherTitleLabel.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        weatherTitleLabel.setText("Overall Scenario:");

        selectOrganizationLbl1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        selectOrganizationLbl1.setText("Number of Accident Cases:");

        accidentPercentageLbl.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        accidentPercentageLbl.setText("Accident Percentage:");

        totalDrivingInstancesValueLbl.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        noOfAccidentValueLbl.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        accidentPercentageValueLbl.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        javax.swing.GroupLayout totalAccidentsPanelLayout = new javax.swing.GroupLayout(totalAccidentsPanel);
        totalAccidentsPanel.setLayout(totalAccidentsPanelLayout);
        totalAccidentsPanelLayout.setHorizontalGroup(totalAccidentsPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(totalAccidentsPanelLayout.createSequentialGroup().addGap(58, 58, 58)
                        .addGroup(totalAccidentsPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(totalAccidentsPanelLayout.createSequentialGroup().addGap(18, 18, 18)
                                        .addComponent(selectOrganizationLbl).addGap(18, 18, 18)
                                        .addComponent(totalDrivingInstancesValueLbl,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                        totalAccidentsPanelLayout.createSequentialGroup()
                                                .addGap(0, 88, Short.MAX_VALUE).addComponent(weatherTitleLabel)
                                                .addGap(151, 151, 151))
                                .addGroup(totalAccidentsPanelLayout.createSequentialGroup()
                                        .addGroup(totalAccidentsPanelLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(accidentPercentageLbl)
                                                .addComponent(selectOrganizationLbl1))
                                        .addGap(18, 18, 18)
                                        .addGroup(totalAccidentsPanelLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(noOfAccidentValueLbl,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 74,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(accidentPercentageValueLbl,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 93,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))))));
        totalAccidentsPanelLayout.setVerticalGroup(totalAccidentsPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(totalAccidentsPanelLayout.createSequentialGroup().addContainerGap()
                        .addGroup(totalAccidentsPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(totalAccidentsPanelLayout.createSequentialGroup()
                                        .addGroup(totalAccidentsPanelLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addGroup(totalAccidentsPanelLayout.createSequentialGroup()
                                                        .addComponent(weatherTitleLabel).addGap(18, 18, 18)
                                                        .addComponent(selectOrganizationLbl))
                                                .addComponent(totalDrivingInstancesValueLbl,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 15,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(18, 18, 18).addComponent(selectOrganizationLbl1))
                                .addComponent(noOfAccidentValueLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 15,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(totalAccidentsPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(accidentPercentageLbl).addComponent(accidentPercentageValueLbl,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 15,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(33, Short.MAX_VALUE)));

        accidentStatisticsPanel.setBackground(new java.awt.Color(255, 255, 255));
        accidentStatisticsPanel
                .setBorder(new javax.swing.border.LineBorder(new java.awt.Color(240, 240, 240), 1, true));

        weatherTitleLabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        weatherTitleLabel2.setText("Accident cause distribution:");

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

        javax.swing.GroupLayout chartPanelLayout = new javax.swing.GroupLayout(chartPanel);
        chartPanel.setLayout(chartPanelLayout);
        chartPanelLayout.setHorizontalGroup(chartPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 398, Short.MAX_VALUE));
        chartPanelLayout.setVerticalGroup(chartPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 271, Short.MAX_VALUE));

        javax.swing.GroupLayout accidentStatisticsPanelLayout = new javax.swing.GroupLayout(
                accidentStatisticsPanel);
        accidentStatisticsPanel.setLayout(accidentStatisticsPanelLayout);
        accidentStatisticsPanelLayout.setHorizontalGroup(
                accidentStatisticsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(accidentStatisticsPanelLayout.createSequentialGroup().addGap(112, 112, 112)
                                .addComponent(weatherTitleLabel2).addContainerGap(115, Short.MAX_VALUE))
                        .addComponent(chartPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
        accidentStatisticsPanelLayout.setVerticalGroup(
                accidentStatisticsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(accidentStatisticsPanelLayout.createSequentialGroup().addContainerGap()
                                .addComponent(weatherTitleLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(chartPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(mainPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup().addContainerGap()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(accidentStatisticsPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(totalAccidentsPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(mainPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(mostFatalPairPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(individualFactorPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap()));
        mainPanelLayout
                .setVerticalGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(mainPanelLayout.createSequentialGroup().addContainerGap()
                                .addGroup(mainPanelLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(totalAccidentsPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(mostFatalPairPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(mainPanelLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(accidentStatisticsPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(individualFactorPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addContainerGap()));

        horizontalSpiltPane.setRightComponent(mainPanel);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(horizontalSpiltPane));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(horizontalSpiltPane, javax.swing.GroupLayout.DEFAULT_SIZE, 600, Short.MAX_VALUE));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void logoutBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logoutBtnActionPerformed
        // TODO add your handling code here:
        dB4OUtil.storeSystem(system);
        this.setVisible(false);
        this.dispose();
        isNetworkAdminAvailable = 0;
    }//GEN-LAST:event_logoutBtnActionPerformed

    private void generateReportsBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generateReportsBtnActionPerformed
        // TODO add your handling code here:
        //isNetworkAdminAvailable=1;
        calculateOverallScenario();
        getFatalPair();
        getAccidentCauseDistribution();
        getCauseWiseStatistics();
    }//GEN-LAST:event_generateReportsBtnActionPerformed

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

    public void calculateOverallScenario() {
        int accidentCount = 0;
        int totalCount = 0;
        float accidentPercentage;

        totalCount = driveDirectory.getDriveList().size();
        for (Drive drive : driveDirectory.getDriveList()) {
            if (drive.isIsAccident()) {
                accidentCount++;
            }
        }
        accidentPercentage = (float) accidentCount * 100 / totalCount;

        totalDrivingInstancesValueLbl.setText(String.valueOf(totalCount));
        noOfAccidentValueLbl.setText(String.valueOf(accidentCount));
        accidentPercentageValueLbl.setText(String.valueOf(accidentPercentage));
    }

    public void getFatalPair() {
        HashMap sortedMap = sortHashMapByValuesD(driveDirectory.getPairHashMap());
        List keyList = new ArrayList(sortedMap.keySet());
        mostFatalPairLabel.setText(String.valueOf(keyList.get(0)));
        noOfAccidentValueLbl1.setText(String.valueOf(sortedMap.get(keyList.get(0))));
    }

    public HashMap sortHashMapByValuesD(HashMap passedMap) {

        List mapKeys = new ArrayList(passedMap.keySet());
        List mapValues = new ArrayList(passedMap.values());
        Collections.sort(mapValues);
        Collections.sort(mapKeys);

        HashMap sortedMap = new HashMap();

        Iterator valueIt = mapValues.iterator();
        while (valueIt.hasNext()) {
            Object val = valueIt.next();
            Iterator keyIt = mapKeys.iterator();

            while (keyIt.hasNext()) {
                Object key = keyIt.next();
                String comp1 = passedMap.get(key).toString();
                String comp2 = val.toString();

                if (comp1.equals(comp2)) {
                    mapKeys.remove(key);
                    sortedMap.put((String) key, (Integer) val);
                    break;
                }

            }

        }
        return sortedMap;
    }

    public void getAccidentCauseDistribution() {
        HashMap<String, Integer> hm = new HashMap<>();
        hm.put("Speed", 0);
        hm.put("TyreP", 0);
        hm.put("Health", 0);
        hm.put("Weather", 0);

        for (Drive drive : driveDirectory.getDriveList()) {

            if (drive.isIsAccident()) {
                if (drive.getAccount().getPerson().getVehicleSensorData().isIsOverSpeeding() == true) {
                    hm.put("Speed", hm.get("Speed") + 1);
                }
                if (drive.getAccount().getPerson().getVehicleSensorData().isIsAbnormalTyrePressure() == true) {
                    hm.put("TyreP", hm.get("TyreP") + 1);
                }
                if (!drive.getAccount().getPerson().getVitalSign().isHealthNormal()) {
                    hm.put("Health", hm.get("Health") + 1);
                }
                if (drive.isNormalWeather() == false) {
                    hm.put("Weather", hm.get("Weather") + 1);
                }
            }
        }

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        int i = 1;
        for (String s : hm.keySet()) {

            dataset.setValue(hm.get(s), "Occurances", s);
        }

        /*for(VitalSign vs:person.getPatientPerson().getVitalSignHistoryPatient().getVitalSignArrayList())
        {
            
        dataset.setValue(vs.getRespiratoryRate(), "Rate Value", "Rate"+i);
        i++;
        }*/

        JFreeChart chart = ChartFactory.createBarChart("Occurance Chart", "Cause", "Number", dataset,
                PlotOrientation.VERTICAL, false, true, false);

        // saving the image as a JPEG file.
        //int width = 398; /* Width of the image */
        //int height = 271; /* Height of the image */ 

        /*File XYChart = new File( "\\src\\images\\chart.jpeg" ); 
        try 
        {
        ChartUtilities.saveChartAsJPEG( XYChart, chart, width, height);
        } catch (IOException e) 
        {
                    // Skip creating the JPEG
        }*/

        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.gray);

        ChartPanel chartPanelGraph = new ChartPanel(chart);
        chartPanel.setLayout(new BorderLayout());
        chartPanel.add(chartPanelGraph, BorderLayout.CENTER);
        /*ChartFrame frame = new ChartFrame("Accident Report",chart);
        frame.setVisible(true);
        frame.setSize(500,450);*/
    }

    public synchronized void getCauseWiseStatistics() {
        int speed = 0, speedAccident = 0;
        int tyre = 0, tyreAccident = 0;
        int health = 0, healthAccident = 0;
        int weather = 0, weatherAccident = 0;

        for (Drive drive : driveDirectory.getDriveList()) {
            if (drive.getAccount().getPerson().getVehicleSensorData().isIsOverSpeeding()) {
                speed++;
                if (drive.isIsAccident()) {
                    speedAccident++;
                }
            }
            if (drive.getAccount().getPerson().getVehicleSensorData().isIsAbnormalTyrePressure()) {
                tyre++;
                if (drive.isIsAccident()) {
                    tyreAccident++;
                }
            }
            if (!drive.getAccount().getPerson().getVitalSign().isHealthNormal()) {
                health++;
                if (drive.isIsAccident()) {
                    healthAccident++;
                }
            }
            if (!drive.isNormalWeather()) {
                weather++;
                if (drive.isIsAccident()) {
                    weatherAccident++;
                }
            }
        }

        String cause = String.valueOf(causeComboBox.getSelectedItem());
        if (cause.equals("Overspeeding")) {
            if (speed != 0) {
                totalCauseOccuranceLbl.setText(String.valueOf(speed));
                noOfCauseWiseAccidentValueLbl.setText(String.valueOf(speedAccident));
                causeForAccidentPercentageLbl.setText(String.valueOf((float) speedAccident * 100 / speed));
            } else {
                totalCauseOccuranceLbl.setText("No occurances");
                noOfCauseWiseAccidentValueLbl.setText("");
                causeForAccidentPercentageLbl.setText("");
            }
        }
        if (cause.equals("Abnormal Tyre Pressure")) {
            if (tyre != 0) {
                totalCauseOccuranceLbl.setText(String.valueOf(tyre));
                noOfCauseWiseAccidentValueLbl.setText(String.valueOf(tyreAccident));
                causeForAccidentPercentageLbl.setText(String.valueOf((float) tyreAccident * 100 / tyre));
            } else {
                totalCauseOccuranceLbl.setText("No occurances");
                noOfCauseWiseAccidentValueLbl.setText("");
                causeForAccidentPercentageLbl.setText("");
            }
        }
        if (cause.equals("Abnormal Health")) {
            if (health != 0) {
                totalCauseOccuranceLbl.setText(String.valueOf(health));
                noOfCauseWiseAccidentValueLbl.setText(String.valueOf(healthAccident));
                causeForAccidentPercentageLbl.setText(String.valueOf((float) healthAccident * 100 / health));
            } else {
                totalCauseOccuranceLbl.setText("No occurances");
                noOfCauseWiseAccidentValueLbl.setText("");
                causeForAccidentPercentageLbl.setText("");
            }
        }
        if (cause.equals("Harsh Weather")) {
            if (weather != 0) {
                totalCauseOccuranceLbl.setText(String.valueOf(weather));
                noOfCauseWiseAccidentValueLbl.setText(String.valueOf(weatherAccident));
                causeForAccidentPercentageLbl.setText(String.valueOf((float) weatherAccident * 100 / weather));
            } else {
                totalCauseOccuranceLbl.setText("No occurances");
                noOfCauseWiseAccidentValueLbl.setText("");
                causeForAccidentPercentageLbl.setText("");
            }
        }

    }

    /**
     * @param args the command line arguments
     */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel accidentPercentageLbl;
    private javax.swing.JLabel accidentPercentageValueLbl;
    private javax.swing.JPanel accidentStatisticsPanel;
    private javax.swing.JComboBox causeComboBox;
    private javax.swing.JLabel causeForAccidentPercentageLbl;
    private javax.swing.JPanel chartPanel;
    private javax.swing.JButton generateReportsBtn;
    private javax.swing.JLabel headerLabel;
    private javax.swing.JPanel headerPanel;
    private javax.swing.JSplitPane horizontalSpiltPane;
    private javax.swing.JPanel individualFactorPanel;
    private javax.swing.JButton logoutBtn;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JLabel mostFatalPairLabel;
    private javax.swing.JPanel mostFatalPairPanel;
    private javax.swing.JLabel noOfAccidentValueLbl;
    private javax.swing.JLabel noOfAccidentValueLbl1;
    private javax.swing.JLabel noOfAccidentsLbl;
    private javax.swing.JLabel noOfCauseWiseAccidentValueLbl;
    private javax.swing.JLabel noOfOccurancesLbl;
    private javax.swing.JLabel noOfOccurancesLbl1;
    private javax.swing.JLabel selectOrganizationLbl;
    private javax.swing.JLabel selectOrganizationLbl1;
    private javax.swing.JLabel selectOrganizationLbl3;
    private javax.swing.JPanel totalAccidentsPanel;
    private javax.swing.JLabel totalCauseOccuranceLbl;
    private javax.swing.JLabel totalDrivingInstancesValueLbl;
    private javax.swing.JLabel weatherTitleLabel;
    private javax.swing.JLabel weatherTitleLabel1;
    private javax.swing.JLabel weatherTitleLabel2;
    private javax.swing.JLabel weatherTitleLabel3;
    private javax.swing.JLabel welcomeLabel;
    private javax.swing.JLabel welcomeRoleLabel;
    // End of variables declaration//GEN-END:variables
}