2.08, not 2.07
[jalview.git] / src / jalview / bin / JalviewLite.java
index c4e17fb..199a843 100755 (executable)
@@ -45,7 +45,13 @@ public class JalviewLite extends Applet
     String file = "No file";\r
     Button launcher = new Button("Start Jalview");\r
 \r
+    //The currentAlignFrame is static, it will change\r
+    //if and when the user selects a new window\r
     static AlignFrame currentAlignFrame;\r
+\r
+    //This is the first frame to be displayed, and does not change\r
+    AlignFrame initialAlignFrame;\r
+\r
     boolean embedded = false;\r
 \r
 \r
@@ -82,17 +88,13 @@ public class JalviewLite extends Applet
         this.setBackground(new Color(r, g, b));\r
 \r
         file = getParameter("file");\r
-        if(file.indexOf("://")==-1)\r
-               file = getCodeBase() + file;\r
 \r
         final JalviewLite applet = this;\r
         if(getParameter("embedded")!=null\r
            && getParameter("embedded").equalsIgnoreCase("true"))\r
         {\r
           embedded = true;\r
-          LoadingThread loader = new LoadingThread(file,\r
-                            "URL",\r
-                            applet);\r
+          LoadingThread loader = new LoadingThread(file, applet);\r
           loader.start();\r
         }\r
         else if (file != null)\r
@@ -104,7 +106,6 @@ public class JalviewLite extends Applet
                     public void actionPerformed(ActionEvent e)\r
                     {\r
                         LoadingThread loader = new LoadingThread(file,\r
-                            "URL",\r
                             applet);\r
                         loader.start();\r
                       }\r
@@ -126,17 +127,18 @@ public class JalviewLite extends Applet
         System.exit(1);\r
       }\r
 \r
-      String format = jalview.io.IdentifyFile.Identify(args[0],"File");\r
+      String format = new jalview.io.IdentifyFile().Identify(args[0],AppletFormatAdapter.FILE);\r
+\r
       SequenceI[] sequences = null;\r
      try{\r
-       sequences = new AppletFormatAdapter().readFile(args[0], "File", format);\r
+       sequences = new AppletFormatAdapter().readFile(args[0], AppletFormatAdapter.FILE, format);\r
      }catch(java.io.IOException ex)\r
      {\r
        ex.printStackTrace();\r
      }\r
       if ( (sequences != null) && (sequences.length > 0))\r
       {\r
-        AlignFrame af = new AlignFrame(new Alignment(sequences), null, args[0]);\r
+        AlignFrame af = new AlignFrame(new Alignment(sequences), null, args[0], false);\r
         af.statusBar.setText("Successfully loaded file " + args[0]);\r
       }\r
     }\r
@@ -167,7 +169,7 @@ public class JalviewLite extends Applet
                       currentAlignFrame = null;\r
                     }\r
                     lastFrameX -=40;\r
-                    lastFrameY-=40;\r
+                    lastFrameY -=40;\r
                     frame.setMenuBar(null);\r
                     frame.dispose();\r
                 }\r
@@ -181,6 +183,23 @@ public class JalviewLite extends Applet
         frame.setVisible(true);\r
     }\r
 \r
+    public String getSelectedSequences()\r
+    {\r
+      StringBuffer result = new StringBuffer("");\r
+\r
+      if(initialAlignFrame.viewport.getSelectionGroup()!=null)\r
+      {\r
+        SequenceI[] seqs = initialAlignFrame.viewport.getSelectionGroup().\r
+            getSequencesInOrder(\r
+                initialAlignFrame.viewport.getAlignment());\r
+\r
+        for (int i = 0; i < seqs.length; i++)\r
+          result.append(seqs[i].getName() + "¬");\r
+      }\r
+\r
+      return result.toString();\r
+    }\r
+\r
     public String getAlignment(String format)\r
     {\r
       return getAlignment(format, "true");\r
@@ -239,14 +258,19 @@ public class JalviewLite extends Applet
         String format;\r
         JalviewLite applet;\r
 \r
-        public LoadingThread(String file,\r
-                             String protocol,\r
-                             JalviewLite applet)\r
+        public LoadingThread(String _file,\r
+                             JalviewLite _applet)\r
         {\r
-            this.file = file;\r
-            this.protocol = protocol;\r
-            format = jalview.io.IdentifyFile.Identify(file, "URL");\r
-            this.applet = applet;\r
+            file = _file;\r
+            if(inArchive(file))\r
+              protocol = AppletFormatAdapter.CLASSLOADER;\r
+            else\r
+            {\r
+              file = addProtocol(file);\r
+              protocol = AppletFormatAdapter.URL;\r
+            }\r
+            format = new jalview.io.IdentifyFile().Identify(file, protocol);\r
+            applet = _applet;\r
         }\r
 \r
         public void run()\r
@@ -262,9 +286,11 @@ public class JalviewLite extends Applet
             if ((sequences != null) && (sequences.length > 0))\r
             {\r
               currentAlignFrame = new AlignFrame(new Alignment(sequences),\r
-                                                 applet, file);\r
-              if (embedded)\r
-                currentAlignFrame.setEmbedded();\r
+                                                 applet,\r
+                                                 file,\r
+                                                 embedded);\r
+\r
+              initialAlignFrame = currentAlignFrame;\r
 \r
               currentAlignFrame.statusBar.setText("Successfully loaded file " + file);\r
 \r
@@ -272,22 +298,23 @@ public class JalviewLite extends Applet
                 String treeFile = applet.getParameter("treeFile");\r
                 if (treeFile != null)\r
                 {\r
-                  if (treeFile.indexOf("://") == -1)\r
-                    treeFile = getCodeBase() + treeFile;\r
-\r
                   try\r
                   {\r
-                    jalview.io.NewickFile fin = new jalview.io.NewickFile(treeFile, "URL");\r
+                    if(inArchive(treeFile))\r
+                      protocol = AppletFormatAdapter.CLASSLOADER;\r
+                    else\r
+                    {\r
+                      protocol = AppletFormatAdapter.URL;\r
+                      treeFile = addProtocol(treeFile);\r
+                    }\r
+\r
+                    jalview.io.NewickFile fin = new jalview.io.NewickFile(treeFile, protocol);\r
+\r
                     fin.parse();\r
 \r
                     if (fin.getTree() != null)\r
                     {\r
-                      TreePanel tp = null;\r
-                      tp = new TreePanel(currentAlignFrame.viewport,\r
-                                         currentAlignFrame.viewport.getAlignment().getSequences(),\r
-                                         fin, "FromFile", treeFile);\r
-                      addFrame(tp, treeFile, 600, 500);\r
-                      currentAlignFrame.addTreeMenuItem(tp, treeFile);\r
+                      currentAlignFrame.loadTree(fin, treeFile);\r
                     }\r
                   }\r
                   catch (Exception ex)\r
@@ -299,8 +326,8 @@ public class JalviewLite extends Applet
               String param = getParameter("features");\r
               if (param != null)\r
               {\r
-                if (param.indexOf("://") == -1)\r
-                  param = getCodeBase() + param;\r
+                if( !inArchive(param) )\r
+                  param = addProtocol( param );\r
 \r
                 currentAlignFrame.parseFeaturesFile(param);\r
               }\r
@@ -308,8 +335,8 @@ public class JalviewLite extends Applet
              param = getParameter("annotations");\r
              if (param != null)\r
              {\r
-               if (param.indexOf("://") == -1)\r
-                 param = getCodeBase() + param;\r
+               if( !inArchive(param) )\r
+                  param = addProtocol( param );\r
 \r
                new AnnotationReader().readAnnotationFile(\r
                    currentAlignFrame.viewport.getAlignment(),\r
@@ -322,14 +349,19 @@ public class JalviewLite extends Applet
                 String pdbfile = applet.getParameter("PDBFILE");\r
                 if(pdbfile!=null)\r
                 {\r
-                  if(pdbfile.indexOf("://")==-1)\r
-                       pdbfile = getCodeBase() + pdbfile;\r
+                  if( inArchive(pdbfile) )\r
+                    protocol = AppletFormatAdapter.CLASSLOADER;\r
+                  else\r
+                  {\r
+                    protocol = AppletFormatAdapter.URL;\r
+                    pdbfile = addProtocol(pdbfile);\r
+                  }\r
 \r
                   String sequence = applet.getParameter("PDBSEQ");\r
 \r
                   if(sequence!=null)\r
                   {\r
-                    new MCview.AppletPDBViewer(pdbfile, "URL",\r
+                    new MCview.AppletPDBViewer(pdbfile, protocol,\r
                                                (Sequence)currentAlignFrame.getAlignViewport().getAlignment().findName(sequence),\r
                                                currentAlignFrame.getSeqcanvas());\r
                   }\r
@@ -343,5 +375,32 @@ public class JalviewLite extends Applet
                 repaint();\r
             }\r
         }\r
+\r
+        /**\r
+         * Discovers whether the given file is in the Applet Archive\r
+         * @param file String\r
+         * @return boolean\r
+         */\r
+        boolean inArchive(String file)\r
+        {\r
+          //This might throw a security exception in certain browsers\r
+          //Netscape Communicator for instance.\r
+          try{\r
+            return (getClass().getResourceAsStream("/" + file) != null);\r
+          }catch(Exception ex)\r
+          {\r
+            System.out.println("Exception checking resources: "+file+" "+ex);\r
+            return false;\r
+          }\r
+        }\r
+\r
+        String addProtocol(String file)\r
+        {\r
+          if (file.indexOf("://") == -1)\r
+             file = getCodeBase() + file;\r
+\r
+          return file;\r
+        }\r
+\r
     }\r
 }\r