What is AutoText?

AutoText is a prototype showing auto-completion behaviour in a simple Java Swing application. While modern IDEs usually provide an auto-completion behaviour to the developer, to ease the pain of typing long words, I don't know of any word-processing application, providing this feature.

With the AutoText component, you can easily apply auto-completion behaviour to any Java application.

How does it work?

AutoText is the general component, that can be used in every application, while AutoTextListener is a KeyListener, that can be added to every JTextComponent instance of any Swing application. It listens to every keystroke, and if it recognizes the auto-complete command (CTRL-SPACE), it automatically segments the text into words, determines the current prefix and completes it to the best matching word of the entire text.

That means: AutoText (currently) depends on the text, that is acutally typed in the given component. Later improvements may use a dictionary to add words that have not been used yet.

When auto-completing, even parts of words are completed, such as if the word Te should be completed, with the words Tester and Testenvironment already written, the completion would be Teste, letting the user choose, wheter to manually complete with r or n (to use auto-completion again).

Example Screenshots

Fig. 1: The user has already written the word Test. Now he wants to complete the current word starting with T. No surprise, he expects the word Test to be completed.

Fig. 2: As expected, the word Test is the result of auto-completion. The completed text is currently selected. It's a special selection that will automatically vanish, if the user types ahead. If the user hits the backspace key, the inserted text is removed.

Fig. 3: Now the user has written some more words, leading to possible conflicts. All words start with Test, two of the words even start with Teste. So what will happen, if the user wants to use auto-completion now?

Fig. 4: AutoText completes the word to the shortest possible prefix. That is for all words starting with T the prefix Test.

Fig. 5: Hitting CTRL-SPACE again (without doing anything else), AutoText completes the e which is the shortest common prefix of all words starting with Test (excluding the word Test itself). Now there is no more prefix for auto-completion left and nothing will happen if the user would just hit CTRL-SPACE again.

Fig. 6: But with typing an n, the shortest common prefix of all words starting with Testen is Testenvironment which will be used by AutoText when the user hits CTRL-SPACE the next time.