[gui][PATCH] fixes to UI Delegates of JMenu & JMenuItem

Olga Rodimina rodimina@redhat.com
Fri May 21 16:07:00 GMT 2004


Hi,

Attached patch makes few fixes to UI Delegates of JMenu & JMenuItem.
I'll be committing this patch to java-gui-branch.


Olga.
-------------- next part --------------
? .snprj
? libjava.proj
? patch
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2660.2.107
diff -c -p -u -r1.2660.2.107 ChangeLog
--- ChangeLog	20 May 2004 15:13:16 -0000	1.2660.2.107
+++ ChangeLog	21 May 2004 15:36:29 -0000
@@ -1,3 +1,16 @@
+2004-05-21  Olga Rodimina  <rodimina@redhat.com>
+
+	* javax/swing/plaf/basic/BasicMenuItemUI.java:
+	(BasicMenuItemUI): Create propertyChangeListener.
+	(getPath):Implemented.
+	(installListeners): Add propertyChangeListener to menuItem.
+	(uninstallListeners): Remove propertyChangeListener from menuItem.
+	(update): Implemented.
+	* javax/swing/plaf/basic/BasicMenuUI.MouseInputHandler:
+	(mouseEntered): Take insets of popup menu into account when
+	calculating position of popup menu.	
+ 	
+
 2004-05-18  Olga Rodimina  <rodimina@redhat.com>
 
 	* Makefile.am: Added new file. 
Index: javax/swing/plaf/basic/BasicMenuItemUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicMenuItemUI.java,v
retrieving revision 1.1.2.8
diff -c -p -u -r1.1.2.8 BasicMenuItemUI.java
--- javax/swing/plaf/basic/BasicMenuItemUI.java	18 May 2004 14:31:21 -0000	1.1.2.8
+++ javax/swing/plaf/basic/BasicMenuItemUI.java	21 May 2004 15:36:31 -0000
@@ -40,6 +40,7 @@ package javax.swing.plaf.basic;
 import java.awt.AWTKeyStroke;
 import java.awt.BasicStroke;
 import java.awt.Color;
+import java.awt.Component;
 import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.FontMetrics;
@@ -57,6 +58,7 @@ import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
+import java.util.Vector;
 import javax.swing.AbstractButton;
 import javax.swing.ButtonModel;
 import javax.swing.Icon;
@@ -64,6 +66,7 @@ import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JComponent;
 import javax.swing.JMenu;
 import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;
 import javax.swing.JRadioButtonMenuItem;
 import javax.swing.KeyStroke;
 import javax.swing.MenuElement;
@@ -167,6 +170,7 @@ public class BasicMenuItemUI extends Men
    * String that separates description of the modifiers and the key
    */
   private String acceleratorDelimiter;
+  private PropertyChangeListener propertyChangeListener;
 
   /**
    * Number of spaces between accelerator and menu item's label.
@@ -178,6 +182,7 @@ public class BasicMenuItemUI extends Men
     mouseInputListener = createMouseInputListener(menuItem);
     menuDragMouseListener = createMenuDragMouseListener(menuItem);
     menuKeyListener = createMenuKeyListener(menuItem);
+    propertyChangeListener = new PropertyChangeHandler();
   }
 
   protected MenuDragMouseListener createMenuDragMouseListener(JComponent c)
@@ -263,8 +268,24 @@ public class BasicMenuItemUI extends Men
    */
   public MenuElement[] getPath()
   {
-    // TODO
-    return null;
+    Vector path = new Vector();
+    Component c = menuItem;
+    while (c instanceof MenuElement)
+      {
+	path.add(c);
+
+	if (c instanceof JPopupMenu)
+	  c = ((JPopupMenu) c).getInvoker();
+	else
+	  c = c.getParent();
+      }
+
+    // convert from vector to array
+    MenuElement[] pathArray = new MenuElement[path.size()];
+    for (int i = 0; i < path.size(); i++)
+      pathArray[i] = (MenuElement) path.get(path.size() - i - 1);
+
+    return pathArray;
   }
 
   /**
@@ -324,15 +345,15 @@ public class BasicMenuItemUI extends Men
 	  d.height = checkIcon.getIconHeight();
       }
 
-     if (arrowIcon != null && (c instanceof JMenu))
+    if (arrowIcon != null && (c instanceof JMenu))
       {
-       d.width = d.width + arrowIcon.getIconWidth() + defaultTextIconGap;
+	d.width = d.width + arrowIcon.getIconWidth() + defaultTextIconGap;
 
-       if (arrowIcon.getIconHeight() > d.height)
-         d.height = arrowIcon.getIconHeight();
-       }
+	if (arrowIcon.getIconHeight() > d.height)
+	  d.height = arrowIcon.getIconHeight();
+      }
 
-     return d;
+    return d;
   }
 
   /**
@@ -392,6 +413,7 @@ public class BasicMenuItemUI extends Men
     menuItem.addMouseListener(mouseInputListener);
     menuItem.addMenuDragMouseListener(menuDragMouseListener);
     menuItem.addMenuKeyListener(menuKeyListener);
+    menuItem.addPropertyChangeListener(propertyChangeListener);
   }
 
   /**
@@ -624,6 +646,7 @@ public class BasicMenuItemUI extends Men
     menuItem.removeMouseListener(mouseInputListener);
     menuItem.removeMenuDragMouseListener(menuDragMouseListener);
     menuItem.removeMenuKeyListener(menuKeyListener);
+    menuItem.removePropertyChangeListener(propertyChangeListener);
   }
 
   /**
@@ -646,7 +669,7 @@ public class BasicMenuItemUI extends Men
    */
   public void update(Graphics g, JComponent c)
   {
-    // TODO
+    paint(g, c);
   }
 
   /**
@@ -892,7 +915,7 @@ public class BasicMenuItemUI extends Men
    * @author $author$
    * @version $Revision: 1.1.2.8 $
    */
-  protected class PropertyChangeHandler
+  protected class PropertyChangeHandler implements PropertyChangeListener
   {
     /**
      * DOCUMENT ME!
Index: javax/swing/plaf/basic/BasicMenuUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/Attic/BasicMenuUI.java,v
retrieving revision 1.1.2.2
diff -c -p -u -r1.1.2.2 BasicMenuUI.java
--- javax/swing/plaf/basic/BasicMenuUI.java	20 May 2004 15:13:19 -0000	1.1.2.2
+++ javax/swing/plaf/basic/BasicMenuUI.java	21 May 2004 15:36:31 -0000
@@ -309,10 +309,11 @@ public class BasicMenuUI extends BasicMe
         {
 	  JMenuBar mb = (JMenuBar) subMenu.getParent();
 
-	  // Take into account menu bar margin when calculating y coordinate
-	  // of the popup menu.
+	  // Subtract menuBar's insets.bottom and popupMenu's insets.top, 
+	  // s.t. the space between menu bar and its popup menu is equal to 
+	  // menuBar's margin. By default menuBar's margin is Insets(0,0,0,0).
 	  y = subMenu.getHeight() - mb.getInsets().bottom
-	      + mb.getMargin().bottom;
+	      - subMenu.getPopupMenu().getInsets().top + mb.getMargin().bottom;
         }
       else
 	x = subMenu.getWidth();


More information about the Java-patches mailing list