/*
 * Calender_n.java
 *
 * Created on February 9, 2004, 1:52 PM
 */

package usda.weru.mcrew.gui;

/**
 * This class builds the GUI calendar so that dates could be set in the MCREW table
 * date column by clicking day, month and year from the visual GUI and also have
 * the provision for future modification though it if needed.
 * @author  manmohan
 */
public class Calendar_n extends javax.swing.JDialog {
    private static final long serialVersionUID = 1L;
    
    /**
     * Default constructor for the calendar dialog GUI object.
     */
    public Calendar_n() {
        super();
        initComponents();
    }
    
    /**
     * Single argument constructor for the calendar dialog GUI object.
     * @param parent The address of the parent component in which this frame sits.
     */
    public Calendar_n(java.awt.Frame parent) {
        super(parent);
        initComponents();
    }
    
    /**
     * Single argument constructor for the calendar dialog GUI object.
     * @param sTitle The title of the frame in which the calendar dialog sits.
     */
    public Calendar_n(java.lang.String sTitle) {
        this();
        setTitle(sTitle);
    }
    
    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        JB_ok = new javax.swing.JButton();
        JB_cancel = new javax.swing.JButton();
        JP_calendar = new javax.swing.JPanel();
        jcTable = new com.klg.jclass.table.beans.LiveTable();
        JTF_year = new javax.swing.JTextField();
        JL_yearUp = new javax.swing.JLabel();
        JL_yearDown = new javax.swing.JLabel();
        JL_monthUp = new javax.swing.JLabel();
        JCB_month = new javax.swing.JComboBox<String>();
        JL_monthDown = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setModal(true);
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        JB_ok.setMnemonic('O');
        JB_ok.setText("OK");
        JB_ok.setDefaultCapable(false);
        JB_ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_ok_ActionPerformed(evt);
            }
        });

        JB_cancel.setMnemonic('C');
        JB_cancel.setText("Cancel");
        JB_cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_cancel_ActionPerformed(evt);
            }
        });

        JP_calendar.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        javax.swing.GroupLayout JP_calendarLayout = new javax.swing.GroupLayout(JP_calendar);
        JP_calendar.setLayout(JP_calendarLayout);
        JP_calendarLayout.setHorizontalGroup(
            JP_calendarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jcTable, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)
        );
        JP_calendarLayout.setVerticalGroup(
            JP_calendarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jcTable, javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE)
        );

        JTF_year.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        JTF_year.setText("0");
        JTF_year.setToolTipText("Rotation or Actual Year");
        JTF_year.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JTFYear_ActionPerformed(evt);
            }
        });
        JTF_year.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                JTFYear_FocusLost(evt);
            }
        });

        JL_yearUp.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        JL_yearUp.setText(">>");
        JL_yearUp.setToolTipText("Increment Year");
        JL_yearUp.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                JLYearUp_MouseClicked(evt);
            }
        });

        JL_yearDown.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        JL_yearDown.setText("<<");
        JL_yearDown.setToolTipText("Decrement Year");
        JL_yearDown.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                JLYearDown_MouseClicked(evt);
            }
        });

        JL_monthUp.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        JL_monthUp.setText(">>");
        JL_monthUp.setToolTipText("Increment Month");
        JL_monthUp.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                JLMonthUp_MouseClicked(evt);
            }
        });

        JCB_month.setMaximumRowCount(12);
        JCB_month.setModel(new javax.swing.DefaultComboBoxModel<String>(new String[]
            { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }));
    JCB_month.setToolTipText("Month");
    JCB_month.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            JCB_month_ItemStateChanged(evt);
        }
    });

    JL_monthDown.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    JL_monthDown.setText("<<");
    JL_monthDown.setToolTipText("Decrement month");
    JL_monthDown.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            JLMonthDown_MouseClicked(evt);
        }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addComponent(JL_monthDown)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(JCB_month, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(JL_monthUp)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 121, Short.MAX_VALUE)
                    .addComponent(JL_yearDown)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(JTF_year, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(JL_yearUp))
                .addComponent(JP_calendar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addComponent(JB_ok, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(JB_cancel, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addContainerGap())
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(JL_monthDown, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(JCB_month, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(JL_yearUp, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(JL_yearDown, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(JTF_year, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(JL_monthUp, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(JP_calendar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(JB_cancel)
                .addComponent(JB_ok))
            .addContainerGap())
    );

    setSize(new java.awt.Dimension(334, 338));
    setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents
    
    private void JCB_month_ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_JCB_month_ItemStateChanged
        JCB_month_itemStateChanged(evt);
    }//GEN-LAST:event_JCB_month_ItemStateChanged
    
    private void JB_cancel_ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_cancel_ActionPerformed
        Cancel_actionPerformed(evt);
}//GEN-LAST:event_JB_cancel_ActionPerformed
    
    private void JB_ok_ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_ok_ActionPerformed
        OK_actionPerformed(evt);
}//GEN-LAST:event_JB_ok_ActionPerformed
    
    private void JTFYear_FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_JTFYear_FocusLost
        JTFYear_focusLost(evt);
    }//GEN-LAST:event_JTFYear_FocusLost
    
    private void JTFYear_ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JTFYear_ActionPerformed
        JTFYear_actionPerformed(evt);
    }//GEN-LAST:event_JTFYear_ActionPerformed
    
    private void JLYearUp_MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_JLYearUp_MouseClicked
        JLYearUp_mouseClicked(evt);
    }//GEN-LAST:event_JLYearUp_MouseClicked
    
    private void JLYearDown_MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_JLYearDown_MouseClicked
        JLYearDown_mouseClicked(evt);
    }//GEN-LAST:event_JLYearDown_MouseClicked
    
    private void JLMonthUp_MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_JLMonthUp_MouseClicked
        JLMonthUp_mouseClicked(evt);
    }//GEN-LAST:event_JLMonthUp_MouseClicked
    
    private void JLMonthDown_MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_JLMonthDown_MouseClicked
        JLMonthDown_mouseClicked(evt);
    }//GEN-LAST:event_JLMonthDown_MouseClicked
    
    /**
     * This method is called when the month combo box changes its state if a user
     * tries to update the values by making different selections.
     * @param evt The event generated when the month combo box has a new selection
     * of items.
     */
    public void JCB_month_itemStateChanged(java.awt.event.ItemEvent evt) {
    }
    
    /**
     * This method is called when a cancel button on the calendar dialog is pressed
     * and any modifications to the data on the screen need not be saved.
     * @param evt The event generated when the cancel button is pressed.
     */
    public void Cancel_actionPerformed(java.awt.event.ActionEvent evt) {
    }
    
    /**
     * This method is called when an OK button on the calendar dialog is pressed
     * and any modifications to the data on the screen need to be saved.
     * @param evt The event generated when the cancel button is pressed.
     */
    public void OK_actionPerformed(java.awt.event.ActionEvent evt) {
    }
    
    /**
     * This method is called when year text field looses focus on the calendar dialog
     * and any modifications to the data in that text field are to be saved.
     * @param evt The event generated when the year text field looses focus
     */
    public void JTFYear_focusLost(java.awt.event.FocusEvent evt) {
    }
    
    /**
     * This method is called when a new value is entered in the year text field
     * on the calendar dialog or any modifications to the existing data is supposed
     * to be saved.
     * @param evt The event generated when the year text field gets new value.
     */
    public void JTFYear_actionPerformed(java.awt.event.ActionEvent evt) {
    }
    
    /**
     * This method is called when the mouse click event to increment the year value
     * occurs and the value is incremented from currently assigned value.
     * @param evt The event generated when the mouse click event to increment the
     * year occurs.
     */
    public void JLYearUp_mouseClicked(java.awt.event.MouseEvent evt) {
    }
    
    /**
     * This method is called when the mouse click event to decrement the year value
     * occurs and the value is decremented from currently assigned value.
     * @param evt The event generated when the mouse click event to decrement the
     * year occurs.
     */
    public void JLYearDown_mouseClicked(java.awt.event.MouseEvent evt) {
    }
    
    /**
     * This method is called when the mouse click event to increment the month value
     * occurs and the value is incremented from currently assigned value.
     * @param evt The event generated when the mouse click event to increment the
     * month occurs.
     */
    public void JLMonthUp_mouseClicked(java.awt.event.MouseEvent evt) {
    }
    
    /**
     * This method is called when the mouse click event to decrement the month value
     * occurs and the value is decremented from currently assigned value.
     * @param evt The event generated when the mouse click event to decrement the
     * month occurs.
     */
    public void JLMonthDown_mouseClicked(java.awt.event.MouseEvent evt) {
    }
    /**
     * This method is called when the calendar dialog is to be closed by hitting the
     * "Red X" button of the window.
     * @param evt The event generated when the " Red X " button on the window is hit.
     */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        
    }//GEN-LAST:event_closeDialog
    
    /**
     * This method is used if this dialog is rum as an independent application.
     * @param args These are the command line arguments passed to the main method.
     */
    public static void main(String args[]) {
        new Calendar_n(new javax.swing.JFrame()).setVisible(true);
    }
    
    /**
     * This method notifies when the window or frame is resized and the components need to be
     * re-arranged so they are evenly spaced relative to each other.
     */
    @Override
    public void addNotify() {
        // Dimension size = getSize();
        super.addNotify();
        if (frameSizeAdjusted)
            return;
        frameSizeAdjusted = true;
        
        // Adjust size of frame according to the insets
        //Insets insets = getInsets();
        //setSize(insets.left + insets.right + size.width, insets.top + insets.bottom + size.height);
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JButton JB_cancel;
    public javax.swing.JButton JB_ok;
    public javax.swing.JComboBox<String> JCB_month;
    public javax.swing.JLabel JL_monthDown;
    public javax.swing.JLabel JL_monthUp;
    public javax.swing.JLabel JL_yearDown;
    public javax.swing.JLabel JL_yearUp;
    public javax.swing.JPanel JP_calendar;
    public javax.swing.JTextField JTF_year;
    protected com.klg.jclass.table.beans.LiveTable jcTable;
    // End of variables declaration//GEN-END:variables
    boolean frameSizeAdjusted = false;
    
}
