command line hook for questionnaire url argument.
[jalview.git] / src / jalview / gui / Desktop.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer
3  * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18  */
19 package jalview.gui;
20
21 import jalview.io.*;
22 import java.awt.*;
23 import java.awt.datatransfer.*;
24 import java.awt.dnd.*;
25 import java.awt.event.*;
26 import java.util.*;
27
28 import javax.swing.*;
29
30
31 /**
32  * DOCUMENT ME!
33  *
34  * @author $author$
35  * @version $Revision$
36  */
37 public class Desktop extends jalview.jbgui.GDesktop
38     implements DropTargetListener, ClipboardOwner
39 {
40     /** DOCUMENT ME!! */
41     public static Desktop instance;
42     public static JDesktopPane desktop;
43     static int openFrameCount = 0;
44     static final int xOffset = 30;
45     static final int yOffset = 30;
46     public static jalview.ws.Discoverer discoverer;
47
48     public static Object [] jalviewClipboard;
49     public static boolean internalCopy = false;
50
51     static int fileLoadingCount= 0;
52
53     /**
54      * Creates a new Desktop object.
55      */
56     public Desktop()
57     {
58         instance = this;
59         doVamsasClientCheck();
60         Image image = null;
61
62         try
63         {
64             java.net.URL url = getClass().getResource("/images/logo.gif");
65
66             if (url != null)
67             {
68                 image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
69
70                 MediaTracker mt = new MediaTracker(this);
71                 mt.addImage(image, 0);
72                 mt.waitForID(0);
73                 setIconImage(image);
74             }
75         }
76         catch (Exception ex)
77         {
78         }
79
80         setTitle("Jalview "+jalview.bin.Cache.getProperty("VERSION"));
81         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
82         desktop = new JDesktopPane();
83         desktop.setBackground(Color.white);
84         getContentPane().setLayout(new BorderLayout());
85         getContentPane().add(desktop, BorderLayout.CENTER);
86         desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
87
88         // This line prevents Windows Look&Feel resizing all new windows to maximum
89         // if previous window was maximised
90         desktop.setDesktopManager(new DefaultDesktopManager());
91
92         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
93         String x = jalview.bin.Cache.getProperty("SCREEN_X");
94         String y = jalview.bin.Cache.getProperty("SCREEN_Y");
95         String width = jalview.bin.Cache.getProperty("SCREEN_WIDTH");
96         String height = jalview.bin.Cache.getProperty("SCREEN_HEIGHT");
97
98         if ((x != null) && (y != null) && (width != null) && (height != null))
99         {
100             setBounds(Integer.parseInt(x), Integer.parseInt(y),
101                 Integer.parseInt(width), Integer.parseInt(height));
102         }
103         else
104         {
105             setBounds((int) (screenSize.width - 900) / 2,
106                 (int) (screenSize.height - 650) / 2, 900, 650);
107         }
108
109         this.addWindowListener(new WindowAdapter()
110             {
111                 public void windowClosing(WindowEvent evt)
112                 {
113                     quit();
114                 }
115             });
116
117         this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
118
119         /////////Add a splashscreen on startup
120         /////////Add a splashscreen on startup
121         JInternalFrame frame = new JInternalFrame();
122
123         SplashScreen splash = new SplashScreen(frame, image);
124         frame.setContentPane(splash);
125         frame.setLayer(JLayeredPane.PALETTE_LAYER);
126         frame.setLocation((int) ((getWidth() - 750) / 2),
127             (int) ((getHeight() - 160) / 2));
128
129         addInternalFrame(frame, "", 750, 160, false);
130
131         discoverer=new jalview.ws.Discoverer(); // Only gets started if gui is displayed.
132     }
133
134     private void doVamsasClientCheck() {
135       if (jalview.bin.Cache.vamsasJarsPresent()) {
136         VamsasMenu.setVisible(true);
137         vamsasLoad.setVisible(true);
138       }
139
140     }
141
142     /**
143      * DOCUMENT ME!
144      *
145      * @param frame DOCUMENT ME!
146      * @param title DOCUMENT ME!
147      * @param w DOCUMENT ME!
148      * @param h DOCUMENT ME!
149      */
150     public static synchronized void addInternalFrame(final JInternalFrame frame,
151         String title, int w, int h)
152     {
153         addInternalFrame(frame, title, w, h, true);
154     }
155
156     /**
157      * DOCUMENT ME!
158      *
159      * @param frame DOCUMENT ME!
160      * @param title DOCUMENT ME!
161      * @param w DOCUMENT ME!
162      * @param h DOCUMENT ME!
163      * @param resizable DOCUMENT ME!
164      */
165     public static synchronized void addInternalFrame(final JInternalFrame frame,
166         String title, int w, int h, boolean resizable)
167     {
168
169       frame.setTitle(title);
170       if(frame.getWidth()<1 || frame.getHeight()<1)
171       {
172         frame.setSize(w, h);
173       }
174       // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
175       // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
176       // IF JALVIEW IS RUNNING HEADLESS
177       /////////////////////////////////////////////////
178       if (System.getProperty("java.awt.headless") != null
179           && System.getProperty("java.awt.headless").equals("true"))
180       {
181         return;
182       }
183
184
185         openFrameCount++;
186
187         frame.setVisible(true);
188         frame.setClosable(true);
189         frame.setResizable(resizable);
190         frame.setMaximizable(resizable);
191         frame.setIconifiable(resizable);
192         frame.setFrameIcon(null);
193
194         if (frame.getX()<1 && frame.getY()<1)
195        {
196          frame.setLocation(xOffset * openFrameCount, yOffset * ((openFrameCount-1)%10)+yOffset);
197        }
198
199         final JMenuItem menuItem = new JMenuItem(title);
200         frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
201             {
202               public void internalFrameActivated(javax.swing.event.
203                                                  InternalFrameEvent evt)
204               {
205                 JInternalFrame itf = desktop.getSelectedFrame();
206                 if (itf != null)
207                   itf.requestFocus();
208
209               }
210
211
212                 public void internalFrameClosed(
213                     javax.swing.event.InternalFrameEvent evt)
214                 {
215                     PaintRefresher.RemoveComponent(frame);
216                     openFrameCount--;
217                     windowMenu.remove(menuItem);
218                     JInternalFrame itf = desktop.getSelectedFrame();
219                        if (itf != null)
220                         itf.requestFocus();
221                 }
222                 ;
223             });
224
225         menuItem.addActionListener(new ActionListener()
226             {
227                 public void actionPerformed(ActionEvent e)
228                 {
229                     try
230                     {
231                         frame.setSelected(true);
232                         frame.setIcon(false);
233                     }
234                     catch (java.beans.PropertyVetoException ex)
235                     {
236
237                     }
238                 }
239             });
240
241         windowMenu.add(menuItem);
242
243         desktop.add(frame);
244         frame.toFront();
245         try{
246           frame.setSelected(true);
247           frame.requestFocus();
248         }catch(java.beans.PropertyVetoException ve)
249         {   }
250     }
251
252     public void lostOwnership(Clipboard clipboard, Transferable contents)
253     {
254       if (!internalCopy)
255         Desktop.jalviewClipboard = null;
256
257       internalCopy = false;
258     }
259
260     public void dragEnter(DropTargetDragEvent evt)
261     {}
262
263     public void dragExit(DropTargetEvent evt)
264     {}
265
266     public void dragOver(DropTargetDragEvent evt)
267     {}
268
269     public void dropActionChanged(DropTargetDragEvent evt)
270     {}
271
272     /**
273      * DOCUMENT ME!
274      *
275      * @param evt DOCUMENT ME!
276      */
277     public void drop(DropTargetDropEvent evt)
278     {
279         Transferable t = evt.getTransferable();
280         java.util.List files = null;
281
282         try
283         {
284           DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
285           if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
286           {
287             //Works on Windows and MacOSX
288             evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
289             files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
290           }
291           else if (t.isDataFlavorSupported(uriListFlavor))
292           {
293             // This is used by Unix drag system
294             evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
295             String data = (String) t.getTransferData(uriListFlavor);
296             files = new java.util.ArrayList(1);
297             for (java.util.StringTokenizer st = new java.util.StringTokenizer(
298                 data,
299                 "\r\n");
300                  st.hasMoreTokens(); )
301             {
302               String s = st.nextToken();
303               if (s.startsWith("#"))
304               {
305                 // the line is a comment (as per the RFC 2483)
306                 continue;
307               }
308
309               java.net.URI uri = new java.net.URI(s);
310               java.io.File file = new java.io.File(uri);
311               files.add(file);
312             }
313           }
314         }
315         catch (Exception e)
316         {      }
317
318         if (files != null)
319         {
320           try
321           {
322             for (int i = 0; i < files.size(); i++)
323             {
324               String file = files.get(i).toString();
325               String protocol = FormatAdapter.FILE;
326               String format = null;
327
328               if (file.endsWith(".jar"))
329               {
330                 format = "Jalview";
331
332               }
333               else
334               {
335                 format = new IdentifyFile().Identify(file,
336                                                           protocol);
337               }
338
339
340               new FileLoader().LoadFile(file, protocol, format);
341
342             }
343           }
344           catch (Exception ex)
345           {      }
346         }
347     }
348
349     /**
350      * DOCUMENT ME!
351      *
352      * @param e DOCUMENT ME!
353      */
354     public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
355     {
356         JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
357                     "LAST_DIRECTORY"),
358                 new String[]
359                 {
360                     "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
361                     "jar"
362                 },
363                 new String[]
364                 {
365                     "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"
366                 }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
367
368         chooser.setFileView(new JalviewFileView());
369         chooser.setDialogTitle("Open local file");
370         chooser.setToolTipText("Open");
371
372         int value = chooser.showOpenDialog(this);
373
374         if (value == JalviewFileChooser.APPROVE_OPTION)
375         {
376             String choice = chooser.getSelectedFile().getPath();
377             jalview.bin.Cache.setProperty("LAST_DIRECTORY",
378                 chooser.getSelectedFile().getParent());
379
380             String format = null;
381             if (chooser.getSelectedFormat().equals("Jalview"))
382             {
383                 format = "Jalview";
384             }
385             else
386             {
387                 format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
388             }
389
390             if (viewport != null)
391               new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format);
392             else
393               new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
394         }
395     }
396
397
398
399     /**
400      * DOCUMENT ME!
401      *
402      * @param e DOCUMENT ME!
403      */
404     public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
405     {
406       // This construct allows us to have a wider textfield
407       // for viewing
408       JLabel label = new JLabel("Enter URL of Input File");
409       final JComboBox history = new JComboBox();
410
411       JPanel panel = new JPanel(new GridLayout(2,1));
412       panel.add(label);
413       panel.add(history);
414       history.setPreferredSize(new Dimension(400,20));
415       history.setEditable(true);
416       history.addItem("http://www.");
417
418       String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
419
420       StringTokenizer st;
421
422       if (historyItems != null)
423       {
424         st = new StringTokenizer(historyItems, "\t");
425
426         while (st.hasMoreTokens())
427         {
428           history.addItem(st.nextElement());
429         }
430       }
431
432        int reply = JOptionPane.showInternalConfirmDialog(desktop,
433           panel, "Input Alignment From URL",
434           JOptionPane.OK_CANCEL_OPTION );
435
436
437         if (reply != JOptionPane.OK_OPTION )
438         {
439             return;
440         }
441
442         String url = history.getSelectedItem().toString();
443
444         if (url.toLowerCase().endsWith(".jar"))
445         {
446           if (viewport != null)
447             new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, "Jalview");
448           else
449             new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
450         }
451         else
452         {
453           String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
454
455           if (format.equals("URL NOT FOUND"))
456           {
457             JOptionPane.showInternalMessageDialog(Desktop.desktop,
458                                                   "Couldn't locate " + url,
459                                                   "URL not found",
460                                                   JOptionPane.WARNING_MESSAGE);
461
462             return;
463           }
464
465           if (viewport != null)
466             new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
467           else
468             new FileLoader().LoadFile(url, FormatAdapter.URL, format);
469         }
470     }
471
472     /**
473      * DOCUMENT ME!
474      *
475      * @param e DOCUMENT ME!
476      */
477     public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
478     {
479         CutAndPasteTransfer cap = new CutAndPasteTransfer();
480         cap.setForInput(viewport);
481         Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
482     }
483
484     /*
485      * Exit the program
486      */
487     public void quit()
488     {
489         jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + "");
490         jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + "");
491         jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
492         jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
493         System.exit(0);
494     }
495
496     /**
497      * DOCUMENT ME!
498      *
499      * @param e DOCUMENT ME!
500      */
501     public void aboutMenuItem_actionPerformed(ActionEvent e)
502     {
503       StringBuffer message = new StringBuffer("JalView version " +
504                                               jalview.bin.Cache.getProperty(
505           "VERSION") +
506                                               "; last updated: " +
507                                               jalview.bin.
508                                               Cache.getDefault("BUILD_DATE", "unknown"));
509
510       if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
511           jalview.bin.Cache.getProperty("VERSION")))
512       {
513         message.append("\n\n!! Jalview version "
514                        + jalview.bin.Cache.getProperty("LATEST_VERSION")
515                        + " is available for download from http://www.jalview.org !!\n");
516
517       }
518
519       message.append( "\nAuthors:  Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." +
520             "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." +
521             "\nFor all issues relating to Jalview, email help@jalview.org" +
522             "\n\nIf  you use JalView, please cite:" +
523             "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
524             "\nBioinformatics,  2004 20;426-7.");
525
526         JOptionPane.showInternalMessageDialog(Desktop.desktop,
527
528            message.toString(), "About Jalview",
529             JOptionPane.INFORMATION_MESSAGE);
530     }
531
532     /**
533      * DOCUMENT ME!
534      *
535      * @param e DOCUMENT ME!
536      */
537     public void documentationMenuItem_actionPerformed(ActionEvent e)
538     {
539         try
540         {
541             ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
542             java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
543             javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
544
545             javax.help.HelpBroker hb = hs.createHelpBroker();
546             hb.setCurrentID("home");
547             hb.setDisplayed(true);
548         }
549         catch (Exception ex)
550         {     }
551     }
552
553     public void closeAll_actionPerformed(ActionEvent e)
554     {
555       JInternalFrame [] frames = desktop.getAllFrames();
556       for(int i=0; i<frames.length; i++)
557       {
558         try{
559         frames[i].setClosed(true);
560       }catch(java.beans.PropertyVetoException ex){}
561       }
562     }
563
564     public void raiseRelated_actionPerformed(ActionEvent e)
565     {
566       reorderAssociatedWindows(false, false);
567     }
568
569     public void minimizeAssociated_actionPerformed(ActionEvent e)
570     {
571       reorderAssociatedWindows(true, false);
572     }
573
574     void closeAssociatedWindows()
575     {
576       reorderAssociatedWindows(false, true);
577     }
578
579     void reorderAssociatedWindows(boolean minimize, boolean close)
580     {
581       JInternalFrame[] frames = desktop.getAllFrames();
582       if (frames == null || frames.length<1)
583         return;
584
585       AlignViewport source = null, target = null;
586       if (frames[0] instanceof AlignFrame)
587         source = ( (AlignFrame) frames[0]).getCurrentView();
588       else if (frames[0] instanceof TreePanel)
589         source = ( (TreePanel) frames[0]).getViewPort();
590       else if (frames[0] instanceof PCAPanel)
591         source = ( (PCAPanel) frames[0]).av;
592       else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
593         source = ((PairwiseAlignPanel)frames[0].getContentPane()).av;
594
595
596       if (source != null)
597         for (int i = 0; i < frames.length; i++)
598         {
599           target = null;
600           if(frames[i]==null)
601           {
602             continue;
603           }
604           if (frames[i] instanceof AlignFrame)
605             target = ( (AlignFrame) frames[i]).getCurrentView();
606           else if (frames[i] instanceof TreePanel)
607             target = ( (TreePanel) frames[i]).getViewPort();
608           else if (frames[i] instanceof PCAPanel)
609             target = ( (PCAPanel) frames[i]).av;
610           else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
611             target = ( (PairwiseAlignPanel) frames[i].getContentPane()).av;
612
613           if (source == target)
614           {
615             try
616             {
617               if (close)
618                 frames[i].setClosed(true);
619               else
620               {
621                 frames[i].setIcon(minimize);
622                 if (!minimize)
623                 {
624                   frames[i].toFront();
625                 }
626               }
627
628             }
629             catch (java.beans.PropertyVetoException ex)
630             {       }
631           }
632         }
633     }
634
635
636
637     /**
638      * DOCUMENT ME!
639      *
640      * @param e DOCUMENT ME!
641      */
642     protected void preferences_actionPerformed(ActionEvent e)
643     {
644         new Preferences();
645     }
646
647     /**
648      * DOCUMENT ME!
649      *
650      * @param e DOCUMENT ME!
651      */
652     public void saveState_actionPerformed(ActionEvent e)
653     {
654         JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
655                     "LAST_DIRECTORY"), new String[] { "jar" },
656                 new String[] { "Jalview Project" }, "Jalview Project");
657
658         chooser.setFileView(new JalviewFileView());
659         chooser.setDialogTitle("Save State");
660
661         int value = chooser.showSaveDialog(this);
662
663         if (value == JalviewFileChooser.APPROVE_OPTION)
664         {
665             java.io.File choice = chooser.getSelectedFile();
666             jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
667             new Jalview2XML().SaveState(choice);
668         }
669     }
670
671     /**
672      * DOCUMENT ME!
673      *
674      * @param e DOCUMENT ME!
675      */
676     public void loadState_actionPerformed(ActionEvent e)
677     {
678         JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
679                     "LAST_DIRECTORY"), new String[] { "jar" },
680                 new String[] { "Jalview Project" }, "Jalview Project");
681         chooser.setFileView(new JalviewFileView());
682         chooser.setDialogTitle("Restore state");
683
684         int value = chooser.showOpenDialog(this);
685
686         if (value == JalviewFileChooser.APPROVE_OPTION)
687         {
688             String choice = chooser.getSelectedFile().getAbsolutePath();
689             jalview.bin.Cache.setProperty("LAST_DIRECTORY",
690                 chooser.getSelectedFile().getParent());
691             new Jalview2XML().LoadJalviewAlign(choice);
692         }
693     }
694
695   /*  public void vamsasLoad_actionPerformed(ActionEvent e)
696     {
697       JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
698           getProperty("LAST_DIRECTORY"));
699
700       chooser.setFileView(new JalviewFileView());
701       chooser.setDialogTitle("Load Vamsas file");
702       chooser.setToolTipText("Import");
703
704       int value = chooser.showOpenDialog(this);
705
706       if (value == JalviewFileChooser.APPROVE_OPTION)
707       {
708         jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(null);
709         vs.load(
710             chooser.getSelectedFile().getAbsolutePath()
711             );
712       }
713
714     }*/
715
716
717     public void inputSequence_actionPerformed(ActionEvent e)
718     {
719       new SequenceFetcher(null);
720     }
721
722     JPanel progressPanel;
723
724     public void startLoading(final String fileName)
725     {
726       if (fileLoadingCount == 0)
727       {
728         progressPanel = new JPanel(new BorderLayout());
729         JProgressBar progressBar = new JProgressBar();
730         progressBar.setIndeterminate(true);
731
732         progressPanel.add(new JLabel("Loading File: " + fileName + "   "),
733                           BorderLayout.WEST);
734
735         progressPanel.add(progressBar, BorderLayout.CENTER);
736
737         instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
738       }
739       fileLoadingCount++;
740       validate();
741     }
742
743     public void stopLoading()
744     {
745       fileLoadingCount--;
746       if (fileLoadingCount < 1)
747       {
748         if(progressPanel!=null)
749         {
750           this.getContentPane().remove(progressPanel);
751           progressPanel = null;
752         }
753         fileLoadingCount = 0;
754       }
755       validate();
756     }
757
758     public static int getViewCount(String viewId)
759     {
760       int count = 0;
761       JInternalFrame[] frames = Desktop.desktop.getAllFrames();
762       for (int t = 0; t < frames.length; t++)
763       {
764         if (frames[t] instanceof AlignFrame)
765         {
766           AlignFrame af = (AlignFrame) frames[t];
767           for(int a=0; a<af.alignPanels.size(); a++)
768           {
769             if(viewId.equals(
770                 ((AlignmentPanel)af.alignPanels.elementAt(a)).av.getSequenceSetId() )
771                 )
772             count ++;
773           }
774         }
775       }
776
777       return count;
778     }
779
780     public void explodeViews(AlignFrame af)
781     {
782       int size = af.alignPanels.size();
783       if(size<2)
784         return;
785
786       for(int i=0; i<size; i++)
787       {
788         AlignmentPanel ap = (AlignmentPanel)af.alignPanels.elementAt(i);
789         AlignFrame newaf = new AlignFrame(ap);
790         if(ap.av.explodedPosition!=null)
791           newaf.setBounds(ap.av.explodedPosition);
792
793         ap.av.gatherViewsHere = false;
794
795         addInternalFrame(newaf, af.getTitle(),
796                          AlignFrame.DEFAULT_WIDTH,
797                          AlignFrame.DEFAULT_HEIGHT);
798       }
799
800       af.alignPanels.clear();
801       af.closeMenuItem_actionPerformed(true);
802
803     }
804
805     public void gatherViews(AlignFrame source)
806     {
807       source.viewport.gatherViewsHere = true;
808       source.viewport.explodedPosition = source.getBounds();
809       JInternalFrame[] frames = desktop.getAllFrames();
810       String viewId = source.viewport.sequenceSetID;
811
812       for (int t = 0; t < frames.length; t++)
813       {
814         if (frames[t] instanceof AlignFrame && frames[t] != source)
815         {
816           AlignFrame af = (AlignFrame) frames[t];
817           boolean gatherThis = false;
818           for (int a = 0; a < af.alignPanels.size(); a++)
819           {
820             AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
821             if (viewId.equals(ap.av.getSequenceSetId()))
822             {
823               gatherThis = true;
824               ap.av.gatherViewsHere = false;
825               ap.av.explodedPosition = af.getBounds();
826               source.addAlignmentPanel(ap, false);
827             }
828           }
829
830           if (gatherThis)
831           {
832             af.alignPanels.clear();
833             af.closeMenuItem_actionPerformed(true);
834           }
835         }
836       }
837
838     }
839
840     jalview.gui.VamsasClient v_client=null;
841     public void vamsasLoad_actionPerformed(ActionEvent e)
842     {
843       if (v_client==null) {
844         // Start a session.
845         JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
846             getProperty("LAST_DIRECTORY"));
847
848         chooser.setFileView(new JalviewFileView());
849         chooser.setDialogTitle("Load Vamsas file");
850         chooser.setToolTipText("Import");
851
852         int value = chooser.showOpenDialog(this);
853
854         if (value == JalviewFileChooser.APPROVE_OPTION)
855         {
856           v_client = new jalview.gui.VamsasClient(this,
857               chooser.getSelectedFile());
858           this.vamsasLoad.setText("Session Update");
859           this.vamsasStop.setVisible(true);
860           v_client.initial_update();
861           v_client.startWatcher();
862         }
863       } else {
864         // store current data in session.
865         v_client.push_update();
866       }
867     }
868     public void vamsasStop_actionPerformed(ActionEvent e) {
869       if (v_client!=null) {
870         v_client.end_session();
871         v_client=null;
872         this.vamsasStop.setVisible(false);
873         this.vamsasLoad.setText("Start Vamsas Session...");
874       }
875     }
876     /**
877      * hide vamsas user gui bits when a vamsas document event is being handled.
878      * @param b true to hide gui, false to reveal gui
879      */
880     public void setVamsasUpdate(boolean b) {
881       jalview.bin.Cache.log.debug("Setting gui for Vamsas update "+(b ? "in progress" : "finished"));
882       vamsasLoad.setVisible(!b);
883       vamsasStop.setVisible(!b);
884
885     }
886     /**
887      * Checks the given url to see if it gives a response indicating that 
888      * the user should be informed of a new questionnaire.
889      * @param url
890      */
891     public void checkForQuestionnaire(String url) {
892         UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
893         javax.swing.SwingUtilities.invokeLater(jvq);
894     }
895
896 }
897