org.PingOO.DLAI.lib.PWidget
Class ComboBoxEditorAuto

java.lang.Object
  |
  +--org.PingOO.DLAI.lib.PWidget.ComboBoxEditorAuto

public class ComboBoxEditorAuto
extends java.lang.Object
implements javax.swing.ComboBoxEditor, java.awt.event.KeyListener

An editor for a combo box with auto-research feature. This will be used with the PComboBox (localized resource capable combox for PingOO).
The text zone automatically suggests to complete the word typed by the user, with word beginning by the same letters and which is inclued in the combobox.

Since:
PingOO 2.0
Version:
2.0
Author:
Frédéric Barrière (fredgate@citeweb.net), Fabrice Bouyé (bouye@cur-archamps.fr)
See Also:
ComboBoxEditor, KeyListener

Field Summary
protected  javax.swing.JComboBox combo
          The combox associated with this editor.
protected  javax.swing.JTextField editor
          The text zone for input characters.
 
Constructor Summary
ComboBoxEditorAuto(javax.swing.JComboBox combo)
          Creates a new editor associated with a combobox.
 
Method Summary
 void addActionListener(java.awt.event.ActionListener listener)
          Adds an ActionListener.
protected  java.lang.String findItemStartsWith(java.lang.String sBegin)
          Research in the combo a word starting with the provided prefix.
protected  java.lang.String findNextItemStartsWith(java.lang.String sBegin, java.lang.String sCur)
          Research form the combo a word beginning with a prefix but which is different from the reference word.
 java.awt.Component getEditorComponent()
          Returns the component that should be added to the tree hierarchy for this editor.
 java.lang.Object getItem()
          Returns the edited item.
 void keyPressed(java.awt.event.KeyEvent event)
          Invoked when a key has been pressed.
 void keyReleased(java.awt.event.KeyEvent event)
          Invoked when a key has been released.
 void keyTyped(java.awt.event.KeyEvent event)
          Invoked when a key has been typed.
 void removeActionListener(java.awt.event.ActionListener listener)
          Remove an ActionListener.
 void selectAll()
          Asks the editor to start editing and to select everything.
 void setItem(java.lang.Object obj)
          Set the item that should be edited.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

editor

protected javax.swing.JTextField editor
The text zone for input characters.

combo

protected javax.swing.JComboBox combo
The combox associated with this editor.
Constructor Detail

ComboBoxEditorAuto

public ComboBoxEditorAuto(javax.swing.JComboBox combo)
Creates a new editor associated with a combobox.
Parameters:
combo - The combox to be associated with this editor.
Method Detail

getEditorComponent

public java.awt.Component getEditorComponent()
Returns the component that should be added to the tree hierarchy for this editor.
Specified by:
getEditorComponent in interface javax.swing.ComboBoxEditor
Returns:
The component that should be added to the tree hierarchy for this editor.

setItem

public void setItem(java.lang.Object obj)
Set the item that should be edited. Cancel any editing if necessary.
Specified by:
setItem in interface javax.swing.ComboBoxEditor

getItem

public java.lang.Object getItem()
Returns the edited item.
Specified by:
getItem in interface javax.swing.ComboBoxEditor
Returns:
The edited item.

selectAll

public void selectAll()
Asks the editor to start editing and to select everything.
Specified by:
selectAll in interface javax.swing.ComboBoxEditor

addActionListener

public void addActionListener(java.awt.event.ActionListener listener)
Adds an ActionListener. An action event is generated when the edited item changes.
Specified by:
addActionListener in interface javax.swing.ComboBoxEditor
Parameters:
listener - The listener to be added.

removeActionListener

public void removeActionListener(java.awt.event.ActionListener listener)
Remove an ActionListener.
Specified by:
removeActionListener in interface javax.swing.ComboBoxEditor
Parameters:
listener - The listener to be removed.

keyTyped

public void keyTyped(java.awt.event.KeyEvent event)
Invoked when a key has been typed. This event occurs when a key press is followed by a key release.
Specified by:
keyTyped in interface java.awt.event.KeyListener
Parameters:
event - The key event.

keyPressed

public void keyPressed(java.awt.event.KeyEvent event)
Invoked when a key has been pressed.
Specified by:
keyPressed in interface java.awt.event.KeyListener
Parameters:
event - The key event.

keyReleased

public void keyReleased(java.awt.event.KeyEvent event)
Invoked when a key has been released.
Specified by:
keyReleased in interface java.awt.event.KeyListener
Parameters:
event - The key event.

findItemStartsWith

protected java.lang.String findItemStartsWith(java.lang.String sBegin)
Research in the combo a word starting with the provided prefix.
Parameters:
sBegin - Thre prefix to research.
Returns:
The first word matching the prefix

findNextItemStartsWith

protected java.lang.String findNextItemStartsWith(java.lang.String sBegin,
                                                  java.lang.String sCur)
Research form the combo a word beginning with a prefix but which is different from the reference word.
Parameters:
sBegin - The prefix to research.
sCur - The reference word.
Returns:
A new word matching the prefix but different from the reference word.