Skip to content
Snippets Groups Projects
Commit 4787831e authored by tjc's avatar tjc
Browse files

file transfer monitor

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@3593 ee4ac58c-ac51-4696-9907-e4b3aa274f04
parent 0835bb3e
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@
package uk.ac.sanger.artemis.components.filetree;
import uk.ac.sanger.artemis.j2ssh.FileTransferProgressMonitor;
import uk.ac.sanger.artemis.j2ssh.SshFileManager;
import java.util.Vector;
import java.util.Collections;
......@@ -100,9 +101,9 @@ public class FileList
* Put a file
*
*/
protected boolean put(String dir, File local_file)
protected boolean put(String dir, File local_file, FileTransferProgressMonitor monitor)
{
return ssh_client.put(dir, local_file);
return ssh_client.put(dir, local_file, monitor);
}
......@@ -111,9 +112,9 @@ public class FileList
* Get the file contents
*
*/
protected byte[] getFileContents(String file)
protected byte[] getFileContents(String file, FileTransferProgressMonitor monitor)
{
return ssh_client.getFileContents(file);
return ssh_client.getFileContents(file, monitor);
}
......
......@@ -34,6 +34,7 @@ import uk.ac.sanger.artemis.util.FileDocument;
import uk.ac.sanger.artemis.util.OutOfRangeException;
import uk.ac.sanger.artemis.sequence.NoSequenceException;
import uk.ac.sanger.artemis.components.MessageDialog;
import uk.ac.sanger.artemis.j2ssh.FileTransferProgressMonitor;
import java.awt.*;
import java.awt.event.*;
......@@ -827,10 +828,10 @@ public class FileTree extends JTree implements DragGestureListener,
e.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
}
public void drop(DropTargetDropEvent e)
public void drop(final DropTargetDropEvent e)
{
Transferable t = e.getTransferable();
final Transferable t = e.getTransferable();
final FileNode dropNode = getSelectedNode();
if(dropNode == null)
{
......@@ -860,6 +861,11 @@ public class FileTree extends JTree implements DragGestureListener,
}
else if(t.isDataFlavorSupported(RemoteFileNode.REMOTEFILENODE))
{
SwingWorker getFileWorker = new SwingWorker()
{
public Object construct()
{
try
{
final RemoteFileNode fn =
......@@ -879,9 +885,8 @@ public class FileTree extends JTree implements DragGestureListener,
}
try
{
setCursor(cbusy);
final byte[] contents = fn.getFileContents();
final byte[] contents = fn.getFileContents(
new FileTransferProgressMonitor(FileTree.this, fn.getFile()));
final String ndropDir = dropDir;
Runnable updateTheTree = new Runnable()
{
......@@ -892,12 +897,9 @@ public class FileTree extends JTree implements DragGestureListener,
};
};
SwingUtilities.invokeLater(updateTheTree);
setCursor(cdone);
}
catch (Exception exp)
{
setCursor(cdone);
System.out.println("FileTree: caught exception");
}
e.getDropTargetContext().dropComplete(true);
......@@ -905,9 +907,14 @@ public class FileTree extends JTree implements DragGestureListener,
catch (Exception exp)
{
e.rejectDrop();
return;
}
return null;
}
};
getFileWorker.start();
}
else
{
......
......@@ -21,6 +21,7 @@
package uk.ac.sanger.artemis.components.filetree;
import uk.ac.sanger.artemis.j2ssh.FileTransferProgressMonitor;
import java.awt.datatransfer.*;
import javax.swing.tree.*;
import java.io.*;
......@@ -208,7 +209,7 @@ public class RemoteFileNode extends DefaultMutableTreeNode
return flist.rename(getRootDir()+"/"+getFullName(), new_file);
}
protected boolean put(File local_file)
protected boolean put(File local_file, FileTransferProgressMonitor monitor)
{
FileList flist = new FileList();
final String dir;
......@@ -217,14 +218,14 @@ public class RemoteFileNode extends DefaultMutableTreeNode
else
dir = getRootDir()+"/"+getFullName();
return flist.put(dir, local_file);
return flist.put(dir, local_file, monitor);
}
public byte[] getFileContents()
public byte[] getFileContents(FileTransferProgressMonitor monitor)
{
FileList flist = new FileList();
return flist.getFileContents(getRootDir()+"/"+getFullName());
return flist.getFileContents(getRootDir()+"/"+getFullName(), monitor);
}
// Transferable
......
......@@ -31,6 +31,7 @@ import uk.ac.sanger.artemis.util.RemoteFileDocument;
import uk.ac.sanger.artemis.util.OutOfRangeException;
import uk.ac.sanger.artemis.sequence.NoSequenceException;
import uk.ac.sanger.artemis.components.MessageDialog;
import uk.ac.sanger.artemis.j2ssh.FileTransferProgressMonitor;
import java.awt.*;
import java.awt.event.*;
......@@ -192,7 +193,6 @@ public class SshFileTree extends JTree implements DragGestureListener,
*/
public void actionPerformed(ActionEvent e)
{
JMenuItem source = (JMenuItem)(e.getSource());
final RemoteFileNode node = getSelectedNode();
if(node == null)
......@@ -214,7 +214,9 @@ public class SshFileTree extends JTree implements DragGestureListener,
}
else if(source.getText().equals("Jemboss Aligmnment Editor"))
{
final byte[] contents = node.getFileContents();
FileTransferProgressMonitor monitor =
new FileTransferProgressMonitor(SshFileTree.this, node.getFile());
final byte[] contents = node.getFileContents(monitor);
org.emboss.jemboss.editor.AlignJFrame ajFrame =
new org.emboss.jemboss.editor.AlignJFrame(new String(contents), fn);
ajFrame.setVisible(true);
......@@ -747,9 +749,9 @@ public class SshFileTree extends JTree implements DragGestureListener,
e.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
}
public void drop(DropTargetDropEvent e)
public void drop(final DropTargetDropEvent e)
{
Transferable t = e.getTransferable();
final Transferable t = e.getTransferable();
if(t.isDataFlavorSupported(RemoteFileNode.REMOTEFILENODE))
{
......@@ -796,6 +798,11 @@ public class SshFileTree extends JTree implements DragGestureListener,
catch(Exception ex){}
}
else if(t.isDataFlavorSupported(FileNode.FILENODE))
{
//put this in separate thread for progress bar
SwingWorker putWorker = new SwingWorker()
{
public Object construct()
{
try
{
......@@ -804,7 +811,7 @@ public class SshFileTree extends JTree implements DragGestureListener,
if (dropPath != null)
{
FileNode fn = (FileNode)t.getTransferData(FileNode.FILENODE);
File lfn = fn.getFile();
final File lfn = fn.getFile();
RemoteFileNode pn = (RemoteFileNode)dropPath.getLastPathComponent();
if(!pn.isDirectory())
......@@ -818,7 +825,8 @@ public class SshFileTree extends JTree implements DragGestureListener,
if(!nodeExists(pn,serverName))
{
pn.put(lfn);
pn.put(lfn, new FileTransferProgressMonitor(SshFileTree.this,
lfn.getName()));
try
{
//add file to remote file tree
......@@ -835,22 +843,21 @@ public class SshFileTree extends JTree implements DragGestureListener,
scrollPathToVisible(new TreePath(childNode.getPath()));
}
}
catch (Exception exp)
{
setCursor(cdone);
}
catch (Exception exp) {}
}
else
e.rejectDrop();
}
}
catch (Exception ex)
{
catch (Exception ex) {}
return null;
}
};
putWorker.start();
}
else
e.rejectDrop();
}
/**
......
/* FileTransferProgressMonitor.java
*
* created: Aug 2005
*
* This file is part of Artemis
*
* Copyright(C) 2005 Genome Research Limited
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or(at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
**/
package uk.ac.sanger.artemis.j2ssh;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import java.awt.Component;
import java.awt.Point;
import com.sshtools.j2ssh.FileTransferProgress;
import uk.ac.sanger.artemis.components.SwingWorker;
public class FileTransferProgressMonitor
implements FileTransferProgress
{
private JProgressBar progress;
private JFrame progressFrame;
private long bytesTotal;
private String filename;
public FileTransferProgressMonitor(Component parent, final String filename)
{
this.filename = filename;
if(filename.length() > 25)
this.filename = filename.substring(0,25)+"...";
progress = new JProgressBar();
progress.setStringPainted(true);
progress.setString(" "+filename+" 0 % ");
progressFrame = new JFrame("Transfer");
progressFrame.getContentPane().add(progress);
progressFrame.pack();
if(parent != null)
{
Point loc = parent.getLocationOnScreen();
loc.x+=100;
loc.y+=100;
progressFrame.setLocation(loc);
}
progressFrame.setVisible(true);
}
public void completed()
{
progressFrame.setVisible(false);
progressFrame.dispose();
}
public boolean isCancelled()
{
return false;
}
public void progressed(long bytesSoFar)
{
progress.setValue((new Long(bytesSoFar)).intValue());
int percent = (int)((bytesSoFar*100)/bytesTotal);
progress.setString(filename+" "+percent+" %");
}
public void started(final long bytesTotal, final String remoteFile)
{
this.bytesTotal = bytesTotal;
progress.setMinimum(0);
progress.setMaximum((new Long(bytesTotal)).intValue());
}
}
......@@ -24,6 +24,7 @@
package uk.ac.sanger.artemis.j2ssh;
import uk.ac.sanger.artemis.components.SwingWorker;
import javax.swing.JOptionPane;
import javax.swing.JFileChooser;
......@@ -211,7 +212,8 @@ public class SshFileManager
* @param local_file file to copy to the server
*
*/
public boolean put(String dir, File local_file)
public boolean put(final String dir, final File local_file,
final FileTransferProgressMonitor monitor)
{
SftpClient sftp = null;
......@@ -247,11 +249,12 @@ public class SshFileManager
if(sftp == null)
return false;
try
{
sftp.put(local_file.getCanonicalPath(),
dir+"/"+local_file.getName());
// sftp.quit();
dir+"/"+local_file.getName(), monitor);
return true;
}
catch(IOException ioe)
{
......@@ -259,25 +262,54 @@ public class SshFileManager
ioe.printStackTrace();
return false;
}
}
return true;
private boolean putTransfer(final SftpClient sftp,
final String dir, final File local_file)
{
SwingWorker progressWorker = new SwingWorker()
{
public Object construct()
{
try
{
FileTransferProgressMonitor progress =
new FileTransferProgressMonitor(null, local_file.getName());
sftp.put(local_file.getCanonicalPath(),
dir+"/"+local_file.getName(), progress);
return new Boolean(true);
}
catch(IOException ioe)
{
rescue();
ioe.printStackTrace();
return new Boolean(false);
}
}
};
progressWorker.start();
return true;
// return ((Boolean)progressWorker.get()).booleanValue();
}
/**
*
* Return the file contents as a byte array
*
*/
public byte[] getFileContents(String file)
public byte[] getFileContents(String file, final FileTransferProgressMonitor monitor)
{
try
{
SftpClient sftp = getSftpClient();
ByteArrayOutputStream os = new ByteArrayOutputStream();
sftp.get(file, os);
sftp.get(file, os, monitor);
// sftp.quit();
return os.toByteArray();
}
......
......@@ -27,6 +27,7 @@ package uk.ac.sanger.artemis.util;
import java.io.*;
import javax.swing.JOptionPane;
import uk.ac.sanger.artemis.components.filetree.*;
import uk.ac.sanger.artemis.j2ssh.FileTransferProgressMonitor;
/**
* Objects of this class are Documents created from a file.
......@@ -106,7 +107,9 @@ public class RemoteFileDocument extends Document
throws IOException
{
final RemoteFileNode node = getRemoteFileNode();
final byte[] bytes = node.getFileContents();
FileTransferProgressMonitor monitor = new FileTransferProgressMonitor(null, node.getFile());
final byte[] bytes = node.getFileContents(monitor);
final InputStream file_input_stream =
new ProgressInputStream(new ByteArrayInputStream(bytes),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment