/********************************************************************************
  
   Program                :  uFr Simple
   File                   :  uFRSimple.java (main class)
   Description            :  Functions to work with the keys card and reader key
   Author                 :  VladanS
   Manufacturer           :  D-Logic
   Development enviroment :  NetBeans 7.2 
   Java Platform          :  JDK 1.7
   Revisions	          :  
   Version                :  1.6
   
*********************************************************************************/
package uFRSimple;


import com.sun.jna.Platform;
import com.sun.jna.ptr.ByteByReference;
import com.sun.jna.ptr.ShortByReference;
import java.awt.Color;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.concurrent.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import javax.swing.*;

/**
 * 
 * @author VladanS
 * @version 1.6
 */


public class UFRSimple extends javax.swing.JFrame  implements KeyListener,FocusListener 
{
    
  private static final int RES_LIGHT_OK = 4,
                           RES_SOUND_OK = 0,//4 Tripple sound
                           ERR_LIGHT = 2,
                           ERR_SOUND = 0,//2 Long sound
                           DL_OK = 0,
                           AUTH1A = 96,
                           AUTH1B = 97,                           
                           LINEAR_MAX_BYTES = 752;
 
   private final static String ANY_DATA = "You must enter any data !",
                               APPROPRIATE_FORMAT = "Enter a number between 0 and 255 decimal or 0 and FF hexadecimal !",
                               NEW_CARD_KEY_A="txtNewCardKeyA",   
                               NEW_CARD_KEY_B="txtNewCardKeyB",
                               NEW_READER_KEY="txtNewReaderKey";
   
    private int iResult = 0;
    private byte bKeyIndex=0;
           
    private int[] iReaderType = new int[2];
    private int[] iReaderSerial = new int[2];
    private int[] iCardSerial = new int[2];
    private byte[] iCardId = new byte[2];
    private byte[] baReadUserData = new byte[16];
    
    private boolean boCONN = false, 
                    boThreadStop = false,
                    boThreadStart = false,
                    boReaderStop = false,            
                    boFunctionOn = false;
           
    
 
    private JTextField TB=new JTextField();  
    
    private void ReaderOff() {
        boReaderStop = true;
    }

    private void ReaderOn() {
        boReaderStop = false;
    }
    
    /** Description PlatformOsType()
     *  Linux          1
     *  Windows        2
     *    
     * @param void   
     * @return     name  .so or .dll file for appropriate platform
     */
    
    public static String PlatformOsType(){
        String platform_lib = "";
        switch(Platform.getOSType()){
            case 1:platform_lib =(Platform.is64Bit() ? "libuFCoder1x64.so" : "libuFCoder1x86.so");
                break;
            case 2:platform_lib="uFCoder1x.dll";    
        }
        return platform_lib;
    }
   
    ExecutorService exec = Executors.newCachedThreadPool();

    public UFRSimple() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btngAUTH1AB = new javax.swing.ButtonGroup();
        pnlReader = new javax.swing.JPanel();
        lblReaderType = new javax.swing.JLabel();
        txtReaderType = new javax.swing.JTextField();
        lblReaderSerial = new javax.swing.JLabel();
        txtReaderSerial = new javax.swing.JTextField();
        lblCardType = new javax.swing.JLabel();
        txtCardType = new javax.swing.JTextField();
        lblReaderType3 = new javax.swing.JLabel();
        txtCardSerial = new javax.swing.JTextField();
        pnlSep1 = new javax.swing.JPanel();
        lblLightMode = new javax.swing.JLabel();
        cboLightMode = new javax.swing.JComboBox();
        lblSoundMode = new javax.swing.JLabel();
        cboSoundMode = new javax.swing.JComboBox();
        stbReader = new javax.swing.JPanel();
        stbConnection = new javax.swing.JLabel();
        stbReaderCode = new javax.swing.JLabel();
        stbReaderExplain = new javax.swing.JLabel();
        btnReaderUISignal = new javax.swing.JButton();
        pnlAUTH1AB = new javax.swing.JPanel();
        rbAUTH1A = new javax.swing.JRadioButton();
        rbAUTH1B = new javax.swing.JRadioButton();
        pnlFormat = new javax.swing.JPanel();
        pgCardReaderKeys = new javax.swing.JTabbedPane();
        pnlNewCardKeys = new javax.swing.JPanel();
        lblKeyA = new javax.swing.JLabel();
        lblKeyB = new javax.swing.JLabel();
        chkNewCardKeys = new javax.swing.JCheckBox();
        btnFormatCardKeys = new javax.swing.JButton();
        lblSectorsFormatted = new javax.swing.JLabel();
        txtSectorsFormatted = new javax.swing.JTextField();
        pnlNewReaderKey = new javax.swing.JPanel();
        chkNewReaderKey = new javax.swing.JCheckBox();
        btnFormatReaderKey = new javax.swing.JButton();
        lblKeyIndex = new javax.swing.JLabel();
        txtKeyIndex = new javax.swing.JLabel();
        stbCardStatusPanel = new javax.swing.JPanel();
        stbCardStatus = new javax.swing.JLabel();
        stbCard_Code = new javax.swing.JLabel();
        stbCard_Explain = new javax.swing.JLabel();
        stbFunctionError = new javax.swing.JPanel();
        stbFunction_error = new javax.swing.JLabel();
        stbFunctionErrorCode = new javax.swing.JLabel();
        stbFunctionErrorExplain = new javax.swing.JLabel();
        pgLinearReadWrite = new javax.swing.JTabbedPane();
        tabLinearRead = new javax.swing.JPanel();
        lblReadData = new javax.swing.JLabel();
        lblLRLinearAddress = new javax.swing.JLabel();
        txtLRLinearAddress = new javax.swing.JTextField();
        lblLRDataLength = new javax.swing.JLabel();
        txtLRDataLength = new javax.swing.JTextField();
        lblBytesRead = new javax.swing.JLabel();
        txtBytesRead = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtLinearRead = new javax.swing.JTextArea();
        btnLinearRead = new javax.swing.JButton();
        tabLinearWrite = new javax.swing.JPanel();
        lblWriteData = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtWriteData = new javax.swing.JTextArea();
        lblLWLinearAddress = new javax.swing.JLabel();
        txtLWLinearAddress = new javax.swing.JTextField();
        lblLWDataLength = new javax.swing.JLabel();
        txtLWDataLength = new javax.swing.JTextField();
        lblBytesWritten = new javax.swing.JLabel();
        txtBytesWritten = new javax.swing.JTextField();
        btnLinearWrite = new javax.swing.JButton();
        mnuMeni = new javax.swing.JMenuBar();
        mnuFileItem = new javax.swing.JMenu();
        mnuExitItems = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("uFRcSimple");
        setLocationByPlatform(true);
        setName("frmUFRSimple"); // NOI18N
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        pnlReader.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lblReaderType.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblReaderType.setText("Reader Type");

        txtReaderType.setEditable(false);
        txtReaderType.setBackground(new java.awt.Color(255, 255, 255));
        txtReaderType.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
        txtReaderType.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtReaderType.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        lblReaderSerial.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblReaderSerial.setText("Reader Serial");

        txtReaderSerial.setEditable(false);
        txtReaderSerial.setBackground(new java.awt.Color(255, 255, 255));
        txtReaderSerial.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
        txtReaderSerial.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtReaderSerial.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        lblCardType.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblCardType.setText("Card Type");

        txtCardType.setEditable(false);
        txtCardType.setBackground(new java.awt.Color(255, 255, 255));
        txtCardType.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
        txtCardType.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtCardType.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        lblReaderType3.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblReaderType3.setText("Card Serial");

        txtCardSerial.setEditable(false);
        txtCardSerial.setBackground(new java.awt.Color(255, 255, 255));
        txtCardSerial.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
        txtCardSerial.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtCardSerial.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        pnlSep1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javax.swing.GroupLayout pnlSep1Layout = new javax.swing.GroupLayout(pnlSep1);
        pnlSep1.setLayout(pnlSep1Layout);
        pnlSep1Layout.setHorizontalGroup(
            pnlSep1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 457, Short.MAX_VALUE)
        );
        pnlSep1Layout.setVerticalGroup(
            pnlSep1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        lblLightMode.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblLightMode.setText("Light Mode");

        cboLightMode.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        cboLightMode.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "None", "Long Green", "Long Red", "Alternation", "Flash" }));
        cboLightMode.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        cboLightMode.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

        lblSoundMode.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblSoundMode.setText("Sound Mode");

        cboSoundMode.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        cboSoundMode.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "None", "Short", "Long", "Double Short", "Tripple Short", "Tripplet Melody" }));
        cboSoundMode.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        cboSoundMode.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

        stbReader.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        stbConnection.setBackground(new java.awt.Color(255, 255, 255));
        stbConnection.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        stbConnection.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        stbConnection.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        stbConnection.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        stbConnection.setOpaque(true);

        stbReaderCode.setBackground(new java.awt.Color(255, 255, 255));
        stbReaderCode.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        stbReaderCode.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        stbReaderCode.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        stbReaderCode.setOpaque(true);

        stbReaderExplain.setBackground(new java.awt.Color(255, 255, 255));
        stbReaderExplain.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        stbReaderExplain.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        stbReaderExplain.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        stbReaderExplain.setOpaque(true);

        javax.swing.GroupLayout stbReaderLayout = new javax.swing.GroupLayout(stbReader);
        stbReader.setLayout(stbReaderLayout);
        stbReaderLayout.setHorizontalGroup(
            stbReaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(stbReaderLayout.createSequentialGroup()
                .addComponent(stbConnection, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(stbReaderCode, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(stbReaderExplain, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        stbReaderLayout.setVerticalGroup(
            stbReaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(stbConnection, javax.swing.GroupLayout.DEFAULT_SIZE, 18, Short.MAX_VALUE)
            .addComponent(stbReaderCode, javax.swing.GroupLayout.DEFAULT_SIZE, 18, Short.MAX_VALUE)
            .addComponent(stbReaderExplain, javax.swing.GroupLayout.DEFAULT_SIZE, 18, Short.MAX_VALUE)
        );

        btnReaderUISignal.setText("READER UI SIGNAL");
        btnReaderUISignal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReaderUISignalActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlReaderLayout = new javax.swing.GroupLayout(pnlReader);
        pnlReader.setLayout(pnlReaderLayout);
        pnlReaderLayout.setHorizontalGroup(
            pnlReaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlReaderLayout.createSequentialGroup()
                .addGap(47, 47, 47)
                .addGroup(pnlReaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlReaderLayout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addGroup(pnlReaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(pnlReaderLayout.createSequentialGroup()
                                .addComponent(lblReaderSerial)
                                .addGap(18, 18, 18)
                                .addComponent(txtReaderSerial, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(pnlReaderLayout.createSequentialGroup()
                                .addComponent(lblReaderType)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(txtReaderType, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(44, 44, 44)
                        .addGroup(pnlReaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(pnlReaderLayout.createSequentialGroup()
                                .addComponent(lblReaderType3)
                                .addGap(18, 18, 18)
                                .addComponent(txtCardSerial, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlReaderLayout.createSequentialGroup()
                                .addComponent(lblCardType)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(txtCardType, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(pnlSep1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(pnlReaderLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(pnlReaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblLightMode)
                            .addComponent(lblSoundMode))
                        .addGap(27, 27, 27)
                        .addGroup(pnlReaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cboLightMode, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cboSoundMode, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(39, 39, 39)
                        .addComponent(btnReaderUISignal, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
            .addComponent(stbReader, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        pnlReaderLayout.setVerticalGroup(
            pnlReaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlReaderLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlReaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblReaderType)
                    .addComponent(txtCardType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtReaderType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblCardType))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlReaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblReaderSerial)
                    .addComponent(txtReaderSerial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblReaderType3)
                    .addComponent(txtCardSerial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlSep1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(pnlReaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlReaderLayout.createSequentialGroup()
                        .addGroup(pnlReaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblLightMode)
                            .addComponent(cboLightMode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlReaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblSoundMode)
                            .addComponent(cboSoundMode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(pnlReaderLayout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(btnReaderUISignal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(stbReader, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pnlAUTH1AB.setBackground(new java.awt.Color(255, 255, 255));
        pnlAUTH1AB.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        rbAUTH1A.setBackground(new java.awt.Color(255, 255, 255));
        btngAUTH1AB.add(rbAUTH1A);
        rbAUTH1A.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
        rbAUTH1A.setSelected(true);
        rbAUTH1A.setText("AUTH 1A");
        rbAUTH1A.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

        rbAUTH1B.setBackground(new java.awt.Color(255, 255, 255));
        btngAUTH1AB.add(rbAUTH1B);
        rbAUTH1B.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
        rbAUTH1B.setText("AUTH 1B");
        rbAUTH1B.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

        javax.swing.GroupLayout pnlAUTH1ABLayout = new javax.swing.GroupLayout(pnlAUTH1AB);
        pnlAUTH1AB.setLayout(pnlAUTH1ABLayout);
        pnlAUTH1ABLayout.setHorizontalGroup(
            pnlAUTH1ABLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlAUTH1ABLayout.createSequentialGroup()
                .addGap(101, 101, 101)
                .addComponent(rbAUTH1A)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(rbAUTH1B)
                .addGap(128, 128, 128))
        );
        pnlAUTH1ABLayout.setVerticalGroup(
            pnlAUTH1ABLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlAUTH1ABLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(rbAUTH1A)
                .addComponent(rbAUTH1B))
        );

        pnlFormat.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        pgCardReaderKeys.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N

        lblKeyA.setText("Key A");

        lblKeyB.setText("Key B");

        chkNewCardKeys.setText("Hex");
        chkNewCardKeys.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                chkNewCardKeysItemStateChanged(evt);
            }
        });

        btnFormatCardKeys.setText("FORMAT CARD KEYS");
        btnFormatCardKeys.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFormatCardKeysActionPerformed(evt);
            }
        });

        lblSectorsFormatted.setText("Sectors Formatted");

        txtSectorsFormatted.setEditable(false);
        txtSectorsFormatted.setBackground(new java.awt.Color(204, 204, 204));
        txtSectorsFormatted.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        txtSectorsFormatted.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtSectorsFormatted.setAutoscrolls(false);
        txtSectorsFormatted.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        txtSectorsFormatted.setPreferredSize(new java.awt.Dimension(5, 16));

        javax.swing.GroupLayout pnlNewCardKeysLayout = new javax.swing.GroupLayout(pnlNewCardKeys);
        pnlNewCardKeys.setLayout(pnlNewCardKeysLayout);
        pnlNewCardKeysLayout.setHorizontalGroup(
            pnlNewCardKeysLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlNewCardKeysLayout.createSequentialGroup()
                .addGroup(pnlNewCardKeysLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlNewCardKeysLayout.createSequentialGroup()
                        .addGap(45, 45, 45)
                        .addGroup(pnlNewCardKeysLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblKeyA)
                            .addComponent(lblKeyB)))
                    .addGroup(pnlNewCardKeysLayout.createSequentialGroup()
                        .addGap(85, 85, 85)
                        .addComponent(chkNewCardKeys)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 196, Short.MAX_VALUE)
                .addGroup(pnlNewCardKeysLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(pnlNewCardKeysLayout.createSequentialGroup()
                        .addComponent(lblSectorsFormatted)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(txtSectorsFormatted, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnFormatCardKeys, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        pnlNewCardKeysLayout.setVerticalGroup(
            pnlNewCardKeysLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlNewCardKeysLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlNewCardKeysLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(pnlNewCardKeysLayout.createSequentialGroup()
                        .addComponent(lblKeyA)
                        .addGap(18, 18, 18)
                        .addComponent(lblKeyB))
                    .addGroup(pnlNewCardKeysLayout.createSequentialGroup()
                        .addComponent(btnFormatCardKeys, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(6, 6, 6)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlNewCardKeysLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlNewCardKeysLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtSectorsFormatted, javax.swing.GroupLayout.DEFAULT_SIZE, 19, Short.MAX_VALUE)
                        .addComponent(lblSectorsFormatted))
                    .addGroup(pnlNewCardKeysLayout.createSequentialGroup()
                        .addComponent(chkNewCardKeys)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addGap(11, 11, 11))
        );

        pgCardReaderKeys.addTab("New Card Keys", pnlNewCardKeys);

        chkNewReaderKey.setText("Hex");
        chkNewReaderKey.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                chkNewReaderKeyItemStateChanged(evt);
            }
        });

        btnFormatReaderKey.setText("FORMAT READER KEY");
        btnFormatReaderKey.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFormatReaderKeyActionPerformed(evt);
            }
        });

        lblKeyIndex.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblKeyIndex.setText("Key Index");

        txtKeyIndex.setBackground(new java.awt.Color(255, 255, 255));
        txtKeyIndex.setFont(new java.awt.Font("Verdana", 1, 20)); // NOI18N
        txtKeyIndex.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        txtKeyIndex.setText("0");
        txtKeyIndex.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        txtKeyIndex.setEnabled(false);

        javax.swing.GroupLayout pnlNewReaderKeyLayout = new javax.swing.GroupLayout(pnlNewReaderKey);
        pnlNewReaderKey.setLayout(pnlNewReaderKeyLayout);
        pnlNewReaderKeyLayout.setHorizontalGroup(
            pnlNewReaderKeyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlNewReaderKeyLayout.createSequentialGroup()
                .addContainerGap(87, Short.MAX_VALUE)
                .addComponent(chkNewReaderKey)
                .addGap(58, 58, 58)
                .addComponent(lblKeyIndex)
                .addGap(17, 17, 17)
                .addComponent(txtKeyIndex, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnFormatReaderKey, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28))
        );
        pnlNewReaderKeyLayout.setVerticalGroup(
            pnlNewReaderKeyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlNewReaderKeyLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(pnlNewReaderKeyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlNewReaderKeyLayout.createSequentialGroup()
                        .addGroup(pnlNewReaderKeyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(chkNewReaderKey)
                            .addComponent(lblKeyIndex))
                        .addGap(16, 16, 16))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlNewReaderKeyLayout.createSequentialGroup()
                        .addComponent(txtKeyIndex, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
            .addGroup(pnlNewReaderKeyLayout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(btnFormatReaderKey, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 20, Short.MAX_VALUE))
        );

        pgCardReaderKeys.addTab("New Reader Key", pnlNewReaderKey);

        javax.swing.GroupLayout pnlFormatLayout = new javax.swing.GroupLayout(pnlFormat);
        pnlFormat.setLayout(pnlFormatLayout);
        pnlFormatLayout.setHorizontalGroup(
            pnlFormatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlFormatLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pgCardReaderKeys)
                .addContainerGap())
        );
        pnlFormatLayout.setVerticalGroup(
            pnlFormatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlFormatLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pgCardReaderKeys, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        stbCardStatusPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        stbCardStatus.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        stbCardStatus.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        stbCardStatus.setText("CARD STATUS");
        stbCardStatus.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        stbCard_Code.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        stbCard_Code.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        stbCard_Code.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        stbCard_Explain.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        stbCard_Explain.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        stbCard_Explain.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        javax.swing.GroupLayout stbCardStatusPanelLayout = new javax.swing.GroupLayout(stbCardStatusPanel);
        stbCardStatusPanel.setLayout(stbCardStatusPanelLayout);
        stbCardStatusPanelLayout.setHorizontalGroup(
            stbCardStatusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(stbCardStatusPanelLayout.createSequentialGroup()
                .addComponent(stbCardStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(6, 6, 6)
                .addComponent(stbCard_Code, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(6, 6, 6)
                .addComponent(stbCard_Explain, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        stbCardStatusPanelLayout.setVerticalGroup(
            stbCardStatusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(stbCardStatus)
            .addComponent(stbCard_Code, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(stbCard_Explain, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        stbFunctionError.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        stbFunction_error.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        stbFunction_error.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        stbFunction_error.setText("Function Error :");
        stbFunction_error.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        stbFunctionErrorCode.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        stbFunctionErrorCode.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        stbFunctionErrorCode.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        stbFunctionErrorExplain.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        stbFunctionErrorExplain.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        stbFunctionErrorExplain.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        javax.swing.GroupLayout stbFunctionErrorLayout = new javax.swing.GroupLayout(stbFunctionError);
        stbFunctionError.setLayout(stbFunctionErrorLayout);
        stbFunctionErrorLayout.setHorizontalGroup(
            stbFunctionErrorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(stbFunctionErrorLayout.createSequentialGroup()
                .addComponent(stbFunction_error, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(6, 6, 6)
                .addComponent(stbFunctionErrorCode, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(6, 6, 6)
                .addComponent(stbFunctionErrorExplain, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        stbFunctionErrorLayout.setVerticalGroup(
            stbFunctionErrorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(stbFunction_error)
            .addComponent(stbFunctionErrorCode, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(stbFunctionErrorExplain, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pgLinearReadWrite.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        pgLinearReadWrite.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N

        tabLinearRead.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        lblReadData.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblReadData.setText("Read Data");
        tabLinearRead.add(lblReadData, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 11, -1, -1));

        lblLRLinearAddress.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblLRLinearAddress.setText("Linear Address");
        tabLinearRead.add(lblLRLinearAddress, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 158, -1, -1));

        txtLRLinearAddress.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
        txtLRLinearAddress.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtLRLinearAddress.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        tabLinearRead.add(txtLRLinearAddress, new org.netbeans.lib.awtextra.AbsoluteConstraints(105, 155, 41, 21));

        lblLRDataLength.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblLRDataLength.setText("Data Length");
        tabLinearRead.add(lblLRDataLength, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 185, -1, -1));

        txtLRDataLength.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
        txtLRDataLength.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtLRDataLength.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        tabLinearRead.add(txtLRDataLength, new org.netbeans.lib.awtextra.AbsoluteConstraints(105, 182, 41, 21));

        lblBytesRead.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblBytesRead.setText("Bytes Read");
        tabLinearRead.add(lblBytesRead, new org.netbeans.lib.awtextra.AbsoluteConstraints(176, 172, -1, -1));

        txtBytesRead.setBackground(new java.awt.Color(204, 204, 204));
        txtBytesRead.setEditable(false);
        txtBytesRead.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
        txtBytesRead.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtBytesRead.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        tabLinearRead.add(txtBytesRead, new org.netbeans.lib.awtextra.AbsoluteConstraints(251, 166, 44, 28));

        txtLinearRead.setEditable(false);
        txtLinearRead.setColumns(20);
        txtLinearRead.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        txtLinearRead.setLineWrap(true);
        txtLinearRead.setRows(5);
        txtLinearRead.setWrapStyleWord(true);
        txtLinearRead.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jScrollPane1.setViewportView(txtLinearRead);

        tabLinearRead.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 32, 510, 113));

        btnLinearRead.setText("LINEAR READ");
        btnLinearRead.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLinearReadActionPerformed(evt);
            }
        });
        tabLinearRead.add(btnLinearRead, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 160, 170, 40));

        pgLinearReadWrite.addTab("Linear Read", tabLinearRead);

        lblWriteData.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblWriteData.setText("Write Data");

        txtWriteData.setColumns(20);
        txtWriteData.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        txtWriteData.setLineWrap(true);
        txtWriteData.setRows(5);
        txtWriteData.setWrapStyleWord(true);
        txtWriteData.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jScrollPane2.setViewportView(txtWriteData);

        lblLWLinearAddress.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblLWLinearAddress.setText("Linear Address");

        txtLWLinearAddress.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
        txtLWLinearAddress.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtLWLinearAddress.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        lblLWDataLength.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblLWDataLength.setText("Data Length");

        txtLWDataLength.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
        txtLWDataLength.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtLWDataLength.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        lblBytesWritten.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblBytesWritten.setText("Bytes Written");

        txtBytesWritten.setEditable(false);
        txtBytesWritten.setBackground(new java.awt.Color(204, 204, 204));
        txtBytesWritten.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
        txtBytesWritten.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtBytesWritten.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        btnLinearWrite.setText("LINEAR WRITE");
        btnLinearWrite.setPreferredSize(new java.awt.Dimension(99, 23));
        btnLinearWrite.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLinearWriteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout tabLinearWriteLayout = new javax.swing.GroupLayout(tabLinearWrite);
        tabLinearWrite.setLayout(tabLinearWriteLayout);
        tabLinearWriteLayout.setHorizontalGroup(
            tabLinearWriteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabLinearWriteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabLinearWriteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2)
                    .addGroup(tabLinearWriteLayout.createSequentialGroup()
                        .addComponent(lblWriteData)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(tabLinearWriteLayout.createSequentialGroup()
                        .addGroup(tabLinearWriteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblLWLinearAddress)
                            .addComponent(lblLWDataLength))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(tabLinearWriteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtLWDataLength)
                            .addComponent(txtLWLinearAddress, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
                        .addComponent(lblBytesWritten)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtBytesWritten, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(41, 41, 41)
                        .addComponent(btnLinearWrite, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        tabLinearWriteLayout.setVerticalGroup(
            tabLinearWriteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabLinearWriteLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblWriteData)
                .addGroup(tabLinearWriteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tabLinearWriteLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(tabLinearWriteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblLWLinearAddress)
                            .addComponent(txtLWLinearAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(tabLinearWriteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblLWDataLength)
                            .addComponent(txtLWDataLength, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(26, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, tabLinearWriteLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(tabLinearWriteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblBytesWritten)
                            .addComponent(txtBytesWritten, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnLinearWrite, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(25, 25, 25))))
        );

        pgLinearReadWrite.addTab("Linear Write", tabLinearWrite);

        mnuMeni.setBackground(new java.awt.Color(255, 255, 255));
        mnuMeni.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        mnuMeni.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        mnuMeni.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N

        mnuFileItem.setText("File");
        mnuFileItem.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N

        mnuExitItems.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        mnuExitItems.setBackground(new java.awt.Color(255, 255, 255));
        mnuExitItems.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        mnuExitItems.setText("Exit");
        mnuExitItems.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        mnuExitItems.setFocusable(true);
        mnuExitItems.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuExitItemsActionPerformed(evt);
            }
        });
        mnuFileItem.add(mnuExitItems);

        mnuMeni.add(mnuFileItem);

        setJMenuBar(mnuMeni);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlAUTH1AB, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(pnlFormat, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(pgLinearReadWrite, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
            .addComponent(pnlReader, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(stbFunctionError, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(stbCardStatusPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(pnlReader, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlAUTH1AB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlFormat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(pgLinearReadWrite, javax.swing.GroupLayout.PREFERRED_SIZE, 255, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(stbFunctionError, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(stbCardStatusPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        getAccessibleContext().setAccessibleName("uFRSimple");

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

      public void CreateKey(int iKeyX,int iKeyY,int iKeyHeight,int iKeyWidth,String sKeyName,JPanel pnlContainer)
  {
      JTextField txtTextField;
      for(int br=0;br<6;br++)
      {
          txtTextField=new JTextField();
          txtTextField.setBounds(iKeyX+(iKeyWidth*br+2),iKeyY, 30, 21);
          txtTextField.setBorder(javax.swing.BorderFactory.createLineBorder(Color.BLACK));
          txtTextField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
          txtTextField.setFont(new java.awt.Font("Verdana",1,11));
          txtTextField.setName(sKeyName);
          txtTextField.addKeyListener(this);
          txtTextField.addFocusListener(this);       
          txtTextField.setText("");         
          txtTextField.setVisible(true);
          pnlContainer.add(txtTextField);          
      }
          pnlContainer.repaint();
  }

    
    public void keyTyped(KeyEvent e) {      
       boolean bPattern=false;
       TB=(JTextField)e.getSource();
       
       try 
         {
            if ((chkNewCardKeys.isSelected() && TB.getName()==NEW_CARD_KEY_A) ||
                (chkNewCardKeys.isSelected() && TB.getName()==NEW_CARD_KEY_B ) ||
                 chkNewReaderKey.isSelected() && TB.getName()==NEW_READER_KEY)  {
             
                if (TB.getText().length() > 1) {
                    e.consume();
                } else {
                    bPattern = Pattern.matches("[a-fA-F_0-9]", String.valueOf(e.getKeyChar()));
                    if (!bPattern) {
                        e.consume();
                    }
                }
            }
           else {                
               if (TB.getText().length() > 2) {
                   e.consume();
               } else {
                   bPattern = Pattern.matches("[0-9]", String.valueOf(e.getKeyChar()));
                   if (!bPattern) {
                       e.consume();
                   }
               }
           }
       }catch(NumberFormatException NFE){
           
       } 
    }

    public void keyPressed(KeyEvent e) {
       
    }

    public void keyReleased(KeyEvent e) {
        
    }

    public void focusGained(FocusEvent e) {
        
    }

    public void focusLost(FocusEvent e) {
       TB=(JTextField)e.getSource();
       if (TB.getText().trim().isEmpty()) return;
       
       if (Short.parseShort(TB.getText().trim(),10)>255){
           TB.requestFocus();
           TB.selectAll();
           JOptionPane.showMessageDialog(rootPane,"You must enter a number between 0 and 255 !");                      
       }
    }

    /**
     *  MainThread for loop
     */

    private void MainThread() {
        boThreadStart = true;
        if (!boCONN) {
            if ((iResult = UFRSimpleDeclaration.UFRSimpleFunction.uFrINSTANCE.ReaderOpen()) == DL_OK) {
                stbConnection.setText("CONNECTED");
                new GLFunctions().ERRORS_CODE(iResult, stbReaderCode, stbReaderExplain);
                boCONN = true;
            } else {
                stbConnection.setText("NOT CONNECTED");
                txtReaderType.setText(null);
                txtReaderSerial.setText(null);
                txtCardType.setText(null);
                txtCardSerial.setText(null);
                new GLFunctions().ERRORS_CODE(iResult, stbReaderCode, stbReaderExplain);

            }
        }
        if (boCONN) {
            if ((iResult = UFRSimpleDeclaration.UFRSimpleFunction.uFrINSTANCE.GetReaderType(iReaderType)) == DL_OK) {
                txtReaderType.setText("0x" + Integer.toHexString(iReaderType[0]).toUpperCase());
            } 
            else {
                UFRSimpleDeclaration.UFRSimpleFunction.uFrINSTANCE.ReaderClose();
                boCONN = false;
            }
            
            if ((iResult = UFRSimpleDeclaration.UFRSimpleFunction.uFrINSTANCE.GetReaderSerialNumber(iReaderSerial)) == DL_OK) {
                txtReaderSerial.setText("0x" + Integer.toHexString(iReaderSerial[0]).toUpperCase());
                new GLFunctions().ERRORS_CODE(iResult, stbReaderCode, stbReaderExplain);
            }

            if ((iResult = UFRSimpleDeclaration.UFRSimpleFunction.uFrINSTANCE.GetCardId(iCardId, iCardSerial)) == DL_OK) {
                txtCardType.setText("0x" + Integer.toHexString(iCardId[0]));
                txtCardSerial.setText("0x" + Integer.toHexString(iCardSerial[0]).toUpperCase());
                new GLFunctions().ERRORS_CODE(iResult, stbCard_Code, stbCard_Explain);
            } else {
                txtCardType.setText(null);
                txtCardSerial.setText(null);
                new GLFunctions().ERRORS_CODE(iResult, stbCard_Code, stbCard_Explain);
            }
        }
        boThreadStart = false;
    }

    class ThreadMain implements Runnable {
        @Override
        public void run() {
            try {
                while (true) {
                    if (!boReaderStop) {
                        MainThread();
                    }
                    TimeUnit.MILLISECONDS.sleep(300);
                }
            } catch (InterruptedException ex) {
                
            }
        }
    }

    private void mnuExitItemsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuExitItemsActionPerformed
        exec.shutdown();
        System.exit(0);
    }//GEN-LAST:event_mnuExitItemsActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
      
        CreateKey(88, 11, 31, 29, NEW_CARD_KEY_A, pnlNewCardKeys);
        CreateKey(88, 37, 31, 29, NEW_CARD_KEY_B, pnlNewCardKeys);  
        CreateKey(88, 15, 31, 29, NEW_READER_KEY, pnlNewReaderKey);
        bKeyIndex=Byte.parseByte(txtKeyIndex.getText(),10);
        exec.execute(new ThreadMain());
    }//GEN-LAST:event_formWindowOpened

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        exec.shutdown();
        System.exit(0);
    }//GEN-LAST:event_formWindowClosing

    private void btnReaderUISignalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReaderUISignalActionPerformed
         if (boFunctionOn) {
            return;
        }
        boFunctionOn=true;
        ReaderOff();
        if (boThreadStart){
           ReaderOn();
           boFunctionOn=false;
           return;
        }
        
        
        try {
            iResult=UFRSimpleDeclaration.UFRSimpleFunction.uFrINSTANCE.ReaderUISignal(cboLightMode.getSelectedIndex(),cboSoundMode.getSelectedIndex());
            new GLFunctions().ERRORS_CODE(iResult, stbFunctionErrorCode, stbFunctionErrorExplain);
            
        }finally{
             
           ReaderOn();
           boFunctionOn=false;
        }
    }//GEN-LAST:event_btnReaderUISignalActionPerformed

    private void btnFormatCardKeysActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFormatCardKeysActionPerformed
        if (boFunctionOn) {
            return;
        }
        boFunctionOn=true;
        ReaderOff();
        if (boThreadStart){
           ReaderOn();
           boFunctionOn=false;
           return;
        }
        byte bAuthMode = 0,                 
             bBlockAccessBits = 0,
             bSectorAccessBits = 1,
             bSectorTrailersByte9 = 45;
        
        
        ByteByReference bSectorsFormatted = new ByteByReference();       
        byte[]baKeyA=new byte[5];
        byte[]baKeyB=new byte[5];
        
        try {
             bAuthMode=(byte)(rbAUTH1A.isSelected() ? AUTH1A :AUTH1B) ;
             baKeyA=new GLFunctions().DecHexConversionForKey(pnlNewCardKeys, NEW_CARD_KEY_A, chkNewCardKeys);
             baKeyB=new GLFunctions().DecHexConversionForKey(pnlNewCardKeys, NEW_CARD_KEY_B, chkNewCardKeys);
             
             iResult=UFRSimpleDeclaration.UFRSimpleFunction.uFrINSTANCE.LinearFormatCard(baKeyA, 
                                                                                         bBlockAccessBits,
                                                                                         bSectorAccessBits,
                                                                                         bSectorTrailersByte9,
                                                                                         baKeyB, bSectorsFormatted, bAuthMode, bKeyIndex);
             if (iResult==DL_OK){
                UFRSimpleDeclaration.UFRSimpleFunction.uFrINSTANCE.ReaderUISignal(RES_LIGHT_OK, RES_SOUND_OK);
                new GLFunctions().ERRORS_CODE(iResult, stbFunctionErrorCode, stbFunctionErrorExplain);
                txtSectorsFormatted.setText(Byte.toString(bSectorsFormatted.getValue()));
                JOptionPane.showMessageDialog(rootPane,"Card keys are formatted successfully !","Information" ,JOptionPane.INFORMATION_MESSAGE);
             }
             else
             {
                UFRSimpleDeclaration.UFRSimpleFunction.uFrINSTANCE.ReaderUISignal(ERR_LIGHT, ERR_SOUND);
                new GLFunctions().ERRORS_CODE(iResult, stbFunctionErrorCode, stbFunctionErrorExplain);
                txtSectorsFormatted.setText(Byte.toString(bSectorsFormatted.getValue()));
                JOptionPane.showMessageDialog(rootPane,"Card keys are not formatted successfully !","Error" ,JOptionPane.ERROR_MESSAGE); 
             }
             
                 
             
        }catch(NumberFormatException ex)
        {
            JOptionPane.showMessageDialog(rootPane,APPROPRIATE_FORMAT,"Error" ,JOptionPane.ERROR_MESSAGE);
        }
        finally{             
           ReaderOn();
           boFunctionOn=false;
        }
    }//GEN-LAST:event_btnFormatCardKeysActionPerformed

    private void chkNewCardKeysItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkNewCardKeysItemStateChanged
       new GLFunctions().CheckBoxHexDec(pnlNewCardKeys,NEW_CARD_KEY_A, evt);
       new GLFunctions().CheckBoxHexDec(pnlNewCardKeys,NEW_CARD_KEY_B, evt);
    }//GEN-LAST:event_chkNewCardKeysItemStateChanged

    private void chkNewReaderKeyItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkNewReaderKeyItemStateChanged
        new GLFunctions().CheckBoxHexDec(pnlNewReaderKey,NEW_READER_KEY, evt);
    }//GEN-LAST:event_chkNewReaderKeyItemStateChanged

    private void btnFormatReaderKeyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFormatReaderKeyActionPerformed
                       
        if (boFunctionOn) return;
            boFunctionOn=true;
            ReaderOff();
        if (boThreadStart){
           ReaderOn();
           boFunctionOn=false;
           return;
        }
           byte[]baReaderKey=new byte[6];
           try
           {
             baReaderKey=new GLFunctions().DecHexConversionForKey(pnlNewReaderKey,NEW_READER_KEY, chkNewReaderKey);  
             iResult=UFRSimpleDeclaration.UFRSimpleFunction.uFrINSTANCE.ReaderKeyWrite(baReaderKey, bKeyIndex);
             if (iResult==DL_OK){
                UFRSimpleDeclaration.UFRSimpleFunction.uFrINSTANCE.ReaderUISignal(RES_LIGHT_OK, RES_SOUND_OK);
                new GLFunctions().ERRORS_CODE(iResult, stbFunctionErrorCode, stbFunctionErrorExplain);               
                JOptionPane.showMessageDialog(rootPane,"Reader key is formatted successfully !","Information" ,JOptionPane.INFORMATION_MESSAGE);
             }
             else
             {
                UFRSimpleDeclaration.UFRSimpleFunction.uFrINSTANCE.ReaderUISignal(ERR_LIGHT, ERR_SOUND);
                new GLFunctions().ERRORS_CODE(iResult, stbFunctionErrorCode, stbFunctionErrorExplain);               
                JOptionPane.showMessageDialog(rootPane,"Reader key is not formatted successfully !","Error" ,JOptionPane.ERROR_MESSAGE); 
             }
             
           }catch(NumberFormatException ex)
        {
            JOptionPane.showMessageDialog(rootPane,APPROPRIATE_FORMAT,"Error" ,JOptionPane.ERROR_MESSAGE);
        }finally{
              ReaderOn();
              boFunctionOn=false; 
           }
        
    }//GEN-LAST:event_btnFormatReaderKeyActionPerformed

    private void btnLinearReadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLinearReadActionPerformed
          if (boFunctionOn) {
            return;
        }
        boFunctionOn=true;
        ReaderOff();
        if (boThreadStart){
           ReaderOn();
           boFunctionOn=false;
           return;
        }
        
        byte bAuthMode=0;
        short shLinearAddress = 0,
              shDataLength = 0;
         ShortByReference shBytesRet = new ShortByReference();
        
        GLFunctions GL = new GLFunctions();
        byte[] baReadData = new byte[LINEAR_MAX_BYTES];
        try {
            if (txtLRLinearAddress.getText().trim().isEmpty()) {
                JOptionPane.showMessageDialog(rootPane, "You must enter LINEAR ADDRESS", "Warning", JOptionPane.WARNING_MESSAGE);
                txtLRLinearAddress.requestFocus();
                return;
            }
            if (txtLRDataLength.getText().trim().isEmpty()) {
                JOptionPane.showMessageDialog(rootPane, "You must enter DATA LENGTH", "Warning", JOptionPane.WARNING_MESSAGE);
                txtLRDataLength.requestFocus();
                return;
            }
            bAuthMode=(byte)(rbAUTH1A.isSelected() ? AUTH1A : AUTH1B);            
            shLinearAddress = Short.parseShort(txtLRLinearAddress.getText());
            shDataLength = Short.parseShort(txtLRDataLength.getText());
            txtBytesRead.setText("");
            iResult = UFRSimpleDeclaration.UFRSimpleFunction.uFrINSTANCE.LinearRead(baReadData, shLinearAddress, shDataLength, shBytesRet, bAuthMode, bKeyIndex);
            if (iResult == DL_OK) {               
                txtLinearRead.setText(new String(baReadData, 0, shDataLength));
                txtBytesRead.setText(Short.toString(shBytesRet.getValue()));
                UFRSimpleDeclaration.UFRSimpleFunction.uFrINSTANCE.ReaderUISignal(RES_LIGHT_OK, RES_SOUND_OK);
                new GLFunctions().ERRORS_CODE(iResult, stbFunctionErrorCode, stbFunctionErrorExplain);
            } else {
                txtLinearRead.setText(new String(baReadData, 0, shBytesRet.getValue()));
                txtBytesRead.setText(Short.toString(shBytesRet.getValue()));
                UFRSimpleDeclaration.UFRSimpleFunction.uFrINSTANCE.ReaderUISignal(ERR_LIGHT, ERR_SOUND);
                new GLFunctions().ERRORS_CODE(iResult, stbFunctionErrorCode, stbFunctionErrorExplain);
            }
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(rootPane, APPROPRIATE_FORMAT, "Error !", JOptionPane.ERROR_MESSAGE);
        }finally{
           GL = null;
           ReaderOn();
           boFunctionOn=false;
        }
    }//GEN-LAST:event_btnLinearReadActionPerformed

    private void btnLinearWriteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLinearWriteActionPerformed
        if (boFunctionOn) {
            return;
        }
        boFunctionOn=true;
        ReaderOff();
        if (boThreadStart){
            ReaderOn();
            boFunctionOn=false;
            return;
        }
        GLFunctions GL = new GLFunctions();

        byte bAuthMode=0;
        short shLinearAddress = 0,
        shDataLength = 0;
        ShortByReference shBytesRet = new ShortByReference();
        byte[] baWriteData = new byte[LINEAR_MAX_BYTES];
        byte[] bConcArray=new byte[LINEAR_MAX_BYTES];

        try {
            if (txtWriteData.getText().trim().isEmpty()) {
                JOptionPane.showMessageDialog(rootPane, ANY_DATA, "Warning", JOptionPane.WARNING_MESSAGE);
                txtWriteData.requestFocus();
                return;
            }
            if (txtLWLinearAddress.getText().trim().isEmpty()) {
                JOptionPane.showMessageDialog(rootPane, "You must enter LINEAR ADDRESS", "Warning", JOptionPane.WARNING_MESSAGE);
                txtLWLinearAddress.requestFocus();
                return;
            }
            if (txtLWDataLength.getText().trim().isEmpty()) {
                JOptionPane.showMessageDialog(rootPane, "You must enter DATA LENGTH", "Warning", JOptionPane.WARNING_MESSAGE);
                txtLWDataLength.requestFocus();
                return;
            }
            shDataLength = Short.parseShort(txtLWDataLength.getText());
            bAuthMode=(byte)(rbAUTH1A.isSelected() ? AUTH1A : AUTH1B );
            shLinearAddress = Short.parseShort(txtLWLinearAddress.getText());

            baWriteData = txtWriteData.getText().getBytes();

            txtBytesWritten.setText("");
            iResult = UFRSimpleDeclaration.UFRSimpleFunction.uFrINSTANCE.LinearWrite(new GLFunctions().WriteArray(baWriteData, shDataLength, LINEAR_MAX_BYTES), shLinearAddress, shDataLength, shBytesRet, bAuthMode,bKeyIndex);

            if (iResult == DL_OK) {
                txtBytesWritten.setText(Short.toString(shBytesRet.getValue()));
                UFRSimpleDeclaration.UFRSimpleFunction.uFrINSTANCE.ReaderUISignal(RES_LIGHT_OK, RES_SOUND_OK);
                new GLFunctions().ERRORS_CODE(iResult, stbFunctionErrorCode, stbFunctionErrorExplain);
            } else {
                txtBytesWritten.setText(Short.toString(shBytesRet.getValue()));
                UFRSimpleDeclaration.UFRSimpleFunction.uFrINSTANCE.ReaderUISignal(ERR_LIGHT, ERR_SOUND);
                new GLFunctions().ERRORS_CODE(iResult, stbFunctionErrorCode, stbFunctionErrorExplain);
            }
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(rootPane, APPROPRIATE_FORMAT, "Error !", JOptionPane.ERROR_MESSAGE);
        }finally{
            GL = null;
            ReaderOn();
            boFunctionOn=false;
        }
    }//GEN-LAST:event_btnLinearWriteActionPerformed

    public static void main(String args[]) {
         try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(UFRSimple.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(UFRSimple.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(UFRSimple.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(UFRSimple.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                UFRSimple US = new UFRSimple();
                US.setLocationRelativeTo(null);
                US.setVisible(true);

            }
        });
    }
    
    
    
    
    
    
    
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnFormatCardKeys;
    private javax.swing.JButton btnFormatReaderKey;
    private javax.swing.JButton btnLinearRead;
    private javax.swing.JButton btnLinearWrite;
    private javax.swing.JButton btnReaderUISignal;
    private javax.swing.ButtonGroup btngAUTH1AB;
    private javax.swing.JComboBox cboLightMode;
    private javax.swing.JComboBox cboSoundMode;
    private javax.swing.JCheckBox chkNewCardKeys;
    private javax.swing.JCheckBox chkNewReaderKey;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblBytesRead;
    private javax.swing.JLabel lblBytesWritten;
    private javax.swing.JLabel lblCardType;
    private javax.swing.JLabel lblKeyA;
    private javax.swing.JLabel lblKeyB;
    private javax.swing.JLabel lblKeyIndex;
    private javax.swing.JLabel lblLRDataLength;
    private javax.swing.JLabel lblLRLinearAddress;
    private javax.swing.JLabel lblLWDataLength;
    private javax.swing.JLabel lblLWLinearAddress;
    private javax.swing.JLabel lblLightMode;
    private javax.swing.JLabel lblReadData;
    private javax.swing.JLabel lblReaderSerial;
    private javax.swing.JLabel lblReaderType;
    private javax.swing.JLabel lblReaderType3;
    private javax.swing.JLabel lblSectorsFormatted;
    private javax.swing.JLabel lblSoundMode;
    private javax.swing.JLabel lblWriteData;
    private javax.swing.JMenuItem mnuExitItems;
    private javax.swing.JMenu mnuFileItem;
    private javax.swing.JMenuBar mnuMeni;
    private javax.swing.JTabbedPane pgCardReaderKeys;
    private javax.swing.JTabbedPane pgLinearReadWrite;
    private javax.swing.JPanel pnlAUTH1AB;
    private javax.swing.JPanel pnlFormat;
    private javax.swing.JPanel pnlNewCardKeys;
    private javax.swing.JPanel pnlNewReaderKey;
    private javax.swing.JPanel pnlReader;
    private javax.swing.JPanel pnlSep1;
    private javax.swing.JRadioButton rbAUTH1A;
    private javax.swing.JRadioButton rbAUTH1B;
    private javax.swing.JLabel stbCardStatus;
    private javax.swing.JPanel stbCardStatusPanel;
    private javax.swing.JLabel stbCard_Code;
    private javax.swing.JLabel stbCard_Explain;
    private javax.swing.JLabel stbConnection;
    private javax.swing.JPanel stbFunctionError;
    private javax.swing.JLabel stbFunctionErrorCode;
    private javax.swing.JLabel stbFunctionErrorExplain;
    private javax.swing.JLabel stbFunction_error;
    private javax.swing.JPanel stbReader;
    private javax.swing.JLabel stbReaderCode;
    private javax.swing.JLabel stbReaderExplain;
    private javax.swing.JPanel tabLinearRead;
    private javax.swing.JPanel tabLinearWrite;
    private javax.swing.JTextField txtBytesRead;
    private javax.swing.JTextField txtBytesWritten;
    private javax.swing.JTextField txtCardSerial;
    private javax.swing.JTextField txtCardType;
    private javax.swing.JLabel txtKeyIndex;
    private javax.swing.JTextField txtLRDataLength;
    private javax.swing.JTextField txtLRLinearAddress;
    private javax.swing.JTextField txtLWDataLength;
    private javax.swing.JTextField txtLWLinearAddress;
    private javax.swing.JTextArea txtLinearRead;
    private javax.swing.JTextField txtReaderSerial;
    private javax.swing.JTextField txtReaderType;
    private javax.swing.JTextField txtSectorsFormatted;
    private javax.swing.JTextArea txtWriteData;
    // End of variables declaration//GEN-END:variables
}
