aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/awt/Menu.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/java/awt/Menu.java')
-rw-r--r--libjava/java/awt/Menu.java77
1 files changed, 57 insertions, 20 deletions
diff --git a/libjava/java/awt/Menu.java b/libjava/java/awt/Menu.java
index c6c4f21..35798a06 100644
--- a/libjava/java/awt/Menu.java
+++ b/libjava/java/awt/Menu.java
@@ -40,8 +40,11 @@ package java.awt;
import java.awt.peer.MenuPeer;
import java.io.Serializable;
-import java.util.Vector;
import java.util.Enumeration;
+import java.util.Vector;
+
+import javax.accessibility.AccessibleContext;
+import javax.accessibility.AccessibleRole;
/**
* This class represents a pull down or tear off menu in Java's AWT.
@@ -72,17 +75,20 @@ private Vector items = new Vector();
/**
* @serial Flag indicating whether or not this menu is a tear off
*/
-private boolean isTearOff;
+private boolean tearOff;
/**
* @serial Indicates whether or not this is a help menu.
*/
private boolean isHelpMenu;
-// From the serialization spec. FIXME: what should it be?
-private int menuSerializedDataVersion;
+ /*
+ * @serial Unused in this implementation, but present in Sun's
+ * serialization spec. Value obtained via reflection.
+ */
+ private int menuSerializedDataVersion = 1;
-static final String separatorLabel = "-";
+static final transient String separatorLabel = "-";
/*************************************************************************/
@@ -134,7 +140,7 @@ Menu(String label, boolean isTearOff)
{
super(label);
- this.isTearOff = isTearOff;
+ tearOff = isTearOff;
if (label.equals("Help"))
isHelpMenu = true;
@@ -158,7 +164,7 @@ Menu(String label, boolean isTearOff)
public boolean
isTearOff()
{
- return(isTearOff);
+ return(tearOff);
}
/*************************************************************************/
@@ -251,8 +257,6 @@ add(String label)
* @param item The menu item to add.
* @param index The index of the menu item.
*
- * XXX: FIXME
- *
* @exception IllegalArgumentException If the index is less than zero.
* @exception ArrayIndexOutOfBoundsException If the index is otherwise invalid.
*/
@@ -262,12 +266,26 @@ insert(MenuItem item, int index)
if (index < 0)
throw new IllegalArgumentException("Index is less than zero");
- items.insertElementAt(item, index);
+ MenuPeer peer = (MenuPeer) getPeer();
+ if (peer == null)
+ return;
- MenuPeer mp = (MenuPeer)getPeer();
- // FIXME: Need to add a peer method here.
-// if (mp != null)
-// mp.insertItem(item, index);
+ int count = getItemCount ();
+
+ if (index >= count)
+ peer.addItem (item);
+ else
+ {
+ for (int i = count - 1; i >= index; i--)
+ peer.delItem (i);
+
+ peer.addItem (item);
+
+ for (int i = index; i < count; i++)
+ peer.addItem ((MenuItem) items.elementAt (i));
+ }
+
+ items.insertElementAt(item, index);
}
/*************************************************************************/
@@ -305,8 +323,6 @@ addSeparator()
*
* @param index The index at which to insert a separator bar.
*
- * XXX: FIXME
- *
* @exception IllegalArgumentException If the index is less than zero.
* @exception ArrayIndexOutOfBoundsException If the index is otherwise invalid.
*/
@@ -339,7 +355,7 @@ remove(int index)
/**
* Removes the specifed item from the menu. If the specified component
- * does not exist, this method does nothing. // FIXME: Right?
+ * does not exist, this method does nothing.
*
* @param item The component to remove.
*/
@@ -415,11 +431,32 @@ removeNotify()
public String
paramString()
{
- return (",isTearOff=" + isTearOff + ",isHelpMenu=" + isHelpMenu
+ return (",tearOff=" + tearOff + ",isHelpMenu=" + isHelpMenu
+ super.paramString());
}
-// Accessibility API not yet implemented.
-// public AccessibleContext getAccessibleContext()
+ /**
+ * Basic Accessibility class for Menu. Details get provided in derived
+ * classes.
+ */
+ protected class AccessibleAWTMenu extends AccessibleAWTMenuItem
+ {
+ protected AccessibleAWTMenu()
+ {
+ }
+
+ public AccessibleRole getAccessibleRole()
+ {
+ return AccessibleRole.MENU;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see java.awt.MenuComponent#getAccessibleContext()
+ */
+ public AccessibleContext getAccessibleContext()
+ {
+ return new AccessibleAWTMenu();
+ }
} // class Menu