< prev index next >

src/share/classes/javax/swing/JOptionPane.java

Print this page
rev 1527 : 6727662: Code improvement and warnings removing from swing packages
Summary: Removed unnecessary castings and other warnings
Reviewed-by: malenkov
rev 1576 : 6464022: Memory leak in JOptionPane.createDialog
Reviewed-by: alexp

*** 961,971 **** } else { dialog = new JDialog((Dialog)window, title, true); } if (window instanceof SwingUtilities.SharedOwnerFrame) { WindowListener ownerShutdownListener = ! (WindowListener)SwingUtilities.getSharedOwnerFrameShutdownListener(); dialog.addWindowListener(ownerShutdownListener); } initDialog(dialog, style, parentComponent); return dialog; } --- 961,971 ---- } else { dialog = new JDialog((Dialog)window, title, true); } if (window instanceof SwingUtilities.SharedOwnerFrame) { WindowListener ownerShutdownListener = ! SwingUtilities.getSharedOwnerFrameShutdownListener(); dialog.addWindowListener(ownerShutdownListener); } initDialog(dialog, style, parentComponent); return dialog; }
*** 985,999 **** --- 985,1021 ---- getRootPane().setWindowDecorationStyle(style); } } dialog.pack(); dialog.setLocationRelativeTo(parentComponent); + + final PropertyChangeListener listener = new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + // Let the defaultCloseOperation handle the closing + // if the user closed the window without selecting a button + // (newValue = null in that case). Otherwise, close the dialog. + if (dialog.isVisible() && event.getSource() == JOptionPane.this && + (event.getPropertyName().equals(VALUE_PROPERTY) || + event.getPropertyName().equals(INPUT_VALUE_PROPERTY)) && + event.getNewValue() != null && + event.getNewValue() != JOptionPane.UNINITIALIZED_VALUE) { + dialog.setVisible(false); + } + } + }; + WindowAdapter adapter = new WindowAdapter() { private boolean gotFocus = false; public void windowClosing(WindowEvent we) { setValue(null); } + + public void windowClosed(WindowEvent e) { + removePropertyChangeListener(listener); + dialog.getContentPane().removeAll(); + } + public void windowGainedFocus(WindowEvent we) { // Once window gets focus, set initial focus if (!gotFocus) { selectInitialValue(); gotFocus = true;
*** 1006,1029 **** public void componentShown(ComponentEvent ce) { // reset value to ensure closing works properly setValue(JOptionPane.UNINITIALIZED_VALUE); } }); ! addPropertyChangeListener(new PropertyChangeListener() { ! public void propertyChange(PropertyChangeEvent event) { ! // Let the defaultCloseOperation handle the closing ! // if the user closed the window without selecting a button ! // (newValue = null in that case). Otherwise, close the dialog. ! if (dialog.isVisible() && event.getSource() == JOptionPane.this && ! (event.getPropertyName().equals(VALUE_PROPERTY) || ! event.getPropertyName().equals(INPUT_VALUE_PROPERTY)) && ! event.getNewValue() != null && ! event.getNewValue() != JOptionPane.UNINITIALIZED_VALUE) { ! dialog.setVisible(false); ! } ! } ! }); } /** * Brings up an internal confirmation dialog panel. The dialog --- 1028,1039 ---- public void componentShown(ComponentEvent ce) { // reset value to ensure closing works properly setValue(JOptionPane.UNINITIALIZED_VALUE); } }); ! ! addPropertyChangeListener(listener); } /** * Brings up an internal confirmation dialog panel. The dialog
*** 1298,1312 **** } } // Use reflection to get Container.startLWModal. try { ! Object obj; ! obj = AccessController.doPrivileged(new ModalPrivilegedAction( Container.class, "startLWModal")); ! if (obj != null) { ! ((Method)obj).invoke(dialog, (Object[])null); } } catch (IllegalAccessException ex) { } catch (IllegalArgumentException ex) { } catch (InvocationTargetException ex) { } --- 1308,1321 ---- } } // Use reflection to get Container.startLWModal. try { ! Method method = AccessController.doPrivileged(new ModalPrivilegedAction( Container.class, "startLWModal")); ! if (method != null) { ! method.invoke(dialog, (Object[])null); } } catch (IllegalAccessException ex) { } catch (IllegalArgumentException ex) { } catch (InvocationTargetException ex) { }
*** 1444,1458 **** } } // Use reflection to get Container.startLWModal. try { ! Object obj; ! obj = AccessController.doPrivileged(new ModalPrivilegedAction( Container.class, "startLWModal")); ! if (obj != null) { ! ((Method)obj).invoke(dialog, (Object[])null); } } catch (IllegalAccessException ex) { } catch (IllegalArgumentException ex) { } catch (InvocationTargetException ex) { } --- 1453,1466 ---- } } // Use reflection to get Container.startLWModal. try { ! Method method = AccessController.doPrivileged(new ModalPrivilegedAction( Container.class, "startLWModal")); ! if (method != null) { ! method.invoke(dialog, (Object[])null); } } catch (IllegalAccessException ex) { } catch (IllegalArgumentException ex) { } catch (InvocationTargetException ex) { }
*** 1529,1544 **** if (iFrame.isVisible() && event.getSource() == JOptionPane.this && event.getPropertyName().equals(VALUE_PROPERTY)) { // Use reflection to get Container.stopLWModal(). try { ! Object obj; ! obj = AccessController.doPrivileged( new ModalPrivilegedAction( Container.class, "stopLWModal")); ! if (obj != null) { ! ((Method)obj).invoke(iFrame, (Object[])null); } } catch (IllegalAccessException ex) { } catch (IllegalArgumentException ex) { } catch (InvocationTargetException ex) { } --- 1537,1551 ---- if (iFrame.isVisible() && event.getSource() == JOptionPane.this && event.getPropertyName().equals(VALUE_PROPERTY)) { // Use reflection to get Container.stopLWModal(). try { ! Method method = AccessController.doPrivileged( new ModalPrivilegedAction( Container.class, "stopLWModal")); ! if (method != null) { ! method.invoke(iFrame, (Object[])null); } } catch (IllegalAccessException ex) { } catch (IllegalArgumentException ex) { } catch (InvocationTargetException ex) { }
*** 1850,1860 **** * bound: true * hidden: true * description: The UI object that implements the optionpane's LookAndFeel */ public void setUI(OptionPaneUI ui) { ! if ((OptionPaneUI)this.ui != ui) { super.setUI(ui); invalidate(); } } --- 1857,1867 ---- * bound: true * hidden: true * description: The UI object that implements the optionpane's LookAndFeel */ public void setUI(OptionPaneUI ui) { ! if (this.ui != ui) { super.setUI(ui); invalidate(); } }
*** 2325,2335 **** } } // Serialization support. private void writeObject(ObjectOutputStream s) throws IOException { ! Vector values = new Vector(); s.defaultWriteObject(); // Save the icon, if its Serializable. if(icon != null && icon instanceof Serializable) { values.addElement("icon"); --- 2332,2342 ---- } } // Serialization support. private void writeObject(ObjectOutputStream s) throws IOException { ! Vector<Object> values = new Vector<Object>(); s.defaultWriteObject(); // Save the icon, if its Serializable. if(icon != null && icon instanceof Serializable) { values.addElement("icon");
*** 2340,2350 **** values.addElement("message"); values.addElement(message); } // Save the treeModel, if its Serializable. if(options != null) { ! Vector serOptions = new Vector(); for(int counter = 0, maxCounter = options.length; counter < maxCounter; counter++) if(options[counter] instanceof Serializable) serOptions.addElement(options[counter]); --- 2347,2357 ---- values.addElement("message"); values.addElement(message); } // Save the treeModel, if its Serializable. if(options != null) { ! Vector<Object> serOptions = new Vector<Object>(); for(int counter = 0, maxCounter = options.length; counter < maxCounter; counter++) if(options[counter] instanceof Serializable) serOptions.addElement(options[counter]);
*** 2508,2527 **** } /** * Retrieves a method from the provided class and makes it accessible. */ ! private static class ModalPrivilegedAction implements PrivilegedAction { ! private Class clazz; private String methodName; ! public ModalPrivilegedAction(Class clazz, String methodName) { this.clazz = clazz; this.methodName = methodName; } ! public Object run() { Method method = null; try { method = clazz.getDeclaredMethod(methodName, (Class[])null); } catch (NoSuchMethodException ex) { } --- 2515,2534 ---- } /** * Retrieves a method from the provided class and makes it accessible. */ ! private static class ModalPrivilegedAction implements PrivilegedAction<Method> { ! private Class<?> clazz; private String methodName; ! public ModalPrivilegedAction(Class<?> clazz, String methodName) { this.clazz = clazz; this.methodName = methodName; } ! public Method run() { Method method = null; try { method = clazz.getDeclaredMethod(methodName, (Class[])null); } catch (NoSuchMethodException ex) { }
< prev index next >