TrueZIP 6.8.2

de.schlichtherle.swing
Class AbstractComboBoxBrowser

java.lang.Object
  extended by de.schlichtherle.swing.AbstractComboBoxBrowser
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
FileComboBoxBrowser

public abstract class AbstractComboBoxBrowser
extends Object
implements Serializable

An observer for a JComboBox which provides auto completion for the editable text in the drop down list in order to provide quick browsing capabilities for the user. Subclasses need to implement the update(java.lang.String) method in order to update the combo box model with the actual auto completion data.

This class is designed to be minimal intrusive: It works with any subclass of JComboBox and doesn't require a special ComboBoxModel, although its specific behaviour will only show if the JComboBox is editable and uses an instance of a MutableComboBoxModel (which, apart from the editable property being set to true, is the default for a plain JComboBox).

Since:
TrueZIP 6.2
Version:
$Id: AbstractComboBoxBrowser.java 5e709f50671d 2010/11/05 11:52:07 christian $
Author:
Christian Schlichtherle
See Also:
Serialized Form

Nested Class Summary
private  class AbstractComboBoxBrowser.ComboBoxEditorProxy
          This proxy controls access to the real ComboBoxEditor installed by the client application or the pluggable look and feel.
private  class AbstractComboBoxBrowser.Listener
           
 
Field Summary
private  JComboBox comboBox
           
private  AbstractComboBoxBrowser.Listener listener
           
private  boolean recursion
          Used to inhibit mutual recursive event firing.
 
Constructor Summary
AbstractComboBoxBrowser()
          Creates a new combo box auto completion browser.
AbstractComboBoxBrowser(JComboBox comboBox)
          Creates a new combo box auto completion browser.
 
Method Summary
private  void changeComboBox(JComboBox oldCB, JComboBox newCB, boolean update)
           
private  void changeDocument(Document oldDoc, Document newDoc, boolean update)
           
private  void changeEditor(ComboBoxEditor oldCBE, ComboBoxEditor newCBE, boolean update)
           
private  void changeText(JTextComponent oldTC, JTextComponent newTC, boolean update)
           
private  void documentUpdated()
           
 JComboBox getComboBox()
          Returns the combo box which this object is auto completing.
private  boolean lock()
          Locks out mutual recursive event notification.
 void setComboBox(JComboBox comboBox)
          Sets the combo box which this object is auto completing and updates the drop down list with the auto completion for the currently selected item.
private  void unlock()
          Unlocks mutual recursive event notification.
protected abstract  boolean update(String initials)
          Subclasses are expected to update the auto completion elements in the model of this combo box based on the specified initials.
private  void updateEditor(ComboBoxEditor cbe, Object item)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listener

private final AbstractComboBoxBrowser.Listener listener

comboBox

private JComboBox comboBox

recursion

private transient boolean recursion
Used to inhibit mutual recursive event firing.

Constructor Detail

AbstractComboBoxBrowser

public AbstractComboBoxBrowser()
Creates a new combo box auto completion browser. setComboBox(javax.swing.JComboBox) must be called in order to use this object.


AbstractComboBoxBrowser

public AbstractComboBoxBrowser(JComboBox comboBox)
Creates a new combo box auto completion browser. Note that this constructor does not call update(java.lang.String) and hence the drop down list of the combo box is left unchanged.

Parameters:
comboBox - The combo box to enable browsing for auto completions. May be null.
Method Detail

getComboBox

public JComboBox getComboBox()
Returns the combo box which this object is auto completing. The default is null.


setComboBox

public void setComboBox(JComboBox comboBox)
Sets the combo box which this object is auto completing and updates the drop down list with the auto completion for the currently selected item.

Parameters:
comboBox - The combo box to enable browsing for auto completions. May be null.

changeComboBox

private void changeComboBox(JComboBox oldCB,
                            JComboBox newCB,
                            boolean update)

changeEditor

private void changeEditor(ComboBoxEditor oldCBE,
                          ComboBoxEditor newCBE,
                          boolean update)

changeText

private void changeText(JTextComponent oldTC,
                        JTextComponent newTC,
                        boolean update)

changeDocument

private void changeDocument(Document oldDoc,
                            Document newDoc,
                            boolean update)

documentUpdated

private void documentUpdated()

updateEditor

private void updateEditor(ComboBoxEditor cbe,
                          Object item)

update

protected abstract boolean update(String initials)
Subclasses are expected to update the auto completion elements in the model of this combo box based on the specified initials. They should not do any other work within this method. In particular, they should not update the visual appearance of this component.

getComboBox() is guaranteed to return non-null if this method is called from this abstract base class.

Parameters:
initials - The text to auto complete. May be null.
Returns:
Whether or not the combo box should pop up to show the updated contents of its model.

lock

private final boolean lock()
Locks out mutual recursive event notification. Warning: This method works in a synchronized or single threaded environment only!

Returns:
Whether or not updating the combo box model was already locked.

unlock

private final void unlock()
Unlocks mutual recursive event notification. Warning: This method works in a synchronized or single threaded environment only!


TrueZIP 6.8.2

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.