/**
 * @author Vladan S ,'D-Logic'
 * @version uFCoderAdvance 2.1
 */
package ufradvanced;

import com.sun.jna.ptr.ByteByReference;
import com.sun.jna.ptr.IntByReference;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import java.util.concurrent.*;

public class frmMain extends javax.swing.JFrame {

    static final int FUNCT_LIGHT_OK = 4,
            FUNCT_SOUND_OK = 0,//4 Tripple sound
            FUNCT_LIGHT_ERROR = 2,
            FUNCT_SOUND_ERROR = 0,//2 Long sound
            DL_OK = 0,
            SLEEP_VALUE = 500;

    boolean boCONN = false;
    ByteByReference bDLCardType = new ByteByReference();
    ByteByReference bCardType = new ByteByReference();
    ByteByReference bCardUIDSize = new ByteByReference();
    IntByReference iCardSerial = new IntByReference();

    int[] iaReaderType = new int[1];
    int[] iaReaderSerial = new int[3];
    byte[] baCardUID = new byte[9];
    byte[] baReadUserData = new byte[15];
    int iRResult, iCResult;
    public  static int bTypeOfCard;

    ExecutorService exec = Executors.newCachedThreadPool();

    static String[] iaErrorCodes = new String[200];

    static boolean bFunctionStart;
    static boolean bLoopStart;

    Declarations.DLCARDTYPE DCT;

    Declarations.ERRORCODES EC;
    Declarations.ERRORCODES[] ERRCODES = Declarations.ERRORCODES.values();

    private void FillEcArray() {
        for (Declarations.ERRORCODES ECC : EC.values()) {
            iaErrorCodes[ECC.getValue()] = ECC.name();
        }
    }

    public void SetStatusBar(JTextField txtErrorCode, JTextField txtErrorExplain, int iResultValue) {

        txtErrorCode.setText("0x" + Integer.toHexString(iResultValue).toUpperCase());
        txtErrorExplain.setText(iaErrorCodes[iResultValue]);
    }

    public void SetFunct(boolean bValue) {
        bFunctionStart = bValue;
    }

    public boolean GetFunct() {
        return bFunctionStart;
    }

    public frmMain() {
        initComponents();
    }

    public void SetLoop(boolean bValue) {
        bLoopStart = bValue;
    }

    public boolean GetLoop() {
        return bLoopStart;
    }

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

        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();
        lblCardUID = new javax.swing.JLabel();
        txtCardType = new javax.swing.JTextField();
        lblCardSerial = new javax.swing.JLabel();
        txtCardSerial = new javax.swing.JTextField();
        lblLightMode = new javax.swing.JLabel();
        cboLightMode = new javax.swing.JComboBox();
        lblSoundMode = new javax.swing.JLabel();
        cboSoundMode = new javax.swing.JComboBox();
        btnReaderUISignal = new javax.swing.JButton();
        btnSoftRestart = new javax.swing.JButton();
        btnReaderReset = new javax.swing.JButton();
        jtabKeysUserData1 = new javax.swing.JTabbedPane();
        pnlReaderKey = new javax.swing.JPanel();
        chkHex = new javax.swing.JCheckBox();
        lblKeyIndex = new javax.swing.JLabel();
        cboKeyIndex = new javax.swing.JComboBox();
        btnReaderSaveKey = new javax.swing.JButton();
        jpnlUserData1 = new javax.swing.JPanel();
        lblUserData5 = new javax.swing.JLabel();
        txtReadUserData = new javax.swing.JTextField();
        lblNewUserData2 = new javax.swing.JLabel();
        txtNewUserData = new javax.swing.JTextField();
        btnSaveUserData = new javax.swing.JButton();
        txtRErrorExplain = new javax.swing.JTextField();
        txtConnected = new javax.swing.JTextField();
        txtRErrorCode = new javax.swing.JTextField();
        lblCardType = new javax.swing.JLabel();
        txtCardUIDSize = new javax.swing.JTextField();
        pnlDesktop = new javax.swing.JDesktopPane();
        lblHeader = new javax.swing.JLabel();
        txtCardStatus = new javax.swing.JTextField();
        txtCErrorCode = new javax.swing.JTextField();
        txtCErrorExplain = new javax.swing.JTextField();
        mnuMeni = new javax.swing.JMenuBar();
        mnuFunctionsItem = new javax.swing.JMenu();
        mnuLinearReadWriteItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        mnuBlockReadWriteItems = new javax.swing.JMenuItem();
        mnuBlockInSectorReadWriteItem = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JPopupMenu.Separator();
        mnuValueBlockReadWriteItems = new javax.swing.JMenuItem();
        mnuValueBlockIncrDecrItems = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JPopupMenu.Separator();
        mnuValueBlockInSectorReadWriteItems = new javax.swing.JMenuItem();
        mnuValueBlockInSectorIncrDecrItems = new javax.swing.JMenuItem();
        jSeparator4 = new javax.swing.JPopupMenu.Separator();
        mnuSectorTrailerWriteItems = new javax.swing.JMenuItem();
        mnuLinearFormatCardItems = new javax.swing.JMenuItem();
        jSeparator5 = new javax.swing.JPopupMenu.Separator();
        mnuReaderHardwareFirmwareVersionItem = new javax.swing.JMenuItem();
        jSeparator7 = new javax.swing.JPopupMenu.Separator();
        mnuViewAllItems = new javax.swing.JMenuItem();
        jSeparator6 = new javax.swing.JPopupMenu.Separator();
        mnuExitItems = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("uFr Advanced");
        setFont(new java.awt.Font("Verdana", 0, 10)); // NOI18N
        setLocationByPlatform(true);
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        pnlReader.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        pnlReader.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        lblReaderType.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblReaderType.setText("Reader Type");
        pnlReader.add(lblReaderType, new org.netbeans.lib.awtextra.AbsoluteConstraints(21, 13, 86, -1));

        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)));
        pnlReader.add(txtReaderType, new org.netbeans.lib.awtextra.AbsoluteConstraints(117, 11, 120, 19));

        lblReaderSerial.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblReaderSerial.setText("Reader Serial");
        pnlReader.add(lblReaderSerial, new org.netbeans.lib.awtextra.AbsoluteConstraints(21, 38, 86, -1));

        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)));
        pnlReader.add(txtReaderSerial, new org.netbeans.lib.awtextra.AbsoluteConstraints(117, 36, 120, 19));

        lblCardUID.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblCardUID.setText("UID Size");
        pnlReader.add(lblCardUID, new org.netbeans.lib.awtextra.AbsoluteConstraints(450, 13, -1, -1));

        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)));
        pnlReader.add(txtCardType, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 11, 40, 19));

        lblCardSerial.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblCardSerial.setText("Card Serial");
        pnlReader.add(lblCardSerial, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 38, -1, -1));

        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)));
        pnlReader.add(txtCardSerial, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 36, 150, 19));

        lblLightMode.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblLightMode.setText("Light Mode");
        pnlReader.add(lblLightMode, new org.netbeans.lib.awtextra.AbsoluteConstraints(21, 72, 132, -1));

        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.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        pnlReader.add(cboLightMode, new org.netbeans.lib.awtextra.AbsoluteConstraints(117, 68, 118, -1));

        lblSoundMode.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblSoundMode.setText("Sound Mode");
        pnlReader.add(lblSoundMode, new org.netbeans.lib.awtextra.AbsoluteConstraints(21, 99, 132, -1));

        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.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        pnlReader.add(cboSoundMode, new org.netbeans.lib.awtextra.AbsoluteConstraints(117, 95, 118, -1));

        btnReaderUISignal.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnReaderUISignal.setText("Reader UI Signal");
        btnReaderUISignal.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnReaderUISignal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReaderUISignalActionPerformed(evt);
            }
        });
        pnlReader.add(btnReaderUISignal, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 70, -1, 44));

        btnSoftRestart.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnSoftRestart.setText("Soft Restart");
        btnSoftRestart.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnSoftRestart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSoftRestartActionPerformed(evt);
            }
        });
        pnlReader.add(btnSoftRestart, new org.netbeans.lib.awtextra.AbsoluteConstraints(416, 68, 139, 25));

        btnReaderReset.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnReaderReset.setText("Reader Reset");
        btnReaderReset.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnReaderReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReaderResetActionPerformed(evt);
            }
        });
        pnlReader.add(btnReaderReset, new org.netbeans.lib.awtextra.AbsoluteConstraints(416, 99, 139, -1));

        jtabKeysUserData1.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        jtabKeysUserData1.setInheritsPopupMenu(true);

        chkHex.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        chkHex.setText("Hex");
        chkHex.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        chkHex.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                chkHexItemStateChanged(evt);
            }
        });

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

        cboKeyIndex.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        cboKeyIndex.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", " " }));
        cboKeyIndex.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        cboKeyIndex.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

        btnReaderSaveKey.setText("SAVE KEY");
        btnReaderSaveKey.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnReaderSaveKey.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReaderSaveKeyActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlReaderKeyLayout = new javax.swing.GroupLayout(pnlReaderKey);
        pnlReaderKey.setLayout(pnlReaderKeyLayout);
        pnlReaderKeyLayout.setHorizontalGroup(
            pnlReaderKeyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlReaderKeyLayout.createSequentialGroup()
                .addGroup(pnlReaderKeyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlReaderKeyLayout.createSequentialGroup()
                        .addGap(225, 225, 225)
                        .addComponent(lblKeyIndex)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cboKeyIndex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnlReaderKeyLayout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addComponent(chkHex)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, Short.MAX_VALUE)
                .addComponent(btnReaderSaveKey, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27))
        );
        pnlReaderKeyLayout.setVerticalGroup(
            pnlReaderKeyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlReaderKeyLayout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addGroup(pnlReaderKeyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(chkHex)
                    .addGroup(pnlReaderKeyLayout.createSequentialGroup()
                        .addGroup(pnlReaderKeyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cboKeyIndex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblKeyIndex)
                            .addComponent(btnReaderSaveKey, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jtabKeysUserData1.addTab("Reader Key", pnlReaderKey);

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

        txtReadUserData.setEditable(false);
        txtReadUserData.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtReadUserData.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        lblNewUserData2.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblNewUserData2.setText("New User Data");

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

        btnSaveUserData.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnSaveUserData.setText("Save User Data");
        btnSaveUserData.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnSaveUserData.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveUserDataActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpnlUserData1Layout = new javax.swing.GroupLayout(jpnlUserData1);
        jpnlUserData1.setLayout(jpnlUserData1Layout);
        jpnlUserData1Layout.setHorizontalGroup(
            jpnlUserData1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnlUserData1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpnlUserData1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblUserData5, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtReadUserData, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(13, 13, 13)
                .addGroup(jpnlUserData1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpnlUserData1Layout.createSequentialGroup()
                        .addComponent(txtNewUserData, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnSaveUserData, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(lblNewUserData2))
                .addContainerGap(13, Short.MAX_VALUE))
        );
        jpnlUserData1Layout.setVerticalGroup(
            jpnlUserData1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnlUserData1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpnlUserData1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblUserData5)
                    .addComponent(lblNewUserData2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpnlUserData1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtNewUserData, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtReadUserData, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnSaveUserData))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        jtabKeysUserData1.addTab("User Data", jpnlUserData1);

        pnlReader.add(jtabKeysUserData1, new org.netbeans.lib.awtextra.AbsoluteConstraints(25, 128, -1, 98));

        txtRErrorExplain.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        txtRErrorExplain.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtRErrorExplain.setText(" ");
        pnlReader.add(txtRErrorExplain, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 230, 360, 20));

        txtConnected.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        txtConnected.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtConnected.setText(" ");
        pnlReader.add(txtConnected, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 230, 150, 20));

        txtRErrorCode.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        txtRErrorCode.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtRErrorCode.setText(" ");
        pnlReader.add(txtRErrorCode, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 230, 70, 20));

        lblCardType.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblCardType.setText("Card Type");
        pnlReader.add(lblCardType, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 13, 64, -1));

        txtCardUIDSize.setEditable(false);
        txtCardUIDSize.setBackground(new java.awt.Color(255, 255, 255));
        txtCardUIDSize.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
        txtCardUIDSize.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtCardUIDSize.setToolTipText("");
        txtCardUIDSize.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        pnlReader.add(txtCardUIDSize, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 11, 40, 19));

        getContentPane().add(pnlReader, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 0, 580, 250));

        pnlDesktop.setBackground(new java.awt.Color(204, 204, 204));

        lblHeader.setBackground(new java.awt.Color(255, 255, 255));
        lblHeader.setFont(new java.awt.Font("Verdana", 1, 14)); // NOI18N
        lblHeader.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblHeader.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        lblHeader.setOpaque(true);
        pnlDesktop.add(lblHeader);
        lblHeader.setBounds(0, 0, 592, 30);
        pnlDesktop.setLayer(lblHeader, javax.swing.JLayeredPane.MODAL_LAYER);

        getContentPane().add(pnlDesktop, new org.netbeans.lib.awtextra.AbsoluteConstraints(2, 255, 592, 400));

        txtCardStatus.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        txtCardStatus.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtCardStatus.setText("CARD STATUS");
        getContentPane().add(txtCardStatus, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 660, 150, 20));

        txtCErrorCode.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        txtCErrorCode.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtCErrorCode.setText(" ");
        getContentPane().add(txtCErrorCode, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 660, 70, 20));

        txtCErrorExplain.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        txtCErrorExplain.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtCErrorExplain.setText(" ");
        getContentPane().add(txtCErrorExplain, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 660, 370, 20));

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

        mnuFunctionsItem.setText("Functions");
        mnuFunctionsItem.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        mnuFunctionsItem.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N

        mnuLinearReadWriteItem.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        mnuLinearReadWriteItem.setText("Linear Read/Write");
        mnuLinearReadWriteItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuLinearReadWriteItemActionPerformed(evt);
            }
        });
        mnuFunctionsItem.add(mnuLinearReadWriteItem);
        mnuFunctionsItem.add(jSeparator1);

        mnuBlockReadWriteItems.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        mnuBlockReadWriteItems.setText("Block Read/Write");
        mnuBlockReadWriteItems.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuBlockReadWriteItemsActionPerformed(evt);
            }
        });
        mnuFunctionsItem.add(mnuBlockReadWriteItems);

        mnuBlockInSectorReadWriteItem.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        mnuBlockInSectorReadWriteItem.setText("BlockInSector Read/Write");
        mnuBlockInSectorReadWriteItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuBlockInSectorReadWriteItemActionPerformed(evt);
            }
        });
        mnuFunctionsItem.add(mnuBlockInSectorReadWriteItem);
        mnuFunctionsItem.add(jSeparator2);

        mnuValueBlockReadWriteItems.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        mnuValueBlockReadWriteItems.setText("ValueBlock Read/Write");
        mnuValueBlockReadWriteItems.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuValueBlockReadWriteItemsActionPerformed(evt);
            }
        });
        mnuFunctionsItem.add(mnuValueBlockReadWriteItems);

        mnuValueBlockIncrDecrItems.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        mnuValueBlockIncrDecrItems.setText("ValueBlock Increment/Decrement");
        mnuValueBlockIncrDecrItems.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuValueBlockIncrDecrItemsActionPerformed(evt);
            }
        });
        mnuFunctionsItem.add(mnuValueBlockIncrDecrItems);
        mnuFunctionsItem.add(jSeparator3);

        mnuValueBlockInSectorReadWriteItems.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        mnuValueBlockInSectorReadWriteItems.setText("ValueBlockInSector Read/Write");
        mnuValueBlockInSectorReadWriteItems.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuValueBlockInSectorReadWriteItemsActionPerformed(evt);
            }
        });
        mnuFunctionsItem.add(mnuValueBlockInSectorReadWriteItems);

        mnuValueBlockInSectorIncrDecrItems.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        mnuValueBlockInSectorIncrDecrItems.setText("ValueBlockInSector Increment/Decrement");
        mnuValueBlockInSectorIncrDecrItems.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuValueBlockInSectorIncrDecrItemsActionPerformed(evt);
            }
        });
        mnuFunctionsItem.add(mnuValueBlockInSectorIncrDecrItems);
        mnuFunctionsItem.add(jSeparator4);

        mnuSectorTrailerWriteItems.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        mnuSectorTrailerWriteItems.setText("Sector Trailer Write");
        mnuSectorTrailerWriteItems.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuSectorTrailerWriteItemsActionPerformed(evt);
            }
        });
        mnuFunctionsItem.add(mnuSectorTrailerWriteItems);

        mnuLinearFormatCardItems.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        mnuLinearFormatCardItems.setText("Linear Format Card");
        mnuLinearFormatCardItems.setToolTipText("");
        mnuLinearFormatCardItems.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuLinearFormatCardItemsActionPerformed(evt);
            }
        });
        mnuFunctionsItem.add(mnuLinearFormatCardItems);
        mnuFunctionsItem.add(jSeparator5);

        mnuReaderHardwareFirmwareVersionItem.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        mnuReaderHardwareFirmwareVersionItem.setText("Reader Hardware/Firmware version");
        mnuReaderHardwareFirmwareVersionItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuReaderHardwareFirmwareVersionItemActionPerformed(evt);
            }
        });
        mnuFunctionsItem.add(mnuReaderHardwareFirmwareVersionItem);
        mnuFunctionsItem.add(jSeparator7);

        mnuViewAllItems.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        mnuViewAllItems.setText("View All");
        mnuViewAllItems.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuViewAllItemsActionPerformed(evt);
            }
        });
        mnuFunctionsItem.add(mnuViewAllItems);
        mnuFunctionsItem.add(jSeparator6);

        mnuExitItems.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        mnuExitItems.setFont(new java.awt.Font("Verdana", 0, 12)); // NOI18N
        mnuExitItems.setText("EXIT");
        mnuExitItems.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuExitItemsActionPerformed(evt);
            }
        });
        mnuFunctionsItem.add(mnuExitItems);

        mnuMeni.add(mnuFunctionsItem);

        setJMenuBar(mnuMeni);

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

    private void btnReaderUISignalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReaderUISignalActionPerformed
        if (GetFunct() || GetLoop()) {
            return;
        }
        try {
            SetFunct(true);
            int iFResult = 0;
            iFResult = Declarations.UFrDeclarations.UFRInstance.ReaderUISignal(cboLightMode.getSelectedIndex(), cboSoundMode.getSelectedIndex());
            if (iFResult == DL_OK) {
                Declarations.UFrDeclarations.UFRInstance.ReaderUISignal(FUNCT_LIGHT_OK, FUNCT_SOUND_OK);
            } else {
                Declarations.UFrDeclarations.UFRInstance.ReaderUISignal(FUNCT_LIGHT_ERROR, FUNCT_SOUND_ERROR);
            }
        } finally {
            SetFunct(false);
        }
    }//GEN-LAST:event_btnReaderUISignalActionPerformed

    private void btnSoftRestartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSoftRestartActionPerformed
        if (GetFunct() || GetLoop()) {
            return;
        }
        try {
            SetFunct(true);
            int iFResult = 0;

            iFResult = Declarations.UFrDeclarations.UFRInstance.ReaderSoftRestart();
            if (iFResult == DL_OK) {
                Declarations.UFrDeclarations.UFRInstance.ReaderUISignal(FUNCT_LIGHT_OK, FUNCT_SOUND_OK);
            } else {
                Declarations.UFrDeclarations.UFRInstance.ReaderUISignal(FUNCT_LIGHT_ERROR, FUNCT_SOUND_ERROR);
            }
        } finally {
            SetFunct(false);
        }
    }//GEN-LAST:event_btnSoftRestartActionPerformed

    private void btnReaderResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReaderResetActionPerformed
        if (GetFunct() || GetLoop()) {
            return;
        }
        try {
            SetFunct(true);
            int iFResult = 0;

            iFResult = Declarations.UFrDeclarations.UFRInstance.ReaderReset();
            if (iFResult == DL_OK) {
                Declarations.UFrDeclarations.UFRInstance.ReaderUISignal(FUNCT_LIGHT_OK, FUNCT_SOUND_OK);
            } else {
                Declarations.UFrDeclarations.UFRInstance.ReaderUISignal(FUNCT_LIGHT_ERROR, FUNCT_SOUND_ERROR);
            }
        } finally {
            SetFunct(false);
        }

    }//GEN-LAST:event_btnReaderResetActionPerformed

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated

        //  frmLinearReadWrite LRW=new frmLinearReadWrite();
        //  GL.AddFrame(LRW,pnlDesktop,lblHeader,"Linear Read/Write (AKM1,AKM2,PK)");
        // GL.CreateKey(27, 20, 31, 29, "txtReaderKey", pnlReaderKey);

    }//GEN-LAST:event_formWindowActivated

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

    private void mnuBlockReadWriteItemsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuBlockReadWriteItemsActionPerformed

        frmBlockReadWrite BRW = new frmBlockReadWrite();
        new Global().AddFrame(BRW, pnlDesktop, lblHeader, "Block Read/Write(AKM1,AKM2,PK");
    }//GEN-LAST:event_mnuBlockReadWriteItemsActionPerformed

    private void mnuLinearReadWriteItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuLinearReadWriteItemActionPerformed

        frmLinearReadWrite LRW = new frmLinearReadWrite();
        new Global().AddFrame(LRW, pnlDesktop, lblHeader, "Linear Read/Write (AKM1,AKM2,PK)");
    }//GEN-LAST:event_mnuLinearReadWriteItemActionPerformed

    private void mnuBlockInSectorReadWriteItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuBlockInSectorReadWriteItemActionPerformed
        frmBlockInSectorReadWrite BSRW = new frmBlockInSectorReadWrite();
        new Global().AddFrame(BSRW, pnlDesktop, lblHeader, "BlockInSector Read/Write (AKM1,AKM2,PK)");
    }//GEN-LAST:event_mnuBlockInSectorReadWriteItemActionPerformed

    private void mnuValueBlockReadWriteItemsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuValueBlockReadWriteItemsActionPerformed
        frmValueBlockReadWrite VBRW = new frmValueBlockReadWrite();
        new Global().AddFrame(VBRW, pnlDesktop, lblHeader, "ValueBlock Read/Write (AKM1,AKM2,PK)");
    }//GEN-LAST:event_mnuValueBlockReadWriteItemsActionPerformed

    private void mnuValueBlockIncrDecrItemsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuValueBlockIncrDecrItemsActionPerformed
        frmValueBlockIncrDecr VBID = new frmValueBlockIncrDecr();
        new Global().AddFrame(VBID, pnlDesktop, lblHeader, "ValueBlock Increment/Decrement (AKM1,AKM2,PK)");
    }
//GEN-LAST:event_mnuValueBlockIncrDecrItemsActionPerformed

    private void mnuValueBlockInSectorReadWriteItemsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuValueBlockInSectorReadWriteItemsActionPerformed
        frmValueBlockInSectorReadWrite VBSRW = new frmValueBlockInSectorReadWrite();
        new Global().AddFrame(VBSRW, pnlDesktop, lblHeader, "ValueBlockInSector Read/Write (AKM1,AKM2,PK)");
    }//GEN-LAST:event_mnuValueBlockInSectorReadWriteItemsActionPerformed

    private void mnuValueBlockInSectorIncrDecrItemsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuValueBlockInSectorIncrDecrItemsActionPerformed
        frmValueBlockInSectorIncrDecr VBSID = new frmValueBlockInSectorIncrDecr();
        new Global().AddFrame(VBSID, pnlDesktop, lblHeader, "ValueBlockInSector Increment/Decrement (AKM1,AKM2,PK)");
    }//GEN-LAST:event_mnuValueBlockInSectorIncrDecrItemsActionPerformed

    private void mnuLinearFormatCardItemsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuLinearFormatCardItemsActionPerformed
        frmLinearFormatCard LFC = new frmLinearFormatCard();
        new Global().AddFrame(LFC, pnlDesktop, lblHeader, "LinearFormat Card (AKM1,AKM2,PK)");
    }//GEN-LAST:event_mnuLinearFormatCardItemsActionPerformed

    private void mnuSectorTrailerWriteItemsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuSectorTrailerWriteItemsActionPerformed
        frmSectorTrailerWrite STW = new frmSectorTrailerWrite();
        new Global().AddFrame(STW, pnlDesktop, lblHeader, "SectorTrailer Write (AKM1,AKM2,PK)");
    }//GEN-LAST:event_mnuSectorTrailerWriteItemsActionPerformed

    private void mnuViewAllItemsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuViewAllItemsActionPerformed
        frmViewAll VA = new frmViewAll();
        new Global().AddFrame(VA, pnlDesktop, lblHeader, "View All");
    }//GEN-LAST:event_mnuViewAllItemsActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened

        try {
            Global glb = new Global();
            frmLinearReadWrite LRW = new frmLinearReadWrite();
            glb.AddFrame(LRW, pnlDesktop, lblHeader, "Linear Read/Write (AKM1,AKM2,PK)");
            glb.CreateKey(27, 20, 31, 29, "txtReaderKey", pnlReaderKey);
            FillEcArray();
            exec.execute(new Main_Thread());
        } catch (Exception ie) {
            System.out.println(ie.toString());
        }


    }//GEN-LAST:event_formWindowOpened

    private void chkHexItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkHexItemStateChanged

        try {
            Global glb = Global.class.newInstance();
            glb.Check_box(pnlReaderKey, "txtReaderKey", evt);
            glb.HEX_BOX = chkHex;
            glb.TEXTFIELD = "txtReaderKey";

        } catch (InstantiationException | IllegalAccessException ie) {
            System.out.println(ie.toString());
        }

    }//GEN-LAST:event_chkHexItemStateChanged

    private void btnSaveUserDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveUserDataActionPerformed
        if (GetFunct() || GetLoop()) {
            return;
        }
        try {
            SetFunct(true);
            int iFResult = 0;

            if (txtNewUserData.getText().trim().isEmpty()) {
                JOptionPane.showMessageDialog(rootPane, "You must enter any data !",
                        "Warning !", JOptionPane.WARNING_MESSAGE);
                txtNewUserData.requestFocus();
                return;
            }

            byte[] baNewUserdata = new byte[16];
            baNewUserdata = txtNewUserData.getText().getBytes();

            iFResult = Declarations.UFrDeclarations.UFRInstance.WriteUserData(baNewUserdata);

            if (iFResult == DL_OK) {
                Declarations.UFrDeclarations.UFRInstance.ReaderUISignal(FUNCT_LIGHT_OK, FUNCT_SOUND_OK);
            } else {
                Declarations.UFrDeclarations.UFRInstance.ReaderUISignal(FUNCT_LIGHT_ERROR, FUNCT_SOUND_ERROR);
            }
        } finally {
            SetFunct(false);
        }
    }//GEN-LAST:event_btnSaveUserDataActionPerformed

    private void btnReaderSaveKeyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReaderSaveKeyActionPerformed

        if (GetFunct() || GetLoop()) {
            return;
        }
        try {
            SetFunct(true);
            int iFResult = 0;
            byte bKeyIndex = 0;

            bKeyIndex = (byte) Integer.parseInt(cboKeyIndex.getSelectedItem().toString());
            iFResult = Declarations.UFrDeclarations.UFRInstance.ReaderKeyWrite(new Global().KEY(pnlReaderKey, "txtReaderKey", chkHex), bKeyIndex);
            if (iFResult == DL_OK) {
                Declarations.UFrDeclarations.UFRInstance.ReaderUISignal(FUNCT_LIGHT_OK, FUNCT_SOUND_OK);
            } else {
                Declarations.UFrDeclarations.UFRInstance.ReaderUISignal(FUNCT_LIGHT_ERROR, FUNCT_SOUND_ERROR);
            }
        } finally {
            SetFunct(false);
        }
    }//GEN-LAST:event_btnReaderSaveKeyActionPerformed

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

    private void mnuReaderHardwareFirmwareVersionItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuReaderHardwareFirmwareVersionItemActionPerformed
        ByteByReference bHMajor = new ByteByReference(), bHMinor = new ByteByReference();
        ByteByReference bFMajor = new ByteByReference(), bFMinor = new ByteByReference();

        Declarations.UFrDeclarations.UFRInstance.GetReaderHardwareVersion(bHMajor, bHMinor);
        Declarations.UFrDeclarations.UFRInstance.GetReaderFirmwareVersion(bFMajor, bFMinor);
        JOptionPane.showMessageDialog(rootPane, "Hardware version : " + bHMajor.getValue() + "." + bHMinor.getValue()
                + "\nFirmware version : " + bFMajor.getValue() + "." + bFMinor.getValue(),
                "Reader Hardware/Firmware version", JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_mnuReaderHardwareFirmwareVersionItemActionPerformed

    private void MainThread() {
        SetLoop(true);
        String sBuffer = "";
        if (!boCONN) {
            if ((iRResult = Declarations.UFrDeclarations.UFRInstance.ReaderOpen()) == DL_OK) {
                boCONN = true;
                txtConnected.setText("CONNECTED");
            } else {
                txtConnected.setText("NOT CONNECTED");
                txtReaderType.setText(null);
                txtReaderSerial.setText(null);
                txtCardType.setText(null);
                txtCardSerial.setText(null);
                txtCardUIDSize.setText(null);
            }
        }
        if (boCONN) {
            if ((iRResult = Declarations.UFrDeclarations.UFRInstance.GetReaderType(iaReaderType)) == DL_OK) {
                txtReaderType.setText("0x" + Integer.toHexString(iaReaderType[0]).toUpperCase());
                if ((iRResult = Declarations.UFrDeclarations.UFRInstance.GetReaderSerialNumber(iaReaderSerial)) == DL_OK) {
                    txtReaderSerial.setText("0x" + Integer.toHexString(iaReaderSerial[0]).toUpperCase());
                    SetStatusBar(txtRErrorCode, txtRErrorExplain, iRResult);

                    iCResult = Declarations.UFrDeclarations.UFRInstance.GetDlogicCardType(bDLCardType);
                    if (iCResult == DL_OK) {
                        if (bDLCardType.getValue() <= DCT.DL_NTAG_216.getValue()) {
                            SetMeniEnable(false);
                        } else {
                            SetMeniEnable(true);
                        }

                        Declarations.UFrDeclarations.UFRInstance.GetCardIdEx(bCardType, baCardUID, bCardUIDSize);
                        for (byte bBr = 0; bBr < bCardUIDSize.getValue(); bBr++) {
                            sBuffer += Integer.toHexString((((char) baCardUID[bBr] & 0xFF)));
                        }
                        txtCardType.setText("0x" + Integer.toHexString(bDLCardType.getValue()).toUpperCase());
                        txtCardUIDSize.setText("0x" + Integer.toHexString(bCardUIDSize.getValue()).toUpperCase());
                        txtCardSerial.setText("0x" + sBuffer.toUpperCase());
                        bTypeOfCard = bDLCardType.getValue();                                                                                                
                        SetStatusBar(txtCErrorCode, txtCErrorExplain, iCResult);
                    } else {
                        txtCardType.setText(null);
                        txtCardSerial.setText(null);
                        txtCardUIDSize.setText(null);
                        bTypeOfCard = bDLCardType.getValue();
                        SetMeniEnable(true);
                        SetStatusBar(txtCErrorCode, txtCErrorExplain, iCResult);
                    }
                }
            } else {
                Declarations.UFrDeclarations.UFRInstance.ReaderClose();
                boCONN = false;
            }
            if ((iRResult = Declarations.UFrDeclarations.UFRInstance.ReadUserData(baReadUserData)) == DL_OK) {
                txtReadUserData.setText(new String(baReadUserData));
            }
        }
        SetLoop(false);
    }

    private void SetMeniEnable(boolean isEnable) {
        mnuBlockInSectorReadWriteItem.setEnabled(isEnable);
        mnuLinearFormatCardItems.setEnabled(isEnable);
        mnuSectorTrailerWriteItems.setEnabled(isEnable);
        mnuValueBlockInSectorIncrDecrItems.setEnabled(isEnable);
        mnuValueBlockInSectorReadWriteItems.setEnabled(isEnable);
        mnuValueBlockIncrDecrItems.setEnabled(isEnable);
        mnuValueBlockReadWriteItems.setEnabled(isEnable);
    }

    class Main_Thread implements Runnable {

        @Override
        public void run() {
            try {
                while (true) {
                    if (!GetFunct()) {
                        MainThread();
                    }
                    TimeUnit.MILLISECONDS.sleep(SLEEP_VALUE);
                }
            } catch (InterruptedException ex) {
                Logger.getLogger(frmMain.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }

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

        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {

                frmMain frmUfrCoder = new frmMain();
                frmUfrCoder.setVisible(true);
                frmUfrCoder.setLocationRelativeTo(null);

            }
        });

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnReaderReset;
    private javax.swing.JButton btnReaderSaveKey;
    private javax.swing.JButton btnReaderUISignal;
    private javax.swing.JButton btnSaveUserData;
    private javax.swing.JButton btnSoftRestart;
    private javax.swing.JComboBox cboKeyIndex;
    private javax.swing.JComboBox cboLightMode;
    private javax.swing.JComboBox cboSoundMode;
    private javax.swing.JCheckBox chkHex;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JPopupMenu.Separator jSeparator2;
    private javax.swing.JPopupMenu.Separator jSeparator3;
    private javax.swing.JPopupMenu.Separator jSeparator4;
    private javax.swing.JPopupMenu.Separator jSeparator5;
    private javax.swing.JPopupMenu.Separator jSeparator6;
    private javax.swing.JPopupMenu.Separator jSeparator7;
    private javax.swing.JPanel jpnlUserData1;
    private javax.swing.JTabbedPane jtabKeysUserData1;
    private javax.swing.JLabel lblCardSerial;
    private javax.swing.JLabel lblCardType;
    private javax.swing.JLabel lblCardUID;
    private javax.swing.JLabel lblHeader;
    private javax.swing.JLabel lblKeyIndex;
    private javax.swing.JLabel lblLightMode;
    private javax.swing.JLabel lblNewUserData2;
    private javax.swing.JLabel lblReaderSerial;
    private javax.swing.JLabel lblReaderType;
    private javax.swing.JLabel lblSoundMode;
    private javax.swing.JLabel lblUserData5;
    private javax.swing.JMenuItem mnuBlockInSectorReadWriteItem;
    private javax.swing.JMenuItem mnuBlockReadWriteItems;
    private javax.swing.JMenuItem mnuExitItems;
    private javax.swing.JMenu mnuFunctionsItem;
    private javax.swing.JMenuItem mnuLinearFormatCardItems;
    private javax.swing.JMenuItem mnuLinearReadWriteItem;
    private javax.swing.JMenuBar mnuMeni;
    private javax.swing.JMenuItem mnuReaderHardwareFirmwareVersionItem;
    private javax.swing.JMenuItem mnuSectorTrailerWriteItems;
    private javax.swing.JMenuItem mnuValueBlockInSectorIncrDecrItems;
    private javax.swing.JMenuItem mnuValueBlockInSectorReadWriteItems;
    private javax.swing.JMenuItem mnuValueBlockIncrDecrItems;
    private javax.swing.JMenuItem mnuValueBlockReadWriteItems;
    private javax.swing.JMenuItem mnuViewAllItems;
    private javax.swing.JDesktopPane pnlDesktop;
    private javax.swing.JPanel pnlReader;
    private javax.swing.JPanel pnlReaderKey;
    private javax.swing.JTextField txtCErrorCode;
    private javax.swing.JTextField txtCErrorExplain;
    private javax.swing.JTextField txtCardSerial;
    private javax.swing.JTextField txtCardStatus;
    private javax.swing.JTextField txtCardType;
    private javax.swing.JTextField txtCardUIDSize;
    private javax.swing.JTextField txtConnected;
    private javax.swing.JTextField txtNewUserData;
    private javax.swing.JTextField txtRErrorCode;
    private javax.swing.JTextField txtRErrorExplain;
    private javax.swing.JTextField txtReadUserData;
    private javax.swing.JTextField txtReaderSerial;
    private javax.swing.JTextField txtReaderType;
    // End of variables declaration//GEN-END:variables
}
