org.fife.ui
Class RComboBoxModel

java.lang.Object
  extended byjavax.swing.AbstractListModel
      extended byjavax.swing.DefaultComboBoxModel
          extended byorg.fife.ui.RComboBoxModel
All Implemented Interfaces:
javax.swing.ComboBoxModel, javax.swing.ListModel, javax.swing.MutableComboBoxModel, java.io.Serializable

public class RComboBoxModel
extends javax.swing.DefaultComboBoxModel
implements java.io.Serializable

A combo box model that limits the number of items the combo box will "remember." You can use it like so:
RComboBoxModel model = new RComboBoxModel();
model.setMaxNumElements(10);
JComboBox comboBox = new JComboBox(model);

It also won't let you add an item to the combo box twice (i.e., no duplicates), and it adds new items to the beginning of the list, not the end (as JComboBox's do by default).

It defaults to 10 elements remembered.

Version:
0.8
Author:
Robert Futrell
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
RComboBoxModel()
          Creates a new combo box model with a maximum element count of 8.
RComboBoxModel(java.lang.Object[] items)
          Creates a new combo box model with a maximum element count of 8.
RComboBoxModel(java.util.Vector v)
          Creates a new combo box model with a maximum element count of 8.
 
Method Summary
 void addElement(java.lang.Object anObject)
          Adds the object (if it's not already in the list) to the front of the list.
 int getMaxNumElements()
          Returns the maximum number of items this combo box can hold.
 void insertElementAt(java.lang.Object anObject, int index)
          Adds an item at a specified index.
 void setMaxNumElements(int numElements)
          Sets the maximum number of items this combo box can hold.
 
Methods inherited from class javax.swing.DefaultComboBoxModel
getElementAt, getIndexOf, getSelectedItem, getSize, removeAllElements, removeElement, removeElementAt, setSelectedItem
 
Methods inherited from class javax.swing.AbstractListModel
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.ListModel
addListDataListener, removeListDataListener
 

Constructor Detail

RComboBoxModel

public RComboBoxModel()
Creates a new combo box model with a maximum element count of 8.


RComboBoxModel

public RComboBoxModel(java.lang.Object[] items)
Creates a new combo box model with a maximum element count of 8.

Parameters:
items - The initial items to use to populate the combo box.

RComboBoxModel

public RComboBoxModel(java.util.Vector v)
Creates a new combo box model with a maximum element count of 8.

Parameters:
v - The initial items to use to populate the combo box.
Method Detail

addElement

public void addElement(java.lang.Object anObject)
Adds the object (if it's not already in the list) to the front of the list. If it's already in the list, move it to the top.

Specified by:
addElement in interface javax.swing.MutableComboBoxModel
Parameters:
anObject - The object to add.

getMaxNumElements

public int getMaxNumElements()
Returns the maximum number of items this combo box can hold.

Returns:
The maximum number of items this combo box can hold.

insertElementAt

public void insertElementAt(java.lang.Object anObject,
                            int index)
Adds an item at a specified index. The implementation of this method should notify all registered ListDataListeners that the item has been added.

Specified by:
insertElementAt in interface javax.swing.MutableComboBoxModel
Parameters:
anObject - The Object to be added.
index - Location to add the object.

setMaxNumElements

public void setMaxNumElements(int numElements)
Sets the maximum number of items this combo box can hold.

Parameters:
numElements - The maximum number of items this combo box can hold. If numElements <= 0, then the capacity of this combo box is set to 4.