Menu.java 2.42 KB
Newer Older
Warren Levy committed
1
/* Copyright (C) 1999, 2000  Free Software Foundation
2 3 4 5 6 7 8 9 10

   This file is part of libjava.

This software is copyrighted work licensed under the terms of the
Libjava License.  Please consult the file "LIBJAVA_LICENSE" for
details.  */

package java.awt;

Bryce McKinlay committed
11 12 13
import java.util.Vector;

/* Status: Incomplete. */
14 15 16

public class Menu extends MenuItem implements MenuContainer
{
Bryce McKinlay committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30
  // Fields from the serialization spec. Decalare others "transient".
  Vector items = new Vector();
  boolean tearOff;
  boolean isHelpMenu;
  int menuSerializedDataVersion;
  
  static final MenuItem separator = new MenuItem("-");

  public Menu()
  {
    this(null, false);
  }
  
  public Menu(String label)
31
  {
Bryce McKinlay committed
32 33 34 35 36 37 38
    this(label, false);
  }
  
  public Menu(String label, boolean tearOff)
  {
    super(label);
    this.tearOff = tearOff;
39 40
  }

Bryce McKinlay committed
41 42 43 44 45 46 47 48 49
  public void addNotify()
  {
    // FIXME
  }

  public void removeNotify()
  {
    // FIXME
  }
50

Bryce McKinlay committed
51
  public boolean isTearOff()
52
  {
Bryce McKinlay committed
53
    return tearOff;
54 55
  }

Bryce McKinlay committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
  public int getItemCount()
  {
    return items.size();
  }

  /** @deprecated Use getItemCount() instead. */
  public int countItems()
  {
    return getItemCount();
  }

  public MenuItem getItem(int index)
  {
    return (MenuItem) items.elementAt(index);
  }

  public synchronized MenuItem add(MenuItem mi)
  {
    items.addElement(mi);
    if (mi.parent != null)
      {
	mi.parent.remove(mi);
      }
    mi.parent = this;
    return mi;
  }

  public void add(String label)
  {
    MenuItem mi = new MenuItem(label);
    this.add(mi);
  }

  public synchronized void insert(MenuItem menuitem, int index)
  {
    if (index < 0)
      throw new IllegalArgumentException();
    items.insertElementAt(menuitem, index);
  }

  public void insert(String label, int index)
  {
    MenuItem mi = new MenuItem(label);
    this.insert(mi, index);
  }

  public void addSeparator()
  {
    this.add(separator);
  }

  public void insertSeparator(int index)
  {
    this.insert(separator, index);    
  }

  public synchronized void remove(int index)
  {
    items.removeElementAt(index);
  }

  public synchronized void remove(MenuComponent item)
  {
    items.removeElement(item);
  }

  public synchronized void removeAll()
  {
    items.removeAllElements();
  }

  public String paramString()
  {
    return getName() + ",label" + label + ",tearOff=" + tearOff + 
           ",isHelpMenu=" + isHelpMenu;
  }
  
  // Accessibility API not yet implemented.
  // public AccessibleContext getAccessibleContext()
135
}