package forms.fd.utilities;

import java.awt.Cursor;
import oracle.forms.handler.IHandler;
import oracle.forms.properties.ID;
import oracle.forms.ui.VTextField;

  public class FJTextField extends VTextField 
  {
    public final static ID SETMAX       = ID.registerProperty("SETMAX");  
    public final static ID SETBLINKRATE = ID.registerProperty("SETBLINKRATE");    
    public final static ID SETCURSOR    = ID.registerProperty("SETCURSOR");    
    private   IHandler  m_handler;  
    
    public FJTextField ()
    {
       super();
    }

      
    public void init(IHandler handler)
    {
      m_handler = handler;
      super.init(handler);
    }      
    
    
    public boolean setProperty(ID property, Object value)
    {
      if (property == SETMAX)  // set the max length of the Text field
      {
        int iMax = Integer.parseInt(value.toString());
        if(this.getText().length() > iMax) setText(this.getText().substring(0,iMax));
        this.setMaximumChars(iMax);
        return true;
      }
      if (property == SETBLINKRATE)  // set the cursor blink rate
      {
        int i = Integer.parseInt(value.toString());
        this.setBlinkRate((long)i);
        return true;
      }   
      if (property == SETCURSOR)  // set the cursor type
      {
        String sCur = value.toString();
        if( sCur.equalsIgnoreCase("HAND")) this.setCursor(new Cursor(Cursor.HAND_CURSOR));
        else if( sCur.equalsIgnoreCase("DEFAULT")) this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));        
        else if( sCur.equalsIgnoreCase("MOVE")) this.setCursor(new Cursor(Cursor.MOVE_CURSOR));        
        else if( sCur.equalsIgnoreCase("TEXT")) this.setCursor(new Cursor(Cursor.TEXT_CURSOR));
        else if( sCur.equalsIgnoreCase("WAIT")) this.setCursor(new Cursor(Cursor.WAIT_CURSOR));                
        else if( sCur.equalsIgnoreCase("CROSS")) this.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
        return true;
      }        
      else
      {
       return super.setProperty(property, value);
      }
    }

  }
