/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
- * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
+ * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
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.*;
new SplashScreen();
discoverer = new jalview.ws.Discoverer(); // Only gets started if gui is
- // displayed.
+ // displayed.
}
private void doVamsasClientCheck()
* DOCUMENT ME!
*
* @param frame
- * DOCUMENT ME!
+ * DOCUMENT ME!
* @param title
- * DOCUMENT ME!
+ * DOCUMENT ME!
* @param w
- * DOCUMENT ME!
+ * DOCUMENT ME!
* @param h
- * DOCUMENT ME!
+ * DOCUMENT ME!
*/
public static synchronized void addInternalFrame(
final JInternalFrame frame, String title, int w, int h)
* DOCUMENT ME!
*
* @param frame
- * DOCUMENT ME!
+ * DOCUMENT ME!
* @param title
- * DOCUMENT ME!
+ * DOCUMENT ME!
* @param w
- * DOCUMENT ME!
+ * DOCUMENT ME!
* @param h
- * DOCUMENT ME!
+ * DOCUMENT ME!
* @param resizable
- * DOCUMENT ME!
+ * DOCUMENT ME!
*/
public static synchronized void addInternalFrame(
final JInternalFrame frame, String title, int w, int h,
* DOCUMENT ME!
*
* @param evt
- * DOCUMENT ME!
+ * DOCUMENT ME!
*/
public void drop(DropTargetDropEvent evt)
{
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"))
* DOCUMENT ME!
*
* @param e
- * DOCUMENT ME!
+ * DOCUMENT ME!
*/
public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
{
* DOCUMENT ME!
*
* @param e
- * DOCUMENT ME!
+ * DOCUMENT ME!
*/
public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
{
* DOCUMENT ME!
*
* @param e
- * DOCUMENT ME!
+ * DOCUMENT ME!
*/
public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
{
* DOCUMENT ME!
*
* @param e
- * DOCUMENT ME!
+ * DOCUMENT ME!
*/
public void aboutMenuItem_actionPerformed(ActionEvent e)
{
+ "\nDevelopment managed by The Barton Group, University of Dundee, Scotland, UK.\n"
+ "\nFor help, see the FAQ at www.jalview.org and/or join the jalview-discuss@jalview.org mailing list\n"
+ "\nIf you use Jalview, please cite:"
- + "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\""
- + "\nBioinformatics, 2004 20;426-7.");
-
+ + "\nWaterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)"
+ + "\nJalview Version 2 - a multiple sequence alignment editor and analysis workbench"
+ + "\nBioinformatics doi: 10.1093/bioinformatics/btp033");
JOptionPane.showInternalMessageDialog(Desktop.desktop,
message.toString(), "About Jalview", JOptionPane.INFORMATION_MESSAGE);
* DOCUMENT ME!
*
* @param e
- * DOCUMENT ME!
+ * DOCUMENT ME!
*/
public void documentationMenuItem_actionPerformed(ActionEvent e)
{
}
}
System.out.println("ALL CLOSED");
+ if (v_client != null)
+ {
+ // TODO clear binding to vamsas document objects on close_all
+ }
}
public void raiseRelated_actionPerformed(ActionEvent e)
/*
* (non-Javadoc)
*
- * @see jalview.jbgui.GDesktop#garbageCollect_actionPerformed(java.awt.event.ActionEvent)
+ * @seejalview.jbgui.GDesktop#garbageCollect_actionPerformed(java.awt.event.
+ * ActionEvent)
*/
protected void garbageCollect_actionPerformed(ActionEvent e)
{
/*
* (non-Javadoc)
*
- * @see jalview.jbgui.GDesktop#showMemusage_actionPerformed(java.awt.event.ActionEvent)
+ * @see
+ * jalview.jbgui.GDesktop#showMemusage_actionPerformed(java.awt.event.ActionEvent
+ * )
*/
protected void showMemusage_actionPerformed(ActionEvent e)
{
* DOCUMENT ME!
*
* @param e
- * DOCUMENT ME!
+ * DOCUMENT ME!
*/
protected void preferences_actionPerformed(ActionEvent e)
{
* DOCUMENT ME!
*
* @param e
- * DOCUMENT ME!
+ * DOCUMENT ME!
*/
public void saveState_actionPerformed(ActionEvent e)
{
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);
+
}
}
* DOCUMENT ME!
*
* @param e
- * DOCUMENT ME!
+ * DOCUMENT ME!
*/
public void loadState_actionPerformed(ActionEvent e)
{
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 int getViewCount(String viewId)
{
+ AlignViewport[] aps = getViewports(viewId);
+ return (aps == null) ? 0 : aps.length;
+ }
+
+ /**
+ *
+ * @param viewId
+ * @return all AlignmentPanels concerning the viewId sequence set
+ */
+ 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++)
{
if (frames[t] instanceof AlignFrame)
.equals(((AlignmentPanel) af.alignPanels.elementAt(a)).av
.getSequenceSetId()))
{
- count++;
+ aps.add(af.alignPanels.elementAt(a));
}
}
}
}
+ if (aps.size() == 0)
+ {
+ return null;
+ }
+ AlignmentPanel[] vap = new AlignmentPanel[aps.size()];
+ for (int t = 0; t < vap.length; t++)
+ {
+ vap[t] = (AlignmentPanel) aps.get(t);
+ }
+ return vap;
+ }
+
+ /**
+ * get all the viewports on an alignment.
+ *
+ * @param sequenceSetId
+ * unique alignment id
+ * @return all viewports on the alignment bound to sequenceSetId
+ */
+ public static AlignViewport[] getViewports(String sequenceSetId)
+ {
+ Vector viewp = new Vector();
+ if (desktop != null)
+ {
+ javax.swing.JInternalFrame[] frames = instance.getAllFrames();
- return count;
+ for (int t = 0; t < frames.length; t++)
+ {
+ if (frames[t] instanceof AlignFrame)
+ {
+ AlignFrame afr = ((AlignFrame) frames[t]);
+ if (afr.getViewport().getSequenceSetId().equals(sequenceSetId))
+ {
+ if (afr.alignPanels != null)
+ {
+ for (int a = 0; a < afr.alignPanels.size(); a++)
+ {
+ if (sequenceSetId.equals(((AlignmentPanel) afr.alignPanels
+ .elementAt(a)).av.getSequenceSetId()))
+ {
+ viewp.addElement(((AlignmentPanel) afr.alignPanels
+ .elementAt(a)).av);
+ }
+ }
+ }
+ else
+ {
+ viewp.addElement(((AlignFrame) frames[t]).getViewport());
+ }
+ }
+ }
+ }
+ if (viewp.size() > 0)
+ {
+ AlignViewport[] vp = new AlignViewport[viewp.size()];
+ viewp.copyInto(vp);
+ return vp;
+ }
+ }
+ return null;
}
public void explodeViews(AlignFrame af)
if (value == JalviewFileChooser.APPROVE_OPTION)
{
- try
- {
- v_client = new jalview.gui.VamsasApplication(this, chooser
- .getSelectedFile());
- } catch (Exception ex)
+ String fle = chooser.getSelectedFile().toString();
+ if (!vamsasImport(chooser.getSelectedFile()))
{
- jalview.bin.Cache.log.error(
- "New vamsas session from existing session file failed:",
- ex);
- return;
+ JOptionPane.showInternalMessageDialog(Desktop.desktop,
+ "Couldn't import '" + fle + "' as a new vamsas session.",
+ "Vamsas Document Import Failed",
+ JOptionPane.ERROR_MESSAGE);
}
- setupVamsasConnectedGui();
- v_client.initial_update(); // TODO: thread ?
}
}
else
}
}
+ /**
+ * 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(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)
+ {
+
+ jalview.bin.Cache.log
+ .error("Implementation error - load session from a running session is not supported.");
+ return false;
+ }
+
+ setProgressBar("Importing VAMSAS session from "+file.getName(),file.hashCode());
+ try
+ {
+ 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 (v_client!=null)
+ {
+ throw new Error("Trying to join a vamsas session when another is already connected.");
+ }
+ if (mysesid==null)
+ {
+ throw new Error("Invalid vamsas session id.");
+ }
+ v_client = new VamsasApplication(this, mysesid);
+ setupVamsasConnectedGui();
+ v_client.initial_update();
+ return (v_client.inSession());
+ }
+
public void vamsasStart_actionPerformed(ActionEvent e)
{
if (v_client == null)
*
* if (value == JalviewFileChooser.APPROVE_OPTION) { v_client = new
* jalview.gui.VamsasApplication(this, chooser.getSelectedFile());
- *
*/
v_client = new VamsasApplication(this);
setupVamsasConnectedGui();
vamsasSave.setVisible(true);
vamsasStop.setVisible(true);
vamsasImport.setVisible(false); // Document import to existing session is
- // not possible for vamsas-client-1.0.
+ // not possible for vamsas-client-1.0.
}
protected void setupVamsasDisconnectedGui()
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,
* hide vamsas user gui bits when a vamsas document event is being handled.
*
* @param b
- * true to hide gui, false to reveal gui
+ * true to hide gui, false to reveal gui
*/
public void setVamsasUpdate(boolean b)
{
/**
* Progress bars managed by the IProgressIndicator method.
*/
- private Hashtable progressBars;
+ private Hashtable progressBars, progressBarHandlers;
/*
* (non-Javadoc)
if (progressBars == null)
{
progressBars = new Hashtable();
+ progressBarHandlers = new Hashtable();
}
if (progressBars.get(new Long(id)) != null)
{
JProgressBar progressPanel = (JProgressBar) progressBars
.remove(new Long(id));
+ if (progressBarHandlers.contains(new Long(id)))
+ {
+ progressBarHandlers.remove(new Long(id));
+ }
removeProgressPanel(progressPanel);
}
else
progressBars.put(new Long(id), addProgressPanel(message));
}
}
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.gui.IProgressIndicator#registerHandler(long,
+ * jalview.gui.IProgressIndicatorHandler)
+ */
+ public void registerHandler(final long id,
+ final IProgressIndicatorHandler handler)
+ {
+ if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
+ {
+ throw new Error(
+ "call setProgressBar before registering the progress bar's handler.");
+ }
+ progressBarHandlers.put(new Long(id), handler);
+ final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
+ if (handler.canCancel())
+ {
+ JButton cancel = new JButton("Cancel");
+ final IProgressIndicator us = this;
+ cancel.addActionListener(new ActionListener()
+ {
+
+ public void actionPerformed(ActionEvent e)
+ {
+ handler.cancelActivity(id);
+ us.setProgressBar("Cancelled "
+ + ((JLabel) progressPanel.getComponent(0)).getText(), id);
+ }
+ });
+ progressPanel.add(cancel, BorderLayout.EAST);
+ }
+ }
+
+ /**
+ * This will return the first AlignFrame viewing AlignViewport av. It will
+ * break if there are more than one AlignFrames viewing a particular av. This
+ *
+ * @param av
+ * @return alignFrame for av
+ */
+ public static AlignFrame getAlignFrameFor(AlignViewport av)
+ {
+ if (desktop != null)
+ {
+ AlignmentPanel[] aps = getAlignmentPanels(av.getSequenceSetId());
+ for (int panel = 0; aps != null && panel < aps.length; panel++)
+ {
+ if (aps[panel] != null && aps[panel].av == av)
+ {
+ return aps[panel].alignFrame;
+ }
+ }
+ }
+ return null;
+ }
+
+ public VamsasApplication getVamsasApplication()
+ {
+ return v_client;
+
+ }
}