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.
Related
I have a text editor in which the user can define a pattern for data. A pattern can contain a reference to another pattern. A simple example would be { name: $pattern2 }, where $pattern2 refers to a different pattern which will later be substituted into this one. However, patterns are identified by a UUID, not by a name, which makes it unwieldy to use. To compensate, users have a bunch of buttons that insert the UUID into the editor for them. However, UUIDs are not nice to look at.
A visually appealing way might be possible using a JTextPane (or JEditorPane) to replaces the UUID with a small square containing the referenced pattern's name. The first image below shows what the actual contents of the Document are, while the second image shows how I imagine it is displayed to the user, given two other patterns with the names GoodName and Date.
I have tried using the javax.swing.text.Style object obtained from jTextPane.addStyle("", null), I tried with a javax.swing.text.StyleContext, and I looked at extending javax.swing.text.DefaultStyledDocument, but those mostly seem to concern themselves with changing the way the font is rendered. I don't really see a way to render specific text as a non-text shape. Furthermore, I don't see a way of making the reference "atomic", in the sense that the user cannot select and remove half of the UUID, which would reveal the underlying data which I'm trying to keep hidden.
Is anyone aware of a component that supports behaviour like this? Am I overlooking a Swing feature here? Swing has loads of documentation but it's hard to find what you're looking for if you don't know what it's called.
Perhaps this is a case where a JLayer can be successfully applied.
Instead of replacing the UUIDs with small rectangles, an equally large rectangle containing the name could be drawn over each UUID.
This code makes an autocomplete and autosuggestion box for me:
if (dataAutoCompleteSearch != null) {
autoCompleteSupport = AutoCompleteSupport.install(jComboBox1, GlazedLists.eventListOf(dataAutoCompleteSearch));
}
The problem occurs when I search for names that contain UTF-8 characters that are not in the data, but start with a few words in the suggestion box.
I could not type these UTF-8 words correctly because the text was added by itself (blue highlighted).
I want to disable GlazedLists autocomplete (Auto add highlighted text when typing) because it is very difficult to type a UTF-8 character.
But I want to keep the suggestion box, looking like Google search.
No. The API of AutoCompleteSupport doesn't support this option. You'd basically have to roll your own version of AutoCompleteSupport (it's all open source) and modify it yourself to stop the auto-complete part. I've just had a quick peak at it and it's quite large and I don't have an immediate solution to offer. It'll probably require a bit of experimenting. The private AutoCompleteFilter class would be my first place to start looking at.
I'm building the keyboard of a calculator application for Android.
I'm using the unicode but the application did not display the button "erase to left"
static String[][] screen2L ={{"sin","asin","sinh","asinh","sind","asind","\u232B","AC"},
{"cos","acos","cosh","acosh","cosd","acosd","log2","gamma"},
{"tan","atan","tanh","atanh","tand","atand","log10","ln"}};
thanks
Unicode characters are not supported in all fonts. Check here to see the supported fonts for \u232B
Instead of using the character, make an image of the character and set it as the buttons background. A post that can help with that has already been answered here: How to make button with custom background image...
Also, as for using strings in java to print in your GUI, it's better practice to use xml for this. The buttons individual values would be stored to the app instead of having to assign them every time the app is run. I would write out instructions on how this is done, but the android developers guide that can be found here gives much better instructions than I could.
Is there any way in iText to format a TextField's input? I want to have a TextField accept a phone number "(###)###-####", but I don't want the user to have to format it when they enter it. Pdf supports masks on form fields, is there any way to do this in iText?
My current solution is to create the pdf in Acrobat, then populate known fields through iText. But that isn't ideal for this deployment. Ideally I'll have iText generate the entire form.
Thanks for all assistance in advance.
You can add JavaScript to your form that changes the content of fields. See for instance the Calculator example for a fun PDF that acts as a Calculator (obviously this app only works in a PDF viewer that supports JavaScript).
When you create a text field, you need to add an additional action with the setAdditionalActions() method. You can choose between different events: K for keystroke (e.g. useful if you want to change every character to uppercase when somebody fills out a form), Bl for blurred (useful to process the content of a field as soon as the focus is lost), etc.
You can write your own document-level JavaScript to format the fields. See calculator.js for the JavaScript used in the Calculator example. Or you can use one of the many AF methods that are predefined Adobe Reader, such as AFNumber_Format (I don't find an overview of the available methods right now).
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"));