Rev 1637 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package org.tela_botanica.client.composants;
import java.util.List;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.FieldEvent;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.google.gwt.event.dom.client.KeyCodes;
public class ChampNombre extends NumberField {
public int lastKeyCode;
public List<Character> allowed;
@Override
protected void onKeyDown( FieldEvent fe )
{
super.onKeyDown( fe ) ;
int keyCode = fe.getKeyCode( ) ;
if( keyCode == 0 )
{
keyCode = fe.getEvent( ).getCharCode( ) ;
}
_setLastKeyCode( keyCode ) ;
}
@Override
protected void onKeyPress( FieldEvent fe )
{
fireEvent( Events.KeyPress, new FieldEvent( this, fe.getEvent( ) ) ) ;
int keyCode = fe.getKeyCode( ) ;
char key = ( char )keyCode ;
if( keyCode == 0 )
{
key = ( char )fe.getEvent( ).getCharCode( ) ;
}
if( fe.isSpecialKey( _getLastKeyCode( ) )
|| _getLastKeyCode( ) == KeyCodes.KEY_BACKSPACE
|| _getLastKeyCode( ) == KeyCodes.KEY_DELETE
|| fe.isControlKey( ) )
{
return ;
}
if( !_getAllowed( ).contains( key ) )
{
fe.stopEvent( ) ;
}
}
private native int _getLastKeyCode( ) /*-{
return this.@org.tela_botanica.client.composants.ChampNombre::lastKeyCode ;
}-*/;
private native void _setLastKeyCode( int keycode ) /*-{
this.@org.tela_botanica.client.composants.ChampNombre::lastKeyCode = keycode ;
}-*/;
private native List<Character> _getAllowed( ) /*-{
return this.@org.tela_botanica.client.composants.ChampNombre::allowed ;
}-*/;
};