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
34 * Jalview Applet. Runs in Java 1.18 runtime
\r
37 * @version $Revision$
\r
39 public class JalviewLite extends Applet
\r
41 static int lastFrameX = 200;
\r
42 static int lastFrameY = 200;
\r
43 static Applet applet;
\r
44 boolean fileFound = true;
\r
45 String file = "No file";
\r
46 Button launcher = new Button("Start Jalview");
\r
49 * init method for Jalview Applet
\r
58 String param = getParameter("RGB");
\r
64 r = Integer.parseInt(param.substring(0, 2), 16);
\r
65 g = Integer.parseInt(param.substring(2, 4), 16);
\r
66 b = Integer.parseInt(param.substring(4, 6), 16);
\r
68 catch (Exception ex)
\r
76 AlignFrame.NEW_WINDOW_WIDTH = 700;
\r
77 AlignFrame.NEW_WINDOW_HEIGHT = 500;
\r
79 param = applet.getParameter("windowWidth");
\r
82 int width = Integer.parseInt(param);
\r
83 AlignFrame.NEW_WINDOW_WIDTH = width;
\r
85 param = applet.getParameter("windowHeight");
\r
88 int height = Integer.parseInt(param);
\r
89 AlignFrame.NEW_WINDOW_HEIGHT = height;
\r
91 }catch(Exception ex){}
\r
93 this.setBackground(new Color(r, g, b));
\r
95 file = getParameter("file");
\r
100 file = applet.getCodeBase() + file;
\r
101 launcher.addActionListener(new java.awt.event.ActionListener()
\r
103 public void actionPerformed(ActionEvent e)
\r
105 String format = jalview.io.IdentifyFile.Identify(file,
\r
107 LoadFile(file, "URL", format);
\r
118 public static void main(String [] args)
\r
122 System.out.println("\nUsage: java -jar jalviewApplet.jar fileName\n");
\r
127 String format = jalview.io.IdentifyFile.Identify(args[0],"File");
\r
128 SequenceI[] sequences = new FormatAdapter().readFile(args[0], "File", format);
\r
130 if ( (sequences != null) && (sequences.length > 0))
\r
132 AlignFrame af = new AlignFrame(new Alignment(sequences), null);
\r
133 addFrame(af, args[0], AlignFrame.NEW_WINDOW_WIDTH,
\r
134 AlignFrame.NEW_WINDOW_HEIGHT);
\r
135 af.statusBar.setText("Successfully loaded file " + args[0]);
\r
140 * Displays the given URL in a new browser window
\r
142 * @param url URL to display in browser window.
\r
143 * <br>New window will be named "HELP_WINDOW"
\r
145 public static void showURL(String url)
\r
147 showURL(url, "HELP");
\r
150 public static void showURL(String url, String target)
\r
154 System.out.println("Not running as applet - no browser available.");
\r
160 applet.getAppletContext().showDocument(new java.net.URL(url),
\r
163 catch (Exception ex)
\r
165 ex.printStackTrace();
\r
172 * Starts a new LoadingThread for loading an alignment file
\r
174 * @param file file name including full path to file
\r
175 * @param protocol file or URL or paste
\r
176 * @param format Fasta, Clustal, PFAM, MSF, PIR, BLC, Jalview
\r
178 public void LoadFile(String file, String protocol, String format)
\r
180 LoadingThread loader = new LoadingThread(file, protocol, format, this);
\r
185 * Initialises and displays a new java.awt.Frame
\r
187 * @param frame java.awt.Frame to be displayed
\r
188 * @param title title of new frame
\r
189 * @param width width if new frame
\r
190 * @param height height of new frame
\r
192 public static void addFrame(final Frame frame, String title, int width,
\r
195 frame.setLocation(lastFrameX, lastFrameY);
\r
198 frame.setSize(width, height);
\r
199 frame.setTitle(title);
\r
200 frame.addWindowListener(new WindowAdapter()
\r
202 public void windowClosing(WindowEvent e)
\r
207 frame.setVisible(true);
\r
211 * This paints the background surrounding the "Launch Jalview button"
\r
213 * <br>If file given in parameter not found, displays error message
\r
215 * @param g graphics context
\r
217 public void paint(Graphics g)
\r
221 g.setColor(new Color(200, 200, 200));
\r
222 g.setColor(Color.cyan);
\r
223 g.fillRect(0, 0, getSize().width, getSize().height);
\r
224 g.setColor(Color.red);
\r
225 g.drawString("Jalview can't open file", 5, 15);
\r
226 g.drawString("\"" + file + "\"", 5, 30);
\r
230 class LoadingThread extends Thread
\r
235 JalviewLite jlapplet;
\r
237 public LoadingThread(String file, String protocol, String format,
\r
238 JalviewLite applet)
\r
241 this.protocol = protocol;
\r
242 this.format = format;
\r
243 this.jlapplet = applet;
\r
248 SequenceI[] sequences = null;
\r
249 sequences = new FormatAdapter().readFile(file, protocol, format);
\r
251 if ((sequences != null) && (sequences.length > 0))
\r
253 AlignFrame af = new AlignFrame(new Alignment(sequences),
\r
255 addFrame(af, file, AlignFrame.NEW_WINDOW_WIDTH,
\r
256 AlignFrame.NEW_WINDOW_HEIGHT);
\r
257 af.statusBar.setText("Successfully loaded file " + file);
\r