JAL-1668 First version JAL-1668
[jalview.git] / src / jalview / ws / uimodel / PDBSummaryListModel.java
1 package jalview.ws.uimodel;
2
3 import java.util.List;
4
5 import javax.swing.DefaultListModel;
6
7 import org.json.simple.JSONObject;
8
9
10 @SuppressWarnings(
11 { "serial", "rawtypes" })
12 public class PDBSummaryListModel extends DefaultListModel
13 {
14   private String pdbId;
15
16   private String summary;
17
18   private int width = 480;
19
20
21   public PDBSummaryListModel(JSONObject doc, List<PDBDocField> diplayFields)
22   {
23     StringBuilder summaryBuilder = new StringBuilder();
24     
25     for (PDBDocField field : diplayFields)
26     {
27       if (field.equals(PDBDocField.MOLECULE_TYPE)
28               && doc.get("molecule_type") != null)
29       {
30         String moleculeType = doc.get("molecule_type").toString();
31         if (moleculeType.equalsIgnoreCase("protein"))
32         {
33           summaryBuilder.append("<img src=\""
34                   + getClass().getResource("/images/protein.png").toString()
35                   + "\">");
36         }
37         if (moleculeType.equalsIgnoreCase("dna"))
38         {
39           summaryBuilder.append("<img src=\""
40                   + getClass().getResource("/images/dna.png").toString()
41                   + "\">");
42         }
43         if (moleculeType.equalsIgnoreCase("rna"))
44         {
45           summaryBuilder.append("<img src=\""
46                   + getClass().getResource("/images/dna.png").toString()
47                   + "\">");
48         }
49         if (moleculeType.equalsIgnoreCase("sugar"))
50         {
51           summaryBuilder.append("<img src=\""
52                   + getClass().getResource("/images/sugar.png").toString()
53                   + "\">");
54         }
55       }else if (doc.get(field.getCode()) != null)
56       {
57         summaryBuilder.append(field.getName()).append(": ")
58                 .append(doc.get(field.getCode())).append(" | ");
59       }
60     }
61     int endIndex = summaryBuilder.lastIndexOf(" | ");
62     String fSummary = summaryBuilder.toString().substring(0, endIndex);
63     this.summary = fSummary.trim();
64
65   }
66
67   public String getPdbId()
68   {
69     return pdbId;
70   }
71
72   public void setPdbId(String pdbId)
73   {
74     this.pdbId = pdbId;
75   }
76
77   public String getSummary()
78   {
79     return summary;
80   }
81
82   public void setSummary(String summary)
83   {
84     this.summary = summary;
85   }
86
87
88   public String toString()
89   {
90     StringBuilder html = new StringBuilder();
91     html.append("<html><div style=\"width:" + width
92             + "; word-wrap: break-word; border-bottom-style: dotted;\"> ");
93     html.append(summary);
94     html.append("</div></html>");
95     return html.toString();
96   }
97
98
99   public enum PDBDocField
100   {
101     PDB_ID("PDB Id", "pdb_id"), TITLE("Title", "title"), MOLECULE_NAME(
102             "Molecule", "molecule_name"), MOLECULE_TYPE("Molecule Type",
103             "molecule_type"), MOLECULE_SEQUENCE("Sequence",
104             "molecule_sequence"), UNIPROT_FEATURES("Uniprot Features",
105             "uniprot_features"), PFAM_ACCESSION("PFAM Accession",
106             "pfam_accession"), INTERPRO_ACCESSION("InterPro Accession",
107             "interpro_accession"), UNIPROT_ACCESSION("UniProt Accession",
108             "uniprot_accession"), R_FACTOR("R Factor", "r_factor"), RESOLUTION(
109             "Resolution", "resolution"), DATA_QUALITY("Data Quality",
110             "data_quality"), OVERALL_QUALITY("Overall Quality",
111             "overall_quality"), POLYMER_COUNT("Polymer Count",
112             "number_of_polymers"), PROTEIN_CHAIN_COUNT(
113             "Protein Chain Count", "number_of_protein_chains"), BOUND_MOLECULE_COUNT(
114             "Bound Molecule Count", "number_of_bound_molecules"), POLYMER_RESIDUE_COUNT(
115             "Polymer Residue Count", "number_of_polymer_residues"), UNIPROT_COVERAGE(
116             "UniProt Coverage", "uniprot_coverage"), GENUS("GENUS", "genus"), GENE_NAME(
117             "Gene Name", "gene_name");
118
119     private String name;
120
121     private String code;
122
123     PDBDocField(String name, String code)
124     {
125       this.name = name;
126       this.code = code;
127     }
128
129     public String getName()
130     {
131       return name;
132     }
133
134     public String getCode()
135     {
136       return code;
137     }
138
139     public String toString()
140     {
141       return name;
142     }
143   }
144 }