JAL-1620 version bump and release notes
[jalview.git] / src / jalview / gui / SequenceFetcher.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2b1)
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                 MessageManager.getString("status.waiting_sequence_database_fetchers_init"),
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                         MessageManager.getString("status.waiting_sequence_database_fetchers_init"),
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(MessageManager.getString("status.init_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(MessageManager.getString("status.init_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                               MessageManager.getString("warn.couldnt_create_sequence_fetcher_client"),
165                               MessageManager.getString("label.couldnt_create_sequence_fetcher"),
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) ? MessageManager.getString("label.new_sequence_fetcher") : MessageManager.getString("label.additional_sequence_fetcher"));
223   }
224
225   private void jbInit() throws Exception
226   {
227     this.setLayout(borderLayout2);
228
229     database.setFont(JvSwingUtils.getLabelFont());
230     dbeg.setFont(new java.awt.Font("Verdana", Font.BOLD, 11));
231     jLabel1.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
232     jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
233     jLabel1.setText(MessageManager
234             .getString("label.separate_multiple_accession_ids"));
235
236     replacePunctuation.setHorizontalAlignment(SwingConstants.CENTER);
237     replacePunctuation
238             .setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
239     replacePunctuation.setText(MessageManager
240             .getString("label.replace_commas_semicolons"));
241     ok.setText(MessageManager.getString("action.ok"));
242     ok.addActionListener(new ActionListener()
243     {
244       @Override
245       public void actionPerformed(ActionEvent e)
246       {
247         ok_actionPerformed();
248       }
249     });
250     clear.setText(MessageManager.getString("action.clear"));
251     clear.addActionListener(new ActionListener()
252     {
253       @Override
254       public void actionPerformed(ActionEvent e)
255       {
256         clear_actionPerformed();
257       }
258     });
259
260     example.setText(MessageManager.getString("label.example"));
261     example.addActionListener(new ActionListener()
262     {
263       @Override
264       public void actionPerformed(ActionEvent e)
265       {
266         example_actionPerformed();
267       }
268     });
269     close.setText(MessageManager.getString("action.close"));
270     close.addActionListener(new ActionListener()
271     {
272       @Override
273       public void actionPerformed(ActionEvent e)
274       {
275         close_actionPerformed(e);
276       }
277     });
278     textArea.setFont(JvSwingUtils.getLabelFont());
279     textArea.setLineWrap(true);
280     textArea.addKeyListener(new KeyAdapter()
281     {
282       @Override
283       public void keyPressed(KeyEvent e)
284       {
285         if (e.getKeyCode() == KeyEvent.VK_ENTER)
286           ok_actionPerformed();
287       }
288     });
289     jPanel3.setLayout(borderLayout1);
290     borderLayout1.setVgap(5);
291     jPanel1.add(ok);
292     jPanel1.add(example);
293     jPanel1.add(clear);
294     jPanel1.add(close);
295     jPanel3.add(jPanel2, java.awt.BorderLayout.CENTER);
296     jPanel2.setLayout(borderLayout3);
297     databaseButt = database.getDatabaseSelectorButton();
298     databaseButt.setFont(JvSwingUtils.getLabelFont());
299     database.addActionListener(new ActionListener()
300     {
301
302       @Override
303       public void actionPerformed(ActionEvent e)
304       {
305         try
306         {
307           databaseButt.setText(database.getSelectedItem()
308                   + (database.getSelectedSources().size() > 1 ? " (and "
309                           + database.getSelectedSources().size()
310                           + " others)" : ""));
311           String eq = database.getExampleQueries();
312           dbeg.setText(MessageManager.formatMessage(
313                   "label.example_query_param", new String[]
314                   { eq }));
315           boolean enablePunct = !(eq != null && eq.indexOf(",") > -1);
316           for (DbSourceProxy dbs : database.getSelectedSources())
317           {
318             if (dbs instanceof jalview.ws.dbsources.das.datamodel.DasSequenceSource)
319             {
320               enablePunct = false;
321               break;
322             }
323           }
324           replacePunctuation.setEnabled(enablePunct);
325
326         } catch (Exception ex)
327         {
328           dbeg.setText("");
329           replacePunctuation.setEnabled(true);
330         }
331         jPanel2.repaint();
332       }
333     });
334     dbeg.setText("");
335     jPanel2.add(databaseButt, java.awt.BorderLayout.NORTH);
336     jPanel2.add(dbeg, java.awt.BorderLayout.CENTER);
337     JPanel jPanel2a = new JPanel(new BorderLayout());
338     jPanel2a.add(jLabel1, java.awt.BorderLayout.NORTH);
339     jPanel2a.add(replacePunctuation, java.awt.BorderLayout.SOUTH);
340     jPanel2.add(jPanel2a, java.awt.BorderLayout.SOUTH);
341     // jPanel2.setPreferredSize(new Dimension())
342     jPanel3.add(jScrollPane1, java.awt.BorderLayout.CENTER);
343     this.add(jPanel1, java.awt.BorderLayout.SOUTH);
344     this.add(jPanel3, java.awt.BorderLayout.CENTER);
345     this.add(jPanel2, java.awt.BorderLayout.NORTH);
346     jScrollPane1.getViewport().add(textArea);
347
348   }
349
350   protected void example_actionPerformed()
351   {
352     DbSourceProxy db = null;
353     try
354     {
355       textArea.setText(database.getExampleQueries());
356     } catch (Exception ex)
357     {
358     }
359     jPanel3.repaint();
360   }
361
362   protected void clear_actionPerformed()
363   {
364     textArea.setText("");
365     jPanel3.repaint();
366   }
367
368   JLabel dbeg = new JLabel();
369
370   JDatabaseTree database;
371
372   JButton databaseButt;
373
374   JLabel jLabel1 = new JLabel();
375
376   JCheckBox replacePunctuation = new JCheckBox();
377
378   JButton ok = new JButton();
379
380   JButton clear = new JButton();
381
382   JButton example = new JButton();
383
384   JButton close = new JButton();
385
386   JPanel jPanel1 = new JPanel();
387
388   JTextArea textArea = new JTextArea();
389
390   JScrollPane jScrollPane1 = new JScrollPane();
391
392   JPanel jPanel2 = new JPanel();
393
394   JPanel jPanel3 = new JPanel();
395
396   JPanel jPanel4 = new JPanel();
397
398   BorderLayout borderLayout1 = new BorderLayout();
399
400   BorderLayout borderLayout2 = new BorderLayout();
401
402   BorderLayout borderLayout3 = new BorderLayout();
403
404   public void close_actionPerformed(ActionEvent e)
405   {
406     try
407     {
408       frame.setClosed(true);
409     } catch (Exception ex)
410     {
411     }
412   }
413
414   public void ok_actionPerformed()
415   {
416     databaseButt.setEnabled(false);
417     example.setEnabled(false);
418     textArea.setEnabled(false);
419     ok.setEnabled(false);
420     close.setEnabled(false);
421
422     Thread worker = new Thread(this);
423     worker.start();
424   }
425
426   private void resetDialog()
427   {
428     databaseButt.setEnabled(true);
429     example.setEnabled(true);
430     textArea.setEnabled(true);
431     ok.setEnabled(true);
432     close.setEnabled(true);
433   }
434
435   @Override
436   public void run()
437   {
438     String error = "";
439     if (!database.hasSelection())
440     {
441       error += "Please select the source database\n";
442     }
443     // TODO: make this transformation more configurable
444     com.stevesoft.pat.Regex empty;
445     if (replacePunctuation.isEnabled() && replacePunctuation.isSelected())
446     {
447       empty = new com.stevesoft.pat.Regex(
448       // replace commas and spaces with a semicolon
449               "(\\s|[,; ])+", ";");
450     }
451     else
452     {
453       // just turn spaces and semicolons into single semicolons
454       empty = new com.stevesoft.pat.Regex("(\\s|[; ])+", ";");
455     }
456     textArea.setText(empty.replaceAll(textArea.getText()));
457     // see if there's anthing to search with
458     if (!new com.stevesoft.pat.Regex("[A-Za-z0-9_.]").search(textArea
459             .getText()))
460     {
461       error += "Please enter a (semi-colon separated list of) database id(s)";
462     }
463     if (error.length() > 0)
464     {
465       showErrorMessage(error);
466       resetDialog();
467       return;
468     }
469     // indicate if successive sources should be merged into one alignment.
470     boolean addToLast = false;
471     ArrayList<String> aresultq = new ArrayList<String>(), presultTitle = new ArrayList<String>();
472     ArrayList<AlignmentI> presult = new ArrayList<AlignmentI>(), aresult = new ArrayList<AlignmentI>();
473     Iterator<DbSourceProxy> proxies = database.getSelectedSources()
474             .iterator();
475     String[] qries;
476     List<String> nextfetch = Arrays.asList(qries = textArea.getText()
477             .split(";"));
478     Iterator<String> en = Arrays.asList(new String[0]).iterator();
479     int nqueries = qries.length;
480     while (proxies.hasNext() && (en.hasNext() || nextfetch.size() > 0))
481     {
482       if (!en.hasNext() && nextfetch.size() > 0)
483       {
484         en = nextfetch.iterator();
485         nqueries = nextfetch.size();
486         // save the remaining queries in the original array
487         qries = nextfetch.toArray(new String[nqueries]);
488         nextfetch = new ArrayList<String>();
489       }
490
491       DbSourceProxy proxy = proxies.next();
492       boolean isAliSource = false;
493       try
494       {
495         // update status
496         guiWindow.setProgressBar(MessageManager.formatMessage("status.fetching_sequence_queries_from", new String[]{Integer.valueOf(nqueries).toString(),proxy.getDbName()}), Thread
497                 .currentThread().hashCode());
498         isAliSource = proxy.isA(DBRefSource.ALIGNMENTDB);
499         if (proxy.getAccessionSeparator() == null)
500         {
501           while (en.hasNext())
502           {
503             String item = en.next();
504             try
505             {
506               if (aresult != null)
507               {
508                 try
509                 {
510                   // give the server a chance to breathe
511                   Thread.sleep(5);
512                 } catch (Exception e)
513                 {
514                   //
515                 }
516
517               }
518
519               AlignmentI indres = null;
520               try
521               {
522                 indres = proxy.getSequenceRecords(item);
523               } catch (OutOfMemoryError oome)
524               {
525                 new OOMWarning("fetching " + item + " from "
526                         + proxy.getDbName(), oome, this);
527               }
528               if (indres != null)
529               {
530                 aresultq.add(item);
531                 aresult.add(indres);
532               }
533               else
534               {
535                 nextfetch.add(item);
536               }
537             } catch (Exception e)
538             {
539               jalview.bin.Cache.log.info("Error retrieving " + item
540                       + " from " + proxy.getDbName(), e);
541               nextfetch.add(item);
542             }
543           }
544         }
545         else
546         {
547           StringBuffer multiacc = new StringBuffer();
548           ArrayList<String> tosend = new ArrayList<String>();
549           while (en.hasNext())
550           {
551             String nel = en.next();
552             tosend.add(nel);
553             multiacc.append(nel);
554             if (en.hasNext())
555             {
556               multiacc.append(proxy.getAccessionSeparator());
557             }
558           }
559           try
560           {
561             AlignmentI rslt;
562             SequenceI[] rs;
563             List<String> nores = new ArrayList<String>();
564             rslt = proxy.getSequenceRecords(multiacc.toString());
565             if (rslt == null || rslt.getHeight() == 0)
566             {
567               // no results - pass on all queries to next source
568               nextfetch.addAll(tosend);
569             }
570             else
571             {
572               aresultq.add(multiacc.toString());
573               aresult.add(rslt);
574
575               rs = rslt.getSequencesArray();
576               // search for each query in the dbrefs associated with each
577               // sequence
578               // returned.
579               // ones we do not find will be used to query next source (if any)
580               for (String q : tosend)
581               {
582                 DBRefEntry dbr = new DBRefEntry(), found[] = null;
583                 dbr.setSource(proxy.getDbSource());
584                 dbr.setVersion(null);
585                 if (proxy.getAccessionValidator() != null)
586                 {
587                   Regex vgr = proxy.getAccessionValidator();
588                   vgr.search(q);
589                   if (vgr.numSubs() > 0)
590                   {
591                     dbr.setAccessionId(vgr.stringMatched(1));
592                   }
593                   else
594                   {
595                     dbr.setAccessionId(vgr.stringMatched());
596                   }
597                 }
598                 else
599                 {
600                   dbr.setAccessionId(q);
601                 }
602                 boolean rfound = false;
603                 for (int r = 0; r < rs.length; r++)
604                 {
605                   if (rs[r] != null
606                           && (found = DBRefUtils.searchRefs(
607                                   rs[r].getDBRef(), dbr)) != null
608                           && found.length > 0)
609                   {
610                     rfound = true;
611                     rs[r] = null;
612                     continue;
613                   }
614                 }
615                 if (!rfound)
616                 {
617                   nextfetch.add(q);
618                 }
619               }
620             }
621           } catch (OutOfMemoryError oome)
622           {
623             new OOMWarning("fetching " + multiacc + " from "
624                     + database.getSelectedItem(), oome, this);
625           }
626         }
627
628       } catch (Exception e)
629       {
630         showErrorMessage("Error retrieving " + textArea.getText()
631                 + " from " + database.getSelectedItem());
632         // error
633         // +="Couldn't retrieve sequences from "+database.getSelectedItem();
634         System.err.println("Retrieval failed for source ='"
635                 + database.getSelectedItem() + "' and query\n'"
636                 + textArea.getText() + "'\n");
637         e.printStackTrace();
638       } catch (OutOfMemoryError e)
639       {
640         // resets dialog box - so we don't use OOMwarning here.
641         showErrorMessage("Out of Memory when retrieving "
642                 + textArea.getText()
643                 + " from "
644                 + database.getSelectedItem()
645                 + "\nPlease see the Jalview FAQ for instructions for increasing the memory available to Jalview.\n");
646         e.printStackTrace();
647       } catch (Error e)
648       {
649         showErrorMessage("Serious Error retrieving " + textArea.getText()
650                 + " from " + database.getSelectedItem());
651         e.printStackTrace();
652       }
653       // Stack results ready for opening in alignment windows
654       if (aresult != null && aresult.size() > 0)
655       {
656         AlignmentI ar = null;
657         if (isAliSource)
658         {
659           addToLast = false;
660           // new window for each result
661           while (aresult.size() > 0)
662           {
663             presult.add(aresult.remove(0));
664             presultTitle.add(aresultq.remove(0) + " "
665                     + getDefaultRetrievalTitle());
666           }
667         }
668         else
669         {
670           String titl = null;
671           if (addToLast && presult.size() > 0)
672           {
673             ar = presult.remove(presult.size() - 1);
674             titl = presultTitle.remove(presultTitle.size() - 1);
675           }
676           // concatenate all results in one window
677           while (aresult.size() > 0)
678           {
679             if (ar == null)
680             {
681               ar = aresult.remove(0);
682             }
683             else
684             {
685               ar.append(aresult.remove(0));
686             }
687             ;
688           }
689           addToLast = true;
690           presult.add(ar);
691           presultTitle.add(titl);
692         }
693       }
694       guiWindow.setProgressBar(MessageManager.getString("status.finshed_querying"), Thread.currentThread()
695               .hashCode());
696     }
697     guiWindow.setProgressBar((presult.size() > 0) ? MessageManager.getString("status.parsing_results")
698             : MessageManager.getString("status.processing"), Thread.currentThread().hashCode());
699     // process results
700     while (presult.size() > 0)
701     {
702       parseResult(presult.remove(0), presultTitle.remove(0), null);
703     }
704     // only remove visual delay after we finished parsing.
705     guiWindow.setProgressBar(null, Thread.currentThread().hashCode());
706     if (nextfetch.size() > 0)
707     {
708       StringBuffer sb = new StringBuffer();
709       sb.append("Didn't retrieve the following "
710               + (nextfetch.size() == 1 ? "query" : nextfetch.size()
711                       + " queries") + ": \n");
712       int l = sb.length(), lr = 0;
713       for (String s : nextfetch)
714       {
715         if (l != sb.length())
716         {
717           sb.append("; ");
718         }
719         if (lr - sb.length() > 40)
720         {
721           sb.append("\n");
722         }
723         sb.append(s);
724       }
725       showErrorMessage(sb.toString());
726     }
727     resetDialog();
728   }
729
730   AlignmentI parseResult(String result, String title)
731   {
732     String format = new IdentifyFile().Identify(result, "Paste");
733     Alignment sequences = null;
734     if (FormatAdapter.isValidFormat(format))
735     {
736       sequences = null;
737       try
738       {
739         sequences = new FormatAdapter().readFile(result.toString(),
740                 "Paste", format);
741       } catch (Exception ex)
742       {
743       }
744
745       if (sequences != null)
746       {
747         return parseResult(sequences, title, format);
748       }
749     }
750     else
751     {
752       showErrorMessage("Error retrieving " + textArea.getText() + " from "
753               + database.getSelectedItem());
754     }
755
756     return null;
757   }
758
759   /**
760    * 
761    * @return a standard title for any results retrieved using the currently
762    *         selected source and settings
763    */
764   public String getDefaultRetrievalTitle()
765   {
766     return "Retrieved from " + database.getSelectedItem();
767   }
768
769   AlignmentI parseResult(AlignmentI al, String title,
770           String currentFileFormat)
771   {
772
773     if (al != null && al.getHeight() > 0)
774     {
775       if (alignFrame == null)
776       {
777         AlignFrame af = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
778                 AlignFrame.DEFAULT_HEIGHT);
779         if (currentFileFormat != null)
780         {
781           af.currentFileFormat = currentFileFormat; // WHAT IS THE DEFAULT
782           // FORMAT FOR
783           // NON-FormatAdapter Sourced
784           // Alignments?
785         }
786
787         if (title == null)
788         {
789           title = getDefaultRetrievalTitle();
790         }
791         SequenceFeature[] sfs = null;
792         List<SequenceI> alsqs;
793         synchronized (alsqs = al.getSequences())
794         {
795           for (SequenceI sq : alsqs)
796           {
797             if ((sfs = (sq).getDatasetSequence().getSequenceFeatures()) != null)
798             {
799               if (sfs.length > 0)
800               {
801                 af.setShowSeqFeatures(true);
802                 break;
803               }
804             }
805
806           }
807         }
808         Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH,
809                 AlignFrame.DEFAULT_HEIGHT);
810
811         af.statusBar.setText(MessageManager
812                 .getString("label.successfully_pasted_alignment_file"));
813
814         try
815         {
816           af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN",
817                   false));
818         } catch (Exception ex)
819         {
820         }
821       }
822       else
823       {
824         for (int i = 0; i < al.getHeight(); i++)
825         {
826           alignFrame.viewport.getAlignment().addSequence(
827                   al.getSequenceAt(i)); // this
828           // also
829           // creates
830           // dataset
831           // sequence
832           // entries
833         }
834         alignFrame.viewport.setEndSeq(alignFrame.viewport.getAlignment()
835                 .getHeight());
836         alignFrame.viewport.getAlignment().getWidth();
837         alignFrame.viewport.firePropertyChange("alignment", null,
838                 alignFrame.viewport.getAlignment().getSequences());
839       }
840     }
841     return al;
842   }
843
844   void showErrorMessage(final String error)
845   {
846     resetDialog();
847     javax.swing.SwingUtilities.invokeLater(new Runnable()
848     {
849       @Override
850       public void run()
851       {
852         JOptionPane.showInternalMessageDialog(Desktop.desktop, error,
853                 MessageManager.getString("label.error_retrieving_data"),
854                 JOptionPane.WARNING_MESSAGE);
855       }
856     });
857   }
858 }