1 7 8 package org.jdesktop.jdnc.runner; 9 10 import java.awt.Component ; 11 import java.awt.Container ; 12 import java.awt.BorderLayout ; 13 import java.awt.HeadlessException ; 14 15 import java.net.URL ; 16 17 import java.util.logging.Level ; 18 19 import javax.swing.JApplet ; 20 import javax.swing.JComponent ; 21 import javax.swing.JFrame ; 22 import javax.swing.JMenuBar ; 23 import javax.swing.JOptionPane ; 24 import javax.swing.JRootPane ; 25 import javax.swing.UIManager ; 26 27 import net.openmarkup.Scribe; 28 29 41 public class Applet extends JApplet { 42 public static final String CONFIG_PARAM = "config"; 43 public static final String LEVEL_PARAM = "level"; 44 private static final String [][] paramInfo = { 45 { CONFIG_PARAM, "String", 46 "XML configuration file URL used to instantiate user interface" }, 47 { LEVEL_PARAM, "String", 48 "The logging level to use" } 49 }; 50 51 public Applet() throws HeadlessException { 52 try { 53 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 54 } 55 catch(Exception e) { 56 e.printStackTrace(); 57 } 58 } 59 60 public void init() { 61 super.init(); 62 63 Application.setLogLevel(getParameter(LEVEL_PARAM)); 65 66 String configuration = getParameter(CONFIG_PARAM); 67 if (configuration == null) { 68 Scribe.getLogger().severe("applet parameter \"" + CONFIG_PARAM + 69 "\" must be specified"); 70 return; 71 } 72 73 JComponent ui = null; 74 try { 75 ui = Application.realizeObject(new URL (getDocumentBase(), configuration)); 76 } catch (Exception ex) { 77 Scribe.getLogger().log(Level.SEVERE, 78 "Exception realizing: " + configuration, ex); 79 return; 80 } 81 82 83 org.jdesktop.swing.Application app = Application.getApplication(ui); 84 if (app == null) { 85 app = org.jdesktop.swing.Application.getInstance(this); 86 } 87 app.registerApplet(this); 88 89 app.setBaseURL(getDocumentBase()); 93 94 if (ui instanceof JRootPane ) { 95 setRootPane((JRootPane )ui); 96 } else { 97 getContentPane().add(BorderLayout.CENTER, ui); 98 } 99 } 100 101 public void destroy() { 102 org.jdesktop.swing.Application.getApp(this).unregisterApplet(this); 103 } 104 105 public String [][] getParameterInfo() { 106 return paramInfo; 107 } 108 } 109 | Popular Tags |