< prev index next >

test/javax/swing/JList/8161483/Bug8161483.java

Print this page
rev 17561 : 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
Summary: Add new keyword 'printer'. Some minor test fixes to show headless exception. Add some @requires windows.
   1 /*
   2  * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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 8161483
  27  * @summary Implement AccessibleAction in JList.AccessibleJList.AccessibleJListChild
  28  * @run main Bug8161483
  29  */
  30 
  31 import javax.accessibility.Accessible;
  32 import javax.accessibility.AccessibleAction;
  33 import javax.accessibility.AccessibleContext;
  34 import javax.accessibility.AccessibleSelection;
  35 import javax.swing.DefaultListModel;
  36 import javax.swing.JFrame;
  37 import javax.swing.JList;
  38 import javax.swing.SwingUtilities;
  39 
  40 public class Bug8161483 extends JFrame {
  41 
  42     private static JFrame frame;
  43     private static volatile Exception exception = null;
  44     private JList<String> countryList;
  45 
  46     public static void main(String args[]) throws Exception {
  47         try {
  48             SwingUtilities.invokeAndWait(() -> {
  49                 DefaultListModel<String> listModel = new DefaultListModel<>();
  50                 listModel.addElement("one");
  51                 listModel.addElement("two");
  52                 listModel.addElement("three");
  53                 JList<String> list = new JList<>(listModel);
  54                 frame = new JFrame();
  55                 frame.add(list);
  56                 frame.pack();
  57                 try {
  58                     AccessibleContext acList = list.getAccessibleContext();
  59                     Accessible accChild = acList.getAccessibleChild(1);
  60                     AccessibleContext acChild = accChild.getAccessibleContext();
  61                     AccessibleAction aa = acChild.getAccessibleAction();
  62                     int c = aa.getAccessibleActionCount();


  79                     boolean isSelected = as.isAccessibleChildSelected(0);
  80                     if (isSelected) {
  81                         throw new RuntimeException("isAccessibleChildSelected(0) did not return false");
  82                     }
  83                     isSelected = as.isAccessibleChildSelected(1);
  84                     if (!isSelected) {
  85                         throw new RuntimeException("isAccessibleChildSelected(1) did not return true");
  86                     }
  87                 } catch (Exception e) {
  88                     exception = e;
  89                 }
  90             });
  91             if (exception != null) {
  92                 System.out.println("Test failed: " + exception.getMessage());
  93                 throw exception;
  94             } else {
  95                 System.out.println("Test passed.");
  96             }
  97         } finally {
  98             SwingUtilities.invokeAndWait(() -> {
  99                 frame.dispose();
 100             });
 101         }
 102     }
 103 
 104 }
   1 /*
   2  * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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 8161483
  28  * @summary Implement AccessibleAction in JList.AccessibleJList.AccessibleJListChild
  29  * @run main Bug8161483
  30  */
  31 
  32 import javax.accessibility.Accessible;
  33 import javax.accessibility.AccessibleAction;
  34 import javax.accessibility.AccessibleContext;
  35 import javax.accessibility.AccessibleSelection;
  36 import javax.swing.DefaultListModel;
  37 import javax.swing.JFrame;
  38 import javax.swing.JList;
  39 import javax.swing.SwingUtilities;
  40 
  41 public class Bug8161483 extends JFrame {
  42 
  43     private static JFrame frame = null;
  44     private static volatile Exception exception = null;
  45     private JList<String> countryList;
  46 
  47     public static void main(String args[]) throws Exception {
  48         try {
  49             SwingUtilities.invokeAndWait(() -> {
  50                 DefaultListModel<String> listModel = new DefaultListModel<>();
  51                 listModel.addElement("one");
  52                 listModel.addElement("two");
  53                 listModel.addElement("three");
  54                 JList<String> list = new JList<>(listModel);
  55                 frame = new JFrame();
  56                 frame.add(list);
  57                 frame.pack();
  58                 try {
  59                     AccessibleContext acList = list.getAccessibleContext();
  60                     Accessible accChild = acList.getAccessibleChild(1);
  61                     AccessibleContext acChild = accChild.getAccessibleContext();
  62                     AccessibleAction aa = acChild.getAccessibleAction();
  63                     int c = aa.getAccessibleActionCount();


  80                     boolean isSelected = as.isAccessibleChildSelected(0);
  81                     if (isSelected) {
  82                         throw new RuntimeException("isAccessibleChildSelected(0) did not return false");
  83                     }
  84                     isSelected = as.isAccessibleChildSelected(1);
  85                     if (!isSelected) {
  86                         throw new RuntimeException("isAccessibleChildSelected(1) did not return true");
  87                     }
  88                 } catch (Exception e) {
  89                     exception = e;
  90                 }
  91             });
  92             if (exception != null) {
  93                 System.out.println("Test failed: " + exception.getMessage());
  94                 throw exception;
  95             } else {
  96                 System.out.println("Test passed.");
  97             }
  98         } finally {
  99             SwingUtilities.invokeAndWait(() -> {
 100                 if (frame != null) { frame.dispose(); }
 101             });
 102         }
 103     }
 104 
 105 }
< prev index next >