1 /* 2 * @test 3 * @bug 4614845 4 * @summary Test drawImage(bgcolor) gets correct RGB from SystemColor objects. 5 * @run main SystemBgColorTest 6 */ 7 8 import java.awt.*; 9 import java.awt.image.*; 10 11 public class SystemBgColorTest { 12 public static final int TESTW = 10; 13 public static final int TESTH = 10; 14 15 static SystemColor systemColorObjects [] = { 16 SystemColor.desktop, 17 SystemColor.activeCaption, 18 SystemColor.activeCaptionText, 19 SystemColor.activeCaptionBorder, 20 SystemColor.inactiveCaption, 21 SystemColor.inactiveCaptionText, 22 SystemColor.inactiveCaptionBorder, 23 SystemColor.window, 24 SystemColor.windowBorder, 25 SystemColor.windowText, 26 SystemColor.menu, 27 SystemColor.menuText, 28 SystemColor.text, 29 SystemColor.textText, 30 SystemColor.textHighlight, 31 SystemColor.textHighlightText, 32 SystemColor.textInactiveText, 33 SystemColor.control, 34 SystemColor.controlText, 35 SystemColor.controlHighlight, 36 SystemColor.controlLtHighlight, 37 SystemColor.controlShadow, 38 SystemColor.controlDkShadow, 39 SystemColor.scrollbar, 40 SystemColor.info, 41 SystemColor.infoText 42 }; 43 44 static boolean counterrors; 45 static int errcount; 46 47 public static void error(String problem) { 48 if (counterrors) { 49 errcount++; 50 } else { 51 throw new RuntimeException(problem); 52 } 53 } 54 55 public static void main(String argv[]) { 56 counterrors = (argv.length > 0); 57 test(BufferedImage.TYPE_INT_ARGB); 58 test(BufferedImage.TYPE_INT_RGB); 59 if (errcount > 0) { 60 throw new RuntimeException(errcount+" errors"); 61 } 62 } 63 64 static int cmap[] = { 65 0x00000000, 66 0xffffffff, 67 }; 68 69 public static void test(int dsttype) { 70 BufferedImage src = 71 new BufferedImage(TESTW, TESTH, BufferedImage.TYPE_INT_ARGB); 72 test(src, dsttype); 73 IndexColorModel icm = new IndexColorModel(8, 2, cmap, 0, true, 0, 74 DataBuffer.TYPE_BYTE); 75 src = new BufferedImage(TESTW, TESTH, 76 BufferedImage.TYPE_BYTE_INDEXED, icm); 77 test(src, dsttype); 78 } 79 80 public static void test(Image src, int dsttype) { 81 BufferedImage dst = 82 new BufferedImage(TESTW, TESTH, dsttype); 83 for (int i = 0; i < systemColorObjects.length; i++) { 84 test(src, dst, systemColorObjects[i]); 85 } 86 } 87 88 public static void test(Image src, BufferedImage dst, Color bg) { 89 Graphics g = dst.getGraphics(); 90 g.setColor(Color.white); 91 g.fillRect(0, 0, TESTW, TESTH); 92 g.drawImage(src, 0, 0, bg, null); 93 if (dst.getRGB(0, 0) != bg.getRGB()) { 94 error("bad bg pixel for: "+bg); 95 } 96 } 97 }