37c085587ba26fb3e447bfabd7742b278e196af1
[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 JSONObject rawJson;
17
18   private int width = 480;
19
20
21   public PDBSummaryListModel(JSONObject doc)
22   {
23     this.rawJson = doc;
24     StringBuilder summary = new StringBuilder();
25     if (doc.get("molecule_type") != null)
26     {
27       String moleculeType = doc.get("molecule_type").toString();
28       if (moleculeType.equalsIgnoreCase("protein"))
29       {
30         summary.append("<img src=\""
31                 + getClass().getResource("/images/protein.png").toString()
32                 + "\">");
33       }
34       if (moleculeType.equalsIgnoreCase("dna"))
35       {
36         summary.append("<img src=\""
37                 + getClass().getResource("/images/dna.png").toString()
38                 + "\">");
39       }
40       if (moleculeType.equalsIgnoreCase("rna"))
41       {
42         summary.append("<img src=\""
43                 + getClass().getResource("/images/dna.png").toString()
44                 + "\">");
45       }
46       if (moleculeType.equalsIgnoreCase("sugar"))
47       {
48         summary.append("<img src=\""
49                 + getClass().getResource("/images/sugar.png").toString()
50                 + "\">");
51       }
52     }
53     this.pdbId = doc.get("pdb_id").toString();
54     summary.append("PDB ID: ").append(pdbId);
55
56     
57     if (doc.get("molecule_name") != null)
58     {
59       summary.append(" | Molecule Name: ").append(doc.get("molecule_name"));
60     }
61     if (doc.get("gene_name") != null)
62     {
63       summary.append(" | Gene Name: ").append(doc.get("gene_name"));
64     }
65     if (doc.get("genus") != null)
66     {
67       summary.append(" | Genus: ").append(doc.get("genus"));
68     }
69     if (doc.get("title") != null)
70     {
71       summary.append(" | Title: ").append(doc.get("title"));
72     }
73     this.summary = summary.toString();
74   }
75
76   public String getPdbId()
77   {
78     return pdbId;
79   }
80
81   public void setPdbId(String pdbId)
82   {
83     this.pdbId = pdbId;
84   }
85
86   public String getSummary()
87   {
88     return summary;
89   }
90
91   public void setSummary(String summary)
92   {
93     this.summary = summary;
94   }
95
96   public JSONObject getRawJson()
97   {
98     return rawJson;
99   }
100
101   public void setRawJson(JSONObject rawJson)
102   {
103     this.rawJson = rawJson;
104   }
105
106   public String toString()
107   {
108     StringBuilder html = new StringBuilder();
109     html.append("<html><div style=\"width:" + width
110             + "; word-wrap: break-word; border-bottom-style: dotted;\"> ");
111     html.append(summary);
112     html.append("</div></html>");
113     return html.toString();
114   }
115 }