1 package jalview.ws.uimodel;
3 import jalview.ws.dbsources.PDBRestClient.PDBDocField;
5 import java.util.Collection;
7 import java.util.Objects;
9 import javax.swing.DefaultListModel;
11 import org.json.simple.JSONObject;
13 public class PDBSearchResponse
15 private int itemsFound;
17 private String responseTime;
19 private Collection<PDBResponseSummary> searchSummary;
21 public int getItemsFound()
26 public void setItemsFound(int itemFound)
28 this.itemsFound = itemFound;
31 public String getResponseTime()
36 public void setResponseTime(String responseTime)
38 this.responseTime = responseTime;
41 public Collection<PDBResponseSummary> getSearchSummary()
46 public void setSearchSummary(Collection<PDBResponseSummary> searchSummary)
48 this.searchSummary = searchSummary;
51 public static DefaultListModel<PDBResponseSummary> getListModel(
52 Collection<PDBResponseSummary> summariesList)
54 DefaultListModel<PDBResponseSummary> defaultListModel = new DefaultListModel<PDBResponseSummary>();
55 for (PDBResponseSummary summaryList : summariesList)
57 defaultListModel.addElement(summaryList);
59 return defaultListModel;
62 public class PDBResponseSummary
66 private String summary;
68 private int width = 480;
70 public PDBResponseSummary(JSONObject doc, List<PDBDocField> diplayFields)
72 StringBuilder summaryBuilder = new StringBuilder();
74 for (PDBDocField field : diplayFields)
76 if (field.equals(PDBDocField.MOLECULE_TYPE)
77 && doc.get(PDBDocField.MOLECULE_TYPE.getCode()) != null)
79 String moleculeType = doc
80 .get(PDBDocField.MOLECULE_TYPE.getCode()).toString();
81 if (moleculeType.equalsIgnoreCase("protein"))
83 summaryBuilder.append("<img src=\""
84 + getClass().getResource("/images/protein.png")
87 if (moleculeType.equalsIgnoreCase("dna"))
89 summaryBuilder.append("<img src=\""
90 + getClass().getResource("/images/dna.png").toString()
93 if (moleculeType.equalsIgnoreCase("rna"))
95 summaryBuilder.append("<img src=\""
96 + getClass().getResource("/images/dna.png").toString()
99 if (moleculeType.equalsIgnoreCase("sugar"))
101 summaryBuilder.append("<img src=\""
102 + getClass().getResource("/images/sugar.png")
103 .toString() + "\">");
106 else if (field.equals(PDBDocField.PDB_ID)
107 && doc.get(PDBDocField.PDB_ID.getCode()) != null)
109 this.pdbId = doc.get(PDBDocField.PDB_ID.getCode()).toString();
111 else if (doc.get(field.getCode()) != null)
113 summaryBuilder.append(field.getName()).append(": ")
114 .append(doc.get(field.getCode())).append(" | ");
117 int endIndex = summaryBuilder.lastIndexOf(" | ");
118 String fSummary = summaryBuilder.toString().substring(0, endIndex);
119 this.summary = fSummary.trim();
120 summaryBuilder = null;
123 public String getPdbId()
128 public void setPdbId(String pdbId)
133 public String getSummary()
138 public void setSummary(String summary)
140 this.summary = summary;
143 public String toString()
145 StringBuilder html = new StringBuilder();
146 html.append("<html><div style=\"width:" + width
147 + "; word-wrap: break-word; border-bottom-style: dotted;\"> ");
148 html.append(summary);
149 html.append("</div></html>");
150 return html.toString();
154 public int hashCode()
156 return Objects.hash(this.pdbId, this.summary);