< prev index next >

## src/java.desktop/share/classes/javax/swing/DefaultComboBoxModel.java

Print this page

    rev 48858 : Work in progress for JDK-6303622
    Use generic in Swing components like JComboBox
    1. Added generic return type and parameter type for JComboBox.
    2. Modified JList related classes as well.
    3. Reverted the changes made to "getSelectedValues" as suggested by Joe.
    4. Modified files that were failing on Linux and Mac as well.

    *** 38,48 ****
       * @since 1.2
       */
      @SuppressWarnings("serial") // Superclass is not serializable across versions
      public class DefaultComboBoxModel<E> extends AbstractListModel<E> implements MutableComboBoxModel<E>, Serializable {
          Vector<E> objects;
    !     Object selectedObject;

          /**
           * Constructs an empty DefaultComboBoxModel object.
           */
          public DefaultComboBoxModel() {
    --- 38,48 ----
       * @since 1.2
       */
      @SuppressWarnings("serial") // Superclass is not serializable across versions
      public class DefaultComboBoxModel<E> extends AbstractListModel<E> implements MutableComboBoxModel<E>, Serializable {
          Vector<E> objects;
    !     E selectedObject;

          /**
           * Constructs an empty DefaultComboBoxModel object.
           */
          public DefaultComboBoxModel() {
    *** 82,104 ****
          }

          // implements javax.swing.ComboBoxModel
          /**
           * Set the value of the selected item. The selected item may be null.
    !      *
           * @param anObject The combo box value or null for no selection.
           */
    !     public void setSelectedItem(Object anObject) {
              if ((selectedObject != null && !selectedObject.equals( anObject )) ||
                  selectedObject == null && anObject != null) {
                  selectedObject = anObject;
                  fireContentsChanged(this, -1, -1);
              }
          }

          // implements javax.swing.ComboBoxModel
    !     public Object getSelectedItem() {
              return selectedObject;
          }

          // implements javax.swing.ListModel
          public int getSize() {
    --- 82,106 ----
          }

          // implements javax.swing.ComboBoxModel
          /**
           * Set the value of the selected item. The selected item may be null.
    !      * @param <E> the type of the elements of this model.
           * @param anObject The combo box value or null for no selection.
           */
    !     @Override
    !     public void setSelectedItem(E anObject) {
              if ((selectedObject != null && !selectedObject.equals( anObject )) ||
                  selectedObject == null && anObject != null) {
                  selectedObject = anObject;
                  fireContentsChanged(this, -1, -1);
              }
          }

          // implements javax.swing.ComboBoxModel
    !     @Override
    !     public E getSelectedItem() {
              return selectedObject;
          }

          // implements javax.swing.ListModel
          public int getSize() {
    *** 114,128 ****
          }

          /**
           * Returns the index-position of the specified object in the list.
           *
           * @param anObject the object to return the index of
           * @return an int representing the index position, where 0 is
           *         the first position
           */
    !     public int getIndexOf(Object anObject) {
              return objects.indexOf(anObject);
          }

          // implements javax.swing.MutableComboBoxModel
          public void addElement(E anObject) {
    --- 116,131 ----
          }

          /**
           * Returns the index-position of the specified object in the list.
           *
    +      * @param <E> the type of the elements of this model.
           * @param anObject the object to return the index of
           * @return an int representing the index position, where 0 is
           *         the first position
           */
    !     public int getIndexOf(E anObject) {
              return objects.indexOf(anObject);
          }

          // implements javax.swing.MutableComboBoxModel
          public void addElement(E anObject) {
    *** 154,164 ****

              fireIntervalRemoved(this, index, index);
          }

          // implements javax.swing.MutableComboBoxModel
    !     public void removeElement(Object anObject) {
              int index = objects.indexOf(anObject);
              if ( index != -1 ) {
                  removeElementAt(index);
              }
          }
    --- 157,167 ----

              fireIntervalRemoved(this, index, index);
          }

          // implements javax.swing.MutableComboBoxModel
    !     public void removeElement(E anObject) {
              int index = objects.indexOf(anObject);
              if ( index != -1 ) {
                  removeElementAt(index);
              }
          }

< prev index next >