SetBackgroundTest.java revision 11127:418d2e751094
138776Snsouch/* 293023Snsouch * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. 338776Snsouch * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 438776Snsouch * 538776Snsouch * This code is free software; you can redistribute it and/or modify it 638776Snsouch * under the terms of the GNU General Public License version 2 only, as 738776Snsouch * published by the Free Software Foundation. 838776Snsouch * 938776Snsouch * This code is distributed in the hope that it will be useful, but WITHOUT 1038776Snsouch * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1138776Snsouch * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1238776Snsouch * version 2 for more details (a copy is included in the LICENSE file that 1338776Snsouch * accompanied this code). 1438776Snsouch * 1538776Snsouch * You should have received a copy of the GNU General Public License version 1638776Snsouch * 2 along with this work; if not, write to the Free Software Foundation, 1738776Snsouch * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1838776Snsouch * 1938776Snsouch * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2038776Snsouch * or visit www.oracle.com if you need additional information or have any 2138776Snsouch * questions. 2238776Snsouch */ 2338776Snsouch 2438776Snsouch/* 2538776Snsouch @test 2638776Snsouch @bug 6246467 2738776Snsouch @summary List does not honor user specified background, foreground colors on XToolkit 28119419Sobrien @author Dmitry Cherepanov area=awt.list 29119419Sobrien @library ../../../../lib/testlibrary 30119419Sobrien @build ExtendedRobot 3138776Snsouch @run main SetBackgroundTest 3238776Snsouch*/ 33162234Sjhb 3438776Snsouch/** 35162234Sjhb * SetBackgroundTest.java 3638776Snsouch * 3738776Snsouch * summary: 3838776Snsouch */ 3938776Snsouch 4038776Snsouchimport java.awt.*; 4138776Snsouchimport java.awt.event.*; 4238776Snsouch 4338776Snsouchpublic class SetBackgroundTest 4438776Snsouch{ 4538776Snsouch 4638776Snsouch private static boolean isXAWT = (Toolkit.getDefaultToolkit().getClass().getName().equals("sun.awt.X11.XToolkit")); 4738776Snsouch private static ExtendedRobot robot = null; 48162234Sjhb private static Frame frame = null; 4938776Snsouch 5038776Snsouch private static final Color color = Color.red; 51162234Sjhb private static Color roughColor = null; 5238776Snsouch 5338776Snsouch private static void initRoughColor(){ 54162234Sjhb 5538776Snsouch Canvas canvas = new Canvas(); 5638776Snsouch canvas.setBackground(color); 5738776Snsouch frame.add(canvas, BorderLayout.CENTER); 5843998Snsouch frame.validate(); 5943998Snsouch robot.waitForIdle(500); 6043998Snsouch 6143998Snsouch Point loc = canvas.getLocationOnScreen(); 6243998Snsouch Color robotColor = robot.getPixelColor(loc.x + canvas.getWidth()/2, loc.y + canvas.getHeight()/2); 6343998Snsouch roughColor = robotColor; 6443998Snsouch 6543998Snsouch System.out.println(" --- init rough color ... "); 6643998Snsouch System.out.println(" color = "+color); 6743998Snsouch System.out.println(" roughColor = "+roughColor); 6843998Snsouch 6943998Snsouch frame.remove(canvas); 70162234Sjhb robot.waitForIdle(500); 7143998Snsouch } 72162234Sjhb 7343998Snsouch 74162234Sjhb private static void test() { 7543998Snsouch if (!isXAWT){ 76162234Sjhb System.out.println(" this is XAWT-only test. "); 7743998Snsouch return; 78162234Sjhb } 79162234Sjhb 80162234Sjhb frame = new Frame(); 8143998Snsouch frame.setBounds(400,400,200,200); 8243998Snsouch frame.setLayout(new BorderLayout()); 8343998Snsouch frame.setVisible(true); 8443998Snsouch 8543998Snsouch 8640785Snsouch try{ 8740785Snsouch robot = new ExtendedRobot(); 8840785Snsouch }catch(AWTException e){ 8940785Snsouch throw new RuntimeException(e.getMessage()); 9040785Snsouch } 9140785Snsouch 92162234Sjhb robot.waitForIdle(500); 93162234Sjhb 9440785Snsouch initRoughColor(); 9540785Snsouch Component[] components = new Component[] { 96162234Sjhb new Button(), new Checkbox(), new Label(), new List(3, false), 97162234Sjhb new TextArea(), new TextField(), new Choice() 9840785Snsouch }; 9940785Snsouch 10040785Snsouch for (Component component : components) { 101162234Sjhb testComponent(new Panel(), component, color); 10240785Snsouch } 10340785Snsouch 10440785Snsouch robot.waitForIdle(1500); 10540785Snsouch frame.dispose(); 10640785Snsouch } 10740785Snsouch 10838776Snsouch private static void testComponent(Container container, Component component, Color color){ 10938776Snsouch 11038776Snsouch component.setBackground(color); 11138776Snsouch 11238776Snsouch container.setLayout(new BorderLayout()); 11338776Snsouch container.add(component, BorderLayout.CENTER); 11438776Snsouch frame.add(container, BorderLayout.CENTER); 11538776Snsouch frame.add("Center", container); 11638776Snsouch frame.validate(); 11738776Snsouch robot.waitForIdle(500); 118162234Sjhb 119162234Sjhb Point loc = component.getLocationOnScreen(); 120162234Sjhb Color robotColor = robot.getPixelColor(loc.x + component.getWidth()/2, loc.y + component.getHeight()/2); 12138776Snsouch 12240785Snsouch System.out.println(" --- test ... "); 123162234Sjhb System.out.println(" container = "+container); 124162234Sjhb System.out.println(" component = "+component); 12552776Snsouch System.out.println(" color = "+color); 126162234Sjhb System.out.println(" roughColor = "+roughColor); 127162234Sjhb System.out.println(" robotColor = "+robotColor); 128162234Sjhb 129162234Sjhb if(robotColor.getRGB() != roughColor.getRGB()){ 13052776Snsouch throw new RuntimeException(" the case failed. "); 13152776Snsouch } else { 13252776Snsouch System.out.println(" the case passed. "); 13340785Snsouch } 134162234Sjhb 135162234Sjhb container.remove(component); 13640785Snsouch frame.remove(container); 137162234Sjhb robot.waitForIdle(500); 13838776Snsouch } 139162234Sjhb public static void main( String args[] ) throws Exception 14038776Snsouch { 14143975Snsouch test(); 14243975Snsouch } 143162234Sjhb} 144162234Sjhb 145162234Sjhb