import java.awt.datatransfer.*;
import java.awt.dnd.*;
import java.awt.event.*;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
import java.lang.reflect.Constructor;
+import java.net.URL;
+import java.net.URLConnection;
+import java.nio.channels.ReadableByteChannel;
import java.util.*;
import javax.swing.*;
{
Transferable t = evt.getTransferable();
java.util.List files = null;
+ java.util.List protocols = null;
try
{
evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
String data = (String) t.getTransferData(uriListFlavor);
files = new java.util.ArrayList(1);
+ protocols = new java.util.ArrayList(1);
for (java.util.StringTokenizer st = new java.util.StringTokenizer(
data, "\r\n"); st.hasMoreTokens();)
{
// the line is a comment (as per the RFC 2483)
continue;
}
-
java.net.URI uri = new java.net.URI(s);
- java.io.File file = new java.io.File(uri);
- files.add(file);
+ if (uri.getScheme().toLowerCase().startsWith("http"))
+ {
+ protocols.add(FormatAdapter.URL);
+ files.add(uri.toString());
+ }
+ else
+ {
+ // otherwise preserve old behaviour: catch all for file objects
+ java.io.File file = new java.io.File(uri);
+ protocols.add(FormatAdapter.FILE);
+ files.add(file.toString());
+ }
}
}
} catch (Exception e)
for (int i = 0; i < files.size(); i++)
{
String file = files.get(i).toString();
- String protocol = FormatAdapter.FILE;
+ String protocol = (protocols==null) ? FormatAdapter.FILE : (String) protocols.get(i);
String format = null;
if (file.endsWith(".jar"))
if (value == JalviewFileChooser.APPROVE_OPTION)
{
java.io.File choice = chooser.getSelectedFile();
+ JProgressBar progpanel = addProgressPanel("Saving jalview project "+choice.getName());
jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
+ // TODO catch and handle errors for savestate
new Jalview2XML().SaveState(choice);
+ removeProgressPanel(progpanel);
+
}
}
if (value == JalviewFileChooser.APPROVE_OPTION)
{
String choice = chooser.getSelectedFile().getAbsolutePath();
+ setProgressBar("loading jalview project "+chooser.getSelectedFile().getName(),choice.hashCode());
jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
.getSelectedFile().getParent());
new Jalview2XML().LoadJalviewAlign(choice);
+ setProgressBar(null,choice.hashCode());
}
}
public static AlignmentPanel[] getAlignmentPanels(String viewId)
{
int count = 0;
+ if (Desktop.desktop==null)
+ {
+ // no frames created and in headless mode
+ // TODO: verify that frames are recoverable when in headless mode
+ return null;
+ }
JInternalFrame[] frames = Desktop.desktop.getAllFrames();
ArrayList aps = new ArrayList();
for (int t = 0; t < frames.length; t++)
* @param file
* @return true if import was a success and a session was started.
*/
+ public boolean vamsasImport(URL url)
+ {
+ // TODO: create progress bar
+ if (v_client != null)
+ {
+
+ jalview.bin.Cache.log
+ .error("Implementation error - load session from a running session is not supported.");
+ return false;
+ }
+
+ try
+ {
+ // copy the URL content to a temporary local file
+ // TODO: be a bit cleverer here with nio (?!)
+ File file = File.createTempFile("vdocfromurl", ".vdj");
+ FileOutputStream fos = new FileOutputStream(file);
+ BufferedInputStream bis = new BufferedInputStream(url.openStream());
+ byte[] buffer = new byte[2048];
+ int ln;
+ while ((ln = bis.read(buffer))>-1)
+ {
+ fos.write(buffer,0,ln);
+ }
+ bis.close();
+ fos.close();
+ v_client = new jalview.gui.VamsasApplication(this, file, url.toExternalForm());
+ } catch (Exception ex)
+ {
+ jalview.bin.Cache.log.error(
+ "Failed to create new vamsas session from contents of URL "+url,ex);
+ return false;
+ }
+ setupVamsasConnectedGui();
+ v_client.initial_update(); // TODO: thread ?
+ return v_client.inSession();
+ }
+
+ /**
+ * import file into a new vamsas session (uses jalview.gui.VamsasApplication)
+ * @param file
+ * @return true if import was a success and a session was started.
+ */
public boolean vamsasImport(File file)
{
if (v_client != null)
return false;
}
+ setProgressBar("Importing VAMSAS session from "+file.getName(),file.hashCode());
try
{
- v_client = new jalview.gui.VamsasApplication(this, file);
+ v_client = new jalview.gui.VamsasApplication(this, file,null);
} catch (Exception ex)
{
+ setProgressBar("Importing VAMSAS session from "+file.getName(),file.hashCode());
jalview.bin.Cache.log.error(
"New vamsas session from existing session file failed:", ex);
return false;
}
setupVamsasConnectedGui();
v_client.initial_update(); // TODO: thread ?
+ setProgressBar("Importing VAMSAS session from "+file.getName(),file.hashCode());
return v_client.inSession();
}
public boolean joinVamsasSession(String mysesid) {
if (value == JalviewFileChooser.APPROVE_OPTION)
{
java.io.File choice = chooser.getSelectedFile();
+ JProgressBar progpanel = addProgressPanel("Saving VAMSAS Document to "+choice.getName());
jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
String warnmsg = null;
String warnttl = null;
+ choice, ex);
}
+ removeProgressPanel(progpanel);
if (warnmsg != null)
{
JOptionPane.showInternalMessageDialog(Desktop.desktop,