X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fuimodel%2FPDBRestResponse.java;h=2a38b39949a0e282c854405ac5ddffb88054fe83;hb=f8563f9a829936e3cf75f36282e4816a3ea6163b;hp=bbd5e8437c7cef0ba346efed569e25cdc0e8e3e3;hpb=86ce701110991d006f506c585e13128996a01477;p=jalview.git diff --git a/src/jalview/ws/uimodel/PDBRestResponse.java b/src/jalview/ws/uimodel/PDBRestResponse.java index bbd5e84..2a38b39 100644 --- a/src/jalview/ws/uimodel/PDBRestResponse.java +++ b/src/jalview/ws/uimodel/PDBRestResponse.java @@ -23,10 +23,12 @@ package jalview.ws.uimodel; import jalview.datamodel.SequenceI; import jalview.ws.dbsources.PDBRestClient.PDBDocField; +import jalview.ws.dbsources.PDBRestClient.PDBDocField.Group; import java.util.Collection; import java.util.Objects; +import javax.swing.JTable; import javax.swing.table.DefaultTableModel; import org.json.simple.JSONObject; @@ -91,6 +93,9 @@ public class PDBRestResponse public static DefaultTableModel getTableModel(PDBRestRequest request, Collection summariesList) { + final PDBDocField[] cols = request.getWantedFields().toArray( + new PDBDocField[0]); + final int colOffset = request.getAssociatedSequence() == null ? 0 : 1; DefaultTableModel tableModel = new DefaultTableModel() { @Override @@ -98,6 +103,22 @@ public class PDBRestResponse { return false; } + + @Override + public Class getColumnClass(int columnIndex) + { + if (colOffset == 1 && columnIndex == 0) + { + return String.class; + } + if (cols[columnIndex - colOffset].getGroup().getName() + .equalsIgnoreCase(Group.QUALITY_MEASURES.getName())) + { + return Double.class; + } + return String.class; + } + }; if (request.getAssociatedSequence() != null) { @@ -156,12 +177,34 @@ public class PDBRestResponse } else { - summaryRowData[colCounter++] = fieldData; + if (field.getGroup().getName() + .equals(Group.QUALITY_MEASURES.getName())) + { + try + { + if (fieldData == null || fieldData.isEmpty()) + { + summaryRowData[colCounter++] = null; + } + else + { + Double value = Double.valueOf(fieldData); + summaryRowData[colCounter++] = value; + } + } catch (Exception e) + { + e.printStackTrace(); + System.out.println("offending value:" + fieldData); + summaryRowData[colCounter++] = 0.0; + } + }else{ + summaryRowData[colCounter++] = fieldData; + } } } } - public String getPdbId() + public Object getPdbId() { return pdbId; } @@ -176,7 +219,7 @@ public class PDBRestResponse return summaryRowData; } - public void setSummaryData(String[] summaryData) + public void setSummaryData(Object[] summaryData) { this.summaryRowData = summaryData; } @@ -190,7 +233,9 @@ public class PDBRestResponse StringBuilder summaryFieldValues = new StringBuilder(); for (Object summaryField : summaryRowData) { - summaryFieldValues.append(summaryField.toString()).append("\t"); + summaryFieldValues.append( + summaryField == null ? " " : summaryField.toString()) + .append("\t"); } return summaryFieldValues.toString(); } @@ -220,4 +265,35 @@ public class PDBRestResponse } + public static void configureTableColumn(JTable tbl_summary, + Collection wantedFields) + { + for (PDBDocField wantedField : wantedFields) + { + if (wantedField.equals(PDBDocField.PDB_ID)) + { + tbl_summary.getColumn(wantedField.getName()).setMinWidth(40); + tbl_summary.getColumn(wantedField.getName()).setMaxWidth(60); + tbl_summary.getColumn(wantedField.getName()).setPreferredWidth(45); + } + else if (wantedField.equals(PDBDocField.TITLE)) + { + tbl_summary.getColumn(wantedField.getName()).setMinWidth(300); + tbl_summary.getColumn(wantedField.getName()).setMaxWidth(1000); + tbl_summary.getColumn(wantedField.getName()).setPreferredWidth(400); + } + else if (wantedField.getGroup() == Group.QUALITY_MEASURES) + { + tbl_summary.getColumn(wantedField.getName()).setMinWidth(50); + tbl_summary.getColumn(wantedField.getName()).setMaxWidth(150); + tbl_summary.getColumn(wantedField.getName()).setPreferredWidth(85); + } + else + { + tbl_summary.getColumn(wantedField.getName()).setMinWidth(50); + tbl_summary.getColumn(wantedField.getName()).setMaxWidth(400); + tbl_summary.getColumn(wantedField.getName()).setPreferredWidth(95); + } + } + } }