1 /* 2 * Copyright (c) 2007, 2020, 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 /* 25 @test 26 @bug 6246467 27 @key headful 28 @requires os.family == "linux" 29 @summary List does not honor user specified background, foreground colors on XToolkit 30 @author Dmitry Cherepanov area=awt.list 31 @library /lib/client 32 @build ExtendedRobot 33 @run main SetBackgroundTest 34 */ 35 36 /** 37 * SetBackgroundTest.java 38 * 39 * summary: 40 */ 41 42 import java.awt.*; 43 import java.awt.event.*; 44 45 public class SetBackgroundTest 46 { 47 48 private static boolean isXAWT = (Toolkit.getDefaultToolkit().getClass().getName().equals("sun.awt.X11.XToolkit")); 49 private static ExtendedRobot robot = null; 50 private static Frame frame = null; 51 52 private static final Color color = Color.red; 53 private static Color roughColor = null; 54 55 private static void initRoughColor(){ 56 57 Canvas canvas = new Canvas(); 58 canvas.setBackground(color); 59 frame.add(canvas, BorderLayout.CENTER); 60 frame.validate(); 61 robot.waitForIdle(500); 62 63 Point loc = canvas.getLocationOnScreen(); 64 Color robotColor = robot.getPixelColor(loc.x + canvas.getWidth()/2, loc.y + canvas.getHeight()/2); 65 roughColor = robotColor; 66 67 System.out.println(" --- init rough color ... "); 68 System.out.println(" color = "+color); 69 System.out.println(" roughColor = "+roughColor); 70 71 frame.remove(canvas); 72 robot.waitForIdle(500); 73 } 74 75 76 private static void test() { 77 if (!isXAWT){ 78 System.out.println(" this is XAWT-only test. "); 79 return; 80 } 81 82 frame = new Frame(); 83 frame.setBounds(400,400,200,200); 84 frame.setLayout(new BorderLayout()); 85 frame.setVisible(true); 86 87 88 try{ 89 robot = new ExtendedRobot(); 90 }catch(AWTException e){ 91 throw new RuntimeException(e.getMessage()); 92 } 93 94 robot.waitForIdle(500); 95 96 initRoughColor(); 97 Component[] components = new Component[] { 98 new Button(), new Checkbox(), new Label(), new List(3, false), 99 new TextArea(), new TextField(), new Choice() 100 }; 101 102 for (Component component : components) { 103 testComponent(new Panel(), component, color); 104 } 105 106 robot.waitForIdle(1500); 107 frame.dispose(); 108 } 109 110 private static void testComponent(Container container, Component component, Color color){ 111 112 component.setBackground(color); 113 114 container.setLayout(new BorderLayout()); 115 container.add(component, BorderLayout.CENTER); 116 frame.add(container, BorderLayout.CENTER); 117 frame.add("Center", container); 118 frame.validate(); 119 robot.waitForIdle(500); 120 121 Point loc = component.getLocationOnScreen(); 122 Color robotColor = robot.getPixelColor(loc.x + component.getWidth()/2, loc.y + component.getHeight()/2); 123 124 System.out.println(" --- test ... "); 125 System.out.println(" container = "+container); 126 System.out.println(" component = "+component); 127 System.out.println(" color = "+color); 128 System.out.println(" roughColor = "+roughColor); 129 System.out.println(" robotColor = "+robotColor); 130 131 if(robotColor.getRGB() != roughColor.getRGB()){ 132 throw new RuntimeException(" the case failed. "); 133 } else { 134 System.out.println(" the case passed. "); 135 } 136 137 container.remove(component); 138 frame.remove(container); 139 robot.waitForIdle(500); 140 } 141 public static void main( String args[] ) throws Exception 142 { 143 test(); 144 } 145 } 146