Subversion Repositories eFlore/Applications.coel

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1620 aurelien 1
package org.tela_botanica.client.composants;
2
 
3
import java.util.List;
4
 
5
import com.extjs.gxt.ui.client.event.Events;
6
import com.extjs.gxt.ui.client.event.FieldEvent;
7
import com.extjs.gxt.ui.client.widget.form.NumberField;
8
import com.google.gwt.event.dom.client.KeyCodes;
9
 
10
public class ChampNombre extends NumberField {
11
 
12
	public int lastKeyCode;
13
	public List<Character> allowed;
14
 
15
	@Override
16
    protected void onKeyDown( FieldEvent fe )
17
    {
18
        super.onKeyDown( fe ) ;
19
        int keyCode = fe.getKeyCode( ) ;
20
 
21
        if( keyCode == 0 )
22
        {
23
            keyCode = fe.getEvent( ).getCharCode( ) ;
24
        }
25
 
26
        _setLastKeyCode( keyCode ) ;
27
    }
28
 
29
    @Override
30
    protected void onKeyPress( FieldEvent fe )
31
    {
32
        fireEvent( Events.KeyPress, new FieldEvent( this, fe.getEvent( ) ) ) ;
33
 
34
        int keyCode = fe.getKeyCode( ) ;
35
 
36
        char key = ( char )keyCode ;
37
 
38
        if( keyCode == 0 )
39
        {
40
            key = ( char )fe.getEvent( ).getCharCode( ) ;
41
        }
42
 
43
        if( fe.isSpecialKey( _getLastKeyCode( ) )
44
           || _getLastKeyCode( ) == KeyCodes.KEY_BACKSPACE
45
           || _getLastKeyCode( ) == KeyCodes.KEY_DELETE
46
           || fe.isControlKey( ) )
47
        {
48
            return ;
49
        }
50
 
51
        if( !_getAllowed( ).contains( key ) )
52
        {
53
            fe.stopEvent( ) ;
54
        }
55
    }
56
 
57
    private native int _getLastKeyCode( ) /*-{
58
       return this.@org.tela_botanica.client.composants.ChampNombre::lastKeyCode ;
59
    }-*/;
60
 
61
    private native void _setLastKeyCode( int keycode ) /*-{
62
        this.@org.tela_botanica.client.composants.ChampNombre::lastKeyCode = keycode ;
63
    }-*/;
64
 
65
    private native List<Character> _getAllowed( ) /*-{
66
        return this.@org.tela_botanica.client.composants.ChampNombre::allowed ;
67
    }-*/;
68
};