aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/awt/Menu.java
blob: 34dd600d779595dfce12c2e4f3cf7e1bdbfb02b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
135
/* Copyright (C) 1999, 2000  Free Software Foundation

   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;

import java.util.Vector;

/* Status: Incomplete. */

public class Menu extends MenuItem implements MenuContainer
{
  // 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)
  {
    this(label, false);
  }
  
  public Menu(String label, boolean tearOff)
  {
    super(label);
    this.tearOff = tearOff;
  }

  public void addNotify()
  {
    // FIXME
  }

  public void removeNotify()
  {
    // FIXME
  }

  public boolean isTearOff()
  {
    return tearOff;
  }

  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()
}