Path: blob/master/test/jdk/java/awt/List/SetBackgroundTest/SetBackgroundTest.java
41155 views
/*1* Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24@test25@bug 624646726@key headful27@requires os.family == "linux"28@summary List does not honor user specified background, foreground colors on XToolkit29@author Dmitry Cherepanov area=awt.list30@library /lib/client31@build ExtendedRobot32@run main SetBackgroundTest33*/3435/**36* SetBackgroundTest.java37*38* summary:39*/4041import java.awt.*;42import java.awt.event.*;4344public class SetBackgroundTest45{4647private static boolean isXAWT = (Toolkit.getDefaultToolkit().getClass().getName().equals("sun.awt.X11.XToolkit"));48private static ExtendedRobot robot = null;49private static Frame frame = null;5051private static final Color color = Color.red;52private static Color roughColor = null;5354private static void initRoughColor(){5556Canvas canvas = new Canvas();57canvas.setBackground(color);58frame.add(canvas, BorderLayout.CENTER);59frame.validate();60robot.waitForIdle(500);6162Point loc = canvas.getLocationOnScreen();63Color robotColor = robot.getPixelColor(loc.x + canvas.getWidth()/2, loc.y + canvas.getHeight()/2);64roughColor = robotColor;6566System.out.println(" --- init rough color ... ");67System.out.println(" color = "+color);68System.out.println(" roughColor = "+roughColor);6970frame.remove(canvas);71robot.waitForIdle(500);72}737475private static void test() {76if (!isXAWT){77System.out.println(" this is XAWT-only test. ");78return;79}8081frame = new Frame();82frame.setBounds(400,400,200,200);83frame.setLayout(new BorderLayout());84frame.setVisible(true);858687try{88robot = new ExtendedRobot();89}catch(AWTException e){90throw new RuntimeException(e.getMessage());91}9293robot.waitForIdle(500);9495initRoughColor();96Component[] components = new Component[] {97new Button(), new Checkbox(), new Label(), new List(3, false),98new TextArea(), new TextField(), new Choice()99};100101for (Component component : components) {102testComponent(new Panel(), component, color);103}104105robot.waitForIdle(1500);106frame.dispose();107}108109private static void testComponent(Container container, Component component, Color color){110111component.setBackground(color);112113container.setLayout(new BorderLayout());114container.add(component, BorderLayout.CENTER);115frame.add(container, BorderLayout.CENTER);116frame.add("Center", container);117frame.validate();118robot.waitForIdle(500);119120Point loc = component.getLocationOnScreen();121Color robotColor = robot.getPixelColor(loc.x + component.getWidth()/2, loc.y + component.getHeight()/2);122123System.out.println(" --- test ... ");124System.out.println(" container = "+container);125System.out.println(" component = "+component);126System.out.println(" color = "+color);127System.out.println(" roughColor = "+roughColor);128System.out.println(" robotColor = "+robotColor);129130if(robotColor.getRGB() != roughColor.getRGB()){131throw new RuntimeException(" the case failed. ");132} else {133System.out.println(" the case passed. ");134}135136container.remove(component);137frame.remove(container);138robot.waitForIdle(500);139}140public static void main( String args[] ) throws Exception141{142test();143}144}145146147148