Scanning barcode into the textbox of a web application - java

I am working on a web based Java application (GWT is used for my UI).
I have a warehouse management system.I need to scan the barcodes and show them in a textbox.
I am aware that the scanners would send keyboard events. How do I capture these events and populate them in my textbox ? Should the cursor focus be on the textbox while scanning the barcode ?
Can anyone please provide a code snippet of how to capture these events and populate in the textbox ?
Please note that this needs to work across different OS and browsers.
This should work for laptops/desktops. It is not for mobile apps.

I would recommend setting cursor focus on the input textbox if scanning barcodes is the default action for that page, you can then use a KeyPressHandler on the textbox to intercept the scanner's control character if its set up to fire off a carriage return line feed (enter key) after each scan.
This
may be a place to start looking.
A quick search for an example came up with a good one here

Since you cannot distinguish between scanner and keyboard events, just focus on the textbox and wait for the input. Be sure to set up the scanners so they send TAB afterwards, not ENTER.

Depending on you scanner, it is possible to program it to send a predefined prefix before the actual bar code. For example, the scanner I was working with, a Honeywell Voyager 95X0, can be configured to transmit, for example, a Start of TeXt (ASCII 02H) before each bar code (see page Chapter 8, page 42 of the configuration guide). You could then use that prefix to filter out which KeyPressEvents were coming from the scanner (and then move the input to the text box) and which were from the user.
Setting up a "global" KeyPressHandler (so that the user doesn't have to remember to focus the text box before scanning the bar code) should be trivial - see, for example, this thread. The key point is using Event.addNativePreviewHandler to capture the events before they are fired to their handlers.

Related

JAWS accessibility issue with GWT framework

In my application, we have various types of dropdown GWT components used. I am using the JAWS latest version for the accessibility.
JAWS have some default keyboard manager setting for the "Downarrow" which perform the respective function. In my application, when the dropdown is opened, on pressing the "downarrow" JAWS is reading the list of values in dropdown one by one along with the respective highlighted thing.
But on the "enter" keypress, the selection of that particular value is not happening.
When in turned-off the JAWS, the down arrow perform its respective function of moving to the next record and on Enter click, that particular value is selected in dropdown.
somewhere JAWS default settings is overridden by the application setting. I tried various attributes like "aria-labelledby", "role - combobox, menuitem". but no luck. Could somebody help on this?
By default, the up/down arrow keys when JAWS is running will move you to the next element in the DOM. If that element is an interactive component that uses the up/down key for interaction (such as a radio), then JAWS will automatically switch to "forms mode" (kind of like a mini application mode) so that the arrow keys can be interpreted by the compoent instead of the screen reader. (The user has options on whether automatic forms mode is turned on). To get out of forms mode, press Escape.
If you have your own custom component that behaves like a native component, as long as you have the proper ARIA roles and attributes (such as role="radiogroup" and role="radio"), JAWS should switch to forms mode automatically.
See https://www.freedomscientific.com/Support/TechnicalSupport/Bulletin/1665 for more details. The title of that article talks about role="applications" and role="document" but it talks about forms mode and the Enter key.

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.

Homework assignment using Java/Swing

I've got an assignment in a class about user interfaces and usability testing. I have to do something that I'm sure I can figure out how to do programatically, but I have no experience with swing so I have no idea what components to use to do the job. My background is in C# so I'm fumbling at times trying to find the right component to use in NetBeans.
Based on the description below, can anybody recommend what kind of text field will do the job? I was thinking jFormattedTextField (based on the name) but I can't seem to figure it out.
Thanks
Submit a Java program that will run on the Linux installation in the general lab (EN-2036).
Provide the following functionality:
load the output of the last command (from a file) into a text viewing area that
allows the user to browse the data
bold all login names only (not the whole line)
bold all occurrences of a user-specified login name
bold all occurrences of a user-specified set of login names
Use JEditorPane or JTextpane, these allow you to add style to text inside them
Tutorial Link

Trying to Implement "Caret Browsing" Using JavaFX 2

I'm trying to write an application using JavaFX 2.0 that includes a web browser control that allows a user to navigate through the text and images on a HTML page using only the keyboard -- basically like "caret browsing" in Internet Explorer.
The goal is to be able to select bits of text or images and copy them to a variable for further manipulation without using a mouse.
I took a look at the HTMLEditor control here:
http://docs.oracle.com/javafx/2.0/ui_controls/editor.htm#CHDBEGDD
but I don't need any editing capability cluttering up the UI, and the documentation says:
The formatting toolbars are provided in the implementation of the
component. You cannot toggle their visibility.
WebView seems like a logical choice (http://docs.oracle.com/javafx/2.0/webview/jfxpub-webview.htm), but I'm not sure how to get a cursor onto the page.
Any advice would be appreciated.
The current WebView support for caret browsing seems patchy at best to me.
Here is what I found running a quick test:
I can invoke webView.requestFocus to have the WebView request focus for responding to key presses, but it just operates on the WebView as a whole, not individual components within the WebView.
WebView does not implement a selection management API similar to TextInputControl for fine grained programmatic management of selections.
WebView does allow you to select text. However, I had to initiate the selection with a mouse drag, and after that I could use a keyboard to enlarge or shorten the selection (left or right arrow keys for a character by character selection and ctrl + left or right arrow keys for word by word selection - up and down arrows did not affect the selection).
After selecting some text in WebView I could press Ctrl-C on it (in Windows) to copy it to a clipboard and paste the text into another program. Only raw text was copied - associated style/html info and images were not copied.
To copy images I had to right click on an image and select Copy Image from a drop down menu and I could paste the image into MS Paint - I could not find a way to do this without a mouse.
In other browsers I can press TAB and Shift + TAB to go from one hyperlink to the next - in WebView, once it has focus, TAB will just go from one control (e.g. an html text field in the WebView) to the next (e.g. an html button in the text field).
The backspace key works as in other browsers (takes you to the previous page).
The above restrictions, and likely others I didn't test for, will likely make it hard to accomplish what you are trying to do. You could try stuff such as capturing keypress events using an eventfilter, then generating mouse events to initiate the selection and copy process, but that sounds difficult to me, and even then, there is currently no public API in JavaFX to generate mouse events, only an unstable com.sun api.
WebView does expose a document object model, and the document is scriptable by JavaScript. Try capturing key events with an eventfilter, listening to the document property for changes and executing JavaScript against the WebView at appropriate times to get and set the current selection. This also seems a little tricky to implement well.
Accomplish as much as you can with the current WebView control and public API and log issues at http://javafx-jira.kenai.com as and when you encounter short-comings.

JKeyListener chars / auto complete

I want to make an auto completion textfield, which replaces the input with the first hit and selects the part which wasn't entered by the keyboard yet. To do so, I'll have to count the chars typed (or deleted). How can I filter if the KeyEvent is a printable Char (and not SHIFT f.e.)?
Look at https://swingx.dev.java.net/
This lib is already have great autocomplete text fields
i prefer to do it with the KeyListener
Well, a KeyListener is the wrong tool for the job.
If you really want to write your own code then you should start with a DocumentListener. Every time text is added or removed from the text field you will be notified. Then you can implement your auto completion code.

Categories