1 19 20 package org.openide.nodes; 21 22 import java.beans.BeanInfo ; 23 import org.openide.util.Utilities; 24 import java.awt.Image ; 25 import java.beans.PropertyChangeEvent ; 26 import junit.framework.TestCase; 27 28 33 public class AbstractNodeTest extends TestCase { 34 35 public AbstractNodeTest(String testName) { 36 super(testName); 37 } 38 39 42 public void testSetIconBaseWithExtension() { 43 AbstractNode an = new AbstractNode(Children.LEAF); 44 Listener lst = new Listener(); 45 an.addNodeListener(lst); 46 47 Image def = getImage("org/openide/nodes/defaultNode.gif"); 49 Image def32 = getImage("org/openide/nodes/defaultNode32.gif"); 50 51 Image aPng = getImage("org/openide/nodes/data/a.png"); 53 Image aPngOpen = getImage("org/openide/nodes/data/aOpen.png"); 54 Image a32Png = getImage("org/openide/nodes/data/a32.png"); 55 56 Image aGif = getImage("org/openide/nodes/data/a.gif"); 58 Image a32Gif = getImage("org/openide/nodes/data/a32.gif"); 59 Image a32GifOpen = getImage("org/openide/nodes/data/aOpen32.gif"); 60 61 Image b = getImage("org/openide/nodes/data/b"); 63 Image b32 = getImage("org/openide/nodes/data/b32"); 64 65 Image b2 = getImage("org/openide/nodes/data/res.t2/b"); 67 68 checkIcons(an, def, def32, def, def32); 70 71 an.setIconBase("org/openide/nodes/data/a"); 73 lst.assertEvents(2); checkIcons(an, aGif, a32Gif, aGif, a32GifOpen); 75 76 an.setIconBaseWithExtension("org/openide/nodes/data/a.png"); 78 lst.assertEvents(2); checkIcons(an, aPng, a32Png, aPngOpen, aPngOpen); 80 81 an.setIconBaseWithExtension("org/openide/nodes/data/a.gif"); 83 lst.assertEvents(2); checkIcons(an, aGif, a32Gif, aGif, a32GifOpen); 85 86 an.setIconBaseWithExtension("org/openide/nodes/data/b"); 88 lst.assertEvents(2); checkIcons(an, b, b32, b, b32); 90 91 an.setIconBaseWithExtension("org/openide/nodes/data/res.t2/b"); 93 lst.assertEvents(2); checkIcons(an, b2, b2, b2, b2); 95 96 } 97 98 99 private static Image getImage(String path) { 100 Image ret = Utilities.loadImage(path, true); 101 assertNotNull("Icon loaded", ret); 102 return ret; 103 } 104 105 private static void checkIcons(Node n, Image base, Image base32, Image open, Image open32) { 106 assertSame("Base icon", base, n.getIcon(BeanInfo.ICON_COLOR_16x16)); 107 assertSame("Base icon (mono)", base, n.getIcon(BeanInfo.ICON_MONO_16x16)); 108 assertSame("Base icon32", base32, n.getIcon(BeanInfo.ICON_COLOR_32x32)); 109 assertSame("Base icon32 (mono)", base32, n.getIcon(BeanInfo.ICON_MONO_32x32)); 110 assertSame("Open icon", open, n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16)); 111 assertSame("Open icon (mono)", open, n.getOpenedIcon(BeanInfo.ICON_MONO_16x16)); 112 assertSame("Open icon32", open32, n.getOpenedIcon(BeanInfo.ICON_COLOR_32x32)); 113 assertSame("Open icon32 (mono)", open32, n.getOpenedIcon(BeanInfo.ICON_MONO_32x32)); 114 115 } 116 117 static class Listener extends NodeAdapter { 118 int cnt; 119 120 public void propertyChange(PropertyChangeEvent propertyChangeEvent) { 121 cnt++; 122 } 123 124 public void assertEvents(int count) { 125 assertEquals("Number of events", count, cnt); 126 cnt = 0; 127 } 128 } 129 } 130 | Popular Tags |