001: // ========================================================================
002: // $Id: Applet.java,v 1.7 2004/07/19 13:12:58 hlavac Exp $
003: // Copyright 1996-2004 Mort Bay Consulting Pty. Ltd.
004: // ------------------------------------------------------------------------
005: // Licensed under the Apache License, Version 2.0 (the "License");
006: // you may not use this file except in compliance with the License.
007: // You may obtain a copy of the License at
008: // http://www.apache.org/licenses/LICENSE-2.0
009: // Unless required by applicable law or agreed to in writing, software
010: // distributed under the License is distributed on an "AS IS" BASIS,
011: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: // See the License for the specific language governing permissions and
013: // limitations under the License.
014: // ========================================================================
015:
016: package org.mortbay.html;
017:
018: import java.io.IOException;
019: import java.io.Writer;
020: import java.util.Enumeration;
021: import java.util.Hashtable;
022:
023: /* ---------------------------------------------------------------- */
024: /** An Applet Block.
025: * <p> Lets you set the class name from the program, and optionally, the
026: * size and the codebase.
027: *
028: * <p> This class uses any attributes set in Element.
029: *
030: * <p><h4>Usage</h4>
031: * <pre>
032: * org.mortbay.Page page = new org.mortbay.html.Page();
033: * page.add(new org.mortbay.Applet("org.mortbay.Foo.App"));
034: * </pre>
035: *
036: * @see org.mortbay.html.Block
037: * @version $Id: Applet.java,v 1.7 2004/07/19 13:12:58 hlavac Exp $
038: * @author Matthew Watson
039: */
040: public class Applet extends Block {
041: /* ------------------------------------------------------------ */
042: public String codeBase = null;
043:
044: /* ------------------------------------------------------------ */
045: private boolean debug = false;
046: private Hashtable params = null;
047: private Composite paramHolder = new Composite();
048:
049: /* ------------------------------------------------------------ */
050: /** Create an Applet Element.
051: * @param className The name of the class to give for the applet
052: */
053: public Applet(String className) {
054: super ("applet");
055: add(paramHolder);
056: attribute("code", className);
057: }
058:
059: /* ------------------------------------------------------------ */
060: /** Set the dimensions of the Applet.
061: */
062: public Applet setDimensions(int height, int width) {
063: width(width);
064: height(height);
065: return this ;
066: }
067:
068: /* ------------------------------------------------------------ */
069: /** Set whether debugging is on in the Applet.
070: * <p> This controls whether the org.mortbay.util.Code debug messages
071: * will be printed to the java console.
072: * <p> Defaults to whether debug is turned on in the generating app */
073: public Applet setDebug(boolean debug) {
074: this .debug = debug;
075: return this ;
076: }
077:
078: /* ------------------------------------------------------------ */
079: /**
080: * Set an alternate display for non-java browsers.
081: * @param alt The alternate element to display
082: * @deprecated use add
083: */
084: public Applet setAlternate(Element alt) {
085: add(alt);
086: return this ;
087: }
088:
089: /* ------------------------------------------------------------ */
090: /** Set an alternate display for non-java browsers.
091: * @param alt The alternate element to display
092: * @deprecated use add
093: */
094: public Applet setAlternate(String alt) {
095: add(alt);
096: return this ;
097: }
098:
099: /* ------------------------------------------------------------ */
100: /** Set the codebase */
101: public Applet codeBase(String cb) {
102: codeBase = cb;
103: return this ;
104: }
105:
106: /* ------------------------------------------------------------ */
107: public Applet setParam(String name, String value) {
108: if (params == null)
109: params = new Hashtable(10);
110: params.put(name, value);
111: return this ;
112: }
113:
114: /* ------------------------------------------------------------ */
115: /** Write out the HTML */
116: public void write(Writer out) throws IOException {
117: if (codeBase != null)
118: attribute("codebase", codeBase);
119:
120: if (debug)
121: paramHolder.add("<param name=\"debug\" value=\"yes\">");
122: if (params != null)
123: for (Enumeration enm = params.keys(); enm.hasMoreElements();) {
124: String key = enm.nextElement().toString();
125: paramHolder.add("<param name=\"" + key + "\" value=\""
126: + params.get(key).toString() + "\">");
127: }
128: super.write(out);
129: }
130: };
|