0N/A/*
2362N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation.
0N/A *
2362N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
2362N/A */
2362N/A
0N/A/*
0N/A * @test
0N/A * @bug 7108598
0N/A * @summary Container.paint/KeyboardFocusManager.clearMostRecentFocusOwner methods deadlock
0N/A * @library ../../regtesthelpers
0N/A * @author Oleg Pekhovskiy
0N/A * @build Util
0N/A * @run main/timeout=20 PaintSetEnabledDeadlock
0N/A */
0N/A
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
0N/Aimport test.java.awt.regtesthelpers.Util;
0N/A
0N/Apublic class PaintSetEnabledDeadlock extends Frame {
0N/A
0N/A final TestPanel panel;
0N/A final Button button;
0N/A
0N/A public static void main(String[] args) {
0N/A PaintSetEnabledDeadlock frame = new PaintSetEnabledDeadlock();
0N/A frame.setSize(200, 200);
0N/A frame.setVisible(true);
0N/A
0N/A Robot robot = Util.createRobot();
0N/A robot.setAutoDelay(100);
0N/A robot.setAutoWaitForIdle(true);
0N/A
0N/A for (int i = 0; i < 20; ++i) {
0N/A Util.clickOnComp(frame.panel, robot);
0N/A Util.clickOnComp(frame.button, robot);
0N/A }
0N/A
0N/A boolean ret = frame.panel.stop();
0N/A frame.dispose();
0N/A
0N/A if (!ret) {
0N/A throw new RuntimeException("Test failed!");
0N/A }
0N/A System.out.println("Test passed.");
0N/A }
0N/A
0N/A public PaintSetEnabledDeadlock() {
0N/A super("7108598 test");
0N/A setLayout(new GridLayout(1, 2));
0N/A addWindowListener(new WindowAdapter() {
0N/A
0N/A @Override
0N/A public void windowClosing(WindowEvent e) {
0N/A panel.stop();
0N/A System.exit(0);
0N/A }
0N/A });
panel = new TestPanel();
add(panel);
button = new Button("Enable");
button.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
panel.setEnabled(true);
panel.sync();
panel.repaint();
}
});
add(button);
}
}
class TestPanel extends Panel implements Runnable {
Image image = null;
Thread thread = null;
volatile boolean active = true;
final Object sync = new Object();
Panel panel = this;
public TestPanel() {
addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
synchronized (panel) {
sync();
panel.setEnabled(false);
}
panel.repaint();
}
});
thread = new Thread(this);
thread.start();
}
@Override
public void paint(Graphics paramGraphics) {
synchronized (getTreeLock()) {
Rectangle rect = getBounds();
if (image == null) {
image = createImage(rect.width, rect.height);
}
if (image != null) {
paramGraphics.drawImage(image, 0, 0, this);
}
}
}
@Override
public void run() {
while (active) {
try {
synchronized (sync) {
sync.wait();
}
} catch (InterruptedException ex) {
}
if (active) {
draw();
}
}
}
public boolean stop() {
active = false;
try {
sync();
thread.join(1000);
if (thread.isAlive()) {
thread.interrupt();
return false;
}
} catch (InterruptedException ex) {
return false;
}
return true;
}
public void draw() {
synchronized (getTreeLock()) {
if (image != null) {
Graphics localGraphics = image.getGraphics();
Dimension size = getSize();
localGraphics.setColor(isEnabled() ? Color.green : Color.red);
localGraphics.fillRect(0, 0, size.width, size.height);
super.paint(localGraphics);
localGraphics.dispose();
getTreeLock().notifyAll();
}
}
}
public void sync() {
synchronized (sync) {
sync.notify();
}
}
}