JAL-2808 convenience method to get attribute as String
[jalview.git] / src / jalview / datamodel / SequenceFeature.java
index a2d91b1..ffbd497 100755 (executable)
@@ -21,6 +21,7 @@
 package jalview.datamodel;
 
 import jalview.datamodel.features.FeatureAttributeType;
+import jalview.datamodel.features.FeatureAttributes;
 import jalview.datamodel.features.FeatureLocationI;
 import jalview.datamodel.features.FeatureSourceI;
 import jalview.datamodel.features.FeatureSources;
@@ -55,7 +56,7 @@ public class SequenceFeature implements FeatureLocationI
   // private key for ENA location designed not to conflict with real GFF data
   private static final String LOCATION = "!Location";
 
-  private static final String ROW_DATA = "<tr><td width=\"10%%\">%s</td><td width=\"50%%\">%s</td><td width=\"40%%\">%s</td></tr>";
+  private static final String ROW_DATA = "<tr><td>%s</td><td>%s</td><td>%s</td></tr>";
 
   /*
    * map of otherDetails special keys, and their value fields' delimiter
@@ -179,6 +180,8 @@ public class SequenceFeature implements FeatureLocationI
     this(newType, sf.getDescription(), newBegin, newEnd, newScore,
             newGroup);
 
+    this.source = sf.source;
+
     if (sf.otherDetails != null)
     {
       otherDetails = new HashMap<String, Object>();
@@ -390,6 +393,23 @@ public class SequenceFeature implements FeatureLocationI
   }
 
   /**
+   * Answers the value of the specified attribute as string, or null if no such
+   * value
+   * 
+   * @param key
+   * @return
+   */
+  public String getValueAsString(String key)
+  {
+    if (otherDetails == null)
+    {
+      return null;
+    }
+    Object value = otherDetails.get(key);
+    return value == null ? null : value.toString();
+  }
+
+  /**
    * Returns a property value for the given key if known, else the specified
    * default value
    * 
@@ -422,6 +442,7 @@ public class SequenceFeature implements FeatureLocationI
       }
 
       otherDetails.put(key, value);
+      FeatureAttributes.getInstance().addAttribute(this.type, key);
     }
   }
 
@@ -660,9 +681,10 @@ public class SequenceFeature implements FeatureLocationI
       return true;
     }
 
-    FeatureAttributeType attributeType = metadata.getAttributeType(key);
-    if (attributeType == FeatureAttributeType.Float
-            || attributeType.equals(FeatureAttributeType.Integer))
+    FeatureAttributeType attType = metadata.getAttributeType(key);
+    if (attType != null
+            && (attType == FeatureAttributeType.Float || attType
+                    .equals(FeatureAttributeType.Integer)))
     {
       try
       {