ef93aeded140fc6e7849627dc49547b57e9e09ba
[jalview.git] / src / jalview / ws / uimodel / PDBSummaryListModel.java
1 package jalview.ws.uimodel;
2
3 import javax.swing.DefaultListModel;
4
5 import org.json.simple.JSONObject;
6
7
8 @SuppressWarnings(
9 { "serial", "rawtypes" })
10 public class PDBSummaryListModel extends DefaultListModel
11 {
12   private String pdbId;
13
14   private String summary;
15
16   private int width = 480;
17
18   public PDBSummaryListModel(String pdbId, String summary)
19   {
20     this.pdbId = pdbId;
21     this.summary = summary;
22   }
23
24   public PDBSummaryListModel(JSONObject doc)
25   {
26     StringBuilder summary = new StringBuilder();
27     if (doc.get("molecule_type") != null)
28     {
29       String moleculeType = doc.get("molecule_type").toString();
30       if (moleculeType.equalsIgnoreCase("protein"))
31       {
32         summary.append("<img src=\""
33                 + getClass().getResource("/images/protein.png").toString()
34                 + "\">");
35       }
36       if (moleculeType.equalsIgnoreCase("dna"))
37       {
38         summary.append("<img src=\""
39                 + getClass().getResource("/images/dna.png").toString()
40                 + "\">");
41       }
42       if (moleculeType.equalsIgnoreCase("rna"))
43       {
44         summary.append("<img src=\""
45                 + getClass().getResource("/images/dna.png").toString()
46                 + "\">");
47       }
48       if (moleculeType.equalsIgnoreCase("sugar"))
49       {
50         summary.append("<img src=\""
51                 + getClass().getResource("/images/sugar.png").toString()
52                 + "\">");
53       }
54     }
55     this.pdbId = doc.get("pdb_id").toString();
56     summary.append("PDB ID: ").append(pdbId);
57
58     
59     if (doc.get("molecule_name") != null)
60     {
61       summary.append(" | Molecule Name: ").append(doc.get("molecule_name"));
62     }
63     if (doc.get("gene_name") != null)
64     {
65       summary.append(" | Gene Name: ").append(doc.get("gene_name"));
66     }
67     if (doc.get("genus") != null)
68     {
69       summary.append(" | Genus: ").append(doc.get("genus"));
70     }
71     if (doc.get("title") != null)
72     {
73       summary.append(" | Title: ").append(doc.get("title"));
74     }
75     this.summary = summary.toString();
76   }
77
78   public String getPdbId()
79   {
80     return pdbId;
81   }
82
83   public void setPdbId(String pdbId)
84   {
85     this.pdbId = pdbId;
86   }
87
88   public String getSummary()
89   {
90     return summary;
91   }
92
93   public void setSummary(String summary)
94   {
95     this.summary = summary;
96   }
97
98   public String toString()
99   {
100     StringBuilder html = new StringBuilder();
101     html.append("<html><div style=\"width:" + width
102             + "; word-wrap: break-word; border-bottom-style: dotted;\"> ");
103     html.append(summary);
104     html.append("</div></html>");
105     return html.toString();
106   }
107
108 }