This fixes some of the size problems with popup menus.

2005-10-21  Lillian Angel  <[EMAIL PROTECTED]>

        * javax/swing/JPopupMenu.java
        (show): Fixed to set the size if it was never set.
        * javax/swing/plaf/basic/BasicMenuUI.java
        (menuDeselected): Added check to prevent NPE.
        * javax/swing/plaf/basic/BasicSeparatorUI.java:
        Removed minSize, horizontalPrefSize, verticalPrefSize and
        maxSize fields. They were causing problems when other classes
        were setting this variables to something else. More reliable if
        actual value is returned.
        (getPreferredSize): Returned appropriate values.
        (getMinimumSize): Likewise.
        (getMaximumSize): Likewise.

Index: javax/swing/JPopupMenu.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JPopupMenu.java,v
retrieving revision 1.29
diff -u -r1.29 JPopupMenu.java
--- javax/swing/JPopupMenu.java	19 Oct 2005 15:45:04 -0000	1.29
+++ javax/swing/JPopupMenu.java	21 Oct 2005 15:11:30 -0000
@@ -552,7 +552,12 @@
             Dimension screenSize = getToolkit().getScreenSize();
             
             boolean fit = true;
-            Dimension size = this.getSize();
+            Dimension size = getSize();
+            if (size.width == 0 && size.height == 0)
+              {
+                size = getPreferredSize();
+                setSize(size);
+              }
             if ((size.width > (rootContainer.getWidth() - popupLocation.x))
                 || (size.height > (rootContainer.getHeight() - popupLocation.y)))
               fit = false;
Index: javax/swing/plaf/basic/BasicMenuUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicMenuUI.java,v
retrieving revision 1.18
diff -u -r1.18 BasicMenuUI.java
--- javax/swing/plaf/basic/BasicMenuUI.java	18 Oct 2005 22:10:32 -0000	1.18
+++ javax/swing/plaf/basic/BasicMenuUI.java	21 Oct 2005 15:11:30 -0000
@@ -422,10 +422,13 @@
     public void menuDeselected(MenuEvent e)
     {
       JMenu menu = (JMenu) menuItem;
-      if (menu.isTopLevelMenu())
-	((JMenuBar) menu.getParent()).getSelectionModel().clearSelection();
-      else
-	((JPopupMenu) menu.getParent()).getSelectionModel().clearSelection();
+      if (menu.getParent() != null)
+        {
+          if (menu.isTopLevelMenu())
+            ((JMenuBar) menu.getParent()).getSelectionModel().clearSelection();
+          else
+            ((JPopupMenu) menu.getParent()).getSelectionModel().clearSelection();
+        }
     }
 
     /**
Index: javax/swing/plaf/basic/BasicSeparatorUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicSeparatorUI.java,v
retrieving revision 1.8
diff -u -r1.8 BasicSeparatorUI.java
--- javax/swing/plaf/basic/BasicSeparatorUI.java	12 Oct 2005 12:10:00 -0000	1.8
+++ javax/swing/plaf/basic/BasicSeparatorUI.java	21 Oct 2005 15:11:30 -0000
@@ -55,27 +55,6 @@
  */
 public class BasicSeparatorUI extends SeparatorUI
 {
-  /**
-   * The standard minimum size.
-   */
-  static final Dimension minSize = new Dimension(0, 0);
-
-  /**
-   * The standard horizontal preferred size.
-   */
-  static final Dimension horizontalPrefSize = new Dimension(0, 2);
-
-  /**
-   * The standard vertical preferred size.
-   */
-  static final Dimension verticalPrefSize = new Dimension(2, 0);
-
-  /**
-   * The standard maxnimum size.
-   */
-  static final Dimension maxSize = new Dimension(Short.MAX_VALUE,
-                                                 Short.MAX_VALUE);
-
   /** The shadow color. */
   protected Color shadow;
 
@@ -234,12 +213,12 @@
    */
   public Dimension getPreferredSize(JComponent c)
   {
-    Dimension pref = verticalPrefSize;
+    Dimension pref = new Dimension(2, 0);
     if (c instanceof JSeparator)
       {
 	JSeparator s = (JSeparator) c;
 	if (s.getOrientation() == JSeparator.HORIZONTAL)
-          pref = horizontalPrefSize;
+          pref = new Dimension(0, 2);
       }
     return pref;
   }
@@ -254,7 +233,7 @@
    */
   public Dimension getMinimumSize(JComponent c)
   {
-    return minSize;
+    return new Dimension(0, 0);
   }
 
   /**
@@ -267,6 +246,7 @@
    */
   public Dimension getMaximumSize(JComponent c)
   {
-    return maxSize;
+    return new Dimension(Short.MAX_VALUE,
+                         Short.MAX_VALUE);
   }
 }
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to