土曜日, 1月 19, 2008

Character.UnicodeBlock: To obtain the character set

In line with the InputContext article the other day to alter keyboard setting and the font range, I would like to present here the following code to obtain the character set and set the locale for the InputContext.

With the use of Character.UnicodeBlock.of(char), and the returned value of the UnicodeBlock information, the locale can be set -- manually. Suppose you have a JTextArea and the cursor is on the area of the text that you want to add some input.

Bopomofo (Zhuyin) is a set of alphabets that is universally used in Taiwan. In the following code, the character under the cursor is examined and the locale is set to Locale.TAIWAN if it is a Zhuyin character.


int pos=textArea.getCaretPosition();
String text=textArea.getText();
char ch=text.charAt(pos);
Character.UnicodeBlock block=Character.UnicodeBlock.of(ch);
Locale current=Locale.US;
if(block==Character.UnicodeBlock.BOPOMOFO)
current=Locale.TAIWAN;

RP2040 Zero で MicroPython を使う

  埋め込み用マイコンでも Python を動かせる MicroPython というものがあります。 リアルタイムでコマンドラインからマイコンを動かせる画期的なシステムなので、ちょっとした感動が味わえます。 使い方としては、まずファームウエアをアップロードしてドライブとして認識さ...