diff options
Diffstat (limited to 'libjava/classpath/java/awt/Menu.java')
-rw-r--r-- | libjava/classpath/java/awt/Menu.java | 59 |
1 files changed, 39 insertions, 20 deletions
diff --git a/libjava/classpath/java/awt/Menu.java b/libjava/classpath/java/awt/Menu.java index 13ebb5211be..6daec72cf44 100644 --- a/libjava/classpath/java/awt/Menu.java +++ b/libjava/classpath/java/awt/Menu.java @@ -1,5 +1,5 @@ /* Menu.java -- A Java AWT Menu - Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -220,15 +220,16 @@ getItem(int index) public MenuItem add(MenuItem item) { + MenuContainer parent = item.getParent(); + if (parent != null) + parent.remove(item); + items.addElement(item); - if (item.parent != null) - { - item.parent.remove(item); - } - item.parent = this; + item.setParent(this); if (peer != null) { + item.addNotify(); MenuPeer mp = (MenuPeer) peer; mp.addItem(item); } @@ -266,26 +267,33 @@ insert(MenuItem item, int index) if (index < 0) throw new IllegalArgumentException("Index is less than zero"); - MenuPeer peer = (MenuPeer) getPeer(); - if (peer == null) - return; - int count = getItemCount (); if (index >= count) - peer.addItem (item); + add(item); else { + MenuContainer parent = item.getParent(); + if (parent != null) + parent.remove(item); + + items.insertElementAt(item, index); + item.setParent(this); + + MenuPeer peer = (MenuPeer) getPeer(); + if (peer == null) + return; + for (int i = count - 1; i >= index; i--) - peer.delItem (i); + peer.delItem(i); - peer.addItem (item); + item.addNotify(); + peer.addItem(item); for (int i = index; i < count; i++) - peer.addItem ((MenuItem) items.elementAt (i)); + peer.addItem((MenuItem) items.elementAt (i)); } - items.insertElementAt(item, index); } /*************************************************************************/ @@ -344,11 +352,15 @@ insertSeparator(int index) public synchronized void remove(int index) { - items.removeElementAt(index); + MenuItem item = (MenuItem) items.remove(index); - MenuPeer mp = (MenuPeer)getPeer(); + MenuPeer mp = (MenuPeer) getPeer(); if (mp != null) - mp.delItem(index); + { + mp.delItem(index); + item.removeNotify(); + } + item.setParent(null); } /*************************************************************************/ @@ -393,14 +405,21 @@ removeAll() public void addNotify() { + MenuPeer peer = (MenuPeer) getPeer(); if (peer == null) - peer = getToolkit().createMenu(this); + { + peer = getToolkit().createMenu(this); + setPeer(peer); + } + Enumeration e = items.elements(); while (e.hasMoreElements()) { MenuItem mi = (MenuItem)e.nextElement(); mi.addNotify(); - } + peer.addItem(mi); + } + super.addNotify (); } |