< prev index next >

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

Print this page

    rev 48358 : 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.

    *** 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() {
    *** 85,104 ****
          /**
           * 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() {
    --- 85,106 ----
          /**
           * Set the value of the selected item. The selected item may be null.
           *
           * @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() {
    *** 118,128 ****
           *
           * @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) {
    --- 120,130 ----
           *
           * @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);
              }
          }
    --- 156,166 ----

              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 >