View Javadoc
1 package net.mlw.fball.gui; 2 3 import java.io.IOException; 4 import java.util.Locale; 5 6 import net.mlw.fball.event.EventListenerGroup; 7 import net.mlw.fball.loader.LoaderGroup; 8 9 import org.springframework.context.NoSuchMessageException; 10 import org.springframework.context.support.ClassPathXmlApplicationContext; 11 12 /*** 13 * @author Matthew L. Wilson 14 * @version $Revision: 1.5 $ $Date: 2004/03/19 21:44:31 $ 15 */ 16 public final class AppContext 17 { 18 private static ClassPathXmlApplicationContext context; 19 private static EventListenerGroup eventListenerGroup; 20 21 /*** Inits the Application Context. 22 * 23 * todo: protect this so it can be called only once! 24 * 25 * @param configLocations 26 * @throws IOException 27 */ 28 public static boolean init(String[] configLocations) throws IOException 29 { 30 if (context == null) 31 { 32 context = new ClassPathXmlApplicationContext(configLocations); 33 eventListenerGroup = (EventListenerGroup) context.getBean("eventListenerGroup", EventListenerGroup.class); 34 return true; 35 } 36 else 37 { 38 return false; 39 } 40 } 41 42 public static Object getBean(String name) 43 { 44 if (context == null) 45 { 46 throw new RuntimeException("Not initialized."); 47 } 48 else 49 { 50 return context.getBean(name); 51 } 52 } 53 54 /*** Gets the container for all the loaders. 55 * 56 * @return 57 */ 58 public static LoaderGroup getRootLoader() 59 { 60 if (context == null) 61 { 62 throw new RuntimeException("Not initialized."); 63 } 64 else 65 { 66 return (LoaderGroup) context.getBean("loader.rootLoaderGroup"); 67 } 68 } 69 70 public static String getMessage(String code) 71 { 72 return getMessage(code, null); 73 74 } 75 public static String getMessage(String code, Object[] args) 76 { 77 if (context == null) 78 { 79 throw new RuntimeException("Not initialized."); 80 } 81 else 82 { 83 try 84 { 85 return context.getMessage(code, args, Locale.getDefault()); 86 } 87 catch (NoSuchMessageException e) 88 { 89 return "***" + code + "***"; 90 } 91 } 92 } 93 94 /*** 95 public static void setLookAndFeel(String laf) 96 { 97 try 98 { 99 UIManager.setLookAndFeel(laf); 100 SwingUtilities.updateComponentTreeUI(root); 101 root.repaint(); 102 if (root instanceof JFrame) 103 { 104 ((JFrame) root).pack(); 105 } 106 107 } 108 catch (Exception e) 109 { 110 } 111 }**/ 112 113 public static void close() 114 { 115 context.close(); 116 System.exit(0); 117 } 118 119 /*** 120 * @return Returns the eventListenerGroup. 121 */ 122 public static EventListenerGroup getEventListenerGroup() 123 { 124 return eventListenerGroup; 125 } 126 127 }

This page was automatically generated by Maven