remove system.out
[jalview.git] / src / jalview / bin / JalviewLite.java
index 2a715a6..e0f0910 100755 (executable)
@@ -22,6 +22,7 @@ import java.applet.*;
 
 import java.awt.*;
 import java.awt.event.*;
+import java.util.*;
 
 import jalview.appletgui.*;
 import jalview.datamodel.*;
@@ -156,18 +157,6 @@ public class JalviewLite
    */
   public void init()
   {
-    try
-    {
-      Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter",
-                    true, Thread.currentThread().getContextClassLoader());
-
-      jmolAvailable = true;
-    }
-    catch (java.lang.ClassNotFoundException ex)
-    {
-      System.out.println("Jmol not found - Using MCview for structures");
-    }
-
     int r = 255;
     int g = 255;
     int b = 255;
@@ -215,6 +204,9 @@ public class JalviewLite
       }
     }
 
+    LoadJmolThread jmolAvailable = new LoadJmolThread();
+    jmolAvailable.start();
+
     final JalviewLite applet = this;
     if (getParameter("embedded") != null
         && getParameter("embedded").equalsIgnoreCase("true"))
@@ -244,33 +236,6 @@ public class JalviewLite
     }
   }
 
-  public static void main(String[] args)
-  {
-    if (args.length != 1)
-    {
-      System.out.println("\nUsage: java -jar jalviewApplet.jar fileName\n");
-      System.exit(1);
-    }
-
-    String format = new jalview.io.IdentifyFile().Identify(args[0],
-        AppletFormatAdapter.FILE);
-
-    Alignment al = null;
-    try
-    {
-      al = new AppletFormatAdapter().readFile(args[0], AppletFormatAdapter.FILE,
-                                              format);
-    }
-    catch (java.io.IOException ex)
-    {
-      ex.printStackTrace();
-    }
-    if ( (al != null) && (al.getHeight() > 0))
-    {
-      AlignFrame af = new AlignFrame(al, null, args[0], false);
-      af.statusBar.setText("Successfully loaded file " + args[0]);
-    }
-  }
 
   /**
    * Initialises and displays a new java.awt.Frame
@@ -343,9 +308,30 @@ public class JalviewLite
       g.drawString("Jalview Applet", 50, this.getSize().height / 2 - 30);
       g.drawString("Loading Data...", 50, this.getSize().height / 2);
     }
+  }
+
 
+  class LoadJmolThread extends Thread
+  {
+    public void run()
+    {
+      try
+      {
+        if (!System.getProperty("java.version").startsWith("1.1"))
+        {
+          Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter");
+          jmolAvailable = true;
+          System.out.println("JMOL FOUND");
+        }
+      }
+      catch (java.lang.ClassNotFoundException ex)
+      {
+        System.out.println("Jmol not available - Using MCview for structures");
+      }
+    }
   }
 
+
   class LoadingThread
       extends Thread
   {
@@ -378,6 +364,11 @@ public class JalviewLite
 
     public void run()
     {
+      startLoading();
+    }
+
+    private void startLoading()
+    {
       Alignment al = null;
       try
       {
@@ -505,44 +496,108 @@ public class JalviewLite
           }
         }
 
+        /*
+         <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B PDB|1GAQ|1GAQ|C">
 
-        param = getParameter("PDBFILE");
-        if (param != null)
-        {
+         <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
+
+         <param name="PDBfile3" value="1q0o Q45135_9MICO">
+        */
 
-          PDBEntry pdb = new PDBEntry();
 
-          if (!inArchive(param) || jmolAvailable)
+        int pdbFileCount = 0;
+        do{
+          if (pdbFileCount > 0)
+            param = getParameter("PDBFILE" + pdbFileCount);
+          else
+            param = getParameter("PDBFILE");
+
+          if (param != null)
           {
-            param = addProtocol(param);
-          }
+            PDBEntry pdb = new PDBEntry();
 
-          pdb.setFile(param);
+            String seqstring;
+            SequenceI[] seqs = null;
+            String [] chains = null;
 
-          String sequence = applet.getParameter("PDBSEQ");
+            StringTokenizer st = new StringTokenizer(param, " ");
 
-          if (sequence != null)
-          {
-            if (jmolAvailable)
-              new jalview.appletgui.AppletJmol(pdb,
-                                               new SequenceI[]
-                                               { (Sequence) currentAlignFrame.
-                                               getAlignViewport().getAlignment().
-                                               findName(sequence)},
-                                               currentAlignFrame.alignPanel,
-                                               protocol);
+            if (st.countTokens() < 2)
+            {
+              String sequence = applet.getParameter("PDBSEQ");
+              if (sequence != null)
+                seqs = new SequenceI[]
+                    {
+                    (Sequence) currentAlignFrame.
+                    getAlignViewport().getAlignment().
+                    findName(sequence)};
+
+            }
             else
+            {
+              param = st.nextToken();
+              Vector tmp = new Vector();
+              Vector tmp2 = new Vector();
+
+              while (st.hasMoreTokens())
+              {
+                seqstring = st.nextToken();
+                StringTokenizer st2 = new StringTokenizer(seqstring,"=");
+                if(st2.countTokens()>1)
+                {
+                  //This is the chain
+                  tmp2.addElement(st2.nextToken());
+                  seqstring = st2.nextToken();
+                }
+                tmp.addElement( (Sequence) currentAlignFrame.
+                                 getAlignViewport().getAlignment().
+                                 findName(seqstring));
+              }
+
+              seqs = new SequenceI[tmp.size()];
+              tmp.copyInto(seqs);
+              if(tmp2.size()==tmp.size())
+              {
+                chains = new String[tmp2.size()];
+                tmp2.copyInto(chains);
+              }
+            }
+
+            param = addProtocol(param);
+            pdb.setFile(param);
 
-              new MCview.AppletPDBViewer(pdb,
-                                         new SequenceI[]
-                                         { (Sequence) currentAlignFrame.
-                                         getAlignViewport().getAlignment().
-                                         findName(sequence)},
-                                         currentAlignFrame.alignPanel,
-                                         protocol);
+            if(seqs!=null)
+            {
+              for (int i = 0; i < seqs.length; i++)
+              {
+                ( (Sequence) seqs[i]).addPDBId(pdb);
+              }
+
+              if (jmolAvailable)
+              {
+                new jalview.appletgui.AppletJmol(pdb,
+                                                 seqs,
+                                                 chains,
+                                                 currentAlignFrame.alignPanel,
+                                                 protocol);
+                lastFrameX += 40;
+                lastFrameY+=40;
+
+                System.out.println(lastFrameX+" "+lastFrameY);
+              }
+              else
+                    new MCview.AppletPDBViewer(pdb,
+                                           seqs,
+                                           chains,
+                                           currentAlignFrame.alignPanel,
+                                           protocol);
+            }
           }
 
+          pdbFileCount++;
         }
+        while(pdbFileCount < 10);
+
       }
       else
       {