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