Author: jflesch
Date: 2007-06-24 00:09:56 +0000 (Sun, 24 Jun 2007)
New Revision: 13747

Modified:
   trunk/apps/Thaw/src/thaw/gui/TransferProgressBar.java
   trunk/apps/Thaw/src/thaw/plugins/TrayIcon.java
Log:
Refresh progressvily the progress bars inside the panel attached to the systray 
icon

Modified: trunk/apps/Thaw/src/thaw/gui/TransferProgressBar.java
===================================================================
--- trunk/apps/Thaw/src/thaw/gui/TransferProgressBar.java       2007-06-23 
23:45:32 UTC (rev 13746)
+++ trunk/apps/Thaw/src/thaw/gui/TransferProgressBar.java       2007-06-24 
00:09:56 UTC (rev 13747)
@@ -9,6 +9,8 @@
 import thaw.core.I18n;

 public class TransferProgressBar extends JProgressBar {
+       private FCPTransferQuery query;
+       private boolean statusInProgressBar;

        public TransferProgressBar(FCPTransferQuery q) {
                this(q, true);
@@ -16,7 +18,14 @@

        public TransferProgressBar(FCPTransferQuery query, boolean 
statusInProgressBar) {
                super(0, 100);
+               this.query = query;
+               this.statusInProgressBar = statusInProgressBar;

+               refresh();
+       }
+
+       public void refresh() {
+
                int progress;

                setStringPainted(true);
@@ -44,5 +53,4 @@
                                setString(Integer.toString(progress)+"%");
                }
        }
-
 }

Modified: trunk/apps/Thaw/src/thaw/plugins/TrayIcon.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/TrayIcon.java      2007-06-23 23:45:32 UTC 
(rev 13746)
+++ trunk/apps/Thaw/src/thaw/plugins/TrayIcon.java      2007-06-24 00:09:56 UTC 
(rev 13747)
@@ -130,7 +130,9 @@
                }
        }

+       private Vector progressBars = null;

+
        private JPanel getTransferPanel(FCPTransferQuery q) {
                JPanel p = new JPanel(new GridLayout(2, 1));

@@ -153,8 +155,11 @@
                l.setIcon(icon);

                p.add(l);
-               p.add(new TransferProgressBar(q));

+               TransferProgressBar bar = new TransferProgressBar(q);
+               progressBars.add(bar);
+               p.add(bar);
+
                return p;
        }

@@ -187,6 +192,8 @@

                north = new JPanel(new GridLayout(queries.size(), 1, 10, 10));

+               progressBars = new Vector();
+
                for (Iterator it = newQueries.iterator();
                     it.hasNext();) {
                        
north.add(getTransferPanel((FCPTransferQuery)it.next()));
@@ -219,6 +226,46 @@
                dialog.setVisible(true);
        }

+
+       private class ProgressBarRefresher implements Runnable {
+               private Vector bars;
+               private boolean stop;
+
+               public ProgressBarRefresher(Vector bars) {
+                       this.bars = bars;
+                       stop = false;
+               }
+
+               public void run() {
+                       while(!stop) {
+
+                               for (Iterator it = bars.iterator();
+                                    it.hasNext();) {
+
+                                       try {
+                                               Thread.sleep(200);
+                                       } catch(InterruptedException e) {
+                                               /* \_o< */
+                                       }
+
+                                       if (stop)
+                                               break;
+
+                                       TransferProgressBar bar = 
(TransferProgressBar)it.next();
+                                       bar.refresh();
+                               }
+                       }
+               }
+
+               public void stop() {
+                       stop = true;
+               }
+       }
+
+
+       private ProgressBarRefresher refresher = null;
+
+
        public void displayFrame(int x, int y) {
                java.awt.Dimension d = 
Toolkit.getDefaultToolkit().getScreenSize();
                int screen_x = (int)d.getWidth();
@@ -230,9 +277,20 @@
                        y -= DIALOG_Y;

                realDisplayFrame(x, y);
+
+               /* progressBars vector is generated at the same time than the 
panels */
+               refresher = new ProgressBarRefresher(progressBars);
        }

+       public void hideFrame() {
+               dialog.setVisible(false);
+               dialog = null;
+               progressBars = null;
+               refresher.stop();
+               refresher = null;
+       }

+
        public void windowActivated(WindowEvent e) { }
        public void windowClosed(WindowEvent e) { }
        public void windowClosing(WindowEvent e) { }
@@ -248,8 +306,7 @@

        public void mouseClicked(MouseEvent e) {
                if (dialog != null) {
-                       dialog.setVisible(false);
-                       dialog = null;
+                       hideFrame();
                        return;
                }

@@ -271,8 +328,7 @@
        public void actionPerformed(ActionEvent e) {
                if (e.getSource() == closeDialog) {
                        if (dialog != null) {
-                               dialog.setVisible(false);
-                               dialog = null;
+                               hideFrame();
                        }
                }
        }


Reply via email to