package oracle.forms.fd;

import java.awt.Cursor;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.net.URL;
import oracle.forms.handler.IHandler;
import oracle.forms.properties.ID;
import oracle.forms.ui.VTextField;


/**
 * A Text area with a custom cursor
 * October 2006
 * @author Francois Degrelle
 * @version 1.0
 */
 
  public class JTextFieldIcon extends VTextField 
  {
    public final static ID SETCURSOR    = ID.registerProperty("SETCURSOR");    
    private   IHandler  m_handler;  
    private   boolean   bLog = true ;
    private   URL       m_codeBase;  
    private   URL       imageURL = null;
    
    public JTextFieldIcon ()
    {
       super();
    }

      
    public void init(IHandler handler)
    {
      m_handler = handler;
      super.init(handler);
    }      
    
    /*
     * Properties you can set
     */
    public boolean setProperty(ID property, Object value)
    {
      if (property == SETCURSOR)  // set the cursor type
      {
        String sImgName = value.toString();
        Cursor c; 
        Toolkit tk = Toolkit.getDefaultToolkit(); 
        // get cursor image from jar file
        imageURL = getClass().getResource(sImgName);
        if (imageURL != null)
        {
          log("URL: " + imageURL.toString());
           try
           {
             Image image = Toolkit.getDefaultToolkit().getImage(imageURL);
             log("Image found: " + imageURL.toString());
             // create custom cursor
             c = tk.createCustomCursor(image, new Point(0,0),"cursorName"); 
             // attach cursor to text item
             this.setCursor(c);             
           }
           catch (Exception ilex)
           {
            log("Error loading image from JAR: " + ilex.toString());
           }
        }
        else
        {
           log("Unable to find " + sImgName + " in JAR");
        }
        return true;
      }  
      
      else
      {
       return super.setProperty(property, value);
      }
    }


  void log( String sMessage )
  {
    if( bLog) System.out.println( sMessage ) ;
  }




  }
