< prev index next >

src/share/classes/javax/swing/plaf/synth/SynthComboBoxUI.java

Print this page
rev 1580 : 6727661: Code improvement and warnings removing from the swing/plaf packages
Summary: Removed unnecessary castings and other warnings
Reviewed-by: alexp
Contributed-by: Florian Brunner <fbrunnerlist@gmx.ch>


 511             } else {
 512                 text = "";
 513             }
 514             // workaround for 4530952
 515             if (!text.equals(editor.getText())) {
 516                 editor.setText(text);
 517             }
 518         }
 519 
 520         @Override
 521         public Object getItem() {
 522             Object newValue = editor.getText();
 523 
 524             if (oldValue != null && !(oldValue instanceof String))  {
 525                 // The original value is not a string. Should return the value in it's
 526                 // original type.
 527                 if (newValue.equals(oldValue.toString())) {
 528                     return oldValue;
 529                 } else {
 530                     // Must take the value from the editor and get the value and cast it to the new type.
 531                     Class cls = oldValue.getClass();
 532                     try {
 533                         Method method = cls.getMethod("valueOf", new Class[]{String.class});
 534                         newValue = method.invoke(oldValue, new Object[] { editor.getText()});
 535                     } catch (Exception ex) {
 536                         // Fail silently and return the newValue (a String object)
 537                     }
 538                 }
 539             }
 540             return newValue;
 541         }
 542 
 543         @Override
 544         public void selectAll() {
 545             editor.selectAll();
 546             editor.requestFocus();
 547         }
 548 
 549         @Override
 550         public void addActionListener(ActionListener l) {
 551             editor.addActionListener(l);




 511             } else {
 512                 text = "";
 513             }
 514             // workaround for 4530952
 515             if (!text.equals(editor.getText())) {
 516                 editor.setText(text);
 517             }
 518         }
 519 
 520         @Override
 521         public Object getItem() {
 522             Object newValue = editor.getText();
 523 
 524             if (oldValue != null && !(oldValue instanceof String))  {
 525                 // The original value is not a string. Should return the value in it's
 526                 // original type.
 527                 if (newValue.equals(oldValue.toString())) {
 528                     return oldValue;
 529                 } else {
 530                     // Must take the value from the editor and get the value and cast it to the new type.
 531                     Class<?> cls = oldValue.getClass();
 532                     try {
 533                         Method method = cls.getMethod("valueOf", new Class[]{String.class});
 534                         newValue = method.invoke(oldValue, new Object[] { editor.getText()});
 535                     } catch (Exception ex) {
 536                         // Fail silently and return the newValue (a String object)
 537                     }
 538                 }
 539             }
 540             return newValue;
 541         }
 542 
 543         @Override
 544         public void selectAll() {
 545             editor.selectAll();
 546             editor.requestFocus();
 547         }
 548 
 549         @Override
 550         public void addActionListener(ActionListener l) {
 551             editor.addActionListener(l);


< prev index next >