QJCC homepage

biz.chitec.quarterback.swing
Class ListKeyInputHandler

java.lang.Object
  extended bybiz.chitec.quarterback.swing.ListKeyInputHandler

public class ListKeyInputHandler
extends java.lang.Object

Keystroke handler for lists to select entries by typing the beginnings of the entries. This handler object allows convenient navigation through JList objects by keyboard. It listens to key strokes and forms a compare string out of them which is compared against the elements of the list. On uniqueness or when at least one (the first) matching element is found, it is selected. The whole process is case insensitive.

The compare string is shown in the lists by inverse presentation of the matching characters of the entries. For this, a special cell renderer object is used which has its own UI delegate. These objects are realized as static subclasses of ListKeyInputHandler. The delegate is inserted into the UI manager tables on loading the class the first time.

Version:
$Id: f3b4327ed8b79ae54f4510402072f28ce164ad36 $
Author:
chitec/Dirk Hillbrecht 2001. Distributed under the terms of the GNU LGPL.

Nested Class Summary
static class ListKeyInputHandler.BasicKIHCellRendererUI
          UI delegate with implementation.
static class ListKeyInputHandler.KIHCellRenderer
          The cell renderer object for the ListKeyInputHandler.
static class ListKeyInputHandler.KIHCellRendererUI
          Generic UI delegate class.
 
Field Summary
private  java.lang.String comparestring
           
static int FIRST_ALWAYS
          Always select the first matching element.
private  int firstselectableindex
           
private  javax.swing.JList mylist
           
private  boolean selected
           
private  int selectstrategy
           
static int UNIQUE_ONLY
          Select only if the compare string is unique.
 
Constructor Summary
private ListKeyInputHandler(javax.swing.JList listx, int sx)
          Constructs a new object.
 
Method Summary
static ListKeyInputHandler bindToList(javax.swing.JList x)
          Bind handler to a list.
static ListKeyInputHandler bindToList(javax.swing.JList x, int sx)
          Bind handler to a list.
private  void checkCompareString(boolean forceselect)
          Checks whether the compare string leads to a new selection.
private  void dropCompareString()
          Drops the compare string.
private  java.lang.String getCompareString()
          Returns the compare string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNIQUE_ONLY

public static final int UNIQUE_ONLY
Select only if the compare string is unique.

See Also:
Constant Field Values

FIRST_ALWAYS

public static final int FIRST_ALWAYS
Always select the first matching element.

See Also:
Constant Field Values

mylist

private javax.swing.JList mylist

comparestring

private java.lang.String comparestring

selectstrategy

private int selectstrategy

firstselectableindex

private int firstselectableindex

selected

private boolean selected
Constructor Detail

ListKeyInputHandler

private ListKeyInputHandler(javax.swing.JList listx,
                            int sx)
Constructs a new object. Binds some listeners to the list and registers its own cell renderer. Private method. ListKeyInputHandlers must always be bound to their lists via the static bindToList() methods.

Method Detail

bindToList

public static ListKeyInputHandler bindToList(javax.swing.JList x,
                                             int sx)
Bind handler to a list. Obtains list and selection strategy, which must be one of UNIQUE_ONLY or FIRST_ALWAYS.


bindToList

public static ListKeyInputHandler bindToList(javax.swing.JList x)
Bind handler to a list. Obtains list and sets strategy to UNIQUE_ONLY.


dropCompareString

private void dropCompareString()
Drops the compare string. This changes the representation. The selection is NOT changed.


checkCompareString

private void checkCompareString(boolean forceselect)
Checks whether the compare string leads to a new selection.


getCompareString

private java.lang.String getCompareString()
Returns the compare string. Needed by the cell renderer.


QJCC homepage