My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* vnkeys - support typing Vietnamese in flash input without preinstalled software
* Copyright (C) 2009 Nguyen Van Nhu
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.vnmedia.flex
{
import flash.events.KeyboardEvent;
import flash.events.TextEvent;
import flash.text.TextField;

import mx.controls.TextInput;

import org.vnmedia.vnkeys.IKeyConverter;
import org.vnmedia.vnkeys.KeyConverter;
import org.vnmedia.vnkeys.mapping.ReplacedWord;
import org.vnmedia.vnkeys.mapping.VNIMap;

public class FlexTextInput extends TextInput
{
private var converter:KeyConverter;
/**
* This is a text copy of TextInput
* This is a special solution for Flex TextArea and TextInput
*/
private var cpField:TextField;

private var eTextEvent:TextEvent;

public function FlexTextInput() {
super();
this.initKeyConveter();
this.addEventListener(KeyboardEvent.KEY_UP,this.onKeyUp);
this.addEventListener(TextEvent.TEXT_INPUT,this.onTextEvent);

}
/**
* Initiate KeyConverter
* Initiate a TextField for passing the text to KeyConverter
*
*/
private function initKeyConveter():void {
this.cpField = new TextField();
this.converter = new KeyConverter(this.cpField, VNIMap.NAME);
}
/**
* Return KeyConverter for mainly switching on/off
*
* @return IKeyConverter
*
*/
public function getKeyConverter():IKeyConverter {
return this.converter;
}
/**
* This is for setting mapping type via flex syntax
* <flex:FlexTextInput id="text" y="120"
* vnkeyType="VNI" x="50" width="220">
*
* @param type
*
*/
public function set vnkeyType(type:String):void {
this.converter.setMapType(type);
}

/**
*
* First converting, then remove the latest text-input
*
* @param e
*
*/
private function onKeyUp(e:KeyboardEvent):void {
this.cpField.text = this.text;
this.cpField.setSelection(this.textField.caretIndex - 1,this.textField.caretIndex-1);
this.converter.convert(e);
var word:ReplacedWord = this.converter.getReplacedWord();
this.converter.replaceWord(this.eTextEvent);
if (!word.isReversed && word.isReplaced) {
this.cpField.replaceText(cpField.caretIndex,cpField.caretIndex+1,'');
}
this.text = this.cpField.text;
}
/**
* listen for TextEvent.TEXT_INPUT
* We don't really need this
*
* @param e
*
*/
private function onTextEvent(e:TextEvent):void {
this.eTextEvent = e;// fire earlier; save and wait
}
}
}

Change log

r12 by van.nhu.nguyen on Oct 28, 2009   Diff
Finshed comments
Go to: 
Project members, sign in to write a code review

Older revisions

r11 by van.nhu.nguyen on Oct 26, 2009   Diff
Added comments
r9 by van.nhu.nguyen on Oct 25, 2009   Diff
Branch for release. VIQR is not
supported and will be removed
r8 by van.nhu.nguyen on Oct 25, 2009   Diff
Prepare and some fix for the first rc
All revisions of this file

File info

Size: 3256 bytes, 109 lines
Powered by Google Project Hosting