Author: jflesch
Date: 2006-07-17 21:18:12 +0000 (Mon, 17 Jul 2006)
New Revision: 9648

Modified:
   trunk/apps/Thaw/src/thaw/core/Core.java
   trunk/apps/Thaw/src/thaw/core/WarningWindow.java
   trunk/apps/Thaw/src/thaw/fcp/FCPBufferedStream.java
   trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java
   trunk/apps/Thaw/src/thaw/i18n/thaw.properties
   trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
Log:
Add a warning before quitting if thaw is sending data to the node

Modified: trunk/apps/Thaw/src/thaw/core/Core.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Core.java     2006-07-17 18:24:50 UTC (rev 
9647)
+++ trunk/apps/Thaw/src/thaw/core/Core.java     2006-07-17 21:18:12 UTC (rev 
9648)
@@ -8,7 +8,9 @@
 import javax.swing.JFrame;
 import javax.swing.UIManager;
 import javax.swing.UIManager.LookAndFeelInfo;
+import javax.swing.JOptionPane;

+
 import thaw.i18n.I18n;
 import thaw.fcp.*;

@@ -279,11 +281,32 @@
                return true;
        }

+       /**
+        * End of the world.
+        */
+       public void exit() {
+               exit(false);
+       }

+
        /**
         * End of the world.
+        * @param force if true, doesn't check if FCPConnection.isWritting().
+        * @see exit()
         */
-       public void exit() {
+       public void exit(boolean force) {
+               if(!force) {
+                       if(connection.isWriting()) {
+                               int ret = JOptionPane.showOptionDialog(null, 
I18n.getMessage("thaw.warning.isWriting"),
+                                                                      
I18n.getMessage("thaw.warning.title"),
+                                                                      
JOptionPane.YES_NO_OPTION, 
+                                                                      
JOptionPane.WARNING_MESSAGE,
+                                                                      null, 
null, 0);
+                               if(ret == JOptionPane.CLOSED_OPTION || ret > 0)
+                                       return;
+                       }
+               }
+
                Logger.info(this, "Stopping scheduler ...");
                if(queueManager != null)
                    queueManager.stopScheduler();

Modified: trunk/apps/Thaw/src/thaw/core/WarningWindow.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/WarningWindow.java    2006-07-17 18:24:50 UTC 
(rev 9647)
+++ trunk/apps/Thaw/src/thaw/core/WarningWindow.java    2006-07-17 21:18:12 UTC 
(rev 9648)
@@ -2,6 +2,7 @@

 import javax.swing.JOptionPane;

+import thaw.i18n.I18n;

 /**
  * Use to create a warning popup.
@@ -18,12 +19,12 @@
                if(core != null && core.getMainWindow() != null) {
                        
JOptionPane.showMessageDialog(core.getMainWindow().getMainFrame(),
                                                      warning,
-                                                     "Warning",
+                                                     
I18n.getMessage("thaw.warning.title"),
                                                      
JOptionPane.WARNING_MESSAGE);
                } else {
                        JOptionPane.showMessageDialog(null,
                                                      warning,
-                                                     "Warning",
+                                                     
I18n.getMessage("thaw.warning.title"),
                                                      
JOptionPane.WARNING_MESSAGE);
                }
        }

Modified: trunk/apps/Thaw/src/thaw/fcp/FCPBufferedStream.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPBufferedStream.java 2006-07-17 18:24:50 UTC 
(rev 9647)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPBufferedStream.java 2006-07-17 21:18:12 UTC 
(rev 9648)
@@ -147,12 +147,21 @@
                }
        }

+
        public boolean stopSender() {
                running = false;
                tractopelle = null;
                return true;
        }

+       public boolean isOutputBufferEmpty() {
+               return (waiting == 0);
+       }
+
+       public boolean isOutputBufferFull() {
+               return (maxUploadSpeed < 0 || waiting >= 
(OUTPUT_BUFFER_SIZE-1));
+       }
+
        /**
         * Just ignore the InterruptedException.
         */

Modified: trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java     2006-07-17 18:24:50 UTC 
(rev 9647)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java     2006-07-17 21:18:12 UTC 
(rev 9648)
@@ -22,6 +22,11 @@
  * TODO: Add functions socketToFile(long size, File file) / fileToSocket(File 
file)
  */
 public class FCPConnection extends Observable {
+       /** If == true, then will print on stdout
+        * all fcp input / output.
+        */
+       private final static boolean DEBUG_MODE = true;
+
        private FCPBufferedStream bufferedOut = null;
        private int maxUploadSpeed = 0;

@@ -38,11 +43,10 @@

        private boolean lockWriting = false;

-       /** If == true, then will print on stdout
-        * all fcp input / output.
-        */
-       private final static boolean DEBUG_MODE = true;
+       private long lastWrite = 0; /* real writes ; System.currentTimeMillis() 
*/

+
+
        /**
         * Don't connect. Call connect() for that.
         * @param maxUploadSpeed in KB: -1 means no limit
@@ -153,6 +157,9 @@
                return true;
        }

+       public boolean isOutputBufferEmpty() {
+               return bufferedOut.isOutputBufferEmpty();
+       }

        public boolean isConnected() {
                if(socket == null)
@@ -192,6 +199,7 @@
        public boolean realRawWrite(byte[] data) {
                if(out != null && socket != null && socket.isConnected()) {
                        try {
+                               lastWrite = System.currentTimeMillis();
                                out.write(data);
                        } catch(java.io.IOException e) {
                                Logger.warning(this, "Unable to write() on the 
socket ?! : "+ e.toString());
@@ -206,6 +214,11 @@
                return true;
        }

+       
+       public boolean isWriting() {
+               return ( isConnected() && ((System.currentTimeMillis() - 
lastWrite) < 300) );
+       }
+
        public boolean write(String toWrite) {
                return write(toWrite, true);
        }

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2006-07-17 18:24:50 UTC 
(rev 9647)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2006-07-17 21:18:12 UTC 
(rev 9648)
@@ -113,3 +113,7 @@
 thaw.plugin.fetch.loadKeyListFromFile=Load keys from file ...
 thaw.plugin.fetch.destinationDirectory=Destination directory
 thaw.plugin.fetch.chooseDestination=Choose destination ...
+
+## Warnings
+thaw.warning.title=Warning
+thaw.warning.isWriting=Warning ! Thaw is sending data to the node. It would be 
better to quit when thaw will finish. Are you sure you want to quit ?

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties    2006-07-17 18:24:50 UTC 
(rev 9647)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties    2006-07-17 21:18:12 UTC 
(rev 9648)
@@ -112,3 +112,7 @@
 thaw.plugin.fetch.loadKeyListFromFile=Charger les cl?s d'un fichier ...
 thaw.plugin.fetch.destinationDirectory=R?pertoire de destination
 thaw.plugin.fetch.chooseDestination=Choisissez la destination ...
+
+## Warnings
+thaw.warning.title=Avertissement
+thaw.warning.isWriting=Attention ! Thaw est entrain d'envoyer des informations 
? la node. Il serait pr?f?rable de quitter une fois ces envois finis. Etes-vous 
s?r de vouloir quitter ?


Reply via email to