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]

[PATCH] Fix show() for modal Dialogs in general


My previous patch fixed only the FileDialog case. This one makes it work as described in the AWT documentation for general dialogs as well.

NOTE: The code for handling the queue was already written but was never tested before. There are a few things that I believe need fixing so I will investigate that further.

OK to check it in?

2004-01-09 Fernando Nasser <fnasser@redhat.com>

* java/awt/Dialog.java (show): Enable blocking for all modal dialogs
and run secondary dispatch thread to process event queue while this
thread is blocked.




--
Fernando Nasser
Red Hat Canada Ltd.                     E-Mail:  fnasser@redhat.com
2323 Yonge Street, Suite #300
Toronto, Ontario   M4P 2C9
Index: java/awt/Dialog.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Dialog.java,v
retrieving revision 1.12
diff -c -p -r1.12 Dialog.java
*** java/awt/Dialog.java	8 Jan 2004 21:12:25 -0000	1.12
--- java/awt/Dialog.java	9 Jan 2004 23:37:23 -0000
*************** private boolean undecorated = false;
*** 88,93 ****
--- 88,99 ----
    */
  private boolean blocked = false;
  
+ /**
+   * Secondary EventQueue to handle AWT events while
+   * we are blocked for modality in show
+   */
+ private EventQueue eq2 = null;
+ 
  /*************************************************************************/
  
  /*
*************** public synchronized void
*** 394,413 ****
  show()
  {
    super.show();
    if (isModal())
      {
        // If already shown (and blocked) just return
        if (blocked)
  	return;
  
!       /* FIXME: Currently this thread may block forever if it called from
!          the event dispatch thread, so we only do this for FileDialog which
!          only depends on a signal which is delivered in the Gtk thread.
!          Remove this test when we add code to start another event
!          dispatch thread. */
!       if ((Thread.currentThread () instanceof EventDispatchThread) &&
!           !(this instanceof FileDialog))
!         return;
        
        try 
          {
--- 400,421 ----
  show()
  {
    super.show();
+   
    if (isModal())
      {
        // If already shown (and blocked) just return
        if (blocked)
  	return;
  
!       /* If show is called in the dispatch thread for a modal dialog it will
!          block so we must run another thread so the events keep being
! 	 dispatched.*/
!       if (EventQueue.isDispatchThread ())
!         {
! 	  EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
!           eq2 = new EventQueue ();
! 	  eq.push (eq2);
! 	}
        
        try 
          {
*************** show()
*** 418,425 ****
        catch (InterruptedException e)
          {
  	  blocked = false;
- 	  return;
          }
      }  
  }
  
--- 426,438 ----
        catch (InterruptedException e)
          {
  	  blocked = false;
          }
+ 	
+       if (eq2 != null)
+         {
+ 	  eq2.pop ();
+ 	  eq2 = null;
+ 	}
      }  
  }
  

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