com.alee.laf.list.editor
Class AbstractListCellEditor<E extends java.awt.Component,T>

java.lang.Object
  extended by com.alee.laf.list.editor.AbstractListCellEditor<E,T>
Type Parameters:
E - Editor component type
T - Editor value type
All Implemented Interfaces:
ListCellEditor<E,T>
Direct Known Subclasses:
DefaultListCellEditor, WebCheckBoxListCellEditor, WebFileListCellEditor

public abstract class AbstractListCellEditor<E extends java.awt.Component,T>
extends java.lang.Object
implements ListCellEditor<E,T>

An abstract list cell editor that provides basic method implementations for list cell editor creation.

Author:
Mikle Garin

Field Summary
protected  int clicksToEdit
          Amount of mouse clicks required to start editing cell.
protected  int editedCell
          Last edited cell index.
protected  E editor
          Currently active editor.
protected  java.awt.event.ComponentAdapter editorPositionUpdater
          List resize adapter.
protected  java.awt.event.KeyAdapter keyAdapter
          List key adapter.
protected  java.awt.event.MouseAdapter mouseAdapter
          List mouse adapter.
protected  T oldValue
          Old value from the edited cell.
 
Constructor Summary
AbstractListCellEditor()
           
 
Method Summary
protected  void addEditor(javax.swing.JList list)
          Adds cell editor into the list.
 void cancelEdit(javax.swing.JList list)
          Cancels list cell editing.
protected abstract  E createCellEditor(javax.swing.JList list, int index, T value)
          Creates list cell editor component for the cell nder specified index.
protected  void createCellEditorListeners(javax.swing.JList list, int index, T value)
          Creates listeners for list cell editor component.
 void editCancelled(javax.swing.JList list, int index)
          Notifies that list cell editing was cancelled.
 void editStarted(javax.swing.JList list, int index)
          Notifies that list cell editing has started.
 void editStopped(javax.swing.JList list, int index, T oldValue, T newValue)
          Notifies that list cell editing has finished.
 E getCellEditor(javax.swing.JList list, int index, T value)
          Returns list cell editor created for the cell under specified index.
 int getClicksToEdit()
          Returns amount of mouse clicks required to start editing cell.
protected  java.awt.Rectangle getEditorBounds(javax.swing.JList list, int index, T value)
          Returns list cell editor bounds within the list.
protected  java.awt.Rectangle getEditorBounds(javax.swing.JList list, int index, T value, java.awt.Rectangle cellBounds)
          Returns list cell editor bounds within the cell.
 void install(javax.swing.JList list)
          Installs cell editor in the list.
protected  void installStartEditActions(javax.swing.JList list)
          Installs start edit actions in the list.
 boolean isCellEditable(javax.swing.JList list, int index, T value)
          Returns whether list cell under the specified index is editable or not.
 boolean isEditing()
          Returns whether editor is currently active or not.
protected  void removeEditor(javax.swing.JList list)
          Removes cell editor from the list.
 void setClicksToEdit(int clicksToEdit)
          Sets amount of mouse clicks required to start editing cell.
 void startEdit(javax.swing.JList list, int index)
          Starts specified list cell editing.
 boolean stopEdit(javax.swing.JList list)
          Stops list cell editing.
 void uninstall(javax.swing.JList list)
          Uninstalls cell editor from the list.
protected  void uninstallStartEditActions(javax.swing.JList list)
          Uninstalls start edit actions from the list.
 boolean updateListModel(javax.swing.JList list, int index, T oldValue, T newValue, boolean updateSelection)
          Returns whether value update operation completed successfully or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.alee.laf.list.editor.ListCellEditor
getCellEditorValue
 

Field Detail

editedCell

protected int editedCell
Last edited cell index.


oldValue

protected T oldValue
Old value from the edited cell.


editor

protected E extends java.awt.Component editor
Currently active editor.


editorPositionUpdater

protected java.awt.event.ComponentAdapter editorPositionUpdater
List resize adapter.


mouseAdapter

protected java.awt.event.MouseAdapter mouseAdapter
List mouse adapter.


clicksToEdit

protected int clicksToEdit
Amount of mouse clicks required to start editing cell.


keyAdapter

protected java.awt.event.KeyAdapter keyAdapter
List key adapter.

Constructor Detail

AbstractListCellEditor

public AbstractListCellEditor()
Method Detail

install

public void install(javax.swing.JList list)
Installs cell editor in the list. This method should add all required listeners in the list that will cause editing to start.

Specified by:
install in interface ListCellEditor<E extends java.awt.Component,T>
Parameters:
list - list to process

installStartEditActions

protected void installStartEditActions(javax.swing.JList list)
Installs start edit actions in the list.

Parameters:
list - list to process

uninstall

public void uninstall(javax.swing.JList list)
Uninstalls cell editor from the list. This method should remove all listeners from the list and cleanup all associated resources.

Specified by:
uninstall in interface ListCellEditor<E extends java.awt.Component,T>
Parameters:
list - list to process

uninstallStartEditActions

protected void uninstallStartEditActions(javax.swing.JList list)
Uninstalls start edit actions from the list.

Parameters:
list - list to process

isCellEditable

public boolean isCellEditable(javax.swing.JList list,
                              int index,
                              T value)
Returns whether list cell under the specified index is editable or not.

Specified by:
isCellEditable in interface ListCellEditor<E extends java.awt.Component,T>
Parameters:
list - list to process
index - cell index
value - cell value
Returns:
whether list cell under the specified index is editable or not

getCellEditor

public E getCellEditor(javax.swing.JList list,
                       int index,
                       T value)
Returns list cell editor created for the cell under specified index.

Specified by:
getCellEditor in interface ListCellEditor<E extends java.awt.Component,T>
Parameters:
list - list to process
index - cell index
value - cell value
Returns:
list cell editor created for the cell under specified index

createCellEditor

protected abstract E createCellEditor(javax.swing.JList list,
                                      int index,
                                      T value)
Creates list cell editor component for the cell nder specified index.

Parameters:
list - list to process
index - cell index
value - cell value
Returns:
list cell editor created for the cell under specified index

createCellEditorListeners

protected void createCellEditorListeners(javax.swing.JList list,
                                         int index,
                                         T value)
Creates listeners for list cell editor component.

Parameters:
list - list to process
index - cell index
value - cell value

startEdit

public void startEdit(javax.swing.JList list,
                      int index)
Starts specified list cell editing.

Specified by:
startEdit in interface ListCellEditor<E extends java.awt.Component,T>
Parameters:
list - list to process
index - cell index

cancelEdit

public void cancelEdit(javax.swing.JList list)
Cancels list cell editing.

Specified by:
cancelEdit in interface ListCellEditor<E extends java.awt.Component,T>
Parameters:
list - list to process

stopEdit

public boolean stopEdit(javax.swing.JList list)
Stops list cell editing. Usually if value did not change editCancelled event will be thrown, but that depends on implementation.

Specified by:
stopEdit in interface ListCellEditor<E extends java.awt.Component,T>
Parameters:
list - list to process
Returns:
true if cell editing was stopped or cancelled, false otherwise

addEditor

protected void addEditor(javax.swing.JList list)
Adds cell editor into the list.

Parameters:
list - list to process

removeEditor

protected void removeEditor(javax.swing.JList list)
Removes cell editor from the list.

Parameters:
list - list to process

getEditorBounds

protected java.awt.Rectangle getEditorBounds(javax.swing.JList list,
                                             int index,
                                             T value,
                                             java.awt.Rectangle cellBounds)
Returns list cell editor bounds within the cell.

Parameters:
list - list to process
index - cell index
value - cell value
cellBounds - cell bounds
Returns:
list cell editor bounds within the list

getEditorBounds

protected java.awt.Rectangle getEditorBounds(javax.swing.JList list,
                                             int index,
                                             T value)
Returns list cell editor bounds within the list.

Parameters:
list - list to process
index - cell index
value - cell value
Returns:
cell editor bounds for the cell under the specified index

updateListModel

public boolean updateListModel(javax.swing.JList list,
                               int index,
                               T oldValue,
                               T newValue,
                               boolean updateSelection)
Returns whether value update operation completed successfully or not. Basically this method should replace old value with a new one in list model and update list view.

Specified by:
updateListModel in interface ListCellEditor<E extends java.awt.Component,T>
Parameters:
list - list to process
index - cell index
oldValue - old cell value
newValue - new cell value
updateSelection - whether update list selection or not
Returns:
true if list model was updated

editStarted

public void editStarted(javax.swing.JList list,
                        int index)
Notifies that list cell editing has started.

Specified by:
editStarted in interface ListCellEditor<E extends java.awt.Component,T>
Parameters:
list - list to process
index - edited cell index

editStopped

public void editStopped(javax.swing.JList list,
                        int index,
                        T oldValue,
                        T newValue)
Notifies that list cell editing has finished.

Specified by:
editStopped in interface ListCellEditor<E extends java.awt.Component,T>
Parameters:
list - list to process
index - edited cell index
oldValue - old cell value
newValue - new cell value

editCancelled

public void editCancelled(javax.swing.JList list,
                          int index)
Notifies that list cell editing was cancelled.

Specified by:
editCancelled in interface ListCellEditor<E extends java.awt.Component,T>
Parameters:
list - list to process
index - edited cell index

isEditing

public boolean isEditing()
Returns whether editor is currently active or not.

Specified by:
isEditing in interface ListCellEditor<E extends java.awt.Component,T>
Returns:
true if editor is currently active, false otherwise

getClicksToEdit

public int getClicksToEdit()
Returns amount of mouse clicks required to start editing cell.

Returns:
amount of mouse clicks required to start editing cell

setClicksToEdit

public void setClicksToEdit(int clicksToEdit)
Sets amount of mouse clicks required to start editing cell.

Parameters:
clicksToEdit - amount of mouse clicks required to start editing cell