2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.bin;
\r
21 import jalview.appletgui.AlignFrame;
\r
23 import jalview.datamodel.*;
\r
25 import jalview.io.*;
\r
27 import java.applet.*;
\r
30 import java.awt.event.*;
\r
31 import jalview.appletgui.TreePanel;
\r
35 * Jalview Applet. Runs in Java 1.18 runtime
\r
38 * @version $Revision$
\r
40 public class JalviewLite extends Applet
\r
42 static int lastFrameX = 200;
\r
43 static int lastFrameY = 200;
\r
44 boolean fileFound = true;
\r
45 String file = "No file";
\r
46 Button launcher = new Button("Start Jalview");
\r
48 static AlignFrame currentAlignFrame;
\r
52 * init method for Jalview Applet
\r
59 String param = getParameter("RGB");
\r
65 r = Integer.parseInt(param.substring(0, 2), 16);
\r
66 g = Integer.parseInt(param.substring(2, 4), 16);
\r
67 b = Integer.parseInt(param.substring(4, 6), 16);
\r
69 catch (Exception ex)
\r
77 param = getParameter("label");
\r
79 launcher.setLabel(param);
\r
81 this.setBackground(new Color(r, g, b));
\r
84 param = getParameter("features");
\r
87 if(param.indexOf("://")==-1)
\r
88 param = getCodeBase() + param;
\r
90 final String featuresFile = param;
\r
92 file = getParameter("file");
\r
93 final JalviewLite applet = this;
\r
97 if(file.indexOf("://")==-1)
\r
98 file = getCodeBase() + file;
\r
100 launcher.addActionListener(new java.awt.event.ActionListener()
\r
102 public void actionPerformed(ActionEvent e)
\r
104 String format = jalview.io.IdentifyFile.Identify(file,
\r
106 LoadingThread loader = new LoadingThread(file,
\r
123 public static void main(String [] args)
\r
127 System.out.println("\nUsage: java -jar jalviewApplet.jar fileName\n");
\r
131 String format = jalview.io.IdentifyFile.Identify(args[0],"File");
\r
132 SequenceI[] sequences = new AppletFormatAdapter().readFile(args[0], "File", format);
\r
134 if ( (sequences != null) && (sequences.length > 0))
\r
136 AlignFrame af = new AlignFrame(new Alignment(sequences), null, args[0]);
\r
137 af.statusBar.setText("Successfully loaded file " + args[0]);
\r
143 * Initialises and displays a new java.awt.Frame
\r
145 * @param frame java.awt.Frame to be displayed
\r
146 * @param title title of new frame
\r
147 * @param width width if new frame
\r
148 * @param height height of new frame
\r
150 public static void addFrame(final Frame frame, String title, int width,
\r
153 frame.setLocation(lastFrameX, lastFrameY);
\r
156 frame.setSize(width, height);
\r
157 frame.setTitle(title);
\r
158 frame.addWindowListener(new WindowAdapter()
\r
160 public void windowClosing(WindowEvent e)
\r
162 if(currentAlignFrame == frame)
\r
164 currentAlignFrame = null;
\r
168 frame.setMenuBar(null);
\r
171 public void windowActivated(WindowEvent e)
\r
173 if(frame instanceof AlignFrame)
\r
174 currentAlignFrame = (AlignFrame)frame;
\r
178 frame.setVisible(true);
\r
181 public String getAlignment(String format)
\r
183 return getAlignment(format, "true");
\r
186 public String getAlignment(String format, String suffix)
\r
190 boolean seqlimits = suffix.equalsIgnoreCase("true");
\r
192 String reply = new AppletFormatAdapter().formatSequences(format,
\r
193 currentAlignFrame.viewport.getAlignment().getSequences(), seqlimits);
\r
196 catch (Exception ex)
\r
198 ex.printStackTrace();
\r
199 return "Error retrieving alignment in " + format + " format. ";
\r
204 * This paints the background surrounding the "Launch Jalview button"
\r
206 * <br>If file given in parameter not found, displays error message
\r
208 * @param g graphics context
\r
210 public void paint(Graphics g)
\r
214 g.setColor(new Color(200, 200, 200));
\r
215 g.setColor(Color.cyan);
\r
216 g.fillRect(0, 0, getSize().width, getSize().height);
\r
217 g.setColor(Color.red);
\r
218 g.drawString("Jalview can't open file", 5, 15);
\r
219 g.drawString("\"" + file + "\"", 5, 30);
\r
223 class LoadingThread extends Thread
\r
228 String featuresFile;
\r
229 JalviewLite applet;
\r
231 public LoadingThread(String file,
\r
235 JalviewLite applet)
\r
238 this.protocol = protocol;
\r
239 this.format = format;
\r
240 featuresFile = features;
\r
241 this.applet = applet;
\r
246 SequenceI[] sequences = null;
\r
247 sequences = new AppletFormatAdapter().readFile(file, protocol, format);
\r
249 if ((sequences != null) && (sequences.length > 0))
\r
251 currentAlignFrame = new AlignFrame(new Alignment(sequences),
\r
253 currentAlignFrame.statusBar.setText("Successfully loaded file " + file);
\r
255 if(featuresFile!=null)
\r
256 currentAlignFrame.parseFeaturesFile(featuresFile);
\r
258 String treeFile = applet.getParameter("treeFile");
\r
259 if (treeFile != null)
\r
263 jalview.io.NewickFile fin = new jalview.io.NewickFile(applet.
\r
264 getCodeBase() + treeFile, "URL");
\r
267 if (fin.getTree() != null)
\r
269 TreePanel tp = null;
\r
270 tp = new TreePanel(currentAlignFrame.viewport,
\r
271 currentAlignFrame.viewport.getAlignment().getSequences(),
\r
272 fin, "FromFile", applet.getCodeBase() + treeFile);
\r
273 addFrame(tp, treeFile, 600, 500);
\r
274 currentAlignFrame.addTreeMenuItem(tp, treeFile);
\r
277 catch (Exception ex)
\r
279 ex.printStackTrace();
\r
284 String pdbfile = applet.getParameter("PDBFILE");
\r
287 if(pdbfile.indexOf("://")==-1)
\r
288 pdbfile = getCodeBase() + pdbfile;
\r
290 String sequence = applet.getParameter("PDBSEQ");
\r
294 new MCview.AppletPDBViewer(pdbfile, "URL",
\r
295 (Sequence)currentAlignFrame.getAlignViewport().getAlignment().findName(sequence),
\r
296 currentAlignFrame.getSeqcanvas());
\r