

/**
 * @author  D-Logic Team
 * @version 2.1
 */
package ufcodersimpleapplet;

import com.sun.jna.ptr.ByteByReference;
import ufcodersimpleapplet.Declarations.uFrFunction;
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.JCheckBox;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class uFCoderSimpleApplet extends javax.swing.JApplet implements KeyListener, FocusListener {
            
    static final String ANY_DATA = "You must enter any data !",
                        APPROPRIATE_FORMAT = "Enter a number between 0 and 255 for decimal or 0 to FF for hexadecimal";
    
    static final String NEW_CARD_KEY_A="txtNewCardKeyA";
    static final String NEW_CARD_KEY_B="txtNewCardKeyB";
    static final String NEW_READER_KEY="txtNewReaderKey";
    
 
   
  
 private final static byte
       MIFARE_AUTHENT1A     =0x60,  
       MIFARE_AUTHENT1B     =0x61,  
       KEY_INDEX            = 0;
 
// final static byte 
//         MAX_SECTORS_1k     = 16,                            
//         MAX_SECTORS_4k     = 40,
//         
 
 
 private final static byte
         MAX_KEY_INDEX      = 6;        
 
 private 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;
                        
     int[]   iaReaderType   =    new int[1];
     int[]   iaReaderSerial =    new int[3];
     
     byte[]  bCardUID       =   new byte[9];     
     ByteByReference  bDLCardType   = new ByteByReference();         
     ByteByReference  bCardUIDSize  = new ByteByReference();
     ByteByReference  bCardType     = new ByteByReference();
     
     int     iRResult     ;
     int     iCResult     ;    
     byte    bTypeOfCard  ;
     
    private String[] iaErrorCodes=new String[200];
    private boolean boCONN       = false;
    
    
    Declarations.DLCARDTYPE DCT;
    Declarations.ERRORCODES   EC;
    Declarations.ERRORCODES[] ERRCODES = Declarations.ERRORCODES.values();
    
    ExecutorService exec = Executors.newCachedThreadPool();

    private void FillEcArray(){        
        for (Declarations.ERRORCODES ECC : EC.values()) {               
               iaErrorCodes[ECC.getValue()]=ECC.name();               
            }
    }
  
   private boolean bFunctionStart;
                    
   public void SetFunct(boolean bValue){
          bFunctionStart=bValue;            
   }  
   public boolean GetFunct(){
       return bFunctionStart;          
}   


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

    private void SetStatusBar(JTextField txtErrorCode, JTextField txtErrorExplain, int iResultValue) {
        
                txtErrorCode.setText("0x" + Integer.toHexString(iResultValue).toUpperCase());
                txtErrorExplain.setText(iaErrorCodes[iResultValue]);           
    }
     
    private JTextField TF=new JTextField();
   
    
    
    
    @Override
    public void keyTyped(KeyEvent e) {
       boolean bPatternCheck;
        JTextField TB = (JTextField) e.getSource();
        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();
            }
            bPatternCheck = Pattern.matches("[a-fA-F_0-9]", String.valueOf(e.getKeyChar()));
            if (!bPatternCheck) {
                e.consume();
            }
        } else
            {
               if (TB.getText().length() > 2) {
                  e.consume();
               }
                  bPatternCheck = Pattern.matches("[0-9]", String.valueOf(e.getKeyChar()));
               if (!bPatternCheck) {
                   e.consume();                
                }
           }
    }

    @Override
    public void keyPressed(KeyEvent e) {
    }

    @Override
    public void keyReleased(KeyEvent e) {
    }

    @Override
    public void focusGained(FocusEvent e) {
    }

    @Override
    public void focusLost(FocusEvent e) {        
       try{ 
        JTextField TB=(JTextField)e.getSource();
        if (Short.parseShort(TB.getText(),10)>255)
        {
            JOptionPane.showMessageDialog(rootPane,APPROPRIATE_FORMAT, "Error",JOptionPane.ERROR_MESSAGE);
            TB.requestFocus();
            TB.selectAll();
        }
       }catch (NumberFormatException NFE){
           
       }
        
    }

    private void CreateKey(int iKeyX, int iKeyY, int iKeyHeight, int iKeyWidth, String sKeyName, JPanel pnlContainer) {

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

        }
        pnlContainer.repaint();
    }

   
    class MainThread implements Runnable {

        @Override
        public void run() {
            try {
                while (true) {
                    if (!GetFunct()) {
                        MainThread();
                    }
                    TimeUnit.MILLISECONDS.sleep(SLEEP_VALUE);
                }
            } catch (Exception InEx) {
                Logger.getLogger(uFCoderSimpleApplet.class.getName()).log(Level.SEVERE, null, InEx);
            }
        }
    }
    private void ConvertToHex(JCheckBox CheckBox,JPanel pnlContainer, String sKeyName)
    {
       
            for (byte bBr=0;bBr<pnlContainer.getComponentCount();bBr++)
            {
                if (pnlContainer.getComponent(bBr).getName()==sKeyName && ((JTextField)(pnlContainer.getComponent(bBr))).getText().isEmpty()){
                    continue;
                }
                else {
                       if (pnlContainer.getComponent(bBr).getName()==sKeyName)
                       {
                           ((JTextField)(pnlContainer.getComponent(bBr))).setText(CheckBox.isSelected()
                                   ? Integer.toHexString(Short.parseShort(((JTextField) (pnlContainer.getComponent(bBr))).getText())) 
                                   : Integer.toString(Short.parseShort(((JTextField) (pnlContainer.getComponent(bBr))).getText(),16)) 
                                       
                                                                                 );                     
                       }
                     }
            }                       
    }
    private byte[] DecHexConversion(JCheckBox CheckBox,JPanel pnlKEYs, String sKeyName) {
        byte bCount = 0;
        byte[] baKey = new byte[MAX_KEY_INDEX];        
        
            for (int br = 0; br < pnlKEYs.getComponentCount(); br++) {
                                                  
                if (pnlKEYs.getComponent(br).getName() == sKeyName) {
                    baKey[bCount] =CheckBox.isSelected() ? (byte) Short.parseShort(((JTextField) (pnlKEYs.getComponent(br))).getText(), 16)
                                                         : (byte) Short.parseShort(((JTextField) (pnlKEYs.getComponent(br))).getText());                                                                
                    bCount++;                                                            
                }
            }
        
        return baKey;
    }

    private void MainThread() {
       
        SetLoop(true);
        String sBuffer = "";
        
        
        if (!boCONN) {
            if ((iRResult = Declarations.uFrFunction.UFrInstance.ReaderOpen()) == DL_OK) {
                txtConnection  .setText("CONNECTED");                
                boCONN = true;
                SetStatusBar(txtRErrorCode,txtRErrorExplain, iRResult);
            } else {
                txtConnection  .setText("NOT CONNECTED");
                txtReaderType  .setText(null);
                txtReaderSerial.setText(null);
                txtCardType    .setText(null);
                txtCardSerial  .setText(null);
                txtCardUIDSize .setText(null);
                SetStatusBar(txtRErrorCode,txtRErrorExplain, iRResult);
            }
        }
        if (boCONN) {
            if ((iRResult = Declarations.uFrFunction.UFrInstance.GetReaderType(iaReaderType)) == DL_OK) {
                txtReaderType.setText("0x" + Integer.toHexString(iaReaderType[0]).toUpperCase());
                                    
            if ((iRResult = Declarations.uFrFunction.UFrInstance.GetReaderSerialNumber(iaReaderSerial)) == DL_OK) {
                txtReaderSerial.setText("0x" + Integer.toHexString(iaReaderSerial[0]).toUpperCase());
                SetStatusBar(txtRErrorCode,txtRErrorExplain, iRResult);
            }
            iCResult = Declarations.uFrFunction.UFrInstance.GetDlogicCardType(bDLCardType);
            if (iCResult == DL_OK) {
                btnFormatCardKeys.setEnabled(bDLCardType.getValue()>0x0A);
                Declarations.uFrFunction.UFrInstance.GetCardIdEx(bCardType, bCardUID,bCardUIDSize);
                for (byte bCount = 0; bCount < bCardUIDSize.getValue(); ++bCount) {
                           sBuffer += Integer.toHexString((((char) bCardUID[bCount] & 0xFF)));
                         }
                txtCardType   .setText("0x" + Integer.toHexString(bDLCardType.getValue()));                
                txtCardUIDSize.setText("0x" + Integer.toHexString(bCardUIDSize.getValue()).toUpperCase());                
                txtCardSerial .setText("0x"+sBuffer.toUpperCase());
                SetStatusBar(txtCErrorCode,txtCErrorExplain, iCResult);
            } else {
                txtCardType   .setText(null);
                txtCardSerial .setText(null);
                txtCardUIDSize.setText(null);
                btnFormatCardKeys.setEnabled(true);
                SetStatusBar(txtCErrorCode,txtCErrorExplain, iCResult);
            }
           }
             
            else {
                btnFormatCardKeys.setEnabled(true);
                Declarations.uFrFunction.UFrInstance.ReaderClose();
                boCONN = false;
            }
        }
        SetLoop(false);
    }

    @Override
    public void init() {
        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(uFCoderSimpleApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(uFCoderSimpleApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(uFCoderSimpleApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(uFCoderSimpleApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {

                @Override
                public void run() {
                    initComponents();
                   
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    @Override
    public void start() {
       
        CreateKey(3, 3, 31, 29,  NEW_CARD_KEY_A, pnlNewCardKeys);
        CreateKey(3, 35, 31, 29, NEW_CARD_KEY_B, pnlNewCardKeys);
        CreateKey(3, 10, 31, 29, NEW_READER_KEY, pnlNewReaderKey); 
        FillEcArray();
        exec.execute(new MainThread());
    }

    @Override
    public void stop() {
        exec.shutdown();
    }
    
    
    public void close(){
        System.exit(0);
    }

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

        rbtnAuthMode = new javax.swing.ButtonGroup();
        buttonGroup1 = new javax.swing.ButtonGroup();
        pnlContainer = new javax.swing.JPanel();
        lblReaderType = new javax.swing.JLabel();
        txtReaderType = new javax.swing.JTextField();
        lblReaderSerial = new javax.swing.JLabel();
        txtReaderSerial = new javax.swing.JTextField();
        lblCardUIDSize = new javax.swing.JLabel();
        lblCardSerial = 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();
        btnReaderUISignal = new javax.swing.JButton();
        lblCardType1 = new javax.swing.JLabel();
        txtCardType = new javax.swing.JTextField();
        txtRErrorExplain = new javax.swing.JTextField();
        txtConnection = new javax.swing.JTextField();
        txtRErrorCode = new javax.swing.JTextField();
        txtCardUIDSize = new javax.swing.JTextField();
        pnlFormat = new javax.swing.JPanel();
        pnlAuth1AB = new javax.swing.JPanel();
        rbAUTH1B = new javax.swing.JRadioButton();
        rbAUTH1A = new javax.swing.JRadioButton();
        pgNewCardReaderKeys = new javax.swing.JTabbedPane();
        tabNewCardKeys = new javax.swing.JPanel();
        lblKeyA = new javax.swing.JLabel();
        lblKeyB = new javax.swing.JLabel();
        chkNewCardKeys = new javax.swing.JCheckBox();
        pnlNewCardKeys = new javax.swing.JPanel();
        btnFormatCardKeys = new javax.swing.JButton();
        lblSectorsFormatted = new javax.swing.JLabel();
        txtSectorsFormatted = new javax.swing.JTextField();
        tabNewReaderKey = new javax.swing.JPanel();
        chkNewReaderKey = new javax.swing.JCheckBox();
        btnFormatReaderKey = new javax.swing.JButton();
        lblKeyIndexZero = new javax.swing.JLabel();
        lblKeyIndex = new javax.swing.JLabel();
        pnlNewReaderKey = new javax.swing.JPanel();
        pnlLinearReadWrite = new javax.swing.JPanel();
        tabLinearReadWrite = new javax.swing.JTabbedPane();
        tabLinearRead = new javax.swing.JPanel();
        lblReadData = new javax.swing.JLabel();
        lblLinearAddress = new javax.swing.JLabel();
        txtLRLinearAddress = new javax.swing.JTextField();
        lblDataLength = new javax.swing.JLabel();
        txtLRDataLength = new javax.swing.JTextField();
        lblBytesRead = new javax.swing.JLabel();
        txtBytesRead = new javax.swing.JTextField();
        btnLinearRead = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        txtLinearRead = new javax.swing.JTextArea();
        tabLinearWrite = new javax.swing.JPanel();
        lblWriteData = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtWriteData = new javax.swing.JTextArea();
        lblLinearAddressWrite = new javax.swing.JLabel();
        lblDataLengthWrite = new javax.swing.JLabel();
        txtLWLinearAddress = new javax.swing.JTextField();
        txtLWDataLength = new javax.swing.JTextField();
        lblBytesWritten = new javax.swing.JLabel();
        txtBytesWritten = new javax.swing.JTextField();
        btnLinearWrite = new javax.swing.JButton();
        txtCardStatus = new javax.swing.JTextField();
        txtCErrorCode = new javax.swing.JTextField();
        txtCErrorExplain = new javax.swing.JTextField();
        txtFunctionError = new javax.swing.JTextField();
        txtFErrorCode = new javax.swing.JTextField();
        txtFErrorExplain = new javax.swing.JTextField();

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

        pnlContainer.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        pnlContainer.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

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

        txtReaderType.setEditable(false);
        txtReaderType.setBackground(java.awt.Color.white);
        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)));
        pnlContainer.add(txtReaderType, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 10, 102, -1));

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

        txtReaderSerial.setEditable(false);
        txtReaderSerial.setBackground(java.awt.Color.white);
        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)));
        pnlContainer.add(txtReaderSerial, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 33, 102, -1));

        lblCardUIDSize.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblCardUIDSize.setText("UID Size");
        pnlContainer.add(lblCardUIDSize, new org.netbeans.lib.awtextra.AbsoluteConstraints(440, 10, 60, -1));

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

        txtCardSerial.setEditable(false);
        txtCardSerial.setBackground(java.awt.Color.white);
        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)));
        pnlContainer.add(txtCardSerial, new org.netbeans.lib.awtextra.AbsoluteConstraints(390, 33, 140, -1));

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

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

        pnlContainer.add(pnlSep1, new org.netbeans.lib.awtextra.AbsoluteConstraints(1, 58, 549, -1));

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

        cboLightMode.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        cboLightMode.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "None", "Long Green", "LongRed", "Alternation", "Flash" }));
        cboLightMode.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        pnlContainer.add(cboLightMode, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 68, 113, -1));

        lblSoundMode.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblSoundMode.setText("Sound Mode");
        pnlContainer.add(lblSoundMode, new org.netbeans.lib.awtextra.AbsoluteConstraints(63, 95, -1, -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));
        pnlContainer.add(cboSoundMode, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 95, -1, -1));

        btnReaderUISignal.setFont(new java.awt.Font("Verdana", 0, 11)); // 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);
            }
        });
        pnlContainer.add(btnReaderUISignal, new org.netbeans.lib.awtextra.AbsoluteConstraints(312, 68, 201, 54));

        lblCardType1.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblCardType1.setText("Card Type");
        pnlContainer.add(lblCardType1, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 10, -1, -1));

        txtCardType.setEditable(false);
        txtCardType.setBackground(java.awt.Color.white);
        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)));
        pnlContainer.add(txtCardType, new org.netbeans.lib.awtextra.AbsoluteConstraints(390, 10, 36, -1));

        txtRErrorExplain.setEditable(false);
        txtRErrorExplain.setBackground(new java.awt.Color(255, 255, 255));
        txtRErrorExplain.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        txtRErrorExplain.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        pnlContainer.add(txtRErrorExplain, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 130, 330, -1));

        txtConnection.setEditable(false);
        txtConnection.setBackground(new java.awt.Color(246, 241, 241));
        txtConnection.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        txtConnection.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        pnlContainer.add(txtConnection, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 130, 120, -1));

        txtRErrorCode.setEditable(false);
        txtRErrorCode.setBackground(new java.awt.Color(255, 255, 255));
        txtRErrorCode.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        txtRErrorCode.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        pnlContainer.add(txtRErrorCode, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 130, 80, -1));

        txtCardUIDSize.setEditable(false);
        txtCardUIDSize.setBackground(java.awt.Color.white);
        txtCardUIDSize.setFont(new java.awt.Font("Verdana", 1, 11)); // NOI18N
        txtCardUIDSize.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtCardUIDSize.setToolTipText("Card UID Size");
        txtCardUIDSize.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        pnlContainer.add(txtCardUIDSize, new org.netbeans.lib.awtextra.AbsoluteConstraints(500, 10, 30, -1));

        getContentPane().add(pnlContainer, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, 160));

        pnlFormat.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        pnlFormat.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

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

        rbAUTH1B.setBackground(java.awt.Color.white);
        rbtnAuthMode.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));

        rbAUTH1A.setBackground(java.awt.Color.white);
        rbtnAuthMode.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));

        javax.swing.GroupLayout pnlAuth1ABLayout = new javax.swing.GroupLayout(pnlAuth1AB);
        pnlAuth1AB.setLayout(pnlAuth1ABLayout);
        pnlAuth1ABLayout.setHorizontalGroup(
            pnlAuth1ABLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlAuth1ABLayout.createSequentialGroup()
                .addGap(98, 98, 98)
                .addComponent(rbAUTH1A)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 170, Short.MAX_VALUE)
                .addComponent(rbAUTH1B)
                .addGap(117, 117, 117))
        );
        pnlAuth1ABLayout.setVerticalGroup(
            pnlAuth1ABLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlAuth1ABLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(rbAUTH1B)
                .addComponent(rbAUTH1A))
        );

        pnlFormat.add(pnlAuth1AB, new org.netbeans.lib.awtextra.AbsoluteConstraints(1, 1, 549, -1));

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

        javax.swing.GroupLayout pnlNewCardKeysLayout = new javax.swing.GroupLayout(pnlNewCardKeys);
        pnlNewCardKeys.setLayout(pnlNewCardKeysLayout);
        pnlNewCardKeysLayout.setHorizontalGroup(
            pnlNewCardKeysLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 226, Short.MAX_VALUE)
        );
        pnlNewCardKeysLayout.setVerticalGroup(
            pnlNewCardKeysLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 58, Short.MAX_VALUE)
        );

        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(153, 153, 153));
        txtSectorsFormatted.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        txtSectorsFormatted.setForeground(new java.awt.Color(255, 255, 255));
        txtSectorsFormatted.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        javax.swing.GroupLayout tabNewCardKeysLayout = new javax.swing.GroupLayout(tabNewCardKeys);
        tabNewCardKeys.setLayout(tabNewCardKeysLayout);
        tabNewCardKeysLayout.setHorizontalGroup(
            tabNewCardKeysLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabNewCardKeysLayout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(tabNewCardKeysLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblKeyB)
                    .addComponent(lblKeyA))
                .addGap(18, 18, 18)
                .addGroup(tabNewCardKeysLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnlNewCardKeys, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(chkNewCardKeys))
                .addGap(18, 18, 18)
                .addGroup(tabNewCardKeysLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnFormatCardKeys, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
                    .addGroup(tabNewCardKeysLayout.createSequentialGroup()
                        .addComponent(lblSectorsFormatted)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(txtSectorsFormatted, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        tabNewCardKeysLayout.setVerticalGroup(
            tabNewCardKeysLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabNewCardKeysLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabNewCardKeysLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(tabNewCardKeysLayout.createSequentialGroup()
                        .addGroup(tabNewCardKeysLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(pnlNewCardKeys, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(tabNewCardKeysLayout.createSequentialGroup()
                                .addComponent(lblKeyA)
                                .addGap(18, 18, 18)
                                .addComponent(lblKeyB)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(chkNewCardKeys))
                    .addGroup(tabNewCardKeysLayout.createSequentialGroup()
                        .addComponent(btnFormatCardKeys, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(tabNewCardKeysLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtSectorsFormatted)
                            .addComponent(lblSectorsFormatted))))
                .addContainerGap())
        );

        pgNewCardReaderKeys.addTab("New Card Keys", tabNewCardKeys);

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

        lblKeyIndexZero.setBackground(new java.awt.Color(255, 255, 255));
        lblKeyIndexZero.setFont(new java.awt.Font("Verdana", 1, 24)); // NOI18N
        lblKeyIndexZero.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblKeyIndexZero.setText("0");
        lblKeyIndexZero.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        lblKeyIndexZero.setOpaque(true);

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

        javax.swing.GroupLayout pnlNewReaderKeyLayout = new javax.swing.GroupLayout(pnlNewReaderKey);
        pnlNewReaderKey.setLayout(pnlNewReaderKeyLayout);
        pnlNewReaderKeyLayout.setHorizontalGroup(
            pnlNewReaderKeyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 226, Short.MAX_VALUE)
        );
        pnlNewReaderKeyLayout.setVerticalGroup(
            pnlNewReaderKeyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 46, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout tabNewReaderKeyLayout = new javax.swing.GroupLayout(tabNewReaderKey);
        tabNewReaderKey.setLayout(tabNewReaderKeyLayout);
        tabNewReaderKeyLayout.setHorizontalGroup(
            tabNewReaderKeyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabNewReaderKeyLayout.createSequentialGroup()
                .addGap(99, 99, 99)
                .addGroup(tabNewReaderKeyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tabNewReaderKeyLayout.createSequentialGroup()
                        .addComponent(pnlNewReaderKey, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
                        .addComponent(btnFormatReaderKey, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(tabNewReaderKeyLayout.createSequentialGroup()
                        .addComponent(chkNewReaderKey)
                        .addGap(85, 85, 85)
                        .addComponent(lblKeyIndex)
                        .addGap(26, 26, 26)
                        .addComponent(lblKeyIndexZero, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        tabNewReaderKeyLayout.setVerticalGroup(
            tabNewReaderKeyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabNewReaderKeyLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabNewReaderKeyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tabNewReaderKeyLayout.createSequentialGroup()
                        .addComponent(pnlNewReaderKey, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(1, 1, 1)
                        .addGroup(tabNewReaderKeyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(chkNewReaderKey)
                            .addComponent(lblKeyIndexZero, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblKeyIndex)))
                    .addComponent(btnFormatReaderKey, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pgNewCardReaderKeys.addTab("New Reader Key", tabNewReaderKey);

        pnlFormat.add(pgNewCardReaderKeys, new org.netbeans.lib.awtextra.AbsoluteConstraints(11, 32, -1, -1));
        pgNewCardReaderKeys.getAccessibleContext().setAccessibleName("New Card Keys");

        getContentPane().add(pnlFormat, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 158, -1, 170));

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

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

        tabLinearRead.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        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(21, 12, -1, -1));

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

        txtLRLinearAddress.setFont(new java.awt.Font("Verdana", 0, 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(124, 123, 40, -1));

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

        txtLRDataLength.setFont(new java.awt.Font("Verdana", 0, 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(124, 148, 40, -1));

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

        txtBytesRead.setEditable(false);
        txtBytesRead.setBackground(java.awt.Color.lightGray);
        txtBytesRead.setFont(new java.awt.Font("Verdana", 0, 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(295, 139, 40, -1));

        btnLinearRead.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        btnLinearRead.setText("READ");
        btnLinearRead.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        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(380, 123, 150, 50));

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

        tabLinearRead.add(jScrollPane3, new org.netbeans.lib.awtextra.AbsoluteConstraints(21, 33, 506, -1));

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

        tabLinearWrite.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        tabLinearWrite.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        lblWriteData.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblWriteData.setText("Write Data");
        tabLinearWrite.add(lblWriteData, new org.netbeans.lib.awtextra.AbsoluteConstraints(22, 12, -1, -1));

        txtWriteData.setColumns(20);
        txtWriteData.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        txtWriteData.setLineWrap(true);
        txtWriteData.setRows(5);
        txtWriteData.setWrapStyleWord(true);
        txtWriteData.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        txtWriteData.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtWriteDataKeyTyped(evt);
            }
        });
        jScrollPane2.setViewportView(txtWriteData);

        tabLinearWrite.add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(22, 33, 506, -1));

        lblLinearAddressWrite.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblLinearAddressWrite.setText("Linear Address");
        tabLinearWrite.add(lblLinearAddressWrite, new org.netbeans.lib.awtextra.AbsoluteConstraints(22, 126, -1, -1));

        lblDataLengthWrite.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblDataLengthWrite.setText("Data Length");
        tabLinearWrite.add(lblDataLengthWrite, new org.netbeans.lib.awtextra.AbsoluteConstraints(22, 151, -1, -1));

        txtLWLinearAddress.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        txtLWLinearAddress.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtLWLinearAddress.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        tabLinearWrite.add(txtLWLinearAddress, new org.netbeans.lib.awtextra.AbsoluteConstraints(125, 123, 40, -1));

        txtLWDataLength.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        txtLWDataLength.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtLWDataLength.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        tabLinearWrite.add(txtLWDataLength, new org.netbeans.lib.awtextra.AbsoluteConstraints(125, 148, 40, -1));

        lblBytesWritten.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        lblBytesWritten.setText("Bytes Written");
        tabLinearWrite.add(lblBytesWritten, new org.netbeans.lib.awtextra.AbsoluteConstraints(213, 135, -1, -1));

        txtBytesWritten.setEditable(false);
        txtBytesWritten.setBackground(java.awt.Color.lightGray);
        txtBytesWritten.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        txtBytesWritten.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtBytesWritten.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        tabLinearWrite.add(txtBytesWritten, new org.netbeans.lib.awtextra.AbsoluteConstraints(308, 133, 40, -1));

        btnLinearWrite.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        btnLinearWrite.setText("WRITE");
        btnLinearWrite.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnLinearWrite.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLinearWriteActionPerformed(evt);
            }
        });
        tabLinearWrite.add(btnLinearWrite, new org.netbeans.lib.awtextra.AbsoluteConstraints(379, 123, 150, 50));

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

        javax.swing.GroupLayout pnlLinearReadWriteLayout = new javax.swing.GroupLayout(pnlLinearReadWrite);
        pnlLinearReadWrite.setLayout(pnlLinearReadWriteLayout);
        pnlLinearReadWriteLayout.setHorizontalGroup(
            pnlLinearReadWriteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabLinearReadWrite, javax.swing.GroupLayout.DEFAULT_SIZE, 549, Short.MAX_VALUE)
        );
        pnlLinearReadWriteLayout.setVerticalGroup(
            pnlLinearReadWriteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlLinearReadWriteLayout.createSequentialGroup()
                .addComponent(tabLinearReadWrite, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        getContentPane().add(pnlLinearReadWrite, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 329, 551, 220));

        txtCardStatus.setEditable(false);
        txtCardStatus.setBackground(new java.awt.Color(255, 255, 255));
        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, 580, 120, -1));

        txtCErrorCode.setEditable(false);
        txtCErrorCode.setBackground(new java.awt.Color(255, 255, 255));
        txtCErrorCode.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        txtCErrorCode.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        getContentPane().add(txtCErrorCode, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 580, 80, -1));

        txtCErrorExplain.setEditable(false);
        txtCErrorExplain.setBackground(new java.awt.Color(255, 255, 255));
        txtCErrorExplain.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        txtCErrorExplain.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        getContentPane().add(txtCErrorExplain, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 580, 350, -1));

        txtFunctionError.setEditable(false);
        txtFunctionError.setBackground(new java.awt.Color(255, 255, 255));
        txtFunctionError.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        txtFunctionError.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtFunctionError.setText("Function Error");
        getContentPane().add(txtFunctionError, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 560, 120, -1));

        txtFErrorCode.setEditable(false);
        txtFErrorCode.setBackground(new java.awt.Color(255, 255, 255));
        txtFErrorCode.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        txtFErrorCode.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        getContentPane().add(txtFErrorCode, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 560, 80, -1));

        txtFErrorExplain.setEditable(false);
        txtFErrorExplain.setBackground(new java.awt.Color(255, 255, 255));
        txtFErrorExplain.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        txtFErrorExplain.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        getContentPane().add(txtFErrorExplain, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 560, 350, -1));
    }// </editor-fold>//GEN-END:initComponents

    
    private void btnReaderUISignalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReaderUISignalActionPerformed
        if (GetFunct() || GetLoop()) {
            return;
        }
        try {
            SetFunct(true);
        uFrFunction.UFrInstance.ReaderUISignal(cboLightMode.getSelectedIndex(), cboSoundMode.getSelectedIndex());
            } finally {
              SetFunct(false);
        }
    }//GEN-LAST:event_btnReaderUISignalActionPerformed

    private void btnLinearReadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLinearReadActionPerformed
       if (GetFunct() || GetLoop()) {
            return;
        }        
       try {
            SetFunct(true);
            int iFResult             = 0;            
            byte bAuthMode=(byte)(rbAUTH1A.isSelected() ? MIFARE_AUTHENT1A : MIFARE_AUTHENT1B);         
            ShortByReference shBytesRet = new ShortByReference();
                                           
            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;
            }
                       
             short shLinearAddress    = Short.parseShort(txtLRLinearAddress.getText()),
                   shDataLength       = Short.parseShort(txtLRDataLength.getText());
             byte[] baReadData        = new byte[shDataLength];
            
            txtBytesRead.setText("");
            iFResult = Declarations.uFrFunction.UFrInstance.LinearRead(baReadData, shLinearAddress, shDataLength, shBytesRet, bAuthMode, KEY_INDEX);
            
            if (iFResult == DL_OK) {               
                txtLinearRead.setText(new String(baReadData, 0, shDataLength));
                txtBytesRead .setText(Short.toString(shBytesRet.getValue()));
                Declarations.uFrFunction.UFrInstance.ReaderUISignal(FUNCT_LIGHT_OK, FUNCT_SOUND_OK);
                SetStatusBar(txtFErrorCode, txtFErrorExplain, iFResult);
                
            } else {
                txtLinearRead.setText(new String(baReadData, 0, shBytesRet.getValue()));
                txtBytesRead .setText(Short.toString(shBytesRet.getValue()));
                Declarations .uFrFunction.UFrInstance.ReaderUISignal(FUNCT_LIGHT_ERROR, FUNCT_SOUND_ERROR);
                SetStatusBar(txtFErrorCode, txtFErrorExplain, iFResult);
                
            }
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(rootPane, APPROPRIATE_FORMAT, "Error !", JOptionPane.ERROR_MESSAGE);
        }finally{
           SetFunct(false);           
        }
    }//GEN-LAST:event_btnLinearReadActionPerformed

    private void btnLinearWriteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLinearWriteActionPerformed
        if (GetFunct() || GetLoop()) {
            return;
        }        
       try {
            SetFunct(true);
            int iFResult             = 0;
                             
            byte bAuthMode=(byte)(rbAUTH1A.isSelected() ? MIFARE_AUTHENT1A : MIFARE_AUTHENT1B);         
            ShortByReference shBytesRet = new ShortByReference();
                            
            
               
            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;
            }
            
            short 
                    shLinearAddress = Short.parseShort(txtLWLinearAddress.getText()),
                    shDataLength    = Short.parseShort(txtLWDataLength.getText());
            
            byte[] baWriteData = new byte[shDataLength];
            baWriteData = txtWriteData.getText().getBytes();

            txtBytesWritten.setText("");
            iFResult = Declarations.uFrFunction.UFrInstance.LinearWrite(baWriteData,shLinearAddress, shDataLength, shBytesRet, bAuthMode,KEY_INDEX);

            if (iFResult == DL_OK) {
                txtBytesWritten.setText(Short.toString(shBytesRet.getValue()));
                Declarations.uFrFunction.UFrInstance.ReaderUISignal(FUNCT_LIGHT_OK, FUNCT_SOUND_OK);
                SetStatusBar(txtFErrorCode, txtFErrorExplain, iFResult);
                
            } else {
                txtBytesWritten.setText(Short.toString(shBytesRet.getValue()));
                Declarations.uFrFunction.UFrInstance.ReaderUISignal(FUNCT_LIGHT_ERROR, FUNCT_SOUND_ERROR);
                SetStatusBar(txtFErrorCode, txtFErrorExplain, iFResult);
                
            }
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(rootPane, APPROPRIATE_FORMAT, "Error !", JOptionPane.ERROR_MESSAGE);
        }finally{
           SetFunct(false);
        }
    }//GEN-LAST:event_btnLinearWriteActionPerformed

    private void btnFormatCardKeysActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFormatCardKeysActionPerformed
           
        if (GetFunct() || GetLoop()) {
            return;
        }        
       try {
            SetFunct(true);
            int iFResult             = 0;
        
            byte bAuthMode=(byte)(rbAUTH1A.isSelected() ? MIFARE_AUTHENT1A : MIFARE_AUTHENT1B);
            
        byte[]baKeyA=new byte[MAX_KEY_INDEX];
        byte[]baKeyB=new byte[MAX_KEY_INDEX];
        
        byte bBlockAccessBits=0;
        byte bSectorAccessBits=1;
        byte bSectorTrailersByte9=45;
        ShortByReference shSectorsFormatted=new ShortByReference(); 
        
        
            baKeyA= DecHexConversion(chkNewCardKeys, pnlNewCardKeys, NEW_CARD_KEY_A);
            baKeyB= DecHexConversion(chkNewCardKeys, pnlNewCardKeys, NEW_CARD_KEY_B);
            iFResult=uFrFunction.UFrInstance.LinearFormatCard(baKeyA, bBlockAccessBits, bSectorAccessBits, bSectorTrailersByte9, baKeyB, shSectorsFormatted, bAuthMode, KEY_INDEX);
            
             if (iFResult == DL_OK) {                   
                      txtSectorsFormatted.setText(Short.toString(shSectorsFormatted.getValue()));
                      uFrFunction.UFrInstance.ReaderUISignal(FUNCT_LIGHT_OK, FUNCT_SOUND_OK); 
                      SetStatusBar(txtFErrorCode, txtFErrorExplain, iFResult);
                      JOptionPane.showMessageDialog(this,"Card keys are formatted successfully !", "Information",JOptionPane.INFORMATION_MESSAGE);
            } 
               else {
                    txtSectorsFormatted.setText(Short.toString(shSectorsFormatted.getValue()));
                    uFrFunction.UFrInstance.ReaderUISignal(FUNCT_LIGHT_ERROR , FUNCT_SOUND_ERROR);                                        
                    SetStatusBar(txtFErrorCode, txtFErrorExplain, iFResult);
                    JOptionPane.showMessageDialog(this,"Card keys are not formatted successfully !", "Error ",JOptionPane.ERROR_MESSAGE);
            }
            
        }  catch (NumberFormatException NfEx) {
            JOptionPane.showMessageDialog(rootPane, APPROPRIATE_FORMAT, "Error !", JOptionPane.ERROR_MESSAGE);
        } finally {
            
          SetFunct(false);
        }
    }//GEN-LAST:event_btnFormatCardKeysActionPerformed

    private void btnFormatReaderKeyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFormatReaderKeyActionPerformed
               
      if (GetFunct() || GetLoop()) {
            return;
        }        
       try {
            SetFunct(true);
            int iFResult             = 0;
        
            
            byte[]baReaderKey=new byte[MAX_KEY_INDEX];
            baReaderKey=DecHexConversion(chkNewReaderKey,pnlNewReaderKey, NEW_READER_KEY);
      
            iFResult=uFrFunction.UFrInstance.ReaderKeyWrite(baReaderKey, KEY_INDEX);
            
            if (iFResult == DL_OK) {
                                           
                      uFrFunction.UFrInstance.ReaderUISignal(FUNCT_LIGHT_OK, FUNCT_SOUND_OK); 
                      JOptionPane.showMessageDialog(this,"Reader key is formatted successfully !", "Information",JOptionPane.INFORMATION_MESSAGE);
            } 
               else {                    
                    uFrFunction.UFrInstance.ReaderUISignal(FUNCT_LIGHT_ERROR, FUNCT_SOUND_ERROR);                   
                    JOptionPane.showMessageDialog(this,"Reader key is not formatted successfully !", "Error ",JOptionPane.ERROR_MESSAGE);
            } 
             
         }  catch (NumberFormatException NfEx) {
            JOptionPane.showMessageDialog(rootPane, APPROPRIATE_FORMAT, "Error !", JOptionPane.ERROR_MESSAGE);
        } finally {
            
            SetFunct(false);
        }
    }//GEN-LAST:event_btnFormatReaderKeyActionPerformed

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

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

    private void txtWriteDataKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtWriteDataKeyTyped
        // TODO add your handling code here:
        txtLWDataLength.setText(Integer.toString(txtWriteData.getText().length()));
    }//GEN-LAST:event_txtWriteDataKeyTyped

    // 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 buttonGroup1;
    private javax.swing.JComboBox cboLightMode;
    private javax.swing.JComboBox cboSoundMode;
    private javax.swing.JCheckBox chkNewCardKeys;
    private javax.swing.JCheckBox chkNewReaderKey;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JLabel lblBytesRead;
    private javax.swing.JLabel lblBytesWritten;
    private javax.swing.JLabel lblCardSerial;
    private javax.swing.JLabel lblCardType1;
    private javax.swing.JLabel lblCardUIDSize;
    private javax.swing.JLabel lblDataLength;
    private javax.swing.JLabel lblDataLengthWrite;
    private javax.swing.JLabel lblKeyA;
    private javax.swing.JLabel lblKeyB;
    private javax.swing.JLabel lblKeyIndex;
    private javax.swing.JLabel lblKeyIndexZero;
    private javax.swing.JLabel lblLightMode;
    private javax.swing.JLabel lblLinearAddress;
    private javax.swing.JLabel lblLinearAddressWrite;
    private javax.swing.JLabel lblReadData;
    private javax.swing.JLabel lblReaderSerial;
    private javax.swing.JLabel lblReaderType;
    private javax.swing.JLabel lblSectorsFormatted;
    private javax.swing.JLabel lblSoundMode;
    private javax.swing.JLabel lblWriteData;
    private javax.swing.JTabbedPane pgNewCardReaderKeys;
    private javax.swing.JPanel pnlAuth1AB;
    private javax.swing.JPanel pnlContainer;
    private javax.swing.JPanel pnlFormat;
    private javax.swing.JPanel pnlLinearReadWrite;
    private javax.swing.JPanel pnlNewCardKeys;
    private javax.swing.JPanel pnlNewReaderKey;
    private javax.swing.JPanel pnlSep1;
    private javax.swing.JRadioButton rbAUTH1A;
    private javax.swing.JRadioButton rbAUTH1B;
    private javax.swing.ButtonGroup rbtnAuthMode;
    private javax.swing.JPanel tabLinearRead;
    private javax.swing.JTabbedPane tabLinearReadWrite;
    private javax.swing.JPanel tabLinearWrite;
    private javax.swing.JPanel tabNewCardKeys;
    private javax.swing.JPanel tabNewReaderKey;
    private javax.swing.JTextField txtBytesRead;
    private javax.swing.JTextField txtBytesWritten;
    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 txtConnection;
    private javax.swing.JTextField txtFErrorCode;
    private javax.swing.JTextField txtFErrorExplain;
    private javax.swing.JTextField txtFunctionError;
    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 txtRErrorCode;
    private javax.swing.JTextField txtRErrorExplain;
    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
}
