View Javadoc

    1   // ========================================================================
    2   // $Id: Applet.java,v 1.7 2004/07/19 13:12:58 hlavac Exp $
    3   // Copyright 1996-2004 Mort Bay Consulting Pty. Ltd.
    4   // ------------------------------------------------------------------------
    5   // Licensed under the Apache License, Version 2.0 (the "License");
    6   // you may not use this file except in compliance with the License.
    7   // You may obtain a copy of the License at
    8   // http://www.apache.org/licenses/LICENSE-2.0
    9   // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  // ========================================================================
    15
    16  package org.mortbay.html;
    17
    18  import java.io.IOException;
    19  import java.io.Writer;
    20  import java.util.Enumeration;
    21  import java.util.Hashtable;
    22
    23  /* ---------------------------------------------------------------- */
    24  /** An Applet Block.
    25   * <p> Lets you set the class name from the program, and optionally, the
    26   * size and the codebase.
    27   *
    28   * <p> This class uses any attributes set in Element.
    29   *
    30   * <p><h4>Usage</h4>
    31   * <pre>
    32   * org.mortbay.Page page = new org.mortbay.html.Page();
    33   * page.add(new org.mortbay.Applet("org.mortbay.Foo.App"));
    34   * </pre>
    35   *
    36   * @see org.mortbay.html.Block
    37   * @version $Id: Applet.java,v 1.7 2004/07/19 13:12:58 hlavac Exp $
    38   * @author Matthew Watson
    39  */
    40  public class Applet extends Block
    41  {
    42      /* ------------------------------------------------------------ */
    43      public String codeBase = null;
    44
    45      /* ------------------------------------------------------------ */
    46      private boolean debug =false;
    47      private Hashtable params = null;
    48      private Composite paramHolder = new Composite();
    49
    50      /* ------------------------------------------------------------ */
    51      /** Create an Applet Element.
    52       * @param className The name of the class to give for the applet
    53       */
    54      public Applet(String className)
    55      {
    56          super("applet");
    57          add(paramHolder);
    58          attribute("code",className);
    59      }
    60
    61      /* ------------------------------------------------------------ */
    62      /** Set the dimensions of the Applet.
    63       */
    64      public Applet setDimensions(int height, int width)
    65      {
    66          width(width);
    67          height(height);
    68          return this;
    69      }
    70
    71      /* ------------------------------------------------------------ */
    72      /** Set whether debugging is on in the Applet.
    73       * <p> This controls whether the org.mortbay.util.Code debug messages
    74       * will be printed to the java console.
    75       * <p> Defaults to whether debug is turned on in the generating app */
    76      public Applet setDebug(boolean debug){
    77          this.debug = debug;
    78          return this;
    79      }
    80
    81      /* ------------------------------------------------------------ */
    82      /**
    83       * Set an alternate display for non-java browsers.
    84       * @param alt The alternate element to display
    85       * @deprecated use add
    86       */
    87      public Applet setAlternate(Element alt)
    88      {
    89          add(alt);
    90          return this;
    91      }
    92
    93      /* ------------------------------------------------------------ */
    94      /** Set an alternate display for non-java browsers.
    95       * @param alt The alternate element to display
    96       * @deprecated use add
    97       */
    98      public Applet setAlternate(String alt)
    99      {
    100         add(alt);
    101         return this;
    102     }
    103
    104     /* ------------------------------------------------------------ */
    105     /** Set the codebase */
    106     public Applet codeBase(String cb)
    107     {
    108         codeBase = cb;
    109         return this;
    110     }
    111
    112     /* ------------------------------------------------------------ */
    113     public Applet setParam(String name, String value)
    114     {
    115         if (params == null)
    116             params = new Hashtable(10);
    117         params.put(name, value);
    118         return this;
    119     }
    120
    121     /* ------------------------------------------------------------ */
    122     /** Write out the HTML */
    123     public void write(Writer out)
    124          throws IOException
    125     {
    126         if (codeBase != null)
    127             attribute("codebase",codeBase);
    128
    129         if (debug)
    130             paramHolder.add("<param name=\"debug\" value=\"yes\">");
    131         if (params != null)
    132             for (Enumeration enm = params.keys(); enm.hasMoreElements();)
    133             {
    134                 String key = enm.nextElement().toString();
    135                 paramHolder.add("<param name=\"" + key + "\" value=\"" +
    136                                 params.get(key).toString() + "\">");
    137             }
    138         super.write(out);
    139     }
    140 };
    141
    142
    143
    144
    145