JAL-1517 source formatting
[jalview.git] / src / jalview / gui / SequenceFetcher.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3  * Copyright (C) 2014 The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.gui;
22
23 import java.util.*;
24 import java.util.List;
25
26 import java.awt.*;
27 import java.awt.event.*;
28
29 import javax.swing.*;
30 import javax.swing.tree.DefaultMutableTreeNode;
31
32 import com.stevesoft.pat.Regex;
33
34 import jalview.datamodel.*;
35 import jalview.io.*;
36 import jalview.util.DBRefUtils;
37 import jalview.util.MessageManager;
38 import jalview.ws.dbsources.das.api.DasSourceRegistryI;
39 import jalview.ws.seqfetcher.DbSourceProxy;
40 import java.awt.BorderLayout;
41
42 public class SequenceFetcher extends JPanel implements Runnable
43 {
44   // ASequenceFetcher sfetch;
45   JInternalFrame frame;
46
47   IProgressIndicator guiWindow;
48
49   AlignFrame alignFrame;
50
51   StringBuffer result;
52
53   final String noDbSelected = "-- Select Database --";
54
55   private static jalview.ws.SequenceFetcher sfetch = null;
56
57   private static long lastDasSourceRegistry = -3;
58
59   private static DasSourceRegistryI dasRegistry = null;
60
61   private static boolean _initingFetcher = false;
62
63   private static Thread initingThread = null;
64
65   /**
66    * Blocking method that initialises and returns the shared instance of the
67    * SequenceFetcher client
68    * 
69    * @param guiWindow
70    *          - where the initialisation delay message should be shown
71    * @return the singleton instance of the sequence fetcher client
72    */
73   public static jalview.ws.SequenceFetcher getSequenceFetcherSingleton(
74           final IProgressIndicator guiWindow)
75   {
76     if (_initingFetcher && initingThread != null && initingThread.isAlive())
77     {
78       if (guiWindow != null)
79       {
80         guiWindow.setProgressBar(
81                 "Waiting for Sequence Database Fetchers to initialise",
82                 Thread.currentThread().hashCode());
83       }
84       // initting happening on another thread - so wait around to see if it
85       // finishes.
86       while (_initingFetcher && initingThread != null
87               && initingThread.isAlive())
88       {
89         try
90         {
91           Thread.sleep(10);
92         } catch (Exception e)
93         {
94         }
95         ;
96       }
97       if (guiWindow != null)
98       {
99         guiWindow.setProgressBar(
100                 "Waiting for Sequence Database Fetchers to initialise",
101                 Thread.currentThread().hashCode());
102       }
103     }
104     if (sfetch == null
105             || dasRegistry != jalview.bin.Cache.getDasSourceRegistry()
106             || lastDasSourceRegistry != (jalview.bin.Cache
107                     .getDasSourceRegistry().getDasRegistryURL() + jalview.bin.Cache
108                     .getDasSourceRegistry().getLocalSourceString())
109                     .hashCode())
110     {
111       _initingFetcher = true;
112       initingThread = Thread.currentThread();
113       /**
114        * give a visual indication that sequence fetcher construction is occuring
115        */
116       if (guiWindow != null)
117       {
118         guiWindow.setProgressBar("Initialising Sequence Database Fetchers",
119                 Thread.currentThread().hashCode());
120       }
121       dasRegistry = jalview.bin.Cache.getDasSourceRegistry();
122       dasRegistry.refreshSources();
123
124       jalview.ws.SequenceFetcher sf = new jalview.ws.SequenceFetcher();
125       if (guiWindow != null)
126       {
127         guiWindow.setProgressBar("Initialising Sequence Database Fetchers",
128                 Thread.currentThread().hashCode());
129       }
130       lastDasSourceRegistry = (dasRegistry.getDasRegistryURL() + dasRegistry
131               .getLocalSourceString()).hashCode();
132       sfetch = sf;
133       _initingFetcher = false;
134       initingThread = null;
135     }
136     return sfetch;
137   }
138
139   public SequenceFetcher(IProgressIndicator guiIndic)
140   {
141     final IProgressIndicator guiWindow = guiIndic;
142     final SequenceFetcher us = this;
143     // launch initialiser thread
144     Thread sf = new Thread(new Runnable()
145     {
146
147       @Override
148       public void run()
149       {
150         if (getSequenceFetcherSingleton(guiWindow) != null)
151         {
152           us.initGui(guiWindow);
153         }
154         else
155         {
156           javax.swing.SwingUtilities.invokeLater(new Runnable()
157           {
158             @Override
159             public void run()
160             {
161               JOptionPane
162                       .showInternalMessageDialog(
163                               Desktop.desktop,
164                               "Could not create the sequence fetcher client. Check error logs for details.",
165                               "Couldn't create SequenceFetcher",
166                               JOptionPane.ERROR_MESSAGE);
167             }
168           });
169
170           // raise warning dialog
171         }
172       }
173     });
174     sf.start();
175   }
176
177   private class DatabaseAuthority extends DefaultMutableTreeNode
178   {
179
180   };
181
182   private class DatabaseSource extends DefaultMutableTreeNode
183   {
184
185   };
186
187   /**
188    * called by thread spawned by constructor
189    * 
190    * @param guiWindow
191    */
192   private void initGui(IProgressIndicator guiWindow)
193   {
194     this.guiWindow = guiWindow;
195     if (guiWindow instanceof AlignFrame)
196     {
197       alignFrame = (AlignFrame) guiWindow;
198     }
199     database = new JDatabaseTree(sfetch);
200     try
201     {
202       jbInit();
203     } catch (Exception ex)
204     {
205       ex.printStackTrace();
206     }
207
208     frame = new JInternalFrame();
209     frame.setContentPane(this);
210     if (new jalview.util.Platform().isAMac())
211     {
212       Desktop.addInternalFrame(frame, getFrameTitle(), 400, 240);
213     }
214     else
215     {
216       Desktop.addInternalFrame(frame, getFrameTitle(), 400, 180);
217     }
218   }
219
220   private String getFrameTitle()
221   {
222     return ((alignFrame == null) ? "New " : "Additional ")
223             + "Sequence Fetcher";
224   }
225
226   private void jbInit() throws Exception
227   {
228     this.setLayout(borderLayout2);
229
230     database.setFont(JvSwingUtils.getLabelFont());
231     dbeg.setFont(new java.awt.Font("Verdana", Font.BOLD, 11));
232     jLabel1.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
233     jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
234     jLabel1.setText(MessageManager
235             .getString("label.separate_multiple_accession_ids"));
236
237     replacePunctuation.setHorizontalAlignment(SwingConstants.CENTER);
238     replacePunctuation
239             .setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
240     replacePunctuation.setText(MessageManager
241             .getString("label.replace_commas_semicolons"));
242     ok.setText(MessageManager.getString("action.ok"));
243     ok.addActionListener(new ActionListener()
244     {
245       @Override
246       public void actionPerformed(ActionEvent e)
247       {
248         ok_actionPerformed();
249       }
250     });
251     clear.setText(MessageManager.getString("action.clear"));
252     clear.addActionListener(new ActionListener()
253     {
254       @Override
255       public void actionPerformed(ActionEvent e)
256       {
257         clear_actionPerformed();
258       }
259     });
260
261     example.setText(MessageManager.getString("label.example"));
262     example.addActionListener(new ActionListener()
263     {
264       @Override
265       public void actionPerformed(ActionEvent e)
266       {
267         example_actionPerformed();
268       }
269     });
270     close.setText(MessageManager.getString("action.close"));
271     close.addActionListener(new ActionListener()
272     {
273       @Override
274       public void actionPerformed(ActionEvent e)
275       {
276         close_actionPerformed(e);
277       }
278     });
279     textArea.setFont(JvSwingUtils.getLabelFont());
280     textArea.setLineWrap(true);
281     textArea.addKeyListener(new KeyAdapter()
282     {
283       @Override
284       public void keyPressed(KeyEvent e)
285       {
286         if (e.getKeyCode() == KeyEvent.VK_ENTER)
287           ok_actionPerformed();
288       }
289     });
290     jPanel3.setLayout(borderLayout1);
291     borderLayout1.setVgap(5);
292     jPanel1.add(ok);
293     jPanel1.add(example);
294     jPanel1.add(clear);
295     jPanel1.add(close);
296     jPanel3.add(jPanel2, java.awt.BorderLayout.CENTER);
297     jPanel2.setLayout(borderLayout3);
298     databaseButt = database.getDatabaseSelectorButton();
299     databaseButt.setFont(JvSwingUtils.getLabelFont());
300     database.addActionListener(new ActionListener()
301     {
302
303       @Override
304       public void actionPerformed(ActionEvent e)
305       {
306         try
307         {
308           databaseButt.setText(database.getSelectedItem()
309                   + (database.getSelectedSources().size() > 1 ? " (and "
310                           + database.getSelectedSources().size()
311                           + " others)" : ""));
312           String eq = database.getExampleQueries();
313           dbeg.setText(MessageManager.formatMessage(
314                   "label.example_query_param", new String[]
315                   { eq }));
316           boolean enablePunct = !(eq != null && eq.indexOf(",") > -1);
317           for (DbSourceProxy dbs : database.getSelectedSources())
318           {
319             if (dbs instanceof jalview.ws.dbsources.das.datamodel.DasSequenceSource)
320             {
321               enablePunct = false;
322               break;
323             }
324           }
325           replacePunctuation.setEnabled(enablePunct);
326
327         } catch (Exception ex)
328         {
329           dbeg.setText("");
330           replacePunctuation.setEnabled(true);
331         }
332         jPanel2.repaint();
333       }
334     });
335     dbeg.setText("");
336     jPanel2.add(databaseButt, java.awt.BorderLayout.NORTH);
337     jPanel2.add(dbeg, java.awt.BorderLayout.CENTER);
338     JPanel jPanel2a = new JPanel(new BorderLayout());
339     jPanel2a.add(jLabel1, java.awt.BorderLayout.NORTH);
340     jPanel2a.add(replacePunctuation, java.awt.BorderLayout.SOUTH);
341     jPanel2.add(jPanel2a, java.awt.BorderLayout.SOUTH);
342     // jPanel2.setPreferredSize(new Dimension())
343     jPanel3.add(jScrollPane1, java.awt.BorderLayout.CENTER);
344     this.add(jPanel1, java.awt.BorderLayout.SOUTH);
345     this.add(jPanel3, java.awt.BorderLayout.CENTER);
346     this.add(jPanel2, java.awt.BorderLayout.NORTH);
347     jScrollPane1.getViewport().add(textArea);
348
349   }
350
351   protected void example_actionPerformed()
352   {
353     DbSourceProxy db = null;
354     try
355     {
356       textArea.setText(database.getExampleQueries());
357     } catch (Exception ex)
358     {
359     }
360     jPanel3.repaint();
361   }
362
363   protected void clear_actionPerformed()
364   {
365     textArea.setText("");
366     jPanel3.repaint();
367   }
368
369   JLabel dbeg = new JLabel();
370
371   JDatabaseTree database;
372
373   JButton databaseButt;
374
375   JLabel jLabel1 = new JLabel();
376
377   JCheckBox replacePunctuation = new JCheckBox();
378
379   JButton ok = new JButton();
380
381   JButton clear = new JButton();
382
383   JButton example = new JButton();
384
385   JButton close = new JButton();
386
387   JPanel jPanel1 = new JPanel();
388
389   JTextArea textArea = new JTextArea();
390
391   JScrollPane jScrollPane1 = new JScrollPane();
392
393   JPanel jPanel2 = new JPanel();
394
395   JPanel jPanel3 = new JPanel();
396
397   JPanel jPanel4 = new JPanel();
398
399   BorderLayout borderLayout1 = new BorderLayout();
400
401   BorderLayout borderLayout2 = new BorderLayout();
402
403   BorderLayout borderLayout3 = new BorderLayout();
404
405   public void close_actionPerformed(ActionEvent e)
406   {
407     try
408     {
409       frame.setClosed(true);
410     } catch (Exception ex)
411     {
412     }
413   }
414
415   public void ok_actionPerformed()
416   {
417     databaseButt.setEnabled(false);
418     example.setEnabled(false);
419     textArea.setEnabled(false);
420     ok.setEnabled(false);
421     close.setEnabled(false);
422
423     Thread worker = new Thread(this);
424     worker.start();
425   }
426
427   private void resetDialog()
428   {
429     databaseButt.setEnabled(true);
430     example.setEnabled(true);
431     textArea.setEnabled(true);
432     ok.setEnabled(true);
433     close.setEnabled(true);
434   }
435
436   @Override
437   public void run()
438   {
439     String error = "";
440     if (!database.hasSelection())
441     {
442       error += "Please select the source database\n";
443     }
444     // TODO: make this transformation more configurable
445     com.stevesoft.pat.Regex empty;
446     if (replacePunctuation.isEnabled() && replacePunctuation.isSelected())
447     {
448       empty = new com.stevesoft.pat.Regex(
449       // replace commas and spaces with a semicolon
450               "(\\s|[,; ])+", ";");
451     }
452     else
453     {
454       // just turn spaces and semicolons into single semicolons
455       empty = new com.stevesoft.pat.Regex("(\\s|[; ])+", ";");
456     }
457     textArea.setText(empty.replaceAll(textArea.getText()));
458     // see if there's anthing to search with
459     if (!new com.stevesoft.pat.Regex("[A-Za-z0-9_.]").search(textArea
460             .getText()))
461     {
462       error += "Please enter a (semi-colon separated list of) database id(s)";
463     }
464     if (error.length() > 0)
465     {
466       showErrorMessage(error);
467       resetDialog();
468       return;
469     }
470     // indicate if successive sources should be merged into one alignment.
471     boolean addToLast = false;
472     ArrayList<String> aresultq = new ArrayList<String>(), presultTitle = new ArrayList<String>();
473     ArrayList<AlignmentI> presult = new ArrayList<AlignmentI>(), aresult = new ArrayList<AlignmentI>();
474     Iterator<DbSourceProxy> proxies = database.getSelectedSources()
475             .iterator();
476     String[] qries;
477     List<String> nextfetch = Arrays.asList(qries = textArea.getText()
478             .split(";"));
479     Iterator<String> en = Arrays.asList(new String[0]).iterator();
480     int nqueries = qries.length;
481     while (proxies.hasNext() && (en.hasNext() || nextfetch.size() > 0))
482     {
483       if (!en.hasNext() && nextfetch.size() > 0)
484       {
485         en = nextfetch.iterator();
486         nqueries = nextfetch.size();
487         // save the remaining queries in the original array
488         qries = nextfetch.toArray(new String[nqueries]);
489         nextfetch = new ArrayList<String>();
490       }
491
492       DbSourceProxy proxy = proxies.next();
493       boolean isAliSource = false;
494       try
495       {
496         // update status
497         guiWindow.setProgressBar("Fetching " + nqueries
498                 + " sequence queries from " + proxy.getDbName(), Thread
499                 .currentThread().hashCode());
500         isAliSource = proxy.isA(DBRefSource.ALIGNMENTDB);
501         if (proxy.getAccessionSeparator() == null)
502         {
503           while (en.hasNext())
504           {
505             String item = en.next();
506             try
507             {
508               if (aresult != null)
509               {
510                 try
511                 {
512                   // give the server a chance to breathe
513                   Thread.sleep(5);
514                 } catch (Exception e)
515                 {
516                   //
517                 }
518
519               }
520
521               AlignmentI indres = null;
522               try
523               {
524                 indres = proxy.getSequenceRecords(item);
525               } catch (OutOfMemoryError oome)
526               {
527                 new OOMWarning("fetching " + item + " from "
528                         + proxy.getDbName(), oome, this);
529               }
530               if (indres != null)
531               {
532                 aresultq.add(item);
533                 aresult.add(indres);
534               }
535               else
536               {
537                 nextfetch.add(item);
538               }
539             } catch (Exception e)
540             {
541               jalview.bin.Cache.log.info("Error retrieving " + item
542                       + " from " + proxy.getDbName(), e);
543               nextfetch.add(item);
544             }
545           }
546         }
547         else
548         {
549           StringBuffer multiacc = new StringBuffer();
550           ArrayList<String> tosend = new ArrayList<String>();
551           while (en.hasNext())
552           {
553             String nel = en.next();
554             tosend.add(nel);
555             multiacc.append(nel);
556             if (en.hasNext())
557             {
558               multiacc.append(proxy.getAccessionSeparator());
559             }
560           }
561           try
562           {
563             AlignmentI rslt;
564             SequenceI[] rs;
565             List<String> nores = new ArrayList<String>();
566             rslt = proxy.getSequenceRecords(multiacc.toString());
567             if (rslt == null || rslt.getHeight() == 0)
568             {
569               // no results - pass on all queries to next source
570               nextfetch.addAll(tosend);
571             }
572             else
573             {
574               aresultq.add(multiacc.toString());
575               aresult.add(rslt);
576
577               rs = rslt.getSequencesArray();
578               // search for each query in the dbrefs associated with each
579               // sequence
580               // returned.
581               // ones we do not find will be used to query next source (if any)
582               for (String q : tosend)
583               {
584                 DBRefEntry dbr = new DBRefEntry(), found[] = null;
585                 dbr.setSource(proxy.getDbSource());
586                 dbr.setVersion(null);
587                 if (proxy.getAccessionValidator() != null)
588                 {
589                   Regex vgr = proxy.getAccessionValidator();
590                   vgr.search(q);
591                   if (vgr.numSubs() > 0)
592                   {
593                     dbr.setAccessionId(vgr.stringMatched(1));
594                   }
595                   else
596                   {
597                     dbr.setAccessionId(vgr.stringMatched());
598                   }
599                 }
600                 else
601                 {
602                   dbr.setAccessionId(q);
603                 }
604                 boolean rfound = false;
605                 for (int r = 0; r < rs.length; r++)
606                 {
607                   if (rs[r] != null
608                           && (found = DBRefUtils.searchRefs(
609                                   rs[r].getDBRef(), dbr)) != null
610                           && found.length > 0)
611                   {
612                     rfound = true;
613                     rs[r] = null;
614                     continue;
615                   }
616                 }
617                 if (!rfound)
618                 {
619                   nextfetch.add(q);
620                 }
621               }
622             }
623           } catch (OutOfMemoryError oome)
624           {
625             new OOMWarning("fetching " + multiacc + " from "
626                     + database.getSelectedItem(), oome, this);
627           }
628         }
629
630       } catch (Exception e)
631       {
632         showErrorMessage("Error retrieving " + textArea.getText()
633                 + " from " + database.getSelectedItem());
634         // error
635         // +="Couldn't retrieve sequences from "+database.getSelectedItem();
636         System.err.println("Retrieval failed for source ='"
637                 + database.getSelectedItem() + "' and query\n'"
638                 + textArea.getText() + "'\n");
639         e.printStackTrace();
640       } catch (OutOfMemoryError e)
641       {
642         // resets dialog box - so we don't use OOMwarning here.
643         showErrorMessage("Out of Memory when retrieving "
644                 + textArea.getText()
645                 + " from "
646                 + database.getSelectedItem()
647                 + "\nPlease see the Jalview FAQ for instructions for increasing the memory available to Jalview.\n");
648         e.printStackTrace();
649       } catch (Error e)
650       {
651         showErrorMessage("Serious Error retrieving " + textArea.getText()
652                 + " from " + database.getSelectedItem());
653         e.printStackTrace();
654       }
655       // Stack results ready for opening in alignment windows
656       if (aresult != null && aresult.size() > 0)
657       {
658         AlignmentI ar = null;
659         if (isAliSource)
660         {
661           addToLast = false;
662           // new window for each result
663           while (aresult.size() > 0)
664           {
665             presult.add(aresult.remove(0));
666             presultTitle.add(aresultq.remove(0) + " "
667                     + getDefaultRetrievalTitle());
668           }
669         }
670         else
671         {
672           String titl = null;
673           if (addToLast && presult.size() > 0)
674           {
675             ar = presult.remove(presult.size() - 1);
676             titl = presultTitle.remove(presultTitle.size() - 1);
677           }
678           // concatenate all results in one window
679           while (aresult.size() > 0)
680           {
681             if (ar == null)
682             {
683               ar = aresult.remove(0);
684             }
685             else
686             {
687               ar.append(aresult.remove(0));
688             }
689             ;
690           }
691           addToLast = true;
692           presult.add(ar);
693           presultTitle.add(titl);
694         }
695       }
696       guiWindow.setProgressBar("Finished querying", Thread.currentThread()
697               .hashCode());
698     }
699     guiWindow.setProgressBar((presult.size() > 0) ? "Parsing results."
700             : "Processing ..", Thread.currentThread().hashCode());
701     // process results
702     while (presult.size() > 0)
703     {
704       parseResult(presult.remove(0), presultTitle.remove(0), null);
705     }
706     // only remove visual delay after we finished parsing.
707     guiWindow.setProgressBar(null, Thread.currentThread().hashCode());
708     if (nextfetch.size() > 0)
709     {
710       StringBuffer sb = new StringBuffer();
711       sb.append("Didn't retrieve the following "
712               + (nextfetch.size() == 1 ? "query" : nextfetch.size()
713                       + " queries") + ": \n");
714       int l = sb.length(), lr = 0;
715       for (String s : nextfetch)
716       {
717         if (l != sb.length())
718         {
719           sb.append("; ");
720         }
721         if (lr - sb.length() > 40)
722         {
723           sb.append("\n");
724         }
725         sb.append(s);
726       }
727       showErrorMessage(sb.toString());
728     }
729     resetDialog();
730   }
731
732   AlignmentI parseResult(String result, String title)
733   {
734     String format = new IdentifyFile().Identify(result, "Paste");
735     Alignment sequences = null;
736     if (FormatAdapter.isValidFormat(format))
737     {
738       sequences = null;
739       try
740       {
741         sequences = new FormatAdapter().readFile(result.toString(),
742                 "Paste", format);
743       } catch (Exception ex)
744       {
745       }
746
747       if (sequences != null)
748       {
749         return parseResult(sequences, title, format);
750       }
751     }
752     else
753     {
754       showErrorMessage("Error retrieving " + textArea.getText() + " from "
755               + database.getSelectedItem());
756     }
757
758     return null;
759   }
760
761   /**
762    * 
763    * @return a standard title for any results retrieved using the currently
764    *         selected source and settings
765    */
766   public String getDefaultRetrievalTitle()
767   {
768     return "Retrieved from " + database.getSelectedItem();
769   }
770
771   AlignmentI parseResult(AlignmentI al, String title,
772           String currentFileFormat)
773   {
774
775     if (al != null && al.getHeight() > 0)
776     {
777       if (alignFrame == null)
778       {
779         AlignFrame af = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
780                 AlignFrame.DEFAULT_HEIGHT);
781         if (currentFileFormat != null)
782         {
783           af.currentFileFormat = currentFileFormat; // WHAT IS THE DEFAULT
784           // FORMAT FOR
785           // NON-FormatAdapter Sourced
786           // Alignments?
787         }
788
789         if (title == null)
790         {
791           title = getDefaultRetrievalTitle();
792         }
793         SequenceFeature[] sfs = null;
794         List<SequenceI> alsqs;
795         synchronized (alsqs = al.getSequences())
796         {
797           for (SequenceI sq : alsqs)
798           {
799             if ((sfs = (sq).getDatasetSequence().getSequenceFeatures()) != null)
800             {
801               if (sfs.length > 0)
802               {
803                 af.setShowSeqFeatures(true);
804                 break;
805               }
806             }
807
808           }
809         }
810         Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH,
811                 AlignFrame.DEFAULT_HEIGHT);
812
813         af.statusBar.setText(MessageManager
814                 .getString("label.successfully_pasted_alignment_file"));
815
816         try
817         {
818           af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN",
819                   false));
820         } catch (Exception ex)
821         {
822         }
823       }
824       else
825       {
826         for (int i = 0; i < al.getHeight(); i++)
827         {
828           alignFrame.viewport.getAlignment().addSequence(
829                   al.getSequenceAt(i)); // this
830           // also
831           // creates
832           // dataset
833           // sequence
834           // entries
835         }
836         alignFrame.viewport.setEndSeq(alignFrame.viewport.getAlignment()
837                 .getHeight());
838         alignFrame.viewport.getAlignment().getWidth();
839         alignFrame.viewport.firePropertyChange("alignment", null,
840                 alignFrame.viewport.getAlignment().getSequences());
841       }
842     }
843     return al;
844   }
845
846   void showErrorMessage(final String error)
847   {
848     resetDialog();
849     javax.swing.SwingUtilities.invokeLater(new Runnable()
850     {
851       @Override
852       public void run()
853       {
854         JOptionPane.showInternalMessageDialog(Desktop.desktop, error,
855                 MessageManager.getString("label.error_retrieving_data"),
856                 JOptionPane.WARNING_MESSAGE);
857       }
858     });
859   }
860 }