com.ga.forms.DailyLogAddUI.java Source code

Java tutorial

Introduction

Here is the source code for com.ga.forms.DailyLogAddUI.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.DailyLogDuration;
import com.ga.logic.DailyLogRecord;
import com.mongodb.DBObject;
import com.mongodb.util.JSON;
import org.json.simple.JSONObject;

import javax.swing.*;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.*;

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

    private static boolean checkIn = false;
    private static boolean checkOut = false;
    private static boolean breakDone = false;
    private static JSONObject logRecordJSONObject;
    private static JSONObject logRecordMetaJSONObject;
    private Date dateObj;
    private SimpleDateFormat formatDateToday;
    private ArrayList<String> timeList;
    private String currentTime;
    private HashMap args;
    private String timeOnBreak = "00:00";
    private DBObject doc;
    private String duration;
    private String underTime;
    private String overTime;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel breakLbl;
    private javax.swing.JPanel breakOptionPanel;
    private javax.swing.JLabel checkInLbl;
    private javax.swing.JToggleButton checkInOutButton;
    private javax.swing.JComboBox checkInTimeCombo;
    private javax.swing.JComboBox checkOutTimeCombo;
    private javax.swing.JLabel checkoutLbl;
    private javax.swing.JTextField customBreakTimeTextField;
    private javax.swing.JRadioButton customRdButton;
    private javax.swing.JPanel dailyLogPanel;
    private javax.swing.JLabel dateDisplayLbl;
    private javax.swing.JLabel dateLbl;
    private javax.swing.JLabel dayDisplayLbl;
    private javax.swing.JLabel dayLbl;
    private javax.swing.JButton exitButton;
    private javax.swing.ButtonGroup group;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel mainTitleLbl;
    private javax.swing.JRadioButton noRdButton;
    private javax.swing.JButton viewButton;
    private javax.swing.JRadioButton yesRdButton;

    /**
     * Creates new form Daily
     */
    public DailyLogAddUI() {
        initComponents();
        initComponentValues();
    }

    /**
     * @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(DailyLogAddUI.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(DailyLogAddUI.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(DailyLogAddUI.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(DailyLogAddUI.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        }
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>

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

    private ArrayList getTimeList() {
        ArrayList<String> newTimeList = new ArrayList<String>();
        for (int hours = 0; hours < 24; hours++) {
            for (int mins = 0; mins < 60; mins++) {
                if (hours < 10 && mins < 10) {
                    newTimeList.add("0" + Integer.toString(hours) + ":0" + Integer.toString(mins));
                } else if (hours < 10 && mins >= 10) {
                    newTimeList.add("0" + Integer.toString(hours) + ":" + Integer.toString(mins));
                } else if (hours >= 10 && mins < 10) {
                    newTimeList.add(Integer.toString(hours) + ":0" + Integer.toString(mins));
                } else {
                    newTimeList.add(Integer.toString(hours) + ":" + Integer.toString(mins));
                }
            }
        }
        return newTimeList;
    }

    private void groupRadioButtons() {
        group = new ButtonGroup();
        group.add(yesRdButton);
        group.add(noRdButton);
        group.add(customRdButton);
    }

    private void initComponentValues() {
        args = new HashMap();
        dateObj = new Date();
        formatDateToday = new SimpleDateFormat("dd-MMM-yyyy");
        dateDisplayLbl.setText(formatDateToday.format(dateObj));
        args.put("date", formatDateToday.format(dateObj));
        DailyLogRecord record = new DailyLogRecord();
        ArrayList logRecord = record.retrieveRecord(args);
        formatDateToday = new SimpleDateFormat("EEEE", Locale.ENGLISH);
        dayDisplayLbl.setText(formatDateToday.format(dateObj));
        timeList = new ArrayList<String>();
        timeList = getTimeList();
        if (!logRecord.isEmpty()) {
            args.clear();
            args = new HashMap();
            formatDateToday = new SimpleDateFormat("HH:mm");
            currentTime = formatDateToday.format(dateObj);
            DailyLogAddUI.logRecordJSONObject = new JSONObject((Map) logRecord.get(0));
            DailyLogAddUI.logRecordMetaJSONObject = new JSONObject(
                    (Map) DailyLogAddUI.logRecordJSONObject.get("meta"));
            DailyLogAddUI.checkIn = Boolean
                    .parseBoolean((String) DailyLogAddUI.logRecordMetaJSONObject.get("checked-in"));
            if (DailyLogAddUI.logRecordMetaJSONObject.get("had-break").equals("")
                    || DailyLogAddUI.logRecordMetaJSONObject.get("had-break").equals("false")) {
                DailyLogAddUI.breakDone = false;
            } else {
                DailyLogAddUI.breakDone = Boolean
                        .parseBoolean((String) DailyLogAddUI.logRecordMetaJSONObject.get("had-break"));
            }
            checkInTimeCombo.setModel(new DefaultComboBoxModel(timeList.toArray()));
            checkInTimeCombo.setSelectedIndex(timeList.indexOf(DailyLogAddUI.logRecordJSONObject.get("check-in")));
            checkInTimeCombo.setEnabled(false);
            if (!DailyLogAddUI.breakDone) {
                breakOptionPanel.setEnabled(true);
                yesRdButton.setEnabled(true);
                noRdButton.setEnabled(true);
                customRdButton.setEnabled(true);
                checkInOutButton.setText("Update");

            } else {
                breakOptionPanel.setEnabled(false);
                yesRdButton.setEnabled(false);
                noRdButton.setEnabled(false);
                customRdButton.setEnabled(false);
                this.timeOnBreak = DailyLogAddUI.logRecordJSONObject.get("break").toString();
                checkInOutButton.setPreferredSize(new Dimension(115, 29));
                checkInOutButton.setText("Check Out");

            }
            DailyLogDuration durationAgent = new DailyLogDuration();
            durationAgent.calculateCurrentDuration(DailyLogAddUI.logRecordJSONObject.get("check-in").toString(),
                    this.timeOnBreak, "");
            String currentTimeDuration = durationAgent.getCurrentDuration();
            String[] currentTimeDurationArray = currentTimeDuration.split(":");
            int hours = Integer.parseInt(currentTimeDurationArray[0]);
            if (hours >= 9 && (DailyLogAddUI.logRecordMetaJSONObject.get("checked-out").equals("")
                    || DailyLogAddUI.logRecordMetaJSONObject.get("checked-out").equals("false"))) { // or duration <=9 and duration>=7
                DailyLogAddUI.checkOut = false;
            } else {
                DailyLogAddUI.checkOut = Boolean
                        .parseBoolean((String) DailyLogAddUI.logRecordMetaJSONObject.get("checked-out"));
            }
            if (!DailyLogAddUI.checkOut) {
                checkOutTimeCombo.setModel(new DefaultComboBoxModel(timeList.toArray()));
                checkOutTimeCombo.setSelectedIndex(timeList.indexOf(currentTime));

            } else {
                checkOutTimeCombo.setModel(new DefaultComboBoxModel(timeList.toArray()));
                checkOutTimeCombo
                        .setSelectedIndex(timeList.indexOf(DailyLogAddUI.logRecordJSONObject.get("check-out")));
                checkOutTimeCombo.setEnabled(false);
                checkInOutButton.setEnabled(false);
            }

        } else {
            formatDateToday = new SimpleDateFormat("HH:mm");
            currentTime = formatDateToday.format(dateObj);
            checkInTimeCombo.setModel(new DefaultComboBoxModel(timeList.toArray()));
            checkInTimeCombo.setSelectedIndex(timeList.indexOf(currentTime));
            checkOutTimeCombo.setModel(new DefaultComboBoxModel(timeList.toArray()));
            checkOutTimeCombo.setSelectedIndex(timeList.indexOf("00:00"));
        }
        groupRadioButtons();
    }

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

        group = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        mainTitleLbl = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        exitButton = new javax.swing.JButton();
        viewButton = new javax.swing.JButton();
        dailyLogPanel = new javax.swing.JPanel();
        dateLbl = new javax.swing.JLabel();
        dateDisplayLbl = new javax.swing.JLabel();
        dayLbl = new javax.swing.JLabel();
        dayDisplayLbl = new javax.swing.JLabel();
        checkInLbl = new javax.swing.JLabel();
        checkoutLbl = new javax.swing.JLabel();
        breakLbl = new javax.swing.JLabel();
        checkInTimeCombo = new javax.swing.JComboBox();
        checkOutTimeCombo = new javax.swing.JComboBox();
        checkInOutButton = new javax.swing.JToggleButton();
        breakOptionPanel = new javax.swing.JPanel();
        yesRdButton = new javax.swing.JRadioButton();
        noRdButton = new javax.swing.JRadioButton();
        customRdButton = new javax.swing.JRadioButton();
        customBreakTimeTextField = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Daily Log Manager");
        setBounds(new java.awt.Rectangle(0, 0, 395, 389));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setMinimumSize(new java.awt.Dimension(395, 389));

        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);
            }
        });

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

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

        dateLbl.setFont(new java.awt.Font("Arial", 0, 15)); // NOI18N
        dateLbl.setText("Date");
        dateLbl.setPreferredSize(new java.awt.Dimension(56, 17));

        dateDisplayLbl.setFont(new java.awt.Font("Arial", 0, 15)); // NOI18N
        dateDisplayLbl.setEnabled(false);
        dateDisplayLbl.setMaximumSize(new java.awt.Dimension(144, 17));
        dateDisplayLbl.setMinimumSize(new java.awt.Dimension(144, 17));
        dateDisplayLbl.setPreferredSize(new java.awt.Dimension(144, 17));
        dateDisplayLbl.setRequestFocusEnabled(false);

        dayLbl.setFont(new java.awt.Font("Arial", 0, 15)); // NOI18N
        dayLbl.setText("Day");
        dayLbl.setPreferredSize(new java.awt.Dimension(56, 17));

        dayDisplayLbl.setFont(new java.awt.Font("Arial", 0, 15)); // NOI18N
        dayDisplayLbl.setEnabled(false);
        dayDisplayLbl.setMaximumSize(new java.awt.Dimension(144, 17));
        dayDisplayLbl.setMinimumSize(new java.awt.Dimension(144, 17));
        dayDisplayLbl.setPreferredSize(new java.awt.Dimension(144, 17));
        dayDisplayLbl.setRequestFocusEnabled(false);

        checkInLbl.setFont(new java.awt.Font("Arial", 0, 15)); // NOI18N
        checkInLbl.setText("In");
        checkInLbl.setPreferredSize(new java.awt.Dimension(56, 17));

        checkoutLbl.setFont(new java.awt.Font("Arial", 0, 15)); // NOI18N
        checkoutLbl.setText("Out");
        checkoutLbl.setPreferredSize(new java.awt.Dimension(56, 17));

        breakLbl.setFont(new java.awt.Font("Arial", 0, 15)); // NOI18N
        breakLbl.setText("Break");
        breakLbl.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        breakLbl.setPreferredSize(new java.awt.Dimension(56, 17));

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

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

        checkInOutButton.setFont(new java.awt.Font("Arial", 0, 15)); // NOI18N
        checkInOutButton.setText("Check In");
        checkInOutButton.setMaximumSize(new java.awt.Dimension(102, 29));
        checkInOutButton.setMinimumSize(new java.awt.Dimension(102, 29));
        checkInOutButton.setPreferredSize(new java.awt.Dimension(102, 29));
        checkInOutButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkInOutButtonActionPerformed(evt);
            }
        });

        breakOptionPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Options"));
        breakOptionPanel.setPreferredSize(new java.awt.Dimension(255, 98));

        yesRdButton.setFont(new java.awt.Font("Arial", 0, 15)); // NOI18N
        yesRdButton.setText("Yes");
        yesRdButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                yesRdButtonMouseClicked(evt);
            }
        });

        noRdButton.setFont(new java.awt.Font("Arial", 0, 15)); // NOI18N
        noRdButton.setSelected(true);
        noRdButton.setText("No");
        noRdButton.setPreferredSize(new java.awt.Dimension(51, 24));
        noRdButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                noRdButtonMouseClicked(evt);
            }
        });

        customRdButton.setFont(new java.awt.Font("Arial", 0, 15)); // NOI18N
        customRdButton.setText("Custom");
        customRdButton.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                customRdButtonItemStateChanged(evt);
            }
        });
        customRdButton.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                customRdButtonStateChanged(evt);
            }
        });
        customRdButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                customRdButtonMouseClicked(evt);
            }
        });

        customBreakTimeTextField.setText("00:30");
        customBreakTimeTextField.setEnabled(false);

        javax.swing.GroupLayout breakOptionPanelLayout = new javax.swing.GroupLayout(breakOptionPanel);
        breakOptionPanel.setLayout(breakOptionPanelLayout);
        breakOptionPanelLayout.setHorizontalGroup(breakOptionPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(breakOptionPanelLayout.createSequentialGroup().addGap(5, 5, 5)
                        .addGroup(breakOptionPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(customBreakTimeTextField, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(breakOptionPanelLayout.createSequentialGroup().addComponent(yesRdButton)
                                        .addGap(5, 5, 5)
                                        .addComponent(noRdButton, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(5, 5, 5).addComponent(customRdButton)
                                        .addGap(0, 0, Short.MAX_VALUE)))
                        .addContainerGap()));
        breakOptionPanelLayout.setVerticalGroup(breakOptionPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(breakOptionPanelLayout.createSequentialGroup().addGap(5, 5, 5)
                        .addGroup(breakOptionPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(yesRdButton)
                                .addComponent(noRdButton, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(customRdButton))
                        .addGap(5, 5, 5).addComponent(customBreakTimeTextField,
                                javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE)));

        yesRdButton.getAccessibleContext().setAccessibleName("breakRdButton");
        noRdButton.getAccessibleContext().setAccessibleName("breakRdButton");
        customRdButton.getAccessibleContext().setAccessibleName("breakRdButton");
        customBreakTimeTextField.getAccessibleContext().setAccessibleName("customBreakTimeTextField");

        javax.swing.GroupLayout dailyLogPanelLayout = new javax.swing.GroupLayout(dailyLogPanel);
        dailyLogPanel.setLayout(dailyLogPanelLayout);
        dailyLogPanelLayout.setHorizontalGroup(dailyLogPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(dailyLogPanelLayout.createSequentialGroup().addContainerGap().addGroup(dailyLogPanelLayout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                dailyLogPanelLayout.createSequentialGroup().addGroup(dailyLogPanelLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, dailyLogPanelLayout
                                                .createSequentialGroup()
                                                .addComponent(dayLbl, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(dayDisplayLbl, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        304, Short.MAX_VALUE))
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, dailyLogPanelLayout
                                                .createSequentialGroup()
                                                .addComponent(dateLbl, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(
                                                        dateDisplayLbl, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                        .addGap(44, 44, 44))
                        .addGroup(dailyLogPanelLayout.createSequentialGroup().addGroup(dailyLogPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(dailyLogPanelLayout.createSequentialGroup()
                                        .addComponent(checkInLbl, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(checkInTimeCombo, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(dailyLogPanelLayout.createSequentialGroup().addGroup(dailyLogPanelLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(checkoutLbl, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(breakLbl, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(dailyLogPanelLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(checkOutTimeCombo,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(breakOptionPanel,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 220,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addContainerGap(152, Short.MAX_VALUE))))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, dailyLogPanelLayout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(checkInOutButton, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(21, 21, 21)));
        dailyLogPanelLayout.setVerticalGroup(dailyLogPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(dailyLogPanelLayout.createSequentialGroup().addContainerGap()
                        .addGroup(dailyLogPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(dateLbl, javax.swing.GroupLayout.DEFAULT_SIZE, 18, Short.MAX_VALUE)
                                .addComponent(dateDisplayLbl, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(dailyLogPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(dayLbl, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(dayDisplayLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 18,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(dailyLogPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(checkInTimeCombo).addComponent(checkInLbl,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(dailyLogPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(checkOutTimeCombo).addComponent(checkoutLbl,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(dailyLogPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(dailyLogPanelLayout.createSequentialGroup()
                                        .addComponent(breakLbl, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGap(47, 47, 47))
                                .addGroup(dailyLogPanelLayout.createSequentialGroup()
                                        .addComponent(breakOptionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 84,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, 40,
                                                Short.MAX_VALUE)
                                        .addComponent(checkInOutButton, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addContainerGap()))));

        dayLbl.getAccessibleContext().setAccessibleName("dayLbl");
        dayDisplayLbl.getAccessibleContext().setAccessibleName("dayDisplayLbl");
        checkInTimeCombo.getAccessibleContext().setAccessibleName("checkInTimeCombo");
        checkOutTimeCombo.getAccessibleContext().setAccessibleName("checkOutTimeCombo");
        checkInOutButton.getAccessibleContext().setAccessibleName("checkInOutButton");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(dailyLogPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 452,
                                        Short.MAX_VALUE)
                                .addGroup(jPanel1Layout.createSequentialGroup().addGap(0, 287, Short.MAX_VALUE)
                                        .addComponent(viewButton, 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))
                                .addComponent(mainTitleLbl, javax.swing.GroupLayout.Alignment.LEADING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE))
                        .addContainerGap())
                .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING));
        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.DEFAULT_SIZE, 327, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .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(viewButton, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap()));

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

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

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

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

    private void checkInOutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkInOutButtonActionPerformed
        DailyLogRecord log = new DailyLogRecord();
        if (DailyLogAddUI.checkIn && !DailyLogAddUI.breakDone) {
            args = new HashMap();
            DailyLogAddUI.breakDone = true;
            args.put("checked-in", Boolean.toString(DailyLogAddUI.checkIn));
            args.put("had-break", Boolean.toString(DailyLogAddUI.breakDone));
            args.put("checked-out", Boolean.toString(DailyLogAddUI.checkOut));
            if (yesRdButton.isSelected() == true) {
                this.timeOnBreak = "00:30";
            } else if (customRdButton.isSelected() == true) {
                this.timeOnBreak = customBreakTimeTextField.getText();
            } else {
                this.timeOnBreak = "00:00";
            }
            log.setDailyLogRecord(dateDisplayLbl.getText(), dayDisplayLbl.getText(),
                    checkInTimeCombo.getSelectedItem().toString(), "", this.timeOnBreak, "", "", "", args);
            doc = (DBObject) JSON.parse(log.getDailyLogRecord().toString());
            args.clear();
            args.put("date", dateDisplayLbl.getText());
            log.updateRecord(doc, args);
        } else if (DailyLogAddUI.checkIn && DailyLogAddUI.breakDone && !DailyLogAddUI.checkOut) {
            args = new HashMap();
            DailyLogAddUI.checkOut = true;
            args.put("checked-in", Boolean.toString(DailyLogAddUI.checkIn));
            args.put("had-break", Boolean.toString(DailyLogAddUI.breakDone));
            args.put("checked-out", Boolean.toString(DailyLogAddUI.checkOut));
            DailyLogDuration durationAgent = new DailyLogDuration();
            durationAgent.calculateCurrentDuration(checkInTimeCombo.getSelectedItem().toString(), this.timeOnBreak,
                    checkOutTimeCombo.getSelectedItem().toString());
            this.duration = durationAgent.getCurrentDuration();

            JFrame parent = new JFrame();
            JOptionPane optionPane = new JOptionPane("Duration: " + this.duration + "\n\nDo you want to Check Out?",
                    JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
            JDialog msgDialog = optionPane.createDialog(parent, "DLM");
            msgDialog.setVisible(true);

            if (optionPane.getValue().equals(0)) {
                int hours = Integer.parseInt(this.duration.split(":")[0]);
                int minutes = Integer.parseInt(this.duration.split(":")[1]);
                if (hours < 9) {
                    durationAgent.calculateUnderTime(this.duration);
                    this.underTime = durationAgent.getUnderTime();
                    this.overTime = "00:00";
                } else if (hours >= 9 && minutes > 0 && minutes < 60) {
                    this.underTime = "00:00";
                    durationAgent.calculateOverTime(this.duration);
                    this.overTime = durationAgent.getOverTime();

                } else {
                    this.underTime = "00:00";
                    this.overTime = "00:00";
                }
                log.setDailyLogRecord(dateDisplayLbl.getText(), dayDisplayLbl.getText(),
                        checkInTimeCombo.getSelectedItem().toString(),
                        checkOutTimeCombo.getSelectedItem().toString(), this.timeOnBreak, this.duration,
                        this.underTime, this.overTime, args);
                doc = (DBObject) JSON.parse(log.getDailyLogRecord().toString());
                args.clear();
                args.put("date", dateDisplayLbl.getText());
                log.updateRecord(doc, args);
            } else {
                msgDialog.dispose();
            }
        } else {
            args = new HashMap();
            DailyLogAddUI.checkIn = true;
            args.put("checked-in", Boolean.toString(DailyLogAddUI.checkIn));
            args.put("had-break", Boolean.toString(DailyLogAddUI.breakDone));
            args.put("checked-out", Boolean.toString(DailyLogAddUI.checkOut));
            log.setDailyLogRecord(dateDisplayLbl.getText(), dayDisplayLbl.getText(),
                    checkInTimeCombo.getSelectedItem().toString(), "", "", "", "", "", args);
            doc = (DBObject) JSON.parse(log.getDailyLogRecord().toString());
            log.insertRecord(doc);

        }

    }//GEN-LAST:event_checkInOutButtonActionPerformed

    private void customRdButtonStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_customRdButtonStateChanged

    }//GEN-LAST:event_customRdButtonStateChanged

    private void customRdButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_customRdButtonMouseClicked
        customBreakTimeTextField.setEnabled(true);

    }//GEN-LAST:event_customRdButtonMouseClicked

    private void customRdButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_customRdButtonItemStateChanged
        customBreakTimeTextField.setEnabled(false);
    }//GEN-LAST:event_customRdButtonItemStateChanged

    private void checkOutTimeComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkOutTimeComboActionPerformed
        args.put("checked-out", Boolean.toString(true));
    }//GEN-LAST:event_checkOutTimeComboActionPerformed

    private void checkInTimeComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkInTimeComboActionPerformed
        args.put("checked-in", Boolean.toString(true));
    }//GEN-LAST:event_checkInTimeComboActionPerformed

    private void yesRdButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_yesRdButtonMouseClicked

    }//GEN-LAST:event_yesRdButtonMouseClicked

    private void noRdButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_noRdButtonMouseClicked

    }//GEN-LAST:event_noRdButtonMouseClicked
     // End of variables declaration//GEN-END:variables

}