+ return result.toString();\r
+ }\r
+\r
+ public String getAlignment(String format)\r
+ {\r
+ return getAlignment(format, "true");\r
+ }\r
+\r
+ public String getAlignment(String format, String suffix)\r
+ {\r
+ try\r
+ {\r
+ boolean seqlimits = suffix.equalsIgnoreCase("true");\r
+\r
+ String reply = new AppletFormatAdapter().formatSequences(format,\r
+ currentAlignFrame.viewport.getAlignment().getSequences(), seqlimits);\r
+ return reply;\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ return "Error retrieving alignment in " + format + " format. ";\r
+ }\r
+ }\r
+\r
+ /**\r
+ * This paints the background surrounding the "Launch Jalview button"\r
+ * <br>\r
+ * <br>If file given in parameter not found, displays error message\r
+ *\r
+ * @param g graphics context\r
+ */\r
+ public void paint(Graphics g)\r
+ {\r
+ if (!fileFound)\r
+ {\r
+ g.setColor(new Color(200, 200, 200));\r
+ g.setColor(Color.cyan);\r
+ g.fillRect(0, 0, getSize().width, getSize().height);\r
+ g.setColor(Color.red);\r
+ g.drawString("Jalview can't open file", 5, 15);\r
+ g.drawString("\"" + file + "\"", 5, 30);\r
+ }\r
+ else if(embedded)\r
+ {\r
+ g.setColor(Color.black);\r
+ g.setFont(new Font("Arial", Font.BOLD, 24));\r
+ g.drawString("Jalview Applet", 50, this.size().height/2 -30);\r
+ g.drawString("Loading Data...", 50, this.size().height/2);\r
+ }\r
+\r
+\r
+ }\r
+\r
+ class LoadingThread extends Thread\r
+ {\r
+ String file;\r
+ String protocol;\r
+ String format;\r
+ JalviewLite applet;\r
+\r
+ public LoadingThread(String _file,\r
+ JalviewLite _applet)\r
+ {\r
+ file = _file;\r
+ if(file.startsWith("PASTE"))\r
+ {\r
+ file = file.substring(5);\r
+ protocol = AppletFormatAdapter.PASTE;\r
+ }\r
+ else 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
+ {\r
+ SequenceI[] sequences = null;\r
+ try{\r
+ sequences = new AppletFormatAdapter().readFile(file, protocol,\r
+ format);\r
+ }catch(java.io.IOException ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\r
+ if ((sequences != null) && (sequences.length > 0))\r
+ {\r
+ currentAlignFrame = new AlignFrame(new Alignment(sequences),\r
+ applet,\r
+ file,\r
+ embedded);\r
+\r
+ if(protocol==jalview.io.AppletFormatAdapter.PASTE)\r
+ currentAlignFrame.setTitle("Sequences from "+getDocumentBase());\r
+\r
+ initialAlignFrame = currentAlignFrame;\r
+\r
+ currentAlignFrame.statusBar.setText("Successfully loaded file " + file);\r
+\r
+\r
+ String treeFile = applet.getParameter("tree");\r
+ if(treeFile==null)\r
+ treeFile = applet.getParameter("treeFile");\r
+\r
+ if (treeFile != null)\r
+ {\r
+ try\r
+ {\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
+ currentAlignFrame.loadTree(fin, treeFile);\r
+ }\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\r
+ }\r
+\r
+ String param = getParameter("features");\r
+ if (param != null)\r
+ {\r
+ if( !inArchive(param) )\r
+ param = addProtocol( param );\r
+\r
+ currentAlignFrame.parseFeaturesFile(param, protocol);\r
+ }\r
+\r
+ param = getParameter("showFeatureSettings");\r
+ if(param !=null && param.equalsIgnoreCase("true"))\r
+ {\r
+ currentAlignFrame.viewport.showSequenceFeatures(true);\r
+ currentAlignFrame.featureSettings_actionPerformed();\r
+ }\r
+\r
+ param = getParameter("annotations");\r
+ if (param != null)\r
+ {\r
+ if( !inArchive(param) )\r
+ param = addProtocol( param );\r
+\r
+ new AnnotationFile().readAnnotationFile(\r
+ currentAlignFrame.viewport.getAlignment(),\r
+ param);\r
+\r
+ currentAlignFrame.alignPanel.fontChanged();\r
+ currentAlignFrame.alignPanel.setScrollValues(0,0);\r
+\r
+ }\r
+\r
+ param = getParameter("jnetfile");\r
+ if (param != null)\r
+ {\r
+ try\r
+ {\r
+ if (inArchive(param))\r
+ protocol = AppletFormatAdapter.CLASSLOADER;\r
+ else\r
+ {\r
+ protocol = AppletFormatAdapter.URL;\r
+ param = addProtocol(param);\r
+ }\r
+\r
+ jalview.io.JPredFile predictions = new jalview.io.JPredFile(\r
+ param, protocol);\r
+ new JnetAnnotationMaker().add_annotation(predictions,\r
+ currentAlignFrame.viewport.getAlignment(),\r
+ 0,false); // do not add sequence profile from concise output\r
+ currentAlignFrame.alignPanel.fontChanged();\r
+ currentAlignFrame.alignPanel.setScrollValues(0, 0);\r
+ } catch (Exception ex) {\r
+ ex.printStackTrace();\r
+ }\r
+ }\r
+\r
+\r
+ String pdbfile = applet.getParameter("PDBFILE");\r
+ if(pdbfile!=null)\r
+ {\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, protocol,\r
+ (Sequence)currentAlignFrame.getAlignViewport().getAlignment().findName(sequence),\r
+ currentAlignFrame.getSeqcanvas());\r
+ }\r
+\r
+ }\r
+ }\r
+ else\r
+ {\r
+ fileFound = false;\r
+ remove(launcher);\r
+ 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