4844N/A/*
4844N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
4844N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4844N/A *
4844N/A * This code is free software; you can redistribute it and/or modify it
4844N/A * under the terms of the GNU General Public License version 2 only, as
4844N/A * published by the Free Software Foundation.
4844N/A *
4844N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4844N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4844N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4844N/A * version 2 for more details (a copy is included in the LICENSE file that
4844N/A * accompanied this code).
4844N/A *
4844N/A * You should have received a copy of the GNU General Public License version
4844N/A * 2 along with this work; if not, write to the Free Software Foundation,
4844N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4844N/A *
4844N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4844N/A * or visit www.oracle.com if you need additional information or have any
4844N/A * questions.
4844N/A */
4844N/A
4844N/A/* @test
4844N/A * @bug 4247996 4260485
4844N/A * @summary Test that rollover toolbar doesn't corrupt buttons
4844N/A * @author Peter Zhelezniakov
4844N/A * @run main bug4247996
4844N/A */
4844N/Aimport java.awt.*;
4844N/Aimport javax.swing.*;
4844N/Aimport sun.awt.SunToolkit;
4844N/A
4844N/Apublic class bug4247996 {
4844N/A
4844N/A private static JButton button;
4844N/A private static JToggleButton toogleButton;
4844N/A
4844N/A public static void main(String[] args) throws Exception {
4844N/A
4844N/A SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
4844N/A Robot robot = new Robot();
4844N/A robot.setAutoDelay(50);
4844N/A
4844N/A UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
4844N/A
4844N/A javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
4844N/A
4844N/A public void run() {
4844N/A createAndShowGUI();
4844N/A }
4844N/A });
4844N/A
4844N/A toolkit.realSync();
4844N/A
4844N/A Point point = getButtonCenter();
4844N/A robot.mouseMove(point.x, point.y);
4844N/A toolkit.realSync();
4844N/A
4844N/A checkButtonsSize();
4844N/A
4844N/A }
4844N/A
4844N/A private static void checkButtonsSize() throws Exception {
4844N/A SwingUtilities.invokeAndWait(new Runnable() {
4844N/A
4844N/A @Override
4844N/A public void run() {
4844N/A if (!button.getSize().equals(toogleButton.getSize())) {
4844N/A throw new RuntimeException("Button sizes are different!");
4844N/A }
4844N/A }
4844N/A });
4844N/A }
4844N/A
4844N/A private static Point getButtonCenter() throws Exception {
4844N/A final Point[] result = new Point[1];
4844N/A
4844N/A SwingUtilities.invokeAndWait(new Runnable() {
4844N/A
4844N/A @Override
4844N/A public void run() {
4844N/A Point p = button.getLocationOnScreen();
4844N/A Dimension size = button.getSize();
4844N/A result[0] = new Point(p.x + size.width / 2, p.y + size.height / 2);
4844N/A }
4844N/A });
4844N/A return result[0];
4844N/A }
4844N/A
4844N/A private static void createAndShowGUI() {
4844N/A JFrame frame = new JFrame("Test");
4844N/A frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
4844N/A frame.setSize(200, 200);
4844N/A
4844N/A JButton rButton = new JButton("Rollover");
4844N/A rButton.setRolloverEnabled(true);
4844N/A JToolBar nrToolbar = new JToolBar();
4844N/A nrToolbar.add(rButton);
4844N/A nrToolbar.remove(rButton);
4844N/A
4844N/A if (!rButton.isRolloverEnabled()) {
4844N/A throw new Error("Failed (bug 4260485): "
4844N/A + "toolbar overrode button's rollover property");
4844N/A }
4844N/A
4844N/A JToolBar rToolbar = new JToolBar();
4844N/A rToolbar.putClientProperty("JToolBar.isRollover", Boolean.TRUE);
4844N/A rToolbar.add(button = new JButton("Test"));
4844N/A rToolbar.add(toogleButton = new JToggleButton("Test"));
4844N/A
4844N/A frame.getContentPane().add(rToolbar, BorderLayout.NORTH);
4844N/A frame.setVisible(true);
4844N/A }
4844N/A}