From 68878a057b30f338eda7cacfe5f93cd850e8aaa1 Mon Sep 17 00:00:00 2001
From: Kelly Rauchenberger <fefferburbia@gmail.com>
Date: Fri, 15 Aug 2008 12:27:16 +0000
Subject: Client: Added org.jdesktop-style progress

Closes #34
---
 .../com/fourisland/instadisc/InstaDiscThread.java  | 20 +++++++++++--
 .../com/fourisland/instadisc/InstaDiscView.java    | 34 +++++++++++++++++++++-
 2 files changed, 51 insertions(+), 3 deletions(-)

(limited to 'client/trunk/src/com')

diff --git a/client/trunk/src/com/fourisland/instadisc/InstaDiscThread.java b/client/trunk/src/com/fourisland/instadisc/InstaDiscThread.java
index e2b203e..d4a293c 100644
--- a/client/trunk/src/com/fourisland/instadisc/InstaDiscThread.java
+++ b/client/trunk/src/com/fourisland/instadisc/InstaDiscThread.java
@@ -21,6 +21,12 @@ import java.util.logging.Logger;
 public class InstaDiscThread implements Runnable {
 
     boolean cancelled = false;
+    InstaDiscView idv;
+    
+    public InstaDiscThread(InstaDiscView idv)
+    {
+        this.idv = idv;
+    }
 
     public void cancel() {
         cancelled = true;
@@ -38,7 +44,7 @@ public class InstaDiscThread implements Runnable {
                 try
                 {
                     Socket s = svr.accept();
-                    HandleItemThread hit = new HandleItemThread(s);
+                    HandleItemThread hit = new HandleItemThread(s,idv);
                     Thread hitt = new Thread(hit);
                     hitt.start();
                 } catch (SocketException ex)
@@ -62,12 +68,17 @@ public class InstaDiscThread implements Runnable {
 class HandleItemThread implements Runnable {
 
     Socket s;
+    InstaDiscView idv;
 
-    public HandleItemThread(Socket s) {
+    public HandleItemThread(Socket s, InstaDiscView idv) {
         this.s = s;
+        this.idv = idv;
     }
 
     public void run() {
+        idv.startProgress();
+        idv.doText("Downloading Item....");
+        
         try
         {
             InputStream is = s.getInputStream();
@@ -85,6 +96,9 @@ class HandleItemThread implements Runnable {
                     {
                         buffer[i] = rs;
                     }
+                    
+                    idv.doProgress(buffer.length / (is.available()+1));
+                    
                     i++;
                 } catch (SocketException ex)
                 {
@@ -135,5 +149,7 @@ class HandleItemThread implements Runnable {
         {
             Logger.getLogger(HandleItemThread.class.getName()).log(Level.SEVERE, null, ex);
         }
+        
+        idv.doneProgress();
     }
 }
diff --git a/client/trunk/src/com/fourisland/instadisc/InstaDiscView.java b/client/trunk/src/com/fourisland/instadisc/InstaDiscView.java
index 198ce2b..b03ce07 100644
--- a/client/trunk/src/com/fourisland/instadisc/InstaDiscView.java
+++ b/client/trunk/src/com/fourisland/instadisc/InstaDiscView.java
@@ -109,7 +109,7 @@ public class InstaDiscView extends FrameView {
         jList1.setCellRenderer(new IDItemListCellRenderer());
         refreshItemPane();
 
-        InstaDiscThread idt = new InstaDiscThread();
+        InstaDiscThread idt = new InstaDiscThread(this);
         Thread idtt = new Thread(idt);
         idtt.start();
 
@@ -436,4 +436,36 @@ public class InstaDiscView extends FrameView {
 
         ipCheckTimer.start();
     }
+    
+    public synchronized void startProgress()
+    {
+        if (!busyIconTimer.isRunning()) {
+            statusAnimationLabel.setIcon(busyIcons[0]);
+            busyIconIndex = 0;
+            busyIconTimer.start();
+        }
+        progressBar.setVisible(true);
+        progressBar.setIndeterminate(true);
+    }
+    
+    public synchronized void doneProgress()
+    {
+        busyIconTimer.stop();
+        statusAnimationLabel.setIcon(idleIcon);
+        progressBar.setVisible(false);
+        progressBar.setValue(0);
+    }
+    
+    public synchronized void doText(String text)
+    {
+        statusMessageLabel.setText((text == null) ? "" : text);
+        messageTimer.restart();
+    }
+    
+    public synchronized void doProgress(Integer value)
+    {
+        progressBar.setVisible(true);
+        progressBar.setIndeterminate(false);
+        progressBar.setValue(value);
+    }
 }
-- 
cgit 1.4.1