JAL-1668 First version JAL-1668
[jalview.git] / src / jalview / ws / uimodel / PDBSummaryListModel.java
index 37c0855..3a68e05 100644 (file)
@@ -1,5 +1,7 @@
 package jalview.ws.uimodel;
 
+import java.util.List;
+
 import javax.swing.DefaultListModel;
 
 import org.json.simple.JSONObject;
@@ -13,64 +15,53 @@ public class PDBSummaryListModel extends DefaultListModel
 
   private String summary;
 
-  private JSONObject rawJson;
-
   private int width = 480;
 
 
-  public PDBSummaryListModel(JSONObject doc)
+  public PDBSummaryListModel(JSONObject doc, List<PDBDocField> diplayFields)
   {
-    this.rawJson = doc;
-    StringBuilder summary = new StringBuilder();
-    if (doc.get("molecule_type") != null)
+    StringBuilder summaryBuilder = new StringBuilder();
+    
+    for (PDBDocField field : diplayFields)
     {
-      String moleculeType = doc.get("molecule_type").toString();
-      if (moleculeType.equalsIgnoreCase("protein"))
-      {
-        summary.append("<img src=\""
-                + getClass().getResource("/images/protein.png").toString()
-                + "\">");
-      }
-      if (moleculeType.equalsIgnoreCase("dna"))
+      if (field.equals(PDBDocField.MOLECULE_TYPE)
+              && doc.get("molecule_type") != null)
       {
-        summary.append("<img src=\""
-                + getClass().getResource("/images/dna.png").toString()
-                + "\">");
-      }
-      if (moleculeType.equalsIgnoreCase("rna"))
-      {
-        summary.append("<img src=\""
-                + getClass().getResource("/images/dna.png").toString()
-                + "\">");
-      }
-      if (moleculeType.equalsIgnoreCase("sugar"))
+        String moleculeType = doc.get("molecule_type").toString();
+        if (moleculeType.equalsIgnoreCase("protein"))
+        {
+          summaryBuilder.append("<img src=\""
+                  + getClass().getResource("/images/protein.png").toString()
+                  + "\">");
+        }
+        if (moleculeType.equalsIgnoreCase("dna"))
+        {
+          summaryBuilder.append("<img src=\""
+                  + getClass().getResource("/images/dna.png").toString()
+                  + "\">");
+        }
+        if (moleculeType.equalsIgnoreCase("rna"))
+        {
+          summaryBuilder.append("<img src=\""
+                  + getClass().getResource("/images/dna.png").toString()
+                  + "\">");
+        }
+        if (moleculeType.equalsIgnoreCase("sugar"))
+        {
+          summaryBuilder.append("<img src=\""
+                  + getClass().getResource("/images/sugar.png").toString()
+                  + "\">");
+        }
+      }else if (doc.get(field.getCode()) != null)
       {
-        summary.append("<img src=\""
-                + getClass().getResource("/images/sugar.png").toString()
-                + "\">");
+        summaryBuilder.append(field.getName()).append(": ")
+                .append(doc.get(field.getCode())).append(" | ");
       }
     }
-    this.pdbId = doc.get("pdb_id").toString();
-    summary.append("PDB ID: ").append(pdbId);
+    int endIndex = summaryBuilder.lastIndexOf(" | ");
+    String fSummary = summaryBuilder.toString().substring(0, endIndex);
+    this.summary = fSummary.trim();
 
-    
-    if (doc.get("molecule_name") != null)
-    {
-      summary.append(" | Molecule Name: ").append(doc.get("molecule_name"));
-    }
-    if (doc.get("gene_name") != null)
-    {
-      summary.append(" | Gene Name: ").append(doc.get("gene_name"));
-    }
-    if (doc.get("genus") != null)
-    {
-      summary.append(" | Genus: ").append(doc.get("genus"));
-    }
-    if (doc.get("title") != null)
-    {
-      summary.append(" | Title: ").append(doc.get("title"));
-    }
-    this.summary = summary.toString();
   }
 
   public String getPdbId()
@@ -93,15 +84,6 @@ public class PDBSummaryListModel extends DefaultListModel
     this.summary = summary;
   }
 
-  public JSONObject getRawJson()
-  {
-    return rawJson;
-  }
-
-  public void setRawJson(JSONObject rawJson)
-  {
-    this.rawJson = rawJson;
-  }
 
   public String toString()
   {
@@ -112,4 +94,51 @@ public class PDBSummaryListModel extends DefaultListModel
     html.append("</div></html>");
     return html.toString();
   }
+
+
+  public enum PDBDocField
+  {
+    PDB_ID("PDB Id", "pdb_id"), TITLE("Title", "title"), MOLECULE_NAME(
+            "Molecule", "molecule_name"), MOLECULE_TYPE("Molecule Type",
+            "molecule_type"), MOLECULE_SEQUENCE("Sequence",
+            "molecule_sequence"), UNIPROT_FEATURES("Uniprot Features",
+            "uniprot_features"), PFAM_ACCESSION("PFAM Accession",
+            "pfam_accession"), INTERPRO_ACCESSION("InterPro Accession",
+            "interpro_accession"), UNIPROT_ACCESSION("UniProt Accession",
+            "uniprot_accession"), R_FACTOR("R Factor", "r_factor"), RESOLUTION(
+            "Resolution", "resolution"), DATA_QUALITY("Data Quality",
+            "data_quality"), OVERALL_QUALITY("Overall Quality",
+            "overall_quality"), POLYMER_COUNT("Polymer Count",
+            "number_of_polymers"), PROTEIN_CHAIN_COUNT(
+            "Protein Chain Count", "number_of_protein_chains"), BOUND_MOLECULE_COUNT(
+            "Bound Molecule Count", "number_of_bound_molecules"), POLYMER_RESIDUE_COUNT(
+            "Polymer Residue Count", "number_of_polymer_residues"), UNIPROT_COVERAGE(
+            "UniProt Coverage", "uniprot_coverage"), GENUS("GENUS", "genus"), GENE_NAME(
+            "Gene Name", "gene_name");
+
+    private String name;
+
+    private String code;
+
+    PDBDocField(String name, String code)
+    {
+      this.name = name;
+      this.code = code;
+    }
+
+    public String getName()
+    {
+      return name;
+    }
+
+    public String getCode()
+    {
+      return code;
+    }
+
+    public String toString()
+    {
+      return name;
+    }
+  }
 }