KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdnc > runner > Applet


1 /*
2  * $Id: Applet.java,v 1.1.1.1 2004/06/16 01:43:41 davidson1 Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.jdnc.runner;
9
10 import java.awt.Component JavaDoc;
11 import java.awt.Container JavaDoc;
12 import java.awt.BorderLayout JavaDoc;
13 import java.awt.HeadlessException JavaDoc;
14
15 import java.net.URL JavaDoc;
16
17 import java.util.logging.Level JavaDoc;
18
19 import javax.swing.JApplet JavaDoc;
20 import javax.swing.JComponent JavaDoc;
21 import javax.swing.JFrame JavaDoc;
22 import javax.swing.JMenuBar JavaDoc;
23 import javax.swing.JOptionPane JavaDoc;
24 import javax.swing.JRootPane JavaDoc;
25 import javax.swing.UIManager JavaDoc;
26
27 import net.openmarkup.Scribe;
28
29 /**
30  * <p>
31  * Applet class which instantiates its user interface based on the
32  * XML configuration file specified in the applet tag's &quot;config&quot;
33  * parameter.</p>
34  * <p>
35  * The configuration file must adhere to the JDNC schema:<br>
36  * TBD
37  * </p>
38  * @author Amy Fowler
39  * @author Ramesh Gupta
40  */

41 public class Applet extends JApplet JavaDoc {
42     public static final String JavaDoc CONFIG_PARAM = "config";
43     public static final String JavaDoc LEVEL_PARAM = "level";
44     private static final String JavaDoc[][] 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 JavaDoc {
52         try {
53           UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
54         }
55         catch(Exception JavaDoc e) {
56           e.printStackTrace();
57         }
58     }
59
60     public void init() {
61     super.init();
62
63     // Set the logging level
64
Application.setLogLevel(getParameter(LEVEL_PARAM));
65
66         String JavaDoc 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 JavaDoc ui = null;
74     try {
75         ui = Application.realizeObject(new URL JavaDoc(getDocumentBase(), configuration));
76     } catch (Exception JavaDoc 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         //REMIND(aim): this should probably be codebase???
90
//need to be careful not to clobber the setting from other applets
91
//who share this app object
92
app.setBaseURL(getDocumentBase());
93
94     if (ui instanceof JRootPane JavaDoc) {
95         setRootPane((JRootPane JavaDoc)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 JavaDoc[][] getParameterInfo() {
106     return paramInfo;
107     }
108 }
109
Popular Tags