1 18 19 package org.apache.jmeter.gui; 20 21 import java.util.HashMap ; 22 import java.util.Map ; 23 24 import javax.swing.ImageIcon ; 25 import javax.swing.JComponent ; 26 27 import org.apache.jmeter.testbeans.gui.TestBeanGUI; 28 29 30 36 public final class GUIFactory 37 { 38 39 private static final Map GUI_MAP = new HashMap (); 40 41 42 private static final Map ICON_MAP = new HashMap (); 43 44 47 private GUIFactory () 48 { 49 } 50 51 59 public static ImageIcon getIcon(Class elementClass) 60 { 61 String key = elementClass.getName(); 62 ImageIcon icon = (ImageIcon ) ICON_MAP.get(key); 63 64 if (icon != null) 65 { 66 return icon; 67 } 68 69 if (elementClass.getSuperclass() != null) 70 { 71 return getIcon(elementClass.getSuperclass()); 72 } 73 74 return null; 75 } 76 77 78 87 public static JComponent getGUI(Class elementClass) 88 { 89 String key = elementClass.getName(); 91 JComponent gui = (JComponent ) GUI_MAP.get(key); 92 93 if (gui != null) 94 { 95 return gui; 96 } 97 98 if (elementClass.getSuperclass() != null) 99 { 100 return getGUI(elementClass.getSuperclass()); 101 } 102 103 return null; 104 } 105 106 107 116 public static void registerIcon(String key, ImageIcon icon) 117 { 118 ICON_MAP.put(key, icon); 119 } 120 121 122 137 public static void registerGUI(String key, Class guiClass, Class testClass) 138 throws InstantiationException , IllegalAccessException 139 { 140 JMeterGUIComponent gui; 142 143 if (guiClass == TestBeanGUI.class) 144 { 145 gui= new TestBeanGUI(testClass); 146 } 147 else 148 { 149 gui = (JMeterGUIComponent) guiClass.newInstance(); 150 } 151 GUI_MAP.put(key, gui); 152 } 153 } 154 | Popular Tags |