package usda.weru.wmrm.gui;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.KeyStroke;
import java.util.HashMap;
import javax.swing.JTextField;

/**
 *
 * @author Ryan
 */
public class EditHeaderWindow_n extends javax.swing.JDialog {
    
    private static final long serialVersionUID = 1L;

    /**
     * A return status code - returned if Cancel button has been pressed
     */
    public static final int RET_CANCEL = 0;
    /**
     * A return status code - returned if OK button has been pressed
     */
    public static final int RET_OK = 1;
    public static String tValueUnit;
    public static String yLengthUnit;
    public static String xLengthUnit;
    public static String fieldAreaUnit;
    public static String orientationUnit;
    public static String latUnit;
    public static String lonUnit;

    /**
     * Creates new form EditHeaderWindow
     * @param parent - WMRM
     * @param modal - always false
     * @param textFields - header fields
     */
    public EditHeaderWindow_n(java.awt.Frame parent, boolean modal, String[] textFields) {
        super(parent, modal);
        initComponents();
        populateText(textFields);
    }
    
    public void configureWindow() {
                
        this.getRootPane().setDefaultButton(null);
        // Close the dialog when Esc is pressed
        String cancelName = "cancel";
        InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
        inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName);
        ActionMap actionMap = getRootPane().getActionMap();
        actionMap.put(cancelName, new AbstractActionImpl());
    }
    
    private void populateText(String[] textFields) {
        JTF_titleField.setText(textFields[0]);
        JTF_farmField.setText(textFields[1]);
        JTF_tractField.setText(textFields[2]);
        JTF_fieldField.setText(textFields[3]);
        JTF_soilField.setText(textFields[4]);
        JTF_tValueField.setText(textFields[5]);
        JTF_latField.setText(textFields[6]);
        
        String[] latlon = textFields[6].split("\\|");
        JTF_latField.setText(latlon[0].trim());
        JTF_lonField.setText(latlon[1].trim());
        
        JTF_fieldArea.setText(textFields[7]);
        JTF_xLengthField.setText(textFields[8]);
        JTF_yLengthField.setText(textFields[9]);
        JTF_orientationField.setText(textFields[10]);
        JTF_degShapeField.setText(textFields[11]);
        JTF_clientField.setText(textFields[12]);
    }

    /**
     * @return the return status of this dialog - one of RET_OK or RET_CANCEL
     */
    public int getReturnStatus() {
        return returnStatus;
    }

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

        okButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        JP_editPanel = new javax.swing.JPanel();
        JL_title = new javax.swing.JLabel();
        JTF_titleField = new javax.swing.JTextField();
        JP_farmNo = new javax.swing.JLabel();
        JTF_farmField = new javax.swing.JTextField();
        JL_tractNo = new javax.swing.JLabel();
        JTF_tractField = new javax.swing.JTextField();
        JL_fieldNo = new javax.swing.JLabel();
        JTF_fieldField = new javax.swing.JTextField();
        JL_soil = new javax.swing.JLabel();
        JTF_soilField = new javax.swing.JTextField();
        JL_Latitude = new javax.swing.JLabel();
        JTF_latField = new javax.swing.JTextField();
        JL_tValue = new javax.swing.JLabel();
        JTF_tValueField = new javax.swing.JTextField();
        JL_fieldArea = new javax.swing.JLabel();
        JTF_fieldArea = new javax.swing.JTextField();
        JL_xLength = new javax.swing.JLabel();
        JTF_xLengthField = new javax.swing.JTextField();
        JL_yLength = new javax.swing.JLabel();
        JTF_yLengthField = new javax.swing.JTextField();
        JL_orientation = new javax.swing.JLabel();
        JTF_orientationField = new javax.swing.JTextField();
        JL_degreeShape = new javax.swing.JLabel();
        JTF_degShapeField = new javax.swing.JTextField();
        JL_client = new javax.swing.JLabel();
        JTF_clientField = new javax.swing.JTextField();
        JL_longitude = new javax.swing.JLabel();
        JTF_lonField = new javax.swing.JTextField();

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.okButton.text")); // NOI18N
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.cancelButton.text")); // NOI18N
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(JL_title, org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.JL_title.text")); // NOI18N

        JTF_titleField.setText(org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.JTF_titleField.text")); // NOI18N
        JTF_titleField.setToolTipText(org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.JTF_titleField.toolTipText")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(JP_farmNo, org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.JP_farmNo.text")); // NOI18N

        JTF_farmField.setText(org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.JTF_farmField.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(JL_tractNo, org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.JL_tractNo.text")); // NOI18N

        JTF_tractField.setText(org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.JTF_tractField.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(JL_fieldNo, org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.JL_fieldNo.text")); // NOI18N

        JTF_fieldField.setText(org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.JTF_fieldField.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(JL_soil, org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.JL_soil.text")); // NOI18N

        JTF_soilField.setText(org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.JTF_soilField.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(JL_Latitude, org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.JL_Latitude.text")); // NOI18N

        JTF_latField.setText(org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.latitude.text")); // NOI18N
        JTF_latField.setName("latitude"); // NOI18N
        JTF_latField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                JTF_latFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                JTF_latFieldFocusLost(evt);
            }
        });
        JTF_latField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                JTF_latFieldKeyPressed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(JL_tValue, org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.JL_tValue.text")); // NOI18N

        JTF_tValueField.setText(org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.tValue.text")); // NOI18N
        JTF_tValueField.setName("tValue"); // NOI18N
        JTF_tValueField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                JTF_tValueFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                JTF_tValueFieldFocusLost(evt);
            }
        });
        JTF_tValueField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                JTF_tValueFieldKeyPressed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(JL_fieldArea, org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.JL_fieldArea.text")); // NOI18N

        JTF_fieldArea.setText(org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.fieldArea.text")); // NOI18N
        JTF_fieldArea.setToolTipText(org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.fieldArea.toolTipText")); // NOI18N
        JTF_fieldArea.setName("fieldArea"); // NOI18N
        JTF_fieldArea.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                JTF_fieldAreaFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                JTF_fieldAreaFocusLost(evt);
            }
        });
        JTF_fieldArea.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                JTF_fieldAreaKeyPressed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(JL_xLength, org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.JL_xLength.text")); // NOI18N

        JTF_xLengthField.setText(org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.xLength.text")); // NOI18N
        JTF_xLengthField.setName("xLength"); // NOI18N
        JTF_xLengthField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                JTF_xLengthFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                JTF_xLengthFieldFocusLost(evt);
            }
        });
        JTF_xLengthField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                JTF_xLengthFieldKeyPressed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(JL_yLength, org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.JL_yLength.text")); // NOI18N

        JTF_yLengthField.setText(org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.yLength.text")); // NOI18N
        JTF_yLengthField.setName("yLength"); // NOI18N
        JTF_yLengthField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                JTF_yLengthFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                JTF_yLengthFieldFocusLost(evt);
            }
        });
        JTF_yLengthField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                JTF_yLengthFieldKeyPressed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(JL_orientation, org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.JL_orientation.text")); // NOI18N

        JTF_orientationField.setText(org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.orientation.text")); // NOI18N
        JTF_orientationField.setName("orientation"); // NOI18N
        JTF_orientationField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                JTF_orientationFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                JTF_orientationFieldFocusLost(evt);
            }
        });
        JTF_orientationField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                JTF_orientationFieldKeyPressed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(JL_degreeShape, org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.JL_degreeShape.text")); // NOI18N

        JTF_degShapeField.setText(org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.JTF_degShapeField.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(JL_client, org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.JL_client.text")); // NOI18N

        JTF_clientField.setText(org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.JTF_clientField.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(JL_longitude, org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.JL_longitude.text")); // NOI18N

        JTF_lonField.setText(org.openide.util.NbBundle.getMessage(EditHeaderWindow_n.class, "EditHeaderWindow_n.longitude.text")); // NOI18N
        JTF_lonField.setName("longitude"); // NOI18N
        JTF_lonField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                JTF_lonFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                JTF_lonFieldFocusLost(evt);
            }
        });
        JTF_lonField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                JTF_lonFieldKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout JP_editPanelLayout = new javax.swing.GroupLayout(JP_editPanel);
        JP_editPanel.setLayout(JP_editPanelLayout);
        JP_editPanelLayout.setHorizontalGroup(
            JP_editPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JP_editPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(JP_editPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(JP_editPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(JP_editPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(JP_editPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(JL_fieldNo)
                                .addComponent(JL_tractNo)
                                .addGroup(JP_editPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(JP_farmNo)
                                    .addComponent(JL_title)))
                            .addComponent(JL_soil))
                        .addComponent(JL_Latitude))
                    .addComponent(JL_tValue))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(JP_editPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(JP_editPanelLayout.createSequentialGroup()
                        .addGroup(JP_editPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(JTF_farmField, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                            .addComponent(JTF_tractField, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(JTF_fieldField, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(JTF_soilField, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(JTF_tValueField)
                            .addComponent(JTF_titleField))
                        .addGap(7, 7, 7)
                        .addGroup(JP_editPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(JL_client)
                            .addComponent(JL_yLength)
                            .addComponent(JL_xLength)
                            .addComponent(JL_fieldArea)
                            .addComponent(JL_degreeShape)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, JP_editPanelLayout.createSequentialGroup()
                                .addComponent(JL_orientation)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))))
                    .addGroup(JP_editPanelLayout.createSequentialGroup()
                        .addComponent(JTF_latField)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(JL_longitude)
                        .addGap(13, 13, 13)))
                .addGroup(JP_editPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(JTF_clientField, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                    .addComponent(JTF_degShapeField, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JTF_orientationField, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JTF_yLengthField, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JTF_xLengthField, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JTF_fieldArea, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JTF_lonField))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        JP_editPanelLayout.setVerticalGroup(
            JP_editPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JP_editPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(JP_editPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JL_title)
                    .addComponent(JTF_titleField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JL_fieldArea)
                    .addComponent(JTF_fieldArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(JP_editPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JP_farmNo)
                    .addComponent(JTF_farmField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JL_xLength)
                    .addComponent(JTF_xLengthField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(JP_editPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JL_tractNo)
                    .addGroup(JP_editPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(JTF_tractField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(JL_yLength)
                        .addComponent(JTF_yLengthField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(JP_editPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JL_fieldNo)
                    .addGroup(JP_editPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(JTF_fieldField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(JTF_orientationField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(JL_orientation)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(JP_editPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JTF_soilField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JL_soil)
                    .addComponent(JTF_degShapeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JL_degreeShape))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(JP_editPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JL_client)
                    .addComponent(JTF_clientField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JL_tValue)
                    .addComponent(JTF_tValueField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(JP_editPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(JP_editPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(JL_Latitude)
                        .addComponent(JTF_latField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(JL_longitude))
                    .addComponent(JTF_lonField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 425, Short.MAX_VALUE)
                        .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelButton))
                    .addComponent(JP_editPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(JP_editPanel, 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)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelButton)
                    .addComponent(okButton))
                .addContainerGap())
        );

        getRootPane().setDefaultButton(okButton);

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

    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        HashMap<String, String> updatedInfo = new HashMap<>();
        // Add in the new values to hashmap
        updatedInfo.put("title", JTF_titleField.getText());
        updatedInfo.put("farm", JTF_farmField.getText());
        updatedInfo.put("tract", JTF_tractField.getText());
        updatedInfo.put("field", JTF_fieldField.getText());
        updatedInfo.put("soil", JTF_soilField.getText());
        updatedInfo.put("latlon", JTF_latField.getText() + " | " + JTF_lonField.getText());
        updatedInfo.put("tvalue", JTF_tValueField.getText());
        updatedInfo.put("field area", JTF_fieldArea.getText());
        updatedInfo.put("xLength", JTF_xLengthField.getText());
        updatedInfo.put("yLength", JTF_yLengthField.getText());
        updatedInfo.put("orientation", JTF_orientationField.getText());
        updatedInfo.put("shape", JTF_degShapeField.getText());
        updatedInfo.put("client", JTF_clientField.getText());
        
        editHeaderAction(updatedInfo);
        doClose(RET_OK);
    }//GEN-LAST:event_okButtonActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        doClose(RET_CANCEL);
    }//GEN-LAST:event_cancelButtonActionPerformed

    
    // Public actions
    public void editHeaderAction(HashMap<String, String> updatedInfo) {
         
    }
    
    /**
     * Closes the dialog
     */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        doClose(RET_CANCEL);
    }//GEN-LAST:event_closeDialog

    private void JTF_tValueFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_JTF_tValueFieldFocusGained
        this.focusGainedEvent(evt);
    }//GEN-LAST:event_JTF_tValueFieldFocusGained

    private void JTF_tValueFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_JTF_tValueFieldFocusLost
        this.focusLostTextUpdate(evt);
    }//GEN-LAST:event_JTF_tValueFieldFocusLost

    private void JTF_tValueFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_JTF_tValueFieldKeyPressed
        this.enterKeyPressed(evt);
    }//GEN-LAST:event_JTF_tValueFieldKeyPressed

    private void JTF_fieldAreaFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_JTF_fieldAreaFocusGained
        this.focusGainedEvent(evt);
    }//GEN-LAST:event_JTF_fieldAreaFocusGained

    private void JTF_fieldAreaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_JTF_fieldAreaFocusLost
        this.focusLostTextUpdate(evt);
    }//GEN-LAST:event_JTF_fieldAreaFocusLost

    private void JTF_fieldAreaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_JTF_fieldAreaKeyPressed
        this.enterKeyPressed(evt);
    }//GEN-LAST:event_JTF_fieldAreaKeyPressed

    private void JTF_xLengthFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_JTF_xLengthFieldFocusGained
        this.focusGainedEvent(evt);
    }//GEN-LAST:event_JTF_xLengthFieldFocusGained

    private void JTF_xLengthFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_JTF_xLengthFieldFocusLost
        this.focusLostTextUpdate(evt);
    }//GEN-LAST:event_JTF_xLengthFieldFocusLost

    private void JTF_xLengthFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_JTF_xLengthFieldKeyPressed
        this.enterKeyPressed(evt);
    }//GEN-LAST:event_JTF_xLengthFieldKeyPressed

    private void JTF_yLengthFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_JTF_yLengthFieldFocusGained
        this.focusGainedEvent(evt);
    }//GEN-LAST:event_JTF_yLengthFieldFocusGained

    private void JTF_yLengthFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_JTF_yLengthFieldFocusLost
        this.focusLostTextUpdate(evt);
    }//GEN-LAST:event_JTF_yLengthFieldFocusLost

    private void JTF_yLengthFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_JTF_yLengthFieldKeyPressed
        this.enterKeyPressed(evt);
    }//GEN-LAST:event_JTF_yLengthFieldKeyPressed

    private void JTF_latFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_JTF_latFieldFocusGained
        this.latLonFocusGained(evt);
    }//GEN-LAST:event_JTF_latFieldFocusGained

    private void JTF_lonFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_JTF_lonFieldFocusGained
        this.latLonFocusGained(evt);
    }//GEN-LAST:event_JTF_lonFieldFocusGained

    private void JTF_lonFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_JTF_lonFieldFocusLost
        this.latLonFocusLost(evt);
    }//GEN-LAST:event_JTF_lonFieldFocusLost

    private void JTF_latFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_JTF_latFieldFocusLost
        this.latLonFocusLost(evt);
    }//GEN-LAST:event_JTF_latFieldFocusLost

    private void JTF_latFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_JTF_latFieldKeyPressed
        this.enterKeyPressed(evt);
    }//GEN-LAST:event_JTF_latFieldKeyPressed

    private void JTF_lonFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_JTF_lonFieldKeyPressed
        this.enterKeyPressed(evt);
    }//GEN-LAST:event_JTF_lonFieldKeyPressed

    private void JTF_orientationFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_JTF_orientationFieldKeyPressed
        this.enterKeyPressed(evt);
    }//GEN-LAST:event_JTF_orientationFieldKeyPressed

    private void JTF_orientationFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_JTF_orientationFieldFocusGained
        this.focusGainedEvent(evt);
    }//GEN-LAST:event_JTF_orientationFieldFocusGained

    private void JTF_orientationFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_JTF_orientationFieldFocusLost
        this.focusLostTextUpdate(evt);
    }//GEN-LAST:event_JTF_orientationFieldFocusLost
    
    private void enterKeyPressed(java.awt.event.KeyEvent evt) {
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            this.requestFocusInWindow();
        }
    }
    
    /**
     * Given a textField focusGained event get any text that we want to save.
     * @param evt 
     */
    private void focusGainedEvent(java.awt.event.FocusEvent evt) {
        JTextField jtf = (JTextField) evt.getSource();

        String[] s = jtf.getText().split("\\s+");
        if (s.length > 1) {
            this.focusGainedTextUpdate(jtf, s[1]);
        } else if (s.length == 1) {
            s[0] = s[0].substring(0, s[0].length() - 1);
            this.focusGainedTextUpdate(jtf, "");
        }
        jtf.setText(s[0]);
    }
    
    private void latLonFocusLost(java.awt.event.FocusEvent evt) {
        JTextField jtf = (JTextField) evt.getSource();
        
        if ("latitude".equals(jtf.getName())) {
            if (jtf.getText().contains("-")) {
                jtf.setText(jtf.getText().replace("-", "") + "° S");
            } else {
                jtf.setText(jtf.getText() + "° N");
            }
        } else {
            if (jtf.getText().contains("-")) {
                jtf.setText(jtf.getText().replace("-", "") + "° W");
            } else {
                jtf.setText(jtf.getText() + "° E");
            }
        }
    }
    
    private void latLonFocusGained(java.awt.event.FocusEvent evt) {
        JTextField jtf = (JTextField) evt.getSource();
        String[] split = jtf.getText().split("\\s+");
        String result;
        String direction = split[1].trim();
        StringBuilder coordinate = new StringBuilder(split[0].trim());
        
        if ("W".equals(direction) || "S".equals(direction)) {
            result = "-" + coordinate.deleteCharAt(coordinate.length() - 1).toString();
        } else {
            result = coordinate.deleteCharAt(coordinate.length() - 1).toString();
        }
        
        jtf.setText(result);
    }
    
    private void focusGainedTextUpdate(JTextField jtf, String unit) {
        switch (jtf.getName()) {
            case "tValue" :
                tValueUnit = unit;
                break;
            case "yLength" :
                yLengthUnit = unit;
                break;
            case "xLength" :
                xLengthUnit = unit;
                break;
            case "fieldArea" :
                fieldAreaUnit = unit;
                break;
            case "orientation" :
                orientationUnit = "°";
        }
    }
    
    private void focusLostTextUpdate(java.awt.event.FocusEvent evt) {
        JTextField jtf = (JTextField) evt.getSource();

        switch (jtf.getName()) {
            case "tValue" :
                jtf.setText(jtf.getText() + " " + tValueUnit);
                break;
            case "yLength" :
                jtf.setText(jtf.getText() + " " + yLengthUnit);
                break;
            case "xLength" :
                jtf.setText(jtf.getText() + " " + xLengthUnit);
                break;
            case "fieldArea" :
                jtf.setText(jtf.getText() + " " + fieldAreaUnit);
                break;
            case "orientation" :
                jtf.setText(jtf.getText() + orientationUnit);
        }
    }
    
    private void doClose(int retStatus) {
        returnStatus = retStatus;
        setVisible(false);
        dispose();
    }

    /**
     * @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) {
        } catch (InstantiationException ex) {
        } catch (IllegalAccessException ex) {
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(() -> {
            String[] tmp = new String[]{"sdf"};
            EditHeaderWindow_n dialog = new EditHeaderWindow_n(new javax.swing.JFrame(), true, tmp);
            dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                @Override
                public void windowClosing(java.awt.event.WindowEvent e) {
                    System.exit(0);
                }
            });
            dialog.setVisible(true);
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel JL_Latitude;
    private javax.swing.JLabel JL_client;
    private javax.swing.JLabel JL_degreeShape;
    private javax.swing.JLabel JL_fieldArea;
    private javax.swing.JLabel JL_fieldNo;
    private javax.swing.JLabel JL_longitude;
    private javax.swing.JLabel JL_orientation;
    private javax.swing.JLabel JL_soil;
    private javax.swing.JLabel JL_tValue;
    private javax.swing.JLabel JL_title;
    private javax.swing.JLabel JL_tractNo;
    private javax.swing.JLabel JL_xLength;
    private javax.swing.JLabel JL_yLength;
    private javax.swing.JPanel JP_editPanel;
    private javax.swing.JLabel JP_farmNo;
    private javax.swing.JTextField JTF_clientField;
    private javax.swing.JTextField JTF_degShapeField;
    private javax.swing.JTextField JTF_farmField;
    private javax.swing.JTextField JTF_fieldArea;
    private javax.swing.JTextField JTF_fieldField;
    private javax.swing.JTextField JTF_latField;
    private javax.swing.JTextField JTF_lonField;
    private javax.swing.JTextField JTF_orientationField;
    private javax.swing.JTextField JTF_soilField;
    private javax.swing.JTextField JTF_tValueField;
    private javax.swing.JTextField JTF_titleField;
    private javax.swing.JTextField JTF_tractField;
    private javax.swing.JTextField JTF_xLengthField;
    private javax.swing.JTextField JTF_yLengthField;
    private javax.swing.JButton cancelButton;
    private javax.swing.JButton okButton;
    // End of variables declaration//GEN-END:variables

    private int returnStatus = RET_CANCEL;

    private class AbstractActionImpl extends AbstractAction {

        private static final long serialVersionUID = 1L;

        public AbstractActionImpl() {
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            doClose(RET_CANCEL);
        }
    }
}
