JAL-1684 align added alignment to match original in split frame
[jalview.git] / src / jalview / bin / JalviewLite.java
index d0c3829..7112381 100644 (file)
@@ -92,7 +92,7 @@ public class JalviewLite extends Applet implements
   }
 
   // /////////////////////////////////////////
-  // The following public methods maybe called
+  // The following public methods may be called
   // externally, eg via javascript in HTML page
   /*
    * (non-Javadoc)
@@ -956,11 +956,16 @@ public class JalviewLite extends Applet implements
     }
   }
 
-  /*
-   * (non-Javadoc)
-   * 
+  /**
+   * Callable from javascript to register a javascript function to pass events
+   * to a structure viewer.
+   *
+   * @param listener
+   *          the name of a javascript function
+   * @param modelSet
+   *          a token separated list of PDB file names listened for
    * @see jalview.bin.JalviewLiteJsApi#setStructureListener(java.lang.String,
-   * java.lang.String)
+   *      java.lang.String)
    */
   public void setStructureListener(String listener, String modelSet)
   {
@@ -1345,9 +1350,10 @@ public class JalviewLite extends Applet implements
   /**
    * init method for Jalview Applet
    */
+  @Override
   public void init()
   {
-    // remove any handlers that might be hanging around from an earlier instance
+    debug = TRUE.equalsIgnoreCase(getParameter("debug"));
     try
     {
       if (debug)
@@ -1370,23 +1376,17 @@ public class JalviewLite extends Applet implements
         ex.printStackTrace();
       }
     }
-    /**
-     * turn on extra applet debugging
-     */
-    debug = TRUE.equalsIgnoreCase(getParameter("debug"));
+
     if (debug)
     {
-
       System.err.println("JalviewLite Version " + getVersion());
       System.err.println("Build Date : " + getBuildDate());
       System.err.println("Installation : " + getInstallation());
-
     }
     String externalsviewer = getParameter("externalstructureviewer");
     if (externalsviewer != null)
     {
-      useXtrnalSviewer = externalsviewer.trim().toLowerCase()
-              .equals(TRUE);
+      useXtrnalSviewer = externalsviewer.trim().toLowerCase().equals(TRUE);
     }
     /**
      * if true disable the check for jmol
@@ -1412,7 +1412,9 @@ public class JalviewLite extends Applet implements
       }
       else
       {
-        throw new Error(MessageManager.getString("error.invalid_separator_parameter"));
+        throw new Error(
+                MessageManager
+                        .getString("error.invalid_separator_parameter"));
       }
     }
     int r = 255;
@@ -1884,8 +1886,11 @@ public class JalviewLite extends Applet implements
       {
         AlignmentI al1 = af.viewport.getAlignment();
         AlignmentI al2 = af2.viewport.getAlignment();
-        if (AlignmentUtils.isMappable(al1, al2))
+        AlignmentI cdna = al1.isNucleotide() ? al1 : al2;
+        AlignmentI prot = al1.isNucleotide() ? al2 : al1;
+        if (AlignmentUtils.mapProteinAlignmentToCdna(prot, cdna))
         {
+          al2.alignAs(al1);
           SplitFrame sf = new SplitFrame(af, af2);
           sf.addToDisplay(embedded, JalviewLite.this);
           return;
@@ -1921,7 +1926,8 @@ public class JalviewLite extends Applet implements
       AlignmentI al = null;
       try
       {
-        al = new AppletFormatAdapter().readFile(resolvedFile, protocol, format);
+        al = new AppletFormatAdapter().readFile(resolvedFile, protocol,
+                format);
         if ((al != null) && (al.getHeight() > 0))
         {
           dbgMsg("Successfully loaded file.");
@@ -1939,13 +1945,13 @@ public class JalviewLite extends Applet implements
           if (protocol == AppletFormatAdapter.PASTE)
           {
             newAlignFrame.setTitle(MessageManager.formatMessage(
-                    "label.sequences_from", new Object[]
-                    { applet.getDocumentBase().toString() }));
+                    "label.sequences_from", new Object[] { applet
+                            .getDocumentBase().toString() }));
           }
 
           newAlignFrame.statusBar.setText(MessageManager.formatMessage(
-                  "label.successfully_loaded_file", new Object[]
-                  { resolvedFile }));
+                  "label.successfully_loaded_file",
+                  new Object[] { resolvedFile }));
 
           return newAlignFrame;
         }
@@ -2040,10 +2046,9 @@ public class JalviewLite extends Applet implements
             String sequence = applet.getParameter("PDBSEQ");
             if (sequence != null)
             {
-              seqs = new SequenceI[]
-              { matcher == null ? (Sequence) alignFrame.getAlignViewport()
-                      .getAlignment().findName(sequence) : matcher
-                      .findIdMatch(sequence) };
+              seqs = new SequenceI[] { matcher == null ? (Sequence) alignFrame
+                      .getAlignViewport().getAlignment().findName(sequence)
+                      : matcher.findIdMatch(sequence) };
             }
 
           }
@@ -2125,8 +2130,8 @@ public class JalviewLite extends Applet implements
             }
             else
             {
-              pdbs.addElement(new Object[]
-              { pdb, seqs, chains, new String(protocol) });
+              pdbs.addElement(new Object[] { pdb, seqs, chains,
+                  new String(protocol) });
             }
           }
         }
@@ -2351,26 +2356,26 @@ public class JalviewLite extends Applet implements
     /**
      * Discovers whether the given file is in the Applet Archive
      * 
-     * @param file
+     * @param f
      *          String
      * @return boolean
      */
-    boolean inArchive(String file)
+    boolean inArchive(String f)
     {
       // This might throw a security exception in certain browsers
       // Netscape Communicator for instance.
       try
       {
-        boolean rtn = (getClass().getResourceAsStream("/" + file) != null);
+        boolean rtn = (getClass().getResourceAsStream("/" + f) != null);
         if (debug)
         {
-          System.err.println("Resource '" + file + "' was "
-                  + (rtn ? "" : "not") + " located by classloader.");
+          System.err.println("Resource '" + f + "' was "
+                  + (rtn ? "" : "not ") + "located by classloader.");
         }
         return rtn;
       } catch (Exception ex)
       {
-        System.out.println("Exception checking resources: " + file + " "
+        System.out.println("Exception checking resources: " + f + " "
                 + ex);
         return false;
       }
@@ -2401,8 +2406,7 @@ public class JalviewLite extends Applet implements
         if (debug)
         {
           System.err.println("Prepended document base '" + documentBase
-                  + "' to make: '" + url
-                  + "'");
+                  + "' to make: '" + url + "'");
         }
         return url;
       }
@@ -2512,8 +2516,9 @@ public class JalviewLite extends Applet implements
    * @param separator
    * @return elements separated by separator
    */
-  public String[] separatorListToArray(String list, String separator)
+  public static String[] separatorListToArray(String list, String separator)
   {
+    // TODO use StringUtils version (slightly different...)
     int seplen = separator.length();
     if (list == null || list.equals("") || list.equals(separator))
     {
@@ -2579,8 +2584,9 @@ public class JalviewLite extends Applet implements
    * @param separator
    * @return concatenated string
    */
-  public String arrayToSeparatorList(String[] list, String separator)
+  public static String arrayToSeparatorList(String[] list, String separator)
   {
+    // TODO use StringUtils version
     StringBuffer v = new StringBuffer();
     if (list != null && list.length > 0)
     {
@@ -2911,8 +2917,7 @@ public class JalviewLite extends Applet implements
     if (url.indexOf("/") == 0)
     {
       String localfile = localref.getFile();
-      url = codebase.substring(0, codebase.length()
-              - localfile.length())
+      url = codebase.substring(0, codebase.length() - localfile.length())
               + url;
     }
     else