JAL-2145 documentation of getWidth()
[jalview.git] / src / jalview / fts / core / FTSRestResponse.java
index 17204d7..92ea5f8 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -25,13 +25,14 @@ import jalview.fts.api.FTSData;
 import jalview.fts.api.FTSDataColumnI;
 
 import java.util.Collection;
+import java.util.Map;
 
 import javax.swing.JTable;
 import javax.swing.table.DefaultTableModel;
 
 /**
- * Represents the response model produced by the PDBRestClient upon successful
- * execution of a given request
+ * Represents the response model generated by the FTSRestClient upon successful
+ * execution of a given FTS request
  * 
  * @author tcnofoegbu
  *
@@ -79,7 +80,7 @@ public class FTSRestResponse
    * on the request parameters
    * 
    * @param request
-   *          the PDBRestRequest object which holds useful information for
+   *          the FTSRestRequest object which holds useful information for
    *          creating a table model
    * @param summariesList
    *          the summary list which contains the data for populating the
@@ -107,12 +108,8 @@ public class FTSRestResponse
         {
           return String.class;
         }
-        if (cols[columnIndex - colOffset].getGroup().getName()
-                .equalsIgnoreCase("Quality Measures"))
-        {
-          return Double.class;
-        }
-        return String.class;
+        return cols[columnIndex - colOffset].getDataType()
+                .getDataTypeClass();
       }
 
     };
@@ -138,16 +135,9 @@ public class FTSRestResponse
   }
 
   public static void configureTableColumn(JTable tbl_summary,
-          Collection<FTSDataColumnI> wantedFields)
+          Collection<FTSDataColumnI> wantedFields,
+          Map<String, Integer> columnPrefs)
   {
-    try
-    {
-      // wait for table model initialisation to complete
-      Thread.sleep(1200);
-    } catch (InterruptedException e1)
-    {
-      e1.printStackTrace();
-    }
     for (FTSDataColumnI wantedField : wantedFields)
     {
       try
@@ -156,12 +146,29 @@ public class FTSRestResponse
                 wantedField.getMinWidth());
         tbl_summary.getColumn(wantedField.getName()).setMaxWidth(
                 wantedField.getMaxWidth());
+        int prefedWidth = columnPrefs.get(wantedField.getName()) == null ? wantedField
+                .getPreferredWidth() : columnPrefs.get(wantedField
+                .getName());
         tbl_summary.getColumn(wantedField.getName()).setPreferredWidth(
-                wantedField.getPreferredWidth());
+                prefedWidth);
       } catch (Exception e)
       {
         e.printStackTrace();
       }
+      if (wantedField.getDataType().getDataTypeClass() == Double.class)
+      {
+        DecimalFormatTableCellRenderer dfr = new DecimalFormatTableCellRenderer(
+                wantedField.getDataType().isFormtted(), wantedField
+                        .getDataType().getSignificantFigures());
+        tbl_summary.getColumn(wantedField.getName()).setCellRenderer(dfr);
+      }
+      else if (wantedField.getDataType().getDataTypeClass() == Integer.class)
+      {
+        DecimalFormatTableCellRenderer dfr = new DecimalFormatTableCellRenderer(
+                wantedField.getDataType().isFormtted(), wantedField
+                        .getDataType().getSignificantFigures());
+        tbl_summary.getColumn(wantedField.getName()).setCellRenderer(dfr);
+      }
     }
   }