< prev index next >

test/java/awt/event/MouseEvent/AltGraphModifierTest/AltGraphModifierTest.java

Print this page




   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 8041928
  27  @summary Confirm that the Alt-Gr Modifier bit is set correctly.

  28  @run main/manual AltGraphModifierTest
  29  */

  30 import java.awt.Button;
  31 import java.awt.Dialog;
  32 import java.awt.Frame;
  33 import java.awt.Panel;
  34 import java.awt.TextArea;
  35 import java.awt.event.ActionEvent;
  36 import java.awt.event.ActionListener;
  37 import java.awt.event.InputEvent;
  38 import java.awt.event.MouseAdapter;
  39 import java.awt.event.MouseEvent;

  40 
  41 public class AltGraphModifierTest {
  42     private static void init() throws Exception {
  43         String[] instructions
  44                 = {
  45                     "This test is for verifying Alt-Gr modifier of an event.",
  46                     "Windows :-",
  47                     "1. Click Pass.",
  48                     "2. Alt-Gr modifier is tested under Robot tests.",
  49                     " ",
  50                     "Linux :-",
  51                     "1. Please check if Alt-Gr key is present on keyboard.",
  52                     "2. If present, press the Alt-Gr key and perform",
  53                     "   mouse click on the TestWindow.",
  54                     "3. Navigate to System Settings-> Keyboard-> Shortcuts->",
  55                     "   Typing.",
  56                     "4. Select an option for the Alternative Characters Key",
  57                     "   For example. Right Alt",
  58                     "5. Close the settings and navigate to test",
  59                     "6. Press Right Alt Key & perform mouse click on the",
  60                     "   TestWindow",
  61                     "7. Test will exit by itself with appropriate result.",
  62                     " ",
  63                     "Mac :-",
  64                     "1. Press Right Option key on the keyboard and mouse click",
  65                     "   on the TestWindow",
  66                     "3. Test will exit by itself with appropriate result.",
  67                 };
  68 
  69         Sysout.createDialog();
  70         Sysout.printInstructions(instructions);
  71     }
  72 
  73     static Frame mainFrame;
  74     public static void initTestWindow() {
  75         mainFrame = new Frame();
  76         mainFrame.setTitle("TestWindow");
  77         mainFrame.setBounds(700, 10, 300, 300);
  78         mainFrame.addMouseListener(new MouseAdapter() {
  79             @Override
  80             public void mousePressed(MouseEvent e) {
  81                 int ex = e.getModifiersEx();
  82                 if ((ex & InputEvent.ALT_GRAPH_DOWN_MASK) == 0) {
  83                     AltGraphModifierTest.fail("Alt-Gr Modifier bit is not set.");
  84                 } else {
  85                     AltGraphModifierTest.pass();
  86                 }


  94         mainFrame.dispose();
  95     }
  96 
  97     /**
  98      * ***************************************************
  99      * Standard Test Machinery Section DO NOT modify anything in this section --
 100      * it's a standard chunk of code which has all of the synchronisation
 101      * necessary for the test harness. By keeping it the same in all tests, it
 102      * is easier to read and understand someone else's test, as well as insuring
 103      * that all tests behave correctly with the test harness. There is a section
 104      * following this for test-defined classes
 105      * ****************************************************
 106      */
 107     private static boolean theTestPassed = false;
 108     private static boolean testGeneratedInterrupt = false;
 109     private static String failureMessage = "";
 110     private static Thread mainThread = null;
 111     final private static int sleepTime = 300000;
 112 
 113     public static void main(String args[]) throws Exception {




 114         mainThread = Thread.currentThread();
 115         try {
 116             init();
 117             initTestWindow();
 118         } catch (Exception e) {
 119             e.printStackTrace();
 120         }
 121         try {
 122             mainThread.sleep(sleepTime);
 123         } catch (InterruptedException e) {
 124             dispose();
 125             if (testGeneratedInterrupt && !theTestPassed) {
 126                 throw new Exception(failureMessage);
 127             }
 128         }
 129         if (!testGeneratedInterrupt) {
 130             dispose();
 131             throw new RuntimeException("Timed out after " + sleepTime / 1000
 132                     + " seconds");
 133         }


 192 }
 193 
 194 /**
 195  * This is part of the standard test machinery. It provides a place for the test
 196  * instructions to be displayed, and a place for interactive messages to the
 197  * user to be displayed. To have the test instructions displayed, see Sysout. To
 198  * have a message to the user be displayed, see Sysout. Do not call anything in
 199  * this dialog directly.
 200  */
 201 class TestDialog extends Dialog implements ActionListener {
 202     TextArea instructionsText;
 203     TextArea messageText;
 204     int maxStringLength = 80;
 205     Panel buttonP;
 206     Button failB;
 207 
 208     // DO NOT call this directly, go through Sysout
 209     public TestDialog(Frame frame, String name) {
 210         super(frame, name);
 211         int scrollBoth = TextArea.SCROLLBARS_BOTH;
 212         instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);
 213         add("North", instructionsText);
 214 
 215         messageText = new TextArea("", 5, maxStringLength, scrollBoth);
 216         add("Center", messageText);
 217 
 218         buttonP = new Panel();
 219         failB = new Button("Fail");
 220         failB.setActionCommand("fail");
 221         failB.addActionListener(this);
 222         buttonP.add("Center", failB);
 223 
 224         add("South", buttonP);
 225         pack();
 226         setVisible(true);
 227     }
 228 
 229     // DO NOT call this directly, go through Sysout
 230     public void printInstructions(String[] instructions) {
 231         instructionsText.setText("");
 232         String printStr, remainingStr;




   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 8041928 8158616
  27  @summary Confirm that the Alt-Gr Modifier bit is set correctly.
  28  @library ../../../../../lib/testlibrary
  29  @run main/manual AltGraphModifierTest
  30  */
  31 
  32 import java.awt.Button;
  33 import java.awt.Dialog;
  34 import java.awt.Frame;
  35 import java.awt.Panel;
  36 import java.awt.TextArea;
  37 import java.awt.event.ActionEvent;
  38 import java.awt.event.ActionListener;
  39 import java.awt.event.InputEvent;
  40 import java.awt.event.MouseAdapter;
  41 import java.awt.event.MouseEvent;
  42 import jdk.testlibrary.OSInfo;
  43 
  44 public class AltGraphModifierTest {
  45     private static void init() throws Exception {
  46         String[] instructions
  47                 = {
  48                     "This test is for verifying Alt-Gr modifier of an event.",




  49                     "Linux :-",
  50                     "1. Please check if Alt-Gr key is present on keyboard.",
  51                     "2. If present, press the Alt-Gr key and perform",
  52                     "   mouse click on the TestWindow.",
  53                     "3. Navigate to System Settings-> Keyboard-> Shortcuts->",
  54                     "   Typing.",
  55                     "4. Select an option for the Alternative Characters Key",
  56                     "   For example. Right Alt",
  57                     "5. Close the settings and navigate to test",
  58                     "6. Press Right Alt Key & perform mouse click on the",
  59                     "   TestWindow",
  60                     "7. Test will exit by itself with appropriate result.",
  61                     " ",
  62                     "Mac :-",
  63                     "1. Press Right Option key on the keyboard and mouse click",
  64                     "   on the TestWindow",
  65                     "2. Test will exit by itself with appropriate result.",
  66                 };
  67 
  68         Sysout.createDialog();
  69         Sysout.printInstructions(instructions);
  70     }
  71 
  72     static Frame mainFrame;
  73     public static void initTestWindow() {
  74         mainFrame = new Frame();
  75         mainFrame.setTitle("TestWindow");
  76         mainFrame.setBounds(700, 10, 300, 300);
  77         mainFrame.addMouseListener(new MouseAdapter() {
  78             @Override
  79             public void mousePressed(MouseEvent e) {
  80                 int ex = e.getModifiersEx();
  81                 if ((ex & InputEvent.ALT_GRAPH_DOWN_MASK) == 0) {
  82                     AltGraphModifierTest.fail("Alt-Gr Modifier bit is not set.");
  83                 } else {
  84                     AltGraphModifierTest.pass();
  85                 }


  93         mainFrame.dispose();
  94     }
  95 
  96     /**
  97      * ***************************************************
  98      * Standard Test Machinery Section DO NOT modify anything in this section --
  99      * it's a standard chunk of code which has all of the synchronisation
 100      * necessary for the test harness. By keeping it the same in all tests, it
 101      * is easier to read and understand someone else's test, as well as insuring
 102      * that all tests behave correctly with the test harness. There is a section
 103      * following this for test-defined classes
 104      * ****************************************************
 105      */
 106     private static boolean theTestPassed = false;
 107     private static boolean testGeneratedInterrupt = false;
 108     private static String failureMessage = "";
 109     private static Thread mainThread = null;
 110     final private static int sleepTime = 300000;
 111 
 112     public static void main(String args[]) throws Exception {
 113         if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) {
 114             // For Windows: Alt-Gr modifier is tested under Robot tests.
 115             return;
 116         }
 117         mainThread = Thread.currentThread();
 118         try {
 119             init();
 120             initTestWindow();
 121         } catch (Exception e) {
 122             e.printStackTrace();
 123         }
 124         try {
 125             mainThread.sleep(sleepTime);
 126         } catch (InterruptedException e) {
 127             dispose();
 128             if (testGeneratedInterrupt && !theTestPassed) {
 129                 throw new Exception(failureMessage);
 130             }
 131         }
 132         if (!testGeneratedInterrupt) {
 133             dispose();
 134             throw new RuntimeException("Timed out after " + sleepTime / 1000
 135                     + " seconds");
 136         }


 195 }
 196 
 197 /**
 198  * This is part of the standard test machinery. It provides a place for the test
 199  * instructions to be displayed, and a place for interactive messages to the
 200  * user to be displayed. To have the test instructions displayed, see Sysout. To
 201  * have a message to the user be displayed, see Sysout. Do not call anything in
 202  * this dialog directly.
 203  */
 204 class TestDialog extends Dialog implements ActionListener {
 205     TextArea instructionsText;
 206     TextArea messageText;
 207     int maxStringLength = 80;
 208     Panel buttonP;
 209     Button failB;
 210 
 211     // DO NOT call this directly, go through Sysout
 212     public TestDialog(Frame frame, String name) {
 213         super(frame, name);
 214         int scrollBoth = TextArea.SCROLLBARS_BOTH;
 215         instructionsText = new TextArea("", 20, maxStringLength, scrollBoth);
 216         add("North", instructionsText);
 217 
 218         messageText = new TextArea("", 5, maxStringLength, scrollBoth);
 219         add("Center", messageText);
 220 
 221         buttonP = new Panel();
 222         failB = new Button("Fail");
 223         failB.setActionCommand("fail");
 224         failB.addActionListener(this);
 225         buttonP.add("Center", failB);
 226 
 227         add("South", buttonP);
 228         pack();
 229         setVisible(true);
 230     }
 231 
 232     // DO NOT call this directly, go through Sysout
 233     public void printInstructions(String[] instructions) {
 234         instructionsText.setText("");
 235         String printStr, remainingStr;


< prev index next >