

package uFCoderSimple;
import java.awt.event.*;
import javax.swing.*;
public class GLFunctions 
{
      private static final int KEYLENGTH=6;
      String[] ERR_CODE = new String[180];
      
 
     
  /** Dec to hex convesion and vice versa for textfields
   * 
   * @param pnlContainer   panel textbox fields
   * @param sKeyName       key name
   * @param evt            CheckBox Selected ? 
   */ 
  public void CheckBoxHexDec(JPanel pnlContainer,String sKeyName,java.awt.event.ItemEvent evt)
  {               
        for (int br = 0; br < pnlContainer.getComponentCount(); ++br) {
          if (pnlContainer.getComponent(br).getName() == sKeyName) {
              if (((JTextField) pnlContainer.getComponent(br)).getText().trim().isEmpty()) {
                  continue;
              } else {
                  if (evt.getStateChange() == ItemEvent.SELECTED) {
                      ((JTextField) pnlContainer.getComponent(br)).setText(Integer.toHexString(Short.parseShort(((JTextField) pnlContainer.getComponent(br)).getText())).toUpperCase());
                  } else {

                      ((JTextField) pnlContainer.getComponent(br)).setText(Integer.toString(Short.parseShort(((JTextField) pnlContainer.getComponent(br)).getText(), 16)));
                  }

              }
          }

      }
  }

  /**  Hex to dec conversion for keys
   *    
   * @param pnlContainer   panel container with dynamic textfields
   * @param sKeyName       name of key
   * @param CheckBox       which checkbox is selected?
   * @return               array of bytes
   */
  public byte[] DecHexConversionForKey(JPanel pnlContainer,String sKeyName,JCheckBox CheckBox)
  {
       byte bCountIndex=0;
       byte[]KEY=new byte[KEYLENGTH];
       
      if (CheckBox.isSelected()) {
          for (int iCounter = 0; iCounter <pnlContainer.getComponentCount(); iCounter++) {
              if (pnlContainer.getComponent(iCounter).getName() == sKeyName) {
                  KEY[bCountIndex] = (byte) Short.parseShort(((JTextField) pnlContainer.getComponent(iCounter)).getText(), 16);
                  bCountIndex++;
              }
          }
      } else {
          for (int iCounter = 0; iCounter < pnlContainer.getComponentCount(); iCounter++) {
             
              if (pnlContainer.getComponent(iCounter).getName() == sKeyName) {
                  KEY[bCountIndex] = (byte) Short.parseShort(((JTextField) (pnlContainer.getComponent(iCounter))).getText());
                  bCountIndex++;
              }
          }
      }
       return KEY;
  }
 /**  Filler bytes behind the entered string   
  *   
  * @param bGetBytesArray   
  * @param iDataLength
  * @param iMaxBytes
  * @return       
  */
  public byte[] WriteArray(byte[] bGetBytesArray,int iDataLength,int iMaxBytes)
        {
            byte[] bCloneArray = new byte[iMaxBytes];
            System.arraycopy(bGetBytesArray,0, bCloneArray,0, bGetBytesArray.length);
            for (int br = bGetBytesArray.length; br < iDataLength; br++)
            {
                bCloneArray[br] = 32;
            }
                                    
            return bCloneArray;

        }
  
  
  
}

