[jsword-svn] r969 - in trunk: bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop common/src/main/java/org/crosswire/common/progress common-swing/src/main/java/org/crosswire/common/progress/swing

dmsmith at crosswire.org dmsmith at crosswire.org
Mon Jan 23 10:20:46 MST 2006


Author: dmsmith
Date: 2006-01-23 10:20:11 -0700 (Mon, 23 Jan 2006)
New Revision: 969

Modified:
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Splash.java
   trunk/common-swing/src/main/java/org/crosswire/common/progress/swing/JobsProgressBar.java
   trunk/common-swing/src/main/java/org/crosswire/common/progress/swing/JobsViewPane.java
   trunk/common/src/main/java/org/crosswire/common/progress/Job.java
   trunk/common/src/main/java/org/crosswire/common/progress/WorkEvent.java
   trunk/common/src/main/java/org/crosswire/common/progress/WorkListener.java
Log:
remove java.beans from common.progress.Job

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Splash.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Splash.java	2006-01-23 16:15:36 UTC (rev 968)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Splash.java	2006-01-23 17:20:11 UTC (rev 969)
@@ -179,5 +179,13 @@
                 Splash.this.pack();
             }
         }
+        
+        /* (non-Javadoc)
+         * @see org.crosswire.common.progress.WorkListener#workStateChanged(org.crosswire.common.progress.WorkEvent)
+         */
+        public void workStateChanged(WorkEvent ev)
+        {
+            // we don't care about these events.
+        }
     }
 }

Modified: trunk/common/src/main/java/org/crosswire/common/progress/Job.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/progress/Job.java	2006-01-23 16:15:36 UTC (rev 968)
+++ trunk/common/src/main/java/org/crosswire/common/progress/Job.java	2006-01-23 17:20:11 UTC (rev 969)
@@ -21,14 +21,14 @@
  */
 package org.crosswire.common.progress;
 
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Timer;
@@ -62,16 +62,14 @@
         this.reportedpc = 0;
         this.finished = false;
         this.interruptable = work != null;
-        this.listeners = new PropertyChangeSupport(this);
+        this.listeners = new ArrayList();
         this.start = -1;
         this.predictedlen = -1;
 
         if (fakeupdates)
         {
             updater = new Timer();
-            updater.schedule(new PredictTask(),
-                             0,
-                             100);
+            updater.schedule(new PredictTask(), 0, 100);
         }
 
         // Set-up the timings files. It's not a disaster if it doesn't load
@@ -211,10 +209,8 @@
         {
             return;
         }
-        Boolean oldValue = Boolean.valueOf(interruptable);
-        Boolean newValue = Boolean.valueOf(newInterruptable);
         interruptable = newInterruptable;
-        listeners.firePropertyChange("interruptable", oldValue, newValue); //$NON-NLS-1$
+        fireStateChanged();
     }
 
     /**
@@ -253,6 +249,60 @@
     }
 
     /**
+     * Add a listener to the list
+     */
+    public synchronized void addWorkListener(WorkListener li)
+    {
+        List temp = new ArrayList();
+        temp.addAll(listeners);
+
+        if (!temp.contains(li))
+        {
+            temp.add(li);
+            listeners = temp;
+        }
+    }
+
+    /**
+     * Remote a listener from the list
+     */
+    public synchronized void removeWorkListener(WorkListener li)
+    {
+        if (listeners.contains(li))
+        {
+            List temp = new ArrayList();
+            temp.addAll(listeners);
+            temp.remove(li);
+            listeners = temp;
+        }
+    }
+
+    protected void fireStateChanged()
+    {
+        final WorkEvent ev = new WorkEvent(this);
+
+        // we need to keep the synchronized section very small to avoid deadlock
+        // certainly keep the event dispatch clear of the synchronized block or
+        // there will be a deadlock
+        final List temp = new ArrayList();
+        synchronized (this)
+        {
+            temp.addAll(listeners);
+        }
+
+        // We ought only to tell listeners about jobs that are in our
+        // list of jobs so we need to fire before delete.
+        if (listeners != null)
+        {
+            int count = temp.size();
+            for (int i = 0; i < count; i++)
+            {
+                ((WorkListener) temp.get(i)).workStateChanged(ev);
+            }
+        }
+    }
+
+    /**
      * Predict a percentage complete
      */
     private synchronized int getAgeFromMap(Map props, String message)
@@ -441,26 +491,6 @@
     }
 
     /**
-     * Interface for people to be notified of changes to the
-     * current Font.
-     * @param li The new listener class
-     */
-    public void addPropertyChangeListener(PropertyChangeListener li)
-    {
-        listeners.addPropertyChangeListener(li);
-    }
-
-    /**
-     * Interface for people to be notified of changes to the
-     * current Font.
-     * @param li The listener class to be deleted
-     */
-    public void removePropertyChangeListener(PropertyChangeListener li)
-    {
-        listeners.removePropertyChangeListener(li);
-    }
-
-    /**
      * Does this job allow interruptions?
      */
     private boolean interruptable;
@@ -543,7 +573,7 @@
     /**
      * People that want to know about "interruptable" changes
      */
-    private PropertyChangeSupport listeners;
+    private List listeners;
 
     /**
      * So we can fake progress for Jobs that don't tell us how they are doing

Modified: trunk/common/src/main/java/org/crosswire/common/progress/WorkEvent.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/progress/WorkEvent.java	2006-01-23 16:15:36 UTC (rev 968)
+++ trunk/common/src/main/java/org/crosswire/common/progress/WorkEvent.java	2006-01-23 17:20:11 UTC (rev 969)
@@ -43,6 +43,14 @@
     }
 
     /**
+     * Initialize a WorkEvent
+     */
+    public WorkEvent(Job source)
+    {
+        super(source);
+    }
+
+    /**
      * Accessor for the Job
      */
     public Job getJob()

Modified: trunk/common/src/main/java/org/crosswire/common/progress/WorkListener.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/progress/WorkListener.java	2006-01-23 16:15:36 UTC (rev 968)
+++ trunk/common/src/main/java/org/crosswire/common/progress/WorkListener.java	2006-01-23 17:20:11 UTC (rev 969)
@@ -39,4 +39,5 @@
      * @param ev Describes the progress
      */
     void workProgressed(WorkEvent ev);
+    void workStateChanged(WorkEvent ev);
 }

Modified: trunk/common-swing/src/main/java/org/crosswire/common/progress/swing/JobsProgressBar.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/progress/swing/JobsProgressBar.java	2006-01-23 16:15:36 UTC (rev 968)
+++ trunk/common-swing/src/main/java/org/crosswire/common/progress/swing/JobsProgressBar.java	2006-01-23 17:20:11 UTC (rev 969)
@@ -29,8 +29,6 @@
 import java.awt.Insets;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -58,7 +56,7 @@
  *      The copyright to this program is held by it's authors.
  * @author Joe Walker [joe at eireneh dot com]
  */
-public class JobsProgressBar extends JPanel implements WorkListener, PropertyChangeListener
+public class JobsProgressBar extends JPanel implements WorkListener
 {
     /**
      * Simple ctor
@@ -111,12 +109,22 @@
         });
     }
 
+    /* (non-Javadoc)
+     * @see org.crosswire.common.progress.WorkListener#workStateChanged(org.crosswire.common.progress.WorkEvent)
+     */
+    public void workStateChanged(WorkEvent ev)
+    {
+        Job job = (Job) ev.getSource();
+        JobData jobdata = (JobData) jobs.get(job);
+        jobdata.workStateChanged(ev);
+    }
+
     /**
      * Create a new set of components for the new Job
      */
     protected synchronized void addJob(Job job)
     {
-        job.addPropertyChangeListener(this);
+        job.addWorkListener(this);
 
         int i = findEmptyPosition();
         log.debug("adding job to panel at " + i + ": " + job.getJobDescription()); //$NON-NLS-1$ //$NON-NLS-2$
@@ -150,13 +158,6 @@
         GuiUtil.refresh(this);
     }
 
-    public void propertyChange(PropertyChangeEvent evt)
-    {
-        Job job = (Job) evt.getSource();
-        JobData jobdata = (JobData) jobs.get(job);
-        jobdata.propertyChange(evt);
-    }
-
     /**
      * Update the job details because it has just progressed
      */
@@ -174,7 +175,7 @@
      */
     protected synchronized void removeJob(Job job)
     {
-        job.addPropertyChangeListener(this);
+        job.removeWorkListener(this);
 
         JobData jobdata = (JobData) jobs.get(job);
 
@@ -239,7 +240,7 @@
     /**
      * A simple struct to group information about a Job
      */
-    private static class JobData implements PropertyChangeListener
+    private static class JobData implements WorkListener
     {
         /**
          * Simple ctor
@@ -306,7 +307,10 @@
             return index;
         }
 
-        public void propertyChange(PropertyChangeEvent evt)
+        /* (non-Javadoc)
+         * @see org.crosswire.common.progress.WorkListener#workStateChanged(org.crosswire.common.progress.WorkEvent)
+         */
+        public void workStateChanged(WorkEvent evt)
         {
             if (cancelButton != null)
             {
@@ -314,6 +318,14 @@
             }
         }
 
+        /* (non-Javadoc)
+         * @see org.crosswire.common.progress.WorkListener#workProgressed(org.crosswire.common.progress.WorkEvent)
+         */
+        public void workProgressed(WorkEvent ev)
+        {
+            // Don't care about progress
+        }
+
         /**
          * Create a cancel button that only shows the cancel icon.
          * When the button is pressed the job is interrupted.

Modified: trunk/common-swing/src/main/java/org/crosswire/common/progress/swing/JobsViewPane.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/progress/swing/JobsViewPane.java	2006-01-23 16:15:36 UTC (rev 968)
+++ trunk/common-swing/src/main/java/org/crosswire/common/progress/swing/JobsViewPane.java	2006-01-23 17:20:11 UTC (rev 969)
@@ -111,6 +111,14 @@
         SwingUtilities.invokeLater(new JobRunner(this, ev));
     }
 
+    /* (non-Javadoc)
+     * @see org.crosswire.common.progress.WorkListener#workStateChanged(org.crosswire.common.progress.WorkEvent)
+     */
+    public void workStateChanged(WorkEvent ev)
+    {
+        // Not needed
+    }
+
     /**
      * Create a new set of components for the new Job
      */



More information about the jsword-svn mailing list