classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] imageio/ImageReader|Writer check *Listeners


From: Andreas Tobler
Subject: [cp-patches] imageio/ImageReader|Writer check *Listeners
Date: Mon, 03 Oct 2005 22:35:59 +0200
User-agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711)

Hello Tom,

as spoken about on irc.

Is this what you had in mind?

I can run 2D swing Demo again.

Andreas


2005-10-03  Andreas Tobler  <address@hidden>

        * javax/imageio/ImageWriter.java (availableLocales, locale,
        originatingProvider, output, progressListeners, warningListeners,
        warningLocales): Initialize.
        (addIIOWriteProgressListener): Check progressListeners against null
        to avoid NPE.
        (addIIOWriteWarningListener): Likewise for warningListeners.
        (processImageComplete): Likewise for progressListeners.
        (processImageProgress): Likewise.
        (processImageStarted): Likewise.
        (processThumbnailComplete): Likewise.
        (processThumbnailProgress): Likewise.
        (processThumbnailStarted): Likewise.
        (processWarningOccurred): Likewise for warningListeners.
        (processWriteAborted): Likewise for progressListeners.
        (removeAllIIOWriteProgressListeners): Likewise.
        (removeAllIIOWriteWarningListeners): Likewise.
        (removeIIOWriteProgressListener): Likewise.
        (removeIIOWriteWarningListener): Likewise for warningListeners.

        * javax/imageio/ImageReader.java (addIIOReadProgressListener): Check
        progressListeners against null to avoid NPE.
        (addIIOReadUpdateListener): Likewise for updateListeners.
        (addIIOReadWarningListener): Likewise for warningListeners.
        (processImageComplete):  Likewise for progressListeners.
        (processImageProgress): Likewise.
        (processImageStarted): Likewise.
        (processImageUpdate): Likewise for updateListeners.
        (processPassComplete): Likewise.
        (processPassStarted): Likewise.
        (processReadAborted): Likewise for progressListeners.
        (processSequenceComplete): Likewise.
        (processSequenceStarted): Likewise.
        (processThumbnailComplete): Likewise.
        (processThumbnailPassComplete): Likewise for updateListeners.
        (processThumbnailPassStarted): Likewise.
        (processThumbnailProgress): Likewise for progressListeners.
        (processThumbnailStarted): Likewise.
        (processThumbnailUpdate): Likewise for updateListeners.
        (processWarningOccurred): Likewise for warningListeners.
        (removeIIOReadProgressListener): Likewise for progressListeners.
        (removeIIOReadUpdateListener): Likewise for updateListeners.
        (removeIIOReadWarningListener): Likewise for warningListeners.
Index: javax/imageio/ImageReader.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/imageio/ImageReader.java,v
retrieving revision 1.6
diff -u -r1.6 ImageReader.java
--- javax/imageio/ImageReader.java      2 Oct 2005 05:29:55 -0000       1.6
+++ javax/imageio/ImageReader.java      3 Oct 2005 20:34:10 -0000
@@ -1,5 +1,5 @@
 /* ImageReader.java -- Decodes raster images.
-   Copyright (C) 2004  Free Software Foundation, Inc.
+   Copyright (C) 2004, 2005  Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -185,8 +185,10 @@
   {
     if (listener == null)
       return;
-
-    progressListeners.add(listener);    
+    if (progressListeners != null)
+      {
+       progressListeners.add(listener);
+      }
   }
 
   /**
@@ -199,10 +201,12 @@
   {
     if (listener == null)
       return;
-    
-    updateListeners.add(listener);    
+    if (updateListeners != null)
+      {
+       updateListeners.add(listener);
+      }
   }
-  
+
   /**
    * Install a read warning listener.  This method will return
    * immediately if listener is null.  Warning messages sent to this
@@ -216,8 +220,10 @@
   {
     if (listener == null)
       return;
-    
-    warningListeners.add(listener);    
+    if (warningListeners != null)
+      {
+       warningListeners.add(listener);
+      }
   }
 
   /**
@@ -763,12 +769,16 @@
    */
   protected void processImageComplete()
   {
-    Iterator it = progressListeners.iterator();
-
-    while (it.hasNext())
+    if (progressListeners != null)
       {
-       IIOReadProgressListener listener = (IIOReadProgressListener) it.next();
-       listener.imageComplete (this);
+       Iterator it = progressListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOReadProgressListener listener =
+             (IIOReadProgressListener) it.next();
+           listener.imageComplete (this);
+         }
       }
   }
 
@@ -782,15 +792,18 @@
    */
   protected void processImageProgress(float percentageDone)
   {
-    Iterator it = progressListeners.iterator();
-
-    while (it.hasNext())
+     if (progressListeners != null)
       {
-       IIOReadProgressListener listener = (IIOReadProgressListener) it.next();
-       listener.imageProgress(this, percentageDone);
+       Iterator it = progressListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOReadProgressListener listener =
+             (IIOReadProgressListener) it.next();
+           listener.imageProgress(this, percentageDone);
+         }
       }
   }
-
   /**
    * Notifies all installed read progress listeners, by calling their
    * imageStarted methods, that image loading has started on the given
@@ -801,12 +814,16 @@
    */
   protected void processImageStarted(int imageIndex)
   {
-    Iterator it = progressListeners.iterator();
-
-    while (it.hasNext())
+     if (progressListeners != null)
       {
-       IIOReadProgressListener listener = (IIOReadProgressListener) it.next();
-       listener.imageStarted(this, imageIndex);
+       Iterator it = progressListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOReadProgressListener listener =
+             (IIOReadProgressListener) it.next();
+           listener.imageStarted(this, imageIndex);
+         }
       }
   }
 
@@ -829,13 +846,16 @@
                                    int width, int height, int periodX,
                                    int periodY, int[] bands)
   {
-    Iterator it = updateListeners.iterator();
-
-    while (it.hasNext())
+    if (updateListeners != null)
       {
-       IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next();
-       listener.imageUpdate(this, image, minX, minY, width, height, periodX,
-                            periodY, bands);
+       Iterator it = updateListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next();
+           listener.imageUpdate(this, image, minX, minY, width, height,
+                                periodX, periodY, bands);
+         }
       }
   }
 
@@ -848,12 +868,15 @@
    */
   protected void processPassComplete(BufferedImage image)
   {
-    Iterator it = updateListeners.iterator();
-
-    while (it.hasNext())
+    if (updateListeners != null)
       {
-       IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next();
-       listener.passComplete(this, image);
+       Iterator it = updateListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next();
+           listener.passComplete(this, image);
+         }
       }
   }
 
@@ -879,13 +902,16 @@
                                    int maxPass, int minX, int minY,
                                    int periodX, int periodY, int[] bands)
   {
-    Iterator it = updateListeners.iterator();
-
-    while (it.hasNext())
+    if (updateListeners != null)
       {
-       IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next();
-       listener.passStarted(this, image, pass, minPass, maxPass, minX, minY,
-                            periodX, periodY, bands);
+       Iterator it = updateListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next();
+           listener.passStarted(this, image, pass, minPass, maxPass, minX,
+                                minY, periodX, periodY, bands);
+         }
       }
   }
 
@@ -895,15 +921,18 @@
    */
   protected void processReadAborted()
   {
-    Iterator it = progressListeners.iterator();
-
-    while (it.hasNext())
+     if (progressListeners != null)
       {
-       IIOReadProgressListener listener = (IIOReadProgressListener) it.next();
-       listener.readAborted(this);
+       Iterator it = progressListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOReadProgressListener listener =
+             (IIOReadProgressListener) it.next();
+           listener.readAborted(this);
+         }
       }
   }
-
   /**
    * Notifies all installed read progress listeners, by calling their
    * sequenceComplete methods, that a sequence of images has completed
@@ -911,12 +940,16 @@
    */
   protected void processSequenceComplete()
   {
-    Iterator it = progressListeners.iterator();
-
-    while (it.hasNext())
+     if (progressListeners != null)
       {
-       IIOReadProgressListener listener = (IIOReadProgressListener) it.next();
-       listener.sequenceComplete(this);
+       Iterator it = progressListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOReadProgressListener listener =
+             (IIOReadProgressListener) it.next();
+           listener.sequenceComplete(this);
+         }
       }
   }
 
@@ -929,12 +962,17 @@
    */
   protected void processSequenceStarted(int minIndex)
   {
-    Iterator it = progressListeners.iterator();
 
-    while (it.hasNext())
+    if (progressListeners != null)
       {
-       IIOReadProgressListener listener = (IIOReadProgressListener) it.next();
-       listener.sequenceStarted(this, minIndex);
+       Iterator it = progressListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOReadProgressListener listener =
+             (IIOReadProgressListener) it.next();
+           listener.sequenceStarted(this, minIndex);
+         }
       }
   }
 
@@ -945,12 +983,16 @@
    */
   protected void processThumbnailComplete()
   {
-    Iterator it = progressListeners.iterator();
-
-    while (it.hasNext())
+    if (progressListeners != null)
       {
-       IIOReadProgressListener listener = (IIOReadProgressListener) it.next();
-       listener.thumbnailComplete(this);
+       Iterator it = progressListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOReadProgressListener listener =
+             (IIOReadProgressListener) it.next();
+           listener.thumbnailComplete(this);
+         }
       }
   }
 
@@ -963,12 +1005,15 @@
    */
   protected void processThumbnailPassComplete(BufferedImage thumbnail)
   {
-    Iterator it = updateListeners.iterator();
-
-    while (it.hasNext())
+    if (updateListeners != null)
       {
-       IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next();
-       listener.thumbnailPassComplete(this, thumbnail);
+       Iterator it = updateListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next();
+           listener.thumbnailPassComplete(this, thumbnail);
+         }
       }
   }
 
@@ -995,16 +1040,20 @@
                                             int minY, int periodX, int periodY,
                                             int[] bands)
   {
-    Iterator it = updateListeners.iterator();
-
-    while (it.hasNext())
+    if (updateListeners != null)
       {
-       IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next();
-       listener.thumbnailPassStarted(this, thumbnail, pass, minPass, maxPass,
-                                     minX, minY, periodX, periodY, bands);
+       Iterator it = updateListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next();
+           listener.thumbnailPassStarted(this, thumbnail, pass, minPass,
+                                         maxPass, minX, minY, periodX,
+                                         periodY, bands);
+         }
       }
   }
-  
+
   /**
    * Notifies all installed read progress listeners that a certain
    * percentage of a thumbnail has been loaded, by calling their
@@ -1015,12 +1064,16 @@
    */
   protected void processThumbnailProgress(float percentageDone)
   {
-    Iterator it = progressListeners.iterator();
-
-    while (it.hasNext())
+    if (progressListeners != null)
       {
-       IIOReadProgressListener listener = (IIOReadProgressListener) it.next();
-       listener.thumbnailProgress(this, percentageDone);
+       Iterator it = progressListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOReadProgressListener listener =
+             (IIOReadProgressListener) it.next();
+           listener.thumbnailProgress(this, percentageDone);
+         }
       }
   }
 
@@ -1036,12 +1089,16 @@
    */
   protected void processThumbnailStarted(int imageIndex, int thumbnailIndex)
   {
-    Iterator it = progressListeners.iterator();
-
-    while (it.hasNext())
+    if (progressListeners != null)
       {
-       IIOReadProgressListener listener = (IIOReadProgressListener) it.next();
-       listener.thumbnailStarted(this, imageIndex, thumbnailIndex);
+       Iterator it = progressListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOReadProgressListener listener =
+             (IIOReadProgressListener) it.next();
+           listener.thumbnailStarted(this, imageIndex, thumbnailIndex);
+         }
       }
   }
 
@@ -1064,13 +1121,16 @@
                                        int width, int height, int periodX,
                                        int periodY, int[] bands)
   {
-    Iterator it = updateListeners.iterator();
-
-    while (it.hasNext())
+    if (updateListeners != null)
       {
-       IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next();
-       listener.thumbnailUpdate(this, image, minX, minY, width, height,
-                                periodX, periodY, bands);
+       Iterator it = updateListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next();
+           listener.thumbnailUpdate(this, image, minX, minY, width, height,
+                                    periodX, periodY, bands);
+         }
       }
   }
 
@@ -1086,13 +1146,16 @@
   {
     if (warning == null)
       throw new IllegalArgumentException ("null argument");
-
-    Iterator it = warningListeners.iterator();
-
-    while (it.hasNext())
+    if (warningListeners != null)
       {
-       IIOReadWarningListener listener = (IIOReadWarningListener) it.next();
-       listener.warningOccurred(this, warning);
+       Iterator it = warningListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOReadWarningListener listener =
+             (IIOReadWarningListener) it.next();
+           listener.warningOccurred(this, warning);
+         }
       }
   }
 
@@ -1205,10 +1268,12 @@
   {
     if (listener == null)
       return;
- 
-    progressListeners.remove(listener);
+    if (progressListeners != null)
+      {
+       progressListeners.remove(listener);
+      }
   }
-  
+
   /**
    * Uninstall the given read update listener.
    *
@@ -1218,10 +1283,13 @@
   {
     if (listener == null)
       return;
-    
-    updateListeners.remove(listener);
+
+    if (updateListeners != null)
+      {
+       updateListeners.remove(listener);
+      }
   }
-  
+
   /**
    * Uninstall the given read warning listener.
    *
@@ -1231,8 +1299,10 @@
   {
     if (listener == null)
       return;
-    
-    warningListeners.remove(listener);
+    if (warningListeners != null)
+      {
+       warningListeners.remove(listener);
+      }
   }
 
   /**
Index: javax/imageio/ImageWriter.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/imageio/ImageWriter.java,v
retrieving revision 1.7
diff -u -r1.7 ImageWriter.java
--- javax/imageio/ImageWriter.java      2 Oct 2005 05:29:55 -0000       1.7
+++ javax/imageio/ImageWriter.java      3 Oct 2005 20:34:12 -0000
@@ -1,5 +1,5 @@
 /* ImageWriter.java -- Encodes raster images.
-   Copyright (C) 2004  Free Software Foundation, Inc.
+   Copyright (C) 2004, 2005  Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -78,41 +78,41 @@
    * All locales available for localization of warning messages, or
    * null if localization is not supported.
    */
-  protected Locale[] availableLocales;
+  protected Locale[] availableLocales = null;
 
   /**
    * The current locale used to localize warning messages, or null if
    * no locale has been set.
    */
-  protected Locale locale;
+  protected Locale locale = null;
 
   /**
    * The image writer SPI that instantiated this writer.
    */
-  protected ImageWriterSpi originatingProvider;
+  protected ImageWriterSpi originatingProvider = null;
 
   /**
    * An ImageInputStream to which image data is written.
    */
-  protected Object output;
+  protected Object output = null;
 
   /**
    * A list of installed progress listeners.  Initially null, meaning
    * no installed listeners.
    */
-  protected List progressListeners = new ArrayList();
+  protected List progressListeners = null;
 
   /**
    * A list of installed warning listeners.  Initially null, meaning
    * no installed listeners.
    */
-  protected List warningListeners = new ArrayList();
+  protected List warningListeners = null;
 
   /**
    * A list of warning locales corresponding with the list of
    * installed warning listeners.  Initially null, meaning no locales.
    */
-  protected List warningLocales = new ArrayList();
+  protected List warningLocales = null;
 
   /**
    * Construct an image writer.
@@ -169,10 +169,12 @@
   {
     if (listener == null)
       return;
-    
-    progressListeners.add(listener);
+    if (progressListeners != null)
+      {
+       progressListeners.add(listener);
+      }
   }
-  
+
   /**
    * Install a write warning listener.  This method will return
    * immediately if listener is null.  Warning messages sent to this
@@ -186,8 +188,10 @@
   {
     if (listener == null)
       return;
-    
-    warningListeners.add(listener);
+    if (warningListeners != null)
+      {
+       warningListeners.add(listener);
+      }
   }
 
   /**
@@ -561,12 +565,16 @@
    */
   protected void processImageComplete()
   {
-    Iterator it = progressListeners.iterator();
-
-    while (it.hasNext())
+    if (progressListeners != null)
       {
-       IIOWriteProgressListener listener = (IIOWriteProgressListener) 
it.next();
-       listener.imageComplete(this);
+       Iterator it = progressListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOWriteProgressListener listener =
+             (IIOWriteProgressListener) it.next();
+           listener.imageComplete(this);
+         }
       }
   }
 
@@ -580,12 +588,16 @@
    */
   protected void processImageProgress(float percentageDone)
   {
-    Iterator it = progressListeners.iterator();
-
-    while (it.hasNext())
+    if (progressListeners != null)
       {
-       IIOWriteProgressListener listener = (IIOWriteProgressListener) 
it.next();
-       listener.imageProgress(this, percentageDone);
+       Iterator it = progressListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOWriteProgressListener listener =
+             (IIOWriteProgressListener) it.next();
+           listener.imageProgress(this, percentageDone);
+         }
       }
   }
 
@@ -599,12 +611,16 @@
    */
   protected void processImageStarted(int imageIndex)
   {
-    Iterator it = progressListeners.iterator();
-
-    while (it.hasNext())
+    if (progressListeners != null)
       {
-       IIOWriteProgressListener listener = (IIOWriteProgressListener) 
it.next();
-       listener.imageStarted(this, imageIndex);
+       Iterator it = progressListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOWriteProgressListener listener =
+             (IIOWriteProgressListener) it.next();
+           listener.imageStarted(this, imageIndex);
+         }
       }
   }
 
@@ -615,12 +631,16 @@
    */
   protected void processThumbnailComplete()
   {
-    Iterator it = progressListeners.iterator();
-
-    while (it.hasNext())
+    if (progressListeners != null)
       {
-       IIOWriteProgressListener listener = (IIOWriteProgressListener) 
it.next();
-       listener.thumbnailComplete(this);
+       Iterator it = progressListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOWriteProgressListener listener =
+             (IIOWriteProgressListener) it.next();
+           listener.thumbnailComplete(this);
+         }
       }
   }
 
@@ -634,12 +654,16 @@
    */
   protected void processThumbnailProgress(float percentageDone)
   {
-    Iterator it = progressListeners.iterator();
-
-    while (it.hasNext())
+    if (progressListeners != null)
       {
-       IIOWriteProgressListener listener = (IIOWriteProgressListener) 
it.next();
-       listener.thumbnailProgress(this, percentageDone);
+       Iterator it = progressListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOWriteProgressListener listener =
+             (IIOWriteProgressListener) it.next();
+           listener.thumbnailProgress(this, percentageDone);
+         }
       }
   }
 
@@ -655,12 +679,16 @@
    */
   protected void processThumbnailStarted(int imageIndex, int thumbnailIndex)
   {
-    Iterator it = progressListeners.iterator();
-
-    while (it.hasNext())
+    if (progressListeners != null)
       {
-       IIOWriteProgressListener listener = (IIOWriteProgressListener) 
it.next();
-       listener.thumbnailStarted(this, imageIndex, thumbnailIndex);
+       Iterator it = progressListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOWriteProgressListener listener =
+             (IIOWriteProgressListener) it.next();
+           listener.thumbnailStarted(this, imageIndex, thumbnailIndex);
+         }
       }
   }
 
@@ -676,12 +704,16 @@
    */
   protected void processWarningOccurred(int imageIndex, String warning)
   {
-    Iterator it = warningListeners.iterator();
-
-    while (it.hasNext())
+     if (warningListeners != null)
       {
-       IIOWriteWarningListener listener = (IIOWriteWarningListener) it.next();
-       listener.warningOccurred(this, imageIndex, warning);
+       Iterator it = warningListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOWriteWarningListener listener =
+             (IIOWriteWarningListener) it.next();
+           listener.warningOccurred(this, imageIndex, warning);
+         }
       }
   }
 
@@ -691,12 +723,16 @@
    */
   protected void processWriteAborted() 
   {
-    Iterator it = progressListeners.iterator();
-
-    while (it.hasNext())
+    if (progressListeners != null)
       {
-       IIOWriteProgressListener listener = (IIOWriteProgressListener) 
it.next();
-       listener.writeAborted(this);
+       Iterator it = progressListeners.iterator();
+
+       while (it.hasNext())
+         {
+           IIOWriteProgressListener listener =
+             (IIOWriteProgressListener) it.next();
+           listener.writeAborted(this);
+         }
       }
   }
 
@@ -705,7 +741,10 @@
    */
   public void removeAllIIOWriteProgressListeners()
   {
-    progressListeners.clear();
+    if (progressListeners != null)
+      {
+       progressListeners.clear();
+      }
   }
 
   /**
@@ -713,22 +752,26 @@
    */
   public void removeAllIIOWriteWarningListeners()
   {
-    progressListeners.clear();
+    if (progressListeners != null)
+      {
+       progressListeners.clear();
+      }
   }
-  
+
   /**
    * Uninstall the given write progress listener.
    *
    * @param listener the listener to remove
    */
-  public void removeIIOWriteProgressListener (IIOWriteProgressListener 
listener) 
+  public void removeIIOWriteProgressListener (IIOWriteProgressListener 
listener)
   {
     if (listener == null)
       return;
-    
-    progressListeners.remove(listener);
+    if (progressListeners != null)
+      {
+       progressListeners.remove(listener);
+      }
   }
-  
   /**
    * Uninstall the given write warning listener.
    *
@@ -738,10 +781,11 @@
   {
     if (listener == null)
       return;
-    
-    warningListeners.remove(listener);
+    if (warningListeners != null)
+      {
+       warningListeners.remove(listener);
+      }
   }
-  
   /**
    * Reset this writer's internal state.
    */

reply via email to

[Prev in Thread] Current Thread [Next in Thread]