Hey,
This patch fixes more constructor regressions from JMenu's constructor.
I have commited a mauve test for this (constructors.java). Again, could
someone please approve this patch so that I can commit it. Thanks.
Here's the Changelog entry:
2006-06-20 Tania Bento <[EMAIL PROTECTED]>
* javax/swing/JMenu.java
(JMenu): Delay should be set to 200, not default of 0.
(JMenu): Delay should be set to 200, not default of 0.
(JMenu): Delay should be set to 200, not default of 0.
(JMenu): Delay should be set to 200, not default of 0.
(remove): Added check that index >= 0 before removing
the component.
(getItem): Return null if item count equals 0.
(isTearOff): Should throw new error and not return false.
(getMenuComponent): Return null if popupMenu is null or
if there are no menu components.
Index: JMenu.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JMenu.java,v
retrieving revision 1.27
diff -u -r1.27 JMenu.java
--- JMenu.java 16 May 2006 06:49:32 -0000 1.27
+++ JMenu.java 20 Jun 2006 20:53:45 -0000
@@ -98,6 +99,7 @@
{
super();
setOpaque(false);
+ setDelay(200);
}
/**
@@ -108,8 +110,10 @@
public JMenu(String text)
{
super(text);
popupMenu = new JPopupMenu();
popupMenu.setInvoker(this);
setOpaque(false);
+ setDelay(200);
}
/**
@@ -122,8 +126,10 @@
{
super(action);
createActionChangeListener(this);
popupMenu = new JPopupMenu();
popupMenu.setInvoker(this);
setOpaque(false);
+ setDelay(200);
}
/**
@@ -137,6 +143,7 @@
{
// FIXME: tearoff not implemented
this(text);
+ setDelay(200);
}
/**
@@ -229,8 +240,9 @@
*/
public void remove(Component component)
{
- int index = popupMenu.getComponentIndex(component);
- popupMenu.remove(index);
+ int index = getPopupMenu().getComponentIndex(component);
+ if (index >= 0)
getPopupMenu().remove(index);
}
/**
@@ -530,6 +542,9 @@
if (index < 0)
throw new IllegalArgumentException("index less than 0");
+ if (getItemCount() == 0)
+ return null;
+
Component c = popupMenu.getComponentAtIndex(index);
if (c instanceof JMenuItem)
@@ -558,7 +573,7 @@
public boolean isTearOff()
{
// NOT YET IMPLEMENTED
- return false;
+ throw new Error("The method isTearOff() has not yet been implemented.");
}
/**
@@ -581,6 +596,9 @@
*/
public Component getMenuComponent(int index)
{
+ if (getPopupMenu() == null || getMenuComponentCount() == 0)
+ return null;
+
return (Component) popupMenu.getComponentAtIndex(index);
}