change the writing language to arabic when text field is clicked - java

The default writing language on my PC is English. What should I add to my code, so when I press on the text field in j frame, I want the writing language to convert automatically into Arabic. And when I press on another text field, I want it to return into English.

How the writting language affect your application? For example, in firefox I can change the writting language by right click on any box and change the language.
If your app needs to keep track the current language you need to save the language configuration somewhere (on a global variable or file), and perhaps make a good first guess reading it from the LANG environment variable.

Related

Option to change language in an android app

I'm building an android app where i have a settings activity.
In this settings Activity, I have a ListPreference with 3 values, each for a language.
I would like to get the value selected by the user and then change the language of the application according to the choice of the user
How would you do this guys ?
Thanks for reading and help !
The link in the comments above is the complete answer, but just to get you started, to support whatever language the user's device is set to, you need to extract all of the text in your app that will be visible on screen out to a 'strings.xml' file. Then translate all of the strings in that file into a separate 'strings.xml' file for each language you wish to support. This file lives in the res/values folder, and if you wanted to do a Spanish translation, you would create a res/values-es folder, and add a 'strings.xml' file there, with entries that have the same 'name' as the English translation, but with the Spanish translation as the 'value' example:
res/values/strings.xml
<string name="change_voter">Change Voter</string>
res/values-es/strings.xml
<string name="change_voter">Cambiar de Votantes</string>
//Then you get the value into your label like so:
tvVoter.setText(getResources().getText(R.string.change_voter));
You will also need to consider any graphics (bitmaps, backgrounds, buttons) and if they have words written in the default language, there will need to be copies of those translated into the other language and in another localized folder.

Sending Unicode Text to Cursor Position in Java

Doing linguistics and phonetics, I often need to use certain special phonetic symbols. Although I'm using a special keyboard layout that enables me to write some of those characters by typing, they key combinations can often get both quite complex and highly repetitive, so I would like to create a litle app that would contain some buttons, perhaps, each of them capable of sending a specified (phonetic) symbol to whatever the current cursor position is, no matter what window on one's screen is in focus.
Is anything of this sort possible to do in Java?
I've seen a solution that copies the values into clipboard and then pastes them (Java paste to current cursor position), but that is not a very clean way to do it, is it? Is there a way better than just pasting the charactedr(s) via ctrl+V?
Many thanks for any help or advice in advance!
P.
You can use the AWT Robot to generate key press events. This will not provided the ability to insert arbitrary unicode characters but you can combine it with the technique you already described: transfer the unicode characters to the clipboard and generate a CTRL+V key event afterwards. You can try to save and restore the original clipboard content but this will work with types supported by Java only.
The focus problem mentioned in the comments can be solved by setting the window to not receive the focus via Window.setFocusableWindowState with an argument of false.
An alternative is to provide the unicode text via drag&drop. Most applications support dropping text in their input fields. The code for exporting the text is very similar as both, clipboard and d&d use the same interfaces in Java.

How textbox identifies type of data and autocompletes it

I was wondering that the textbox itself identifies its type and when clicked inside textbox it gives the suggestion for that. For a instance i am creating a textbox for mobile no and when click inside the textbox it correctly detects it. Can anyone explain me how it was coded. It was browser feature or HTML feature?
Here is the Image explanation
This features of modern browsers is called auto-fill option, where the browser recognizes that you have performed a specific search before and suggests information that you have typed before. For sweepers, auto-fill saves a ton of time. When Roboform doesn't fill out a form for me, I usually only have to double-click in the text field and select the data I want from the drop-down list of options. This is particularly useful for daily sweepstakes that require codes.

Java Hyperlink to file in text editor

I have a question related to hyperlinks in java.
How can I set hyperlink in java file to point to another java file loaded on the text editor in Eclipse, when I have the filename and code line:
ex. Test.java:102
How to show the given code line of that file on the text editor?
Thank you!
The Java language does not know hyperlinks.
JavaDoc does know hyperlinks, which you can easily access in the Eclipse editor by typing either the # sign and choose a local member or by typing the name of an external class and hitting controlspace, then choose the right link.
Fortunately, you cannot directly create links to lines. Lines change in time, the contract of the class (the description of the methods/fields) is what should remain relatively static. When configured correctly, Eclipse will even change your links if you refactor your code (e.g. rename your method or class).
You cannot create hyperlinks to lines -afaik, but you can create links to fields or functions in javadoc:
/**
* {#link package.ClassName#fieldOrFunction}
*/
doing it like that allows you to ctrl-click on the "fieldOrFunction" and jumps right there (at least in eclipse)
2 years later, I know...
If you are looking for hyperlinks from any file surround it with parenthesis like so
(AnotherClass.java:52)
ctrl click will take you there if it knows of that class.

English characters don't show up when entering text with Urdu fonts in Swing

This is similar to my own previous question, but that solution didn't work here.
As mentioned in the previous question, I'm working on a cross platform(Windows/Ubuntu) application that has to transliterate English into one of several official Indian languages. The application has a custom input method, and typing in English and pressing space will transliterate the typed text into the specific local language. Urdu is different from the others in being right to left, like Arabic/Hebrew.
I managed to find an open licensed Urdu font that has both English and Urdu glyphs, but when I type characters in English, nothing shows up.
I don't understand whether it's a font painting issue, or related to the input method. So far, if I disable the custom input method (InputMethod.dispatchEvent() ) for this language, I am able to see the English text (but of course no transliteration takes place).
My findings:
Change font to one of Windows' built in Arabic fonts - same result.
Instead of using ComponentOrientation to align text in the text field, I used setHorizontalAlignment for when the locale is Urdu. Same result.
Decompiled the JDK's default input method provider on Windows (sun.awt.windows.WInputMethod). Here I see the dispatchEvent() makes a native call to the OS for handling IME. I can't do that here.
Found a custom IM for Hebrew - my version of dispatchEvent() is essentially the same.
Stepped through code for JTextField in Eclipse - wasn't able to find anything in the AbstractDocument and subclasses. The AbstractDocument.insertUpdate() method checks for and updates bidirectional text input, but there wasn't anything else significant.
I'm unable to understand what happens after the dispatchEvent() call. The characters are being registered, i.e. the transliteration engine is able to detect the typed characters and process them, but they just don't show up on screen.
Workaround
If I let the text field's orientation be as it is for regular left to right languages, I can see the English text. However, this would not be acceptable to an Urdu speaking user.
Can someone point me in the right direction?
I set the locale to ur_IN.
Sadly, ur_IN is not among the supported locales; I only see en_IN and hi_IN. In the example cited, I used the following code to get the image below:
spinner.setLocale(new Locale("hi", "IN"));

Categories