changeset 20125:65a1e01378a2

7124537: [macosx] Menu shortcuts for all menu items should be disabled if a menu itself is disabled Reviewed-by: anthony, leonidr
author serb
date Thu, 12 Sep 2013 18:21:06 +0400
parents ad00860443b0
children e09648d4170c
files jdk/src/macosx/classes/sun/lwawt/macosx/CMenu.java jdk/src/macosx/classes/sun/lwawt/macosx/CMenuItem.java jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java
diffstat 3 files changed, 34 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/CMenu.java	Thu Sep 12 15:50:25 2013 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CMenu.java	Thu Sep 12 18:21:06 2013 +0400
@@ -26,9 +26,11 @@
 package sun.lwawt.macosx;
 
 import java.awt.*;
+import java.awt.peer.MenuItemPeer;
 import java.awt.peer.MenuPeer;
 
 public class CMenu extends CMenuItem implements MenuPeer {
+
     public CMenu(Menu target) {
         super(target);
     }
@@ -41,6 +43,20 @@
     }
 
     @Override
+    public final void setEnabled(final boolean b) {
+        super.setEnabled(b);
+        final Menu target = (Menu) getTarget();
+        final int count = target.getItemCount();
+        for (int i = 0; i < count; ++i) {
+            MenuItem item = target.getItem(i);
+            MenuItemPeer p = (MenuItemPeer) LWCToolkit.targetToPeer(item);
+            if (p != null) {
+                p.setEnabled(b && item.isEnabled());
+            }
+        }
+    }
+
+    @Override
     protected long createModel() {
         CMenuComponent parent = (CMenuComponent)
             LWCToolkit.targetToPeer(getTarget().getParent());
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/CMenuItem.java	Thu Sep 12 15:50:25 2013 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CMenuItem.java	Thu Sep 12 18:21:06 2013 +0400
@@ -28,17 +28,20 @@
 import sun.awt.SunToolkit;
 import sun.lwawt.LWToolkit;
 
+import java.awt.MenuContainer;
 import java.awt.MenuItem;
 import java.awt.MenuShortcut;
 import java.awt.event.*;
 import java.awt.peer.MenuItemPeer;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 public class CMenuItem extends CMenuComponent implements MenuItemPeer {
 
+    private final AtomicBoolean enabled = new AtomicBoolean(true);
+
     public CMenuItem(MenuItem target) {
         super(target);
         initialize(target);
-
     }
 
     // This way we avoiding invocation of the setters twice
@@ -124,9 +127,19 @@
         setEnabled(false);
     }
 
+    public final boolean isEnabled() {
+        return enabled.get();
+    }
+
     @Override
     public void setEnabled(boolean b) {
-        nativeSetEnabled(getModel(), b);
+        final Object parent = LWToolkit.targetToPeer(getTarget().getParent());
+        if (parent instanceof CMenuItem) {
+            b &= ((CMenuItem) parent).isEnabled();
+        }
+        if (enabled.compareAndSet(!b, b)) {
+            nativeSetEnabled(getModel(), b);
+        }
     }
 
     private native long nativeCreate(long parentMenu, boolean isSeparator);
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java	Thu Sep 12 15:50:25 2013 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java	Thu Sep 12 18:21:06 2013 +0400
@@ -207,9 +207,9 @@
 
     @Override
     public MenuBarPeer createMenuBar(MenuBar target) {
-         MenuBarPeer peer = new CMenuBar(target);
-         targetCreatedPeer(target, peer);
-             return peer;
+        MenuBarPeer peer = new CMenuBar(target);
+        targetCreatedPeer(target, peer);
+        return peer;
     }
 
     @Override