Autocomplete and Input History for MagicTree

Submitted by alla on Thu, 02/11/2010 - 18:54

Components for Java Swing

Most modern user interfaces remember user input and provide autocomplete function. When you start typing a URL in a browser location bar, you get a list of URLs matching the pattern you have typed.

We wanted similar functionality for MagicTree. Whenever user has to type something, whether it is a command line, an XPath expression or a search term, we wanted the application to remember the previous input and provide autocompletion. Now we have that:
Autocomplete in Query Editor table

Autocomplete in command line

This functionality seems to be generally useful, so I decided to publish the components I have developed.

The main building block of the History package is the History class. It is not a GUI component, but rather a store for user input history. It is backed by Java preferences, so input history is stored between application invocations. This class also keeps statistics about the usage of each history item, so the user is presented with suggestions with most often used strings coming first. This class also allows to have multiple separate input histories in the application. For example, you may want to have a separate history for street name field and for city name field.

The package provides three GUI components: HistoryTextField inherited from JTextField, HistoryComboBox inherited from JComboBox and HistoryCellEditor implementing TableCellEditor interface. You can also use HistoryDocument inherited from PlainDocument to provide autocompletion for any other GUI component inherited from JTextComponent.

Download [attachment:gremwell-history.jar=binary jar], [attachment:gremwell-history-src.zip=source code], and [attachment:gremwell-history-javadoc.zip=javadoc] for gremwell-history package.

Update: I have uploaded a new version. It fixes a problem preventing long history entries (Java preferences only allows keys up to 80 characters long) and a bug in HistoryComboBox which caused autocomplete when the component lost focus.

Contacts

+32 (0) 2 215 53 58

Gremwell BVBA
Sint-Katherinastraat 24
1742 Ternat
Belgium
VAT: BE 0821.897.133.