This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: JFrame DefaultCloseOperation CLOSE_ON_EXIT fixlet


Hi,

On Thu, 2004-04-15 at 11:30, Mark Wielaard wrote:
> Noticed that JFrame get/setDefaultCloseOperation weren't public and
> didn't do the right default thing. So I fixed them and added the correct
> argument checking to setDefaultCloseOperation.

Here is a similar patch for JDialog. But I also had to make the
constructors public to even use this class. There is clearly still much
to do. I stopped playing with it as soon as I saw my first JDialog pop
up. Both JFrame and JDialog should get their constants through the
WindowConstants interface which they now both implement.

2004-04-15  Mark Wielaard  <mark@klomp.org>
                                                                                
        * javax/awt/JFrame.java: Implement WindowConstants. Remove final
        static fields defined in interface.
        * javax/awt/JDialog.java: Likewise.
        (JDialog): Make constructors public.
        (getDefaultCloseOperation): Make public.
        (processWindowEvent): Call System.exit(0) when HIDE_ON_CLOSE set.
        (setDefaultCloseOperation): Make public. Check argument. Add API doc.

> Committed to classpath CVS.
> Could someone with a recent gcj-gui-branch checkout add it there?

Same again.

Thanks,

Mark
Index: javax/swing/JDialog.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JDialog.java,v
retrieving revision 1.5
diff -u -r1.5 JDialog.java
--- javax/swing/JDialog.java	8 Jun 2003 11:20:07 -0000	1.5
+++ javax/swing/JDialog.java	15 Apr 2004 11:30:58 -0000
@@ -1,5 +1,5 @@
 /* JDialog.java --
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2004 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -57,12 +57,8 @@
  *
  * @author Ronald Veldema (rveldema@cs.vu.nl)
  */
-public class JDialog extends Dialog implements Accessible
+public class JDialog extends Dialog implements Accessible, WindowConstants
 {
-    public final static int HIDE_ON_CLOSE        = 0;
-    public final static int DISPOSE_ON_CLOSE     = 1;
-    public final static int DO_NOTHING_ON_CLOSE  = 2;
-
     protected  AccessibleContext accessibleContext;
 
     private int close_action = HIDE_ON_CLOSE;    
@@ -75,42 +71,42 @@
      *
      *************/
 
-    JDialog(Frame owner)
+    public JDialog(Frame owner)
     {
 	this(owner, "dialog");
     }
     
-    JDialog(Frame owner,
+    public JDialog(Frame owner,
 	    String s)
     {
 	this(owner, s, true);
     }
     
-  JDialog(Frame owner,
+  public JDialog(Frame owner,
 	  String s,
 	  boolean modeld)
     {
 	super(owner, s, modeld);
     }
 
-  JDialog(Frame owner,
+  public JDialog(Frame owner,
 	  //  String s,
 	  boolean modeld)
     {
 	super(owner, "JDialog", modeld);
     }
-  JDialog(Dialog owner)
+  public JDialog(Dialog owner)
   {
       this(owner, "dialog");
   }
     
-    JDialog(Dialog owner,
+    public JDialog(Dialog owner,
 	    String s)
     {
 	this(owner, s, true);
     }
     
-  JDialog(Dialog owner,
+  public JDialog(Dialog owner,
 	  String s,
 	  boolean modeld)
     {
@@ -221,18 +217,20 @@
 
     protected  void processWindowEvent(WindowEvent e)
     {
-	//	System.out.println("PROCESS_WIN_EV-1: " + e);
 	super.processWindowEvent(e); 
-	//	System.out.println("PROCESS_WIN_EV-2: " + e);
 	switch (e.getID())
 	    {
 	    case WindowEvent.WINDOW_CLOSING:
 		{
 		    switch(close_action)
 			{
+			case EXIT_ON_CLOSE:
+			  {
+			    System.exit(0);
+			    break;
+			  }
 			case DISPOSE_ON_CLOSE:
 			    {
-				System.out.println("user requested dispose on close");
 				dispose();
 				break;
 			    }
@@ -258,8 +256,34 @@
     }   
  
 
-    void setDefaultCloseOperation(int operation)
-    {  close_action = operation;   }
+  /**
+   * Defines what happens when this frame is closed. Can be one off
+   * <code>EXIT_ON_CLOSE</code>,
+   * <code>DISPOSE_ON_CLOSE</code>,
+   * <code>HIDE_ON_CLOSE</code> or
+   * <code>DO_NOTHING_ON_CLOSE</code>.
+   * The default is <code>HIDE_ON_CLOSE</code>.
+   * When <code>EXIT_ON_CLOSE</code> is specified this method calls
+   * <code>SecurityManager.checkExit(0)</code> which might throw a
+   * <code>SecurityException</code>. When the specified operation is
+   * not one of the above a <code>IllegalArgumentException</code> is
+   * thrown.
+   */
+  public void setDefaultCloseOperation(int operation)
+  {
+    SecurityManager sm = System.getSecurityManager();
+    if (sm != null && operation == EXIT_ON_CLOSE)
+      sm.checkExit(0);
+    
+    if (operation != EXIT_ON_CLOSE && operation != DISPOSE_ON_CLOSE
+	&& operation != HIDE_ON_CLOSE && operation != DO_NOTHING_ON_CLOSE)
+      throw new IllegalArgumentException("operation = " + operation);
+    
+    close_action = operation;
+  }
+  
+  public int getDefaultCloseOperation()
+  {    return close_action;   }
 
     protected  String paramString()
     {   return "JDialog";     }
Index: javax/swing/JFrame.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JFrame.java,v
retrieving revision 1.9
diff -u -r1.9 JFrame.java
--- javax/swing/JFrame.java	15 Apr 2004 09:35:52 -0000	1.9
+++ javax/swing/JFrame.java	15 Apr 2004 11:30:58 -0000
@@ -1,5 +1,5 @@
 /* JFrame.java --
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2004 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -57,13 +57,8 @@
  *
  * @author Ronald Veldema (rveldema@cs.vu.nl)
  */
-public class JFrame extends Frame
+public class JFrame extends Frame implements WindowConstants
 {
-    public final static int HIDE_ON_CLOSE        = 0;
-    public final static int EXIT_ON_CLOSE        = 1;
-    public final static int DISPOSE_ON_CLOSE     = 2;
-    public final static int DO_NOTHING_ON_CLOSE  = 3;
-
     protected  AccessibleContext accessibleContext;
 
     private int close_action = HIDE_ON_CLOSE;    

Attachment: signature.asc
Description: This is a digitally signed message part


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]