jdk/src/java.desktop/share/classes/javax/swing/JLayer.java
changeset 26037 508779ce6619
parent 26029 730f9bc4b85e
parent 25859 3317bb8137f4
child 27265 a6528e9ca83b
--- a/jdk/src/java.desktop/share/classes/javax/swing/JLayer.java	Mon Aug 18 14:03:21 2014 +0100
+++ b/jdk/src/java.desktop/share/classes/javax/swing/JLayer.java	Tue Aug 19 10:32:16 2014 -0700
@@ -158,8 +158,9 @@
     private LayerUI<? super V> layerUI;
     private JPanel glassPane;
     private long eventMask;
-    private transient boolean isPainting;
-    private transient boolean isPaintingImmediately;
+    private transient boolean isPaintCalling;
+    private transient boolean isPaintImmediatelyCalling;
+    private transient boolean isImageUpdateCalling;
 
     private static final LayerEventController eventController =
             new LayerEventController();
@@ -405,12 +406,12 @@
      * @param h  the height of the region to be painted
      */
     public void paintImmediately(int x, int y, int w, int h) {
-        if (!isPaintingImmediately && getUI() != null) {
-            isPaintingImmediately = true;
+        if (!isPaintImmediatelyCalling && getUI() != null) {
+            isPaintImmediatelyCalling = true;
             try {
                 getUI().paintImmediately(x, y, w, h, this);
             } finally {
-                isPaintingImmediately = false;
+                isPaintImmediatelyCalling = false;
             }
         } else {
             super.paintImmediately(x, y, w, h);
@@ -418,17 +419,44 @@
     }
 
     /**
+     * Delegates its functionality to the
+     * {@link javax.swing.plaf.LayerUI#imageUpdate(java.awt.Image, int, int, int, int, int, JLayer)} method,
+     * if the {@code LayerUI} is set.
+     *
+     * @param     img   the image being observed
+     * @param     infoflags   see {@code imageUpdate} for more information
+     * @param     x   the <i>x</i> coordinate
+     * @param     y   the <i>y</i> coordinate
+     * @param     w   the width
+     * @param     h   the height
+     * @return    {@code false} if the infoflags indicate that the
+     *            image is completely loaded; {@code true} otherwise.
+     */
+    public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h) {
+        if (!isImageUpdateCalling && getUI() != null) {
+            isImageUpdateCalling = true;
+            try {
+                return getUI().imageUpdate(img, infoflags, x, y, w, h, this);
+            } finally {
+                isImageUpdateCalling = false;
+            }
+        } else {
+            return super.imageUpdate(img, infoflags, x, y, w, h);
+        }
+    }
+
+    /**
      * Delegates all painting to the {@link javax.swing.plaf.LayerUI} object.
      *
      * @param g the {@code Graphics} to render to
      */
     public void paint(Graphics g) {
-        if (!isPainting) {
-            isPainting = true;
+        if (!isPaintCalling) {
+            isPaintCalling = true;
             try {
                 super.paintComponent(g);
             } finally {
-                isPainting = false;
+                isPaintCalling = false;
             }
         } else {
             super.paint(g);
@@ -646,15 +674,21 @@
         return 1;
     }
 
+    @SuppressWarnings("unchecked")
     private void readObject(ObjectInputStream s)
             throws IOException, ClassNotFoundException {
-        s.defaultReadObject();
-        if (layerUI != null) {
-            setUI(layerUI);
-        }
+        ObjectInputStream.GetField f = s.readFields();
+
+        view = (V) f.get("view", null);
+        glassPane = (JPanel) f.get("glassPane", null);
+        eventMask = f.get("eventMask", 0l);
         if (eventMask != 0) {
             eventController.updateAWTEventListener(0, eventMask);
         }
+        LayerUI<V> newLayerUI = (LayerUI<V>) f.get("layerUI", null);
+        if (newLayerUI != null) {
+            setUI(newLayerUI);
+        }
     }
 
     /**