Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/List/SetBackgroundTest/SetBackgroundTest.java
38828 views
/*1* Copyright (c) 2007, 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@summary List does not honor user specified background, foreground colors on XToolkit27@author Dmitry Cherepanov area=awt.list28@library ../../../../lib/testlibrary29@build ExtendedRobot30@run main SetBackgroundTest31*/3233/**34* SetBackgroundTest.java35*36* summary:37*/3839import java.awt.*;40import java.awt.event.*;4142public class SetBackgroundTest43{4445private static boolean isXAWT = (Toolkit.getDefaultToolkit().getClass().getName().equals("sun.awt.X11.XToolkit"));46private static ExtendedRobot robot = null;47private static Frame frame = null;4849private static final Color color = Color.red;50private static Color roughColor = null;5152private static void initRoughColor(){5354Canvas canvas = new Canvas();55canvas.setBackground(color);56frame.add(canvas, BorderLayout.CENTER);57frame.validate();58robot.waitForIdle(500);5960Point loc = canvas.getLocationOnScreen();61Color robotColor = robot.getPixelColor(loc.x + canvas.getWidth()/2, loc.y + canvas.getHeight()/2);62roughColor = robotColor;6364System.out.println(" --- init rough color ... ");65System.out.println(" color = "+color);66System.out.println(" roughColor = "+roughColor);6768frame.remove(canvas);69robot.waitForIdle(500);70}717273private static void test() {74if (!isXAWT){75System.out.println(" this is XAWT-only test. ");76return;77}7879frame = new Frame();80frame.setBounds(400,400,200,200);81frame.setLayout(new BorderLayout());82frame.setVisible(true);838485try{86robot = new ExtendedRobot();87}catch(AWTException e){88throw new RuntimeException(e.getMessage());89}9091robot.waitForIdle(500);9293initRoughColor();94Component[] components = new Component[] {95new Button(), new Checkbox(), new Label(), new List(3, false),96new TextArea(), new TextField(), new Choice()97};9899for (Component component : components) {100testComponent(new Panel(), component, color);101}102103robot.waitForIdle(1500);104frame.dispose();105}106107private static void testComponent(Container container, Component component, Color color){108109component.setBackground(color);110111container.setLayout(new BorderLayout());112container.add(component, BorderLayout.CENTER);113frame.add(container, BorderLayout.CENTER);114frame.add("Center", container);115frame.validate();116robot.waitForIdle(500);117118Point loc = component.getLocationOnScreen();119Color robotColor = robot.getPixelColor(loc.x + component.getWidth()/2, loc.y + component.getHeight()/2);120121System.out.println(" --- test ... ");122System.out.println(" container = "+container);123System.out.println(" component = "+component);124System.out.println(" color = "+color);125System.out.println(" roughColor = "+roughColor);126System.out.println(" robotColor = "+robotColor);127128if(robotColor.getRGB() != roughColor.getRGB()){129throw new RuntimeException(" the case failed. ");130} else {131System.out.println(" the case passed. ");132}133134container.remove(component);135frame.remove(container);136robot.waitForIdle(500);137}138public static void main( String args[] ) throws Exception139{140test();141}142}143144145146