java - using DocumentFilter.replace with unicode characters -


i building gui 1 textfield must typed in latin characters, others in arabic. avoid switching keyboard layout, choosed maintain in arabic , use documentfilter in particular textfield replace arabic characters counterpart according latin azerty layout. example, if 1 types '\u0628' (it 'ب'), should printed 'f' because in in same key. worked fine characters except b key, translates two characters "لا" in arabic layout, , documentfilter.replace called 2 times each character. there way control size of text argument when replace called? other solution problem?

here original documentfilter.replace code

... private static char[] latin = {'a','z','e','r','t','y','u','i','o','p',...}; private static char[] arabic = {'\u0636','\u0635','\u062b','\u0642','\u0641',...}; ...     (plaindocument) txtfileid.getdocument().setdocumentfilter(new documentfilter() {     @override     public void replace(documentfilter.filterbypass fb, int offset,int length, string text, attributeset attr) throws badlocationexception {     stringbuilder sb = new stringbuilder();     int i=0;     if (text.length()==1) {         while (text.charat(0)!=arabic[i] && i<arabic.length)         i++;     if (text.charat(0)==arabic[i])         sb.append(latin[i]);     }     if (text.length()==2) {         if (text.equals(new string(new char[]{'\u0627','\u0644'})))         sb.append('b');     }     super.insertstring(fb, offset, sb.tostring(), attr); } 

thanks you!

how creating global variable keep track of whether callback has been called b event? can simple boolean flag flips each time b event generated. output b when flag true.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -