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 8158478
  27 * @requires (os.family == "linux")
  28 * @summary To Verify X11 Keysym unicode for topt
  29 * @run main/manual Test8158478
  30  */
  31 import java.awt.Button;
  32 import java.awt.Frame;
  33 import java.awt.GridBagConstraints;
  34 import java.awt.GridBagLayout;
  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.util.concurrent.CountDownLatch;
  40 
  41 public class Test8158478 {
  42 
  43     public static void main(String args[]) throws Exception {
  44         final CountDownLatch latch = new CountDownLatch(1);
  45 
  46         X11KeysymTest test = new X11KeysymTest(latch);
  47         Thread T1 = new Thread(test);
  48         T1.start();
  49 
  50         // wait for latch to complete
  51         latch.await();
  52 
  53         if (test.testResult == false) {
  54             throw new RuntimeException("User Clicked Fail! "
  55                     + "Wrong Unicode Character");
  56         }
  57     }
  58 }
  59 
  60 class X11KeysymTest implements Runnable {
  61 
  62     private static GridBagLayout layout;
  63     private static Panel mainControlPanel;
  64     private static Panel resultButtonPanel;
  65     private static TextArea instructionTextArea;
  66     private static Button passButton;
  67     private static Button failButton;
  68     private static Frame mainFrame;
  69     private static TextArea testArea;
  70     private final CountDownLatch latch;
  71     public volatile boolean testResult = false;
  72 
  73     public X11KeysymTest(CountDownLatch latch) {
  74         this.latch = latch;
  75     }
  76 
  77     @Override
  78     public void run() {
  79         createUI();
  80     }
  81 
  82     public final void createUI() {
  83 
  84         mainFrame = new Frame("X11 Keysym Test");
  85         layout = new GridBagLayout();
  86         mainControlPanel = new Panel(layout);
  87         resultButtonPanel = new Panel(layout);
  88 
  89         GridBagConstraints gbc = new GridBagConstraints();
  90         String instructions
  91                 = "INSTRUCTIONS:"
  92                 + "\n Have a custom X11 keyboard layout with"
  93                 + " \"topt\" assigned to some key:  "
  94                 + "\n Map \"topt\" key to \"Caps_Lock\" by executing"
  95                 + " following command in Terminal:"
  96                 + "\n xmodmap -e \"keysym Caps_Lock = topt\"."
  97                 + "\n Go to TextArea below and press \"CAPSLOCK\" key"
  98                 + "\n If Symbol: " + "\u252c" + " is displayed then test Pass,"
  99                 + "\n If Symbol: " + "\u242c" + " is displayed then test Fail,"
 100                 + "\n Execute the below command to reset the above settigs, "
 101                 + "\n setxkbmap -layout us";
 102 
 103         instructionTextArea = new TextArea();
 104         instructionTextArea.setText(instructions);
 105         instructionTextArea.setEnabled(true);
 106 
 107         gbc.gridx = 0;
 108         gbc.gridy = 0;
 109         gbc.fill = GridBagConstraints.HORIZONTAL;
 110         mainControlPanel.add(instructionTextArea, gbc);
 111 
 112         testArea = new TextArea("TextArea");
 113         gbc.gridx = 0;
 114         gbc.gridy = 1;
 115         mainControlPanel.add(testArea, gbc);
 116         passButton = new Button("Pass");
 117         passButton.setActionCommand("Pass");
 118         passButton.addActionListener((ActionEvent e) -> {
 119             testResult = true;
 120             mainFrame.dispose();
 121             latch.countDown();
 122 
 123         });
 124         failButton = new Button("Fail");
 125         failButton.setActionCommand("Fail");
 126         failButton.addActionListener(new ActionListener() {
 127             @Override
 128             public void actionPerformed(ActionEvent e) {
 129                 testResult = false;
 130                 mainFrame.dispose();
 131                 latch.countDown();
 132             }
 133         });
 134         gbc.gridx = 0;
 135         gbc.gridy = 0;
 136         resultButtonPanel.add(passButton, gbc);
 137         gbc.gridx = 1;
 138         gbc.gridy = 0;
 139         resultButtonPanel.add(failButton, gbc);
 140 
 141         gbc.gridx = 0;
 142         gbc.gridy = 2;
 143         mainControlPanel.add(resultButtonPanel, gbc);
 144 
 145         mainFrame.add(mainControlPanel);
 146         mainFrame.pack();
 147         mainFrame.setVisible(true);
 148     }
 149 
 150 }
 151