Set alignFrame of gathered panels to be the source AlignFrame
[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     /**
555      * DOCUMENT ME!
556      *
557      * @param e DOCUMENT ME!
558      */
559     protected void preferences_actionPerformed(ActionEvent e)
560     {
561         new Preferences();
562     }
563
564     /**
565      * DOCUMENT ME!
566      *
567      * @param e DOCUMENT ME!
568      */
569     public void saveState_actionPerformed(ActionEvent e)
570     {
571         JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
572                     "LAST_DIRECTORY"), new String[] { "jar" },
573                 new String[] { "Jalview Project" }, "Jalview Project");
574
575         chooser.setFileView(new JalviewFileView());
576         chooser.setDialogTitle("Save State");
577
578         int value = chooser.showSaveDialog(this);
579
580         if (value == JalviewFileChooser.APPROVE_OPTION)
581         {
582             java.io.File choice = chooser.getSelectedFile();
583             jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
584             new Jalview2XML().SaveState(choice);
585         }
586     }
587
588     /**
589      * DOCUMENT ME!
590      *
591      * @param e DOCUMENT ME!
592      */
593     public void loadState_actionPerformed(ActionEvent e)
594     {
595         JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
596                     "LAST_DIRECTORY"), new String[] { "jar" },
597                 new String[] { "Jalview Project" }, "Jalview Project");
598         chooser.setFileView(new JalviewFileView());
599         chooser.setDialogTitle("Restore state");
600
601         int value = chooser.showOpenDialog(this);
602
603         if (value == JalviewFileChooser.APPROVE_OPTION)
604         {
605             String choice = chooser.getSelectedFile().getAbsolutePath();
606             jalview.bin.Cache.setProperty("LAST_DIRECTORY",
607                 chooser.getSelectedFile().getParent());
608             new Jalview2XML().LoadJalviewAlign(choice);
609         }
610     }
611
612   /*  public void vamsasLoad_actionPerformed(ActionEvent e)
613     {
614       JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
615           getProperty("LAST_DIRECTORY"));
616
617       chooser.setFileView(new JalviewFileView());
618       chooser.setDialogTitle("Load Vamsas file");
619       chooser.setToolTipText("Import");
620
621       int value = chooser.showOpenDialog(this);
622
623       if (value == JalviewFileChooser.APPROVE_OPTION)
624       {
625         jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(null);
626         vs.load(
627             chooser.getSelectedFile().getAbsolutePath()
628             );
629       }
630
631     }*/
632
633
634     public void inputSequence_actionPerformed(ActionEvent e)
635     {
636       new SequenceFetcher(null);
637     }
638
639     JPanel progressPanel;
640
641     public void startLoading(final String fileName)
642     {
643       if (fileLoadingCount == 0)
644       {
645         progressPanel = new JPanel(new BorderLayout());
646         JProgressBar progressBar = new JProgressBar();
647         progressBar.setIndeterminate(true);
648
649         progressPanel.add(new JLabel("Loading File: " + fileName + "   "),
650                           BorderLayout.WEST);
651
652         progressPanel.add(progressBar, BorderLayout.CENTER);
653
654         instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
655       }
656       fileLoadingCount++;
657       validate();
658     }
659
660     public void stopLoading()
661     {
662       fileLoadingCount--;
663       if (fileLoadingCount < 1)
664       {
665         if(progressPanel!=null)
666         {
667           this.getContentPane().remove(progressPanel);
668           progressPanel = null;
669         }
670         fileLoadingCount = 0;
671       }
672       validate();
673     }
674
675     public static int getViewCount(String viewId)
676     {
677       int count = 0;
678       JInternalFrame[] frames = Desktop.desktop.getAllFrames();
679       for (int t = 0; t < frames.length; t++)
680       {
681         if (frames[t] instanceof AlignFrame)
682         {
683           AlignFrame af = (AlignFrame) frames[t];
684           for(int a=0; a<af.alignPanels.size(); a++)
685           {
686             if(viewId.equals(
687                 ((AlignmentPanel)af.alignPanels.elementAt(a)).av.getSequenceSetId() )
688                 )
689             count ++;
690           }
691         }
692       }
693
694       return count;
695     }
696
697     public void explodeViews(AlignFrame af)
698     {
699       int size = af.alignPanels.size();
700       if(size<2)
701         return;
702       af.closeMenuItem_actionPerformed(null);
703
704       for(int i=0; i<size; i++)
705       {
706         AlignmentPanel ap = (AlignmentPanel)af.alignPanels.elementAt(i);
707         AlignFrame newaf = new AlignFrame(ap);
708         if(ap.av.explodedPosition!=null)
709           newaf.setBounds(ap.av.explodedPosition);
710
711         ap.av.gatherViewsHere = false;
712
713         PaintRefresher.Register(ap.seqPanel.seqCanvas, ap.av.getSequenceSetId());
714         PaintRefresher.Register(ap.idPanel.idCanvas, ap.av.getSequenceSetId());
715         PaintRefresher.Register(ap, ap.av.getSequenceSetId());
716
717
718         newaf.viewport = ap.av;
719         addInternalFrame(newaf, af.getTitle(),
720                          AlignFrame.DEFAULT_WIDTH,
721                          AlignFrame.DEFAULT_HEIGHT);
722       }
723
724     }
725
726     public void gatherViews(AlignFrame source)
727     {
728       source.viewport.gatherViewsHere = true;
729       source.viewport.explodedPosition = source.getBounds();
730       JInternalFrame[] frames = Desktop.desktop.getAllFrames();
731       String viewId = source.viewport.sequenceSetID;
732
733       for (int t = 0; t < frames.length; t++)
734       {
735         if (frames[t] instanceof AlignFrame && frames[t] != source)
736         {
737           AlignFrame af = (AlignFrame) frames[t];
738           boolean gatherThis = false;
739           for (int a = 0; a < af.alignPanels.size(); a++)
740           {
741             AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
742             if (viewId.equals(ap.av.getSequenceSetId()))
743             {
744               gatherThis = true;
745               ap.alignFrame = source;
746               ap.av.gatherViewsHere = false;
747               ap.av.explodedPosition = af.getBounds();
748               source.addAlignmentPanel(ap);
749             }
750           }
751           if (gatherThis)
752             af.closeMenuItem_actionPerformed(null);
753         }
754       }
755
756     }
757
758     jalview.gui.VamsasClient v_client=null;
759     public void vamsasLoad_actionPerformed(ActionEvent e)
760     {
761       if (v_client==null) {
762         // Start a session.
763         JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
764             getProperty("LAST_DIRECTORY"));
765
766         chooser.setFileView(new JalviewFileView());
767         chooser.setDialogTitle("Load Vamsas file");
768         chooser.setToolTipText("Import");
769
770         int value = chooser.showOpenDialog(this);
771
772         if (value == JalviewFileChooser.APPROVE_OPTION)
773         {
774           v_client = new jalview.gui.VamsasClient(this,
775               chooser.getSelectedFile());
776           this.vamsasLoad.setText("Session Update");
777           this.vamsasStop.setVisible(true);
778           v_client.initial_update();
779           v_client.startWatcher();
780         }
781       } else {
782         // store current data in session.
783         v_client.push_update();
784       }
785     }
786     public void vamsasStop_actionPerformed(ActionEvent e) {
787       if (v_client!=null) {
788         v_client.end_session();
789         v_client=null;
790         this.vamsasStop.setVisible(false);
791         this.vamsasLoad.setText("Start Vamsas Session...");
792       }
793     }
794     /**
795      * hide vamsas user gui bits when a vamsas document event is being handled.
796      * @param b true to hide gui, false to reveal gui
797      */
798     public void setVamsasUpdate(boolean b) {
799       jalview.bin.Cache.log.debug("Setting gui for Vamsas update "+(b ? "in progress" : "finished"));
800       vamsasLoad.setVisible(!b);
801       vamsasStop.setVisible(!b);
802
803     }
804 }
805