5348N/A/*
5348N/A * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
5348N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5348N/A *
5348N/A * This code is free software; you can redistribute it and/or modify it
5348N/A * under the terms of the GNU General Public License version 2 only, as
5348N/A * published by the Free Software Foundation.
5348N/A *
5348N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5348N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5348N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5348N/A * version 2 for more details (a copy is included in the LICENSE file that
5348N/A * accompanied this code).
5348N/A *
5348N/A * You should have received a copy of the GNU General Public License version
5348N/A * 2 along with this work; if not, write to the Free Software Foundation,
5348N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5348N/A *
5348N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5348N/A * or visit www.oracle.com if you need additional information or have any
5348N/A * questions.
5348N/A */
5348N/A
5348N/A/*
5348N/A * Portions Copyright (c) 2012 IBM Corporation
5348N/A */
5348N/A
5348N/A
5348N/A/* @test
5348N/A * @bug 7129742
5348N/A * @summary Focus in non-editable TextArea is not shown on Linux.
5348N/A * @author Sean Chou
5348N/A */
5348N/A
5348N/Aimport java.awt.FlowLayout;
5348N/Aimport java.awt.TextArea;
5348N/Aimport java.awt.Toolkit;
5348N/Aimport java.lang.reflect.Field;
5348N/A
5348N/Aimport javax.swing.JFrame;
5348N/Aimport javax.swing.JTextArea;
5348N/Aimport javax.swing.SwingUtilities;
5348N/Aimport javax.swing.text.DefaultCaret;
5348N/A
5348N/Aimport sun.awt.SunToolkit;
5348N/A
5348N/Apublic class bug7129742 {
5348N/A
5348N/A public static DefaultCaret caret = null;
5348N/A public static JFrame frame = null;
5348N/A public static boolean fastreturn = false;
5348N/A
5348N/A public static void main(String[] args) throws Exception {
5348N/A SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
5348N/A
5348N/A SwingUtilities.invokeAndWait(new Runnable() {
5348N/A @Override
5348N/A public void run() {
5348N/A frame = new JFrame("Test");
5348N/A TextArea textArea = new TextArea("Non-editable textArea");
5348N/A textArea.setEditable(false);
5348N/A frame.setLayout(new FlowLayout());
5348N/A frame.add(textArea);
5348N/A frame.pack();
5348N/A frame.setVisible(true);
5348N/A
5348N/A try {
5348N/A Class XTextAreaPeerClzz = textArea.getPeer().getClass();
5348N/A System.out.println(XTextAreaPeerClzz.getName());
5348N/A if (!XTextAreaPeerClzz.getName().equals("sun.awt.X11.XTextAreaPeer")) {
5348N/A fastreturn = true;
5348N/A return;
5348N/A }
5348N/A
5348N/A Field jtextField = XTextAreaPeerClzz.getDeclaredField("jtext");
5348N/A jtextField.setAccessible(true);
5348N/A JTextArea jtext = (JTextArea)jtextField.get(textArea.getPeer());
5348N/A caret = (DefaultCaret) jtext.getCaret();
5348N/A
5348N/A textArea.requestFocusInWindow();
5348N/A } catch (NoSuchFieldException | SecurityException
5348N/A | IllegalArgumentException | IllegalAccessException e) {
5348N/A /* These exceptions mean the implementation of XTextAreaPeer is
5348N/A * changed, this testcase is not valid any more, fix it or remove.
5348N/A */
5348N/A frame.dispose();
5348N/A throw new RuntimeException("This testcase is not valid any more!");
5348N/A }
5348N/A }
5348N/A });
5348N/A toolkit.realSync();
5348N/A
5348N/A SwingUtilities.invokeAndWait(new Runnable() {
5348N/A @Override
5348N/A public void run() {
5348N/A try{
5348N/A if (fastreturn) {
5348N/A return;
5348N/A }
5348N/A boolean passed = caret.isActive();
5348N/A System.out.println("is caret visible : " + passed);
5348N/A
5348N/A if (!passed) {
5348N/A throw new RuntimeException("The test for bug 71297422 failed");
5348N/A }
5348N/A } finally {
5348N/A frame.dispose();
5348N/A }
5348N/A }
5348N/A });
5348N/A }
5348N/A
5348N/A}