JavaFX 1.2 and input methods

One of the Features and Enhancements in JavaFX 1.2 is the API for dealing with input methods. Prior to the JavaFX 1.2 release, Nodes in a scene graph can only receive the result of the input method composition as a series of KeyEvents. With the new API introduced in JavaFX 1.2, Nodes can directly receive the input method composition information and do whatever they want with it.

The overall design of how the input methods work in JavaFX is pretty much analogous to the Input Method Framework in Java itself. By default, Nodes receive only the result of the input method composition through KeyEvents (as noted above), but once they extend the new TextInput mixin, then they are able to receive the whole input method composition information through the new InputMethodEvent, delivered in the user defined onInputMethodTextChanged() function. Here is a simple example of a Circle subclass that receives InputMethodEvent:


class InputMethodCircle extends Circle, TextInput {
    override var onInputMethodTextChanged = 
        function (e:InputMethodEvent): Void {
            println(e);
        };
}

The above code dumps the contents of InputMethodEvents to the console, whenever they are delivered.

An InputMethodEvent contains four variables, i.e., node on which this event has occurred, composed which is a sequence of InputMethodTextRun that represents the text in composition, committed which is the result of the composition, and caretPosition which designates the caret position inside the composed text. On receiving InputMethodEvents, applications would typically display the composed text with the visual feedback according to the InputMethodHighlight in each InputMethodTextRun, insert the committed text into applications text, and display the caret as suggested by caretPosition.

Here is another simple example that displays the contents of InputMethodEvents, with the color scheme shown at the top of the application ("U-R" denotes "unselected raw" highlight, and "S-C" for "selected converted" and so on). A little visualized version than the one above.

If you don't have input methods on your underlying operating system, you might want to try out input methods written in Java. How to use them are described in my old article.

HOWEVER, if you do not want to deal with such details, don't worry. The TextBox UI control is your friend. It has a built-in implementation for such behavior, so use it in your application and you can just call it a day :-)

Comments:

Post a Comment:
Comments are closed for this entry.
About

naotoj

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
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
   
       
Today
News

No bookmarks in folder

Blogroll