com.ga.forms.DailyLogUI.java Source code

Java tutorial

Introduction

Here is the source code for com.ga.forms.DailyLogUI.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 com.ga.forms;

import com.ga.logic.DailyLogAnalysis;
import com.ga.logic.DailyLogCSVExport;
import com.ga.logic.DailyLogRecord;
import org.json.simple.JSONObject;

import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author gurpreet
 */
public class DailyLogUI extends javax.swing.JFrame {

    private HashMap args;
    private ArrayList monthList;
    private ArrayList yearList;
    private Date dateToday;
    private SimpleDateFormat dateFormatter;
    private String currMonth;
    private String currYear;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addButton;
    private javax.swing.JPanel analysisPanel;
    private javax.swing.JPanel dailyLogPanel;
    private javax.swing.JTable dailyLogTable;
    private javax.swing.JLabel differenceLbl;
    private javax.swing.JLabel durationDifferenceLbl;
    private javax.swing.JLabel durationLbl;
    private javax.swing.JButton exitButton;
    private javax.swing.JButton exportButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel mainTitleLbl;
    private javax.swing.JComboBox monthCombo;
    private javax.swing.JLabel monthlyDurationLbl;
    private javax.swing.JLabel monthlyRequiredDurationLbl;
    private javax.swing.JLabel netDurationLbl;
    private javax.swing.JComboBox yearCombo;

    /**
     * Creates new form DailyLogViewUI
     */
    public DailyLogUI() {
        initComponents();
        initComponentsValues();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(DailyLogUI.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(DailyLogUI.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(DailyLogUI.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(DailyLogUI.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new DailyLogUI().setVisible(true);
            }
        });
    }

    private ArrayList getMonthList() {
        ArrayList<String> newMonthList = new ArrayList<String>();
        newMonthList.add("Jan");
        newMonthList.add("Feb");
        newMonthList.add("Mar");
        newMonthList.add("Apr");
        newMonthList.add("May");
        newMonthList.add("Jun");
        newMonthList.add("Jul");
        newMonthList.add("Aug");
        newMonthList.add("Sep");
        newMonthList.add("Oct");
        newMonthList.add("Nov");
        newMonthList.add("Dec");
        return newMonthList;
    }

    private ArrayList getYearList() {
        ArrayList<String> newYearList = new ArrayList<String>();
        for (int years = 2000; years < 2050; years++) {
            newYearList.add(Integer.toString(years));
        }
        return newYearList;
    }

    private ArrayList updateDailyLogTable(ArrayList logs, String currMonth, String currTear) {
        String[] columnNames = new String[] { "Date", "Day", "In", "Out", "Break", "Duration", "Under-Time",
                "Over-Time" };
        Object[][] data = null;
        ArrayList duration = null;
        if (!logs.isEmpty()) {
            duration = new ArrayList();
            data = new Object[logs.size()][columnNames.length];
            for (int logIndex = 0; logIndex < logs.size(); logIndex++) {
                JSONObject logJSONOBject = new JSONObject((Map) logs.get(logIndex));

                data[logIndex][0] = logJSONOBject.get("date");
                data[logIndex][1] = logJSONOBject.get("day");
                data[logIndex][2] = logJSONOBject.get("check-in");
                data[logIndex][3] = logJSONOBject.get("check-out");
                data[logIndex][4] = logJSONOBject.get("break");
                data[logIndex][5] = logJSONOBject.get("duration");
                data[logIndex][6] = logJSONOBject.get("under-time");
                data[logIndex][7] = logJSONOBject.get("over-time");
                duration.add(logJSONOBject.get("duration"));
            }
        }
        DefaultTableModel dailyLogTableModel = new DefaultTableModel(data, columnNames);
        dailyLogTable.setModel(dailyLogTableModel);
        return duration;
    }

    private void updateAnalysis(ArrayList duration) {

        DailyLogAnalysis analysis = new DailyLogAnalysis();
        if (duration == null) {
            duration = new ArrayList();
        }
        analysis.analyse(duration);
        durationLbl.setText(analysis.getTotalDuration());
        monthlyDurationLbl.setText(analysis.getMonthlyDuration());
        int netDurationHours = Integer.parseInt(analysis.getTotalDuration().toString().split(":")[0]);
        int monthlyDurationHours = Integer.parseInt(analysis.getMonthlyDuration().toString().split(":")[0]);
        if (netDurationHours < monthlyDurationHours) {
            differenceLbl.setForeground(Color.red);
        } else {
            differenceLbl.setForeground(Color.green);
        }
        differenceLbl.setText(analysis.getDifference());
    }

    private void initComponentsValues() {
        monthList = new ArrayList();
        yearList = new ArrayList();
        monthList = getMonthList();
        yearList = getYearList();
        dateToday = new Date();
        dateFormatter = new SimpleDateFormat("MMM");
        currMonth = dateFormatter.format(dateToday);
        dateFormatter = new SimpleDateFormat("yyyy");
        currYear = dateFormatter.format(dateToday);
        monthCombo.setModel(new DefaultComboBoxModel(monthList.toArray()));
        monthCombo.setSelectedIndex(monthList.indexOf(currMonth));
        yearCombo.setModel(new DefaultComboBoxModel(yearList.toArray()));
        yearCombo.setSelectedIndex(yearList.indexOf(currYear));
        args = new HashMap();
        HashMap regex = new HashMap();
        regex.put("$regex", monthCombo.getSelectedItem().toString() + "-" + yearCombo.getSelectedItem().toString());
        args.put("date", regex);
        DailyLogRecord record = new DailyLogRecord();
        ArrayList logs = record.retrieveRecord(args);
        ArrayList duration = updateDailyLogTable(logs, this.currMonth, this.currYear);
        updateAnalysis(duration);
    }

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

        jPanel1 = new javax.swing.JPanel();
        mainTitleLbl = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        exitButton = new javax.swing.JButton();
        exportButton = new javax.swing.JButton();
        dailyLogPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        dailyLogTable = new javax.swing.JTable();
        addButton = new javax.swing.JButton();
        analysisPanel = new javax.swing.JPanel();
        netDurationLbl = new javax.swing.JLabel();
        durationLbl = new javax.swing.JLabel();
        monthlyRequiredDurationLbl = new javax.swing.JLabel();
        monthlyDurationLbl = new javax.swing.JLabel();
        durationDifferenceLbl = new javax.swing.JLabel();
        differenceLbl = new javax.swing.JLabel();
        monthCombo = new javax.swing.JComboBox();
        yearCombo = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setMaximumSize(new java.awt.Dimension(395, 389));
        jPanel1.setMinimumSize(new java.awt.Dimension(395, 389));
        jPanel1.setPreferredSize(new java.awt.Dimension(464, 474));

        mainTitleLbl.setFont(new java.awt.Font("Arial", 0, 36)); // NOI18N
        mainTitleLbl.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        mainTitleLbl.setText("Daily Log Manager");
        mainTitleLbl.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        exitButton.setText("Exit");
        exitButton.setMaximumSize(new java.awt.Dimension(72, 29));
        exitButton.setMinimumSize(new java.awt.Dimension(72, 29));
        exitButton.setPreferredSize(new java.awt.Dimension(72, 29));
        exitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitButtonActionPerformed(evt);
            }
        });

        exportButton.setText("Export");
        exportButton.setMaximumSize(new java.awt.Dimension(92, 29));
        exportButton.setMinimumSize(new java.awt.Dimension(92, 29));
        exportButton.setPreferredSize(new java.awt.Dimension(92, 29));
        exportButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exportButtonActionPerformed(evt);
            }
        });

        dailyLogPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Daily Logs"));
        dailyLogPanel.setFont(new java.awt.Font("Arial", 0, 15)); // NOI18N
        dailyLogPanel.setName("Daily Log Entry"); // NOI18N
        dailyLogPanel.setPreferredSize(new java.awt.Dimension(240, 190));

        jScrollPane1.setFont(new java.awt.Font("Arial", 0, 10)); // NOI18N

        dailyLogTable
                .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[] { "Title 1", "Title 2", "Title 3", "Title 4" }));
        jScrollPane1.setViewportView(dailyLogTable);

        javax.swing.GroupLayout dailyLogPanelLayout = new javax.swing.GroupLayout(dailyLogPanel);
        dailyLogPanel.setLayout(dailyLogPanelLayout);
        dailyLogPanelLayout.setHorizontalGroup(
                dailyLogPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 770, Short.MAX_VALUE));
        dailyLogPanelLayout
                .setVerticalGroup(dailyLogPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE));

        addButton.setText("Add");
        addButton.setMaximumSize(new java.awt.Dimension(72, 29));
        addButton.setMinimumSize(new java.awt.Dimension(72, 29));
        addButton.setPreferredSize(new java.awt.Dimension(72, 29));
        addButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addButtonActionPerformed(evt);
            }
        });

        analysisPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Analysis"));

        netDurationLbl.setFont(new java.awt.Font("Arial", 1, 13)); // NOI18N
        netDurationLbl.setText("NET DURATION:");

        durationLbl.setFont(new java.awt.Font("Arial", 1, 13)); // NOI18N

        monthlyRequiredDurationLbl.setFont(new java.awt.Font("Arial", 1, 13)); // NOI18N
        monthlyRequiredDurationLbl.setText("MONTHLY REQUIRED DURATION:");

        monthlyDurationLbl.setFont(new java.awt.Font("Arial", 1, 13)); // NOI18N

        durationDifferenceLbl.setFont(new java.awt.Font("Arial", 1, 13)); // NOI18N
        durationDifferenceLbl.setText("DIFFERENCE:");

        differenceLbl.setFont(new java.awt.Font("Arial", 1, 13)); // NOI18N

        javax.swing.GroupLayout analysisPanelLayout = new javax.swing.GroupLayout(analysisPanel);
        analysisPanel.setLayout(analysisPanelLayout);
        analysisPanelLayout.setHorizontalGroup(analysisPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(analysisPanelLayout.createSequentialGroup().addContainerGap().addGroup(analysisPanelLayout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(analysisPanelLayout.createSequentialGroup().addComponent(netDurationLbl)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(durationLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 71,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(
                                analysisPanelLayout.createSequentialGroup().addComponent(monthlyRequiredDurationLbl)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(monthlyDurationLbl, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                71, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(analysisPanelLayout.createSequentialGroup().addComponent(durationDifferenceLbl)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(differenceLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 71,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(18, Short.MAX_VALUE)));
        analysisPanelLayout
                .setVerticalGroup(analysisPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(analysisPanelLayout.createSequentialGroup().addContainerGap()
                                .addGroup(analysisPanelLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(netDurationLbl, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(durationLbl, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(analysisPanelLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(monthlyDurationLbl, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(monthlyRequiredDurationLbl))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(analysisPanelLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(differenceLbl, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(durationDifferenceLbl))
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        netDurationLbl.getAccessibleContext().setAccessibleName("netDurationLbl");
        durationLbl.getAccessibleContext().setAccessibleName("durationLbl");
        monthlyRequiredDurationLbl.getAccessibleContext().setAccessibleName("monthlyRequiredDurationLbl");
        monthlyDurationLbl.getAccessibleContext().setAccessibleName("monthlyDurationLbl");
        durationDifferenceLbl.getAccessibleContext().setAccessibleName("durationDifferenceLbl");
        differenceLbl.getAccessibleContext().setAccessibleName("differenceLbl");

        monthCombo.setModel(
                new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        monthCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                monthComboActionPerformed(evt);
            }
        });

        yearCombo.setModel(
                new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        yearCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                yearComboActionPerformed(evt);
            }
        });

        jLabel1.setText("Month:");

        jLabel2.setText("Year:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jSeparator1)
                .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(addButton, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(exportButton, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(exitButton, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel1Layout.createSequentialGroup().addGap(6, 6, 6)
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addComponent(analysisPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(jLabel1)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(monthCombo, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(24, 24, 24).addComponent(jLabel2)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(yearCombo, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(mainTitleLbl, javax.swing.GroupLayout.Alignment.TRAILING,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(dailyLogPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 788,
                                                Short.MAX_VALUE))))
                        .addContainerGap()));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
                        .addComponent(mainTitleLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 70,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(dailyLogPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 206,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(analysisPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(monthCombo, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(yearCombo, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel1).addComponent(jLabel2)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 6,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(exitButton, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(exportButton, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(addButton, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap()));

        exportButton.getAccessibleContext().setAccessibleName("exportButton");
        addButton.getAccessibleContext().setAccessibleName("addButton");
        analysisPanel.getAccessibleContext().setAccessibleName("analysisPanel");
        jLabel1.getAccessibleContext().setAccessibleName("monthLbl");
        jLabel2.getAccessibleContext().setAccessibleName("yearLbl");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 800, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 800, Short.MAX_VALUE)));
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGap(0, 469, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 469,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(0, 0, Short.MAX_VALUE))));

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

    private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitButtonActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitButtonActionPerformed

    private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed
        System.out.print(
                "REGEX: " + monthCombo.getSelectedItem().toString() + "-" + yearCombo.getSelectedItem().toString());
        JFrame fileChooserFrame = new JFrame();
        JFileChooser saveFileDialog = new JFileChooser();
        FileNameExtensionFilter fileExtentionFilter = new FileNameExtensionFilter("Comma Seperated Values (*.csv)",
                "csv");
        saveFileDialog.setFileFilter(fileExtentionFilter);
        int saveFileDialogStatus = saveFileDialog.showSaveDialog(fileChooserFrame);
        if (saveFileDialogStatus == JFileChooser.APPROVE_OPTION) {
            String fileSaveDetails = saveFileDialog.getSelectedFile().toString();
            args = new HashMap();
            HashMap regex = new HashMap();
            regex.put("$regex",
                    monthCombo.getSelectedItem().toString() + "-" + yearCombo.getSelectedItem().toString());
            args.put("date", regex);
            DailyLogRecord record = new DailyLogRecord();
            ArrayList logs = record.retrieveRecord(args);
            String[] columnNames = new String[] { "Date", "Day", "In", "Out", "Break", "Duration", "Under-Time",
                    "Over-Time" };
            ArrayList data = null;
            if (!logs.isEmpty()) {
                data = new ArrayList();
                data.add(String.join(",", columnNames));
                for (int logIndex = 0; logIndex < logs.size(); logIndex++) {
                    JSONObject logJSONOBject = new JSONObject((Map) logs.get(logIndex));
                    String csvRecord = logJSONOBject.get("date").toString() + ","
                            + logJSONOBject.get("day").toString() + "," + logJSONOBject.get("check-in").toString()
                            + "," + logJSONOBject.get("check-out").toString() + ","
                            + logJSONOBject.get("break").toString() + "," + logJSONOBject.get("duration").toString()
                            + "," + logJSONOBject.get("under-time").toString() + ","
                            + logJSONOBject.get("over-time").toString();
                    data.add(csvRecord);
                }

            }
            DailyLogCSVExport csvExporter = new DailyLogCSVExport();
            csvExporter.save(data, fileSaveDetails);
        }
    }//GEN-LAST:event_exportButtonActionPerformed

    private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
        this.dispose();
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                DailyLogAddUI manager = new DailyLogAddUI();
                manager.setVisible(true);
            }
        });
    }//GEN-LAST:event_addButtonActionPerformed

    private void monthComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_monthComboActionPerformed
        args = new HashMap();
        HashMap regex = new HashMap();
        regex.put("$regex", monthCombo.getSelectedItem().toString() + "-" + yearCombo.getSelectedItem().toString());
        args.put("date", regex);
        DailyLogRecord record = new DailyLogRecord();
        ArrayList logs = record.retrieveRecord(args);
        ArrayList duration = updateDailyLogTable(logs, this.currMonth, this.currYear);
        updateAnalysis(duration);
    }//GEN-LAST:event_monthComboActionPerformed

    private void yearComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yearComboActionPerformed
        args = new HashMap();
        HashMap regex = new HashMap();
        regex.put("$regex", monthCombo.getSelectedItem().toString() + "-" + yearCombo.getSelectedItem().toString());
        args.put("date", regex);
        DailyLogRecord record = new DailyLogRecord();
        ArrayList logs = record.retrieveRecord(args);
        ArrayList duration = updateDailyLogTable(logs, this.currMonth, this.currYear);
        updateAnalysis(duration);
    }//GEN-LAST:event_yearComboActionPerformed
     // End of variables declaration//GEN-END:variables
}