jdk/src/share/classes/javax/swing/plaf/synth/SynthMenuUI.java
changeset 1295 3cf2264a5743
parent 2 90ce3da70b43
child 4394 92a8ec883f5d
--- a/jdk/src/share/classes/javax/swing/plaf/synth/SynthMenuUI.java	Fri Jul 25 14:26:27 2008 -0400
+++ b/jdk/src/share/classes/javax/swing/plaf/synth/SynthMenuUI.java	Fri Aug 08 20:49:26 2008 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2002-2008 Sun Microsystems, Inc.  All Rights Reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -35,7 +35,7 @@
 import java.util.Arrays;
 import java.util.ArrayList;
 import sun.swing.plaf.synth.SynthUI;
-
+import sun.swing.MenuItemLayoutHelper;
 
 /**
  * Synth's MenuUI.
@@ -86,7 +86,7 @@
             acceleratorDelimiter = style.getString(context, prefix +
                                             ".acceleratorDelimiter", "+");
 
-            if (useCheckAndArrow()) {
+            if (MenuItemLayoutHelper.useCheckAndArrow(menuItem)) {
                 checkIcon = style.getIcon(context, prefix + ".checkIcon");
                 arrowIcon = style.getIcon(context, prefix + ".arrowIcon");
             } else {
@@ -111,6 +111,16 @@
         accContext.dispose();
     }
 
+    public void uninstallUI(JComponent c) {
+        super.uninstallUI(c);
+        // Remove values from the parent's Client Properties.
+        JComponent p = MenuItemLayoutHelper.getMenuItemParent((JMenuItem) c);
+        if (p != null) {
+            p.putClientProperty(
+                    SynthMenuItemLayoutHelper.MAX_ACC_OR_ARROW_WIDTH, null);
+        }
+    }
+
     protected void uninstallDefaults() {
         SynthContext context = getContext(menuItem, ENABLED);
         style.uninstallDefaults(context);
@@ -182,9 +192,11 @@
                                                      int defaultTextIconGap) {
         SynthContext context = getContext(c);
         SynthContext accContext = getContext(c, Region.MENU_ITEM_ACCELERATOR);
-        Dimension value = SynthMenuItemUI.getPreferredMenuItemSize(
-                  context, accContext, c, checkIcon, arrowIcon,
-                  defaultTextIconGap, acceleratorDelimiter);
+        Dimension value = SynthGraphicsUtils.getPreferredMenuItemSize(
+                context, accContext, c, checkIcon, arrowIcon,
+                defaultTextIconGap, acceleratorDelimiter,
+                MenuItemLayoutHelper.useCheckAndArrow(menuItem),
+                getPropertyPrefix());
         context.dispose();
         accContext.dispose();
         return value;
@@ -211,21 +223,12 @@
     protected void paint(SynthContext context, Graphics g) {
         SynthContext accContext = getContext(menuItem,
                                              Region.MENU_ITEM_ACCELERATOR);
-        SynthStyle style = context.getStyle();
-        Icon checkIcon;
-        Icon arrowIcon;
-        if (useCheckAndArrow()) {
-            // Refetch the appropriate icons for the current state
-            String prefix = getPropertyPrefix();
-            checkIcon = style.getIcon(context, prefix + ".checkIcon");
-            arrowIcon = style.getIcon(context, prefix + ".arrowIcon");
-        } else {
-            // Not needed in this case
-            checkIcon = null;
-            arrowIcon = null;
-        }
-        SynthMenuItemUI.paint(context, accContext, g, checkIcon, arrowIcon,
-                              acceleratorDelimiter, defaultTextIconGap);
+        // Refetch the appropriate check indicator for the current state
+        String prefix = getPropertyPrefix();
+        Icon checkIcon = style.getIcon(context, prefix + ".checkIcon");
+        Icon arrowIcon = style.getIcon(context, prefix + ".arrowIcon");
+        SynthGraphicsUtils.paint(context, accContext, g, checkIcon, arrowIcon,
+              acceleratorDelimiter, defaultTextIconGap, getPropertyPrefix());
         accContext.dispose();
     }
 
@@ -239,8 +242,4 @@
             updateStyle((JMenu)e.getSource());
         }
     }
-
-    private boolean useCheckAndArrow() {
-        return !((JMenu)menuItem).isTopLevelMenu();
-    }
 }