src/share/classes/javax/swing/PopupFactory.java

Print this page

        

@@ -23,14 +23,18 @@
  * questions.
  */
 
 package javax.swing;
 
+import sun.awt.EmbeddedFrame;
+import sun.awt.OSInfo;
+
 import java.applet.Applet;
 import java.awt.*;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
+import java.security.AccessController;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import static javax.swing.ClientPropertyKey.PopupFactory_FORCE_HEAVYWEIGHT_POPUP;

@@ -224,11 +228,16 @@
         case LIGHT_WEIGHT_POPUP:
             return getLightWeightPopup(owner, contents, ownerX, ownerY);
         case MEDIUM_WEIGHT_POPUP:
             return getMediumWeightPopup(owner, contents, ownerX, ownerY);
         case HEAVY_WEIGHT_POPUP:
-            return getHeavyWeightPopup(owner, contents, ownerX, ownerY);
+            Popup popup = getHeavyWeightPopup(owner, contents, ownerX, ownerY);
+            if ((AccessController.doPrivileged(OSInfo.getOSTypeAction()) ==
+                OSInfo.OSType.MACOSX) && (EmbeddedFrame.getAppletIfAncestorOf(owner) != null)) {
+                ((HeavyWeightPopup)popup).setCacheEnabled(false);
+            }
+            return popup;
         }
         return null;
     }
 
     /**

@@ -292,10 +301,12 @@
      */
     private static class HeavyWeightPopup extends Popup {
         private static final Object heavyWeightPopupCacheKey =
                  new StringBuffer("PopupFactory.heavyWeightPopupCache");
 
+        private volatile boolean isCacheEnabled = true;
+
         /**
          * Returns either a new or recycled <code>Popup</code> containing
          * the specified children.
          */
         static Popup getHeavyWeightPopup(Component owner, Component contents,

@@ -446,16 +457,27 @@
                     popup._dispose();
                 }
             }
         }
 
+        /**
+         * Enables or disables cache for current object.
+         */
+        void setCacheEnabled(boolean enable) {
+            isCacheEnabled = enable;
+        }
+
         //
         // Popup methods
         //
         public void hide() {
             super.hide();
+            if (isCacheEnabled) {
             recycleHeavyWeightPopup(this);
+            } else {
+                this._dispose();
+            }
         }
 
         /**
          * As we recycle the <code>Window</code>, we don't want to dispose it,
          * thus this method does nothing, instead use <code>_dipose</code>