Merge branch 'Release_2_7_Branch_hotfix_JAL-962' into Release_2_7_Branch
authorjprocter <jprocter@compbio.dundee.ac.uk>
Fri, 21 Oct 2011 12:09:37 +0000 (13:09 +0100)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Fri, 21 Oct 2011 12:09:37 +0000 (13:09 +0100)
examples/jalviewLiteJs.html
src/jalview/appletgui/AlignFrame.java
src/jalview/appletgui/FeatureRenderer.java
src/jalview/appletgui/FeatureSettings.java
src/jalview/bin/JalviewLite.java
src/jalview/javascript/JalviewLiteJsApi.java

index e33b30d..197ef56 100644 (file)
@@ -215,11 +215,21 @@ public String getAlignmentFrom(AlignFrame alf, String format)
 public String getAlignmentFrom(AlignFrame alf, String format, String suffix)
 
 // add the given features or annotation to the current alignment
+// if features are loaded, feature display is automatically enabled
 public void loadAnnotation(String annotation)
 
 // add the given features or annotation to the given alignment view
+// if features are loaded, feature display is automatically enabled
 public void loadAnnotationFrom(AlignFrame alf, String annotation)
 
+// parse the given string as a jalview or GFF features file and optionally enable feature display on the current alignment
+// (v2.7.1)
+public abstract void loadFeatures(String features, boolean autoenabledisplay)
+
+// parse the given string as a jalview or GFF features file and optionally enable feature display on the given alignment
+// (v2.7.1)
+public abstract void loadFeaturesFrom(AlignFrame alf, String features, boolean autoenabledisplay)
+
 // get the sequence features in the given format (Jalview or GFF)
 public String getFeatures(String format)
 
index 759075a..5790bc3 100644 (file)
@@ -161,14 +161,26 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   }\r
 \r
   /**\r
-   * DOCUMENT ME!\r
+   * Load a features file onto the alignment\r
    * \r
-   * @param String\r
-   *          DOCUMENT ME!\r
+   * @param file file URL, content, or other resolvable path\r
+   * @param type is protocol for accessing data referred to by file\r
    */\r
 \r
   public void parseFeaturesFile(String file, String type)\r
   {\r
+    parseFeaturesFile(file, type, true);\r
+  }\r
+  \r
+  /**\r
+   * Load a features file onto the alignment\r
+   * \r
+   * @param file file URL, content, or other resolvable path\r
+   * @param type is protocol for accessing data referred to by file\r
+   * @param autoenabledisplay when true, display features flag will be automatically enabled if features are loaded\r
+   */\r
+  public void parseFeaturesFile(String file, String type, boolean autoenabledisplay)\r
+  {    \r
     Hashtable featureLinks = new Hashtable();\r
     boolean featuresFile = false;\r
     try\r
@@ -188,8 +200,11 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       {\r
         alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureLinks = featureLinks;\r
       }\r
-      viewport.showSequenceFeatures = true;\r
-      sequenceFeatures.setState(true);\r
+      if (autoenabledisplay)\r
+      {\r
+        viewport.showSequenceFeatures = true;\r
+        sequenceFeatures.setState(true);\r
+      }\r
       if (viewport.featureSettings != null)\r
       {\r
         viewport.featureSettings.refreshTable();\r
index 39249cc..03f15d3 100755 (executable)
@@ -1064,9 +1064,9 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer
       for (int i = 0; i < toset.length; i++)
       {
         Object st = featureGroups.get(toset[i]);
+        featureGroups.put(toset[i], new Boolean(visible));
         if (st != null)
         {
-          featureGroups.put(toset[i], new Boolean(visible));
           rdrw = rdrw || (visible != ((Boolean) st).booleanValue());
         }
       }
@@ -1090,6 +1090,7 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer
     }
   }
 
+  ArrayList<String> hiddenGroups=new ArrayList<String>();
   /**
    * analyse alignment for groups and hash tables (used to be embedded in
    * FeatureSettings.setTableData)
@@ -1103,8 +1104,10 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer
     {
       featureGroups = new Hashtable();
     }
-    Vector allFeatures = new Vector();
-    Vector allGroups = new Vector();
+    hiddenGroups =new ArrayList<String>();
+    hiddenGroups.addAll(featureGroups.keySet());
+    ArrayList allFeatures = new ArrayList();
+    ArrayList allGroups = new ArrayList();
     SequenceFeature[] tmpfeatures;
     String group;
     for (int i = 0; i < av.alignment.getHeight(); i++)
@@ -1123,9 +1126,11 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer
         if (tmpfeatures[index].getFeatureGroup() != null)
         {
           group = tmpfeatures[index].featureGroup;
+          // Remove group from the hiddenGroup list
+          hiddenGroups.remove(group);
           if (!allGroups.contains(group))
           {
-            allGroups.addElement(group);
+            allGroups.add(group);
 
             boolean visible = true;
             if (featureGroups.containsKey(group))
@@ -1141,7 +1146,7 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer
 
         if (!allFeatures.contains(tmpfeatures[index].getType()))
         {
-          allFeatures.addElement(tmpfeatures[index].getType());
+          allFeatures.add(tmpfeatures[index].getType());
         }
         index++;
       }
index e137416..ee0e23d 100755 (executable)
@@ -118,8 +118,10 @@ public class FeatureSettings extends Panel implements ItemListener,
 
     if (groupPanel != null)
     {
-      groupPanel.setLayout(new GridLayout(fr.featureGroups.size() / 4 + 1,
-              4));
+      groupPanel
+              .setLayout(new GridLayout(
+                      (fr.featureGroups.size() - fr.hiddenGroups.size()) / 4 + 1,
+                      4));
       groupPanel.validate();
 
       add(groupPanel, BorderLayout.NORTH);
@@ -261,7 +263,7 @@ public class FeatureSettings extends Panel implements ItemListener,
       rdrw = true;
       groupPanel.removeAll();
     }
-
+    // TODO: JAL-964 - smoothly incorporate new group entries if panel already displayed and new groups present
     Enumeration gps = fr.featureGroups.keys();
     while (gps.hasMoreElements())
     {
@@ -273,6 +275,7 @@ public class FeatureSettings extends Panel implements ItemListener,
       check.addMouseListener(this);
       check.setFont(new Font("Serif", Font.BOLD, 12));
       check.addItemListener(this);
+      check.setVisible(fr.hiddenGroups.contains(group));
       groupPanel.add(check);
     }
     if (rdrw)
index 52e7408..0cba50e 100644 (file)
@@ -716,6 +716,29 @@ public class JalviewLite extends Applet implements
   /*\r
    * (non-Javadoc)\r
    * \r
+   * @see jalview.bin.JalviewLiteJsApi#loadAnnotation(java.lang.String)\r
+   */\r
+  public void loadFeatures(String features, boolean autoenabledisplay)\r
+  {\r
+    loadFeaturesFrom(getDefaultTargetFrame(), features, autoenabledisplay);\r
+  }\r
+\r
+  /*\r
+   * (non-Javadoc)\r
+   * \r
+   * @see\r
+   * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame\r
+   * , java.lang.String)\r
+   */\r
+  public void loadFeaturesFrom(AlignFrame alf, String features, boolean autoenabledisplay)\r
+  {\r
+    alf.parseFeaturesFile(features, AppletFormatAdapter.PASTE, autoenabledisplay);\r
+  }\r
+\r
+\r
+  /*\r
+   * (non-Javadoc)\r
+   * \r
    * @see jalview.bin.JalviewLiteJsApi#getFeatures(java.lang.String)\r
    */\r
   public String getFeatures(String format)\r
@@ -1840,7 +1863,27 @@ public class JalviewLite extends Applet implements
           }\r
         }\r
 \r
-        String param = applet.getParameter("features");\r
+        // ///////////////////////////\r
+        // modify display of features\r
+        // we do this before any features have been loaded, ensuring any hidden groups are hidden when features first displayed\r
+        //\r
+        // hide specific groups\r
+        // \r
+        String param = applet.getParameter("hidefeaturegroups");\r
+        if (param != null)\r
+        {\r
+          newAlignFrame.setFeatureGroupState(separatorListToArray(param), false);        \r
+//          applet.setFeatureGroupStateOn(newAlignFrame, param, false);\r
+        }\r
+        // show specific groups\r
+        param = applet.getParameter("showfeaturegroups");\r
+        if (param != null)\r
+        {\r
+          newAlignFrame.setFeatureGroupState(separatorListToArray(param), true);        \r
+//          applet.setFeatureGroupStateOn(newAlignFrame, param, true);\r
+        }\r
+        // and now load features\r
+        param = applet.getParameter("features");\r
         if (param != null)\r
         {\r
           param = setProtocolState(param);\r
@@ -2059,21 +2102,6 @@ public class JalviewLite extends Applet implements
                   protocols);\r
 \r
         }\r
-        // ///////////////////////////\r
-        // modify display of features\r
-        //\r
-        // hide specific groups\r
-        param = applet.getParameter("hidefeaturegroups");\r
-        if (param != null)\r
-        {\r
-          applet.setFeatureGroupStateOn(newAlignFrame, param, false);\r
-        }\r
-        // show specific groups\r
-        param = applet.getParameter("showfeaturegroups");\r
-        if (param != null)\r
-        {\r
-          applet.setFeatureGroupStateOn(newAlignFrame, param, true);\r
-        }\r
       }\r
       else\r
       {\r
index 103e7da..d064790 100644 (file)
@@ -280,6 +280,21 @@ public interface JalviewLiteJsApi
   public abstract void loadAnnotationFrom(AlignFrame alf, String annotation);
 
   /**
+   * parse the given string as a jalview feature or GFF annotation file and optionally enable feature display on the current alignFrame
+   * @param features - gff or features file
+   * @param autoenabledisplay - when true, feature display will be enabled if any features can be parsed from the string.
+   */
+  public abstract void loadFeatures(String features, boolean autoenabledisplay);
+
+  /**
+   * parse the given string as a jalview feature or GFF annotation file and optionally enable feature display on the given alignFrame.
+   * @param alf
+   * @param features - gff or features file
+   * @param autoenabledisplay - when true, feature display will be enabled if any features can be parsed from the string.
+   */
+  public abstract void loadFeaturesFrom(AlignFrame alf, String features, boolean autoenabledisplay);
+
+  /**
    * get the sequence features in the given format (Jalview or GFF)
    * @param format
    * @return