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