package oracle.forms.fd;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.StringTokenizer;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import oracle.forms.engine.Main;
import oracle.forms.ui.CustomEvent;
import oracle.forms.ui.VBean;
import oracle.forms.handler.IHandler;
import oracle.forms.properties.ID;
import sun.misc.BASE64Encoder;
import sun.misc.BASE64Decoder;

    /**
     * A javabean that read/display/write images
     * 
     * image can be read from file system or database BLOB column
     * image can be written to database BLOB column
     * image can be scaled to fit the display size
     * 
     * needs no JDBC connexion to read/write images
     * to/from the database
     * 
     * @author Francois Degrelle
     * @version 1.7
     *
     * add the SETBORDER method
     * can save images read from JAR and Internet URLs to the database
     * bug correction : decembre 2008
     *     issue with the CLEAR method when bean used in multi-record block
     */

    public class HandleImage   extends VBean
    {
      public final static ID SETPOS            = ID.registerProperty("SETPOS");   
      public final static ID SETBG             = ID.registerProperty("SETBG");   
      public final static ID SETLOG            = ID.registerProperty("SETLOG");   
      public final static ID CLEAR             = ID.registerProperty("CLEAR");   
      public final static ID GETSIZE           = ID.registerProperty("GETSIZE");     
      public final static ID GETMODIFIER       = ID.registerProperty("GETMODIFIER");           
      public final static ID READIMGBASE       = ID.registerProperty("READIMGBASE");         
      public final static ID READIMGFILE       = ID.registerProperty("READIMGFILE");         
      public final static ID GETIMAGE          = ID.registerProperty("GETIMAGE");               
      public final static ID SCALEIMAGE        = ID.registerProperty("SCALE_IMAGE");               
      public final static ID SETSCROLL         = ID.registerProperty("SETSCROLL");               
      protected static final ID SETBORDER      = ID.registerProperty("SETBORDER");
      protected static final ID SETFILECHOOSER = ID.registerProperty("SET_FILECHOOSER_TITLE");
      protected static final ID SETCHOOSERLAF  = ID.registerProperty("SET_FILECHOOSER_LAF");
      protected static final ID GETFILENAME    = ID.registerProperty("GET_FILE_NAME");

      public final static ID INIT              = ID.registerProperty("INIT");   
      public final static ID KEYTYPED          = ID.registerProperty("KEY_PRESSED");   
      public final static ID KEYCODE           = ID.registerProperty("KEY_CODE");   
      public final static ID KEYCHAR           = ID.registerProperty("KEY_CHAR");   
      public final static ID KEYMOD            = ID.registerProperty("KEY_MODIFIER");         
      
      private   String      sFileChooserTitle = "Select an image file" ;
      private   String      sFileStartDir = "" ;
      private   IHandler    m_handler; 
      private   ImagePanel  mp = null ;
      private   JScrollPane jsp = null ;      
      private   Image       imgReal  = null ;
      private   Image       imgShown = null ;
      private   String      sChooserLAF = "SYSTEM" ;
      private   Color       cDefaultColor ;
      private   boolean     bLog = false ;
      private   boolean     bImg = false ;
      private   URL         m_codeBase;
      private   File        file_image = null ;
      private   FileInputStream fis = null ;
      private   int         iMageSize = 0 ;
      private   int         numBytesRead = 0;
      private   int         iScaleWidth=-1, iScaleHeight=-1 ;
      private   int         iImgStart=0, iImgEnd=0 ;
      private   byte[]      bImage ;
      private   StringBuffer sbImage =new StringBuffer();

      private   KeyListener kl ;     
      private   Main         formsMain = null;
      private   char        cChar ;
      private   int         iModifier = 0 ;
      private   String      sModifier = "" ;      
      
      public HandleImage()
      {
         super();
      }
       
      public void init(IHandler handler)
      {
        m_handler = handler;
        super.init(handler);
        try
        {
          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
          SwingUtilities.updateComponentTreeUI(this);
        }
        catch (Exception ex)
        {
          ex.printStackTrace();
        }             
        // create the panel
        mp = new ImagePanel(this.getWidth(),this.getHeight()) ;
        mp.setVisible(true);
        mp.setBorder(BorderFactory.createEmptyBorder());
        // create the JScrollPane and associate with the panel
        jsp =  new JScrollPane(mp) ;
        jsp.setPreferredSize(new Dimension(this.getWidth(),this.getHeight()));
        jsp.setVisible(true);
        jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
        jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        add(jsp);
        setKeyListener();
        formsMain  =  (Main) handler.getApplet();
      }     
  
 
      /**----------------------------------*
       *  set the properties of the bean   *
       *-----------------------------------*/
      public boolean setProperty(ID property, Object value)
      {
        if(property == ID.VISIBLE && cDefaultColor == null)
        {
          cDefaultColor = this.getParent().getBackground() ;
        }
        
        if(property == INIT)
        {
          getTextItems(formsMain.getFrame(),0);
          return true ;
        }
        //
        // read an image from a file
        //
        if (property == READIMGFILE)  
        {
          String sFileName = value.toString() ;
          imgReal = loadImage( sFileName ) ;
          if(imgReal == null) return false;
          bImg = true ;
          bImage = imageIconToByteArray(new ImageIcon(imgReal));
          if((iScaleWidth != 0) && (iScaleHeight != 0))
          {
            ImageIcon icon = new ImageIcon(imgReal.getScaledInstance(iScaleWidth, iScaleHeight, Image.SCALE_SMOOTH));
            imgShown = icon.getImage();
            mp.setImage(imgShown) ;
          }
          else
            mp.setImage(imgReal) ;
          mp.repaint();
          return true;
        }
        
        //
        // read an image from the database
        //
        else if (property == READIMGBASE)  
        {        
            String sImage = value.toString();
            if(!sImage.equalsIgnoreCase("[END_IMAGE]"))
            {
              sbImage.append(sImage) ;
            }
            else
            {
              BASE64Decoder decoder = new BASE64Decoder();
              try{
                byte[] decodedStr = decoder.decodeBuffer(sbImage.toString());
                ImageIcon ii = new ImageIcon(decodedStr);
                imgReal = ii.getImage() ;
                bImage = imageIconToByteArray(new ImageIcon(imgReal));
                fis = null ;
                if((iScaleWidth != 0) && (iScaleHeight != 0))
                {
                    ImageIcon icon = new ImageIcon(imgReal.getScaledInstance(iScaleWidth, iScaleHeight, Image.SCALE_SMOOTH));
                    imgShown = icon.getImage();
                    mp.setImage(imgShown) ;
                }
                else 
                   mp.setImage(imgReal) ;  
                mp.repaint();   
              } catch(Exception e){;}
              finally{ sbImage =new StringBuffer(); }
            }
            return true ;
        }
        
        
        //
        // set the border
        //
        else if (property == SETBORDER) 
        {
          String s = value.toString() ;
          String s1="", s2=null ;
          Color c = Color.white ;
          int iThick=0 ;
          StringTokenizer st = new StringTokenizer(s,",");
          if(st.hasMoreTokens()) s1 = st.nextToken() ;
          else return false ;
          if(st.hasMoreTokens()) s2 = st.nextToken() ;
          if(s1.equalsIgnoreCase("0")) jsp.setBorder(BorderFactory.createEmptyBorder());
          else iThick = Integer.parseInt(s1) ;
          if(s2 != null)
          {
            c = makeColor(s2);
            jsp.setBorder(BorderFactory.createLineBorder(c,iThick));
          }  
          return true;
        }

        //
        // set the position of the image
        //
        else if (property == SETPOS) 
        {
          int iPos = new Integer((String)value).intValue() ;
          return true;
        }
        
        //
        // set the background color
        //
        else if (property == SETBG) 
        {
          String color = value.toString().trim();
          int r=-1, g=-1, b=-1, c=0 ;
          StringTokenizer st = new StringTokenizer(color,",");
          while (st.hasMoreTokens()) {
                   c = new Integer((String)st.nextToken()).intValue()  ;
                   if( (c <0) || (c > 255) ) c = 0 ;
                   if( r == -1 ) r = c ;
                   else if( g == -1 ) g = c ;
                   else if( b == -1 ) b = c ;
                 }
          mp.setBGColor(new Color(r, g, b)) ;
          return true;
        }

        //
        // clear the image
        //
        else if (property == CLEAR) 
        {
          log("Clear image") ;          
          imgReal = null ;
          imgShown = null ;
          mp.setImage(null) ;
          mp.repaint();
          return true;
        }

        //
        // image scaling
        //
        else if (property == SCALEIMAGE)  
        {
          String s   = value.toString();
          String tok = "" ;
          log("SCALE_IMAGE="+s);
          StringTokenizer st = new StringTokenizer(s,",");
          while(st.hasMoreTokens())
          {
            tok = st.nextToken().toUpperCase() ;
            // width ?
            if(tok.startsWith("WIDTH="))
            {
              tok = tok.substring(6);
              if(tok.equalsIgnoreCase("FIT"))
              {
                log("jsp Width="+jsp.getSize());
                iScaleWidth = (int)jsp.getSize().getWidth();
              }
              else
              {
                try
                {
                  iScaleWidth = Integer.parseInt(tok);
                  if(iScaleWidth < -1) iScaleWidth = 0 ;
                }
                catch (Exception e) {
                  System.out.println( "SCALE_IMAGE : bad Width integer value provided") ;
                  return false ;
                }
              }
              log("Scale Width="+iScaleWidth);
            }
            // height ?
            if(tok.startsWith("HEIGHT="))
            {
              tok = tok.substring(7);
              if(tok.equalsIgnoreCase("FIT"))
              {
                iScaleHeight = (int)jsp.getSize().getHeight();
              }              
              else
              {
                try
                {
                  iScaleHeight = Integer.parseInt(tok);
                    if(iScaleHeight < -1) iScaleHeight = 0 ;
                }
                catch (Exception e) {
                  System.out.println( "SCALE_IMAGE : bad Height integer value provided") ;
                  return false ;
                }          
              }
              log("Scale Height="+iScaleHeight);
            }
          }
          return true;
        }
        
        //
        // set the FileChooser title and starting directory
        //
        else if(property ==SETFILECHOOSER) {
            String s = (String)value ;
            StringTokenizer st = new StringTokenizer(s,",");
            if(st.hasMoreTokens()) sFileChooserTitle = st.nextToken() ;
            if(st.hasMoreTokens()) sFileStartDir = st.nextToken() ;
            return true ;
        }
        
        //
        // set the JFileChooser L&F
        //
        else if(property==SETCHOOSERLAF) {
            sChooserLAF = (String)value ;
            return true ;
        }
        
        //
        // show/hide the scrollbars
        //
        else if (property == SETSCROLL) 
        {
          String s = (String)value ;
          if( s.equalsIgnoreCase("TRUE"))
          {
            jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
            jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
          }
          else 
          {
            jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
            jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
          }            
          return true;
        }        
        
        //
        // set the log flag to output the messages on the console
        //
        else if (property == SETLOG) 
        {
          String s = (String)value ;
          if( s.equalsIgnoreCase("TRUE"))
          {
            bLog= true ;
          }
          else 
          {
            bLog = false ;
          }            
          return true;
        }        
        
        else
        {
         return super.setProperty(property, value);
        }
      }

      /**----------------------------------*
       * Get the properties from the bean  *
       *-----------------------------------*/
      public Object getProperty(ID pId) 
      {
        //
        // returns image size
        //
        if( pId == GETSIZE)
        {
          int w=0, h=0 ;
          //return "" + mp.getImageWidth()+","+mp.getImageHeight() ;
          if(imgReal != null)
          {
            ImageIcon icon = new ImageIcon(imgReal);
            w = icon.getIconWidth();
            h = icon.getIconHeight() ;
          }
          return  "" + w + "," + h ;
        }
        //
        // returns selected filename
        //
        else if(pId == GETFILENAME)
        {
          GetImageFileName gifn = new GetImageFileName() ;
          gifn.SetLAF(sChooserLAF.toUpperCase());
          return gifn.GetFile(sFileChooserTitle,sFileStartDir) ;
        }
        
        //
        // returns the current image chunks
        //
        else if(pId == GETIMAGE)
        {         

          try {
              log("Start GetImage()") ;
              BASE64Encoder encoder = new BASE64Encoder();
              if(fis != null)
              {
                byte[] buf = new byte[16384];           
                if ((numBytesRead = fis.read(buf)) != -1) {
                  log("Send chunk:"+numBytesRead);
                  return encoder.encodeBuffer(buf);
                }
                else
                {
                  numBytesRead = 0;
                  return "" ;
                }
              }
              else
              {
                if(numBytesRead < bImage.length)
                {
                  if((numBytesRead + 16384) < (bImage.length-1))
                  {
                    iImgEnd = numBytesRead + 16384 ;
                  }
                  else iImgEnd = bImage.length-1 ;
                  byte[] buf = new byte[16384];
                  int j=0 ;
                  for (int i=iImgStart; i<iImgEnd;i++)
                    buf[j++] = bImage[i] ;
                  iImgStart += iImgEnd ;
                  numBytesRead += iImgEnd ;
                  return encoder.encodeBuffer(buf);  
                }
                else
                {
                  iImgStart = iImgEnd = 0 ;
                  numBytesRead = 0;
                  return "" ;
                }  
              }
          }          
          catch (Exception e) {
               System.out.println( e.toString()) ;
          }          

          return "" ;
        }
        
        else
        {
          return super.getProperty(pId);
        }
      }
     
    /*--------------------------------------------------------------*
     *  Load an image from JAR file, Client machine or Internet URL 
     *--------------------------------------------------------------*/
    private Image loadImage(String p_imageName)
    {
      URL imageURL = null;
      boolean loadSuccess = false;
      Image img = null ;
      String imageName = p_imageName ;
      imageName = p_imageName ;
      fis = null ;
  
      // add    
      try {
      file_image = new File( imageName );
      fis = new FileInputStream( file_image );
      }
      catch( Exception e )
          {
            System.out.println("loadImage:"+e.toString());
          }      
      iMageSize = ( int )file_image.length() ;
      //JAR
      log("Searching JAR for " + imageName);
      imageURL = getClass().getResource(imageName);
      if (imageURL != null)
      {
        log("URL: " + imageURL.toString());
        try
        {
          img = Toolkit.getDefaultToolkit().getImage(imageURL);
          loadSuccess = true;
          log("Image found in JAR: " + imageURL.toString());
          return img ;
        }
        catch (Exception ilex)
        {
          log("Error loading image from JAR: " + ilex.toString());
        }
      }
      else
      {
        log("Unable to find " + imageName + " in JAR");
      }

      //DOCBASE
      if (loadSuccess == false)
      {
        imageName = "file:///" + p_imageName ;
        log("Searching docbase for " + p_imageName);
        try
        {
         if(p_imageName.toLowerCase().startsWith("http://")||p_imageName.toLowerCase().startsWith("https://"))
          {
            log("trying to read:"+p_imageName);
            imageURL = new URL(p_imageName);
          }
          else if(imageName.toLowerCase().startsWith("file:"))
          {
            imageURL = new URL(imageName);
          }
          else
          {
            imageURL = new URL(m_codeBase.getProtocol() + "://" +m_codeBase.getHost() + ":" + m_codeBase.getPort() + imageName);
          }
          log("Constructed URL: " + imageURL.toString());
          try
          {
            if(imageURL != null)
            {
              img = Toolkit.getDefaultToolkit().getImage(imageURL);
              loadSuccess = true;
              log("Image found in DOCBASE: " + imageURL.toString());
              return img ;
            }
            else
               System.out.println("imageURL == null");
          }
          catch (Exception ilex)
          {
            log("Error reading image - " + ilex.toString());
          }

        }
        catch (java.net.MalformedURLException urlex)
        {
          log("Error creating URL - " + urlex.toString());
        }
      }

      //CODEBASE
      if (loadSuccess == false)
      {
        log("Searching codebase for " + imageName);
        try
        {
          imageURL = new URL(m_codeBase, imageName);
          log("Constructed URL: " + imageURL.toString());
          try
          {
            img = Toolkit.getDefaultToolkit().getImage(imageURL);
            loadSuccess = true;
            log("Image found in CODEBASE: " + imageURL.toString());
            return img ;
          }
          catch (Exception ilex)
          {
             log("Error reading image - " + ilex.toString());
          }
        }
        catch (java.net.MalformedURLException urlex)
        {
          log("Error creating URL - " + urlex.toString());
        }
      }

      if (loadSuccess == false)
      {
        System.out.println("Error image " + imageName + " could not be located");
      }
      return img ;
    }
    


    /*-------------------------------*
     * method to transform an image
     * to a byte[] array
     *-------------------------------*/
    private byte[] imageIconToByteArray(ImageIcon icon) {

    BufferedImage bi=new BufferedImage(icon.getImage().getWidth(null),
    icon.getImage().getHeight(null), BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.createGraphics();

    g.drawImage(icon.getImage(), 0, 0, null);
    g.dispose();

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    try {
      ImageIO.write(bi, "jpeg", stream);
    } catch (IOException ex1) {;}

    return stream.toByteArray();

    } 
    
  /**----------------------------*
   *  A panel to draw the image  *
   *-----------------------------*/
  class ImagePanel extends JPanel
  {
    private Image  img = null ;
    private Color  colorBG = null ;
    private int    iImageWidth = 0, iImageHeight = 0 ;
    private int    iInitialWidth = 0, iInitialHeight = 0 ;
    
    ImagePanel( int iWidth, int iHeight)
    {
      iInitialWidth  = iWidth ;
      iInitialHeight = iHeight ;
      this.setPreferredSize(new Dimension(iInitialWidth,iInitialHeight));
    }
    
    // set the image
    void setImage( Image p_image )
    {
      img = p_image ;
      if( img != null )
      {
        ImageIcon ii = new ImageIcon(img) ;
        iImageWidth  = ii.getIconWidth() ;
        iImageHeight = ii.getIconHeight() ;    
        // ajust the panel size to the new image size
        this.setPreferredSize(new Dimension(iImageWidth,iImageHeight));
      }
      else
      {
         // restore panel size to its initial values
         this.setPreferredSize(new Dimension(iInitialWidth,iInitialHeight)) ;
         iImageWidth = iImageHeight = 0 ;
         img = null ;
      }
      this.revalidate();
    }
    
    // set the background color
    void setBGColor( Color p_color )
    {
      colorBG = p_color ;
    }
    
    // get the image width
    int getImageWidth()
    {
      return iImageWidth ;
    }  
    
    // get the image height
    int getImageHeight()
    {
      return iImageHeight ;
    }    
    
    // draw the image
    protected void paintComponent(Graphics g) {
      if( colorBG != null )
      {
         g.setColor(colorBG);
      }  
      else g.setColor(cDefaultColor);
      g.fillRect(0, 0, this.getWidth(), this.getHeight());
      // draw image
      if( img != null ) g.drawImage(img, 0, 0, this); 

    }  
  }

    
  /*----------------------------------------*
   *  Make a color from a RGB string
   *  Color c = makeColor( "r128g25b100" ); 
   *----------------------------------------*/
  Color makeColor(String s)
  {
    int r=-1, g=-1, b=-1 ;
    String sR = "255", sG = "255", sB = "255" ;
    int iR=255, iG=255, iB=255 ;
    Color c = Color.white ;
    r = s.indexOf("r") ;
    g = s.indexOf("g") ;
    b = s.indexOf("b") ;
    if( r>-1 && g>-1 && b>-1 )
    {
      iR = Integer.parseInt(s.substring(r+1,g)) ;
      iG = Integer.parseInt(s.substring(g+1,b)) ;
      iB = Integer.parseInt(s.substring(b+1)) ;
      try
      {
        c = new Color(iR,iG,iB) ;
      }
      catch( Exception e) {} ;
    }
    return c ;
  }
  
  public void log( String sMessage )
  {
    if( bLog) System.out.println( sMessage ) ;
  }   


protected void getTextItems(Component component, int iter)
{    
    //System.out.println("->"+component.getClass().getName());
    if (component.getClass().getName().equals("oracle.forms.ui.VTextField"))
     {
      oracle.forms.ui.VTextField vt = (oracle.forms.ui.VTextField)component ;
      vt.addKeyListener(kl);
     }
    else if (component.getClass().getName().equals("oracle.forms.ui.VTextArea"))
     {
      oracle.forms.ui.VTextArea ta = (oracle.forms.ui.VTextArea)component ;
      ta.addKeyListener(kl);
     }     
  if (component instanceof Container)
      { 
      Component components[] = ((Container)component).getComponents(); 
      iter++;
      for (int i = 0; i < components.length; i++)
          { if (components[i] != null)
               { getTextItems(components[i],iter);}
          }
       }
}
   /*---------------------------------------*
    *   create a KeyListener for the items
    *---------------------------------------*/
   void setKeyListener()
   {
        kl = new KeyListener(){
	       public void keyPressed(KeyEvent e) {
            // get the code
            int iKey = e.getKeyCode() ;
            // get the character
            cChar = e.getKeyChar() ;
            // get the modifier
            iModifier = e.getModifiers();
            sModifier = KeyEvent.getKeyModifiersText(iModifier);
            /*
             * Inform Forms that a character was typed
             */
             try{
               m_handler.setProperty(KEYCODE, ""+iKey);
               m_handler.setProperty(KEYCHAR, ""+cChar);
               m_handler.setProperty(KEYMOD, sModifier);
             }
             catch (Exception ex) 
              {
                System.out.println("DispatchKeyEvent -> exception while dispatching: " + ex.toString());
              }           
             CustomEvent ce = new CustomEvent(m_handler, KEYTYPED);
             dispatchCustomEvent(ce);  
             switch(iKey)
             {
                case KeyEvent.VK_ENTER:
                case KeyEvent.VK_BACK_SPACE:
                case KeyEvent.VK_TAB:
                case KeyEvent.VK_CANCEL:
                case KeyEvent.VK_CLEAR:
                case KeyEvent.VK_SHIFT:
                case KeyEvent.VK_CONTROL:
                case KeyEvent.VK_ALT:
                case KeyEvent.VK_PAUSE:
                case KeyEvent.VK_CAPS_LOCK:
                case KeyEvent.VK_ESCAPE:
                case KeyEvent.VK_PAGE_UP:
                case KeyEvent.VK_PAGE_DOWN:
                case KeyEvent.VK_UP:
                case KeyEvent.VK_DOWN:
                case KeyEvent.VK_F1:
                case KeyEvent.VK_F2:
                case KeyEvent.VK_F3:
                case KeyEvent.VK_F4:
                case KeyEvent.VK_F5:
                case KeyEvent.VK_F6:
                case KeyEvent.VK_F7:
                case KeyEvent.VK_F8:
                case KeyEvent.VK_F9:
                case KeyEvent.VK_F10:
                case KeyEvent.VK_F11:
                case KeyEvent.VK_F12:            
                case KeyEvent.VK_F13:
                case KeyEvent.VK_F14:
                case KeyEvent.VK_F15:
                case KeyEvent.VK_F16:
                case KeyEvent.VK_F17:
                case KeyEvent.VK_F18:            
                case KeyEvent.VK_F19:
                case KeyEvent.VK_F20:
                case KeyEvent.VK_F21:
                case KeyEvent.VK_F22:
                case KeyEvent.VK_F23:
                case KeyEvent.VK_F24:                        
                try
                   {
                     m_handler.setProperty(KEY_EVENT, e);
                   }
                catch ( Exception ex ){ System.out.println("Unable to send key to Forms");}                        
                 }
           }
           public void keyReleased(KeyEvent e) {
           }
           public void keyTyped(KeyEvent e) {
           }
        };             
   }    



}     
