Index: javax/swing/JDialog.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/JDialog.java,v retrieving revision 1.13 diff -u -r1.13 JDialog.java --- javax/swing/JDialog.java 17 Jun 2005 11:53:50 -0000 1.13 +++ javax/swing/JDialog.java 22 Jun 2005 14:55:59 -0000 @@ -547,14 +547,12 @@ */ public void setDefaultCloseOperation(int operation) { - if (operation == DO_NOTHING_ON_CLOSE || - operation == HIDE_ON_CLOSE || - operation == DISPOSE_ON_CLOSE) - close_action = operation; - else - // accept illegal value and set the property to the default value, - // that's what the reference implementation does - close_action = DO_NOTHING_ON_CLOSE; + /* Reference implementation allows invalid operations + to be specified. If so, getDefaultCloseOperation + must return the invalid code, and the behaviour + defaults to DO_NOTHING_ON_CLOSE. processWindowEvent + above handles this */ + close_action = operation; } /** Index: javax/swing/JFrame.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/JFrame.java,v retrieving revision 1.23 diff -u -r1.23 JFrame.java --- javax/swing/JFrame.java 17 Jun 2005 11:53:50 -0000 1.23 +++ javax/swing/JFrame.java 22 Jun 2005 14:55:59 -0000 @@ -342,7 +342,7 @@ if (operation != EXIT_ON_CLOSE && operation != DISPOSE_ON_CLOSE && operation != HIDE_ON_CLOSE && operation != DO_NOTHING_ON_CLOSE) - throw new IllegalArgumentException("operation = " + operation); + throw new IllegalArgumentException("defaultCloseOperation must be EXIT_ON_CLOSE, HIDE_ON_CLOSE, DISPOSE_ON_CLOSE, or DO_NOTHING_ON_CLOSE"); close_action = operation; } Index: javax/swing/JInternalFrame.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/JInternalFrame.java,v retrieving revision 1.17 diff -u -r1.17 JInternalFrame.java --- javax/swing/JInternalFrame.java 17 Jun 2005 11:53:50 -0000 1.17 +++ javax/swing/JInternalFrame.java 22 Jun 2005 14:55:59 -0000 @@ -1305,10 +1305,10 @@ */ public void setDefaultCloseOperation(int operation) { - if (operation != DO_NOTHING_ON_CLOSE - && operation != HIDE_ON_CLOSE - && operation != DISPOSE_ON_CLOSE) - throw new Error("Close operation must be one of DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE, or DISPOSE_ON_CLOSE"); + /* Reference implementation allows invalid operations to be specified. + In that case, behaviour defaults to DO_NOTHING_ON_CLOSE. + processWindowEvent handles the behaviour. getDefaultCloseOperation + must return the invalid operator code. */ defaultCloseOperation = operation; } Index: javax/swing/plaf/basic/BasicInternalFrameUI.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicInternalFrameUI.java,v retrieving revision 1.7 diff -u -r1.7 BasicInternalFrameUI.java --- javax/swing/plaf/basic/BasicInternalFrameUI.java 4 Jun 2005 19:16:11 -0000 1.7 +++ javax/swing/plaf/basic/BasicInternalFrameUI.java 22 Jun 2005 14:55:59 -0000 @@ -53,6 +53,8 @@ import java.awt.event.MouseEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.beans.PropertyVetoException; +import java.beans.VetoableChangeListener; import javax.swing.DefaultDesktopManager; import javax.swing.DesktopManager; @@ -864,8 +866,28 @@ * JInternalFrame. */ public class InternalFramePropertyChangeListener - implements PropertyChangeListener + implements PropertyChangeListener, VetoableChangeListener { + + /** + * This method is called when one of the JInternalFrame's properties + * change. This method is to allow JInternalFrame to veto an attempt + * to close the internal frame. This allows JInternalFrame to honour + * its defaultCloseOperation if that is DO_NOTHING_ON_CLOSE. + */ + public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException + { + if (e.getPropertyName().equals(JInternalFrame.IS_CLOSED_PROPERTY)) + { + if (frame.getDefaultCloseOperation() == JInternalFrame.HIDE_ON_CLOSE) + frame.setVisible(false); + else if (frame.getDefaultCloseOperation() == JInternalFrame.DISPOSE_ON_CLOSE) + closeFrame(frame); + else + throw new PropertyVetoException ("close operation is DO_NOTHING_ON_CLOSE\n", e); + } + } + /** * This method is called when one of the JInternalFrame's properties * change. @@ -881,8 +903,6 @@ else minimizeFrame(frame); } - else if (evt.getPropertyName().equals(JInternalFrame.IS_CLOSED_PROPERTY)) - closeFrame(frame); else if (evt.getPropertyName().equals(JInternalFrame.IS_ICON_PROPERTY)) { if (frame.isIcon()) @@ -1031,6 +1051,13 @@ */ protected PropertyChangeListener propertyChangeListener; + /** + * The VetoableChangeListener. Listens to PropertyChangeEvents + * from the JInternalFrame and allows the JInternalFrame to + * veto attempts to close it. + */ + private VetoableChangeListener internalFrameVetoableChangeListener; + /** The InternalFrameListener that listens to the JInternalFrame. */ private transient BasicInternalFrameListener internalFrameListener; @@ -1171,12 +1198,13 @@ borderListener = createBorderListener(frame); componentListener = createComponentListener(); propertyChangeListener = createPropertyChangeListener(); + internalFrameVetoableChangeListener = new InternalFramePropertyChangeListener(); frame.addMouseListener(borderListener); frame.addMouseMotionListener(borderListener); frame.addInternalFrameListener(internalFrameListener); frame.addPropertyChangeListener(propertyChangeListener); - + frame.addVetoableChangeListener(internalFrameVetoableChangeListener); frame.getRootPane().getGlassPane().addMouseListener(glassPaneDispatcher); frame.getRootPane().getGlassPane().addMouseMotionListener(glassPaneDispatcher); } @@ -1552,7 +1580,10 @@ */ protected DesktopManager getDesktopManager() { - DesktopManager value = frame.getDesktopPane().getDesktopManager(); + DesktopManager value = null; + JDesktopPane pane = frame.getDesktopPane(); + if (pane != null) + value = frame.getDesktopPane().getDesktopManager(); if (value == null) value = createDesktopManager(); return value;