This patch properly fixes JInternalFrame, JDialog, and JFrame accepting
invalid defaultCloseOperations.  As per 1.5, JFrame throws an invalid
argument error, but the other two allow (and store) the invalid operator
and default to DO_NOTHING_ON_CLOSE (tested against reference
implementation).

This passes Robert Schuster's Mauve test
gnu.testlet.javax.swing.JDialog.setDefaultCloseOperation.

2005-06-21  Anthony Balkissoon  <[EMAIL PROTECTED]>
        * javax/swing/JDialog.java:
        (setDefaultCloseOperation): Removed validity check for 
        operation code.  Validity is handled in processWindowEvent.
        * javax/swing/JFrame.java:
        (setDefaultCloseOperation): Changed error message to be more
        descriptive and similar to reference implementation.
        * javax/swing/JInternalFrame.java:
        (setDefaultCloseOperation): Removed validity check for 
        operation code.
        *javax/swing/plaf/basic/BasicInternalFrameUI.java:
        (InternalFramePropertyListener): Added implementation of
        VetoableChangeListener.
        (InternalFramePropertyListener.vetoableChange): New method.
        (InternalFramePropertyListener.propertyChange): Removed
        check for JInternalFrame.IS_CLOSED_PROPERTY.  This is now
        handled in vetoableChange.
        (getDesktopManager): Added a check for null pointer from 
        JInternalFrame.getDesktopPane().

This patch can be commited upon approval.

-Tony
? javax/swing/JComponent.java.OLD
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	21 Jun 2005 22:17:07 -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	21 Jun 2005 22:17:07 -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	21 Jun 2005 22:17:07 -0000
@@ -1305,13 +1305,14 @@
    */
   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;
   }
 
+
   /**
    * This method sets the JDesktopIcon that represents this JInternalFrame
    * while it is iconified.
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	21 Jun 2005 22:17:07 -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,25 @@
    * 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.DISPOSE_ON_CLOSE)
+              && (frame.getDefaultCloseOperation() != JInternalFrame.HIDE_ON_CLOSE))
+            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 +900,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 +1048,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 +1195,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 +1577,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;
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to