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
49 boolean embedded = false;
\r
53 * init method for Jalview Applet
\r
60 String param = getParameter("RGB");
\r
66 r = Integer.parseInt(param.substring(0, 2), 16);
\r
67 g = Integer.parseInt(param.substring(2, 4), 16);
\r
68 b = Integer.parseInt(param.substring(4, 6), 16);
\r
70 catch (Exception ex)
\r
78 param = getParameter("label");
\r
80 launcher.setLabel(param);
\r
82 this.setBackground(new Color(r, g, b));
\r
85 param = getParameter("features");
\r
88 if(param.indexOf("://")==-1)
\r
89 param = getCodeBase() + param;
\r
91 final String featuresFile = param;
\r
93 file = getParameter("file");
\r
94 if(file.indexOf("://")==-1)
\r
95 file = getCodeBase() + file;
\r
97 final JalviewLite applet = this;
\r
98 if(getParameter("embedded")!=null
\r
99 && getParameter("embedded").equalsIgnoreCase("true"))
\r
102 LoadingThread loader = new LoadingThread(file,
\r
108 else if (file != null)
\r
112 launcher.addActionListener(new java.awt.event.ActionListener()
\r
114 public void actionPerformed(ActionEvent e)
\r
116 LoadingThread loader = new LoadingThread(file,
\r
132 public static void main(String [] args)
\r
136 System.out.println("\nUsage: java -jar jalviewApplet.jar fileName\n");
\r
140 String format = jalview.io.IdentifyFile.Identify(args[0],"File");
\r
141 SequenceI[] sequences = new AppletFormatAdapter().readFile(args[0], "File", format);
\r
143 if ( (sequences != null) && (sequences.length > 0))
\r
145 AlignFrame af = new AlignFrame(new Alignment(sequences), null, args[0]);
\r
146 af.statusBar.setText("Successfully loaded file " + args[0]);
\r
152 * Initialises and displays a new java.awt.Frame
\r
154 * @param frame java.awt.Frame to be displayed
\r
155 * @param title title of new frame
\r
156 * @param width width if new frame
\r
157 * @param height height of new frame
\r
159 public static void addFrame(final Frame frame, String title, int width,
\r
162 frame.setLocation(lastFrameX, lastFrameY);
\r
165 frame.setSize(width, height);
\r
166 frame.setTitle(title);
\r
167 frame.addWindowListener(new WindowAdapter()
\r
169 public void windowClosing(WindowEvent e)
\r
171 if(currentAlignFrame == frame)
\r
173 currentAlignFrame = null;
\r
177 frame.setMenuBar(null);
\r
180 public void windowActivated(WindowEvent e)
\r
182 if(frame instanceof AlignFrame)
\r
183 currentAlignFrame = (AlignFrame)frame;
\r
187 frame.setVisible(true);
\r
190 public String getAlignment(String format)
\r
192 return getAlignment(format, "true");
\r
195 public String getAlignment(String format, String suffix)
\r
199 boolean seqlimits = suffix.equalsIgnoreCase("true");
\r
201 String reply = new AppletFormatAdapter().formatSequences(format,
\r
202 currentAlignFrame.viewport.getAlignment().getSequences(), seqlimits);
\r
205 catch (Exception ex)
\r
207 ex.printStackTrace();
\r
208 return "Error retrieving alignment in " + format + " format. ";
\r
213 * This paints the background surrounding the "Launch Jalview button"
\r
215 * <br>If file given in parameter not found, displays error message
\r
217 * @param g graphics context
\r
219 public void paint(Graphics g)
\r
223 g.setColor(new Color(200, 200, 200));
\r
224 g.setColor(Color.cyan);
\r
225 g.fillRect(0, 0, getSize().width, getSize().height);
\r
226 g.setColor(Color.red);
\r
227 g.drawString("Jalview can't open file", 5, 15);
\r
228 g.drawString("\"" + file + "\"", 5, 30);
\r
232 g.setColor(Color.black);
\r
233 g.setFont(new Font("Arial", Font.BOLD, 24));
\r
234 g.drawString("Jalview Applet", 50, this.size().height/2 -30);
\r
235 g.drawString("Loading Data...", 50, this.size().height/2);
\r
241 class LoadingThread extends Thread
\r
246 String featuresFile;
\r
247 JalviewLite applet;
\r
249 public LoadingThread(String file,
\r
252 JalviewLite applet)
\r
255 this.protocol = protocol;
\r
256 format = jalview.io.IdentifyFile.Identify(file, "URL");
\r
257 featuresFile = features;
\r
258 this.applet = applet;
\r
263 SequenceI[] sequences = null;
\r
264 sequences = new AppletFormatAdapter().readFile(file, protocol, format);
\r
266 if ((sequences != null) && (sequences.length > 0))
\r
268 currentAlignFrame = new AlignFrame(new Alignment(sequences),
\r
271 currentAlignFrame.setEmbedded();
\r
273 currentAlignFrame.statusBar.setText("Successfully loaded file " + file);
\r
275 if (featuresFile != null)
\r
276 currentAlignFrame.parseFeaturesFile(featuresFile);
\r
278 String treeFile = applet.getParameter("treeFile");
\r
279 if (treeFile != null)
\r
283 jalview.io.NewickFile fin = new jalview.io.NewickFile(applet.
\r
284 getCodeBase() + treeFile, "URL");
\r
287 if (fin.getTree() != null)
\r
289 TreePanel tp = null;
\r
290 tp = new TreePanel(currentAlignFrame.viewport,
\r
291 currentAlignFrame.viewport.getAlignment().getSequences(),
\r
292 fin, "FromFile", applet.getCodeBase() + treeFile);
\r
293 addFrame(tp, treeFile, 600, 500);
\r
294 currentAlignFrame.addTreeMenuItem(tp, treeFile);
\r
297 catch (Exception ex)
\r
299 ex.printStackTrace();
\r
304 String pdbfile = applet.getParameter("PDBFILE");
\r
307 if(pdbfile.indexOf("://")==-1)
\r
308 pdbfile = getCodeBase() + pdbfile;
\r
310 String sequence = applet.getParameter("PDBSEQ");
\r
314 new MCview.AppletPDBViewer(pdbfile, "URL",
\r
315 (Sequence)currentAlignFrame.getAlignViewport().getAlignment().findName(sequence),
\r
316 currentAlignFrame.getSeqcanvas());
\r