[gui][PATCH] MenuListener & more fixes
Olga Rodimina
rodimina@redhat.com
Tue Jun 22 17:20:00 GMT 2004
Hi,
Attached patch makes few fixes to menues and implements MenuListener.
I'll be committing this patch to java-gui-branch.
--
Olga Rodimina <rodimina@redhat.com>
-------------- next part --------------
? .snprj
? libjava.proj
? patch
? popup_Patch
? resources
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2660.2.212
diff -c -p -u -r1.2660.2.212 ChangeLog
--- ChangeLog 21 Jun 2004 20:26:23 -0000 1.2660.2.212
+++ ChangeLog 22 Jun 2004 16:50:43 -0000
@@ -1,3 +1,18 @@
+2004-06-22 Olga Rodimina <rodimina@redhat.com>
+
+ * javax/swing/AbstractButton.java:
+ (setDisplayedMnemonicIndex): Check if button
+ text is not null before checking its length.
+ * javax/swing/JMenuItem.java:
+ (processMouseEvent): Disarm menu item if mouse has
+ exited it.
+ * javax/swing/plaf/basic/BasicMenuUI.java:
+ (MouseInputHandler.mouseEntered): Do not raise
+ popup menu if this menu is already selected.
+ (MouseInputHandler.mousePressed): Do not fire
+ MenuEvents.
+ (MenuHandler): Implemented.
+
2004-06-21 Olga Rodimina <rodimina@redhat.com>
* javax/swing/AbstractButton.java:
Index: javax/swing/AbstractButton.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/AbstractButton.java,v
retrieving revision 1.5.2.9
diff -c -p -u -r1.5.2.9 AbstractButton.java
--- javax/swing/AbstractButton.java 21 Jun 2004 20:26:24 -0000 1.5.2.9
+++ javax/swing/AbstractButton.java 22 Jun 2004 16:50:43 -0000
@@ -760,7 +760,7 @@ public abstract class AbstractButton ext
public void setDisplayedMnemonicIndex(int index)
{
- if (index < -1 || index >= text.length())
+ if (index < -1 || (text != null && index >= text.length()))
throw new IllegalArgumentException();
else
mnemonicIndex = index;
Index: javax/swing/JMenuItem.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JMenuItem.java,v
retrieving revision 1.2.18.8
diff -c -p -u -r1.2.18.8 JMenuItem.java
--- javax/swing/JMenuItem.java 9 Jun 2004 22:46:48 -0000 1.2.18.8
+++ javax/swing/JMenuItem.java 22 Jun 2004 16:50:43 -0000
@@ -346,6 +346,9 @@ public class JMenuItem extends AbstractB
ButtonModel model = item.getModel();
if (item.isRolloverEnabled())
model.setRollover(false);
+
+ if (! (event.getSource() instanceof JMenu))
+ setArmed(false);
}
break;
case MouseEvent.MOUSE_PRESSED:
Index: javax/swing/plaf/basic/BasicMenuUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicMenuUI.java,v
retrieving revision 1.1.2.7
diff -c -p -u -r1.1.2.7 BasicMenuUI.java
--- javax/swing/plaf/basic/BasicMenuUI.java 21 Jun 2004 20:26:25 -0000 1.1.2.7
+++ javax/swing/plaf/basic/BasicMenuUI.java 22 Jun 2004 16:50:43 -0000
@@ -302,19 +302,17 @@ public class BasicMenuUI extends BasicMe
public void mouseEntered(MouseEvent e)
{
-
/* When mouse enters menu item, it should be considered selected
if (i) if this menu is a submenu in some other menu
(ii) or if this menu is in a menu bar and some other menu in a menu bar was just
selected. (If nothing was selected, menu should be pressed before
- it will be selected)
+ it will be selected)
*/
-
JMenu menu = (JMenu) menuItem;
if (! menu.isTopLevelMenu()
|| (menu.isTopLevelMenu()
- && (((JMenuBar) menu.getParent()).isSelected())))
+ && (((JMenuBar) menu.getParent()).isSelected() && ! menu.isArmed())))
{
// set new selection and forward this event to MenuSelectionManager
MenuSelectionManager manager = MenuSelectionManager.defaultManager();
@@ -335,29 +333,24 @@ public class BasicMenuUI extends BasicMe
public void mousePressed(MouseEvent e)
{
-
MenuSelectionManager manager = MenuSelectionManager.defaultManager();
JMenu menu = (JMenu) menuItem;
manager.processMouseEvent(e);
-
+
// Menu should be displayed when the menu is pressed only if
// it is top-level menu
if (menu.isTopLevelMenu())
{
if (menu.getPopupMenu().isVisible())
- {
- // If menu is visible and menu button was pressed..
- // then need to cancel the menu
- menu.fireMenuCanceled();
- manager.clearSelectedPath();
- }
+ // If menu is visible and menu button was pressed..
+ // then need to cancel the menu
+ manager.clearSelectedPath();
else
{
// Display the menu
int x = 0;
int y = menu.getHeight();
- menu.fireMenuSelected();
manager.setSelectedPath(getPath());
JMenuBar mb = (JMenuBar) menu.getParent();
@@ -382,30 +375,44 @@ public class BasicMenuUI extends BasicMe
{
/**
* This method is called when menu is cancelled. The menu is cancelled
- * when its popup menu is closed without selection.
+ * when its popup menu is closed without selection. It clears selected index
+ * in the selectionModel of the menu parent.
*
* @param e The MenuEvent.
*/
public void menuCanceled(MenuEvent e)
{
+ menuDeselected(e);
}
/**
- * This method is called when menu is deselected.
+ * This method is called when menu is deselected. It clears selected index
+ * in the selectionModel of the menu parent.
*
* @param e The MenuEvent.
*/
public void menuDeselected(MenuEvent e)
{
+ JMenu menu = (JMenu) menuItem;
+ if (menu.isTopLevelMenu())
+ ((JMenuBar) menu.getParent()).getSelectionModel().clearSelection();
+ else
+ ((JPopupMenu) menu.getParent()).getSelectionModel().clearSelection();
}
/**
- * This method is called when menu is selected.
+ * This method is called when menu is selected. It sets selected index
+ * in the selectionModel of the menu parent.
*
* @param e The MenuEvent.
*/
public void menuSelected(MenuEvent e)
{
+ JMenu menu = (JMenu) menuItem;
+ if (menu.isTopLevelMenu())
+ ((JMenuBar) menu.getParent()).setSelected(menu);
+ else
+ ((JPopupMenu) menu.getParent()).setSelected(menu);
}
}
More information about the Java-patches
mailing list