cbfbbc46d093ef649f92adc13795d9117e358c37
[jalview.git] / src / jalview / gui / AssociatePdbFileWithSeq.java
1 package jalview.gui;
2
3 import javax.swing.JOptionPane;
4
5 import jalview.datamodel.PDBEntry;
6 import jalview.datamodel.Sequence;
7 import jalview.datamodel.SequenceI;
8
9 /**
10  * GUI related routines for associating PDB files with sequences
11  * @author JimP
12  *
13  */
14 public class AssociatePdbFileWithSeq
15 {
16
17 /**
18  * assocate the given PDB file with 
19  * @param choice
20  * @param sequence
21  */
22   public PDBEntry associatePdbWithSeq(String choice, String protocol, SequenceI sequence, boolean prompt)
23   {
24     PDBEntry entry = new PDBEntry();
25     try
26     {
27       MCview.PDBfile pdbfile = new MCview.PDBfile(choice,
28               protocol);
29
30       if (pdbfile.id == null)
31       {
32         String reply = null;
33       
34         if (prompt) { reply = JOptionPane
35                 .showInternalInputDialog(
36                         Desktop.desktop,
37                         "Couldn't find a PDB id in the file supplied."
38                                 + "Please enter an Id to identify this structure.",
39                         "No PDB Id in File", JOptionPane.QUESTION_MESSAGE);}
40         if (reply == null)
41         {
42           return null;
43         }
44
45         entry.setId(reply);
46       }
47       else
48       {
49         entry.setId(pdbfile.id);
50       }
51     } catch (java.io.IOException ex)
52     {
53       ex.printStackTrace();
54     }
55
56     entry.setFile(choice);
57     sequence.getDatasetSequence().addPDBId(entry);
58     return entry;
59   }
60
61 }