< prev index next >

test/jdk/java/awt/Focus/WindowUpdateFocusabilityTest/WindowUpdateFocusabilityTest.java

Print this page




   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25   test

  26   @bug       6253913
  27   @summary   Tests that a Window shown before its owner is focusable.
  28   @author    anton.tarasov@sun.com: area=awt-focus
  29   @run       applet WindowUpdateFocusabilityTest.html
  30 */
  31 
  32 import java.awt.*;
  33 import java.awt.event.*;
  34 import java.applet.Applet;
  35 import java.lang.reflect.*;
  36 
  37 public class WindowUpdateFocusabilityTest extends Applet {
  38     Robot robot;
  39     boolean focusGained = false;
  40     final Object monitor = new Object();
  41     FocusListener listener = new FocusAdapter () {
  42             public void focusGained(FocusEvent e) {
  43                 System.out.println(e.toString());
  44                 synchronized (monitor) {
  45                     focusGained = true;
  46                     monitor.notifyAll();
  47                 }
  48             }
  49         };
  50 
  51     public static void main(String[] args) {
  52         WindowUpdateFocusabilityTest app = new WindowUpdateFocusabilityTest();
  53         app.init();
  54         app.start();
  55     }
  56 
  57     public void init() {
  58         try {
  59             robot = new Robot();
  60         } catch (AWTException e) {
  61             throw new RuntimeException("Error: couldn't create robot");
  62         }
  63         // Create instructions for the user here, as well as set up
  64         // the environment -- set the layout manager, add buttons,
  65         // etc.
  66         this.setLayout (new BorderLayout ());
  67     }
  68 
  69     public void start() {
  70         if ("sun.awt.motif.MToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName())) {
  71             System.out.println("No testing on Motif.");
  72             return;
  73         }
  74 
  75         test(new Frame("Frame owner"));
  76         Frame dialog_owner = new Frame("dialog's owner");
  77         test(new Dialog(dialog_owner));
  78         test(new Dialog(dialog_owner, Dialog.ModalityType.DOCUMENT_MODAL));
  79         test(new Dialog(dialog_owner, Dialog.ModalityType.APPLICATION_MODAL));
  80         test(new Dialog(dialog_owner, Dialog.ModalityType.TOOLKIT_MODAL));
  81         test(new Dialog((Window) null, Dialog.ModalityType.MODELESS));
  82         test(new Dialog((Window) null, Dialog.ModalityType.DOCUMENT_MODAL));
  83         test(new Dialog((Window) null, Dialog.ModalityType.APPLICATION_MODAL));
  84         test(new Dialog((Window) null, Dialog.ModalityType.TOOLKIT_MODAL));
  85         dialog_owner.dispose();
  86     }




   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25   @test
  26   @key headful
  27   @bug        6253913
  28   @summary    Tests that a Window shown before its owner is focusable.
  29   @modules java.desktop/sun.awt
  30   @run        main WindowUpdateFocusabilityTest
  31 */
  32 
  33 import java.awt.*;
  34 import java.awt.event.*;

  35 import java.lang.reflect.*;
  36 
  37 public class WindowUpdateFocusabilityTest {
  38     Robot robot;
  39     boolean focusGained = false;
  40     final Object monitor = new Object();
  41     FocusListener listener = new FocusAdapter () {
  42             public void focusGained(FocusEvent e) {
  43                 System.out.println(e.toString());
  44                 synchronized (monitor) {
  45                     focusGained = true;
  46                     monitor.notifyAll();
  47                 }
  48             }
  49         };
  50 
  51     public static void main(String[] args) {
  52         WindowUpdateFocusabilityTest app = new WindowUpdateFocusabilityTest();
  53         app.init();
  54         app.start();
  55     }
  56 
  57     public void init() {
  58         try {
  59             robot = new Robot();
  60         } catch (AWTException e) {
  61             throw new RuntimeException("Error: couldn't create robot");
  62         }




  63     }
  64 
  65     public void start() {
  66         if ("sun.awt.motif.MToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName())) {
  67             System.out.println("No testing on Motif.");
  68             return;
  69         }
  70 
  71         test(new Frame("Frame owner"));
  72         Frame dialog_owner = new Frame("dialog's owner");
  73         test(new Dialog(dialog_owner));
  74         test(new Dialog(dialog_owner, Dialog.ModalityType.DOCUMENT_MODAL));
  75         test(new Dialog(dialog_owner, Dialog.ModalityType.APPLICATION_MODAL));
  76         test(new Dialog(dialog_owner, Dialog.ModalityType.TOOLKIT_MODAL));
  77         test(new Dialog((Window) null, Dialog.ModalityType.MODELESS));
  78         test(new Dialog((Window) null, Dialog.ModalityType.DOCUMENT_MODAL));
  79         test(new Dialog((Window) null, Dialog.ModalityType.APPLICATION_MODAL));
  80         test(new Dialog((Window) null, Dialog.ModalityType.TOOLKIT_MODAL));
  81         dialog_owner.dispose();
  82     }


< prev index next >