added separator parameter with default of '|' to control the list separator to use...
[jalview.git] / src / jalview / bin / JalviewLite.java
index 4d1c216..5b103c5 100755 (executable)
@@ -48,9 +48,9 @@ public class JalviewLite
    */
   public String getSelectedSequences()
   {
-    return getSelectedSequences(currentAlignFrame);
+    return getSelectedSequencesFrom(currentAlignFrame);
   }
-  public String getSelectedSequences(AlignFrame alf)
+  public String getSelectedSequencesFrom(AlignFrame alf)
   {
     StringBuffer result = new StringBuffer("");
 
@@ -71,17 +71,17 @@ public class JalviewLite
   
   public String getAlignment(String format)
   {
-    return getAlignment(currentAlignFrame, format, "true");
+    return getAlignmentFrom(currentAlignFrame, format, "true");
   }
-  public String getAlignment(AlignFrame alf, String format)
+  public String getAlignmentFrom(AlignFrame alf, String format)
   {
-    return getAlignment(alf, format, "true");
+    return getAlignmentFrom(alf, format, "true");
   }
   public String getAlignment(String format, String suffix)
   {
-    return getAlignment(currentAlignFrame, format, suffix);
+    return getAlignmentFrom(currentAlignFrame, format, suffix);
   }
-  public String getAlignment(AlignFrame alf, String format, String suffix)
+  public String getAlignmentFrom(AlignFrame alf, String format, String suffix)
   {
     try
     {
@@ -100,9 +100,9 @@ public class JalviewLite
 
   public void loadAnnotation(String annotation)
   {
-    loadAnnotation(currentAlignFrame, annotation);
+    loadAnnotationFrom(currentAlignFrame, annotation);
   }
-  public void loadAnnotation(AlignFrame alf, String annotation)
+  public void loadAnnotationFrom(AlignFrame alf, String annotation)
   {
     if (new AnnotationFile().readAnnotationFile(
         alf.getAlignViewport().getAlignment(), annotation,
@@ -119,34 +119,34 @@ public class JalviewLite
 
   public String getFeatures(String format)
   {
-    return getFeatures(currentAlignFrame, format);
+    return getFeaturesFrom(currentAlignFrame, format);
   }
-  public String getFeatures(AlignFrame alf, String format)
+  public String getFeaturesFrom(AlignFrame alf, String format)
   {
     return alf.outputFeatures(false, format);
   }
   public String getAnnotation()
   {
-    return getAnnotation(currentAlignFrame);
+    return getAnnotationFrom(currentAlignFrame);
   }
-  public String getAnnotation(AlignFrame alf)
+  public String getAnnotationFrom(AlignFrame alf)
   {
     return alf.outputAnnotations(false);
   }
   public AlignFrame newView()
   {
-    return newView(currentAlignFrame);
+    return newViewFrom(currentAlignFrame);
   }
   public AlignFrame newView(String name)
   {
-    return newView(currentAlignFrame, name);
+    return newViewFrom(currentAlignFrame, name);
   }
 
-  public AlignFrame newView(AlignFrame alf)
+  public AlignFrame newViewFrom(AlignFrame alf)
   {
     return alf.newView(null);
   }
-  public AlignFrame newView(AlignFrame alf, String name)
+  public AlignFrame newViewFrom(AlignFrame alf, String name)
   {
     return alf.newView(name);
   }
@@ -198,12 +198,34 @@ public class JalviewLite
   boolean embedded = false;
 
   public boolean jmolAvailable = false;
+  public static boolean debug;
 
   /**
    * init method for Jalview Applet
    */
   public void init()
   {
+    String dbg = getParameter("debug");
+    if (dbg!=null)
+    {
+      debug = dbg.toLowerCase().equals("true");
+    }
+    /**
+     * get the separator parameter if present
+     */
+    String sep = getParameter("separator");
+    if (sep!=null)
+    {
+      if (sep.length()>0)
+      {      separator = sep;
+        if (debug)
+        {
+          System.err.println("Separator set to '"+separator+"'");
+        }
+      } else {
+        throw new Error("Invalid separator parameter - must be non-zero length");
+      }
+    }
     int r = 255;
     int g = 255;
     int b = 255;
@@ -323,7 +345,10 @@ public class JalviewLite
         if (frame instanceof AlignFrame)
         {
           currentAlignFrame = (AlignFrame) frame;
-          System.err.println("Activated window "+frame);
+          if (debug)
+          {
+            System.err.println("Activated window "+frame);
+          }
         }
       }
 
@@ -390,6 +415,10 @@ public class JalviewLite
     public LoadingThread(String _file,
                          JalviewLite _applet)
     {
+      if (applet.debug)
+      {
+        System.err.println("Loading thread started with:\n>>file\n"+_file+">>endfile");
+      }
       file = _file;
       if (file.startsWith("PASTE"))
       {
@@ -405,7 +434,15 @@ public class JalviewLite
         file = addProtocol(file);
         protocol = AppletFormatAdapter.URL;
       }
+      if (applet.debug)
+      {
+        System.err.println("Protocol identified as '"+protocol+"'");
+      }
       format = new jalview.io.IdentifyFile().Identify(file, protocol);
+      if (applet.debug)
+      {
+        System.err.println("File identified as '"+format+"'");
+      }
       applet = _applet;
     }
 
@@ -651,7 +688,22 @@ public class JalviewLite
           pdbFileCount++;
         }
         while(pdbFileCount < 10);
-
+        
+        /////////////////////////////
+        // modify display of features
+        //
+        // hide specific groups
+        param = getParameter("hidefeaturegroups");
+        if (param != null)
+        {
+          applet.setFeatureGroupState(param, false);
+        }
+        // show specific groups
+        param = getParameter("showfeaturegroups");
+        if (param != null)
+        {
+          applet.setFeatureGroupState(param, true);
+        }
       }
       else
       {
@@ -691,17 +743,26 @@ public class JalviewLite
       return file;
     }
   }
-
-  public String[] tabbedListToArray(String list)
+  /**
+   * separator used for separatorList
+   */
+  protected String separator = "|"; // this is a safe(ish) separator - tabs don't work for firefox
+  /**
+   * parse the string into a list
+   * @param list
+   * @return elements separated by separator
+   */
+  public String[] separatorListToArray(String list)
   {
+    int seplen = separator.length();
     if (list==null || list.equals(""))
       return null;
     java.util.Vector jv = new Vector();
     int cp=0,pos;
-    while ((pos=list.indexOf("\t",cp))>cp)
+    while ((pos=list.indexOf(separator,cp))>cp)
     {
       jv.addElement(list.substring(cp,pos));
-      cp = pos+1;
+      cp = pos+seplen;
     }
     if (cp<list.length())
     {
@@ -709,16 +770,33 @@ public class JalviewLite
     }
     if (jv.size()>0)
     { String[] v = new String[jv.size()];
-      jv.copyInto(v);
+      for (int i=0; i<v.length; i++)
+      {
+        v[i] = (String) jv.elementAt(i);
+      }
       jv.removeAllElements();
-      System.err.println("Array from Tabbed List:\n"+v.length+"\n"+v.toString());
+      if (debug)
+      {
+        System.err.println("Array from '"+separator+"' separated List:\n"+v.length);
+        for (int i=0; i<v.length;i++)
+        {
+          System.err.println("item "+i+" '"+v[i]+"'");
+        }
+      }
       return v;
     }
-    System.err.println("Empty Array from Tabbed List");
+    if (debug)
+    {
+      System.err.println("Empty Array from '"+separator+"' separated List");
+    }
     return null;
   }
-
-  public String ArraytotabbedList(String[] list)
+  /**
+   * concatenate the list with separator
+   * @param list
+   * @return concatenated string
+   */
+  public String arrayToSeparatorList(String[] list)
   {
     StringBuffer v = new StringBuffer();
     if (list!=null)
@@ -729,15 +807,22 @@ public class JalviewLite
         {  
           v.append(list[i]); 
         }
-        v.append("\t");
+        v.append(separator);
       }
       if (list[list.length-1]!=null)
       { v.append(list[list.length-1]);
       }
-      System.err.println("Tabbed List:\n"+v.toString());
+      if (debug)
+      {
+        System.err.println("Returning '"+separator+"' separated List:\n");
+        System.err.println(v);
+      }
       return v.toString();
     }
-    System.err.println("Empty Tabbed List\n");
+    if (debug)
+    {
+      System.err.println("Returning empty '"+separator+"' separated List\n");
+    }
     return "";
   }
   /**
@@ -746,10 +831,19 @@ public class JalviewLite
    */
   public String getFeatureGroups()
   {
-    String lst = ArraytotabbedList(currentAlignFrame.getFeatureGroups());
+    String lst = arrayToSeparatorList(currentAlignFrame.getFeatureGroups());
+    return lst;
+  }
+  /**
+   * @param alf alignframe to get feature groups on
+   * @return
+   * @see jalview.appletgui.AlignFrame#getFeatureGroups()
+   */
+  public String getFeatureGroupsOn(AlignFrame alf)
+  {
+    String lst = arrayToSeparatorList(alf.getFeatureGroups());
     return lst;
   }
-
   /**
    * @param visible
    * @return
@@ -757,20 +851,45 @@ public class JalviewLite
    */
   public String getFeatureGroupsOfState(boolean visible)
   {
-    return ArraytotabbedList(currentAlignFrame.getFeatureGroupsOfState(visible));
+    return arrayToSeparatorList(currentAlignFrame.getFeatureGroupsOfState(visible));
   }
   /**
+   * @param alf align frame to get groups of state visible
+   * @param visible
+   * @return
+   * @see jalview.appletgui.AlignFrame#getFeatureGroupsOfState(boolean)
+   */
+  public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
+  {
+    return arrayToSeparatorList(alf.getFeatureGroupsOfState(visible));
+  }  /**
    * @param groups tab separated list of group names 
    * @param state true or false
    * @see jalview.appletgui.AlignFrame#setFeatureGroupState(java.lang.String[], boolean)
    */
-  public void setFeatureGroupState(AlignFrame alf, String groups, boolean state)
+  public void setFeatureGroupStateOn(AlignFrame alf, String groups, boolean state)
   {
     boolean st = state;//!(state==null || state.equals("") || state.toLowerCase().equals("false"));
-    alf.setFeatureGroupState(tabbedListToArray(groups), st);
+    alf.setFeatureGroupState(separatorListToArray(groups), st);
   }
   public void setFeatureGroupState(String groups, boolean state)
   {
-    setFeatureGroupState(currentAlignFrame, groups, state);
+    setFeatureGroupStateOn(currentAlignFrame, groups, state);
+  }
+  /**
+   * List separator string
+   * @return the separator
+   */
+  public String getSeparator()
+  {
+    return separator;
+  }
+  /**
+   * List separator string
+   * @param separator the separator to set
+   */
+  public void setSeparator(String separator)
+  {
+    this.separator = separator;
   }
 }