1 19 package org.openide.util; 20 21 import java.awt.Color ; 22 import java.awt.Image ; 23 import java.awt.Transparency ; 24 import java.awt.image.BufferedImage ; 25 import junit.framework.*; 26 import java.lang.ref.*; 27 import java.util.*; 28 29 33 public class IconManagerTest extends TestCase { 34 35 public IconManagerTest (String testName) { 36 super (testName); 37 } 38 39 public void testMergeImages() throws Exception { 40 BufferedImage img1 = new BufferedImage (16, 16, BufferedImage.TYPE_INT_ARGB); 42 java.awt.Graphics2D g = img1.createGraphics(); 44 Color c = new Color (255, 255, 255, 128); 45 g.setColor(c); 46 g.fillRect(0, 0, 16, 16); 47 g.dispose(); 48 49 BufferedImage img2 = new BufferedImage (1, 1, BufferedImage.TYPE_INT_ARGB); 50 g = img2.createGraphics(); 52 c = new Color (255, 255, 255); 53 g.setColor(c); 54 g.fillRect(0, 0, 2, 2); 55 g.dispose(); 56 57 Image mergedImg = IconManager.mergeImages(img1, img2, 0, 0); 58 if (!(mergedImg instanceof BufferedImage )) { 59 fail("It is assumed that mergeImages returns BufferedImage. Need to update test"); 60 } 61 62 BufferedImage merged = (BufferedImage )mergedImg; 63 assertNotSame("transparency has to be kept for pixel <1,1>", merged.getRGB(10, 10), merged.getRGB(0, 0)); 65 } 66 67 public void testMergeBitmaskImages() throws Exception { 68 BufferedImage img1 = new BufferedImage (16, 16, BufferedImage.TYPE_INT_RGB); 70 java.awt.Graphics2D g = img1.createGraphics(); 72 g.setColor(Color.BLUE); 73 g.fillRect(0, 0, 16, 16); 74 g.dispose(); 75 76 BufferedImage img2 = new BufferedImage (2, 2, BufferedImage.TYPE_INT_RGB); 77 g = img2.createGraphics(); 79 g.setColor(Color.RED); 80 g.fillRect(0, 0, 2, 2); 81 g.dispose(); 82 83 Image mergedImg = IconManager.mergeImages(img1, img2, 0, 0); 84 if (!(mergedImg instanceof BufferedImage )) { 85 fail("It is assumed that mergeImages returns BufferedImage. Need to update test"); 86 } 87 88 BufferedImage merged = (BufferedImage )mergedImg; 89 assertEquals("Should create bitmask image", Transparency.BITMASK, merged.getTransparency()); 90 assertEquals(Color.RED, new Color (merged.getRGB(1, 1))); 91 assertEquals(Color.BLUE, new Color (merged.getRGB(10, 10))); 92 } 93 94 } 95 | Popular Tags |