1 /* 2 * Copyright (c) 2013, 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 * @test 1.4 08/08/05 25 * @key headful 26 * @bug 6276188 27 * @library ../../../../regtesthelpers 28 * @build Util 29 * @author Romain Guy 30 * @summary Tests PRESSED and MOUSE_OVER and FOCUSED state for buttons with Synth. 31 * @run main bug6276188 32 */ 33 import java.awt.*; 34 import java.awt.image.*; 35 import java.awt.event.*; 36 37 import javax.swing.*; 38 import javax.swing.plaf.synth.*; 39 import sun.awt.SunToolkit; 40 41 public class bug6276188 extends JFrame { 42 43 private static JButton button; 44 private static Point p; 45 private static final SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); 46 47 public static void main(String[] args) throws Throwable { 48 SynthLookAndFeel lookAndFeel = new SynthLookAndFeel(); 49 lookAndFeel.load(bug6276188.class.getResourceAsStream("bug6276188.xml"), bug6276188.class); 50 51 UIManager.setLookAndFeel(lookAndFeel); 52 SwingUtilities.invokeAndWait(new Runnable() { 53 public void run() { 54 JFrame testFrame = new JFrame(); 55 testFrame.setLayout(new BorderLayout()); 56 testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 57 testFrame.add(BorderLayout.CENTER, button = new JButton()); 58 59 testFrame.setSize(new Dimension(320, 200)); 60 testFrame.setVisible(true); 61 } 62 }); 63 64 p = Util.getCenterPoint(button); 65 66 Robot robot = new Robot(); 67 robot.setAutoDelay(50); 68 69 robot.mouseMove(p.x , p.y); 70 robot.mousePress(InputEvent.BUTTON1_MASK); 71 toolkit.realSync(); 72 robot.delay(1000); 73 74 Color color = robot.getPixelColor(p.x, p.y); 75 robot.mouseRelease(InputEvent.BUTTON1_MASK); 76 boolean red = color.getRed() > 0 && color.getGreen() == 0 && color.getBlue() == 0; 77 if (!red) { 78 System.err.println("Red: " + color.getRed() + "; Green: " + color.getGreen() + "; Blue: " + color.getBlue()); 79 throw new RuntimeException("Synth ButtonUI does not handle PRESSED & MOUSE_OVER state"); 80 } 81 } 82 }