Author: jflesch
Date: 2006-07-23 21:18:05 +0000 (Sun, 23 Jul 2006)
New Revision: 9740

Added:
   trunk/apps/Thaw/src/thaw/plugins/queueWatcher/DragAndDropManager.java
Modified:
   trunk/apps/Thaw/src/thaw/core/FileChooser.java
   trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java
   trunk/apps/Thaw/src/thaw/fcp/FCPMessage.java
   trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
   trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java
   trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
Log:
Drag and drop : Doesn't work under Linux, maybe Windows ?

Modified: trunk/apps/Thaw/src/thaw/core/FileChooser.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/FileChooser.java      2006-07-23 19:38:44 UTC 
(rev 9739)
+++ trunk/apps/Thaw/src/thaw/core/FileChooser.java      2006-07-23 21:18:05 UTC 
(rev 9740)
@@ -17,6 +17,7 @@

        public FileChooser(String path) {
                fileChooser = new JFileChooser(path);
+               fileChooser.setDragEnabled(true);
        }

        public void setTitle(String title) {

Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java      2006-07-23 19:38:44 UTC 
(rev 9739)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java      2006-07-23 21:18:05 UTC 
(rev 9740)
@@ -600,10 +600,15 @@
                FCPMessage stopMessage = new FCPMessage();

                if(!isPersistent()) {
-                       Logger.info(this, "Can't remove non persistent 
request.");
+                       Logger.notice(this, "Can't remove non persistent 
request.");
                        return false;
                }

+               if(identifier == null) {
+                       Logger.notice(this, "Can't remove non-started queries");
+                       return true;
+               }
+
                stopMessage.setMessageName("RemovePersistentRequest");

                if(globalQueue)

Modified: trunk/apps/Thaw/src/thaw/fcp/FCPMessage.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPMessage.java        2006-07-23 19:38:44 UTC 
(rev 9739)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPMessage.java        2006-07-23 21:18:05 UTC 
(rev 9740)
@@ -98,6 +98,11 @@
                        setAmountOfDataWaiting((new Long(value)).longValue());
                }

+               if(value == null) {
+                       fields.remove(field);
+                       return;
+               }
+
                fields.put(field, value);
        }


Modified: trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties    2006-07-23 19:38:44 UTC 
(rev 9739)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties    2006-07-23 21:18:05 UTC 
(rev 9740)
@@ -102,7 +102,7 @@
 thaw.plugin.insert.specifyNameAndRev=Please specify a name and a revision
 thaw.plugin.insert.specifyFile=Please specify a file

-thaw.plugin.priority.p0=Urgence (pas pour un usage normal)
+thaw.plugin.priority.p0=Urgence (*pas* pour un usage normal)
 thaw.plugin.priority.p1=Tr?s haute
 thaw.plugin.priority.p2=Haute
 thaw.plugin.priority.p3=Moyenne (recommand?)
@@ -111,7 +111,7 @@
 thaw.plugin.priority.p6=Ne finira jamais

 thaw.plugin.fetch.keyList=Liste de cl?s (une cl? par ligne)
-thaw.plugin.fetch.loadKeyListFromFile=Charger les cl?s d'un fichier ...
+thaw.plugin.fetch.loadKeyListFromFile=Charger les cl?s depuis un fichier ...
 thaw.plugin.fetch.destinationDirectory=R?pertoire de destination
 thaw.plugin.fetch.chooseDestination=Choisir la destination ...
 thaw.plugin.fetch.pasteFromClipboard=Coller depuis le presse-papier

Modified: trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java  2006-07-23 19:38:44 UTC 
(rev 9739)
+++ trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java  2006-07-23 21:18:05 UTC 
(rev 9740)
@@ -28,6 +28,8 @@

        private QueuePanel[] queuePanels = new QueuePanel[2];
        private DetailPanel detailPanel;
+       private DragAndDropManager dnd;
+
        private JPanel panel;

        private final static int DIVIDER_LOCATION = 310;
@@ -95,6 +97,7 @@
                    return false;
                }

+               dnd = new DragAndDropManager(core, queuePanels);

                return true;
        }

Added: trunk/apps/Thaw/src/thaw/plugins/queueWatcher/DragAndDropManager.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/queueWatcher/DragAndDropManager.java       
2006-07-23 19:38:44 UTC (rev 9739)
+++ trunk/apps/Thaw/src/thaw/plugins/queueWatcher/DragAndDropManager.java       
2006-07-23 21:18:05 UTC (rev 9740)
@@ -0,0 +1,185 @@
+package thaw.plugins.queueWatcher;
+
+import java.awt.dnd.DragSource;
+import java.awt.dnd.DragGestureListener;
+import java.awt.dnd.DragGestureEvent;
+import java.awt.dnd.DnDConstants;
+import java.awt.datatransfer.Transferable;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.dnd.DragSourceListener;
+import java.awt.dnd.DragSourceDragEvent;
+import java.awt.dnd.DragSourceEvent;
+import java.awt.dnd.DragSourceDropEvent;
+import java.awt.dnd.DragSourceContext;
+import javax.swing.TransferHandler;
+
+import java.awt.Component;
+
+import java.util.Vector;
+import java.util.Iterator;
+import java.io.File;
+
+import thaw.core.*;
+import thaw.plugins.QueueWatcher;
+import thaw.fcp.*;
+import thaw.i18n.I18n;
+
+
+public class DragAndDropManager implements DragGestureListener, 
DragSourceListener {
+
+       private Core core;
+       private QueuePanel[] queuePanels;
+
+       private DragSource dragSource;
+       private DragGestureListener dgListener;
+
+       private String tmpDir = System.getProperty("java.io.tmpdir");
+
+       public DragAndDropManager(Core core, QueuePanel[] queuePanels) {
+               this.core = core;
+               this.queuePanels = queuePanels;
+
+               dragSource = DragSource.getDefaultDragSource();
+
+               for(int i = 0 ; i < queuePanels.length ; i++) {
+                       
this.dragSource.createDefaultDragGestureRecognizer(queuePanels[i].getTable(),
+                                                                          
DnDConstants.ACTION_COPY_OR_MOVE,
+                                                                          
this);
+                       queuePanels[i].getTable().setDragEnabled(true);
+               }
+
+       }
+
+
+       public void dragGestureRecognized(DragGestureEvent dge) {
+               try {
+                       Transferable transferable;
+
+                       transferable = getTransferableFor(dge.getComponent());
+
+                       dge.startDrag(DragSource.DefaultCopyDrop, transferable);
+
+
+               } catch(java.awt.dnd.InvalidDnDOperationException e) {
+                       Logger.warning(this, "InvalideDnDOperation !");
+               }
+       }
+
+
+       
+       private class DragableFinishedDownloads implements Transferable{
+               public final DataFlavor[] FLAVORS = {
+                       DataFlavor.javaFileListFlavor,
+                       DataFlavor.stringFlavor,
+               };
+
+               private Vector queries; /* FCPTransferQuery */
+
+
+               public DragableFinishedDownloads(Vector queries) {
+                       if(queries == null || queries.size() <= 0) {
+                               Logger.warning(this, "Selection null ?!");
+                       }
+
+                       this.queries = queries;
+               }
+               
+
+               private Vector getQueries() {
+                       return queries;
+               }
+
+               public Object getTransferData(DataFlavor flavor) {
+                       if(flavor == DataFlavor.javaFileListFlavor
+                          || flavor.equals(DataFlavor.javaFileListFlavor) ) {
+                               Vector fileList = new Vector();
+
+                               for(Iterator queryIt = queries.iterator();
+                                   queryIt.hasNext();) {
+                                       FCPTransferQuery query = 
(FCPTransferQuery)queryIt.next();
+
+                                       if(!query.isFinished() || 
!query.isSuccessful())
+                                               continue;
+
+                                       if(query.getPath() == null) // We need 
a path !
+                                               query.saveFileTo(tmpDir);
+
+                                       fileList.add(new File(query.getPath()));
+                               }
+
+
+                               return fileList;
+                       }
+
+                       if(flavor == DataFlavor.stringFlavor
+                          || flavor.equals(DataFlavor.stringFlavor) ) {
+                               String result = "";
+
+                               for(Iterator queryIt = queries.iterator();
+                                   queryIt.hasNext();) {
+                                       FCPTransferQuery query = 
(FCPTransferQuery)queryIt.next();
+
+                                       if(!query.isFinished() || 
!query.isSuccessful())
+                                               continue;
+
+                                       if(query.getPath() == null) // We need 
a path !
+                                               continue;
+
+                                       result = result +query.getPath()+"\n";
+                               }
+
+                               return result;
+                       }
+
+                       return null;
+               }
+               
+               public DataFlavor[] getTransferDataFlavors() {
+                       return FLAVORS;
+               }
+
+               public boolean isDataFlavorSupported(DataFlavor flavor) {
+                       for(int i = 0 ; i < FLAVORS.length ; i++)
+                               if(FLAVORS[i] == flavor || 
FLAVORS[i].equals(flavor))
+                                       return true;
+
+                       return false;
+               }
+       }
+
+
+
+
+       private Transferable getTransferableFor(Component c) {
+               if(c == queuePanels[0].getTable()) {
+                       queuePanels[0].reloadSelections();
+                       return new 
DragableFinishedDownloads(queuePanels[0].getSelectedQueries());
+               }
+
+               return null;
+       }
+
+       public void dragEnter(DragSourceDragEvent e) {
+
+               DragSourceContext context = e.getDragSourceContext();
+               //intersection of the users selected action, and the source and 
target actions
+               int myaction = e.getDropAction();
+
+               if( (myaction & DnDConstants.ACTION_COPY) != 0) {
+                       context.setCursor(DragSource.DefaultCopyDrop);   
+               } else {
+                       context.setCursor(DragSource.DefaultCopyNoDrop);   
+               }
+    
+               
+       }
+
+       public void dragOver(DragSourceDragEvent e) { }
+       public void dragExit(DragSourceEvent e) { }
+
+       public void dragDropEnd(DragSourceDropEvent e) {
+       }
+
+       public void dropActionChanged (DragSourceDragEvent e) { }
+       
+}

Modified: trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java       
2006-07-23 19:38:44 UTC (rev 9739)
+++ trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java       
2006-07-23 21:18:05 UTC (rev 9740)
@@ -213,7 +213,30 @@
        }


+       public void reloadSelections() {
+               selectedRows = table.getSelectedRows();
+       }

+       /**
+        * return a vector made of FCPTransferQueries.
+        * Doesn't refresh the selection !
+        */
+       public Vector getSelectedQueries() {
+               Vector queries = new Vector();
+               Vector initialQueries = tableModel.getQueries();
+
+               if(selectedRows == null)
+                       return queries;
+
+               /* Create a separate vector to avoid collisions */
+               for(int i = 0 ; i < selectedRows.length; i++) {
+                       queries.add(initialQueries.get(selectedRows[i]));
+               }
+               
+               return queries;
+       }
+
+
        public void resetTable() {
                tableModel.resetTable();
        }
@@ -266,6 +289,11 @@
        }


+       public JTable getTable() {
+               return table;
+       }
+
+
        private class ActionReplier implements Runnable, ClipboardOwner {
                ActionEvent e;
                Vector queries;
@@ -356,21 +384,14 @@
         * Manage it on a different thread to avoid UI freeze.
         */
        public void actionPerformed(ActionEvent e) {
-               Vector queries = new Vector();
-               Vector initialQueries = tableModel.getQueries();
+               Thread action = new Thread(new ActionReplier(e, 
getSelectedQueries()));

-               /* Create a separate vector to avoid collisions */
-               for(int i = 0 ; i < selectedRows.length; i++) {
-                       queries.add(initialQueries.get(selectedRows[i]));
-               }
-
-               Thread action = new Thread(new ActionReplier(e, queries));
                action.start();
        }

        public void mouseClicked(MouseEvent e) {
                if(e.getButton() == MouseEvent.BUTTON3) {
-                       selectedRows = table.getSelectedRows();
+                       reloadSelections();
                        queries = tableModel.getQueries();
                        rightClickMenu.show(e.getComponent(), e.getX(), 
e.getY());
                }


Reply via email to