Exemplo n.º 1
0
  /** Print the HTML tag. */
  public static void printTag(PrintStream out, Hashtable atts) {
    out.print("<applet");

    String v = (String) atts.get("codebase");
    if (v != null) {
      out.print(" codebase=\"" + v + "\"");
    }

    v = (String) atts.get("code");
    if (v == null) {
      v = "applet.class";
    }
    out.print(" code=\"" + v + "\"");
    v = (String) atts.get("width");
    if (v == null) {
      v = "150";
    }
    out.print(" width=" + v);

    v = (String) atts.get("height");
    if (v == null) {
      v = "100";
    }
    out.print(" height=" + v);

    v = (String) atts.get("name");
    if (v != null) {
      out.print(" name=\"" + v + "\"");
    }
    out.println(">");

    // A very slow sorting algorithm
    int len = atts.size();
    String params[] = new String[len];
    len = 0;
    for (Enumeration e = atts.keys(); e.hasMoreElements(); ) {
      String param = (String) e.nextElement();
      int i = 0;
      for (; i < len; i++) {
        if (params[i].compareTo(param) >= 0) {
          break;
        }
      }
      System.arraycopy(params, i, params, i + 1, len - i);
      params[i] = param;
      len++;
    }

    for (int i = 0; i < len; i++) {
      String param = params[i];
      if (systemParam.get(param) == null) {
        out.println("<param name=" + param + " value=\"" + atts.get(param) + "\">");
      }
    }
    out.println("</applet>");
  }
Exemplo n.º 2
0
    public TreeNode nextElement() {
      Enumeration enumer = (Enumeration) queue.firstObject();
      TreeNode node = (TreeNode) enumer.nextElement();
      Enumeration children = node.children();

      if (!enumer.hasMoreElements()) {
        queue.dequeue();
      }
      if (children.hasMoreElements()) {
        queue.enqueue(children);
      }
      return node;
    }
Exemplo n.º 3
0
    public TreeNode nextElement() {
      Enumeration enumer = stack.peek();
      TreeNode node = (TreeNode) enumer.nextElement();
      Enumeration children = node.children();

      if (!enumer.hasMoreElements()) {
        stack.pop();
      }
      if (children.hasMoreElements()) {
        stack.push(children);
      }
      return node;
    }
Exemplo n.º 4
0
  /**
   * Returns the depth of the tree rooted at this node -- the longest distance from this node to a
   * leaf. If this node has no children, returns 0. This operation is much more expensive than
   * <code>getLevel()</code> because it must effectively traverse the entire tree rooted at this
   * node.
   *
   * @see #getLevel
   * @return the depth of the tree whose root is this node
   */
  public int getDepth() {
    Object last = null;
    Enumeration enum_ = breadthFirstEnumeration();

    while (enum_.hasMoreElements()) {
      last = enum_.nextElement();
    }

    if (last == null) {
      throw new Error("nodes should be null");
    }

    return ((DefaultMutableTreeNode) last).getLevel() - getLevel();
  }
Exemplo n.º 5
0
    public TreeNode nextElement() {
      TreeNode retval;

      if (subtree.hasMoreElements()) {
        retval = subtree.nextElement();
      } else if (children.hasMoreElements()) {
        subtree = new PostorderEnumeration(children.nextElement());
        retval = subtree.nextElement();
      } else {
        retval = root;
        root = null;
      }

      return retval;
    }
Exemplo n.º 6
0
  /** Return an enumeration of all the accessible applets on this page. */
  public Enumeration getApplets() {
    AppletSecurity security = (AppletSecurity) System.getSecurityManager();
    Vector v = new Vector();
    SocketPermission panelSp = new SocketPermission(panel.getCodeBase().getHost(), "connect");

    for (Enumeration e = appletPanels.elements(); e.hasMoreElements(); ) {
      AppletPanel p = (AppletPanel) e.nextElement();
      if (p.getDocumentBase().equals(panel.getDocumentBase())) {

        SocketPermission sp = new SocketPermission(p.getCodeBase().getHost(), "connect");
        if (panelSp.implies(sp)) {
          v.addElement(p.applet);
        }
      }
    }
    return v.elements();
  }
Exemplo n.º 7
0
  /**
   * Returns the total number of leaves that are descendants of this node. If this node is a leaf,
   * returns <code>1</code>. This method is O(n) where n is the number of descendants of this node.
   *
   * @see #isNodeAncestor
   * @return the number of leaves beneath this node
   */
  public int getLeafCount() {
    int count = 0;

    TreeNode node;
    Enumeration enum_ = breadthFirstEnumeration(); // order matters not

    while (enum_.hasMoreElements()) {
      node = (TreeNode) enum_.nextElement();
      if (node.isLeaf()) {
        count++;
      }
    }

    if (count < 1) {
      throw new Error("tree has zero leaves");
    }

    return count;
  }
Exemplo n.º 8
0
  /** Get an applet by name. */
  public Applet getApplet(String name) {
    AppletSecurity security = (AppletSecurity) System.getSecurityManager();
    name = name.toLowerCase();
    SocketPermission panelSp = new SocketPermission(panel.getCodeBase().getHost(), "connect");
    for (Enumeration e = appletPanels.elements(); e.hasMoreElements(); ) {
      AppletPanel p = (AppletPanel) e.nextElement();
      String param = p.getParameter("name");
      if (param != null) {
        param = param.toLowerCase();
      }
      if (name.equals(param) && p.getDocumentBase().equals(panel.getDocumentBase())) {

        SocketPermission sp = new SocketPermission(p.getCodeBase().getHost(), "connect");

        if (panelSp.implies(sp)) {
          return p.applet;
        }
      }
    }
    return null;
  }