src/share/classes/javax/swing/plaf/basic/BasicComboBoxEditor.java

Print this page




  83             text = "";
  84         }
  85         // workaround for 4530952
  86         if (! text.equals(editor.getText())) {
  87             editor.setText(text);
  88         }
  89     }
  90 
  91     public Object getItem() {
  92         Object newValue = editor.getText();
  93 
  94         if (oldValue != null && !(oldValue instanceof String))  {
  95             // The original value is not a string. Should return the value in it's
  96             // original type.
  97             if (newValue.equals(oldValue.toString()))  {
  98                 return oldValue;
  99             } else {
 100                 // Must take the value from the editor and get the value and cast it to the new type.
 101                 Class<?> cls = oldValue.getClass();
 102                 try {
 103                     Method method = MethodUtil.getMethod(cls, "valueOf", new Class[]{String.class});
 104                     newValue = MethodUtil.invoke(method, oldValue, new Object[] { editor.getText()});
 105                 } catch (Exception ex) {
 106                     // Fail silently and return the newValue (a String object)
 107                 }
 108             }
 109         }
 110         return newValue;
 111     }
 112 
 113     public void selectAll() {
 114         editor.selectAll();
 115         editor.requestFocus();
 116     }
 117 
 118     // This used to do something but now it doesn't.  It couldn't be
 119     // removed because it would be an API change to do so.
 120     public void focusGained(FocusEvent e) {}
 121 
 122     // This used to do something but now it doesn't.  It couldn't be
 123     // removed because it would be an API change to do so.




  83             text = "";
  84         }
  85         // workaround for 4530952
  86         if (! text.equals(editor.getText())) {
  87             editor.setText(text);
  88         }
  89     }
  90 
  91     public Object getItem() {
  92         Object newValue = editor.getText();
  93 
  94         if (oldValue != null && !(oldValue instanceof String))  {
  95             // The original value is not a string. Should return the value in it's
  96             // original type.
  97             if (newValue.equals(oldValue.toString()))  {
  98                 return oldValue;
  99             } else {
 100                 // Must take the value from the editor and get the value and cast it to the new type.
 101                 Class<?> cls = oldValue.getClass();
 102                 try {
 103                     Method method = MethodUtil.getMethod(cls, "valueOf", new Class<?>[]{String.class});
 104                     newValue = MethodUtil.invoke(method, oldValue, new Object[] { editor.getText()});
 105                 } catch (Exception ex) {
 106                     // Fail silently and return the newValue (a String object)
 107                 }
 108             }
 109         }
 110         return newValue;
 111     }
 112 
 113     public void selectAll() {
 114         editor.selectAll();
 115         editor.requestFocus();
 116     }
 117 
 118     // This used to do something but now it doesn't.  It couldn't be
 119     // removed because it would be an API change to do so.
 120     public void focusGained(FocusEvent e) {}
 121 
 122     // This used to do something but now it doesn't.  It couldn't be
 123     // removed because it would be an API change to do so.