set icon false if raising windows
[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
23 import java.awt.*;
24 import java.awt.datatransfer.*;
25 import java.awt.dnd.*;
26 import java.awt.event.*;
27 import java.util.*;
28
29 import javax.swing.*;
30
31
32 /**
33  * DOCUMENT ME!
34  *
35  * @author $author$
36  * @version $Revision$
37  */
38 public class Desktop extends jalview.jbgui.GDesktop
39     implements DropTargetListener, ClipboardOwner
40 {
41     /** DOCUMENT ME!! */
42     public static Desktop instance;
43     public static JDesktopPane desktop;
44     static int openFrameCount = 0;
45     static final int xOffset = 30;
46     static final int yOffset = 30;
47     public static jalview.ws.Discoverer discoverer;
48
49     public static Object [] jalviewClipboard;
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                     openFrameCount--;
216                     windowMenu.remove(menuItem);
217                     JInternalFrame itf = desktop.getSelectedFrame();
218                        if (itf != null)
219                         itf.requestFocus();
220                 }
221                 ;
222             });
223
224         menuItem.addActionListener(new ActionListener()
225             {
226                 public void actionPerformed(ActionEvent e)
227                 {
228                     try
229                     {
230                         frame.setSelected(true);
231                         frame.setIcon(false);
232                     }
233                     catch (java.beans.PropertyVetoException ex)
234                     {
235
236                     }
237                 }
238             });
239
240         windowMenu.add(menuItem);
241
242         desktop.add(frame);
243         frame.toFront();
244         try{
245           frame.setSelected(true);
246           frame.requestFocus();
247         }catch(java.beans.PropertyVetoException ve)
248         {   }
249     }
250
251     public void lostOwnership(Clipboard clipboard, Transferable contents)
252     {
253       Desktop.jalviewClipboard = null;
254     }
255
256     public void dragEnter(DropTargetDragEvent evt)
257     {}
258
259     public void dragExit(DropTargetEvent evt)
260     {}
261
262     public void dragOver(DropTargetDragEvent evt)
263     {}
264
265     public void dropActionChanged(DropTargetDragEvent evt)
266     {}
267
268     /**
269      * DOCUMENT ME!
270      *
271      * @param evt DOCUMENT ME!
272      */
273     public void drop(DropTargetDropEvent evt)
274     {
275         Transferable t = evt.getTransferable();
276         java.util.List files = null;
277
278         try
279         {
280           DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
281           if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
282           {
283             //Works on Windows and MacOSX
284             evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
285             files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
286           }
287           else if (t.isDataFlavorSupported(uriListFlavor))
288           {
289             // This is used by Unix drag system
290             evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
291             String data = (String) t.getTransferData(uriListFlavor);
292             files = new java.util.ArrayList(1);
293             for (java.util.StringTokenizer st = new java.util.StringTokenizer(
294                 data,
295                 "\r\n");
296                  st.hasMoreTokens(); )
297             {
298               String s = st.nextToken();
299               if (s.startsWith("#"))
300               {
301                 // the line is a comment (as per the RFC 2483)
302                 continue;
303               }
304
305               java.net.URI uri = new java.net.URI(s);
306               java.io.File file = new java.io.File(uri);
307               files.add(file);
308             }
309           }
310         }
311         catch (Exception e)
312         {      }
313
314         if (files != null)
315         {
316           try
317           {
318             for (int i = 0; i < files.size(); i++)
319             {
320               String file = files.get(i).toString();
321               String protocol = FormatAdapter.FILE;
322               String format = null;
323
324               if (file.endsWith(".jar"))
325               {
326                 format = "Jalview";
327
328               }
329               else
330               {
331                 format = new IdentifyFile().Identify(file,
332                                                           protocol);
333               }
334
335
336               new FileLoader().LoadFile(file, protocol, format);
337
338             }
339           }
340           catch (Exception ex)
341           {      }
342         }
343     }
344
345     /**
346      * DOCUMENT ME!
347      *
348      * @param e DOCUMENT ME!
349      */
350     public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
351     {
352         JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
353                     "LAST_DIRECTORY"),
354                 new String[]
355                 {
356                     "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
357                     "jar"
358                 },
359                 new String[]
360                 {
361                     "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"
362                 }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
363
364         chooser.setFileView(new JalviewFileView());
365         chooser.setDialogTitle("Open local file");
366         chooser.setToolTipText("Open");
367
368         int value = chooser.showOpenDialog(this);
369
370         if (value == JalviewFileChooser.APPROVE_OPTION)
371         {
372             String choice = chooser.getSelectedFile().getPath();
373             jalview.bin.Cache.setProperty("LAST_DIRECTORY",
374                 chooser.getSelectedFile().getParent());
375
376             String format = null;
377             if (chooser.getSelectedFormat().equals("Jalview"))
378             {
379                 format = "Jalview";
380             }
381             else
382             {
383                 format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
384             }
385
386             if (viewport != null)
387               new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format);
388             else
389               new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
390         }
391     }
392
393
394
395     /**
396      * DOCUMENT ME!
397      *
398      * @param e DOCUMENT ME!
399      */
400     public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
401     {
402       // This construct allows us to have a wider textfield
403       // for viewing
404       JLabel label = new JLabel("Enter URL of Input File");
405       final JComboBox history = new JComboBox();
406
407       JPanel panel = new JPanel(new GridLayout(2,1));
408       panel.add(label);
409       panel.add(history);
410       history.setPreferredSize(new Dimension(400,20));
411       history.setEditable(true);
412       history.addItem("http://www.");
413
414       String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
415
416       StringTokenizer st;
417
418       if (historyItems != null)
419       {
420         st = new StringTokenizer(historyItems, "\t");
421
422         while (st.hasMoreTokens())
423         {
424           history.addItem(st.nextElement());
425         }
426       }
427
428        int reply = JOptionPane.showInternalConfirmDialog(desktop,
429           panel, "Input Alignment From URL",
430           JOptionPane.OK_CANCEL_OPTION );
431
432
433         if (reply != JOptionPane.OK_OPTION )
434         {
435             return;
436         }
437
438         String url = history.getSelectedItem().toString();
439
440         if (url.toLowerCase().endsWith(".jar"))
441         {
442           if (viewport != null)
443             new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, "Jalview");
444           else
445             new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
446         }
447         else
448         {
449           String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
450
451           if (format.equals("URL NOT FOUND"))
452           {
453             JOptionPane.showInternalMessageDialog(Desktop.desktop,
454                                                   "Couldn't locate " + url,
455                                                   "URL not found",
456                                                   JOptionPane.WARNING_MESSAGE);
457
458             return;
459           }
460
461           if (viewport != null)
462             new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
463           else
464             new FileLoader().LoadFile(url, FormatAdapter.URL, format);
465         }
466     }
467
468     /**
469      * DOCUMENT ME!
470      *
471      * @param e DOCUMENT ME!
472      */
473     public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
474     {
475         CutAndPasteTransfer cap = new CutAndPasteTransfer();
476         cap.setForInput(viewport);
477         Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
478     }
479
480     /*
481      * Exit the program
482      */
483     public void quit()
484     {
485         jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + "");
486         jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + "");
487         jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
488         jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
489         System.exit(0);
490     }
491
492     /**
493      * DOCUMENT ME!
494      *
495      * @param e DOCUMENT ME!
496      */
497     public void aboutMenuItem_actionPerformed(ActionEvent e)
498     {
499       StringBuffer message = new StringBuffer("JalView version " +
500                                               jalview.bin.Cache.getProperty(
501           "VERSION") +
502                                               "; last updated: " +
503                                               jalview.bin.
504                                               Cache.getDefault("BUILD_DATE", "unknown"));
505
506       if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
507           jalview.bin.Cache.getProperty("VERSION")))
508       {
509         message.append("\n\n!! Jalview version "
510                        + jalview.bin.Cache.getProperty("LATEST_VERSION")
511                        + " is available for download from http://www.jalview.org !!\n");
512
513       }
514
515       message.append( "\nAuthors:  Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." +
516             "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." +
517             "\nFor all issues relating to Jalview, email help@jalview.org" +
518             "\n\nIf  you use JalView, please cite:" +
519             "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
520             "\nBioinformatics,  2004 20;426-7.");
521
522         JOptionPane.showInternalMessageDialog(Desktop.desktop,
523
524            message.toString(), "About Jalview",
525             JOptionPane.INFORMATION_MESSAGE);
526     }
527
528     /**
529      * DOCUMENT ME!
530      *
531      * @param e DOCUMENT ME!
532      */
533     public void documentationMenuItem_actionPerformed(ActionEvent e)
534     {
535         try
536         {
537             ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
538             java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
539             javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
540
541             javax.help.HelpBroker hb = hs.createHelpBroker();
542             hb.setCurrentID("home");
543             hb.setDisplayed(true);
544         }
545         catch (Exception ex)
546         {     }
547     }
548
549     public void closeAll_actionPerformed(ActionEvent e)
550     {
551       JInternalFrame [] frames = desktop.getAllFrames();
552       for(int i=0; i<frames.length; i++)
553       {
554         try{
555         frames[i].setClosed(true);
556       }catch(java.beans.PropertyVetoException ex){}
557       }
558     }
559
560     public void raiseRelated_actionPerformed(ActionEvent e)
561     {
562       reorderAssociatedWindows(false, false);
563     }
564
565     public void minimizeAssociated_actionPerformed(ActionEvent e)
566     {
567       reorderAssociatedWindows(true, false);
568     }
569
570     void closeAssociatedWindows()
571     {
572       reorderAssociatedWindows(false, true);
573     }
574
575     void reorderAssociatedWindows(boolean minimize, boolean close)
576     {
577       JInternalFrame[] frames = desktop.getAllFrames();
578       if (frames == null || frames.length<1)
579         return;
580
581       AlignViewport source = null, target = null;
582       if (frames[0] instanceof AlignFrame)
583         source = ( (AlignFrame) frames[0]).getCurrentView();
584       else if (frames[0] instanceof TreePanel)
585         source = ( (TreePanel) frames[0]).getViewPort();
586       else if (frames[0] instanceof PCAPanel)
587         source = ( (PCAPanel) frames[0]).av;
588       else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
589         source = ((PairwiseAlignPanel)frames[0].getContentPane()).av;
590
591
592       if (source != null)
593         for (int i = 0; i < frames.length; i++)
594         {
595           target = null;
596           if(frames[i]==null)
597           {
598             continue;
599           }
600           if (frames[i] instanceof AlignFrame)
601             target = ( (AlignFrame) frames[i]).getCurrentView();
602           else if (frames[i] instanceof TreePanel)
603             target = ( (TreePanel) frames[i]).getViewPort();
604           else if (frames[i] instanceof PCAPanel)
605             target = ( (PCAPanel) frames[i]).av;
606           else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
607             target = ( (PairwiseAlignPanel) frames[i].getContentPane()).av;
608
609           if (source == target)
610           {
611             try
612             {
613               if (close)
614                 frames[i].setClosed(true);
615               else
616               {
617                 frames[i].setIcon(minimize);
618                 if (!minimize)
619                 {
620                   frames[i].toFront();
621                 }
622               }
623
624             }
625             catch (java.beans.PropertyVetoException ex)
626             {       }
627           }
628         }
629     }
630
631
632
633     /**
634      * DOCUMENT ME!
635      *
636      * @param e DOCUMENT ME!
637      */
638     protected void preferences_actionPerformed(ActionEvent e)
639     {
640         new Preferences();
641     }
642
643     /**
644      * DOCUMENT ME!
645      *
646      * @param e DOCUMENT ME!
647      */
648     public void saveState_actionPerformed(ActionEvent e)
649     {
650         JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
651                     "LAST_DIRECTORY"), new String[] { "jar" },
652                 new String[] { "Jalview Project" }, "Jalview Project");
653
654         chooser.setFileView(new JalviewFileView());
655         chooser.setDialogTitle("Save State");
656
657         int value = chooser.showSaveDialog(this);
658
659         if (value == JalviewFileChooser.APPROVE_OPTION)
660         {
661             java.io.File choice = chooser.getSelectedFile();
662             jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
663             new Jalview2XML().SaveState(choice);
664         }
665     }
666
667     /**
668      * DOCUMENT ME!
669      *
670      * @param e DOCUMENT ME!
671      */
672     public void loadState_actionPerformed(ActionEvent e)
673     {
674         JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
675                     "LAST_DIRECTORY"), new String[] { "jar" },
676                 new String[] { "Jalview Project" }, "Jalview Project");
677         chooser.setFileView(new JalviewFileView());
678         chooser.setDialogTitle("Restore state");
679
680         int value = chooser.showOpenDialog(this);
681
682         if (value == JalviewFileChooser.APPROVE_OPTION)
683         {
684             String choice = chooser.getSelectedFile().getAbsolutePath();
685             jalview.bin.Cache.setProperty("LAST_DIRECTORY",
686                 chooser.getSelectedFile().getParent());
687             new Jalview2XML().LoadJalviewAlign(choice);
688         }
689     }
690
691   /*  public void vamsasLoad_actionPerformed(ActionEvent e)
692     {
693       JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
694           getProperty("LAST_DIRECTORY"));
695
696       chooser.setFileView(new JalviewFileView());
697       chooser.setDialogTitle("Load Vamsas file");
698       chooser.setToolTipText("Import");
699
700       int value = chooser.showOpenDialog(this);
701
702       if (value == JalviewFileChooser.APPROVE_OPTION)
703       {
704         jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(null);
705         vs.load(
706             chooser.getSelectedFile().getAbsolutePath()
707             );
708       }
709
710     }*/
711
712
713     public void inputSequence_actionPerformed(ActionEvent e)
714     {
715       new SequenceFetcher(null);
716     }
717
718     JPanel progressPanel;
719
720     public void startLoading(final String fileName)
721     {
722       if (fileLoadingCount == 0)
723       {
724         progressPanel = new JPanel(new BorderLayout());
725         JProgressBar progressBar = new JProgressBar();
726         progressBar.setIndeterminate(true);
727
728         progressPanel.add(new JLabel("Loading File: " + fileName + "   "),
729                           BorderLayout.WEST);
730
731         progressPanel.add(progressBar, BorderLayout.CENTER);
732
733         instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
734       }
735       fileLoadingCount++;
736       validate();
737     }
738
739     public void stopLoading()
740     {
741       fileLoadingCount--;
742       if (fileLoadingCount < 1)
743       {
744         if(progressPanel!=null)
745         {
746           this.getContentPane().remove(progressPanel);
747           progressPanel = null;
748         }
749         fileLoadingCount = 0;
750       }
751       validate();
752     }
753
754     public static int getViewCount(String viewId)
755     {
756       int count = 0;
757       JInternalFrame[] frames = Desktop.desktop.getAllFrames();
758       for (int t = 0; t < frames.length; t++)
759       {
760         if (frames[t] instanceof AlignFrame)
761         {
762           AlignFrame af = (AlignFrame) frames[t];
763           for(int a=0; a<af.alignPanels.size(); a++)
764           {
765             if(viewId.equals(
766                 ((AlignmentPanel)af.alignPanels.elementAt(a)).av.getSequenceSetId() )
767                 )
768             count ++;
769           }
770         }
771       }
772
773       return count;
774     }
775
776     public void explodeViews(AlignFrame af)
777     {
778       int size = af.alignPanels.size();
779       if(size<2)
780         return;
781
782       for(int i=0; i<size; i++)
783       {
784         AlignmentPanel ap = (AlignmentPanel)af.alignPanels.elementAt(i);
785         AlignFrame newaf = new AlignFrame(ap);
786         if(ap.av.explodedPosition!=null)
787           newaf.setBounds(ap.av.explodedPosition);
788
789         ap.av.gatherViewsHere = false;
790
791         addInternalFrame(newaf, af.getTitle(),
792                          AlignFrame.DEFAULT_WIDTH,
793                          AlignFrame.DEFAULT_HEIGHT);
794       }
795
796       af.alignPanels.clear();
797       af.closeMenuItem_actionPerformed(true);
798
799     }
800
801     public void gatherViews(AlignFrame source)
802     {
803       source.viewport.gatherViewsHere = true;
804       source.viewport.explodedPosition = source.getBounds();
805       JInternalFrame[] frames = desktop.getAllFrames();
806       String viewId = source.viewport.sequenceSetID;
807
808       for (int t = 0; t < frames.length; t++)
809       {
810         if (frames[t] instanceof AlignFrame && frames[t] != source)
811         {
812           AlignFrame af = (AlignFrame) frames[t];
813           boolean gatherThis = false;
814           for (int a = 0; a < af.alignPanels.size(); a++)
815           {
816             AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
817             if (viewId.equals(ap.av.getSequenceSetId()))
818             {
819               gatherThis = true;
820               ap.av.gatherViewsHere = false;
821               ap.av.explodedPosition = af.getBounds();
822               source.addAlignmentPanel(ap, false);
823             }
824           }
825
826           if (gatherThis)
827           {
828             af.alignPanels.clear();
829             af.closeMenuItem_actionPerformed(true);
830           }
831         }
832       }
833
834     }
835
836     jalview.gui.VamsasClient v_client=null;
837     public void vamsasLoad_actionPerformed(ActionEvent e)
838     {
839       if (v_client==null) {
840         // Start a session.
841         JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
842             getProperty("LAST_DIRECTORY"));
843
844         chooser.setFileView(new JalviewFileView());
845         chooser.setDialogTitle("Load Vamsas file");
846         chooser.setToolTipText("Import");
847
848         int value = chooser.showOpenDialog(this);
849
850         if (value == JalviewFileChooser.APPROVE_OPTION)
851         {
852           v_client = new jalview.gui.VamsasClient(this,
853               chooser.getSelectedFile());
854           this.vamsasLoad.setText("Session Update");
855           this.vamsasStop.setVisible(true);
856           v_client.initial_update();
857           v_client.startWatcher();
858         }
859       } else {
860         // store current data in session.
861         v_client.push_update();
862       }
863     }
864     public void vamsasStop_actionPerformed(ActionEvent e) {
865       if (v_client!=null) {
866         v_client.end_session();
867         v_client=null;
868         this.vamsasStop.setVisible(false);
869         this.vamsasLoad.setText("Start Vamsas Session...");
870       }
871     }
872     /**
873      * hide vamsas user gui bits when a vamsas document event is being handled.
874      * @param b true to hide gui, false to reveal gui
875      */
876     public void setVamsasUpdate(boolean b) {
877       jalview.bin.Cache.log.debug("Setting gui for Vamsas update "+(b ? "in progress" : "finished"));
878       vamsasLoad.setVisible(!b);
879       vamsasStop.setVisible(!b);
880
881     }
882 }
883