< prev index next >

## src/java.desktop/share/classes/javax/swing/DefaultCellEditor.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.

     111                 if (value instanceof Boolean) {
     112                     selected = ((Boolean)value).booleanValue();
     113                 }
     114                 else if (value instanceof String) {
     115                     selected = value.equals("true");
     116                 }
     117                 checkBox.setSelected(selected);
     118             }
     119
     120             public Object getCellEditorValue() {
     121                 return Boolean.valueOf(checkBox.isSelected());
     122             }
     123         };
     124         checkBox.addActionListener(delegate);
     125         checkBox.setRequestFocusEnabled(false);
     126     }
     127
     128     /**
     129      * Constructs a <code>DefaultCellEditor</code> object that uses a
     130      * combo box.
     131      *
     132      * @param comboBox  a <code>JComboBox</code> object
     133      */
     134     public DefaultCellEditor(final JComboBox<?> comboBox) {

     135         editorComponent = comboBox;
     136         comboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
     137         delegate = new EditorDelegate() {
     138             public void setValue(Object value) {
     139                 comboBox.setSelectedItem(value);
     140             }
     141
     142             public Object getCellEditorValue() {
     143                 return comboBox.getSelectedItem();
     144             }
     145
     146             public boolean shouldSelectCell(EventObject anEvent) {
     147                 if (anEvent instanceof MouseEvent) {
     148                     MouseEvent e = (MouseEvent)anEvent;
     149                     return e.getID() != MouseEvent.MOUSE_DRAGGED;
     150                 }
     151                 return true;
     152             }
     153             public boolean stopCellEditing() {
     154                 if (comboBox.isEditable()) {
     155                     // Commit edited value.
     156                     comboBox.actionPerformed(new ActionEvent(
     157                                      DefaultCellEditor.this, 0, ""));
     158                 }
     159                 return super.stopCellEditing();
     111                 if (value instanceof Boolean) {
     112                     selected = ((Boolean)value).booleanValue();
     113                 }
     114                 else if (value instanceof String) {
     115                     selected = value.equals("true");
     116                 }
     117                 checkBox.setSelected(selected);
     118             }
     119
     120             public Object getCellEditorValue() {
     121                 return Boolean.valueOf(checkBox.isSelected());
     122             }
     123         };
     124         checkBox.addActionListener(delegate);
     125         checkBox.setRequestFocusEnabled(false);
     126     }
     127
     128     /**
     129      * Constructs a <code>DefaultCellEditor</code> object that uses a
     130      * combo box.
     131      * @param <E> the type of the elements of comboBox
     132      * @param comboBox  a <code>JComboBox</code> object
     133      */
     134     @SuppressWarnings("unchecked")
     135     public <E> DefaultCellEditor(final JComboBox<E> comboBox) {
     136         editorComponent = comboBox;
     137         comboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
     138         delegate = new EditorDelegate() {
     139             public void setValue(Object value) {
     140                 comboBox.setSelectedItem((E)value);
     141             }
     142
     143             public Object getCellEditorValue() {
     144                 return comboBox.getSelectedItem();
     145             }
     146
     147             public boolean shouldSelectCell(EventObject anEvent) {
     148                 if (anEvent instanceof MouseEvent) {
     149                     MouseEvent e = (MouseEvent)anEvent;
     150                     return e.getID() != MouseEvent.MOUSE_DRAGGED;
     151                 }
     152                 return true;
     153             }
     154             public boolean stopCellEditing() {
     155                 if (comboBox.isEditable()) {
     156                     // Commit edited value.
     157                     comboBox.actionPerformed(new ActionEvent(
     158                                      DefaultCellEditor.this, 0, ""));
     159                 }
     160                 return super.stopCellEditing();

< prev index next >