java.text.AttributedCharacterIterator.Attribute.READING doesn't return
correct values from InputMethodEvent when turning TSF (Text Services
Framework) on. Java depends on IMM32 APIs although not still supported by
Microsoft.
---------------------BEGIN SOURCE---------------------------------------------------------
import java.text.AttributedCharacterIterator;
import java.awt.event.InputMethodEvent;
import java.awt.event.InputMethodListener;
import javax.swing.JTextField;
import javax.swing.JFrame;
public class IME {
public static void main(String ... arg) throws Exception {
final JTextField t2 = new JTextField();
t2.setLocation(100, 140);
t2.setSize(200, 30);
t2.setEditable(false);
JTextField t1 = new JTextField();
t1.setLocation(100, 100);
t1.setSize(200, 30);
t1.addInputMethodListener(new InputMethodListener() {
public void caretPositionChanged(InputMethodEvent event) {}
public void inputMethodTextChanged(InputMethodEvent event) {
AttributedCharacterIterator itr = event.getText();
if (itr != null) {
int toCopy = event.getCommittedCharacterCount();
itr.first();
StringBuilder yomi = new StringBuilder(t2.getText());
while (toCopy-- > 0) {
if (itr.getIndex() == itr.getRunStart(AttributedCharacterIterator.Attribute.READING)) {
java.text.Annotation obj = (java.text.Annotation)itr.getAttribute(AttributedCharacterIterator.Attribute.READING);
yomi.append(obj.getValue());
}
itr.next();
}
t2.setText(yomi.toString());
}
}
});
JFrame fr = new JFrame();
fr.setSize(700, 500);
fr.setLayout(null);
fr.add(t1);
fr.add(t2);
fr.setVisible(true);
}
}
---------------------ENDSOURCE---------------------------------------------------------
Expected behavior.
Steps to run:
(0) Use IME which supports IMM32 such as OFFICE-IME, and make the setting of
using TSF off.
(1) Type 'a', 'b', 'e', and blank and blank at the first text field.
(2) A drop-down box appears and several candidates are listed.
(3) Select the third one by using down arrow key.
Be careful not to use enter key here.
(4) Type 's', 'i', 'n', 'z', 'o', 'u'.
At this point, the yomigana of "abe" is displayed at the second text
field.
(5) Type blank, and select proper one, and type enter key.
the yomigana of both "abe" and "sinzou" are displayed.
Actual behavior:
Steps to run:
(0) Use IME which supports TSF such as MS-IME, and make the setting of using
TSF on.
(1) Type 'a', 'b', 'e', and blank and blank at the first text field.
(2) A drop-down box appears and several candidates are listed.
(3) Select the second one by using down arrow key.
Be careful not to use enter key here.
(4) Type 's', 'i', 'n', 'z', 'o', 'u'.
At this point, the yomigana of "abe" is NOT displayed at the second text
field.
(5) Type blank, and select proper one, and type enter key.
Only the yomigana of "sinzou" is displayed.